diff options
author | Yann Bodson <yann.bodson@nokia.com> | 2011-07-29 14:41:16 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-07-29 09:39:41 +0200 |
commit | f1407da2cbaffcc1f175ec66ad389c3326efbe4a (patch) | |
tree | 0da4bf4bab76877663ed2834c7be06c6a83a6a94 | |
parent | 9bfdaadd36cdb5254d808688aa8485e5a592937d (diff) |
Add sourceComponentChanged signal to Loader
When setting the 'sourceComponent' property in Loader, we emit
a sourceChanged signal with source == "". We should emit
sourceComponentChanged instead.
Task-number: QTBUG-20628
Change-Id: If5f8f389b7dc214e729b366d82fe4d32827408ee
Reviewed-on: http://codereview.qt.nokia.com/2371
Reviewed-by: Martin Jones <martin.jones@nokia.com>
-rw-r--r-- | doc/src/declarative/whatsnew.qdoc | 4 | ||||
-rw-r--r-- | src/declarative/items/qsgloader.cpp | 17 | ||||
-rw-r--r-- | src/declarative/items/qsgloader_p.h | 5 | ||||
-rw-r--r-- | tests/auto/declarative/qsgloader/tst_qsgloader.cpp | 19 |
4 files changed, 34 insertions, 11 deletions
diff --git a/doc/src/declarative/whatsnew.qdoc b/doc/src/declarative/whatsnew.qdoc index f9b6683fa2..d2326fae44 100644 --- a/doc/src/declarative/whatsnew.qdoc +++ b/doc/src/declarative/whatsnew.qdoc @@ -45,6 +45,10 @@ QDeclarativeScriptString. Flickable: added dragging, draggingHorizontally and draggingVerically properties. +The Loader element now only emits the \c sourceChanged signal when the source is changed and the +\c sourceComponentChanged signal when the sourceComponent is changed. It used to emit both signals when one +of the properties was changed. + \section2 QtQuick 1 is now a separate library and module Writing C++ applications using QtQuick 1 specific API, i.e. QDeclarativeView or QDeclarativeItem diff --git a/src/declarative/items/qsgloader.cpp b/src/declarative/items/qsgloader.cpp index 0d1febacb4..ccf16896fb 100644 --- a/src/declarative/items/qsgloader.cpp +++ b/src/declarative/items/qsgloader.cpp @@ -165,7 +165,7 @@ void QSGLoader::setSourceComponent(QDeclarativeComponent *comp) d->component = comp; d->ownComponent = false; if (!d->component) { - emit sourceChanged(); + emit sourceComponentChanged(); emit statusChanged(); emit progressChanged(); emit itemChanged(); @@ -197,7 +197,10 @@ void QSGLoaderPrivate::load() q, SIGNAL(progressChanged())); emit q->statusChanged(); emit q->progressChanged(); - emit q->sourceChanged(); + if (ownComponent) + emit q->sourceChanged(); + else + emit q->sourceComponentChanged(); emit q->itemChanged(); } } @@ -209,7 +212,10 @@ void QSGLoaderPrivate::_q_sourceLoaded() if (component) { if (!component->errors().isEmpty()) { QDeclarativeEnginePrivate::warning(qmlEngine(q), component->errors()); - emit q->sourceChanged(); + if (ownComponent) + emit q->sourceChanged(); + else + emit q->sourceComponentChanged(); emit q->statusChanged(); emit q->progressChanged(); return; @@ -253,7 +259,10 @@ void QSGLoaderPrivate::_q_sourceLoaded() source = QUrl(); } component->completeCreate(); - emit q->sourceChanged(); + if (ownComponent) + emit q->sourceChanged(); + else + emit q->sourceComponentChanged(); emit q->statusChanged(); emit q->progressChanged(); emit q->itemChanged(); diff --git a/src/declarative/items/qsgloader_p.h b/src/declarative/items/qsgloader_p.h index b8605db567..832d3a6138 100644 --- a/src/declarative/items/qsgloader_p.h +++ b/src/declarative/items/qsgloader_p.h @@ -58,13 +58,13 @@ class Q_AUTOTEST_EXPORT QSGLoader : public QSGImplicitSizeItem Q_ENUMS(Status) Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) - Q_PROPERTY(QDeclarativeComponent *sourceComponent READ sourceComponent WRITE setSourceComponent RESET resetSourceComponent NOTIFY sourceChanged) + Q_PROPERTY(QDeclarativeComponent *sourceComponent READ sourceComponent WRITE setSourceComponent RESET resetSourceComponent NOTIFY sourceComponentChanged) Q_PROPERTY(QSGItem *item READ item NOTIFY itemChanged) Q_PROPERTY(Status status READ status NOTIFY statusChanged) Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) public: - QSGLoader(QSGItem *parent=0); + QSGLoader(QSGItem *parent = 0); virtual ~QSGLoader(); QUrl source() const; @@ -83,6 +83,7 @@ public: Q_SIGNALS: void itemChanged(); void sourceChanged(); + void sourceComponentChanged(); void statusChanged(); void progressChanged(); void loaded(); diff --git a/tests/auto/declarative/qsgloader/tst_qsgloader.cpp b/tests/auto/declarative/qsgloader/tst_qsgloader.cpp index 89285ebca6..c7e01da7ba 100644 --- a/tests/auto/declarative/qsgloader/tst_qsgloader.cpp +++ b/tests/auto/declarative/qsgloader/tst_qsgloader.cpp @@ -99,6 +99,7 @@ tst_QSGLoader::tst_QSGLoader() void tst_QSGLoader::sourceOrComponent() { + QFETCH(QString, sourceOrComponent); QFETCH(QString, sourceDefinition); QFETCH(QUrl, sourceUrl); QFETCH(QString, errorString); @@ -113,6 +114,7 @@ void tst_QSGLoader::sourceOrComponent() "Loader {\n" " property int onItemChangedCount: 0\n" " property int onSourceChangedCount: 0\n" + " property int onSourceComponentChangedCount: 0\n" " property int onStatusChangedCount: 0\n" " property int onProgressChangedCount: 0\n" " property int onLoadedCount: 0\n") @@ -120,6 +122,7 @@ void tst_QSGLoader::sourceOrComponent() + QByteArray( " onItemChanged: onItemChangedCount += 1\n" " onSourceChanged: onSourceChangedCount += 1\n" + " onSourceComponentChanged: onSourceComponentChangedCount += 1\n" " onStatusChanged: onStatusChangedCount += 1\n" " onProgressChanged: onProgressChangedCount += 1\n" " onLoaded: onLoadedCount += 1\n" @@ -141,7 +144,13 @@ void tst_QSGLoader::sourceOrComponent() QCOMPARE(loader->sourceComponent(), c); } - QCOMPARE(loader->property("onSourceChangedCount").toInt(), 1); + if (sourceOrComponent == "component") { + QCOMPARE(loader->property("onSourceComponentChangedCount").toInt(), 1); + QCOMPARE(loader->property("onSourceChangedCount").toInt(), 0); + } else { + QCOMPARE(loader->property("onSourceComponentChangedCount").toInt(), 0); + QCOMPARE(loader->property("onSourceChangedCount").toInt(), 1); + } QCOMPARE(loader->property("onStatusChangedCount").toInt(), 1); QCOMPARE(loader->property("onProgressChangedCount").toInt(), 1); @@ -153,14 +162,14 @@ void tst_QSGLoader::sourceOrComponent() void tst_QSGLoader::sourceOrComponent_data() { + QTest::addColumn<QString>("sourceOrComponent"); QTest::addColumn<QString>("sourceDefinition"); QTest::addColumn<QUrl>("sourceUrl"); QTest::addColumn<QString>("errorString"); - 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() << ""; - - QTest::newRow("invalid source") << "source: 'IDontExist.qml'\n" << QUrl::fromLocalFile(SRCDIR "/data/IDontExist.qml") + QTest::newRow("source") << "source" << "source: 'Rect120x60.qml'\n" << QUrl::fromLocalFile(SRCDIR "/data/Rect120x60.qml") << ""; + QTest::newRow("sourceComponent") << "component" << "Component { id: comp; Rectangle { width: 100; height: 50 } }\n sourceComponent: comp\n" << QUrl() << ""; + QTest::newRow("invalid source") << "source" << "source: 'IDontExist.qml'\n" << QUrl::fromLocalFile(SRCDIR "/data/IDontExist.qml") << QString(QUrl::fromLocalFile(SRCDIR "/data/IDontExist.qml").toString() + ": File not found"); } |