43 #include <QtGui/QColor> 51 template <
class DataPo
int>
69 void draw(
Plot1DCanvas*
const canvas, QPainter& painter,
bool flipped =
false)
override 75 QPoint position_widget, peak_position_widget;
82 const auto prebox = QApplication::fontMetrics().boundingRect(position_widget.x(), position_widget.y(), 0, 0, Qt::AlignCenter,
getText());
86 const auto deltaXY_in_units = canvas->
widgetToDataDistance(prebox.width(), prebox.height()).abs();
91 bounding_box_ = QApplication::fontMetrics().boundingRect(position_widget.x(), position_widget.y(), 0, 0, Qt::AlignCenter,
getText());
95 if ((position_widget - peak_position_widget).manhattanLength() > 2)
101 painter.setPen(Qt::DashLine);
102 painter.drawLine(peak_position_widget, border_point);
108 QString text =
text_;
109 if (!text.contains(R
"(<\)")) 113 QRegExp reg_exp(R
"([abcdwxyz](\d+))"); 114 int match_pos = reg_exp.indexIn(text);
118 QString index_str = reg_exp.cap(1);
121 text = text[match_pos] + QString(
"<sub>") + index_str + QString(
"</sub>") + text.right(text.size() - match_pos - index_str.size() - 1);
125 QRegExp reg_exp_xlms(R
"((ci|xi)[$][abcxyz](\d+))"); 126 match_pos = reg_exp_xlms.indexIn(text); 127 if ((match_pos == 6) || (match_pos == 7))
131 QString index_str = reg_exp.cap(1);
134 text = text.left(match_pos) + text[match_pos] + QString(
"<sub>") + index_str + QString(
"</sub>") + text.right(text.size() - match_pos - index_str.size() - 1);
140 text.replace(
"H2O1",
"H<sub>2</sub>O");
141 text.replace(
"H2O",
"H<sub>2</sub>O");
142 text.replace(
"NH3",
"NH<sub>3</sub>");
143 text.replace(
"H3N1",
"NH<sub>3</sub>");
144 text.replace(
"C1H4O1S1",
"H<sub>4</sub>COS");
147 text.replace(
"H3PO4",
"H<sub>3</sub>PO<sub>4</sub>");
148 text.replace(
"HPO3",
"HPO<sub>3</sub>");
149 text.replace(
"C3O",
"C<sub>3</sub>O");
152 QRegExp charge_rx(R
"([\+|\-](\d+)$)"); 153 int match_pos = charge_rx.indexIn(text);
156 text = text.left(match_pos) + QString(
"<sup>") + text[match_pos]
157 + charge_rx.cap(1) + QString(
"</sup>");
161 charge_rx = QRegExp(R
"((\d+)[\+|\-]$)"); 162 match_pos = charge_rx.indexIn(text); 165 text = text.left(match_pos) + QString(
"<sup>") + charge_rx.cap(1)
166 + text[match_pos + charge_rx.cap(1).size()] + QString(
"</sup>");
169 text.replace(QRegExp(R
"(\+\+$)"), "<sup>2+</sup>");
170 text.replace(QRegExp(R
"(\+$)"), "");
171 text.replace(QRegExp(R
"(\-\-$)"), "<sup>2-</sup>");
172 text.replace(QRegExp(R
"(\-$)"), "");
175 text =
"<font color=\"" +
color_.name() +
"\">" + text +
"</font>";
181 double w = td.size().width();
182 double h = td.size().height();
183 painter.translate(position_widget.x() - w / 2, position_widget.y() -
h / 2);
184 td.drawContents(&painter);
243 QString peak_anno = this->
getText().trimmed();
246 peak_anno.remove(
'\r');
247 QStringList lines = peak_anno.split(
'\n');
250 if (lines.size() > 1)
252 peak_anno = lines[0];
256 QRegExp reg_exp(R
"(([\+|\-]\d+)$)"); 261 int match_pos = reg_exp.indexIn(peak_anno);
265 tmp_charge = reg_exp.cap(1).toInt();
266 peak_anno = peak_anno.left(match_pos);
271 int plus(0), minus(0);
273 for (
int p = (
int)peak_anno.size() - 1; p >= 0; --p)
275 if (peak_anno[p] ==
'+')
280 else if (peak_anno[p] ==
'-')
287 if (plus > 0 && minus == 0)
290 peak_anno = peak_anno.left(peak_anno.size() - plus);
293 else if (minus > 0 && plus == 0)
296 peak_anno = peak_anno.left(peak_anno.size() - minus);
308 if (lines.size() > 1)
310 peak_anno.append(
"\n").append(lines[1]);
An abstract class acting as an interface for the different 1D annotation items.
Definition: Annotation1DItem.h:61
const DataPoint & getPeakPosition() const
Returns the position of the annotated peak.
Definition: Annotation1DPeakItem.h:216
bool selected_
Determines whether this item is currently selected on the canvas.
Definition: Annotation1DItem.h:112
~Annotation1DPeakItem() override=default
Destructor.
void draw(Plot1DCanvas *const canvas, QPainter &painter, bool flipped=false) override
Draws the item on painter.
Definition: Annotation1DPeakItem.h:69
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...
void drawBoundingBox_(QPainter &painter)
Draws the bounding_box_.
Canvas for visualization of one or several spectra.
Definition: Plot1DCanvas.h:319
Gravitator swap() const
Swap gravity axis (from X to Y, or vice versa)
Definition: Plot1DCanvas.h:134
const QString & getText() const
Returns the text of the item.
Annotation1DItem * clone() const override
Creates a copy of the item on the heap and returns a pointer.
Definition: Annotation1DPeakItem.h:318
void setPosition(const DataPoint &position)
Sets the position of the label.
Definition: Annotation1DPeakItem.h:204
double mz
Definition: PeptideHit.h:87
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
QColor color_
The color of the label.
Definition: Annotation1DPeakItem.h:331
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:196
String annotation
Definition: PeptideHit.h:85
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:454
Point map(const T &data) const
convert an OpenMS datatype (such as Feature) to an N_DIM-dimensional point
Definition: DimMapper.h:699
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:438
const Gravitator & getGravitator() const
Get gravity manipulation object to apply gravity to points.
Definition: Plot1DCanvas.h:524
void setColor(const QColor &color)
Set the color of the label.
Definition: Annotation1DPeakItem.h:228
DataPoint peak_position_
The position of the anchor (e.g. the Peak1D)
Definition: Annotation1DPeakItem.h:325
QRectF bounding_box_
The current bounding box of this item on the canvas where it has last been drawn. ...
Definition: Annotation1DItem.h:109
const double h
Definition: Constants.h:167
const DimMapper< 2 > & getMapper() const
Get Mapper to translate between values for axis (X/Y) and units (m/z, RT, intensity, ...)
PeptideHit::PeakAnnotation toPeakAnnotation() const
Convert the 'text()' to a Peptide::PeakAnnotation.
Definition: Annotation1DPeakItem.h:240
double intensity
Definition: PeptideHit.h:88
const QColor & getColor() const
Returns the color of the label.
Definition: Annotation1DPeakItem.h:234
DataPoint position_
The position of the label (e.g. the Peak1D)
Definition: Annotation1DPeakItem.h:328
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:222
int charge
Definition: PeptideHit.h:86
void fromXY(const DRange< N_DIM > &in, RangeManager< Ranges... > &output) const
Definition: DimMapper.h:735
Contains annotations of a peak.
Definition: PeptideHit.h:83
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:67
Annotation1DPeakItem(const DataPoint &peak_position, const QString &text, const QColor &color)
Constructor.
Definition: Annotation1DPeakItem.h:57
A peak annotation item.
Definition: Annotation1DPeakItem.h:52
void dataToWidget(const DPosition< 2 > &peak, QPoint &point, bool flipped=false)
For convenience - calls dataToWidget.
QString text_
The displayed text.
Definition: Annotation1DItem.h:115
QPoint gravitateZero(QPoint p) const
Definition: Plot1DCanvas.h:230
const DataPoint & getPosition() const
Returns the position of the label (peak)
Definition: Annotation1DPeakItem.h:210