17 #include <QtGui/QColor>
18 #include <QtGui/QFontMetricsF>
26 template <
class DataPo
int>
44 void draw(
Plot1DCanvas*
const canvas, QPainter& painter,
bool flipped =
false)
override
50 QPoint position_widget, peak_position_widget;
57 const QFontMetricsF fm(QApplication::font());
58 const auto prebox = fm.boundingRect(QRectF(position_widget.x(), position_widget.y(), 0, 0), Qt::AlignCenter,
getText());
67 bounding_box_ = fm.boundingRect(QRectF(position_widget.x(), position_widget.y(), 0, 0), Qt::AlignCenter,
getText());
71 if ((position_widget - peak_position_widget).manhattanLength() > 2)
77 painter.setPen(Qt::DashLine);
78 painter.drawLine(peak_position_widget, border_point);
85 if (!text.contains(
"<\\"))
89 QRegularExpression reg_exp(R
"(([abcdwxyz])(\d+))");
90 QRegularExpressionMatch match = reg_exp.match(text);
91 if (text.indexOf(reg_exp) == 0)
93 text.replace(reg_exp,
"\\1<sub>\\2</sub>");
97 QRegularExpression reg_exp_xlms(R
"((ci|xi)[$][abcxyz](\d+))");
98 auto match_pos = text.indexOf(reg_exp_xlms);
99 if ((match_pos == 6) || (match_pos == 7))
104 QString charge_str = match.captured(2);
106 text = text.left(match_pos) + QString(
"<sub>") + charge_str + QString(
"</sub>") + text.right(text.size() - match_pos - charge_str.size());
112 text.replace(
"H2O1",
"H<sub>2</sub>O");
113 text.replace(
"H2O",
"H<sub>2</sub>O");
114 text.replace(
"NH3",
"NH<sub>3</sub>");
115 text.replace(
"H3N1",
"NH<sub>3</sub>");
116 text.replace(
"C1H4O1S1",
"H<sub>4</sub>COS");
119 text.replace(
"H3PO4",
"H<sub>3</sub>PO<sub>4</sub>");
120 text.replace(
"HPO3",
"HPO<sub>3</sub>");
121 text.replace(
"C3O",
"C<sub>3</sub>O");
124 QRegularExpression charge_rx(R
"([\+|\-](\d+)$)");
125 int match_pos = text.indexOf(charge_rx);
128 text = text.left(match_pos) + QString(
"<sup>") + text[match_pos]
129 + charge_rx.match(text).captured(1) + QString(
"</sup>");
133 charge_rx = QRegularExpression(R
"((\d+)[\+|\-]$)");
134 match_pos = text.indexOf(charge_rx);
137 auto charge_match = charge_rx.match(text).captured(1);
138 text = text.left(match_pos) + QString(
"<sup>") + charge_match
139 + text[match_pos + charge_match.size()] + QString(
"</sup>");
142 text.replace(QRegularExpression(R
"(\+\+$)"), "<sup>2+</sup>");
143 text.replace(QRegularExpression(R
"(\+$)"), "");
144 text.replace(QRegularExpression(R
"(\-\-$)"), "<sup>2-</sup>");
145 text.replace(QRegularExpression(R
"(\-$)"), "");
148 text =
"<font color=\"" +
color_.name() +
"\">" + text +
"</font>";
155 double w = td.size().width();
156 double h = td.size().height();
157 painter.translate(position_widget.x() - w / 2, position_widget.y() -
h / 2);
158 td.drawContents(&painter);
218 QString peak_anno = this->
getText().trimmed();
221 peak_anno.remove(
'\r');
222 QStringList lines = peak_anno.split(
'\n', Qt::SkipEmptyParts);
223 if (lines.size() > 1)
225 peak_anno = lines[0];
229 QRegularExpression reg_exp(R
"(([\+|\-]\d+)$)");
234 int match_pos = peak_anno.indexOf(reg_exp);
238 tmp_charge = reg_exp.match(peak_anno).captured(1).toInt();
239 peak_anno = peak_anno.left(match_pos);
244 int plus(0), minus(0);
246 for (
int p = (
int)peak_anno.size() - 1; p >= 0; --p)
248 if (peak_anno[p] ==
'+')
253 else if (peak_anno[p] ==
'-')
260 if (plus > 0 && minus == 0)
263 peak_anno = peak_anno.left(peak_anno.size() - plus);
266 else if (minus > 0 && plus == 0)
269 peak_anno = peak_anno.left(peak_anno.size() - minus);
281 if (lines.size() > 1)
283 peak_anno.append(
"\n").append(lines[1]);
An abstract class acting as an interface for the different 1D annotation items.
Definition: Annotation1DItem.h:36
QRectF bounding_box_
The current bounding box of this item on the canvas where it has last been drawn.
Definition: Annotation1DItem.h:83
QString text_
The displayed text.
Definition: Annotation1DItem.h:89
void drawBoundingBox_(QPainter &painter)
Draws the bounding_box_.
const QString & getText() const
Returns the text of the item.
bool selected_
Determines whether this item is currently selected on the canvas.
Definition: Annotation1DItem.h:86
A peak annotation item.
Definition: Annotation1DPeakItem.h:29
const QColor & getColor() const
Returns the color of the label.
Definition: Annotation1DPeakItem.h:209
Annotation1DItem * clone() const override
Creates a copy of the item on the heap and returns a pointer.
Definition: Annotation1DPeakItem.h:291
~Annotation1DPeakItem() override=default
Destructor.
const DataPoint & getPosition() const
Returns the position of the label (peak)
Definition: Annotation1DPeakItem.h:185
void draw(Plot1DCanvas *const canvas, QPainter &painter, bool flipped=false) override
Draws the item on painter.
Definition: Annotation1DPeakItem.h:44
const DataPoint & getPeakPosition() const
Returns the position of the annotated peak.
Definition: Annotation1DPeakItem.h:191
QColor color_
The color of the label.
Definition: Annotation1DPeakItem.h:304
Annotation1DPeakItem(const Annotation1DPeakItem &rhs)=default
Copy constructor.
void ensureWithinDataRange(Plot1DCanvas *const canvas, const int layer_index) override
Ensures that the item has coordinates within the visible area of the canvas.
Definition: Annotation1DPeakItem.h:197
PeptideHit::PeakAnnotation toPeakAnnotation() const
Convert the 'text()' to a Peptide::PeakAnnotation.
Definition: Annotation1DPeakItem.h:215
DataPoint peak_position_
The position of the anchor (e.g. the Peak1D)
Definition: Annotation1DPeakItem.h:298
void setColor(const QColor &color)
Set the color of the label.
Definition: Annotation1DPeakItem.h:203
Annotation1DPeakItem(const DataPoint &peak_position, const QString &text, const QColor &color)
Constructor.
Definition: Annotation1DPeakItem.h:32
void setPosition(const DataPoint &position)
Sets the position of the label.
Definition: Annotation1DPeakItem.h:179
void move(const PointXYType delta, const Gravitator &, const DimMapper< 2 > &dim_mapper) override
Moves the item on the drawing canvas; behavior depends on item type and is implemented in the subclas...
Definition: Annotation1DPeakItem.h:171
DataPoint position_
The position of the label (e.g. the Peak1D)
Definition: Annotation1DPeakItem.h:301
DPosition & abs() noexcept
Make all dimension values positive.
Definition: DPosition.h:111
void fromXY(const DRange< N_DIM > &in, RangeManager< Ranges... > &output) const
Definition: DimMapper.h:752
Point map(const T &data) const
convert an OpenMS datatype (such as Feature) to an N_DIM-dimensional point
Definition: DimMapper.h:716
Manipulates X or Y component of points in the X-Y plane, by assuming one axis (either X or Y axis) ha...
Definition: Plot1DCanvas.h:42
QPoint gravitateZero(QPoint p) const
Definition: Plot1DCanvas.h:204
Gravitator swap() const
Swap gravity axis (from X to Y, or vice versa)
Definition: Plot1DCanvas.h:108
Canvas for visualization of one or several spectra.
Definition: Plot1DCanvas.h:295
void dataToWidget(const DPosition< 2 > &peak, QPoint &point, bool flipped=false)
For convenience - calls dataToWidget.
const Gravitator & getGravitator() const
Get gravity manipulation object to apply gravity to points.
Definition: Plot1DCanvas.h:504
void pushIntoDataRange(T &data_point, const int layer_index)
Pushes a data point back into the valid data range of the current layer area. Useful for annotation i...
Definition: Plot1DCanvas.h:434
PointXYType widgetToDataDistance(double x, double y)
compute distance in data coordinates (unit axis as shown) when moving x/y pixel in chart/widget coord...
Definition: Plot1DCanvas.h:412
const DimMapper< 2 > & getMapper() const
Get Mapper to translate between values for axis (X/Y) and units (m/z, RT, intensity,...
const double h
Definition: Constants.h:141
QPointF intersectionPoint(const QRectF &rect, const QPointF &p)
Find the point on a rectangle where a ray/line from a point p to its center would intersect at.
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
Contains annotations of a peak.
Definition: PeptideHit.h:76
double intensity
Definition: PeptideHit.h:80
double mz
Definition: PeptideHit.h:79
String annotation
Definition: PeptideHit.h:77
int charge
Definition: PeptideHit.h:78