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
52namespace pappso
53{
54
55enum class RangeType
56{
57 outermost = 1,
58 innermost = 2,
59};
60
61class BasePlotWidget;
62
63typedef std::shared_ptr<BasePlotWidget> BasePlotWidgetSPtr;
64typedef std::shared_ptr<const BasePlotWidget> BasePlotWidgetCstSPtr;
65
66class 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 mouseWheelHandler(QWheelEvent *event);
122
123 virtual void mouseMoveHandler(QMouseEvent *event);
124 virtual void mouseMoveHandlerNotDraggingCursor();
125 virtual void mouseMoveHandlerDraggingCursor();
126 virtual void mouseMoveHandlerLeftButtonDraggingCursor();
127 virtual void mouseMoveHandlerRightButtonDraggingCursor();
128
129 virtual void axisDoubleClickHandler(QCPAxis *axis,
130 QCPAxis::SelectablePart part,
131 QMouseEvent *event);
132 bool isClickOntoXAxis(const QPointF &mousePoint);
133 bool isClickOntoYAxis(const QPointF &mousePoint);
134 /// MOUSE-related EVENTS
135
136
137 /// MOUSE MOVEMENTS mouse/keyboard-triggered
138 int dragDirection();
139 virtual void moveMouseCursorGraphCoordToGlobal(QPointF plot_coordinates);
140 virtual void moveMouseCursorPixelCoordToGlobal(QPointF local_coordinates);
141 virtual void horizontalMoveMouseCursorCountPixels(int pixel_count);
142 virtual QPointF horizontalGetGraphCoordNewPointCountPixels(int pixel_count);
143 virtual void verticalMoveMouseCursorCountPixels(int pixel_count);
144 virtual QPointF verticalGetGraphCoordNewPointCountPixels(int pixel_count);
145 /// MOUSE MOVEMENTS mouse/keyboard-triggered
146
147
148 /// RANGE-related functions
149 virtual QCPRange getRangeX(bool &found_range, int index) const;
150 virtual QCPRange getRangeY(bool &found_range, int index) const;
151 QCPRange getRange(Axis axis, RangeType range_type, bool &found_range) const;
152
153 virtual QCPRange getInnermostRangeX(bool &found_range) const;
154 virtual QCPRange getOutermostRangeX(bool &found_range) const;
155
156 virtual QCPRange getInnermostRangeY(bool &found_range) const;
157 virtual QCPRange getOutermostRangeY(bool &found_range) const;
158
160 double &max,
161 QCPAbstractPlottable *plottable_p = nullptr);
162 void yMinMaxOnXAxisCurrentRange(double &min, double &max, int index);
163 /// RANGE-related functions
164
165
166 /// PLOTTING / REPLOTTING functions
167 virtual void axisRescale();
168 virtual void axisReframe();
169 virtual void axisZoom();
170 virtual void axisPan();
171
172 virtual void replotWithAxesRanges(QCPRange xAxisRange,
173 QCPRange yAxisRange,
174 Axis axis);
175
176 virtual void replotWithAxisRangeX(double lower, double upper);
177 virtual void replotWithAxisRangeY(double lower, double upper);
178 /// PLOTTING / REPLOTTING functions
179
180
181 /// PLOT ITEMS : TRACER TEXT ITEMS...
182 virtual void hideAllPlotItems();
183
184 virtual void showTracers();
185 virtual void hideTracers();
186
187 virtual void drawXDeltaFeatures();
188 virtual void drawYDeltaFeatures();
189
190 virtual void calculateDragDeltas();
191
192 virtual bool isVerticalDisplacementAboveThreshold();
193
194 virtual void
195 drawSelectionRectangleAndPrepareZoom(bool as_line_segment = false,
196 bool for_integration = false);
197
198 virtual void updateSelectionRectangle(bool as_line_segment = false,
199 bool for_integration = false);
200
201 virtual void resetSelectionRectangle();
202 virtual void hideSelectionRectangle(bool reset_values = false);
203 virtual bool isSelectionRectangleVisible();
204 virtual PolygonType whatIsVisibleOfTheSelectionRectangle();
205
206 /// PLOT ITEMS : TRACER TEXT ITEMS...
207
208
209 virtual void setFocus();
210
211 virtual void redrawPlotBackground(QWidget *focusedPlotWidget);
212
213 virtual void updateContextXandYAxisRanges();
214
215 virtual const BasePlotContext &getContext() const;
216
217 signals:
218
220
221 void lastCursorHoveredPointSignal(const QPointF &pointf);
222
224
225 void xAxisMeasurementSignal(const BasePlotContext &context, bool with_delta);
226
229
231
233
234 void plottableSelectionChangedSignal(QCPAbstractPlottable *plottable_p,
235 bool selected);
236
238
240 QCPAbstractPlottable *plottable_p,
241 const BasePlotContext &context);
242
243 protected:
244 //! Name of the plot widget.
245 QString m_name = "NOT_SET";
246
247 //! Description of the plot widget.
248 QString m_desc = "NOT_SET";
249
250 //! The name of the data file from which the mass data were read.
251 QString m_fileName;
252
255
257
258 int m_leftMousePseudoButtonKey = Qt::Key_Less;
259 int m_rightMousePseudoButtonKey = Qt::Key_Greater;
260
261 //! Rectangle defining the borders of zoomed-in/out data.
262 // QCPItemRect *mp_zoomRectItem = nullptr;
263
264 // The four lines that are needed to craft the selection rectangle.
265 QCPItemLine *mp_selectionRectangeLine1 = nullptr;
266 QCPItemLine *mp_selectionRectangeLine2 = nullptr;
267 QCPItemLine *mp_selectionRectangeLine3 = nullptr;
268 QCPItemLine *mp_selectionRectangeLine4 = nullptr;
269
270 //! Text describing the x-axis delta value during a drag operation.
271 QCPItemText *mp_xDeltaTextItem = nullptr;
272 QCPItemText *mp_yDeltaTextItem = nullptr;
273
274 //! Tells if the tracers should be visible.
275 bool m_shouldTracersBeVisible = true;
276
277 //! Horizontal position tracer
278 QCPItemLine *mp_hPosTracerItem = nullptr;
279
280 //! Vertical position tracer
281 QCPItemLine *mp_vPosTracerItem = nullptr;
282
283 //! Vertical selection start tracer (typically in green).
284 QCPItemLine *mp_vStartTracerItem = nullptr;
285
286 //! Vertical selection end tracer (typically in red).
287 QCPItemLine *mp_vEndTracerItem = nullptr /*only vertical*/;
288
289 //! Index of the last axis range history item.
290 /*!
291
292 Each time the user modifies the ranges (x/y axis) during panning or
293 zooming of the graph, the new axis ranges are stored in a axis ranges
294 history list. This index allows to point to the last range of that
295 history.
296
297*/
298 std::size_t m_lastAxisRangeHistoryIndex = 0;
299
300 //! List of x axis ranges occurring during the panning zooming actions.
301 std::vector<QCPRange *> m_xAxisRangeHistory;
302
303 //! List of y axis ranges occurring during the panning zooming actions.
304 std::vector<QCPRange *> m_yAxisRangeHistory;
305
306 //! How many mouse move events must be skipped */
307 /*!
308
309 when the data are so massive that the graph panning becomes sluggish. By
310 default, the value is 10 events to be skipped before accounting one. The
311 "fat data" mouse movement handler mechanism is actuated by using a
312 keyboard key combination. There is no automatic shift between normal
313 processing and "fat data" processing.
314
315*/
316 int m_mouseMoveHandlerSkipAmount = 10;
317
318 //! Counter to handle the "fat data" mouse move event handling.
319 /*!
320
321 \sa m_mouseMoveHandlerSkipAmount.
322
323*/
324 int m_mouseMoveHandlerSkipCount = 0;
325
326 // QColor m_unfocusedColor = QColor(Qt::lightGray);
327 // QColor m_unfocusedColor = QColor(230, 230, 230, 255);
328
329 //! Color used for the background of unfocused plot.
330 QColor m_unfocusedColor = QColor("lightgray");
331 //! Color used for the background of unfocused plot.
332 QBrush m_unfocusedBrush = QBrush(m_unfocusedColor);
333
334 //! Color used for the background of focused plot.
335 QColor m_focusedColor = QColor(Qt::transparent);
336 //! Color used for the background of focused plot.
337 QBrush m_focusedBrush = QBrush(m_focusedColor);
338
339 //! Pen used to draw the graph and textual elements in the plot widget.
340 QPen m_pen;
341
342 virtual void createAllAncillaryItems();
343 virtual void update1DSelectionRectangle(bool for_integration = false);
344 virtual void update2DSelectionRectangleSquare(bool for_integration = false);
345 virtual void update2DSelectionRectangleSkewed(bool for_integration = false);
346 virtual QString allLayerNamesToString() const;
347 virtual QString layerableLayerName(QCPLayerable *layerable_p) const;
348 virtual int layerableLayerIndex(QCPLayerable *layerable_p) const;
349};
350
351
352} // namespace pappso
353
354
357
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 mouseWheelEventSignal(const BasePlotContext &context)
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:220
std::shared_ptr< const BasePlotWidget > BasePlotWidgetCstSPtr
std::shared_ptr< BasePlotWidget > BasePlotWidgetSPtr