OpenMS
Plot2DWidget.h
Go to the documentation of this file.
1 // Copyright (c) 2002-2023, The OpenMS Team -- 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
17 
18 class QGroupBox;
19 class QLabel;
20 class QCheckBox;
21 
22 namespace OpenMS
23 {
24  class Plot1DWidget;
25 
37  class OPENMS_GUI_DLLAPI Plot2DWidget :
38  public PlotWidget
39  {
40  Q_OBJECT
41 public:
44 
46  Plot2DWidget(const Param & preferences, QWidget * parent = nullptr);
48  ~Plot2DWidget() override = default;
49 
50  // docu in base class
51  Plot2DCanvas* canvas() const override
52  {
53  return static_cast<Plot2DCanvas*>(canvas_);
54  }
55 
60 
62  bool projectionsVisible() const;
63 
67  void setMapper(const DimMapper<2>& mapper) override
68  {
69  canvas_->setMapper(mapper); // update canvas
70  // ... and projections: the projected Dim becomes intensity
71  projection_onto_X_->setMapper(DimMapper<2>({mapper.getDim(DIM::X).getUnit(), DIM_UNIT::INT}));
72  projection_onto_Y_->setMapper(DimMapper<2>({DIM_UNIT::INT, mapper.getDim(DIM::Y).getUnit()}));
73 
74  // decide on default draw mode, depending on main axis unit (e.g. m/z or RT)
75  auto set_style = [&](const DIM_UNIT main_unit_1d, Plot1DCanvas* canvas) {
76  switch (main_unit_1d)
77  { // this may not be optimal for every unit. Feel free to change behavior.
78  case DIM_UNIT::MZ:
79  // to show isotope distributions as sticks
80  canvas->setDrawMode(Plot1DCanvas::DM_PEAKS);
81  canvas->setIntensityMode(PlotCanvas::IM_PERCENTAGE);
82  break;
83  // all other units
84  default:
85  canvas->setDrawMode(Plot1DCanvas::DM_CONNECTEDLINES);
86  canvas->setIntensityMode(PlotCanvas::IM_SNAP);
87  break;
88  }
89  };
90  set_style(mapper.getDim(DIM::X).getUnit(), projection_onto_Y_->canvas());
91  set_style(mapper.getDim(DIM::Y).getUnit(), projection_onto_X_->canvas());
92  }
93 
94 public slots:
95  // Docu in base class
96  void recalculateAxes_() override;
99  // Docu in base class
100  void showGoToDialog() override;
101 
102 signals:
110  void showSpectrumAsNew1D(int index);
111  void showChromatogramsAsNew1D(std::vector<int, std::allocator<int> > indices);
114 
115 protected:
117  void projectionInfo_(int peaks, double intensity, double max);
118 
124  QGroupBox * projection_box_;
128  QLabel * projection_sum_;
130  QLabel * projection_max_;
132  QCheckBox * projections_auto_;
135 
136 private slots:
138  void showProjections_(const LayerDataBase* source_layer);
141  };
142 }
143 
A D-dimensional half-open interval.
Definition: DRange.h:36
DIM_UNIT getUnit() const
The unit of the dimension.
Definition: DimMapper.h:129
const DimBase & getDim(DIM d) const
obtain unit/name for X/Y/Z dimension.
Definition: DimMapper.h:758
Class that stores the data for one layer.
Definition: LayerDataBase.h:169
Management and storage of parameters / INI files.
Definition: Param.h:44
Canvas for visualization of one or several spectra.
Definition: Plot1DCanvas.h:295
@ DM_PEAKS
draw data as peak
Definition: Plot1DCanvas.h:358
@ DM_CONNECTEDLINES
draw as connected lines
Definition: Plot1DCanvas.h:359
Widget for visualization of several spectra.
Definition: Plot1DWidget.h:41
Canvas for 2D-visualization of peak map, feature map and consensus map data.
Definition: Plot2DCanvas.h:46
Widget for 2D-visualization of peak map and feature map data.
Definition: Plot2DWidget.h:39
void recalculateAxes_() override
Plot2DWidget(const Param &preferences, QWidget *parent=nullptr)
Default constructor.
const Plot1DWidget * getProjectionOntoX() const
const reference to the horizontal projection
void showSpectrumAsNew1D(int index)
Requests to display the spectrum with index index in 1D.
~Plot2DWidget() override=default
Destructor.
bool projectionsVisible() const
Returns if one of the projections is visible (or both are visible)
void toggleProjections()
Shows/hides the projections.
void projectionInfo_(int peaks, double intensity, double max)
shows projections information
void visibleAreaChanged(DRange< 2 > area)
Signal emitted whenever the visible area changes.
QLabel * projection_sum_
Intensity sum of the projection.
Definition: Plot2DWidget.h:128
QTimer * projections_timer_
Timer that triggers auto-update of projections.
Definition: Plot2DWidget.h:134
void setMapper(const DimMapper< 2 > &mapper) override
Definition: Plot2DWidget.h:67
QCheckBox * projections_auto_
Checkbox that indicates that projections should be automatically updated (with a slight delay)
Definition: Plot2DWidget.h:132
void showProjections_(const LayerDataBase *source_layer)
extracts the projections from the source_layer and displays them
QLabel * projection_max_
Intensity maximum of the projection.
Definition: Plot2DWidget.h:130
Plot1DWidget * projection_onto_Y_
Horizontal projection widget.
Definition: Plot2DWidget.h:122
Plot2DCanvas * canvas() const override
Returns a pointer to canvas object.
Definition: Plot2DWidget.h:51
void showChromatogramsAsNew1D(std::vector< int, std::allocator< int > > indices)
Plot1DWidget * projection_onto_X_
Vertical projection widget.
Definition: Plot2DWidget.h:120
void showCurrentPeaksAs3D()
Requests to display all spectra as 1D.
QGroupBox * projection_box_
Group box that shows information about the projections.
Definition: Plot2DWidget.h:124
void showGoToDialog() override
const Plot1DWidget * getProjectionOntoY() const
const reference to the vertical projection
QLabel * projection_peaks_
Number of peaks of the projection.
Definition: Plot2DWidget.h:126
LayerDataBase::ExperimentSharedPtrType ExperimentSharedPtrType
Main managed data type (experiment)
Definition: Plot2DWidget.h:43
void autoUpdateProjections_()
slot that monitors the visible area changes and triggers the update of projections
@ IM_SNAP
Shows the maximum displayed intensity (across all layers) as if it was the overall maximum intensity.
Definition: PlotCanvas.h:180
@ IM_PERCENTAGE
Shows intensities normalized by each layer's maximum: f(x)=x/max(x)*100.
Definition: PlotCanvas.h:179
Base class for spectrum widgets.
Definition: PlotWidget.h:57
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:22
DIM_UNIT
Definition: CommonEnums.h:20
@ INT
intensity
boost::shared_ptr< ExperimentType > ExperimentSharedPtrType
SharedPtr on MSExperiment.
Definition: LayerDataBase.h:126