summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBea Lam <bea.lam@nokia.com>2011-01-21 01:39:28 (GMT)
committerJason McDonald <jason.mcdonald@nokia.com>2011-01-21 07:44:08 (GMT)
commit91700dfbd9e3d8e1cbd0536a39becad2e41b1861 (patch)
tree0fb872274bb4ffcb1837db22aec67947e3fc9840
parentdab56893758aaa5e7ecfd2a9765f7397795b46d8 (diff)
downloadQt-91700dfbd9e3d8e1cbd0536a39becad2e41b1861.zip
Qt-91700dfbd9e3d8e1cbd0536a39becad2e41b1861.tar.gz
Qt-91700dfbd9e3d8e1cbd0536a39becad2e41b1861.tar.bz2
Revert "Fix loaded() signal to be emitted only once"
This reverts commit 82ff3f484c7ec49e60b7fddf23794937974a6768. QTBUG-16796 reports that this commit is causing regressions relating to initial sizing of items. Task-number: QTBUG-16796 (cherry picked from commit 8c3086aa36b51a9731fce8eb8146b33ab8196aed)
-rw-r--r--src/declarative/graphicsitems/qdeclarativeloader.cpp60
-rw-r--r--src/declarative/graphicsitems/qdeclarativeloader_p_p.h2
-rw-r--r--tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp94
3 files changed, 67 insertions, 89 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativeloader.cpp b/src/declarative/graphicsitems/qdeclarativeloader.cpp
index 86e438f..ded2be3 100644
--- a/src/declarative/graphicsitems/qdeclarativeloader.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeloader.cpp
@@ -48,7 +48,7 @@
QT_BEGIN_NAMESPACE
QDeclarativeLoaderPrivate::QDeclarativeLoaderPrivate()
- : item(0), component(0), ownComponent(false), isComponentComplete(false)
+ : item(0), component(0), ownComponent(false)
{
}
@@ -262,7 +262,6 @@ void QDeclarativeLoader::setSource(const QUrl &url)
d->clear();
d->source = url;
-
if (d->source.isEmpty()) {
emit sourceChanged();
emit statusChanged();
@@ -273,9 +272,18 @@ void QDeclarativeLoader::setSource(const QUrl &url)
d->component = new QDeclarativeComponent(qmlEngine(this), d->source, this);
d->ownComponent = true;
-
- if (d->isComponentComplete)
- d->load();
+ if (!d->component->isLoading()) {
+ d->_q_sourceLoaded();
+ } else {
+ connect(d->component, SIGNAL(statusChanged(QDeclarativeComponent::Status)),
+ this, SLOT(_q_sourceLoaded()));
+ connect(d->component, SIGNAL(progressChanged(qreal)),
+ this, SIGNAL(progressChanged()));
+ emit statusChanged();
+ emit progressChanged();
+ emit sourceChanged();
+ emit itemChanged();
+ }
}
/*!
@@ -316,7 +324,6 @@ void QDeclarativeLoader::setSourceComponent(QDeclarativeComponent *comp)
d->component = comp;
d->ownComponent = false;
-
if (!d->component) {
emit sourceChanged();
emit statusChanged();
@@ -325,8 +332,18 @@ void QDeclarativeLoader::setSourceComponent(QDeclarativeComponent *comp)
return;
}
- if (d->isComponentComplete)
- d->load();
+ if (!d->component->isLoading()) {
+ d->_q_sourceLoaded();
+ } else {
+ connect(d->component, SIGNAL(statusChanged(QDeclarativeComponent::Status)),
+ this, SLOT(_q_sourceLoaded()));
+ connect(d->component, SIGNAL(progressChanged(qreal)),
+ this, SIGNAL(progressChanged()));
+ emit progressChanged();
+ emit sourceChanged();
+ emit statusChanged();
+ emit itemChanged();
+ }
}
void QDeclarativeLoader::resetSourceComponent()
@@ -334,27 +351,6 @@ void QDeclarativeLoader::resetSourceComponent()
setSourceComponent(0);
}
-void QDeclarativeLoaderPrivate::load()
-{
- Q_Q(QDeclarativeLoader);
-
- if (!isComponentComplete || !component)
- return;
-
- if (!component->isLoading()) {
- _q_sourceLoaded();
- } else {
- QObject::connect(component, SIGNAL(statusChanged(QDeclarativeComponent::Status)),
- q, SLOT(_q_sourceLoaded()));
- QObject::connect(component, SIGNAL(progressChanged(qreal)),
- q, SIGNAL(progressChanged()));
- emit q->statusChanged();
- emit q->progressChanged();
- emit q->sourceChanged();
- emit q->itemChanged();
- }
-}
-
void QDeclarativeLoaderPrivate::_q_sourceLoaded()
{
Q_Q(QDeclarativeLoader);
@@ -469,11 +465,9 @@ QDeclarativeLoader::Status QDeclarativeLoader::status() const
void QDeclarativeLoader::componentComplete()
{
- Q_D(QDeclarativeLoader);
-
QDeclarativeItem::componentComplete();
- d->isComponentComplete = true;
- d->load();
+ if (status() == Ready)
+ emit loaded();
}
diff --git a/src/declarative/graphicsitems/qdeclarativeloader_p_p.h b/src/declarative/graphicsitems/qdeclarativeloader_p_p.h
index 81ca66d..45ab595 100644
--- a/src/declarative/graphicsitems/qdeclarativeloader_p_p.h
+++ b/src/declarative/graphicsitems/qdeclarativeloader_p_p.h
@@ -72,13 +72,11 @@ public:
void itemGeometryChanged(QDeclarativeItem *item, const QRectF &newGeometry, const QRectF &oldGeometry);
void clear();
void initResize();
- void load();
QUrl source;
QGraphicsObject *item;
QDeclarativeComponent *component;
bool ownComponent : 1;
- bool isComponentComplete : 1;
void _q_sourceLoaded();
void _q_updateSize(bool loaderGeometryChanged = true);
diff --git a/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp b/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp
index 358822e..bfa81ed 100644
--- a/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp
+++ b/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp
@@ -69,8 +69,9 @@ public:
tst_QDeclarativeLoader();
private slots:
- void sourceOrComponent();
- void sourceOrComponent_data();
+ void url();
+ void invalidUrl();
+ void component();
void clear();
void urlToComponent();
void componentToUrl();
@@ -99,71 +100,56 @@ tst_QDeclarativeLoader::tst_QDeclarativeLoader()
{
}
-void tst_QDeclarativeLoader::sourceOrComponent()
+void tst_QDeclarativeLoader::url()
{
- QFETCH(QString, sourceDefinition);
- QFETCH(QUrl, sourceUrl);
- QFETCH(QString, errorString);
-
- bool error = !errorString.isEmpty();
- if (error)
- QTest::ignoreMessage(QtWarningMsg, errorString.toUtf8().constData());
-
QDeclarativeComponent component(&engine);
- component.setData(QByteArray(
- "import QtQuick 1.0\n"
- "Loader {\n"
- " property int onItemChangedCount: 0\n"
- " property int onSourceChangedCount: 0\n"
- " property int onStatusChangedCount: 0\n"
- " property int onProgressChangedCount: 0\n"
- " property int onLoadedCount: 0\n")
- + sourceDefinition.toUtf8()
- + QByteArray(
- " onItemChanged: onItemChangedCount += 1\n"
- " onSourceChanged: onSourceChangedCount += 1\n"
- " onStatusChanged: onStatusChangedCount += 1\n"
- " onProgressChanged: onProgressChangedCount += 1\n"
- " onLoaded: onLoadedCount += 1\n"
- "}")
- , TEST_FILE(""));
-
+ component.setData(QByteArray("import QtQuick 1.0\nLoader { property int did_load: 0; onLoaded: did_load=123; source: \"Rect120x60.qml\" }"), TEST_FILE(""));
QDeclarativeLoader *loader = qobject_cast<QDeclarativeLoader*>(component.create());
QVERIFY(loader != 0);
- QCOMPARE(loader->item() == 0, error);
- QCOMPARE(loader->source(), sourceUrl);
+ QVERIFY(loader->item());
+ QVERIFY(loader->source() == QUrl::fromLocalFile(SRCDIR "/data/Rect120x60.qml"));
QCOMPARE(loader->progress(), 1.0);
+ QCOMPARE(loader->status(), QDeclarativeLoader::Ready);
+ QCOMPARE(loader->property("did_load").toInt(), 123);
+ QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 1);
- QCOMPARE(loader->status(), error ? QDeclarativeLoader::Error : QDeclarativeLoader::Ready);
- QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), error ? 0: 1);
+ delete loader;
+}
- if (!error) {
- QDeclarativeComponent *c = qobject_cast<QDeclarativeComponent*>(loader->QGraphicsObject::children().at(0));
- QVERIFY(c);
- QCOMPARE(loader->sourceComponent(), c);
- }
+void tst_QDeclarativeLoader::component()
+{
+ QDeclarativeComponent component(&engine, TEST_FILE("/SetSourceComponent.qml"));
+ QDeclarativeItem *item = qobject_cast<QDeclarativeItem*>(component.create());
+ QVERIFY(item);
- QCOMPARE(loader->property("onSourceChangedCount").toInt(), 1);
- QCOMPARE(loader->property("onStatusChangedCount").toInt(), 1);
- QCOMPARE(loader->property("onProgressChangedCount").toInt(), 1);
+ QDeclarativeLoader *loader = qobject_cast<QDeclarativeLoader*>(item->QGraphicsObject::children().at(1));
+ QVERIFY(loader);
+ QVERIFY(loader->item());
+ QCOMPARE(loader->progress(), 1.0);
+ QCOMPARE(loader->status(), QDeclarativeLoader::Ready);
+ QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 1);
- QCOMPARE(loader->property("onItemChangedCount").toInt(), error ? 0 : 1);
- QCOMPARE(loader->property("onLoadedCount").toInt(), error ? 0 : 1);
+ QDeclarativeComponent *c = qobject_cast<QDeclarativeComponent*>(item->QGraphicsObject::children().at(0));
+ QVERIFY(c);
+ QCOMPARE(loader->sourceComponent(), c);
- delete loader;
+ delete item;
}
-void tst_QDeclarativeLoader::sourceOrComponent_data()
+void tst_QDeclarativeLoader::invalidUrl()
{
- QTest::addColumn<QString>("sourceDefinition");
- QTest::addColumn<QUrl>("sourceUrl");
- QTest::addColumn<QString>("errorString");
+ QTest::ignoreMessage(QtWarningMsg, QString(QUrl::fromLocalFile(SRCDIR "/data/IDontExist.qml").toString() + ": File not found").toUtf8().constData());
- QTest::newRow("source") << "source: 'Rect120x60.qml'\n" << QUrl::fromLocalFile(SRCDIR "/data/Rect120x60.qml") << "";
- QTest::newRow("sourceComponent") << "Component { id: comp; Rectangle { width: 100; height: 50 } }\n sourceComponent: comp\n" << QUrl() << "";
+ QDeclarativeComponent component(&engine);
+ component.setData(QByteArray("import QtQuick 1.0\nLoader { source: \"IDontExist.qml\" }"), TEST_FILE(""));
+ QDeclarativeLoader *loader = qobject_cast<QDeclarativeLoader*>(component.create());
+ QVERIFY(loader != 0);
+ QVERIFY(loader->item() == 0);
+ QCOMPARE(loader->progress(), 1.0);
+ QCOMPARE(loader->status(), QDeclarativeLoader::Error);
+ QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 0);
- QTest::newRow("invalid source") << "source: 'IDontExist.qml'\n" << QUrl::fromLocalFile(SRCDIR "/data/IDontExist.qml")
- << QString(QUrl::fromLocalFile(SRCDIR "/data/IDontExist.qml").toString() + ": File not found");
+ delete loader;
}
void tst_QDeclarativeLoader::clear()
@@ -460,7 +446,7 @@ void tst_QDeclarativeLoader::networkRequestUrl()
server.serveDirectory(SRCDIR "/data");
QDeclarativeComponent component(&engine);
- component.setData(QByteArray("import QtQuick 1.0\nLoader { property int signalCount : 0; source: \"http://127.0.0.1:14450/Rect120x60.qml\"; onLoaded: signalCount += 1 }"), QUrl::fromLocalFile(SRCDIR "/dummy.qml"));
+ component.setData(QByteArray("import QtQuick 1.0\nLoader { property int did_load : 0; source: \"http://127.0.0.1:14450/Rect120x60.qml\"; onLoaded: did_load=123 }"), QUrl::fromLocalFile(SRCDIR "/dummy.qml"));
if (component.isError())
qDebug() << component.errors();
QDeclarativeLoader *loader = qobject_cast<QDeclarativeLoader*>(component.create());
@@ -470,7 +456,7 @@ void tst_QDeclarativeLoader::networkRequestUrl()
QVERIFY(loader->item());
QCOMPARE(loader->progress(), 1.0);
- QCOMPARE(loader->property("signalCount").toInt(), 1);
+ QCOMPARE(loader->property("did_load").toInt(), 123);
QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 1);
delete loader;