libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
baseplotcontext.h
Go to the documentation of this file.
1// Copyright 2021 Filippo Rusconi
2// GPL3+
3
4#pragma once
5
6/////////////////////// StdLib includes
7
8
9/////////////////////// Qt includes
10#include <QJSEngine>
11#include <QPointF>
12#include <QString>
13
14/////////////////////// Local includes
15#include "../../core/types.h"
20
21
22////////////////////// Other includes
23#include "qcustomplot.h"
24
25
26
27namespace pappso
28{
29
30Q_NAMESPACE
31
33{
34 NOT_SET = 0x0000,
35 LEFT_TO_RIGHT = 1 << 0,
36 RIGHT_TO_LEFT = 1 << 1,
37 TOP_TO_BOTTOM = 1 << 2,
38 BOTTOM_TO_TOP = 1 << 3
39};
40Q_ENUM_NS(DragDirections)
41
42extern std::map<Qt::MouseButton, QString> qtMouseButtonMap;
43extern std::map<Qt::MouseButtons, QString> qtMouseButtonsMap;
44
45extern std::map<Qt::KeyboardModifier, QString> qtKeyboardModifierMap;
46
47 /* END CLASS JS REFERENCE
48 * namespace: pappso
49 * class name: BasePlotContext
50 */
51
52class PMSPP_LIB_DECL BasePlotContext : public QObject
53{
54 Q_OBJECT
55
56 Q_PROPERTY(bool isMouseDragging MEMBER m_isMouseDragging)
57 Q_PROPERTY(bool wasMouseDragging MEMBER m_wasMouseDragging)
58 Q_PROPERTY(bool isKeyBoardDragging MEMBER m_isKeyBoardDragging)
59 Q_PROPERTY(bool isLeftPseudoButtonKeyPressed MEMBER m_isLeftPseudoButtonKeyPressed)
60 Q_PROPERTY(bool isRightPseudoButtonKeyPressed MEMBER m_isRightPseudoButtonKeyPressed)
61 Q_PROPERTY(bool wasKeyBoardDragging MEMBER m_wasKeyBoardDragging)
62 Q_PROPERTY(QPointF startDragPoint MEMBER m_startDragPoint FINAL)
63 Q_PROPERTY(QPointF currentDragPoint MEMBER m_currentDragPoint FINAL)
64 Q_PROPERTY(QPointF lastCursorHoveredPoint MEMBER m_lastCursorHoveredPoint FINAL);
65 Q_PROPERTY(DragDirections dragDirections MEMBER m_dragDirections FINAL);
66 Q_PROPERTY(double xRegionRangeStart MEMBER m_xRegionRangeStart FINAL);
67 Q_PROPERTY(double xRegionRangeStop MEMBER m_xRegionRangeStop FINAL);
68 Q_PROPERTY(double yRegionRangeStart MEMBER m_yRegionRangeStart FINAL);
69 Q_PROPERTY(double yRegionRangeStop MEMBER m_yRegionRangeStop FINAL);
70 Q_PROPERTY(double xDelta MEMBER m_xDelta FINAL);
71 Q_PROPERTY(double yDelta MEMBER m_yDelta FINAL);
72 Q_PROPERTY(int pressedKeyCode MEMBER m_pressedKeyCode FINAL);
73 Q_PROPERTY(QString pressedKeyText MEMBER m_pressedKeyText FINAL);
74 Q_PROPERTY(int releasedKeyCode MEMBER m_releasedKeyCode FINAL);
75 Q_PROPERTY(QString releasedKeyText MEMBER m_releasedKeyText FINAL);
76 Q_PROPERTY(Qt::KeyboardModifiers keyboardModifiers MEMBER m_keyboardModifiers FINAL);
77 Q_PROPERTY(Qt::MouseButtons lastPressedMouseButton MEMBER m_lastPressedMouseButton FINAL);
78 Q_PROPERTY(Qt::MouseButtons lastReleasedMouseButton MEMBER m_lastReleasedMouseButton FINAL);
79 Q_PROPERTY(Qt::MouseButtons pressedMouseButtons MEMBER m_pressedMouseButtons FINAL);
80 Q_PROPERTY(Qt::MouseButtons mouseButtonsAtMousePress MEMBER m_mouseButtonsAtMousePress FINAL);
81 Q_PROPERTY(Qt::MouseButtons mouseButtonsAtMouseRelease MEMBER m_mouseButtonsAtMouseRelease FINAL);
82
83public:
84 Q_INVOKABLE explicit BasePlotContext(QObject *parent = nullptr);
85
86 virtual ~BasePlotContext();
87
88 Q_INVOKABLE BasePlotContext *clone(QObject *parent = nullptr);
89 Q_INVOKABLE void initialize(const BasePlotContext &other);
90
91 BasePlotContext(const BasePlotContext &other) = delete;
92 BasePlotContext &operator=(const BasePlotContext &other) = delete;
93
94 Enums::DataKind m_dataKind = Enums::DataKind::unset;
95
96 bool m_isMouseDragging = false;
97 bool m_wasMouseDragging = false;
98
99 bool m_isKeyBoardDragging = false;
100 bool m_isLeftPseudoButtonKeyPressed = false;
101 bool m_isRightPseudoButtonKeyPressed = false;
102 bool m_wasKeyBoardDragging = false;
103
104 QPointF m_startDragPoint;
105 QPointF m_currentDragPoint;
106 QPointF m_lastCursorHoveredPoint;
107 DragDirections m_dragDirections = DragDirections::NOT_SET;
108
109 IntegrationScopeBaseCstSPtr msp_integrationScope = nullptr;
110 SelectionPolygon m_selectionPolygon;
111 double m_integrationScopeRhombWidth = 0;
112 double m_integrationScopeRhombHeight = 0;
113
114 // The effective range of the axes.
115 QCPRange m_xRange;
116 QCPRange m_yRange;
117
118 // Tell if the mouse move was started onto either axis, because that will
119 // condition if some calculations needs to be performed or not (for example,
120 // if the mouse cursor motion was started on an axis, there is no point to
121 // perform deconvolutions).
122 bool m_wasClickOnXAxis = false;
123 bool m_wasClickOnYAxis = false;
124
125 bool m_isMeasuringDistance = false;
126
127 // The user-selected region over the plot.
128 // Note that we cannot use QCPRange structures because these are normalized by
129 // QCustomPlot in such a manner that lower is actually < upper. But we need
130 // for a number of our calculations (specifically for the deconvolutions) to
131 // actually have the lower value be start drag point.x even if the drag
132 // direction was from right to left.
133 double m_xRegionRangeStart = std::numeric_limits<double>::min();
134 double m_xRegionRangeStop = std::numeric_limits<double>::min();
135
136 double m_yRegionRangeStart = std::numeric_limits<double>::min();
137 double m_yRegionRangeStop = std::numeric_limits<double>::min();
138
139 double m_xDelta = 0;
140 double m_yDelta = 0;
141
142 int m_pressedKeyCode;
143 QString m_pressedKeyText;
144 int m_releasedKeyCode;
145 QString m_releasedKeyText;
146
147 Qt::KeyboardModifiers m_keyboardModifiers;
148
149 Qt::MouseButtons m_lastPressedMouseButton;
150 Qt::MouseButtons m_lastReleasedMouseButton;
151
152 Qt::MouseButtons m_pressedMouseButtons;
153
154 Qt::MouseButtons m_mouseButtonsAtMousePress;
155 Qt::MouseButtons m_mouseButtonsAtMouseRelease;
156
157 void updateIntegrationScope();
158 void updateIntegrationScopeRect();
159 void updateIntegrationScopeRhomb();
160 void updateIntegrationScopeRhombHorizontal();
161 void updateIntegrationScopeRhombVertical();
162
163 DragDirections recordDragDirections();
164
165 Q_INVOKABLE QString toString() const;
166 Q_INVOKABLE QString dragDirectionsToString() const;
167
168 static void registerJsConstructor(QJSEngine *engine);
169};
170
172
173 /* END CLASS JS REFERENCE
174 * namespace: pappso
175 * class name: BasePlotContext
176 */
177
178} // namespace pappso
#define PMSPP_LIB_DECL
#define PAPPSO_REGISTER_JS_CLASS(NS_IDENT, CLASS_NAME)
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
std::map< Qt::MouseButton, QString > qtMouseButtonMap
std::shared_ptr< const IntegrationScopeBase > IntegrationScopeBaseCstSPtr
std::map< Qt::MouseButtons, QString > qtMouseButtonsMap
std::map< Qt::KeyboardModifier, QString > qtKeyboardModifierMap