OpenMS  2.7.0
Plot1DCanvas.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2021.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Timo Sachsenberg$
32 // $Authors: Marc Sturm, Timo Sachsenberg, Chris Bielow $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
37 // OpenMS_GUI config
38 #include <OpenMS/VISUAL/OpenMS_GUIConfig.h>
39 
40 // OpenMS
42 
43 #include <QTextDocument>
44 
45 // STL
46 #include <vector>
47 #include <utility>
48 
49 // QT
50 class QAction;
51 
52 namespace OpenMS
53 {
67  class OPENMS_GUI_DLLAPI Plot1DCanvas :
68  public PlotCanvas
69  {
70  Q_OBJECT
71 
72 public:
74  enum LabelMode
75  {
79  LM_XPERCENT_YPERCENT
80  };
81 
83  constexpr static double TOP_MARGIN{1.09};
84 
86  Plot1DCanvas(const Param & preferences, QWidget* parent = nullptr);
88  ~Plot1DCanvas() override;
89 
101  ODExperimentSharedPtrType ondisc_sptr,
102  OSWDataSharedPtrType chrom_annotation,
103  const int index,
104  const String& filename,
105  const String& caption,
106  const bool multiple_select);
107 
108 
111  {
113  DM_CONNECTEDLINES
114  };
115 
118 
120  void setDrawMode(DrawModes mode);
121 
122  // Docu in base class
124 
125  // Docu in base class
126  void saveCurrentLayer(bool visible) override;
127 
130 
132  void flipLayer(Size index);
133 
136 
138  void setMirrorModeActive(bool b);
139 
141  void dataToWidget(const PeakType& peak, QPoint& point, bool flipped = false, bool percentage = true);
142 
144  void dataToWidget(double x, double y, QPoint& point, bool flipped = false, bool percentage = false);
145 
147  PointType widgetToData(const QPoint& pos, bool percentage = false);
148 
150  PointType widgetToData(double x, double y, bool percentage = false);
151 
153  void setTextBox(const QString& html);
154 
156 
158  Annotation1DItem* addPeakAnnotation(const PeakIndex& peak_index, const QString& text, const QColor& color);
159 
161  void drawAnnotations(Size layer_index, QPainter& painter);
162 
164 
166  void performAlignment(Size layer_index_1, Size layer_index_2, const Param& param);
167 
170 
172  void drawAlignment(QPainter& painter);
173 
176 
179 
181  std::vector<std::pair<Size, Size> > getAlignedPeaksIndices();
182 
184  void activateSpectrum(Size index, bool repaint = true);
185 
187  void setSwappedAxis(bool swapped);
188 
190  void setCurrentLayerPeakPenStyle(Qt::PenStyle ps);
191 
193  void paint(QPainter* paint_device, QPaintEvent* e);
194 
196  void setDrawInterestingMZs(bool enable);
197 
199  bool isDrawInterestingMZs() const;
200 
201  // Show/hide ion ladder on top right corner (Identification view)
202  void setIonLadderVisible(bool show);
203 
204  // Returns true if ion ladder is visible
205  bool isIonLadderVisible() const;
206 
207 signals:
210 
213 
216 
219 
220 public slots:
221  // Docu in base class
222  void activateLayer(Size layer_index) override;
223  // Docu in base class
224  void removeLayer(Size layer_index) override;
225  // Docu in base class
226  void updateLayer(Size i) override;
227 
234  void setVisibleArea(DRange<2> range); //Do not change this to AreaType the signal needs QT needs the exact type...
235  // Docu in base class
236  void horizontalScrollBarChange(int value) override;
237 
238 protected slots:
239 
242 
243 protected:
244  // Docu in base class
245  bool finishAdding_() override;
246 
248  void drawCoordinates_(QPainter& painter, const PeakIndex& peak);
250  void drawDeltas_(QPainter& painter, const PeakIndex& start, const PeakIndex& end);
251 
253  void drawMZAtInterestingPeaks_(Size layer_index, QPainter& painter);
254 
260  void changeVisibleArea_(double lo, double hi, bool repaint = true, bool add_to_stack = false);
261 
263  void drawHighlightedPeak_(Size layer_index, const PeakIndex& peak, QPainter& painter, bool draw_elongation = false);
264 
266  void drawDashedLine_(const QPoint& from, const QPoint& to, QPainter& painter);
267 
269  void updatePercentageFactor_(Size layer_index);
270 
281  void changeVisibleArea_(const AreaType& new_area, bool repaint = true, bool add_to_stack = false) override;
282  // Docu in base class
283  void recalculateSnapFactor_() override;
284  // Docu in base class
285  void updateScrollbars_() override;
286  // Docu in base class
287  void intensityModeChange_() override;
288 
290  std::vector<DrawModes> draw_modes_;
292  std::vector<Qt::PenStyle> peak_penstyle_;
293 
298 
301 
309  std::vector<std::pair<double, double> > aligned_peaks_mz_delta_;
311  std::vector<std::pair<Size, Size> > aligned_peaks_indices_;
320 
323 
325  void addUserLabelAnnotation_(const QPoint& screen_position);
327  void addLabelAnnotation_(const QPoint& screen_position, QString label_text);
330 
333 
334  QTextDocument text_box_content_;
335 
338  void paintEvent(QPaintEvent* e) override;
339  void mousePressEvent(QMouseEvent* e) override;
340  void mouseReleaseEvent(QMouseEvent* e) override;
341  void mouseMoveEvent(QMouseEvent* e) override;
342  void keyPressEvent(QKeyEvent* e) override;
343  void contextMenuEvent(QContextMenuEvent* e) override;
345 
347  void zoomForward_() override;
349  void zoom_(int x, int y, bool zoom_in) override;
350  //docu in base class
351  void translateLeft_(Qt::KeyboardModifiers m) override;
352  //docu in base class
353  void translateRight_(Qt::KeyboardModifiers m) override;
354  //docu in base class
355  void paintGridLines_(QPainter& painter) override;
356  };
357 } // namespace OpenMS
358 
An abstract class acting as an interface for the different 1D annotation items.
Definition: Annotation1DItem.h:60
Management and storage of parameters / INI files.
Definition: Param.h:70
A 1-dimensional raw data point or peak.
Definition: Peak1D.h:54
Canvas for visualization of one or several spectra.
Definition: Plot1DCanvas.h:69
void setSwappedAxis(bool swapped)
is the widget shown vertically? (for projections)
double alignment_score_
Stores the score of the last alignment.
Definition: Plot1DCanvas.h:313
~Plot1DCanvas() override
Destructor.
std::vector< std::pair< Size, Size > > getAlignedPeaksIndices()
Returns aligned_peaks_indices_.
void drawAlignment(QPainter &painter)
Draws the alignment on painter.
void drawMZAtInterestingPeaks_(Size layer_index, QPainter &painter)
annotate interesting peaks in visible area with m/z
void drawCoordinates_(QPainter &painter, const PeakIndex &peak)
Draws the coordinates (or coordinate deltas) to the widget's upper left corner.
std::vector< std::pair< double, double > > aligned_peaks_mz_delta_
Stores the alignment as MZ values of pairs of aligned peaks in both spectra.
Definition: Plot1DCanvas.h:309
void addUserPeakAnnotation_(PeakIndex near_peak)
Shows dialog and calls addPeakAnnotation_.
void drawAnnotations(Size layer_index, QPainter &painter)
Draws all annotation items of layer_index on painter.
bool show_alignment_
Indicates whether an alignment is currently visualized.
Definition: Plot1DCanvas.h:303
void zoomForward_() override
Go forward in zoom history.
bool finishAdding_() override
Method that is called when a new layer has been added.
QPoint measurement_start_point_
start point of "ruler" for measure mode
Definition: Plot1DCanvas.h:295
Plot1DCanvas(const Param &preferences, QWidget *parent=nullptr)
Default constructor.
void removeLayer(Size layer_index) override
void mousePressEvent(QMouseEvent *e) override
void setDrawInterestingMZs(bool enable)
interesting (e.g., high-intensity) get live annotated with m/s's
DrawModes getDrawMode() const
Returns the draw mode of the current layer.
LabelMode
Label modes (percentage or absolute) of x axis and y axis.
Definition: Plot1DCanvas.h:75
@ LM_XPERCENT_YABSOLUTE
Definition: Plot1DCanvas.h:77
@ LM_XABSOLUTE_YPERCENT
Definition: Plot1DCanvas.h:78
@ LM_XABSOLUTE_YABSOLUTE
Definition: Plot1DCanvas.h:76
void horizontalScrollBarChange(int value) override
void setCurrentLayerPeakPenStyle(Qt::PenStyle ps)
Set's the Qt PenStyle of the active layer.
void mouseMoveEvent(QMouseEvent *e) override
std::vector< DrawModes > draw_modes_
Draw modes (for each layer)
Definition: Plot1DCanvas.h:290
void setMirrorModeActive(bool b)
Sets whether this widget is currently in mirror mode.
void mouseReleaseEvent(QMouseEvent *e) override
void showCurrentPeaksAsIonMobility()
Requests to display all spectra in ion mobility plot.
void currentLayerParamtersChanged_()
Reacts on changed layer parameters.
bool isIonLadderVisible() const
PeakIndex findPeakAtPosition_(QPoint)
Find peak next to the given position.
bool ion_ladder_visible_
whether the ion ladder is displayed on the top right corner in ID view
Definition: Plot1DCanvas.h:317
void drawDashedLine_(const QPoint &from, const QPoint &to, QPainter &painter)
Draws a dashed line using the highlighted peak color parameter.
void keyPressEvent(QKeyEvent *e) override
void activateSpectrum(Size index, bool repaint=true)
Sets current spectrum index of current layer to index.
void showCurrentPeaksAs2D()
Requests to display all spectra in 2D plot.
void updateScrollbars_() override
Updates the scroll bars.
void recalculateSnapFactor_() override
Recalculates the intensity scaling factor for 'snap to maximum intensity mode'.
DrawModes
Enumerate all available paint styles.
Definition: Plot1DCanvas.h:111
@ DM_PEAKS
draw data as peak
Definition: Plot1DCanvas.h:112
void showCurrentPeaksAsDIA()
Requests to display all spectra as DIA.
void showCurrentLayerPreferences() override
Shows the preferences dialog of the active layer.
void translateLeft_(Qt::KeyboardModifiers m) override
Translation bound to the 'Left' key.
void setIonLadderVisible(bool show)
void drawHighlightedPeak_(Size layer_index, const PeakIndex &peak, QPainter &painter, bool draw_elongation=false)
Draws a highlighted peak; if draw_elongation is true, the elongation line is drawn (for measuring)
double getAlignmentScore()
Returns the score of the alignment.
void setTextBox(const QString &html)
Display a static text box on the top right.
void drawDeltas_(QPainter &painter, const PeakIndex &start, const PeakIndex &end)
Draws the coordinates (or coordinate deltas) to the widget's upper left corner.
bool draw_interesting_MZs_
annotate interesting peaks with m/z's
Definition: Plot1DCanvas.h:319
void flipLayer(Size index)
Flips the layer with index up/downwards.
void performAlignment(Size layer_index_1, Size layer_index_2, const Param &param)
—– Alignment
bool isDrawInterestingMZs() const
Return true if interesting m/s are annotated.
std::vector< std::pair< Size, Size > > aligned_peaks_indices_
Stores the peak indices of pairs of aligned peaks in both spectra.
Definition: Plot1DCanvas.h:311
std::vector< Qt::PenStyle > peak_penstyle_
Draw style (for each layer)
Definition: Plot1DCanvas.h:292
void paint(QPainter *paint_device, QPaintEvent *e)
Actual painting takes place here.
void intensityModeChange_() override
This method is called whenever the intensity mode changes. Reimplement if you need to react on such c...
void updatePercentageFactor_(Size layer_index)
Recalculates the current scale factor based on the specified layer (= 1.0 if intensity mode !...
void changeVisibleArea_(double lo, double hi, bool repaint=true, bool add_to_stack=false)
Changes visible area interval.
void activateLayer(Size layer_index) override
void translateRight_(Qt::KeyboardModifiers m) override
Translation bound to the 'Right' key.
void updateLayer(Size i) override
void contextMenuEvent(QContextMenuEvent *e) override
PointType widgetToData(double x, double y, bool percentage=false)
Calls PlotCanvas::widgetToData_(), takes mirror mode into account.
void addUserLabelAnnotation_(const QPoint &screen_position)
Shows dialog and calls addLabelAnnotation_.
void setDrawMode(DrawModes mode)
Sets draw mode of the current layer.
QTextDocument text_box_content_
Definition: Plot1DCanvas.h:334
void showCurrentPeaksAs3D()
Requests to display all spectra in 3D plot.
bool moving_annotations_
Indicates whether annotation items are just being moved on the canvas.
Definition: Plot1DCanvas.h:300
bool addChromLayer(ExperimentSharedPtrType chrom_exp_sptr, ODExperimentSharedPtrType ondisc_sptr, OSWDataSharedPtrType chrom_annotation, const int index, const String &filename, const String &caption, const bool multiple_select)
void zoom_(int x, int y, bool zoom_in) override
docu in base class
void paintGridLines_(QPainter &painter) override
Helper function to paint grid lines.
void ensureAnnotationsWithinDataRange_()
Ensure that all annotations are within data range.
PointType widgetToData(const QPoint &pos, bool percentage=false)
For convenience - calls widgetToData.
Annotation1DItem * addPeakAnnotation(const PeakIndex &peak_index, const QString &text, const QColor &color)
—– Annotations
void dataToWidget(const PeakType &peak, QPoint &point, bool flipped=false, bool percentage=true)
For convenience - calls dataToWidget.
Size alignment_layer_1_
Layer index of the first alignment layer.
Definition: Plot1DCanvas.h:305
bool is_swapped_
is this widget showing data with swapped m/z and RT axis? (for drawCoordinates_ only)
Definition: Plot1DCanvas.h:315
bool mirror_mode_
Indicates whether this widget is currently in mirror mode.
Definition: Plot1DCanvas.h:297
void addLabelAnnotation_(const QPoint &screen_position, QString label_text)
Adds an annotation item at the given screen position.
Size getAlignmentSize()
Returns the number of aligned pairs of peaks.
bool mirrorModeActive()
Returns whether this widget is currently in mirror mode.
Size alignment_layer_2_
Layer index of the second alignment layer.
Definition: Plot1DCanvas.h:307
void dataToWidget(double x, double y, QPoint &point, bool flipped=false, bool percentage=false)
Calls PlotCanvas::dataToWidget_(), takes mirror mode into account.
void saveCurrentLayer(bool visible) override
Saves the current layer data.
void paintEvent(QPaintEvent *e) override
bool flippedLayersExist()
Returns whether flipped layers exist or not.
void changeVisibleArea_(const AreaType &new_area, bool repaint=true, bool add_to_stack=false) override
Sets the visible area.
void resetAlignment()
Resets alignment_.
void setVisibleArea(DRange< 2 > range)
Sets the visible area.
Base class for visualization canvas classes.
Definition: PlotCanvas.h:136
LayerData::ExperimentSharedPtrType ExperimentSharedPtrType
Main managed data type (experiment)
Definition: PlotCanvas.h:146
LayerData::OSWDataSharedPtrType OSWDataSharedPtrType
Definition: PlotCanvas.h:149
LayerData::ODExperimentSharedPtrType ODExperimentSharedPtrType
Definition: PlotCanvas.h:148
A more convenient string class.
Definition: String.h:61
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
Index of a peak or feature.
Definition: PeakIndex.h:51