1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QQMLENGINE_H |
5 | #define QQMLENGINE_H |
6 | |
7 | #include <QtCore/qurl.h> |
8 | #include <QtCore/qobject.h> |
9 | #include <QtCore/qmap.h> |
10 | #include <QtQml/qjsengine.h> |
11 | #include <QtQml/qqml.h> |
12 | #include <QtQml/qqmlerror.h> |
13 | #include <QtQml/qqmlabstracturlinterceptor.h> |
14 | |
15 | QT_BEGIN_NAMESPACE |
16 | |
17 | class Q_QML_EXPORT QQmlImageProviderBase : public QObject |
18 | { |
19 | Q_OBJECT |
20 | public: |
21 | enum ImageType : int { |
22 | Invalid = 0, |
23 | Image, |
24 | Pixmap, |
25 | Texture, |
26 | ImageResponse, |
27 | }; |
28 | |
29 | enum Flag { |
30 | ForceAsynchronousImageLoading = 0x01 |
31 | }; |
32 | Q_DECLARE_FLAGS(Flags, Flag) |
33 | |
34 | virtual ~QQmlImageProviderBase(); |
35 | |
36 | virtual ImageType imageType() const = 0; |
37 | virtual Flags flags() const = 0; |
38 | |
39 | private: |
40 | friend class QQuickImageProvider; |
41 | QQmlImageProviderBase(); |
42 | }; |
43 | Q_DECLARE_OPERATORS_FOR_FLAGS(QQmlImageProviderBase::Flags) |
44 | |
45 | class QQmlComponent; |
46 | class QQmlEnginePrivate; |
47 | class QQmlExpression; |
48 | class QQmlContext; |
49 | class QQmlType; |
50 | class QUrl; |
51 | #if QT_CONFIG(qml_network) |
52 | class QNetworkAccessManager; |
53 | class QQmlNetworkAccessManagerFactory; |
54 | #endif |
55 | class QQmlIncubationController; |
56 | class Q_QML_EXPORT QQmlEngine : public QJSEngine |
57 | { |
58 | Q_PROPERTY(QString offlineStoragePath READ offlineStoragePath WRITE setOfflineStoragePath NOTIFY offlineStoragePathChanged) |
59 | Q_OBJECT |
60 | public: |
61 | explicit QQmlEngine(QObject *p = nullptr); |
62 | ~QQmlEngine() override; |
63 | |
64 | QQmlContext *rootContext() const; |
65 | |
66 | void clearComponentCache(); |
67 | void trimComponentCache(); |
68 | void clearSingletons(); |
69 | |
70 | QStringList importPathList() const; |
71 | void setImportPathList(const QStringList &paths); |
72 | void addImportPath(const QString& dir); |
73 | |
74 | QStringList pluginPathList() const; |
75 | void setPluginPathList(const QStringList &paths); |
76 | void addPluginPath(const QString& dir); |
77 | |
78 | #if QT_DEPRECATED_SINCE(6, 0) |
79 | QT_DEPRECATED bool addNamedBundle(const QString &, const QString &) { return false; } |
80 | #endif |
81 | |
82 | #if QT_CONFIG(library) |
83 | #if QT_DEPRECATED_SINCE(6, 4) |
84 | QT_DEPRECATED_VERSION_X_6_4("Import the module from QML instead" ) |
85 | bool importPlugin(const QString &filePath, const QString &uri, QList<QQmlError> *errors); |
86 | #endif |
87 | #endif |
88 | |
89 | #if QT_CONFIG(qml_network) |
90 | void setNetworkAccessManagerFactory(QQmlNetworkAccessManagerFactory *); |
91 | QQmlNetworkAccessManagerFactory *networkAccessManagerFactory() const; |
92 | |
93 | QNetworkAccessManager *networkAccessManager() const; |
94 | #endif |
95 | |
96 | #if QT_DEPRECATED_SINCE(6, 0) |
97 | QT_DEPRECATED void setUrlInterceptor(QQmlAbstractUrlInterceptor* urlInterceptor) |
98 | { |
99 | addUrlInterceptor(urlInterceptor); |
100 | } |
101 | QT_DEPRECATED QQmlAbstractUrlInterceptor *urlInterceptor() const; |
102 | #endif |
103 | |
104 | void addUrlInterceptor(QQmlAbstractUrlInterceptor *urlInterceptor); |
105 | void removeUrlInterceptor(QQmlAbstractUrlInterceptor *urlInterceptor); |
106 | QList<QQmlAbstractUrlInterceptor *> urlInterceptors() const; |
107 | QUrl interceptUrl(const QUrl &url, QQmlAbstractUrlInterceptor::DataType type) const; |
108 | |
109 | void addImageProvider(const QString &id, QQmlImageProviderBase *); |
110 | QQmlImageProviderBase *imageProvider(const QString &id) const; |
111 | void removeImageProvider(const QString &id); |
112 | |
113 | void setIncubationController(QQmlIncubationController *); |
114 | QQmlIncubationController *incubationController() const; |
115 | |
116 | void setOfflineStoragePath(const QString& dir); |
117 | QString offlineStoragePath() const; |
118 | QString offlineStorageDatabaseFilePath(const QString &databaseName) const; |
119 | |
120 | QUrl baseUrl() const; |
121 | void setBaseUrl(const QUrl &); |
122 | |
123 | bool outputWarningsToStandardError() const; |
124 | void setOutputWarningsToStandardError(bool); |
125 | |
126 | void markCurrentFunctionAsTranslationBinding(); |
127 | |
128 | template<typename T> |
129 | T singletonInstance(int qmlTypeId); |
130 | |
131 | template<typename T> |
132 | T singletonInstance(QAnyStringView moduleName, QAnyStringView typeName); |
133 | |
134 | void captureProperty(QObject *object, const QMetaProperty &property) const; |
135 | |
136 | public Q_SLOTS: |
137 | void retranslate(); |
138 | |
139 | Q_SIGNALS: |
140 | void offlineStoragePathChanged(); |
141 | |
142 | public: |
143 | static QQmlContext *contextForObject(const QObject *); |
144 | static void setContextForObject(QObject *, QQmlContext *); |
145 | |
146 | protected: |
147 | QQmlEngine(QQmlEnginePrivate &dd, QObject *p); |
148 | bool event(QEvent *) override; |
149 | |
150 | Q_SIGNALS: |
151 | void quit(); |
152 | void exit(int retCode); |
153 | void warnings(const QList<QQmlError> &warnings); |
154 | |
155 | private: |
156 | Q_DISABLE_COPY(QQmlEngine) |
157 | Q_DECLARE_PRIVATE(QQmlEngine) |
158 | }; |
159 | |
160 | template<> |
161 | Q_QML_EXPORT QJSValue QQmlEngine::singletonInstance<QJSValue>(int qmlTypeId); |
162 | |
163 | template<typename T> |
164 | T QQmlEngine::singletonInstance(int qmlTypeId) { |
165 | return qobject_cast<T>(singletonInstance<QJSValue>(qmlTypeId).toQObject()); |
166 | } |
167 | |
168 | template<> |
169 | Q_QML_EXPORT QJSValue QQmlEngine::singletonInstance<QJSValue>(QAnyStringView uri, QAnyStringView typeName); |
170 | |
171 | template<typename T> |
172 | T QQmlEngine::singletonInstance(QAnyStringView uri, QAnyStringView typeName) |
173 | { |
174 | return qobject_cast<T>(singletonInstance<QJSValue>(uri, typeName).toQObject()); |
175 | } |
176 | |
177 | QT_END_NAMESPACE |
178 | |
179 | #endif // QQMLENGINE_H |
180 | |