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 
92  bool addChromLayer(ExperimentSharedPtrType chrom_exp_sptr,
93  ODExperimentSharedPtrType ondisc_sptr,
94  const String& filename,
95  const String& caption,
96  ExperimentSharedPtrType exp_sptr,
97  const int index,
98  const bool multiple_select);
99 
100 
103  {
105  DM_CONNECTEDLINES
106  };
107 
109  DrawModes getDrawMode() const;
110 
112  void setDrawMode(DrawModes mode);
113 
114  // Docu in base class
115  void showCurrentLayerPreferences() override;
116 
117  // Docu in base class
118  void saveCurrentLayer(bool visible) override;
119 
121  bool flippedLayersExist();
122 
124  void flipLayer(Size index);
125 
127  bool mirrorModeActive();
128 
130  void setMirrorModeActive(bool b);
131 
133  void dataToWidget(const PeakType& peak, QPoint& point, bool flipped = false, bool percentage = true);
134 
136  void dataToWidget(double x, double y, QPoint& point, bool flipped = false, bool percentage = false);
137 
139  PointType widgetToData(const QPoint& pos, bool percentage = false);
140 
142  PointType widgetToData(double x, double y, bool percentage = false);
143 
145  void setTextBox(const QString& html);
146 
148 
150  Annotation1DItem* addPeakAnnotation(const PeakIndex& peak_index, const QString& text, const QColor& color);
151 
153  void drawAnnotations(Size layer_index, QPainter& painter);
154 
156 
158  void performAlignment(Size layer_index_1, Size layer_index_2, const Param& param);
159 
161  void resetAlignment();
162 
164  void drawAlignment(QPainter& painter);
165 
167  Size getAlignmentSize();
168 
170  double getAlignmentScore();
171 
173  std::vector<std::pair<Size, Size> > getAlignedPeaksIndices();
174 
176  void activateSpectrum(Size index, bool repaint = true);
177 
179  void setSwappedAxis(bool swapped);
180 
182  void setCurrentLayerPeakPenStyle(Qt::PenStyle ps);
183 
185  void paint(QPainter* paint_device, QPaintEvent* e);
186 
188  void setDrawInterestingMZs(bool enable);
189 
191  bool isDrawInterestingMZs() const;
192 
193  // Show/hide ion ladder on top right corner (Identification view)
194  void setIonLadderVisible(bool show);
195 
196  // Returns true if ion ladder is visible
197  bool isIonLadderVisible() const;
198 
199 signals:
201  void showCurrentPeaksAs2D();
202 
204  void showCurrentPeaksAs3D();
205 
207  void showCurrentPeaksAsIonMobility();
208 
210  void showCurrentPeaksAsDIA();
211 
212 public slots:
213  // Docu in base class
214  void activateLayer(Size layer_index) override;
215  // Docu in base class
216  void removeLayer(Size layer_index) override;
217  // Docu in base class
218  void updateLayer(Size i) override;
219 
226  void setVisibleArea(DRange<2> range); //Do not change this to AreaType the signal needs QT needs the exact type...
227  // Docu in base class
228  void horizontalScrollBarChange(int value) override;
229 
230 protected slots:
231 
233  void currentLayerParamtersChanged_();
234 
235 protected:
236  // Docu in base class
237  bool finishAdding_() override;
238 
240  void drawCoordinates_(QPainter& painter, const PeakIndex& peak);
242  void drawDeltas_(QPainter& painter, const PeakIndex& start, const PeakIndex& end);
243 
245  void drawMZAtInterestingPeaks_(Size layer_index, QPainter& painter);
246 
252  void changeVisibleArea_(double lo, double hi, bool repaint = true, bool add_to_stack = false);
253 
255  void drawHighlightedPeak_(Size layer_index, const PeakIndex& peak, QPainter& painter, bool draw_elongation = false);
256 
258  void drawDashedLine_(const QPoint& from, const QPoint& to, QPainter& painter);
259 
261  void updatePercentageFactor_(Size layer_index);
262 
273  void changeVisibleArea_(const AreaType& new_area, bool repaint = true, bool add_to_stack = false) override;
274  // Docu in base class
275  void recalculateSnapFactor_() override;
276  // Docu in base class
277  void updateScrollbars_() override;
278  // Docu in base class
279  void intensityModeChange_() override;
280 
282  std::vector<DrawModes> draw_modes_;
284  std::vector<Qt::PenStyle> peak_penstyle_;
285 
290 
293 
301  std::vector<std::pair<double, double> > aligned_peaks_mz_delta_;
303  std::vector<std::pair<Size, Size> > aligned_peaks_indices_;
312 
314  PeakIndex findPeakAtPosition_(QPoint);
315 
317  void addUserLabelAnnotation_(const QPoint& screen_position);
319  void addLabelAnnotation_(const QPoint& screen_position, QString label_text);
321  void addUserPeakAnnotation_(PeakIndex near_peak);
322 
324  void ensureAnnotationsWithinDataRange_();
325 
326  QTextDocument text_box_content_;
327 
330  void paintEvent(QPaintEvent* e) override;
331  void mousePressEvent(QMouseEvent* e) override;
332  void mouseReleaseEvent(QMouseEvent* e) override;
333  void mouseMoveEvent(QMouseEvent* e) override;
334  void keyPressEvent(QKeyEvent* e) override;
335  void contextMenuEvent(QContextMenuEvent* e) override;
337 
339  void zoomForward_() override;
341  void zoom_(int x, int y, bool zoom_in) override;
342  //docu in base class
343  void translateLeft_(Qt::KeyboardModifiers m) override;
344  //docu in base class
345  void translateRight_(Qt::KeyboardModifiers m) override;
346  //docu in base class
347  void paintGridLines_(QPainter& painter) override;
348  };
349 } // namespace OpenMS
350 
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:309
OpenMS::Spectrum1DCanvas::peak_penstyle_
std::vector< Qt::PenStyle > peak_penstyle_
Draw style.
Definition: Spectrum1DCanvas.h:284
OpenMS::Spectrum1DCanvas::moving_annotations_
bool moving_annotations_
Indicates whether annotation items are just being moved on the canvas.
Definition: Spectrum1DCanvas.h:292
OpenMS::Spectrum1DCanvas::draw_modes_
std::vector< DrawModes > draw_modes_
Draw modes (for each spectrum)
Definition: Spectrum1DCanvas.h:282
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:305
OpenMS::String
A more convenient string class.
Definition: String.h:59
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:297
OpenMS::Spectrum1DCanvas::DM_PEAKS
draw data as peak
Definition: Spectrum1DCanvas.h:104
QWidget
OpenMS::Spectrum1DCanvas::text_box_content_
QTextDocument text_box_content_
Definition: Spectrum1DCanvas.h:326
OpenMS::Spectrum1DCanvas::measurement_start_point_
QPoint measurement_start_point_
start point of "ruler" for measure mode
Definition: Spectrum1DCanvas.h:287
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:295
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:299
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:301
OpenMS::Spectrum1DCanvas::DrawModes
DrawModes
Enumerate all available paint styles.
Definition: Spectrum1DCanvas.h:102
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:303
OpenMS::Param
Management and storage of parameters / INI files.
Definition: Param.h:73
OpenMS::SpectrumCanvas
Base class for visualization canvas classes.
Definition: SpectrumCanvas.h:133
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:311
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:307
SpectrumCanvas.h
OpenMS::Spectrum1DCanvas::mirror_mode_
bool mirror_mode_
Indicates whether this widget is currently in mirror mode.
Definition: Spectrum1DCanvas.h:289