1// Copyright (C) 2019 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef QQUICK3DLOADER_P_H
5#define QQUICK3DLOADER_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtQuick3D/private/qquick3dnode_p.h>
19#include <QQmlIncubator>
20#include <private/qqmlguard_p.h>
21
22#include <private/qv4value_p.h>
23
24QT_BEGIN_NAMESPACE
25class QQuick3DLoader;
26class QQuick3DLoaderIncubator : public QQmlIncubator
27{
28public:
29 QQuick3DLoaderIncubator(QQuick3DLoader *l, IncubationMode mode)
30 : QQmlIncubator(mode), m_loader(l) {}
31
32protected:
33 void statusChanged(Status) override;
34 void setInitialState(QObject *) override;
35
36private:
37 QQuick3DLoader *m_loader;
38};
39
40class QQmlContext;
41
42class Q_QUICK3D_EXPORT QQuick3DLoader : public QQuick3DNode
43{
44 Q_OBJECT
45
46 Q_PROPERTY(bool active READ active WRITE setActive NOTIFY activeChanged)
47 Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
48 Q_PROPERTY(QQmlComponent *sourceComponent READ sourceComponent WRITE setSourceComponent RESET resetSourceComponent NOTIFY sourceComponentChanged)
49 Q_PROPERTY(QObject *item READ item NOTIFY itemChanged)
50 Q_PROPERTY(Status status READ status NOTIFY statusChanged)
51 Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged)
52 Q_PROPERTY(bool asynchronous READ asynchronous WRITE setAsynchronous NOTIFY asynchronousChanged)
53
54 QML_NAMED_ELEMENT(Loader3D)
55
56public:
57 explicit QQuick3DLoader(QQuick3DNode *parent = nullptr);
58 ~QQuick3DLoader() override;
59
60 bool active() const;
61 void setActive(bool newVal);
62
63 Q_INVOKABLE void setSource(QQmlV4Function *);
64
65 QUrl source() const;
66 void setSource(const QUrl &);
67
68 QQmlComponent *sourceComponent() const;
69 void setSourceComponent(QQmlComponent *);
70 void resetSourceComponent();
71
72 enum Status { Null, Ready, Loading, Error };
73 Q_ENUM(Status)
74 Status status() const;
75 qreal progress() const;
76
77 bool asynchronous() const;
78 void setAsynchronous(bool a);
79
80 QObject *item() const;
81
82Q_SIGNALS:
83 void itemChanged();
84 void activeChanged();
85 void sourceChanged();
86 void sourceComponentChanged();
87 void statusChanged();
88 void progressChanged();
89 void loaded();
90 void asynchronousChanged();
91
92protected:
93 void componentComplete() override;
94
95private Q_SLOTS:
96 void sourceLoaded();
97
98private:
99 Q_DISABLE_COPY(QQuick3DLoader)
100 friend QQuick3DLoaderIncubator;
101 void setSource(const QUrl &sourceUrl, bool needsClear);
102 void loadFromSource();
103 void loadFromSourceComponent();
104 void clear();
105 void load();
106
107 void incubatorStateChanged(QQmlIncubator::Status status);
108 void setInitialState(QObject *obj);
109 void disposeInitialPropertyValues();
110 static QUrl resolveSourceUrl(QQmlV4Function *args);
111 QV4::ReturnedValue extractInitialPropertyValues(QQmlV4Function *args, bool *error);
112
113 void createComponent();
114
115 QUrl m_source;
116 QQuick3DNode *m_item;
117 QObject *m_object;
118 QQmlStrongJSQObjectReference<QQmlComponent> m_component;
119 QQmlContext *m_itemContext;
120 QQuick3DLoaderIncubator *m_incubator;
121 QV4::PersistentValue m_initialPropertyValues;
122 QV4::PersistentValue m_qmlCallingContext;
123 bool m_active : 1;
124 bool m_loadingFromSource : 1;
125 bool m_asynchronous : 1;
126};
127
128QT_END_NAMESPACE
129
130QML_DECLARE_TYPE(QQuick3DLoader)
131
132#endif // QQUICK3DLOADER_P_H
133

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