1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef Q_QUICK3D_OBJECT_H
5#define Q_QUICK3D_OBJECT_H
6
7#include <QtQuick3D/qtquick3dglobal.h>
8
9#include <QtQml/qqml.h>
10#include <QtQml/qqmlcomponent.h>
11
12#include <QtCore/QObject>
13#include <QtCore/qsharedpointer.h>
14
15QT_BEGIN_NAMESPACE
16
17class QQuick3DObjectPrivate;
18class QQuick3DSceneManager;
19class QSSGRenderGraphObject;
20
21class Q_QUICK3D_EXPORT QQuick3DObject : public QObject, public QQmlParserStatus
22{
23 Q_OBJECT
24 Q_INTERFACES(QQmlParserStatus)
25 Q_DECLARE_PRIVATE(QQuick3DObject)
26 Q_DISABLE_COPY(QQuick3DObject)
27
28 Q_PROPERTY(QQuick3DObject *parent READ parentItem WRITE setParentItem NOTIFY parentChanged DESIGNABLE false FINAL)
29 Q_PRIVATE_PROPERTY(QQuick3DObject::d_func(), QQmlListProperty<QObject> data READ data DESIGNABLE false)
30 Q_PRIVATE_PROPERTY(QQuick3DObject::d_func(), QQmlListProperty<QObject> resources READ resources DESIGNABLE false)
31 Q_PRIVATE_PROPERTY(QQuick3DObject::d_func(),
32 QQmlListProperty<QQuick3DObject> children READ children NOTIFY childrenChanged DESIGNABLE false)
33
34 Q_PRIVATE_PROPERTY(QQuick3DObject::d_func(), QQmlListProperty<QQuickState> states READ states DESIGNABLE false)
35 Q_PRIVATE_PROPERTY(QQuick3DObject::d_func(), QQmlListProperty<QQuickTransition> transitions READ transitions DESIGNABLE false)
36 Q_PROPERTY(QString state READ state WRITE setState NOTIFY stateChanged)
37
38 Q_CLASSINFO("DefaultProperty", "data")
39 Q_CLASSINFO("qt_QmlJSWrapperFactoryMethod", "_q_createJSWrapper(QV4::ExecutionEngine*)")
40
41 QML_NAMED_ELEMENT(Object3D)
42 QML_UNCREATABLE("Object3D is Abstract")
43public:
44 enum ItemChange {
45 ItemChildAddedChange, // value.item
46 ItemChildRemovedChange, // value.item
47 ItemSceneChange, // value.window
48 ItemVisibleHasChanged, // value.boolValue
49 ItemParentHasChanged, // value.item
50 ItemOpacityHasChanged, // value.realValue
51 ItemActiveFocusHasChanged, // value.boolValue
52 ItemRotationHasChanged, // value.realValue
53 ItemAntialiasingHasChanged, // value.boolValue
54 ItemDevicePixelRatioHasChanged, // value.realValue
55 ItemEnabledHasChanged // value.boolValue
56 };
57
58 union ItemChangeData {
59 ItemChangeData(QQuick3DObject *v) : item(v) {}
60 ItemChangeData(QQuick3DSceneManager *v) : sceneManager(v) {}
61 ItemChangeData(qreal v) : realValue(v) {}
62 ItemChangeData(bool v) : boolValue(v) {}
63
64 QQuick3DObject *item;
65 QQuick3DSceneManager *sceneManager;
66 qreal realValue;
67 bool boolValue;
68 };
69
70 explicit QQuick3DObject(QQuick3DObject *parent = nullptr);
71 ~QQuick3DObject() override;
72
73 QString state() const;
74 void setState(const QString &state);
75
76 QList<QQuick3DObject *> childItems() const;
77
78 QQuick3DObject *parentItem() const;
79
80public Q_SLOTS:
81 void update();
82
83 void setParentItem(QQuick3DObject *parentItem);
84
85Q_SIGNALS:
86 void parentChanged();
87 void childrenChanged();
88 void stateChanged();
89
90protected:
91 virtual QSSGRenderGraphObject *updateSpatialNode(QSSGRenderGraphObject *node);
92 virtual void markAllDirty();
93 virtual void itemChange(ItemChange, const ItemChangeData &);
94 explicit QQuick3DObject(QQuick3DObjectPrivate &dd, QQuick3DObject *parent = nullptr);
95
96 void classBegin() override;
97 void componentComplete() override;
98
99 bool isComponentComplete() const;
100
101 virtual void preSync();
102
103private:
104 Q_PRIVATE_SLOT(d_func(), void _q_resourceObjectDeleted(QObject *))
105 Q_PRIVATE_SLOT(d_func(), quint64 _q_createJSWrapper(QV4::ExecutionEngine *))
106 Q_PRIVATE_SLOT(d_func(), void _q_cleanupContentItem2D())
107
108 friend class QQuick3DSceneManager;
109};
110
111QT_END_NAMESPACE
112
113QML_DECLARE_TYPE(QQuick3DObject)
114
115#endif // Q_QUICK3D_OBJECT_H
116

source code of qtquick3d/src/quick3d/qquick3dobject.h