41 :
public QObjectPrivate,
public QQmlNotifyingBlob::Callback
43 Q_DECLARE_PUBLIC(QQmlComponent)
46 enum class CreateBehavior
52 struct AnnotatedQmlError
54 AnnotatedQmlError() =
default;
55 AnnotatedQmlError(QQmlError error) : error(std::move(error)) {}
56 AnnotatedQmlError(QQmlError error,
bool transient)
57 : error(std::move(error)), isTransient(transient)
62 bool isTransient =
false;
65 struct ConstructionState
68 ConstructionState() =
default;
69 inline ConstructionState(ConstructionState &&other)
noexcept;
70 inline ~ConstructionState();
72 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QQmlComponentPrivate::ConstructionState)
73 void swap(ConstructionState &other)
75 m_creatorOrRequiredProperties.swap(other.m_creatorOrRequiredProperties);
78 inline void ensureRequiredPropertyStorage(QObject *target);
79 inline RequiredProperties *requiredProperties()
const;
80 inline void addPendingRequiredProperty(
81 const QObject *object,
const QQmlPropertyData *propData,
82 const RequiredPropertyInfo &info);
83 inline bool hasUnsetRequiredProperties()
const;
84 inline void clearRequiredProperties();
86 inline void appendErrors(
const QList<QQmlError> &qmlErrors);
87 inline void appendCreatorErrors();
89 inline QQmlObjectCreator *creator();
90 inline const QQmlObjectCreator *creator()
const;
92 inline bool hasCreator()
const;
93 inline QQmlObjectCreator *initCreator(
94 const QQmlRefPointer<QQmlContextData> &parentContext,
95 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &compilationUnit,
96 const QQmlRefPointer<QQmlContextData> &creationContext,
97 const QString &inlineComponentName);
99 QList<AnnotatedQmlError> errors;
100 inline bool isCompletePending()
const;
101 inline void setCompletePending(
bool isPending);
103 QObject *target()
const
105 if (m_creatorOrRequiredProperties.isNull())
108 if (m_creatorOrRequiredProperties.isT1()) {
109 const auto &objects = m_creatorOrRequiredProperties.asT1()->allCreatedObjects();
110 return objects.empty() ?
nullptr : objects.at(0);
113 Q_ASSERT(m_creatorOrRequiredProperties.isT2());
114 return m_creatorOrRequiredProperties.asT2()->target;
118 Q_DISABLE_COPY(ConstructionState)
119 QBiPointer<QQmlObjectCreator, RequiredPropertiesAndTarget> m_creatorOrRequiredProperties;
122 using DeferredState = std::vector<ConstructionState>;
124 void loadUrl(
const QUrl &newUrl,
125 QQmlComponent::CompilationMode mode = QQmlComponent::PreferSynchronous);
127 QQmlType loadedType()
const {
return m_loadHelper ? m_loadHelper->type() : QQmlType(); }
129 QObject *beginCreate(QQmlRefPointer<QQmlContextData>);
130 void completeCreate();
131 void initializeObjectWithInitialProperties(
132 QV4::QmlContext *qmlContext,
const QV4::Value &valuemap, QObject *toCreate,
133 RequiredProperties *requiredProperties);
134 static void setInitialProperties(
135 QV4::ExecutionEngine *engine, QV4::QmlContext *qmlContext,
const QV4::Value &o,
136 const QV4::Value &v, RequiredProperties *requiredProperties, QObject *createdComponent,
137 const QQmlObjectCreator *creator);
138 static QQmlError unsetRequiredPropertyToQQmlError(
139 const RequiredPropertyInfo &unsetRequiredProperty);
141 virtual void incubateObject(
142 QQmlIncubator *incubationTask,
143 QQmlComponent *component,
145 const QQmlRefPointer<QQmlContextData> &context,
146 const QQmlRefPointer<QQmlContextData> &forContext);
148 void ready(QQmlNotifyingBlob *) final;
149 void progress(QQmlNotifyingBlob *, qreal) final;
151 void fromTypeData(
const QQmlRefPointer<QQmlTypeData> &data);
153 bool hadTopLevelRequiredProperties()
const;
155 static void beginDeferred(
156 QQmlEnginePrivate *enginePriv, QObject *object, DeferredState* deferredState);
157 static void completeDeferred(
158 QQmlEnginePrivate *enginePriv, DeferredState *deferredState);
160 static void complete(QQmlEnginePrivate *enginePriv, ConstructionState *state);
161 static QQmlProperty removePropertyFromRequired(
162 QObject *createdComponent,
const QString &name,
163 RequiredProperties *requiredProperties, QQmlEngine *engine,
164 bool *wasInRequiredProperties =
nullptr);
168 static QQmlComponentPrivate *get(QQmlComponent *c) {
169 return static_cast<QQmlComponentPrivate *>(QObjectPrivate::get(c));
172 QObject *doBeginCreate(QQmlComponent *q, QQmlContext *context);
173 bool setInitialProperties(QObject *object,
const QVariantMap &properties);
174 bool setInitialProperty(QObject *component,
const QString &name,
const QVariant& value);
176 QObject *createWithProperties(
177 QObject *parent,
const QVariantMap &properties, QQmlContext *context,
178 CreateBehavior behavior);
180 bool isBound()
const {
return m_compilationUnit && (m_compilationUnit->componentsAreBound()); }
181 void prepareLoadFromModule(
182 QAnyStringView uri, QAnyStringView typeName, QQmlTypeLoader::Mode mode);
183 void completeLoadFromModule(
184 QAnyStringView uri, QAnyStringView typeName);
186 void setProgress(qreal progress)
188 if (progress != m_progress) {
189 m_progress = progress;
190 emit q_func()->progressChanged(progress);
193 void setCreationContext(QQmlRefPointer<QQmlContextData> creationContext)
195 m_creationContext = std::move(creationContext);
198 QQmlType loadHelperType()
const {
return m_loadHelper->type(); }
199 bool hasUnsetRequiredProperties()
const {
return m_state.hasUnsetRequiredProperties(); }
200 RequiredProperties *requiredProperties()
const {
return m_state.requiredProperties(); }
201 const QQmlObjectCreator *creator()
const {
return m_state.creator(); }
203 QQmlEngine *engine()
const {
return m_engine; }
204 QQmlRefPointer<QV4::ExecutableCompilationUnit> compilationUnit()
const
206 return m_compilationUnit;
210 ConstructionState m_state;
211 QQmlGuardedContextData m_creationContext;
213 QQmlRefPointer<QV4::ExecutableCompilationUnit> m_compilationUnit;
214 QQmlRefPointer<QQmlTypeData> m_typeData;
215 QQmlRefPointer<LoadHelper> m_loadHelper;
216 std::unique_ptr<QString> m_inlineComponentName;
217 QQmlEngine *m_engine =
nullptr;
220 qreal m_progress = 0;
223
321inline QQmlObjectCreator *QQmlComponentPrivate::ConstructionState::initCreator(
322 const QQmlRefPointer<QQmlContextData> &parentContext,
323 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &compilationUnit,
324 const QQmlRefPointer<QQmlContextData> &creationContext,
325 const QString &inlineComponentName)
327 if (m_creatorOrRequiredProperties.isT1())
328 delete m_creatorOrRequiredProperties.asT1();
330 delete m_creatorOrRequiredProperties.asT2();
331 m_creatorOrRequiredProperties =
new QQmlObjectCreator(
332 parentContext, compilationUnit, creationContext, inlineComponentName);
333 return m_creatorOrRequiredProperties.asT1();