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