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

source code of qtdatavis3d/src/datavisualizationqml/abstractdeclarative_p.h