OpenMS  2.6.0
Spectrum1DCanvas.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-2020.
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 Spectrum1DCanvas :
68  public SpectrumCanvas
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  Spectrum1DCanvas(const Param & preferences, QWidget* parent = nullptr);
88  ~Spectrum1DCanvas() override;
89 
91  enum DrawModes
92  {
94  DM_CONNECTEDLINES
95  };
96 
98  DrawModes getDrawMode() const;
99 
101  void setDrawMode(DrawModes mode);
102 
103  // Docu in base class
104  void showCurrentLayerPreferences() override;
105 
106  // Docu in base class
107  void saveCurrentLayer(bool visible) override;
108 
110  bool flippedLayersExist();
111 
113  void flipLayer(Size index);
114 
116  bool mirrorModeActive();
117 
119  void setMirrorModeActive(bool b);
120 
122  void dataToWidget(const PeakType& peak, QPoint& point, bool flipped = false, bool percentage = true);
123 
125  void dataToWidget(double x, double y, QPoint& point, bool flipped = false, bool percentage = false);
126 
128  PointType widgetToData(const QPoint& pos, bool percentage = false);
129 
131  PointType widgetToData(double x, double y, bool percentage = false);
132 
134  void setTextBox(const QString& html);
135 
137 
139  Annotation1DItem* addPeakAnnotation(const PeakIndex& peak_index, const QString& text, const QColor& color);
140 
142  void drawAnnotations(Size layer_index, QPainter& painter);
143 
145 
147  void performAlignment(Size layer_index_1, Size layer_index_2, const Param& param);
148 
150  void resetAlignment();
151 
153  void drawAlignment(QPainter& painter);
154 
156  Size getAlignmentSize();
157 
159  double getAlignmentScore();
160 
162  std::vector<std::pair<Size, Size> > getAlignedPeaksIndices();
163 
165  void activateSpectrum(Size index, bool repaint = true);
166 
168  void setSwappedAxis(bool swapped);
169 
171  void setCurrentLayerPeakPenStyle(Qt::PenStyle ps);
172 
174  void paint(QPainter* paint_device, QPaintEvent* e);
175 
177  void setDrawInterestingMZs(bool enable);
178 
180  bool isDrawInterestingMZs() const;
181 
182  // Show/hide ion ladder on top right corner (Identification view)
183  void setIonLadderVisible(bool show);
184 
185  // Returns true if ion ladder is visible
186  bool isIonLadderVisible() const;
187 
188 signals:
190  void showCurrentPeaksAs2D();
191 
193  void showCurrentPeaksAs3D();
194 
196  void showCurrentPeaksAsIonMobility();
197 
199  void showCurrentPeaksAsDIA();
200 
201 public slots:
202  // Docu in base class
203  void activateLayer(Size layer_index) override;
204  // Docu in base class
205  void removeLayer(Size layer_index) override;
206  // Docu in base class
207  void updateLayer(Size i) override;
208 
215  void setVisibleArea(DRange<2> range); //Do not change this to AreaType the signal needs QT needs the exact type...
216  // Docu in base class
217  void horizontalScrollBarChange(int value) override;
218 
219 protected slots:
220 
222  void currentLayerParamtersChanged_();
223 
224 protected:
225  // Docu in base class
226  bool finishAdding_() override;
227 
229  void drawCoordinates_(QPainter& painter, const PeakIndex& peak);
231  void drawDeltas_(QPainter& painter, const PeakIndex& start, const PeakIndex& end);
232 
234  void drawMZAtInterestingPeaks_(Size layer_index, QPainter& painter);
235 
241  void changeVisibleArea_(double lo, double hi, bool repaint = true, bool add_to_stack = false);
242 
244  void drawHighlightedPeak_(Size layer_index, const PeakIndex& peak, QPainter& painter, bool draw_elongation = false);
245 
247  void drawDashedLine_(const QPoint& from, const QPoint& to, QPainter& painter);
248 
250  void updatePercentageFactor_(Size layer_index);
251 
262  void changeVisibleArea_(const AreaType& new_area, bool repaint = true, bool add_to_stack = false) override;
263  // Docu in base class
264  void recalculateSnapFactor_() override;
265  // Docu in base class
266  void updateScrollbars_() override;
267  // Docu in base class
268  void intensityModeChange_() override;
269 
271  std::vector<DrawModes> draw_modes_;
273  std::vector<Qt::PenStyle> peak_penstyle_;
274 
279 
282 
290  std::vector<std::pair<double, double> > aligned_peaks_mz_delta_;
292  std::vector<std::pair<Size, Size> > aligned_peaks_indices_;
301 
303  PeakIndex findPeakAtPosition_(QPoint);
304 
306  void addUserLabelAnnotation_(const QPoint& screen_position);
308  void addLabelAnnotation_(const QPoint& screen_position, QString label_text);
310  void addUserPeakAnnotation_(PeakIndex near_peak);
311 
313  void ensureAnnotationsWithinDataRange_();
314 
315  QTextDocument text_box_content_;
316 
319  void paintEvent(QPaintEvent* e) override;
320  void mousePressEvent(QMouseEvent* e) override;
321  void mouseReleaseEvent(QMouseEvent* e) override;
322  void mouseMoveEvent(QMouseEvent* e) override;
323  void keyPressEvent(QKeyEvent* e) override;
324  void contextMenuEvent(QContextMenuEvent* e) override;
326 
328  void zoomForward_() override;
330  void zoom_(int x, int y, bool zoom_in) override;
331  //docu in base class
332  void translateLeft_(Qt::KeyboardModifiers m) override;
333  //docu in base class
334  void translateRight_(Qt::KeyboardModifiers m) override;
335  //docu in base class
336  void paintGridLines_(QPainter& painter) override;
337  };
338 } // namespace OpenMS
339 
OpenMS::Spectrum1DCanvas::ion_ladder_visible_
bool ion_ladder_visible_
whether the ion ladder is displayed on the top right corner in ID view
Definition: Spectrum1DCanvas.h:298
OpenMS::Spectrum1DCanvas::peak_penstyle_
std::vector< Qt::PenStyle > peak_penstyle_
Draw style.
Definition: Spectrum1DCanvas.h:273
OpenMS::Spectrum1DCanvas::moving_annotations_
bool moving_annotations_
Indicates whether annotation items are just being moved on the canvas.
Definition: Spectrum1DCanvas.h:281
OpenMS::Spectrum1DCanvas::draw_modes_
std::vector< DrawModes > draw_modes_
Draw modes (for each spectrum)
Definition: Spectrum1DCanvas.h:271
OpenMS::Spectrum1DCanvas::LabelMode
LabelMode
Label modes (percentage or absolute) of x axis and y axis.
Definition: Spectrum1DCanvas.h:74
OpenMS::Peak2D
A 2-dimensional raw data point or peak.
Definition: Peak2D.h:54
OpenMS::Spectrum1DCanvas::alignment_score_
double alignment_score_
Stores the score of the last alignment.
Definition: Spectrum1DCanvas.h:294
OpenMS::Spectrum1DCanvas::LM_XPERCENT_YABSOLUTE
Definition: Spectrum1DCanvas.h:77
OpenMS::DRange< 2 >
OpenMS::Spectrum1DCanvas
Canvas for visualization of one or several spectra.
Definition: Spectrum1DCanvas.h:67
OpenMS::Size
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
OpenMS::Spectrum1DCanvas::alignment_layer_1_
Size alignment_layer_1_
Layer index of the first alignment layer.
Definition: Spectrum1DCanvas.h:286
OpenMS::Spectrum1DCanvas::DM_PEAKS
draw data as peak
Definition: Spectrum1DCanvas.h:93
QWidget
OpenMS::Spectrum1DCanvas::text_box_content_
QTextDocument text_box_content_
Definition: Spectrum1DCanvas.h:315
OpenMS::Spectrum1DCanvas::measurement_start_point_
QPoint measurement_start_point_
start point of "ruler" for measure mode
Definition: Spectrum1DCanvas.h:276
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
OpenMS::PeakIndex
Index of a peak or feature.
Definition: PeakIndex.h:50
OpenMS::Spectrum1DCanvas::show_alignment_
bool show_alignment_
Indicates whether an alignment is currently visualized.
Definition: Spectrum1DCanvas.h:284
OpenMS::Spectrum1DCanvas::LM_XABSOLUTE_YABSOLUTE
Definition: Spectrum1DCanvas.h:76
OpenMS::Annotation1DItem
An abstract class acting as an interface for the different 1D annotation items.
Definition: Annotation1DItem.h:59
OpenMS::Spectrum1DCanvas::alignment_layer_2_
Size alignment_layer_2_
Layer index of the second alignment layer.
Definition: Spectrum1DCanvas.h:288
OpenMS::Spectrum1DCanvas::aligned_peaks_mz_delta_
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: Spectrum1DCanvas.h:290
OpenMS::Spectrum1DCanvas::DrawModes
DrawModes
Enumerate all available paint styles.
Definition: Spectrum1DCanvas.h:91
OpenMS::Spectrum1DCanvas::aligned_peaks_indices_
std::vector< std::pair< Size, Size > > aligned_peaks_indices_
Stores the peak indices of pairs of aligned peaks in both spectra.
Definition: Spectrum1DCanvas.h:292
OpenMS::Param
Management and storage of parameters / INI files.
Definition: Param.h:73
OpenMS::SpectrumCanvas
Base class for visualization canvas classes.
Definition: SpectrumCanvas.h:98
OpenMS::Spectrum1DCanvas::LM_XABSOLUTE_YPERCENT
Definition: Spectrum1DCanvas.h:78
OpenMS::Spectrum1DCanvas::draw_interesting_MZs_
bool draw_interesting_MZs_
annotate interesting peaks with m/z's
Definition: Spectrum1DCanvas.h:300
OpenMS::Spectrum1DCanvas::is_swapped_
bool is_swapped_
is this widget showing data with swapped m/z and RT axis? (for drawCoordinates_ only)
Definition: Spectrum1DCanvas.h:296
SpectrumCanvas.h
OpenMS::Spectrum1DCanvas::mirror_mode_
bool mirror_mode_
Indicates whether this widget is currently in mirror mode.
Definition: Spectrum1DCanvas.h:278