40 :
public QObjectPrivate,
public QQmlNotifyingBlob::Callback
42 Q_DECLARE_PUBLIC(QQmlComponent)
48 CreateWarnAboutRequiredProperties,
51 struct AnnotatedQmlError
53 AnnotatedQmlError() =
default;
54 AnnotatedQmlError(QQmlError error) : error(std::move(error)) {}
55 AnnotatedQmlError(QQmlError error,
bool transient)
56 : error(std::move(error)), isTransient(transient)
61 bool isTransient =
false;
64 struct ConstructionState
67 ConstructionState() =
default;
68 inline ConstructionState(ConstructionState &&other)
noexcept;
69 inline ~ConstructionState();
71 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QQmlComponentPrivate::ConstructionState)
72 void swap(ConstructionState &other)
74 m_creatorOrRequiredProperties.swap(other.m_creatorOrRequiredProperties);
77 inline void ensureRequiredPropertyStorage(QObject *target);
78 inline RequiredProperties *requiredProperties()
const;
79 inline void addPendingRequiredProperty(
80 const QObject *object,
const QQmlPropertyData *propData,
81 const RequiredPropertyInfo &info);
82 inline bool hasUnsetRequiredProperties()
const;
83 inline void clearRequiredProperties();
85 inline void appendErrors(
const QList<QQmlError> &qmlErrors);
86 inline void appendCreatorErrors();
88 inline QQmlObjectCreator *creator();
89 inline const QQmlObjectCreator *creator()
const;
91 inline bool hasCreator()
const;
92 inline QQmlObjectCreator *initCreator(
93 const QQmlRefPointer<QQmlContextData> &parentContext,
94 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &compilationUnit,
95 const QQmlRefPointer<QQmlContextData> &creationContext,
96 const QString &inlineComponentName);
98 QList<AnnotatedQmlError> errors;
99 inline bool isCompletePending()
const;
100 inline void setCompletePending(
bool isPending);
102 QObject *target()
const
104 if (m_creatorOrRequiredProperties.isNull())
107 if (m_creatorOrRequiredProperties.isT1()) {
108 const auto &objects = m_creatorOrRequiredProperties.asT1()->allCreatedObjects();
109 return objects.empty() ?
nullptr : objects.at(0);
112 Q_ASSERT(m_creatorOrRequiredProperties.isT2());
113 return m_creatorOrRequiredProperties.asT2()->target;
117 Q_DISABLE_COPY(ConstructionState)
118 QBiPointer<QQmlObjectCreator, RequiredPropertiesAndTarget> m_creatorOrRequiredProperties;
121 using DeferredState = std::vector<ConstructionState>;
123 void loadUrl(
const QUrl &newUrl,
124 QQmlComponent::CompilationMode mode = QQmlComponent::PreferSynchronous);
126 QQmlType loadedType()
const {
return m_loadHelper ? m_loadHelper->type() : QQmlType(); }
128 QObject *beginCreate(QQmlRefPointer<QQmlContextData>);
129 void completeCreate();
130 void initializeObjectWithInitialProperties(
131 QV4::QmlContext *qmlContext,
const QV4::Value &valuemap, QObject *toCreate,
132 RequiredProperties *requiredProperties);
133 static void setInitialProperties(
134 QV4::ExecutionEngine *engine, QV4::QmlContext *qmlContext,
const QV4::Value &o,
135 const QV4::Value &v, RequiredProperties *requiredProperties, QObject *createdComponent,
136 const QQmlObjectCreator *creator);
137 static QQmlError unsetRequiredPropertyToQQmlError(
138 const RequiredPropertyInfo &unsetRequiredProperty);
140 virtual void incubateObject(
141 QQmlIncubator *incubationTask,
142 QQmlComponent *component,
144 const QQmlRefPointer<QQmlContextData> &context,
145 const QQmlRefPointer<QQmlContextData> &forContext);
147 void ready(QQmlNotifyingBlob *) final;
148 void progress(QQmlNotifyingBlob *, qreal) final;
150 void fromTypeData(
const QQmlRefPointer<QQmlTypeData> &data);
152 bool hadTopLevelRequiredProperties()
const;
154 static void beginDeferred(
155 QQmlEnginePrivate *enginePriv, QObject *object, DeferredState* deferredState);
156 static void completeDeferred(
157 QQmlEnginePrivate *enginePriv, DeferredState *deferredState);
159 static void complete(QQmlEnginePrivate *enginePriv, ConstructionState *state);
160 static QQmlProperty removePropertyFromRequired(
161 QObject *createdComponent,
const QString &name,
162 RequiredProperties *requiredProperties, QQmlEngine *engine,
163 bool *wasInRequiredProperties =
nullptr);
167 static QQmlComponentPrivate *get(QQmlComponent *c) {
168 return static_cast<QQmlComponentPrivate *>(QObjectPrivate::get(c));
171 QObject *doBeginCreate(QQmlComponent *q, QQmlContext *context);
172 bool setInitialProperty(QObject *component,
const QString &name,
const QVariant& value);
174 QObject *createWithProperties(QObject *parent,
const QVariantMap &properties,
175 QQmlContext *context, CreateBehavior behavior = CreateDefault,
176 bool createFromQml =
false);
178 bool isBound()
const {
return m_compilationUnit && (m_compilationUnit->componentsAreBound()); }
179 void prepareLoadFromModule(
180 QAnyStringView uri, QAnyStringView typeName, QQmlTypeLoader::Mode mode);
181 void completeLoadFromModule(
182 QAnyStringView uri, QAnyStringView typeName);
184 void setProgress(qreal progress)
186 if (progress != m_progress) {
187 m_progress = progress;
188 emit q_func()->progressChanged(progress);
191 void setCreationContext(QQmlRefPointer<QQmlContextData> creationContext)
193 m_creationContext = std::move(creationContext);
196 QQmlType loadHelperType()
const {
return m_loadHelper->type(); }
197 bool hasUnsetRequiredProperties()
const {
return m_state.hasUnsetRequiredProperties(); }
198 RequiredProperties *requiredProperties()
const {
return m_state.requiredProperties(); }
199 const QQmlObjectCreator *creator()
const {
return m_state.creator(); }
201 QQmlEngine *engine()
const {
return m_engine; }
202 QQmlRefPointer<QV4::ExecutableCompilationUnit> compilationUnit()
const
204 return m_compilationUnit;
208 ConstructionState m_state;
209 QQmlGuardedContextData m_creationContext;
211 QQmlRefPointer<QV4::ExecutableCompilationUnit> m_compilationUnit;
212 QQmlRefPointer<QQmlTypeData> m_typeData;
213 QQmlRefPointer<LoadHelper> m_loadHelper;
214 std::unique_ptr<QString> m_inlineComponentName;
215 QQmlEngine *m_engine =
nullptr;
218 qreal m_progress = 0;
221
319inline QQmlObjectCreator *QQmlComponentPrivate::ConstructionState::initCreator(
320 const QQmlRefPointer<QQmlContextData> &parentContext,
321 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &compilationUnit,
322 const QQmlRefPointer<QQmlContextData> &creationContext,
323 const QString &inlineComponentName)
325 if (m_creatorOrRequiredProperties.isT1())
326 delete m_creatorOrRequiredProperties.asT1();
328 delete m_creatorOrRequiredProperties.asT2();
329 m_creatorOrRequiredProperties =
new QQmlObjectCreator(
330 parentContext, compilationUnit, creationContext, inlineComponentName);
331 return m_creatorOrRequiredProperties.asT1();