| 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 | |
| 24 | QT_BEGIN_NAMESPACE |
| 25 | class QQuick3DLoader; |
| 26 | class QQuick3DLoaderIncubator : public QQmlIncubator |
| 27 | { |
| 28 | public: |
| 29 | QQuick3DLoaderIncubator(QQuick3DLoader *l, IncubationMode mode) |
| 30 | : QQmlIncubator(mode), m_loader(l) {} |
| 31 | |
| 32 | protected: |
| 33 | void statusChanged(Status) override; |
| 34 | void setInitialState(QObject *) override; |
| 35 | |
| 36 | private: |
| 37 | QQuick3DLoader *m_loader; |
| 38 | }; |
| 39 | |
| 40 | class QQmlContext; |
| 41 | |
| 42 | class 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 | |
| 56 | public: |
| 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(QQmlV4FunctionPtr); |
| 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 | |
| 82 | Q_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 | |
| 92 | protected: |
| 93 | void componentComplete() override; |
| 94 | |
| 95 | private Q_SLOTS: |
| 96 | void sourceLoaded(); |
| 97 | |
| 98 | private: |
| 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(QQmlV4FunctionPtr args); |
| 111 | QV4::ReturnedValue (QQmlV4FunctionPtr 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 | |
| 128 | QT_END_NAMESPACE |
| 129 | |
| 130 | QML_DECLARE_TYPE(QQuick3DLoader) |
| 131 | |
| 132 | #endif // QQUICK3DLOADER_P_H |
| 133 | |