libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
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
47#include "../../core/types.h"
49#include "baseplotcontext.h"
50
51
52namespace pappso
53{
54
71
72 enum class RangeType
73 {
76 };
77
78 class BasePlotWidget;
79
80 typedef std::shared_ptr<BasePlotWidget> BasePlotWidgetSPtr;
81 typedef std::shared_ptr<const BasePlotWidget> BasePlotWidgetCstSPtr;
82
83 class PMSPP_LIB_DECL BasePlotWidget : public QCustomPlot
84 {
85 Q_OBJECT
86
87 public:
88 explicit BasePlotWidget(QWidget *parent);
89 explicit BasePlotWidget(QWidget *parent,
90 const QString &x_axis_label,
91 const QString &y_axis_label);
92
93 virtual ~BasePlotWidget();
94
95 virtual bool setupWidget();
96
97 virtual void setPen(const QPen &pen);
98 virtual const QPen &getPen() const;
99
100 virtual void setPlottingColor(QCPAbstractPlottable *plottable_p, const QColor &new_color);
101 virtual void setPlottingColor(int index, const QColor &new_color);
102
103 virtual QColor getPlottingColor(QCPAbstractPlottable *plottable_p) const;
104 virtual QColor getPlottingColor(int index = 0) const;
105
106 virtual void setAxisLabelX(const QString &label);
107 virtual void setAxisLabelY(const QString &label);
108
109 // AXES RANGE HISTORY-related functions
110 virtual void resetAxesRangeHistory();
111 virtual void updateAxesRangeHistory();
112 virtual void restorePreviousAxesRangeHistory();
113 virtual void restoreAxesRangeHistory(std::size_t index);
114 // AXES RANGE HISTORY-related functions
115
116
117 /// KEYBOARD-related EVENTS
118 virtual void keyPressEvent(QKeyEvent *event);
119 virtual void keyReleaseEvent(QKeyEvent *event);
120
121 virtual void spaceKeyReleaseEvent(QKeyEvent *event);
122
123 virtual void directionKeyPressEvent(QKeyEvent *event);
124 virtual void directionKeyReleaseEvent(QKeyEvent *event);
125
126 virtual void mousePseudoButtonKeyPressEvent(QKeyEvent *event);
127 virtual void mousePseudoButtonKeyReleaseEvent(QKeyEvent *event);
128 /// KEYBOARD-related EVENTS
129
130
131 /// MOUSE-related EVENTS
132 virtual void mousePressHandler(QMouseEvent *event);
133 virtual void mouseReleaseHandler(QMouseEvent *event);
134 virtual void mouseReleaseHandlerLeftButton(QMouseEvent *event);
135 virtual void mouseReleaseHandlerRightButton(QMouseEvent *event);
136
137 virtual void mouseWheelHandler(QWheelEvent *event);
138
139 virtual void mouseMoveHandler(QMouseEvent *event);
140 virtual void mouseMoveHandlerNotDraggingCursor(QMouseEvent *event);
141 virtual void mouseMoveHandlerDraggingCursor(QMouseEvent *event);
142 virtual void mouseMoveHandlerLeftButtonDraggingCursor(QMouseEvent *event);
143 virtual void mouseMoveHandlerRightButtonDraggingCursor(QMouseEvent *event);
144
145 virtual void
146 axisDoubleClickHandler(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event);
147 bool isClickOntoXAxis(const QPointF &mousePoint);
148 bool isClickOntoYAxis(const QPointF &mousePoint);
149 /// MOUSE-related EVENTS
150
151
152 /// MOUSE MOVEMENTS mouse/keyboard-triggered
153 int dragDirection();
154 virtual void moveMouseCursorGraphCoordToGlobal(QPointF plot_coordinates);
155 virtual void moveMouseCursorPixelCoordToGlobal(QPointF local_coordinates);
156 virtual void horizontalMoveMouseCursorCountPixels(int pixel_count);
157 virtual QPointF horizontalGetGraphCoordNewPointCountPixels(int pixel_count);
158 virtual void verticalMoveMouseCursorCountPixels(int pixel_count);
159 virtual QPointF verticalGetGraphCoordNewPointCountPixels(int pixel_count);
160 /// MOUSE MOVEMENTS mouse/keyboard-triggered
161
162
163 /// RANGE-related functions
164 virtual QCPRange getRangeX(bool &found_range, int index, RangeType range_type) const;
165 virtual void
166 getRangeX(bool &found_range, int index, RangeType range_type, double &start, double &stop) const;
167 virtual void getRangeX(bool &found_range,
168 int index,
169 RangeType range_type,
170 std::pair<double, double> &start_stop_pair) const;
171
172 virtual QCPRange getRangeY(bool &found_range, int index, RangeType range_type) const;
173 virtual void
174 getRangeY(bool &found_range, int index, RangeType range_type, double &start, double &stop) const;
175 virtual void getRangeY(bool &found_range,
176 int index,
177 RangeType range_type,
178 std::pair<double, double> &start_stop_pair) const;
179
180 QCPRange getRange(Enums::Axis axis, RangeType range_type, bool &found_range) const;
181
182 virtual QCPRange getInnermostRangeX(bool &found_range) const;
183 virtual QCPRange getOutermostRangeX(bool &found_range) const;
184
185 virtual QCPRange getInnermostRangeY(bool &found_range) const;
186 virtual QCPRange getOutermostRangeY(bool &found_range) const;
187
189 double &max,
190 QCPAbstractPlottable *plottable_p = nullptr);
191 void yMinMaxOnXAxisCurrentRange(double &min, double &max, int index);
192 /// RANGE-related functions
193
194
195 /// PLOTTING / REPLOTTING functions
196 virtual void axisRescale();
197 virtual void axisReframe();
198 virtual void axisZoom();
199 virtual void axisPan();
200
201 virtual void replotWithAxesRanges(QCPRange xAxisRange, QCPRange yAxisRange, Enums::Axis axis);
202
203 virtual void replotWithAxisRangeX(double lower, double upper);
204 virtual void replotWithAxisRangeY(double lower, double upper);
205 /// PLOTTING / REPLOTTING functions
206
207
208 /// PLOT ITEMS : TRACER TEXT ITEMS...
209 virtual void hideAllPlotItems();
210
211 virtual void showTracers();
212 virtual void hideTracers();
213
214 virtual void drawXScopeSpanFeatures();
215 virtual void drawYScopeSpanFeatures();
216
217 virtual void calculateDragDeltas();
218
220
221 virtual void drawSelectionRectangleAndPrepareZoom(bool as_line_segment = false,
222 bool for_integration = false);
223
224 virtual void updateIntegrationScopeDrawing(bool as_line_segment = false,
225 bool for_integration = false);
226
227 virtual void resetSelectionRectangle();
228 virtual void hideSelectionRectangle(bool reset_values = false);
229 virtual bool isSelectionRectangleVisible();
231 /// PLOT ITEMS : TRACER TEXT ITEMS...
232
233
234 virtual void setFocus();
235
236 virtual void redrawPlotBackground(QWidget *focusedPlotWidget);
237
238 virtual void updateContextXandYAxisRanges();
239
240 virtual const BasePlotContext &getContext() const;
241
242 virtual int getPlotIndex(QCPAbstractPlottable *plottable_p);
243
244 ////////////////////////// SIGNALS /////////////////////////////////
245 ////////////////////////// SIGNALS /////////////////////////////////
246 ////////////////////////// SIGNALS /////////////////////////////////
247 signals:
248
250
251 void lastCursorHoveredPointSignal(const QPointF &pointf);
252
253 void plotRangesChangedSignal(QMouseEvent *event, const pappso::BasePlotContext &context);
254 void plotRangesChangedWheelEventSignal(QWheelEvent *event,
255 const pappso::BasePlotContext &context);
256
257 void xAxisMeasurementSignal(const pappso::BasePlotContext &context, bool with_delta);
258
259 void keyPressEventSignal(QKeyEvent *event, const pappso::BasePlotContext &context);
260 void keyReleaseEventSignal(QKeyEvent *event, const pappso::BasePlotContext &context);
261
262 void mousePressEventSignal(QMouseEvent *event, const pappso::BasePlotContext &context);
263 void mouseReleaseEventSignal(QMouseEvent *event, const pappso::BasePlotContext &context);
264 void mouseMoveDraggingCursorSignal(QMouseEvent *event, const pappso::BasePlotContext &context);
265
266 void mouseWheelEventSignal(QWheelEvent *event, const pappso::BasePlotContext &context);
267
268 void plottableSelectionChangedSignal(QCPAbstractPlottable *plottable_p, bool selected);
269
271
273 QCPAbstractPlottable *plottable_p,
274 const pappso::BasePlotContext &context);
275
279
280 protected:
281 //! Name of the plot widget.
282 QString m_name = "NOT_SET";
283
284 //! Description of the plot widget.
285 QString m_desc = "NOT_SET";
286
287 //! The name of the data file from which the mass data were read.
288 QString m_fileName;
289
292
294
295 int m_leftMousePseudoButtonKey = Qt::Key_Less;
296 int m_rightMousePseudoButtonKey = Qt::Key_Greater;
297
298 //! Rectangle defining the borders of zoomed-in/out data.
299 // QCPItemRect *mp_zoomRectItem = nullptr;
300
301 // The four lines that are needed to craft the selection rectangle.
302 QCPItemLine *mp_selectionRectangeLine1 = nullptr;
303 QCPItemLine *mp_selectionRectangeLine2 = nullptr;
304 QCPItemLine *mp_selectionRectangeLine3 = nullptr;
305 QCPItemLine *mp_selectionRectangeLine4 = nullptr;
306
307 //! Text describing the x-axis delta value during a drag operation.
308 QCPItemText *mp_xDeltaTextItem = nullptr;
309 QCPItemText *mp_yDeltaTextItem = nullptr;
310
311 //! Tells if the tracers should be visible.
313
314 //! Horizontal position tracer
315 QCPItemLine *mp_hPosTracerItem = nullptr;
316
317 //! Vertical position tracer
318 QCPItemLine *mp_vPosTracerItem = nullptr;
319
320 //! Vertical selection start tracer (typically in green).
321 QCPItemLine *mp_vStartTracerItem = nullptr;
322
323 //! Vertical selection end tracer (typically in red).
324 QCPItemLine *mp_vEndTracerItem = nullptr /*only vertical*/;
325
326 //! Index of the last axis range history item.
327 /*!
328
329 Each time the user modifies the ranges (x/y axis) during panning or
330 zooming of the graph, the new axis ranges are stored in a axis ranges
331 history list. This index allows to point to the last range of that
332 history.
333
334 */
336
337 //! List of x axis ranges occurring during the panning zooming actions.
338 std::vector<QCPRange *> m_xAxisRangeHistory;
339
340 //! List of y axis ranges occurring during the panning zooming actions.
341 std::vector<QCPRange *> m_yAxisRangeHistory;
342
343 //! How many mouse move events must be skipped */
344 /*!
345
346 when the data are so massive that the graph panning becomes sluggish. By
347 default, the value is 10 events to be skipped before accounting one. The
348 "fat data" mouse movement handler mechanism is actuated by using a
349 keyboard key combination. There is no automatic shift between normal
350 processing and "fat data" processing.
351
352 */
354
355 //! Counter to handle the "fat data" mouse move event handling.
356 /*!
357
358 \sa m_mouseMoveHandlerSkipAmount.
359
360 */
362
363 // QColor m_unfocusedColor = QColor(Qt::lightGray);
364 // QColor m_unfocusedColor = QColor(230, 230, 230, 255);
365
366 //! Color used for the background of unfocused plot.
367 QColor m_unfocusedColor = QColor("lightgray");
368 //! Color used for the background of unfocused plot.
370
371 //! Color used for the background of focused plot.
372 QColor m_focusedColor = QColor(Qt::transparent);
373 //! Color used for the background of focused plot.
375
376 //! Pen used to draw the graph and textual elements in the plot widget.
377 QPen m_pen;
378
379 virtual void createAllAncillaryItems();
380 virtual void updateIntegrationScope(bool for_integration = false);
381 virtual void updateIntegrationScopeRect(bool for_integration = false);
382 virtual void updateIntegrationScopeHorizontalRhomb(bool for_integration = false);
383 virtual void updateIntegrationScopeVerticalRhomb(bool for_integration = false);
384 virtual void updateIntegrationScopeRhomb(bool for_integration = false);
385 virtual QString allLayerNamesToString() const;
386 virtual QString layerableLayerName(QCPLayerable *layerable_p) const;
387 virtual int layerableLayerIndex(QCPLayerable *layerable_p) const;
388 };
389
390
391} // namespace pappso
392
393
396
int basePlotContextPtrMetaTypeId
int basePlotContextMetaTypeId
Q_DECLARE_METATYPE(pappso::BasePlotContext)
virtual void updateIntegrationScopeRect(bool for_integration=false)
int m_mouseMoveHandlerSkipAmount
How many mouse move events must be skipped *‍/.
std::size_t m_lastAxisRangeHistoryIndex
Index of the last axis range history item.
virtual void replotWithAxesRanges(QCPRange xAxisRange, QCPRange yAxisRange, Enums::Axis axis)
virtual void updateAxesRangeHistory()
Create new axis range history items and append them to the history.
virtual void mouseWheelHandler(QWheelEvent *event)
void plottableDestructionRequestedSignal(BasePlotWidget *base_plot_widget_p, QCPAbstractPlottable *plottable_p, const pappso::BasePlotContext &context)
bool m_shouldTracersBeVisible
Tells if the tracers should be visible.
virtual void hideSelectionRectangle(bool reset_values=false)
virtual void updateIntegrationScopeDrawing(bool as_line_segment=false, bool for_integration=false)
virtual void directionKeyReleaseEvent(QKeyEvent *event)
QString m_name
Name of the plot widget.
QCPItemText * mp_yDeltaTextItem
void mousePressEventSignal(QMouseEvent *event, const pappso::BasePlotContext &context)
QCPItemLine * mp_selectionRectangeLine1
Rectangle defining the borders of zoomed-in/out data.
virtual QCPRange getOutermostRangeX(bool &found_range) const
void lastCursorHoveredPointSignal(const QPointF &pointf)
virtual const BasePlotContext & getContext() const
virtual void drawSelectionRectangleAndPrepareZoom(bool as_line_segment=false, bool for_integration=false)
virtual QCPRange getRangeY(bool &found_range, int index, RangeType range_type) const
virtual void keyPressEvent(QKeyEvent *event)
KEYBOARD-related EVENTS.
void xAxisMeasurementSignal(const pappso::BasePlotContext &context, bool with_delta)
virtual QCPRange getRangeX(bool &found_range, int index, RangeType range_type) const
MOUSE MOVEMENTS mouse/keyboard-triggered.
virtual void updateIntegrationScope(bool for_integration=false)
QString m_fileName
The name of the data file from which the mass data were read.
virtual void mouseMoveHandlerLeftButtonDraggingCursor(QMouseEvent *event)
QCPItemLine * mp_selectionRectangeLine2
void plotRangesChangedSignal(QMouseEvent *event, const pappso::BasePlotContext &context)
QCPItemText * mp_xDeltaTextItem
Text describing the x-axis delta value during a drag operation.
virtual void setAxisLabelX(const QString &label)
int m_mouseMoveHandlerSkipCount
Counter to handle the "fat data" mouse move event handling.
virtual QCPRange getOutermostRangeY(bool &found_range) const
virtual void mouseMoveHandlerRightButtonDraggingCursor(QMouseEvent *event)
int dragDirection()
MOUSE-related EVENTS.
bool isClickOntoYAxis(const QPointF &mousePoint)
virtual void moveMouseCursorPixelCoordToGlobal(QPointF local_coordinates)
QCPItemLine * mp_hPosTracerItem
Horizontal position tracer.
QCPItemLine * mp_vPosTracerItem
Vertical position tracer.
void keyPressEventSignal(QKeyEvent *event, const pappso::BasePlotContext &context)
virtual void setPen(const QPen &pen)
virtual void mouseMoveHandlerDraggingCursor(QMouseEvent *event)
virtual QCPRange getInnermostRangeX(bool &found_range) const
virtual void redrawPlotBackground(QWidget *focusedPlotWidget)
Redraw the background of the focusedPlotWidget plot widget.
virtual void mouseReleaseHandlerLeftButton(QMouseEvent *event)
virtual void mouseMoveHandlerNotDraggingCursor(QMouseEvent *event)
bool isClickOntoXAxis(const QPointF &mousePoint)
virtual void setAxisLabelY(const QString &label)
virtual void restoreAxesRangeHistory(std::size_t index)
Get the axis histories at index index and update the plot ranges.
virtual void drawXScopeSpanFeatures()
virtual void spaceKeyReleaseEvent(QKeyEvent *event)
virtual void replotWithAxisRangeX(double lower, double upper)
QColor m_unfocusedColor
Color used for the background of unfocused plot.
virtual void createAllAncillaryItems()
virtual QColor getPlottingColor(QCPAbstractPlottable *plottable_p) const
QBrush m_focusedBrush
Color used for the background of focused plot.
QPen m_pen
Pen used to draw the graph and textual elements in the plot widget.
virtual bool isSelectionRectangleVisible()
virtual bool isVerticalDisplacementAboveThreshold()
virtual void mousePressHandler(QMouseEvent *event)
KEYBOARD-related EVENTS.
virtual void verticalMoveMouseCursorCountPixels(int pixel_count)
virtual void updateIntegrationScopeRhomb(bool for_integration=false)
void mouseWheelEventSignal(QWheelEvent *event, const pappso::BasePlotContext &context)
virtual void resetAxesRangeHistory()
virtual SelectionDrawingLines whatIsVisibleOfTheSelectionRectangle()
virtual void showTracers()
Show the traces (vertical and horizontal).
virtual QPointF horizontalGetGraphCoordNewPointCountPixels(int pixel_count)
QCPItemLine * mp_selectionRectangeLine4
QColor m_focusedColor
Color used for the background of focused plot.
void yMinMaxOnXAxisCurrentRange(double &min, double &max, int index)
virtual void horizontalMoveMouseCursorCountPixels(int pixel_count)
virtual int getPlotIndex(QCPAbstractPlottable *plottable_p)
BasePlotWidget(QWidget *parent)
std::vector< QCPRange * > m_yAxisRangeHistory
List of y axis ranges occurring during the panning zooming actions.
virtual QCPRange getInnermostRangeY(bool &found_range) const
virtual void setFocus()
PLOT ITEMS : TRACER TEXT ITEMS...
virtual void drawYScopeSpanFeatures()
virtual const QPen & getPen() const
virtual void updateContextXandYAxisRanges()
virtual void updateIntegrationScopeHorizontalRhomb(bool for_integration=false)
void plottableSelectionChangedSignal(QCPAbstractPlottable *plottable_p, bool selected)
virtual void mousePseudoButtonKeyPressEvent(QKeyEvent *event)
virtual void setPlottingColor(QCPAbstractPlottable *plottable_p, const QColor &new_color)
virtual void calculateDragDeltas()
QCPRange getRange(Enums::Axis axis, RangeType range_type, bool &found_range) const
virtual QPointF verticalGetGraphCoordNewPointCountPixels(int pixel_count)
QCPItemLine * mp_vStartTracerItem
Vertical selection start tracer (typically in green).
virtual void mouseReleaseHandler(QMouseEvent *event)
QBrush m_unfocusedBrush
Color used for the background of unfocused plot.
virtual void axisRescale()
RANGE-related functions.
void mouseMoveDraggingCursorSignal(QMouseEvent *event, const pappso::BasePlotContext &context)
virtual void moveMouseCursorGraphCoordToGlobal(QPointF plot_coordinates)
virtual QString allLayerNamesToString() const
QCPItemLine * mp_selectionRectangeLine3
void mouseReleaseEventSignal(QMouseEvent *event, const pappso::BasePlotContext &context)
virtual void axisDoubleClickHandler(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event)
QString m_desc
Description of the plot widget.
QCPItemLine * mp_vEndTracerItem
Vertical selection end tracer (typically in red).
void plotRangesChangedWheelEventSignal(QWheelEvent *event, const pappso::BasePlotContext &context)
virtual void mouseMoveHandler(QMouseEvent *event)
KEYBOARD-related EVENTS.
virtual void directionKeyPressEvent(QKeyEvent *event)
virtual QString layerableLayerName(QCPLayerable *layerable_p) const
virtual void keyReleaseEvent(QKeyEvent *event)
Handle specific key codes and trigger respective actions.
virtual void resetSelectionRectangle()
virtual void restorePreviousAxesRangeHistory()
Go up one history element in the axis history.
virtual int layerableLayerIndex(QCPLayerable *layerable_p) const
void integrationRequestedSignal(const BasePlotContext &context)
void keyReleaseEventSignal(QKeyEvent *event, const pappso::BasePlotContext &context)
virtual void replotWithAxisRangeY(double lower, double upper)
virtual void hideTracers()
Hide the traces (vertical and horizontal).
virtual void mouseReleaseHandlerRightButton(QMouseEvent *event)
void yMinMaxOnXAxisCurrentRange(double &min, double &max, QCPAbstractPlottable *plottable_p=nullptr)
virtual void updateIntegrationScopeVerticalRhomb(bool for_integration=false)
virtual void mousePseudoButtonKeyReleaseEvent(QKeyEvent *event)
virtual void hideAllPlotItems()
PLOTTING / REPLOTTING functions.
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
SelectionDrawingLines
std::shared_ptr< const BasePlotWidget > BasePlotWidgetCstSPtr
std::shared_ptr< BasePlotWidget > BasePlotWidgetSPtr