1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the Qt Data Visualization module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 or (at your option) any later version |
20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
22 | ** included in the packaging of this file. Please review the following |
23 | ** information to ensure the GNU General Public License requirements will |
24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
25 | ** |
26 | ** $QT_END_LICENSE$ |
27 | ** |
28 | ****************************************************************************/ |
29 | |
30 | // |
31 | // W A R N I N G |
32 | // ------------- |
33 | // |
34 | // This file is not part of the QtDataVisualization API. It exists purely as an |
35 | // implementation detail. This header file may change from version to |
36 | // version without notice, or even be removed. |
37 | // |
38 | // We mean it. |
39 | |
40 | #ifndef ABSTRACTDECLARATIVE_P_H |
41 | #define ABSTRACTDECLARATIVE_P_H |
42 | |
43 | #include "datavisualizationglobal_p.h" |
44 | #include "abstract3dcontroller_p.h" |
45 | #include "declarativescene_p.h" |
46 | |
47 | #include <QtQuick/QQuickItem> |
48 | #include <QtCore/QPointer> |
49 | #include <QtCore/QThread> |
50 | #include <QtCore/QMutex> |
51 | #include <QtCore/QSharedPointer> |
52 | |
53 | class GLStateStore; |
54 | |
55 | QT_BEGIN_NAMESPACE_DATAVISUALIZATION |
56 | |
57 | class AbstractDeclarative : public QQuickItem |
58 | { |
59 | Q_OBJECT |
60 | Q_ENUMS(ShadowQuality) |
61 | Q_ENUMS(RenderingMode) |
62 | Q_ENUMS(ElementType) |
63 | Q_FLAGS(SelectionFlag SelectionFlags) |
64 | Q_FLAGS(OptimizationHint OptimizationHints) |
65 | Q_PROPERTY(SelectionFlags selectionMode READ selectionMode WRITE setSelectionMode NOTIFY selectionModeChanged) |
66 | Q_PROPERTY(ShadowQuality shadowQuality READ shadowQuality WRITE setShadowQuality NOTIFY shadowQualityChanged) |
67 | Q_PROPERTY(bool shadowsSupported READ shadowsSupported NOTIFY shadowsSupportedChanged) |
68 | Q_PROPERTY(int msaaSamples READ msaaSamples WRITE setMsaaSamples NOTIFY msaaSamplesChanged) |
69 | Q_PROPERTY(Declarative3DScene* scene READ scene NOTIFY sceneChanged) |
70 | Q_PROPERTY(QAbstract3DInputHandler* inputHandler READ inputHandler WRITE setInputHandler NOTIFY inputHandlerChanged) |
71 | Q_PROPERTY(Q3DTheme* theme READ theme WRITE setTheme NOTIFY themeChanged) |
72 | Q_PROPERTY(RenderingMode renderingMode READ renderingMode WRITE setRenderingMode NOTIFY renderingModeChanged) |
73 | Q_PROPERTY(bool measureFps READ measureFps WRITE setMeasureFps NOTIFY measureFpsChanged REVISION 1) |
74 | Q_PROPERTY(qreal currentFps READ currentFps NOTIFY currentFpsChanged REVISION 1) |
75 | Q_PROPERTY(QQmlListProperty<QCustom3DItem> customItemList READ customItemList REVISION 1) |
76 | Q_PROPERTY(bool orthoProjection READ isOrthoProjection WRITE setOrthoProjection NOTIFY orthoProjectionChanged REVISION 1) |
77 | Q_PROPERTY(ElementType selectedElement READ selectedElement NOTIFY selectedElementChanged REVISION 1) |
78 | Q_PROPERTY(qreal aspectRatio READ aspectRatio WRITE setAspectRatio NOTIFY aspectRatioChanged REVISION 1) |
79 | Q_PROPERTY(OptimizationHints optimizationHints READ optimizationHints WRITE setOptimizationHints NOTIFY optimizationHintsChanged REVISION 1) |
80 | Q_PROPERTY(bool polar READ isPolar WRITE setPolar NOTIFY polarChanged REVISION 2) |
81 | Q_PROPERTY(float radialLabelOffset READ radialLabelOffset WRITE setRadialLabelOffset NOTIFY radialLabelOffsetChanged REVISION 2) |
82 | Q_PROPERTY(qreal horizontalAspectRatio READ horizontalAspectRatio WRITE setHorizontalAspectRatio NOTIFY horizontalAspectRatioChanged REVISION 2) |
83 | Q_PROPERTY(bool reflection READ isReflection WRITE setReflection NOTIFY reflectionChanged REVISION 2) |
84 | Q_PROPERTY(qreal reflectivity READ reflectivity WRITE setReflectivity NOTIFY reflectivityChanged REVISION 2) |
85 | Q_PROPERTY(QLocale locale READ locale WRITE setLocale NOTIFY localeChanged REVISION 2) |
86 | Q_PROPERTY(QVector3D queriedGraphPosition READ queriedGraphPosition NOTIFY queriedGraphPositionChanged REVISION 2) |
87 | Q_PROPERTY(qreal margin READ margin WRITE setMargin NOTIFY marginChanged REVISION 2) |
88 | |
89 | public: |
90 | enum SelectionFlag { |
91 | SelectionNone = 0, |
92 | SelectionItem = 1, |
93 | SelectionRow = 2, |
94 | SelectionItemAndRow = SelectionItem | SelectionRow, |
95 | SelectionColumn = 4, |
96 | SelectionItemAndColumn = SelectionItem | SelectionColumn, |
97 | SelectionRowAndColumn = SelectionRow | SelectionColumn, |
98 | SelectionItemRowAndColumn = SelectionItem | SelectionRow | SelectionColumn, |
99 | SelectionSlice = 8, |
100 | SelectionMultiSeries = 16 |
101 | }; |
102 | Q_DECLARE_FLAGS(SelectionFlags, SelectionFlag) |
103 | |
104 | enum ShadowQuality { |
105 | ShadowQualityNone = 0, |
106 | ShadowQualityLow, |
107 | ShadowQualityMedium, |
108 | ShadowQualityHigh, |
109 | ShadowQualitySoftLow, |
110 | ShadowQualitySoftMedium, |
111 | ShadowQualitySoftHigh |
112 | }; |
113 | |
114 | enum ElementType { |
115 | ElementNone = 0, |
116 | ElementSeries, |
117 | ElementAxisXLabel, |
118 | ElementAxisYLabel, |
119 | ElementAxisZLabel, |
120 | ElementCustomItem |
121 | }; |
122 | |
123 | enum RenderingMode { |
124 | RenderDirectToBackground = 0, |
125 | RenderDirectToBackground_NoClear, |
126 | RenderIndirect |
127 | }; |
128 | |
129 | enum OptimizationHint { |
130 | OptimizationDefault = 0, |
131 | OptimizationStatic = 1 |
132 | }; |
133 | Q_DECLARE_FLAGS(OptimizationHints, OptimizationHint) |
134 | |
135 | public: |
136 | explicit AbstractDeclarative(QQuickItem *parent = 0); |
137 | virtual ~AbstractDeclarative(); |
138 | |
139 | virtual void setRenderingMode(RenderingMode mode); |
140 | virtual AbstractDeclarative::RenderingMode renderingMode() const; |
141 | |
142 | virtual void setSelectionMode(SelectionFlags mode); |
143 | virtual AbstractDeclarative::SelectionFlags selectionMode() const; |
144 | |
145 | virtual void setShadowQuality(ShadowQuality quality); |
146 | virtual AbstractDeclarative::ShadowQuality shadowQuality() const; |
147 | |
148 | virtual AbstractDeclarative::ElementType selectedElement() const; |
149 | |
150 | virtual bool shadowsSupported() const; |
151 | |
152 | virtual void setMsaaSamples(int samples); |
153 | virtual int msaaSamples() const; |
154 | |
155 | virtual Declarative3DScene *scene() const; |
156 | |
157 | virtual QAbstract3DInputHandler *inputHandler() const; |
158 | virtual void setInputHandler(QAbstract3DInputHandler *inputHandler); |
159 | |
160 | virtual void setTheme(Q3DTheme *theme); |
161 | virtual Q3DTheme *theme() const; |
162 | |
163 | Q_INVOKABLE virtual void clearSelection(); |
164 | |
165 | Q_REVISION(1) Q_INVOKABLE virtual int addCustomItem(QCustom3DItem *item); |
166 | Q_REVISION(1) Q_INVOKABLE virtual void removeCustomItems(); |
167 | Q_REVISION(1) Q_INVOKABLE virtual void removeCustomItem(QCustom3DItem *item); |
168 | Q_REVISION(1) Q_INVOKABLE virtual void removeCustomItemAt(const QVector3D &position); |
169 | Q_REVISION(1) Q_INVOKABLE virtual void releaseCustomItem(QCustom3DItem *item); |
170 | |
171 | Q_REVISION(1) Q_INVOKABLE virtual int selectedLabelIndex() const; |
172 | Q_REVISION(1) Q_INVOKABLE virtual QAbstract3DAxis *selectedAxis() const; |
173 | |
174 | Q_REVISION(1) Q_INVOKABLE virtual int selectedCustomItemIndex() const; |
175 | Q_REVISION(1) Q_INVOKABLE virtual QCustom3DItem *selectedCustomItem() const; |
176 | |
177 | QQmlListProperty<QCustom3DItem> customItemList(); |
178 | static void appendCustomItemFunc(QQmlListProperty<QCustom3DItem> *list, |
179 | QCustom3DItem *item); |
180 | static int countCustomItemFunc(QQmlListProperty<QCustom3DItem> *list); |
181 | static QCustom3DItem *atCustomItemFunc(QQmlListProperty<QCustom3DItem> *list, int index); |
182 | static void clearCustomItemFunc(QQmlListProperty<QCustom3DItem> *list); |
183 | |
184 | virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); |
185 | |
186 | void setSharedController(Abstract3DController *controller); |
187 | // Used to synch up data model from controller to renderer while main thread is locked |
188 | void synchDataToRenderer(); |
189 | void render(); |
190 | |
191 | void activateOpenGLContext(QQuickWindow *window); |
192 | void doneOpenGLContext(QQuickWindow *window); |
193 | |
194 | void checkWindowList(QQuickWindow *window); |
195 | |
196 | void setMeasureFps(bool enable); |
197 | bool measureFps() const; |
198 | qreal currentFps() const; |
199 | |
200 | void setOrthoProjection(bool enable); |
201 | bool isOrthoProjection() const; |
202 | |
203 | void setAspectRatio(qreal ratio); |
204 | qreal aspectRatio() const; |
205 | |
206 | void setOptimizationHints(OptimizationHints hints); |
207 | OptimizationHints optimizationHints() const; |
208 | |
209 | void setPolar(bool enable); |
210 | bool isPolar() const; |
211 | |
212 | void setRadialLabelOffset(float offset); |
213 | float radialLabelOffset() const; |
214 | |
215 | void setHorizontalAspectRatio(qreal ratio); |
216 | qreal horizontalAspectRatio() const; |
217 | |
218 | void setReflection(bool enable); |
219 | bool isReflection() const; |
220 | |
221 | void setReflectivity(qreal reflectivity); |
222 | qreal reflectivity() const; |
223 | |
224 | void setLocale(const QLocale &locale); |
225 | QLocale locale() const; |
226 | |
227 | QVector3D queriedGraphPosition() const; |
228 | |
229 | void setMargin(qreal margin); |
230 | qreal margin() const; |
231 | |
232 | QMutex *mutex() { return &m_mutex; } |
233 | |
234 | public Q_SLOTS: |
235 | virtual void handleAxisXChanged(QAbstract3DAxis *axis) = 0; |
236 | virtual void handleAxisYChanged(QAbstract3DAxis *axis) = 0; |
237 | virtual void handleAxisZChanged(QAbstract3DAxis *axis) = 0; |
238 | void windowDestroyed(QObject *obj); |
239 | void destroyContext(); |
240 | |
241 | protected: |
242 | virtual void mouseDoubleClickEvent(QMouseEvent *event); |
243 | virtual void touchEvent(QTouchEvent *event); |
244 | virtual void mousePressEvent(QMouseEvent *event); |
245 | virtual void mouseReleaseEvent(QMouseEvent *event); |
246 | virtual void mouseMoveEvent(QMouseEvent *event); |
247 | #if QT_CONFIG(wheelevent) |
248 | virtual void wheelEvent(QWheelEvent *event); |
249 | #endif |
250 | virtual void handleWindowChanged(QQuickWindow *win); |
251 | virtual void itemChange(ItemChange change, const ItemChangeData &value); |
252 | virtual void updateWindowParameters(); |
253 | virtual void handleSelectionModeChange(QAbstract3DGraph::SelectionFlags mode); |
254 | virtual void handleShadowQualityChange(QAbstract3DGraph::ShadowQuality quality); |
255 | virtual void handleSelectedElementChange(QAbstract3DGraph::ElementType type); |
256 | virtual void handleOptimizationHintChange(QAbstract3DGraph::OptimizationHints hints); |
257 | virtual QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *); |
258 | |
259 | Q_SIGNALS: |
260 | void selectionModeChanged(AbstractDeclarative::SelectionFlags mode); |
261 | void shadowQualityChanged(AbstractDeclarative::ShadowQuality quality); |
262 | void shadowsSupportedChanged(bool supported); |
263 | void msaaSamplesChanged(int samples); |
264 | void sceneChanged(Q3DScene *scene); |
265 | void inputHandlerChanged(QAbstract3DInputHandler *inputHandler); |
266 | void themeChanged(Q3DTheme *theme); |
267 | void renderingModeChanged(AbstractDeclarative::RenderingMode mode); |
268 | Q_REVISION(1) void measureFpsChanged(bool enabled); |
269 | Q_REVISION(1) void currentFpsChanged(qreal fps); |
270 | Q_REVISION(1) void selectedElementChanged(AbstractDeclarative::ElementType type); |
271 | Q_REVISION(1) void orthoProjectionChanged(bool enabled); |
272 | Q_REVISION(1) void aspectRatioChanged(qreal ratio); |
273 | Q_REVISION(1) void optimizationHintsChanged(AbstractDeclarative::OptimizationHints hints); |
274 | Q_REVISION(2) void polarChanged(bool enabled); |
275 | Q_REVISION(2) void radialLabelOffsetChanged(float offset); |
276 | Q_REVISION(2) void horizontalAspectRatioChanged(qreal ratio); |
277 | Q_REVISION(2) void reflectionChanged(bool enabled); |
278 | Q_REVISION(2) void reflectivityChanged(qreal reflectivity); |
279 | Q_REVISION(2) void localeChanged(const QLocale &locale); |
280 | Q_REVISION(2) void queriedGraphPositionChanged(const QVector3D &data); |
281 | Q_REVISION(2) void marginChanged(qreal margin); |
282 | |
283 | protected: |
284 | QSharedPointer<QMutex> m_nodeMutex; |
285 | |
286 | private: |
287 | QPointer<Abstract3DController> m_controller; |
288 | QRectF m_cachedGeometry; |
289 | QPointer<QQuickWindow> m_contextWindow; |
290 | AbstractDeclarative::RenderingMode m_renderMode; |
291 | int m_samples; |
292 | int m_windowSamples; |
293 | QSize m_initialisedSize; |
294 | union { |
295 | QObject *m_contextOrStateStore; |
296 | QOpenGLContext *m_context; |
297 | GLStateStore *m_stateStore; |
298 | }; |
299 | QPointer<QOpenGLContext> m_qtContext; |
300 | QThread *m_mainThread; |
301 | QThread *m_contextThread; |
302 | bool m_runningInDesigner; |
303 | QMutex m_mutex; |
304 | }; |
305 | Q_DECLARE_OPERATORS_FOR_FLAGS(AbstractDeclarative::SelectionFlags) |
306 | Q_DECLARE_OPERATORS_FOR_FLAGS(AbstractDeclarative::OptimizationHints) |
307 | |
308 | QT_END_NAMESPACE_DATAVISUALIZATION |
309 | |
310 | #endif |
311 | |