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

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