1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtQml module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #ifndef QQMLCOMPONENT_H |
41 | #define QQMLCOMPONENT_H |
42 | |
43 | #include <QtQml/qqml.h> |
44 | #include <QtQml/qqmlerror.h> |
45 | |
46 | #include <QtCore/qobject.h> |
47 | #include <QtCore/qstring.h> |
48 | #include <QtQml/qjsvalue.h> |
49 | |
50 | QT_BEGIN_NAMESPACE |
51 | |
52 | |
53 | class QByteArray; |
54 | class QQmlEngine; |
55 | class QQmlComponent; |
56 | class QQmlIncubator; |
57 | class QQmlV4Function; |
58 | class QQmlComponentPrivate; |
59 | class QQmlComponentAttached; |
60 | |
61 | namespace QV4 { |
62 | class ExecutableCompilationUnit; |
63 | } |
64 | |
65 | class Q_QML_EXPORT QQmlComponent : public QObject |
66 | { |
67 | Q_OBJECT |
68 | Q_DECLARE_PRIVATE(QQmlComponent) |
69 | |
70 | Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) |
71 | Q_PROPERTY(Status status READ status NOTIFY statusChanged) |
72 | Q_PROPERTY(QUrl url READ url CONSTANT) |
73 | |
74 | public: |
75 | enum CompilationMode { PreferSynchronous, Asynchronous }; |
76 | Q_ENUM(CompilationMode) |
77 | |
78 | QQmlComponent(QObject *parent = nullptr); |
79 | QQmlComponent(QQmlEngine *, QObject *parent = nullptr); |
80 | QQmlComponent(QQmlEngine *, const QString &fileName, QObject *parent = nullptr); |
81 | QQmlComponent(QQmlEngine *, const QString &fileName, CompilationMode mode, QObject *parent = nullptr); |
82 | QQmlComponent(QQmlEngine *, const QUrl &url, QObject *parent = nullptr); |
83 | QQmlComponent(QQmlEngine *, const QUrl &url, CompilationMode mode, QObject *parent = nullptr); |
84 | ~QQmlComponent() override; |
85 | |
86 | enum Status { Null, Ready, Loading, Error }; |
87 | Q_ENUM(Status) |
88 | Status status() const; |
89 | |
90 | bool isNull() const; |
91 | bool isReady() const; |
92 | bool isError() const; |
93 | bool isLoading() const; |
94 | |
95 | QList<QQmlError> errors() const; |
96 | Q_INVOKABLE QString errorString() const; |
97 | |
98 | qreal progress() const; |
99 | |
100 | QUrl url() const; |
101 | |
102 | virtual QObject *create(QQmlContext *context = nullptr); |
103 | virtual QObject *beginCreate(QQmlContext *); |
104 | virtual void completeCreate(); |
105 | |
106 | void create(QQmlIncubator &, QQmlContext *context = nullptr, |
107 | QQmlContext *forContext = nullptr); |
108 | |
109 | QQmlContext *creationContext() const; |
110 | QQmlEngine *engine() const; |
111 | |
112 | static QQmlComponentAttached *qmlAttachedProperties(QObject *); |
113 | |
114 | public Q_SLOTS: |
115 | void loadUrl(const QUrl &url); |
116 | void loadUrl(const QUrl &url, CompilationMode mode); |
117 | void setData(const QByteArray &, const QUrl &baseUrl); |
118 | |
119 | Q_SIGNALS: |
120 | void statusChanged(QQmlComponent::Status); |
121 | void progressChanged(qreal); |
122 | |
123 | protected: |
124 | QQmlComponent(QQmlComponentPrivate &dd, QObject* parent); |
125 | Q_INVOKABLE void createObject(QQmlV4Function *); |
126 | Q_INVOKABLE void incubateObject(QQmlV4Function *); |
127 | |
128 | private: |
129 | QQmlComponent(QQmlEngine *, QV4::ExecutableCompilationUnit *compilationUnit, int, |
130 | QObject *parent); |
131 | |
132 | Q_DISABLE_COPY(QQmlComponent) |
133 | friend class QQmlTypeData; |
134 | friend class QQmlObjectCreator; |
135 | }; |
136 | |
137 | QT_END_NAMESPACE |
138 | |
139 | QML_DECLARE_TYPE(QQmlComponent) |
140 | QML_DECLARE_TYPEINFO(QQmlComponent, QML_HAS_ATTACHED_PROPERTIES) |
141 | |
142 | #endif // QQMLCOMPONENT_H |
143 | |