KDeclarative

qmlobject.h
1 /*
2  SPDX-FileCopyrightText: 2013 Marco Martin <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #ifndef QMLOBJECT_H
8 #define QMLOBJECT_H
9 
10 #include <QObject>
11 
12 #include <QQmlComponent>
13 
14 #include <KPackage/Package>
15 #include <kdeclarative/kdeclarative_export.h>
16 
17 class QQmlEngine;
18 class QQmlComponent;
19 class QQmlContext;
20 
21 namespace KDeclarative {
22 
23 class QmlObjectPrivate;
24 
38 class KDECLARATIVE_EXPORT QmlObject : public QObject
39 {
40  Q_OBJECT
41 
42  Q_PROPERTY(QUrl source READ source WRITE setSource)
43  Q_PROPERTY(QString translationDomain READ translationDomain WRITE setTranslationDomain)
44  Q_PROPERTY(bool initializationDelayed READ isInitializationDelayed WRITE setInitializationDelayed)
45  Q_PROPERTY(QObject *rootObject READ rootObject)
46  Q_PROPERTY(QQmlComponent::Status status READ status NOTIFY statusChanged)
47 
48 public:
49 
55  explicit QmlObject(QObject *parent = nullptr);
56 
63  explicit QmlObject(QQmlEngine *engine, QObject *parent = nullptr);
64 
72  explicit QmlObject(QQmlEngine *engine, QQmlContext *rootContext, QObject *parent = nullptr);
73  ~QmlObject();
74 
91  void setTranslationDomain(const QString &translationDomain);
92 
97  QString translationDomain() const;
98 
104  void setSource(const QUrl &source);
105 
109  QUrl source() const;
110 
117  void loadPackage(const QString &packageName);
118 
126  void setPackage(const KPackage::Package &package);
127 
131  KPackage::Package package() const;
132 
144  void setInitializationDelayed(const bool delay);
145 
150  bool isInitializationDelayed() const;
151 
155  QQmlEngine *engine();
156 
160  QObject *rootObject() const;
161 
165  QQmlComponent *mainComponent() const;
166 
171  QQmlContext *rootContext() const;
172 
177  QQmlComponent::Status status() const;
178 
190  QObject *createObjectFromSource(const QUrl &source, QQmlContext *context = nullptr, const QVariantHash &initialProperties = QVariantHash());
191 
203  QObject *createObjectFromComponent(QQmlComponent *component, QQmlContext *context = nullptr, const QVariantHash &initialProperties = QVariantHash());
204 
205 public Q_SLOTS:
213  void completeInitialization(const QVariantHash &initialProperties = QVariantHash());
214 
215 Q_SIGNALS:
219  void finished();
220 
221  void statusChanged(QQmlComponent::Status);
222 
223 protected:
235  explicit QmlObject(QQmlEngine *engine, QQmlContext *rootContext, QmlObject *obj, QObject *parent = nullptr);
236 
237 private:
238  friend class QmlObjectPrivate;
239  QmlObjectPrivate *const d;
240 
241  Q_PRIVATE_SLOT(d, void scheduleExecutionEnd())
242  Q_PRIVATE_SLOT(d, void checkInitializationCompleted())
243 };
244 
245 }
246 
247 #endif // multiple inclusion guard
An object that instantiates an entire QML context, with its own declarative engine.
Definition: qmlobject.h:38
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Jan 19 2021 22:41:07 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.