OpenMS  2.4.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-2018.
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  Spectrum1DCanvas(const Param & preferences, QWidget * parent = nullptr);
85  ~Spectrum1DCanvas() override;
86 
88  enum DrawModes
89  {
91  DM_CONNECTEDLINES
92  };
93 
95  DrawModes getDrawMode() const;
96 
98  void setDrawMode(DrawModes mode);
99 
100  // Docu in base class
101  void showCurrentLayerPreferences() override;
102 
103  // Docu in base class
104  void saveCurrentLayer(bool visible) override;
105 
107  bool flippedLayersExist();
108 
110  void flipLayer(Size index);
111 
113  bool mirrorModeActive();
114 
116  void setMirrorModeActive(bool b);
117 
119  void dataToWidget(const PeakType & peak, QPoint & point, bool flipped = false, bool percentage = true);
120 
122  void dataToWidget(double x, double y, QPoint & point, bool flipped = false, bool percentage = false);
123 
125  PointType widgetToData(const QPoint & pos, bool percentage = false);
126 
128  PointType widgetToData(double x, double y, bool percentage = false);
129 
131  void setTextBox(const QString& html);
132 
134 
136  Annotation1DItem * addPeakAnnotation(const PeakIndex& peak_index, const QString& text, const QColor& color);
137 
139  void drawAnnotations(Size layer_index, QPainter & painter);
140 
142 
144  void performAlignment(Size layer_index_1, Size layer_index_2, const Param & param);
145 
147  void resetAlignment();
148 
150  void drawAlignment(QPainter & painter);
151 
153  Size getAlignmentSize();
154 
156  double getAlignmentScore();
157 
159  std::vector<std::pair<Size, Size> > getAlignedPeaksIndices();
160 
162  void activateSpectrum(Size index, bool repaint = true);
163 
165  void setSwappedAxis(bool swapped);
166 
168  void setCurrentLayerPeakPenStyle(Qt::PenStyle ps);
169 
171  void paint(QPainter * paint_device, QPaintEvent * e);
172 
173  // Show/hide ion ladder on top right corner (Identification view)
174  void setIonLadderVisible(bool show);
175 
176  // Returns true if ion ladder is visible
177  bool isIonLadderVisible() const;
178 
179 signals:
181  void showCurrentPeaksAs2D();
182 
184  void showCurrentPeaksAs3D();
185 
187  void showCurrentPeaksAsIonMobility();
188 
190  void showCurrentPeaksAsDIA();
191 
192 public slots:
193  // Docu in base class
194  void activateLayer(Size layer_index) override;
195  // Docu in base class
196  void removeLayer(Size layer_index) override;
197  // Docu in base class
198  void updateLayer(Size i) override;
199 
206  void setVisibleArea(DRange<2> range); //Do not change this to AreaType the signal needs QT needs the exact type...
207  // Docu in base class
208  void horizontalScrollBarChange(int value) override;
209 
210 protected slots:
211 
213  void currentLayerParamtersChanged_();
214 
215 protected:
216  // Docu in base class
217  bool finishAdding_() override;
218 
220  void drawCoordinates_(QPainter & painter, const PeakIndex & peak);
222  void drawDeltas_(QPainter & painter, const PeakIndex & start, const PeakIndex & end);
223 
229  void changeVisibleArea_(double lo, double hi, bool repaint = true, bool add_to_stack = false);
230 
232  void drawHighlightedPeak_(Size layer_index, const PeakIndex & peak, QPainter & painter, bool draw_elongation = false);
233 
235  void drawDashedLine_(const QPoint & from, const QPoint & to, QPainter & painter);
236 
238  void updatePercentageFactor_(Size layer_index);
239 
250  void changeVisibleArea_(const AreaType & new_area, bool repaint = true, bool add_to_stack = false) override;
251  // Docu in base class
252  void recalculateSnapFactor_() override;
253  // Docu in base class
254  void updateScrollbars_() override;
255  // Docu in base class
256  void intensityModeChange_() override;
257 
259  std::vector<DrawModes> draw_modes_;
261  std::vector<Qt::PenStyle> peak_penstyle_;
262 
267 
270 
278  std::vector<std::pair<double, double> > aligned_peaks_mz_delta_;
280  std::vector<std::pair<Size, Size> > aligned_peaks_indices_;
287 
289  PeakIndex findPeakAtPosition_(QPoint);
290 
292  void addUserLabelAnnotation_(const QPoint & screen_position);
294  void addLabelAnnotation_(const QPoint & screen_position, QString label_text);
296  void addUserPeakAnnotation_(PeakIndex near_peak);
297 
299  void ensureAnnotationsWithinDataRange_();
300 
301  QTextDocument text_box_content_;
302 
305  void paintEvent(QPaintEvent * e) override;
306  void mousePressEvent(QMouseEvent * e) override;
307  void mouseReleaseEvent(QMouseEvent * e) override;
308  void mouseMoveEvent(QMouseEvent * e) override;
309  void keyPressEvent(QKeyEvent * e) override;
310  void contextMenuEvent(QContextMenuEvent * e) override;
312 
314  void zoomForward_() override;
316  void zoom_(int x, int y, bool zoom_in) override;
317  //docu in base class
318  void translateLeft_(Qt::KeyboardModifiers m) override;
319  //docu in base class
320  void translateRight_(Qt::KeyboardModifiers m) override;
321  //docu in base class
322  void paintGridLines_(QPainter & painter) override;
323  };
324 } // namespace OpenMS
325 
An abstract class acting as an interface for the different 1D annotation items.
Definition: Annotation1DItem.h:59
bool moving_annotations_
Indicates whether annotation items are just being moved on the canvas.
Definition: Spectrum1DCanvas.h:269
QTextDocument text_box_content_
Definition: Spectrum1DCanvas.h:301
std::vector< DrawModes > draw_modes_
Draw modes (for each spectrum)
Definition: Spectrum1DCanvas.h:259
Size alignment_layer_2_
Layer index of the second alignment layer.
Definition: Spectrum1DCanvas.h:276
LabelMode
Label modes (percentage or absolute) of x axis and y axis.
Definition: Spectrum1DCanvas.h:74
DrawModes
Enumerate all available paint styles.
Definition: Spectrum1DCanvas.h:88
A 2-dimensional raw data point or peak.
Definition: Peak2D.h:54
draw data as peak
Definition: Spectrum1DCanvas.h:90
Definition: Spectrum1DCanvas.h:76
Base class for visualization canvas classes.
Definition: SpectrumCanvas.h:100
std::vector< Qt::PenStyle > peak_penstyle_
Draw style.
Definition: Spectrum1DCanvas.h:261
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
bool is_swapped_
is this widget showing data with swapped m/z and RT axis? (for drawCoordinates_ only) ...
Definition: Spectrum1DCanvas.h:284
bool show_alignment_
Indicates whether an alignment is currently visualized.
Definition: Spectrum1DCanvas.h:272
Size alignment_layer_1_
Layer index of the first alignment layer.
Definition: Spectrum1DCanvas.h:274
bool mirror_mode_
Indicates whether this widget is currently in mirror mode.
Definition: Spectrum1DCanvas.h:266
Canvas for visualization of one or several spectra.
Definition: Spectrum1DCanvas.h:67
Management and storage of parameters / INI files.
Definition: Param.h:74
double alignment_score_
Stores the score of the last alignment.
Definition: Spectrum1DCanvas.h:282
Definition: Spectrum1DCanvas.h:78
QPoint measurement_start_point_
start point of "ruler" for measure mode
Definition: Spectrum1DCanvas.h:264
bool ion_ladder_visible_
whether the ion ladder is displayed on the top right corner in ID view
Definition: Spectrum1DCanvas.h:286
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
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:278
std::vector< std::pair< Size, Size > > aligned_peaks_indices_
Stores the peak indices of pairs of aligned peaks in both spectra.
Definition: Spectrum1DCanvas.h:280
Definition: Spectrum1DCanvas.h:77
Index of a peak or feature.
Definition: PeakIndex.h:50