summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBea Lam <bea.lam@nokia.com>2010-04-07 01:53:16 (GMT)
committerBea Lam <bea.lam@nokia.com>2010-04-07 02:38:42 (GMT)
commit973cfce37fcdd1ce330f237eaa76930db55a73f6 (patch)
tree96480cb291d6e5d2e0a9bf78bf1127a693ab2930
parent32fdd579afc2933ccc5fc658553cf18cf2057ff2 (diff)
downloadQt-973cfce37fcdd1ce330f237eaa76930db55a73f6.zip
Qt-973cfce37fcdd1ce330f237eaa76930db55a73f6.tar.gz
Qt-973cfce37fcdd1ce330f237eaa76930db55a73f6.tar.bz2
Add QListModelInterface::modelReset() signal and emit this in
XmlListModel when all data has changed.
-rw-r--r--src/declarative/3rdparty/qlistmodelinterface.cpp6
-rw-r--r--src/declarative/3rdparty/qlistmodelinterface_p.h1
-rw-r--r--src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp2
-rw-r--r--src/declarative/util/qdeclarativexmllistmodel.cpp25
-rw-r--r--src/declarative/util/qdeclarativexmllistmodel_p.h1
-rw-r--r--tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp54
6 files changed, 43 insertions, 46 deletions
diff --git a/src/declarative/3rdparty/qlistmodelinterface.cpp b/src/declarative/3rdparty/qlistmodelinterface.cpp
index 98d6a5b..20501a0 100644
--- a/src/declarative/3rdparty/qlistmodelinterface.cpp
+++ b/src/declarative/3rdparty/qlistmodelinterface.cpp
@@ -106,4 +106,10 @@ QT_BEGIN_NAMESPACE
\a roles changed.
*/
+/*! \fn void QListModelInterface::modelReset()
+ Emit this signal when all of the model data has changed.
+ This is more efficient than forcing the receivier to handle multiple
+ inserted and removed signals etc.
+*/
+
QT_END_NAMESPACE
diff --git a/src/declarative/3rdparty/qlistmodelinterface_p.h b/src/declarative/3rdparty/qlistmodelinterface_p.h
index 07592ad..da91d12 100644
--- a/src/declarative/3rdparty/qlistmodelinterface_p.h
+++ b/src/declarative/3rdparty/qlistmodelinterface_p.h
@@ -72,6 +72,7 @@ class Q_DECLARATIVE_EXPORT QListModelInterface : public QObject
void itemsRemoved(int index, int count);
void itemsMoved(int from, int to, int count);
void itemsChanged(int index, int count, const QList<int> &roles);
+ void modelReset();
protected:
QListModelInterface(QObjectPrivate &dd, QObject *parent)
diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp
index 2938f51..172362c 100644
--- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp
+++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp
@@ -662,6 +662,7 @@ void QDeclarativeVisualDataModel::setModel(const QVariant &model)
this, SLOT(_q_itemsRemoved(int,int)));
QObject::disconnect(d->m_listModelInterface, SIGNAL(itemsMoved(int,int,int)),
this, SLOT(_q_itemsMoved(int,int,int)));
+ QObject::disconnect(d->m_listModelInterface, SIGNAL(modelReset()), this, SLOT(_q_modelReset()));
d->m_listModelInterface = 0;
} else if (d->m_abstractItemModel) {
QObject::disconnect(d->m_abstractItemModel, SIGNAL(rowsInserted(const QModelIndex &,int,int)),
@@ -705,6 +706,7 @@ void QDeclarativeVisualDataModel::setModel(const QVariant &model)
this, SLOT(_q_itemsRemoved(int,int)));
QObject::connect(d->m_listModelInterface, SIGNAL(itemsMoved(int,int,int)),
this, SLOT(_q_itemsMoved(int,int,int)));
+ QObject::connect(d->m_listModelInterface, SIGNAL(modelReset()), this, SLOT(_q_modelReset()));
d->m_metaDataCacheable = true;
if (d->m_delegate && d->m_listModelInterface->count())
emit itemsInserted(0, d->m_listModelInterface->count());
diff --git a/src/declarative/util/qdeclarativexmllistmodel.cpp b/src/declarative/util/qdeclarativexmllistmodel.cpp
index b33af06..11c7305 100644
--- a/src/declarative/util/qdeclarativexmllistmodel.cpp
+++ b/src/declarative/util/qdeclarativexmllistmodel.cpp
@@ -878,21 +878,22 @@ void QDeclarativeXmlListModel::queryCompleted(const QDeclarativeXmlQueryResult &
}
}
if (!hasKeys) {
- if (!(origCount == 0 && d->size == 0)) {
- emit itemsRemoved(0, origCount);
- emit itemsInserted(0, d->size);
- emit countChanged();
- }
+ if (!(origCount == 0 && d->size == 0))
+ emit modelReset();
} else {
+ if (result.removed.count() == 1 && result.removed[0].first == 0
+ && result.removed[0].second == origCount) {
+ emit modelReset();
+ } else {
+ for (int i=0; i<result.removed.count(); i++)
+ emit itemsRemoved(result.removed[i].first, result.removed[i].second);
+ for (int i=0; i<result.inserted.count(); i++)
+ emit itemsInserted(result.inserted[i].first, result.inserted[i].second);
- for (int i=0; i<result.removed.count(); i++)
- emit itemsRemoved(result.removed[i].first, result.removed[i].second);
- for (int i=0; i<result.inserted.count(); i++)
- emit itemsInserted(result.inserted[i].first, result.inserted[i].second);
-
- if (sizeChanged)
- emit countChanged();
+ if (sizeChanged)
+ emit countChanged();
+ }
}
emit statusChanged(d->status);
diff --git a/src/declarative/util/qdeclarativexmllistmodel_p.h b/src/declarative/util/qdeclarativexmllistmodel_p.h
index 7b85476..fd410a7 100644
--- a/src/declarative/util/qdeclarativexmllistmodel_p.h
+++ b/src/declarative/util/qdeclarativexmllistmodel_p.h
@@ -124,6 +124,7 @@ Q_SIGNALS:
void xmlChanged();
void queryChanged();
void namespaceDeclarationsChanged();
+ void modelReset();
public Q_SLOTS:
// ### need to use/expose Expiry to guess when to call this?
diff --git a/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp b/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp
index 74da79e..ba0f9a7 100644
--- a/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp
+++ b/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp
@@ -378,17 +378,16 @@ void tst_qdeclarativexmllistmodel::reload()
QSignalSpy spyInsert(model, SIGNAL(itemsInserted(int,int)));
QSignalSpy spyRemove(model, SIGNAL(itemsRemoved(int,int)));
QSignalSpy spyCount(model, SIGNAL(countChanged()));
+ QSignalSpy spyReset(model, SIGNAL(modelReset()));
model->reload();
- QTRY_COMPARE(spyCount.count(), 1);
- QTRY_COMPARE(spyInsert.count(), 1);
- QTRY_COMPARE(spyRemove.count(), 1);
-
- QCOMPARE(spyInsert[0][0].toInt(), 0);
- QCOMPARE(spyInsert[0][1].toInt(), 9);
+ QTRY_COMPARE(spyReset.count(), 1);
+ QCOMPARE(spyCount.count(), 0);
+ QCOMPARE(spyInsert.count(), 0);
+ QCOMPARE(spyRemove.count(), 0);
- QCOMPARE(spyRemove[0][0].toInt(), 0);
- QCOMPARE(spyRemove[0][1].toInt(), 9);
+ QCOMPARE(model->data(0, model->roles().first()).toString(), QString("Polly"));
+ QCOMPARE(model->data(model->count()-1, model->roles().first()).toString(), QString("Tiny"));
delete model;
}
@@ -416,15 +415,15 @@ void tst_qdeclarativexmllistmodel::useKeys()
QSignalSpy spyInsert(model, SIGNAL(itemsInserted(int,int)));
QSignalSpy spyRemove(model, SIGNAL(itemsRemoved(int,int)));
QSignalSpy spyCount(model, SIGNAL(countChanged()));
+ QSignalSpy spyReset(model, SIGNAL(modelReset()));
model->setXml(newXml);
- if (oldCount != newData.count()) {
- QTRY_COMPARE(model->count(), newData.count());
- QCOMPARE(spyCount.count(), 1);
+ if (insertRanges.isEmpty() && removeRanges.isEmpty()) {
+ QTRY_COMPARE(spyReset.count(), 1);
} else {
QTRY_VERIFY(spyInsert.count() > 0 || spyRemove.count() > 0);
- QCOMPARE(spyCount.count(), 0);
+ QCOMPARE(spyCount.count() == 0, oldCount == newData.count());
}
QList<int> roles = model->roles();
@@ -513,21 +512,14 @@ void tst_qdeclarativexmllistmodel::useKeys_data()
<< makeItemXmlAndData("", &modelData)
<< modelData
<< QList<QDeclarativeXmlListRange>()
- << (QList<QDeclarativeXmlListRange>() << qMakePair(0, 3));
+ << QList<QDeclarativeXmlListRange>();
QTest::newRow("replace item")
<< makeItemXmlAndData("name=A,age=25,sport=Football") << 1
<< makeItemXmlAndData("name=ZZZ,age=25,sport=Football", &modelData)
<< modelData
- << (QList<QDeclarativeXmlListRange>() << qMakePair(0, 1))
- << (QList<QDeclarativeXmlListRange>() << qMakePair(0, 1));
-
- QTest::newRow("add and remove simultaneously, in different spots")
- << makeItemXmlAndData("name=A,age=25,sport=Football;name=B,age=35,sport=Athletics;name=C,age=45,sport=Curling;name=D,age=55,sport=Golf") << 4
- << makeItemXmlAndData("name=B,age=35,sport=Athletics;name=E,age=65,sport=Fencing", &modelData)
- << modelData
- << (QList<QDeclarativeXmlListRange>() << qMakePair(1, 1))
- << (QList<QDeclarativeXmlListRange>() << qMakePair(0, 1) << qMakePair(2,2));
+ << QList<QDeclarativeXmlListRange>()
+ << QList<QDeclarativeXmlListRange>();
QTest::newRow("insert at start, remove at end i.e. rss feed")
<< makeItemXmlAndData("name=C,age=45,sport=Curling;name=D,age=55,sport=Golf;name=E,age=65,sport=Fencing") << 3
@@ -547,8 +539,8 @@ void tst_qdeclarativexmllistmodel::useKeys_data()
<< makeItemXmlAndData("name=A,age=25,sport=Football;name=B,age=35") << 2
<< makeItemXmlAndData("name=C,age=45,sport=Curling;name=D,age=55,sport=Golf", &modelData)
<< modelData
- << (QList<QDeclarativeXmlListRange>() << qMakePair(0, 2))
- << (QList<QDeclarativeXmlListRange>() << qMakePair(0, 2));
+ << QList<QDeclarativeXmlListRange>()
+ << QList<QDeclarativeXmlListRange>();
}
void tst_qdeclarativexmllistmodel::noKeysValueChanges()
@@ -608,20 +600,14 @@ void tst_qdeclarativexmllistmodel::keysChanged()
QSignalSpy spyInsert(model, SIGNAL(itemsInserted(int,int)));
QSignalSpy spyRemove(model, SIGNAL(itemsRemoved(int,int)));
QSignalSpy spyCount(model, SIGNAL(countChanged()));
+ QSignalSpy spyReset(model, SIGNAL(modelReset()));
QVERIFY(QMetaObject::invokeMethod(model, "disableNameKey"));
model->setXml(xml);
- QTRY_VERIFY(spyInsert.count() > 0 && spyRemove.count() > 0);
-
- QCOMPARE(spyInsert.count(), 1);
- QCOMPARE(spyInsert[0][0].toInt(), 0);
- QCOMPARE(spyInsert[0][1].toInt(), 2);
-
- QCOMPARE(spyRemove.count(), 1);
- QCOMPARE(spyRemove[0][0].toInt(), 0);
- QCOMPARE(spyRemove[0][1].toInt(), 2);
-
+ QTRY_COMPARE(spyReset.count(), 1);
+ QCOMPARE(spyInsert.count(), 0);
+ QCOMPARE(spyRemove.count(), 0);
QCOMPARE(spyCount.count(), 0);
delete model;