OpenMS
Plot2DCanvas.h
Go to the documentation of this file.
1 // Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Timo Sachsenberg$
6 // $Authors: Marc Sturm $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
11 // OpenMS_GUI config
12 #include <OpenMS/VISUAL/OpenMS_GUIConfig.h>
13 
14 // OpenMS
18 
19 // QT
20 class QPainter;
21 class QMouseEvent;
22 class QAction;
23 class QMenu;
24 
25 namespace OpenMS
26 {
44  class OPENMS_GUI_DLLAPI Plot2DCanvas :
45  public PlotCanvas
46  {
47  Q_OBJECT
48 
49 public:
51  Plot2DCanvas() = delete;
52 
54  Plot2DCanvas(const Param& preferences, QWidget* parent = nullptr);
55 
57  ~Plot2DCanvas() override;
58 
59  // Docu in base class
60  void showCurrentLayerPreferences() override;
61 
64 
67 
69  void mergeIntoLayer(Size i, std::vector<PeptideIdentification>& peptides);
70 
73 
74 signals:
76  void showProjections(const LayerDataBase* source_layer);
80  void showSpectrumAsNew1D(int index);
81  void showChromatogramsAsNew1D(std::vector<int, std::allocator<int> > indices);
86 
87 
88 public slots:
89  // Docu in base class
90  void activateLayer(Size layer_index) override;
91  // Docu in base class
92  void removeLayer(Size layer_index) override;
93  //docu in base class
94  void updateLayer(Size i) override;
95  // Docu in base class
96  void horizontalScrollBarChange(int value) override;
97  // Docu in base class
98  void verticalScrollBarChange(int value) override;
99 
102 
103 protected slots:
104 
107 
108 protected:
109  // Docu in base class
110  bool finishAdding_() override;
111 
113  bool collectFragmentScansInArea_(const RangeType& range, QAction* a, QMenu* msn_scans, QMenu* msn_meta);
114 
116  void drawCoordinates_(QPainter& painter, const PeakIndex& peak);
118  void drawDeltas_(QPainter& painter, const PeakIndex& start, const PeakIndex& end);
119 
122  void mousePressEvent(QMouseEvent* e) override;
123  void mouseReleaseEvent(QMouseEvent* e) override;
124  void mouseMoveEvent(QMouseEvent* e) override;
125  void paintEvent(QPaintEvent* e) override;
126  void contextMenuEvent(QContextMenuEvent* e) override;
127  void keyPressEvent(QKeyEvent* e) override;
128  void keyReleaseEvent(QKeyEvent* e) override;
129  void mouseDoubleClickEvent(QMouseEvent* e) override;
131 
132  // Docu in base class
133  void updateScrollbars_() override;
134 
135  // Docu in base class
136  void intensityModeChange_() override;
137  // Docu in base class
138  void recalculateSnapFactor_() override;
139 
145  Int precalculatedColorIndex_(float val, const MultiGradient& gradient, double snap_factor)
146  {
147  float gradientPos = val;
148  switch (intensity_mode_)
149  {
150  case IM_NONE:
151  gradientPos = val;
152  break;
153 
154  case IM_PERCENTAGE:
155  gradientPos = val * percentage_factor_;
156  break;
157 
158  case IM_SNAP:
159  gradientPos = val * snap_factor;
160  break;
161 
162  case IM_LOG:
163  gradientPos = std::log(val + 1);
164  break;
165  }
166  return gradient.precalculatedColorIndex(gradientPos);
167  }
168 
174  QColor heightColor_(float val, const MultiGradient& gradient, double snap_factor)
175  {
176  return gradient.precalculatedColorByIndex(precalculatedColorIndex_(val, gradient, snap_factor));
177  }
178 
190  double adaptPenScaling_(double ratio_data2pixel, double& pen_size) const;
191 
194 
196  void highlightPeak_(QPainter& p, const PeakIndex& peak);
197 
199  PeakIndex findNearestPeak_(const QPoint& pos);
200 
202  void paintIcon_(const QPoint& pos, const QRgb& color, const String& icon, Size s, QPainter& p) const;
203 
205  void translateVisibleArea_(double x_axis_rel, double y_axis_rel);
206 
215  QPoint dataToWidget_(double x, double y) const
216  {
217  QPoint point;
218  const auto& xy = visible_area_.getAreaXY();
219  point.setX(int((x - xy.minX()) / xy.width() * width()));
220  point.setY(int((xy.maxY() - y) / xy.height() * height()));
221  return point;
222  }
223 
224  QPoint dataToWidget_(const DPosition<2>& xy)
225  {
226  return dataToWidget_(xy.getX(), xy.getY());
227  }
228 
229  //docu in base class
230  void translateLeft_(Qt::KeyboardModifiers m) override;
231  //docu in base class
232  void translateRight_(Qt::KeyboardModifiers m) override;
233  //docu in base class
234  void translateForward_() override;
235  //docu in base class
236  void translateBackward_() override;
237 
239  void finishContextMenu_(QMenu* context_menu, QMenu* settings_menu);
240 
241  friend class Painter2DBase;
242  friend class Painter2DChrom;
243  friend class Painter2DConsensus;
244  friend class Painter2DIdent;
245  friend class Painter2DFeature;
246  friend class Painter2DIonMobility;
247  friend class Painter2DPeak;
248 
253 
256 
257  double pen_size_min_;
258  double pen_size_max_;
260  };
261 }
262 
CoordinateType getY() const
Name accessor for the second dimension. Only for DPosition<2>, for visualization.
Definition: DPosition.h:149
CoordinateType getX() const
Name accessor for the first dimension. Only for DPosition<2>, for visualization.
Definition: DPosition.h:142
Class that stores the data for one layer.
Definition: LayerDataBase.h:169
The representation of a 1D spectrum.
Definition: MSSpectrum.h:44
A gradient of multiple colors and arbitrary distances between colors.
Definition: MultiGradient.h:42
Int precalculatedColorIndex(double position) const
index of color in precalculated table by position in gradient
Definition: MultiGradient.h:110
QColor precalculatedColorByIndex(Int index) const
precalculated color by its index in the table
Definition: MultiGradient.h:121
A base class for painting all items from a data layer (as supported by class derived from here) onto ...
Definition: Painter2DBase.h:42
Painter2D for chromatograms.
Definition: Painter2DBase.h:131
Painter2D for ConsensusFeatures.
Definition: Painter2DBase.h:191
Painter2D for Features.
Definition: Painter2DBase.h:163
Painter2D for Identifications.
Definition: Painter2DBase.h:236
Painter2D for ion mobilograms.
Definition: Painter2DBase.h:147
Painter2D for spectra.
Definition: Painter2DBase.h:94
Management and storage of parameters / INI files.
Definition: Param.h:44
Canvas for 2D-visualization of peak map, feature map and consensus map data.
Definition: Plot2DCanvas.h:46
void translateForward_() override
Translation bound to the 'Up' key.
Plot2DCanvas()=delete
Default C'tor hidden.
double pen_size_max_
maximum number of pixels for one data point
Definition: Plot2DCanvas.h:258
void drawCoordinates_(QPainter &painter, const PeakIndex &peak)
Draws the coordinates (or coordinate deltas) to the widget's upper left corner.
void mergeIntoLayer(Size i, const ConsensusMapSharedPtrType &map)
Merges the consensus features in map into the features layer i.
void showSpectrumAsNew1D(int index)
Requests to display the spectrum with index index in 1D.
PeakIndex selected_peak_
the nearest peak/feature to the mouse cursor
Definition: Plot2DCanvas.h:250
double canvas_coverage_min_
minimum coverage of the canvas required; if lower, points are upscaled in size
Definition: Plot2DCanvas.h:259
bool finishAdding_() override
Method that is called when a new layer has been added.
void removeLayer(Size layer_index) override
void mousePressEvent(QMouseEvent *e) override
void horizontalScrollBarChange(int value) override
void toggleProjections()
Signal emitted when the projections are to be shown/hidden (e.g. via context menu)
void recalculateCurrentLayerDotGradient()
recalculates the dot gradient of the active layer
Plot2DCanvas(const Param &preferences, QWidget *parent=nullptr)
Constructor.
void mouseMoveEvent(QMouseEvent *e) override
void highlightPeak_(QPainter &p, const PeakIndex &peak)
Highlights a single peak and prints coordinates to screen.
void finishContextMenu_(QMenu *context_menu, QMenu *settings_menu)
Finishes context menu after customization to peaks, features or consensus features.
void mouseReleaseEvent(QMouseEvent *e) override
void keyReleaseEvent(QKeyEvent *e) override
void keyPressEvent(QKeyEvent *e) override
void showCurrentPeaksAsIonMobility(const MSSpectrum &spec)
Requests to display this spectrum (=frame) in ion mobility plot.
void updateScrollbars_() override
Updates the scroll bars.
void recalculateSnapFactor_() override
Recalculates the intensity scaling factor for 'snap to maximum intensity mode'.
void showCurrentLayerPreferences() override
Shows the preferences dialog of the active layer.
void translateLeft_(Qt::KeyboardModifiers m) override
Translation bound to the 'Left' key.
void currentLayerParametersChanged_()
Reacts on changed layer parameters.
void drawDeltas_(QPainter &painter, const PeakIndex &start, const PeakIndex &end)
Draws the coordinates (or coordinate deltas) to the widget's upper left corner.
void recalculateDotGradient_(Size layer)
Recalculates the dot gradient of a layer.
void mergeIntoLayer(Size i, const FeatureMapSharedPtrType &map)
Merges the features in map into the features layer i.
void showProjections(const LayerDataBase *source_layer)
Requests to show projections for the source_layer. Emitted after calling pickProjectionLayer().
void paintIcon_(const QPoint &pos, const QRgb &color, const String &icon, Size s, QPainter &p) const
Paints a peak icon for feature and consensus feature peaks.
void intensityModeChange_() override
This method is called whenever the intensity mode changes. Reimplement if you need to react on such c...
bool collectFragmentScansInArea_(const RangeType &range, QAction *a, QMenu *msn_scans, QMenu *msn_meta)
Collects fragment ion scans in the indicated RT/mz area and adds them to the indicated action.
Int precalculatedColorIndex_(float val, const MultiGradient &gradient, double snap_factor)
Returns the position on color gradient associated with given intensity.
Definition: Plot2DCanvas.h:145
double adaptPenScaling_(double ratio_data2pixel, double &pen_size) const
For a certain dimension: computes the size a data point would need, such that the image reaches a cer...
void activateLayer(Size layer_index) override
void translateRight_(Qt::KeyboardModifiers m) override
Translation bound to the 'Right' key.
void showChromatogramsAsNew1D(std::vector< int, std::allocator< int > > indices)
void updateLayer(Size i) override
void contextMenuEvent(QContextMenuEvent *e) override
double pen_size_min_
minimum number of pixels for one data point
Definition: Plot2DCanvas.h:257
~Plot2DCanvas() override
Destructor.
void mouseDoubleClickEvent(QMouseEvent *e) override
void verticalScrollBarChange(int value) override
void showCurrentPeaksAs3D()
Requests to display all spectra in 3D plot.
PeakIndex measurement_start_
start peak/feature of measuring mode
Definition: Plot2DCanvas.h:252
MultiGradient linear_gradient_
stores the linear color gradient for non-log modes
Definition: Plot2DCanvas.h:255
void pickProjectionLayer()
Picks an appropriate layer for projection and emits the signal showProjections(LayerDataBase*).
PeakIndex findNearestPeak_(const QPoint &pos)
Returns the nearest peak to position pos.
QPoint dataToWidget_(const DPosition< 2 > &xy)
Definition: Plot2DCanvas.h:224
void translateBackward_() override
Translation bound to the 'Down' key.
void translateVisibleArea_(double x_axis_rel, double y_axis_rel)
Translates the visible area by a given offset specified in fractions of current visible area.
QPoint dataToWidget_(double x, double y) const
Convert chart to widget coordinates.
Definition: Plot2DCanvas.h:215
QColor heightColor_(float val, const MultiGradient &gradient, double snap_factor)
Returns the color associated with val for the gradient gradient.
Definition: Plot2DCanvas.h:174
void paintEvent(QPaintEvent *e) override
void mergeIntoLayer(Size i, std::vector< PeptideIdentification > &peptides)
Merges the peptide identifications in peptides into the peptide layer i.
Base class for visualization canvas classes.
Definition: PlotCanvas.h:120
LayerDataBase::ConsensusMapSharedPtrType ConsensusMapSharedPtrType
Main managed data type (consensus features)
Definition: PlotCanvas.h:140
LayerDataBase::FeatureMapSharedPtrType FeatureMapSharedPtrType
Main managed data type (features)
Definition: PlotCanvas.h:136
A more convenient string class.
Definition: String.h:34
int Int
Signed integer type.
Definition: Types.h:72
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:97
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
Index of a peak or feature.
Definition: PeakIndex.h:25