From 34052400e537c188af883c4152df760bc531060d Mon Sep 17 00:00:00 2001 From: Joona Petrell Date: Thu, 4 Mar 2010 15:58:26 +1000 Subject: Add missing NOTIFYs to timer, xmllistmodel, xmlrole Reviewed-by: akennedy --- src/declarative/util/qdeclarativetimer.cpp | 3 + src/declarative/util/qdeclarativetimer_p.h | 9 ++- src/declarative/util/qdeclarativexmllistmodel.cpp | 14 +++-- src/declarative/util/qdeclarativexmllistmodel_p.h | 41 +++++++++---- .../qdeclarativetimer/tst_qdeclarativetimer.cpp | 37 ++++++++++++ .../data/propertychanges.qml | 10 ++++ .../tst_qdeclarativexmllistmodel.cpp | 70 ++++++++++++++++++++++ 7 files changed, 167 insertions(+), 17 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativexmllistmodel/data/propertychanges.qml diff --git a/src/declarative/util/qdeclarativetimer.cpp b/src/declarative/util/qdeclarativetimer.cpp index d7e02b1..104e3ae 100644 --- a/src/declarative/util/qdeclarativetimer.cpp +++ b/src/declarative/util/qdeclarativetimer.cpp @@ -123,6 +123,7 @@ void QDeclarativeTimer::setInterval(int interval) if (interval != d->interval) { d->interval = interval; update(); + emit intervalChanged(); } } @@ -183,6 +184,7 @@ void QDeclarativeTimer::setRepeating(bool repeating) if (repeating != d->repeating) { d->repeating = repeating; update(); + emit repeatChanged(); } } @@ -215,6 +217,7 @@ void QDeclarativeTimer::setTriggeredOnStart(bool triggeredOnStart) if (d->triggeredOnStart != triggeredOnStart) { d->triggeredOnStart = triggeredOnStart; update(); + emit triggeredOnStartChanged(); } } diff --git a/src/declarative/util/qdeclarativetimer_p.h b/src/declarative/util/qdeclarativetimer_p.h index e063657..d1e6630 100644 --- a/src/declarative/util/qdeclarativetimer_p.h +++ b/src/declarative/util/qdeclarativetimer_p.h @@ -59,10 +59,10 @@ class Q_DECLARATIVE_EXPORT QDeclarativeTimer : public QObject, public QDeclarati Q_OBJECT Q_DECLARE_PRIVATE(QDeclarativeTimer) Q_INTERFACES(QDeclarativeParserStatus) - Q_PROPERTY(int interval READ interval WRITE setInterval) + Q_PROPERTY(int interval READ interval WRITE setInterval NOTIFY intervalChanged) Q_PROPERTY(bool running READ isRunning WRITE setRunning NOTIFY runningChanged) - Q_PROPERTY(bool repeat READ isRepeating WRITE setRepeating) - Q_PROPERTY(bool triggeredOnStart READ triggeredOnStart WRITE setTriggeredOnStart) + Q_PROPERTY(bool repeat READ isRepeating WRITE setRepeating NOTIFY repeatChanged) + Q_PROPERTY(bool triggeredOnStart READ triggeredOnStart WRITE setTriggeredOnStart NOTIFY triggeredOnStartChanged) public: QDeclarativeTimer(QObject *parent=0); @@ -91,6 +91,9 @@ public Q_SLOTS: Q_SIGNALS: void triggered(); void runningChanged(); + void intervalChanged(); + void repeatChanged(); + void triggeredOnStartChanged(); private: void update(); diff --git a/src/declarative/util/qdeclarativexmllistmodel.cpp b/src/declarative/util/qdeclarativexmllistmodel.cpp index d260ada..53e08b0 100644 --- a/src/declarative/util/qdeclarativexmllistmodel.cpp +++ b/src/declarative/util/qdeclarativexmllistmodel.cpp @@ -571,9 +571,10 @@ void QDeclarativeXmlListModel::setSource(const QUrl &src) { Q_D(QDeclarativeXmlListModel); if (d->src != src) { - d->src = src; reload(); - } + d->src = src; + emit sourceChanged(); + } } /*! @@ -593,8 +594,11 @@ QString QDeclarativeXmlListModel::xml() const void QDeclarativeXmlListModel::setXml(const QString &xml) { Q_D(QDeclarativeXmlListModel); - d->xml = xml; - reload(); + if (d->xml != xml) { + d->xml = xml; + reload(); + emit xmlChanged(); + } } /*! @@ -619,6 +623,7 @@ void QDeclarativeXmlListModel::setQuery(const QString &query) if (d->query != query) { d->query = query; reload(); + emit queryChanged(); } } @@ -638,6 +643,7 @@ void QDeclarativeXmlListModel::setNamespaceDeclarations(const QString &declarati if (d->namespaces != declarations) { d->namespaces = declarations; reload(); + emit namespaceDeclarationsChanged(); } } diff --git a/src/declarative/util/qdeclarativexmllistmodel_p.h b/src/declarative/util/qdeclarativexmllistmodel_p.h index f0ad4b8..23ff7ce 100644 --- a/src/declarative/util/qdeclarativexmllistmodel_p.h +++ b/src/declarative/util/qdeclarativexmllistmodel_p.h @@ -68,10 +68,10 @@ class Q_DECLARATIVE_EXPORT QDeclarativeXmlListModel : public QListModelInterface Q_PROPERTY(Status status READ status NOTIFY statusChanged) Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) - Q_PROPERTY(QUrl source READ source WRITE setSource) - Q_PROPERTY(QString xml READ xml WRITE setXml) - Q_PROPERTY(QString query READ query WRITE setQuery) - Q_PROPERTY(QString namespaceDeclarations READ namespaceDeclarations WRITE setNamespaceDeclarations) + Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) + Q_PROPERTY(QString xml READ xml WRITE setXml NOTIFY xmlChanged) + Q_PROPERTY(QString query READ query WRITE setQuery NOTIFY queryChanged) + Q_PROPERTY(QString namespaceDeclarations READ namespaceDeclarations WRITE setNamespaceDeclarations NOTIFY namespaceDeclarationsChanged) Q_PROPERTY(QDeclarativeListProperty roles READ roleObjects) Q_PROPERTY(int count READ count NOTIFY countChanged) Q_CLASSINFO("DefaultProperty", "roles") @@ -111,6 +111,10 @@ Q_SIGNALS: void statusChanged(Status); void progressChanged(qreal progress); void countChanged(); + void sourceChanged(); + void xmlChanged(); + void queryChanged(); + void namespaceDeclarationsChanged(); public Q_SLOTS: // ### need to use/expose Expiry to guess when to call this? @@ -132,16 +136,20 @@ private: class Q_DECLARATIVE_EXPORT QDeclarativeXmlListModelRole : public QObject { Q_OBJECT - Q_PROPERTY(QString name READ name WRITE setName) - Q_PROPERTY(QString query READ query WRITE setQuery) - Q_PROPERTY(bool isKey READ isKey WRITE setIsKey) - + Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) + Q_PROPERTY(QString query READ query WRITE setQuery NOTIFY queryChanged) + Q_PROPERTY(bool isKey READ isKey WRITE setIsKey NOTIFY isKeyChanged) public: QDeclarativeXmlListModelRole() : m_isKey(false) {} ~QDeclarativeXmlListModelRole() {} QString name() const { return m_name; } - void setName(const QString &name) { m_name = name; } + void setName(const QString &name) { + if (name == m_name) + return; + m_name = name; + emit nameChanged(); + } QString query() const { return m_query; } void setQuery(const QString &query) @@ -150,16 +158,29 @@ public: qmlInfo(this) << tr("An XmlRole query must not start with '/'"); return; } + if (m_query == query) + return; m_query = query; + emit queryChanged(); } bool isKey() const { return m_isKey; } - void setIsKey(bool b) { m_isKey = b; } + void setIsKey(bool b) { + if (m_isKey == b) + return; + m_isKey = b; + emit isKeyChanged(); + } bool isValid() { return !m_name.isEmpty() && !m_query.isEmpty(); } +Q_SIGNALS: + void nameChanged(); + void queryChanged(); + void isKeyChanged(); + private: QString m_name; QString m_query; diff --git a/tests/auto/declarative/qdeclarativetimer/tst_qdeclarativetimer.cpp b/tests/auto/declarative/qdeclarativetimer/tst_qdeclarativetimer.cpp index b120d5d..1dfec50 100644 --- a/tests/auto/declarative/qdeclarativetimer/tst_qdeclarativetimer.cpp +++ b/tests/auto/declarative/qdeclarativetimer/tst_qdeclarativetimer.cpp @@ -38,6 +38,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#include #include #include #include @@ -161,6 +162,18 @@ void tst_qdeclarativetimer::repeat() QVERIFY(helper.count == oldCount); QVERIFY(timer->isRunning() == false); + QSignalSpy spy(timer, SIGNAL(repeatChanged())); + + timer->setRepeating(false); + QVERIFY(!timer->isRepeating()); + QCOMPARE(spy.count(),1); + + timer->setRepeating(false); + QCOMPARE(spy.count(),1); + + timer->setRepeating(true); + QCOMPARE(spy.count(),2); + delete timer; } @@ -184,6 +197,18 @@ void tst_qdeclarativetimer::triggeredOnStart() QCOMPARE(helper.count, 2); QVERIFY(timer->isRunning() == false); + QSignalSpy spy(timer, SIGNAL(triggeredOnStartChanged())); + + timer->setTriggeredOnStart(false); + QVERIFY(!timer->triggeredOnStart()); + QCOMPARE(spy.count(),1); + + timer->setTriggeredOnStart(false); + QCOMPARE(spy.count(),1); + + timer->setTriggeredOnStart(true); + QCOMPARE(spy.count(),2); + delete timer; } @@ -250,6 +275,18 @@ void tst_qdeclarativetimer::changeDuration() QCOMPARE(helper.count, 3); QVERIFY(timer->isRunning()); + QSignalSpy spy(timer, SIGNAL(intervalChanged())); + + timer->setInterval(200); + QCOMPARE(timer->interval(), 200); + QCOMPARE(spy.count(),1); + + timer->setInterval(200); + QCOMPARE(spy.count(),1); + + timer->setInterval(300); + QCOMPARE(spy.count(),2); + delete timer; } diff --git a/tests/auto/declarative/qdeclarativexmllistmodel/data/propertychanges.qml b/tests/auto/declarative/qdeclarativexmllistmodel/data/propertychanges.qml new file mode 100644 index 0000000..737ec81 --- /dev/null +++ b/tests/auto/declarative/qdeclarativexmllistmodel/data/propertychanges.qml @@ -0,0 +1,10 @@ +import Qt 4.6 + +XmlListModel { + source: "model.xml" + query: "/Pets/Pet" + XmlRole { objectName: "role"; name: "name"; query: "name/string()" } + XmlRole { name: "type"; query: "type/string()" } + XmlRole { name: "age"; query: "age/number()" } + XmlRole { name: "size"; query: "size/string()" } +} diff --git a/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp b/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp index 68029bc..6199234 100644 --- a/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp +++ b/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp @@ -74,6 +74,7 @@ private slots: void useKeys_data(); void noKeysValueChanges(); void keysChanged(); + void propertyChanges(); private: QString makeItemXmlAndData(const QString &data, QDeclarativeXmlModelData *modelData = 0) const @@ -440,6 +441,8 @@ void tst_qdeclarativexmllistmodel::noKeysValueChanges() model->setXml(xml); QTRY_COMPARE(model->count(), 2); + model->setXml(""); + QSignalSpy spyInsert(model, SIGNAL(itemsInserted(int,int))); QSignalSpy spyRemove(model, SIGNAL(itemsRemoved(int,int))); QSignalSpy spyCount(model, SIGNAL(countChanged())); @@ -476,6 +479,8 @@ void tst_qdeclarativexmllistmodel::keysChanged() model->setXml(xml); QTRY_COMPARE(model->count(), 2); + model->setXml(""); + QSignalSpy spyInsert(model, SIGNAL(itemsInserted(int,int))); QSignalSpy spyRemove(model, SIGNAL(itemsRemoved(int,int))); QSignalSpy spyCount(model, SIGNAL(countChanged())); @@ -496,6 +501,71 @@ void tst_qdeclarativexmllistmodel::keysChanged() QCOMPARE(spyCount.count(), 0); } +void tst_qdeclarativexmllistmodel::propertyChanges() +{ + QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/propertychanges.qml")); + QDeclarativeXmlListModel *model = qobject_cast(component.create()); + QVERIFY(model != 0); + QTRY_COMPARE(model->count(), 9); + + QDeclarativeXmlListModelRole *role = model->findChild("role"); + QVERIFY(role); + + QSignalSpy nameSpy(role, SIGNAL(nameChanged())); + QSignalSpy querySpy(role, SIGNAL(queryChanged())); + QSignalSpy isKeySpy(role, SIGNAL(isKeyChanged())); + + role->setName("size"); + role->setQuery("size/string()"); + role->setIsKey(true); + + QCOMPARE(role->name(), QString("size")); + QCOMPARE(role->query(), QString("size/string()")); + QVERIFY(role->isKey()); + + QCOMPARE(nameSpy.count(),1); + QCOMPARE(querySpy.count(),1); + QCOMPARE(isKeySpy.count(),1); + + role->setName("size"); + role->setQuery("size/string()"); + role->setIsKey(true); + + QCOMPARE(nameSpy.count(),1); + QCOMPARE(querySpy.count(),1); + QCOMPARE(isKeySpy.count(),1); + + QSignalSpy sourceSpy(model, SIGNAL(sourceChanged())); + QSignalSpy xmlSpy(model, SIGNAL(xmlChanged())); + QSignalSpy modelQuerySpy(model, SIGNAL(queryChanged())); + QSignalSpy namespaceDeclarationsSpy(model, SIGNAL(namespaceDeclarationsChanged())); + + model->setSource(QUrl("")); + model->setXml("PollyParrot12Small"); + model->setQuery("/Pets"); + model->setNamespaceDeclarations("declare namespace media=\"http://search.yahoo.com/mrss/\";"); + + QCOMPARE(model->source(), QUrl("")); + QCOMPARE(model->xml(), QString("PollyParrot12Small")); + QCOMPARE(model->query(), QString("/Pets")); + QCOMPARE(model->namespaceDeclarations(), QString("declare namespace media=\"http://search.yahoo.com/mrss/\";")); + + QCOMPARE(sourceSpy.count(),1); + QCOMPARE(xmlSpy.count(),1); + QCOMPARE(modelQuerySpy.count(),1); + QCOMPARE(namespaceDeclarationsSpy.count(),1); + + model->setSource(QUrl("")); + model->setXml("PollyParrot12Small"); + model->setQuery("/Pets"); + model->setNamespaceDeclarations("declare namespace media=\"http://search.yahoo.com/mrss/\";"); + + QCOMPARE(sourceSpy.count(),1); + QCOMPARE(xmlSpy.count(),1); + QCOMPARE(modelQuerySpy.count(),1); + QCOMPARE(namespaceDeclarationsSpy.count(),1); +} + QTEST_MAIN(tst_qdeclarativexmllistmodel) #include "tst_qdeclarativexmllistmodel.moc" -- cgit v0.12