QT_BEGIN_NAMESPACE
QSGLoaderPrivate::QSGLoaderPrivate()
- : item(0), component(0), ownComponent(false), updatingSize(false),
- itemWidthValid(false), itemHeightValid(false), active(true)
+ : item(0), component(0), updatingSize(false),
+ itemWidthValid(false), itemHeightValid(false),
+ active(true), loadingFromSource(false)
{
}
{
disposeInitialPropertyValues();
- if (ownComponent) {
+ if (loadingFromSource && component) {
component->deleteLater();
component = 0;
- ownComponent = false;
}
source = QUrl();
return;
}
- d->component = new QDeclarativeComponent(qmlEngine(this), d->source, this);
- d->ownComponent = true;
-
- if (isComponentComplete())
+ if (isComponentComplete()) {
+ d->component = new QDeclarativeComponent(qmlEngine(this), d->source, this);
d->load();
+ }
}
/*!
d->clear();
d->component = comp;
- d->ownComponent = false;
d->loadingFromSource = false;
if (d->active)
q, SIGNAL(progressChanged()));
emit q->statusChanged();
emit q->progressChanged();
- if (ownComponent)
+ if (loadingFromSource)
emit q->sourceChanged();
else
emit q->sourceComponentChanged();
if (component) {
if (!component->errors().isEmpty()) {
QDeclarativeEnginePrivate::warning(qmlEngine(q), component->errors());
- if (ownComponent)
+ if (loadingFromSource)
emit q->sourceChanged();
else
emit q->sourceComponentChanged();
source = QUrl();
}
completeCreateWithInitialPropertyValues(component, obj, initialPropertyValues, qmlGlobalForIpv);
- if (ownComponent)
+ if (loadingFromSource)
emit q->sourceChanged();
else
emit q->sourceComponentChanged();
{
Q_D(QSGLoader);
QSGItem::componentComplete();
- d->load();
+ if (active()) {
+ if (d->loadingFromSource) {
+ d->component = new QDeclarativeComponent(qmlEngine(this), d->source, this);
+ }
+ d->load();
+ }
}
/*!
QCOMPARE(static_cast<QSGItem*>(loader)->childItems().count(), error ? 0: 1);
if (!error) {
- QDeclarativeComponent *c = qobject_cast<QDeclarativeComponent*>(loader->children().at(0));
- QVERIFY(c);
- QCOMPARE(loader->sourceComponent(), c);
+ bool sourceComponentIsChildOfLoader = false;
+ for (int ii = 0; ii < loader->children().size(); ++ii) {
+ QDeclarativeComponent *c = qobject_cast<QDeclarativeComponent*>(loader->children().at(ii));
+ if (c && c == loader->sourceComponent()) {
+ sourceComponentIsChildOfLoader = true;
+ }
+ }
+ QVERIFY(sourceComponentIsChildOfLoader);
}
if (sourceOrComponent == "component") {
delete object;
}
+
+ // check that the component isn't loaded until active is set to true
+ {
+ QDeclarativeComponent component(&engine, TEST_FILE("active.7.qml"));
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+ QCOMPARE(object->property("success").toBool(), true);
+ delete object;
+ }
+
+ // check that the component is loaded if active is not set (true by default)
+ {
+ QDeclarativeComponent component(&engine, TEST_FILE("active.8.qml"));
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+ QCOMPARE(object->property("success").toBool(), true);
+ delete object;
+ }
}
void tst_QSGLoader::initialPropertyValues_data()