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 QQMLINCUBATOR_H
41#define QQMLINCUBATOR_H
42
43#include <QtQml/qtqmlglobal.h>
44#include <QtQml/qqmlerror.h>
45#include <atomic>
46
47QT_BEGIN_NAMESPACE
48
49
50class QQmlEngine;
51class QQmlPropertyData;
52class QVariant;
53using QVariantMap = QMap<QString, QVariant>;
54
55class QQmlIncubatorPrivate;
56class Q_QML_EXPORT QQmlIncubator
57{
58 Q_DISABLE_COPY(QQmlIncubator)
59public:
60 enum IncubationMode {
61 Asynchronous,
62 AsynchronousIfNested,
63 Synchronous
64 };
65 enum Status {
66 Null,
67 Ready,
68 Loading,
69 Error
70 };
71
72 QQmlIncubator(IncubationMode = Asynchronous);
73 virtual ~QQmlIncubator();
74
75 void clear();
76 void forceCompletion();
77
78 bool isNull() const;
79 bool isReady() const;
80 bool isError() const;
81 bool isLoading() const;
82
83 QList<QQmlError> errors() const;
84
85 IncubationMode incubationMode() const;
86
87 Status status() const;
88
89 QObject *object() const;
90
91 void setInitialProperties(const QVariantMap &initialProperties);
92
93protected:
94 virtual void statusChanged(Status);
95 virtual void setInitialState(QObject *);
96
97private:
98 friend class QQmlComponent;
99 friend class QQmlEnginePrivate;
100 friend class QQmlIncubatorPrivate;
101 QQmlIncubatorPrivate *d;
102};
103
104class QQmlEnginePrivate;
105class Q_QML_EXPORT QQmlIncubationController
106{
107 Q_DISABLE_COPY(QQmlIncubationController)
108public:
109 QQmlIncubationController();
110 virtual ~QQmlIncubationController();
111
112 QQmlEngine *engine() const;
113 int incubatingObjectCount() const;
114
115 void incubateFor(int msecs);
116#if QT_DEPRECATED_SINCE(5, 15)
117 QT_DEPRECATED_VERSION_X(5, 15, "Use the overload that takes a std::atomic<bool>")
118 void incubateWhile(volatile bool *flag, int msecs=0);
119#endif
120 void incubateWhile(std::atomic<bool> *flag, int msecs = 0);
121
122protected:
123 virtual void incubatingObjectCountChanged(int);
124
125private:
126 friend class QQmlEngine;
127 friend class QQmlEnginePrivate;
128 friend class QQmlIncubatorPrivate;
129 QQmlEnginePrivate *d;
130};
131
132QT_END_NAMESPACE
133
134#endif // QQMLINCUBATOR_H
135

source code of qtdeclarative/src/qml/qml/qqmlincubator.h