summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWarwick Allison <warwick.allison@nokia.com>2010-05-17 03:36:35 (GMT)
committerWarwick Allison <warwick.allison@nokia.com>2010-05-17 03:36:35 (GMT)
commitfd0b25da6997553bb95ea91bbdd509fa35711b9d (patch)
treecacaa230a8d8a1b7cc2ffee84d603a429194ebbb
parente752dda20ae8b8e75de653371b6bd369d2966104 (diff)
downloadQt-fd0b25da6997553bb95ea91bbdd509fa35711b9d.zip
Qt-fd0b25da6997553bb95ea91bbdd509fa35711b9d.tar.gz
Qt-fd0b25da6997553bb95ea91bbdd509fa35711b9d.tar.bz2
Fix doc for status, add Image::onLoaded.
statusChanged is NOT emitted for local files, nor should it be (they are loaded synchronously, so status is *initially* Ready). Add onLoaded signal that *is* emitted. Reviewed-by: Michael Brasser
-rw-r--r--src/declarative/graphicsitems/qdeclarativeloader.cpp22
-rw-r--r--src/declarative/graphicsitems/qdeclarativeloader_p.h3
-rw-r--r--tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp9
3 files changed, 29 insertions, 5 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativeloader.cpp b/src/declarative/graphicsitems/qdeclarativeloader.cpp
index 7edd53c..cbdfd87 100644
--- a/src/declarative/graphicsitems/qdeclarativeloader.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeloader.cpp
@@ -321,6 +321,7 @@ void QDeclarativeLoaderPrivate::_q_sourceLoaded()
emit q->statusChanged();
emit q->progressChanged();
emit q->itemChanged();
+ emit q->loaded();
}
}
@@ -341,10 +342,13 @@ void QDeclarativeLoaderPrivate::_q_sourceLoaded()
of the following ways:
\list
\o Create a state, so that a state change occurs, e.g. State{name: 'loaded'; when: loader.status = Loader.Ready;}
- \o Do something inside the onStatusChanged signal handler, e.g. Loader{id: loader; onStatusChanged: if(loader.status == Loader.Ready) console.log('Loaded');}
+ \o Do something inside the onLoaded signal handler, e.g. Loader{id: loader; onLoaded: console.log('Loaded');}
\o Bind to the status variable somewhere, e.g. Text{text: if(loader.status!=Loader.Ready){'Not Loaded';}else{'Loaded';}}
\endlist
\sa progress
+
+ Note that if the source is a local file, the status will initially be Ready (or Error). While
+ there will be no onStatusChanged signal in that case, the onLoaded will still be invoked.
*/
QDeclarativeLoader::Status QDeclarativeLoader::status() const
@@ -360,6 +364,21 @@ QDeclarativeLoader::Status QDeclarativeLoader::status() const
return d->source.isEmpty() ? Null : Error;
}
+void QDeclarativeLoader::componentComplete()
+{
+ if (status() == Ready)
+ emit loaded();
+}
+
+
+/*!
+ \qmlsignal Loader::onLoaded()
+
+ This handler is called when the \l status becomes Loader.Ready, or on successful
+ initial load.
+*/
+
+
/*!
\qmlproperty real Loader::progress
@@ -382,7 +401,6 @@ qreal QDeclarativeLoader::progress() const
return 0.0;
}
-
void QDeclarativeLoaderPrivate::_q_updateSize(bool loaderGeometryChanged)
{
Q_Q(QDeclarativeLoader);
diff --git a/src/declarative/graphicsitems/qdeclarativeloader_p.h b/src/declarative/graphicsitems/qdeclarativeloader_p.h
index 49dfa11..ec7ffe9 100644
--- a/src/declarative/graphicsitems/qdeclarativeloader_p.h
+++ b/src/declarative/graphicsitems/qdeclarativeloader_p.h
@@ -84,11 +84,14 @@ Q_SIGNALS:
void sourceChanged();
void statusChanged();
void progressChanged();
+ void loaded();
protected:
void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
bool eventFilter(QObject *watched, QEvent *e);
+ void componentComplete();
+
private:
Q_DISABLE_COPY(QDeclarativeLoader)
Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeLoader)
diff --git a/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp b/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp
index b56ff13..59580ea 100644
--- a/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp
+++ b/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp
@@ -104,13 +104,14 @@ tst_QDeclarativeLoader::tst_QDeclarativeLoader()
void tst_QDeclarativeLoader::url()
{
QDeclarativeComponent component(&engine);
- component.setData(QByteArray("import Qt 4.7\nLoader { source: \"Rect120x60.qml\" }"), TEST_FILE(""));
+ component.setData(QByteArray("import Qt 4.7\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);
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);
delete loader;
@@ -427,7 +428,7 @@ void tst_QDeclarativeLoader::networkRequestUrl()
server.serveDirectory(SRCDIR "/data");
QDeclarativeComponent component(&engine);
- component.setData(QByteArray("import Qt 4.7\nLoader { source: \"http://127.0.0.1:14450/Rect120x60.qml\" }"), QUrl::fromLocalFile(SRCDIR "/dummy.qml"));
+ component.setData(QByteArray("import Qt 4.7\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());
@@ -437,6 +438,7 @@ void tst_QDeclarativeLoader::networkRequestUrl()
QVERIFY(loader->item());
QCOMPARE(loader->progress(), 1.0);
+ QCOMPARE(loader->property("did_load").toInt(), 123);
QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 1);
delete loader;
@@ -483,7 +485,7 @@ void tst_QDeclarativeLoader::failNetworkRequest()
QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: Network error for URL http://127.0.0.1:14450/IDontExist.qml");
QDeclarativeComponent component(&engine);
- component.setData(QByteArray("import Qt 4.7\nLoader { source: \"http://127.0.0.1:14450/IDontExist.qml\" }"), QUrl::fromLocalFile("http://127.0.0.1:14450/dummy.qml"));
+ component.setData(QByteArray("import Qt 4.7\nLoader { property int did_load: 123; source: \"http://127.0.0.1:14450/IDontExist.qml\"; onLoaded: did_load=456 }"), QUrl::fromLocalFile("http://127.0.0.1:14450/dummy.qml"));
QDeclarativeLoader *loader = qobject_cast<QDeclarativeLoader*>(component.create());
QVERIFY(loader != 0);
@@ -491,6 +493,7 @@ void tst_QDeclarativeLoader::failNetworkRequest()
QVERIFY(loader->item() == 0);
QCOMPARE(loader->progress(), 0.0);
+ QCOMPARE(loader->property("did_load").toInt(), 123);
QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 0);
delete loader;