libpappsomspp
Library for mass spectrometry
baseplotwidget.h
Go to the documentation of this file.
1 /* This code comes right from the msXpertSuite software project.
2  *
3  * msXpertSuite - mass spectrometry software suite
4  * -----------------------------------------------
5  * Copyright(C) 2009,...,2018 Filippo Rusconi
6  *
7  * http://www.msxpertsuite.org
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  *
22  * END software license
23  */
24 
25 
26 #pragma once
27 
28 /////////////////////// StdLib includes
29 #include <memory>
30 
31 
32 /////////////////////// Qt includes
33 #include <QObject>
34 #include <QString>
35 #include <QWidget>
36 #include <QBrush>
37 #include <QColor>
38 #include <QVector>
39 
40 
41 /////////////////////// QCustomPlot
42 #include <qcustomplot.h>
43 
44 
45 /////////////////////// Local includes
46 #include "../../exportinmportconfig.h"
47 #include "../../types.h"
48 #include "../../processing/combiners/selectionpolygon.h"
49 #include "baseplotcontext.h"
50 
51 
52 namespace pappso
53 {
54 
55 enum class RangeType
56 {
57  outermost = 1,
58  innermost = 2,
59 };
60 
61 class BasePlotWidget;
62 
63 typedef std::shared_ptr<BasePlotWidget> BasePlotWidgetSPtr;
64 typedef std::shared_ptr<const BasePlotWidget> BasePlotWidgetCstSPtr;
65 
66 class PMSPP_LIB_DECL BasePlotWidget : public QCustomPlot
67 {
68  Q_OBJECT
69 
70  public:
71  explicit BasePlotWidget(QWidget *parent);
72  explicit BasePlotWidget(QWidget *parent,
73  const QString &x_axis_label,
74  const QString &y_axis_label);
75 
76  virtual ~BasePlotWidget();
77 
78  virtual bool setupWidget();
79 
80  virtual void setPen(const QPen &pen);
81  virtual const QPen &getPen() const;
82 
83  virtual void setPlottingColor(QCPAbstractPlottable *plottable_p,
84  const QColor &new_color);
85  virtual void setPlottingColor(int index, const QColor &new_color);
86 
87  virtual QColor getPlottingColor(QCPAbstractPlottable *plottable_p) const;
88  virtual QColor getPlottingColor(int index = 0) const;
89 
90  virtual void setAxisLabelX(const QString &label);
91  virtual void setAxisLabelY(const QString &label);
92 
93  // AXES RANGE HISTORY-related functions
94  virtual void resetAxesRangeHistory();
95  virtual void updateAxesRangeHistory();
96  virtual void restorePreviousAxesRangeHistory();
97  virtual void restoreAxesRangeHistory(std::size_t index);
98  // AXES RANGE HISTORY-related functions
99 
100 
101  /// KEYBOARD-related EVENTS
102  virtual void keyPressEvent(QKeyEvent *event);
103  virtual void keyReleaseEvent(QKeyEvent *event);
104 
105  virtual void spaceKeyReleaseEvent(QKeyEvent *event);
106 
107  virtual void directionKeyPressEvent(QKeyEvent *event);
108  virtual void directionKeyReleaseEvent(QKeyEvent *event);
109 
110  virtual void mousePseudoButtonKeyPressEvent(QKeyEvent *event);
111  virtual void mousePseudoButtonKeyReleaseEvent(QKeyEvent *event);
112  /// KEYBOARD-related EVENTS
113 
114 
115  /// MOUSE-related EVENTS
116  virtual void mousePressHandler(QMouseEvent *event);
117  virtual void mouseReleaseHandler(QMouseEvent *event);
118  virtual void mouseReleaseHandlerLeftButton();
119  virtual void mouseReleaseHandlerRightButton();
120 
121  virtual void mouseMoveHandler(QMouseEvent *event);
122  virtual void mouseMoveHandlerNotDraggingCursor();
123  virtual void mouseMoveHandlerDraggingCursor();
124  virtual void mouseMoveHandlerLeftButtonDraggingCursor();
125  virtual void mouseMoveHandlerRightButtonDraggingCursor();
126 
127  virtual void axisDoubleClickHandler(QCPAxis *axis,
128  QCPAxis::SelectablePart part,
129  QMouseEvent *event);
130  bool isClickOntoXAxis(const QPointF &mousePoint);
131  bool isClickOntoYAxis(const QPointF &mousePoint);
132  /// MOUSE-related EVENTS
133 
134 
135  /// MOUSE MOVEMENTS mouse/keyboard-triggered
136  int dragDirection();
137  virtual void moveMouseCursorGraphCoordToGlobal(QPointF plot_coordinates);
138  virtual void moveMouseCursorPixelCoordToGlobal(QPointF local_coordinates);
139  virtual void horizontalMoveMouseCursorCountPixels(int pixel_count);
140  virtual QPointF horizontalGetGraphCoordNewPointCountPixels(int pixel_count);
141  virtual void verticalMoveMouseCursorCountPixels(int pixel_count);
142  virtual QPointF verticalGetGraphCoordNewPointCountPixels(int pixel_count);
143  /// MOUSE MOVEMENTS mouse/keyboard-triggered
144 
145 
146  /// RANGE-related functions
147  virtual QCPRange getRangeX(bool &found_range, int index) const;
148  virtual QCPRange getRangeY(bool &found_range, int index) const;
149  QCPRange
150  getRange(Axis axis, RangeType range_type, bool &found_range) const;
151 
152  virtual QCPRange getInnermostRangeX(bool &found_range) const;
153  virtual QCPRange getOutermostRangeX(bool &found_range) const;
154 
155  virtual QCPRange getInnermostRangeY(bool &found_range) const;
156  virtual QCPRange getOutermostRangeY(bool &found_range) const;
157 
158  void yMinMaxOnXAxisCurrentRange(double &min,
159  double &max,
160  QCPAbstractPlottable *plottable_p = nullptr);
161  void yMinMaxOnXAxisCurrentRange(double &min, double &max, int index);
162  /// RANGE-related functions
163 
164 
165  /// PLOTTING / REPLOTTING functions
166  virtual void axisRescale();
167  virtual void axisReframe();
168  virtual void axisZoom();
169  virtual void axisPan();
170 
171  virtual void replotWithAxesRanges(QCPRange xAxisRange,
172  QCPRange yAxisRange,
173  Axis whichAxis);
174  virtual void replotWithAxisRangeX(double lower, double upper);
175  virtual void replotWithAxisRangeY(double lower, double upper);
176  /// PLOTTING / REPLOTTING functions
177 
178 
179  /// PLOT ITEMS : TRACER TEXT ITEMS...
180  virtual void hideAllPlotItems();
181 
182  virtual void showTracers();
183  virtual void hideTracers();
184 
185  virtual void drawXDeltaFeatures();
186  virtual void drawYDeltaFeatures();
187 
188  virtual void calculateDragDeltas();
189 
190  virtual bool isVerticalDisplacementAboveThreshold();
191 
192  virtual void
193  drawSelectionRectangleAndPrepareZoom(bool as_line_segment = false,
194  bool for_integration = false);
195 
196  virtual void updateSelectionRectangle(bool as_line_segment = false,
197  bool for_integration = false);
198 
199  virtual void resetSelectionRectangle();
200  virtual void hideSelectionRectangle(bool reset_values = false);
201  virtual bool isSelectionRectangleVisible();
202  virtual PolygonType whatIsVisibleOfTheSelectionRectangle();
203 
204  /// PLOT ITEMS : TRACER TEXT ITEMS...
205 
206 
207  virtual void setFocus();
208 
209  virtual void redrawPlotBackground(QWidget *focusedPlotWidget);
210 
211  virtual void updateContextXandYAxisRanges();
212 
213  virtual const BasePlotContext &getContext() const;
214 
215  signals:
216 
218 
219  void lastCursorHoveredPointSignal(const QPointF &pointf);
220 
222 
223  void xAxisMeasurementSignal(const BasePlotContext &context, bool with_delta);
224 
225  void keyPressEventSignal(const BasePlotContext &context);
227 
229 
230  void plottableSelectionChangedSignal(QCPAbstractPlottable *plottable_p,
231  bool selected);
232 
234 
236  QCPAbstractPlottable *plottable_p,
237  const BasePlotContext &context);
238 
239  protected:
240  //! Name of the plot widget.
241  QString m_name = "NOT_SET";
242 
243  //! Description of the plot widget.
244  QString m_desc = "NOT_SET";
245 
246  //! The name of the data file from which the mass data were read.
247  QString m_fileName;
248 
249  QString m_axisLabelX;
250  QString m_axisLabelY;
251 
253 
254  int m_leftMousePseudoButtonKey = Qt::Key_Less;
255  int m_rightMousePseudoButtonKey = Qt::Key_Greater;
256 
257  //! Rectangle defining the borders of zoomed-in/out data.
258  // QCPItemRect *mp_zoomRectItem = nullptr;
259 
260  // The four lines that are needed to craft the selection rectangle.
261  QCPItemLine *mp_selectionRectangeLine1 = nullptr;
262  QCPItemLine *mp_selectionRectangeLine2 = nullptr;
263  QCPItemLine *mp_selectionRectangeLine3 = nullptr;
264  QCPItemLine *mp_selectionRectangeLine4 = nullptr;
265 
266  //! Text describing the x-axis delta value during a drag operation.
267  QCPItemText *mp_xDeltaTextItem = nullptr;
268  QCPItemText *mp_yDeltaTextItem = nullptr;
269 
270  //! Tells if the tracers should be visible.
271  bool m_shouldTracersBeVisible = true;
272 
273  //! Horizontal position tracer
274  QCPItemLine *mp_hPosTracerItem = nullptr;
275 
276  //! Vertical position tracer
277  QCPItemLine *mp_vPosTracerItem = nullptr;
278 
279  //! Vertical selection start tracer (typically in green).
280  QCPItemLine *mp_vStartTracerItem = nullptr;
281 
282  //! Vertical selection end tracer (typically in red).
283  QCPItemLine *mp_vEndTracerItem = nullptr /*only vertical*/;
284 
285  //! Index of the last axis range history item.
286  /*!
287 
288  Each time the user modifies the ranges (x/y axis) during panning or
289  zooming of the graph, the new axis ranges are stored in a axis ranges
290  history list. This index allows to point to the last range of that
291  history.
292 
293 */
294  std::size_t m_lastAxisRangeHistoryIndex = 0;
295 
296  //! List of x axis ranges occurring during the panning zooming actions.
297  std::vector<QCPRange *> m_xAxisRangeHistory;
298 
299  //! List of y axis ranges occurring during the panning zooming actions.
300  std::vector<QCPRange *> m_yAxisRangeHistory;
301 
302  //! How many mouse move events must be skipped */
303  /*!
304 
305  when the data are so massive that the graph panning becomes sluggish. By
306  default, the value is 10 events to be skipped before accounting one. The
307  "fat data" mouse movement handler mechanism is actuated by using a
308  keyboard key combination. There is no automatic shift between normal
309  processing and "fat data" processing.
310 
311 */
312  int m_mouseMoveHandlerSkipAmount = 10;
313 
314  //! Counter to handle the "fat data" mouse move event handling.
315  /*!
316 
317  \sa m_mouseMoveHandlerSkipAmount.
318 
319 */
320  int m_mouseMoveHandlerSkipCount = 0;
321 
322  // QColor m_unfocusedColor = QColor(Qt::lightGray);
323  // QColor m_unfocusedColor = QColor(230, 230, 230, 255);
324 
325  //! Color used for the background of unfocused plot.
326  QColor m_unfocusedColor = QColor("lightgray");
327  //! Color used for the background of unfocused plot.
328  QBrush m_unfocusedBrush = QBrush(m_unfocusedColor);
329 
330  //! Color used for the background of focused plot.
331  QColor m_focusedColor = QColor(Qt::transparent);
332  //! Color used for the background of focused plot.
333  QBrush m_focusedBrush = QBrush(m_focusedColor);
334 
335  //! Pen used to draw the graph and textual elements in the plot widget.
336  QPen m_pen;
337 
338  virtual void createAllAncillaryItems();
339  virtual void
340  update1DSelectionRectangle(bool for_integration = false);
341  virtual void update2DSelectionRectangleSquare(bool for_integration = false);
342  virtual void update2DSelectionRectangleSkewed(bool for_integration = false);
343  virtual QString allLayerNamesToString() const;
344  virtual QString layerableLayerName(QCPLayerable *layerable_p) const;
345  virtual int layerableLayerIndex(QCPLayerable *layerable_p) const;
346 };
347 
348 
349 } // namespace pappso
350 
351 
353 extern int basePlotContextMetaTypeId;
354 
Q_DECLARE_METATYPE(pappso::BasePlotContext)
int basePlotContextPtrMetaTypeId
int basePlotContextMetaTypeId
void lastCursorHoveredPointSignal(const QPointF &pointf)
void plottableDestructionRequestedSignal(BasePlotWidget *base_plot_widget_p, QCPAbstractPlottable *plottable_p, const BasePlotContext &context)
QString m_fileName
The name of the data file from which the mass data were read.
QPen m_pen
Pen used to draw the graph and textual elements in the plot widget.
void yMinMaxOnXAxisCurrentRange(double &min, double &max, int index)
std::vector< QCPRange * > m_yAxisRangeHistory
List of y axis ranges occurring during the panning zooming actions.
void mouseReleaseEventSignal(const BasePlotContext &context)
void keyReleaseEventSignal(const BasePlotContext &context)
void plottableSelectionChangedSignal(QCPAbstractPlottable *plottable_p, bool selected)
void plotRangesChangedSignal(const BasePlotContext &context)
void integrationRequestedSignal(const BasePlotContext &context)
void xAxisMeasurementSignal(const BasePlotContext &context, bool with_delta)
void keyPressEventSignal(const BasePlotContext &context)
void yMinMaxOnXAxisCurrentRange(double &min, double &max, QCPAbstractPlottable *plottable_p=nullptr)
std::vector< QCPRange * > m_xAxisRangeHistory
List of x axis ranges occurring during the panning zooming actions.
BasePlotContext m_context
#define PMSPP_LIB_DECL
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition: aa.cpp:39
Axis
Definition: types.h:180
std::shared_ptr< const BasePlotWidget > BasePlotWidgetCstSPtr
std::shared_ptr< BasePlotWidget > BasePlotWidgetSPtr