summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2010-03-01 06:32:35 (GMT)
committerMartin Jones <martin.jones@nokia.com>2010-03-01 06:32:35 (GMT)
commit049330b4a54836f227a0e179082527a5272e868d (patch)
treeb33ce32ee9b86c4c6bf2e87cfd1c6d6f61bf2e2c
parentd5449c3cc85624b50e6a6fcabc6ad96b79d4bd0a (diff)
parentfa7053103f4aa528972dc8766c05b5a1371b2bd8 (diff)
downloadQt-049330b4a54836f227a0e179082527a5272e868d.zip
Qt-049330b4a54836f227a0e179082527a5272e868d.tar.gz
Qt-049330b4a54836f227a0e179082527a5272e868d.tar.bz2
Merge branch 'master' of scm.dev.nokia.troll.no:qt/qt-qml
Conflicts: demos/declarative/flickr/mobile/ImageDetails.qml
-rw-r--r--demos/declarative/flickr/mobile/ImageDetails.qml3
-rw-r--r--src/declarative/util/qdeclarativexmllistmodel.cpp21
-rw-r--r--tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp130
-rw-r--r--tools/qml/main.cpp2
4 files changed, 110 insertions, 46 deletions
diff --git a/demos/declarative/flickr/mobile/ImageDetails.qml b/demos/declarative/flickr/mobile/ImageDetails.qml
index 55061db..c51371c 100644
--- a/demos/declarative/flickr/mobile/ImageDetails.qml
+++ b/demos/declarative/flickr/mobile/ImageDetails.qml
@@ -66,8 +66,7 @@ Flipable {
Image {
id: bigImage; source: container.photoUrl; scale: slider.value
- anchors.centerIn: parent
- smooth: !flickable.moving
+ anchors.centerIn: parent; smooth: !flickable.moving
onStatusChanged : {
// Default scale shows the entire image.
if (status == 1 && width != 0) {
diff --git a/src/declarative/util/qdeclarativexmllistmodel.cpp b/src/declarative/util/qdeclarativexmllistmodel.cpp
index 386df46..162a669 100644
--- a/src/declarative/util/qdeclarativexmllistmodel.cpp
+++ b/src/declarative/util/qdeclarativexmllistmodel.cpp
@@ -709,8 +709,24 @@ void QDeclarativeXmlListModel::reload()
d->qmlXmlQuery.abort();
d->queryId = -1;
- if (d->size < 0)
+ int count = d->size;
+ if (count < 0)
d->size = 0;
+ bool hasKeys = false;
+ for (int i=0; i<d->roleObjects.count(); i++) {
+ if (d->roleObjects[i]->isKey()) {
+ hasKeys = true;
+ break;
+ }
+ }
+ if (!hasKeys) {
+ d->data.clear();
+ d->size = 0;
+ if (count > 0) {
+ emit itemsRemoved(0, count);
+ emit countChanged();
+ }
+ }
if (d->src.isEmpty() && d->xml.isEmpty())
return;
@@ -782,9 +798,10 @@ void QDeclarativeXmlListModel::queryCompleted(int id, int size)
d->data = d->qmlXmlQuery.modelData();
QList<QDeclarativeXmlListRange> removed = d->qmlXmlQuery.removedItemRanges();
+ QList<QDeclarativeXmlListRange> inserted = d->qmlXmlQuery.insertedItemRanges();
+
for (int i=0; i<removed.count(); i++)
emit itemsRemoved(removed[i].first, removed[i].second);
- QList<QDeclarativeXmlListRange> inserted = d->qmlXmlQuery.insertedItemRanges();
for (int i=0; i<inserted.count(); i++)
emit itemsInserted(inserted[i].first, inserted[i].second);
diff --git a/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp b/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp
index e19e03d..68029bc 100644
--- a/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp
+++ b/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp
@@ -69,6 +69,7 @@ private slots:
void roles();
void roleErrors();
void uniqueRoleNames();
+ void reload();
void useKeys();
void useKeys_data();
void noKeysValueChanges();
@@ -116,90 +117,90 @@ private:
void tst_qdeclarativexmllistmodel::buildModel()
{
QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/model.qml"));
- QDeclarativeXmlListModel *listModel = qobject_cast<QDeclarativeXmlListModel*>(component.create());
- QVERIFY(listModel != 0);
- QTRY_COMPARE(listModel->count(), 9);
+ QDeclarativeXmlListModel *model = qobject_cast<QDeclarativeXmlListModel*>(component.create());
+ QVERIFY(model != 0);
+ QTRY_COMPARE(model->count(), 9);
QList<int> roles;
roles << Qt::UserRole << Qt::UserRole + 1 << Qt::UserRole + 2 << Qt::UserRole + 3;
- QHash<int, QVariant> data = listModel->data(3, roles);
+ QHash<int, QVariant> data = model->data(3, roles);
QVERIFY(data.count() == 4);
QCOMPARE(data.value(Qt::UserRole).toString(), QLatin1String("Spot"));
QCOMPARE(data.value(Qt::UserRole+1).toString(), QLatin1String("Dog"));
QCOMPARE(data.value(Qt::UserRole+2).toInt(), 9);
QCOMPARE(data.value(Qt::UserRole+3).toString(), QLatin1String("Medium"));
- delete listModel;
+ delete model;
}
void tst_qdeclarativexmllistmodel::missingFields()
{
QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/model2.qml"));
- QDeclarativeXmlListModel *listModel = qobject_cast<QDeclarativeXmlListModel*>(component.create());
- QVERIFY(listModel != 0);
- QTRY_COMPARE(listModel->count(), 9);
+ QDeclarativeXmlListModel *model = qobject_cast<QDeclarativeXmlListModel*>(component.create());
+ QVERIFY(model != 0);
+ QTRY_COMPARE(model->count(), 9);
QList<int> roles;
roles << Qt::UserRole << Qt::UserRole + 1 << Qt::UserRole + 2 << Qt::UserRole + 3 << Qt::UserRole + 4;
- QHash<int, QVariant> data = listModel->data(5, roles);
+ QHash<int, QVariant> data = model->data(5, roles);
QVERIFY(data.count() == 5);
QCOMPARE(data.value(Qt::UserRole+3).toString(), QLatin1String(""));
QCOMPARE(data.value(Qt::UserRole+4).toString(), QLatin1String(""));
- data = listModel->data(7, roles);
+ data = model->data(7, roles);
QVERIFY(data.count() == 5);
QCOMPARE(data.value(Qt::UserRole+2).toString(), QLatin1String(""));
- delete listModel;
+ delete model;
}
void tst_qdeclarativexmllistmodel::cdata()
{
QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/recipes.qml"));
- QDeclarativeXmlListModel *listModel = qobject_cast<QDeclarativeXmlListModel*>(component.create());
- QVERIFY(listModel != 0);
- QTRY_COMPARE(listModel->count(), 5);
+ QDeclarativeXmlListModel *model = qobject_cast<QDeclarativeXmlListModel*>(component.create());
+ QVERIFY(model != 0);
+ QTRY_COMPARE(model->count(), 5);
QList<int> roles;
roles << Qt::UserRole + 2;
- QHash<int, QVariant> data = listModel->data(2, roles);
+ QHash<int, QVariant> data = model->data(2, roles);
QVERIFY(data.count() == 1);
QVERIFY(data.value(Qt::UserRole+2).toString().startsWith(QLatin1String("<html>")));
- delete listModel;
+ delete model;
}
void tst_qdeclarativexmllistmodel::attributes()
{
QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/recipes.qml"));
- QDeclarativeXmlListModel *listModel = qobject_cast<QDeclarativeXmlListModel*>(component.create());
- QVERIFY(listModel != 0);
- QTRY_COMPARE(listModel->count(), 5);
+ QDeclarativeXmlListModel *model = qobject_cast<QDeclarativeXmlListModel*>(component.create());
+ QVERIFY(model != 0);
+ QTRY_COMPARE(model->count(), 5);
QList<int> roles;
roles << Qt::UserRole;
- QHash<int, QVariant> data = listModel->data(2, roles);
+ QHash<int, QVariant> data = model->data(2, roles);
QVERIFY(data.count() == 1);
QCOMPARE(data.value(Qt::UserRole).toString(), QLatin1String("Vegetable Soup"));
- delete listModel;
+ delete model;
}
void tst_qdeclarativexmllistmodel::roles()
{
QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/model.qml"));
- QDeclarativeXmlListModel *listModel = qobject_cast<QDeclarativeXmlListModel*>(component.create());
- QVERIFY(listModel != 0);
- QTRY_COMPARE(listModel->count(), 9);
+ QDeclarativeXmlListModel *model = qobject_cast<QDeclarativeXmlListModel*>(component.create());
+ QVERIFY(model != 0);
+ QTRY_COMPARE(model->count(), 9);
- QList<int> roles = listModel->roles();
+ QList<int> roles = model->roles();
QCOMPARE(roles.count(), 4);
- QCOMPARE(listModel->toString(roles.at(0)), QLatin1String("name"));
- QCOMPARE(listModel->toString(roles.at(1)), QLatin1String("type"));
- QCOMPARE(listModel->toString(roles.at(2)), QLatin1String("age"));
- QCOMPARE(listModel->toString(roles.at(3)), QLatin1String("size"));
+ QCOMPARE(model->toString(roles.at(0)), QLatin1String("name"));
+ QCOMPARE(model->toString(roles.at(1)), QLatin1String("type"));
+ QCOMPARE(model->toString(roles.at(2)), QLatin1String("age"));
+ QCOMPARE(model->toString(roles.at(3)), QLatin1String("size"));
- delete listModel;
+ delete model;
}
void tst_qdeclarativexmllistmodel::roleErrors()
@@ -207,13 +208,13 @@ void tst_qdeclarativexmllistmodel::roleErrors()
QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/roleErrors.qml"));
QTest::ignoreMessage(QtWarningMsg, QString("QML XmlRole (" + QUrl::fromLocalFile(SRCDIR "/data/roleErrors.qml").toString() + ":6:5) An XmlRole query must not start with '/'").toUtf8().constData());
//### make sure we receive all expected warning messages.
- QDeclarativeXmlListModel *listModel = qobject_cast<QDeclarativeXmlListModel*>(component.create());
- QVERIFY(listModel != 0);
- QTRY_COMPARE(listModel->count(), 9);
+ QDeclarativeXmlListModel *model = qobject_cast<QDeclarativeXmlListModel*>(component.create());
+ QVERIFY(model != 0);
+ QTRY_COMPARE(model->count(), 9);
QList<int> roles;
roles << Qt::UserRole << Qt::UserRole + 1 << Qt::UserRole + 2 << Qt::UserRole + 3;
- QHash<int, QVariant> data = listModel->data(3, roles);
+ QHash<int, QVariant> data = model->data(3, roles);
QVERIFY(data.count() == 4);
//### should any of these return valid values?
@@ -224,21 +225,47 @@ void tst_qdeclarativexmllistmodel::roleErrors()
QEXPECT_FAIL("", "QT-2456", Continue);
QCOMPARE(data.value(Qt::UserRole+3), QVariant());
- delete listModel;
+ delete model;
}
void tst_qdeclarativexmllistmodel::uniqueRoleNames()
{
QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/unique.qml"));
QTest::ignoreMessage(QtWarningMsg, QString("QML XmlRole (" + QUrl::fromLocalFile(SRCDIR "/data/unique.qml").toString() + ":7:5) \"name\" duplicates a previous role name and will be disabled.").toUtf8().constData());
- QDeclarativeXmlListModel *listModel = qobject_cast<QDeclarativeXmlListModel*>(component.create());
- QVERIFY(listModel != 0);
- QTRY_COMPARE(listModel->count(), 9);
+ QDeclarativeXmlListModel *model = qobject_cast<QDeclarativeXmlListModel*>(component.create());
+ QVERIFY(model != 0);
+ QTRY_COMPARE(model->count(), 9);
- QList<int> roles = listModel->roles();
+ QList<int> roles = model->roles();
QCOMPARE(roles.count(), 1);
- delete listModel;
+ delete model;
+}
+
+void tst_qdeclarativexmllistmodel::reload()
+{
+ // If no keys are used, the model should be rebuilt from scratch when
+ // reload() is called.
+
+ QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/model.qml"));
+ QDeclarativeXmlListModel *model = qobject_cast<QDeclarativeXmlListModel*>(component.create());
+ QVERIFY(model != 0);
+ QTRY_COMPARE(model->count(), 9);
+
+ QSignalSpy spyInsert(model, SIGNAL(itemsInserted(int,int)));
+ QSignalSpy spyRemove(model, SIGNAL(itemsRemoved(int,int)));
+ QSignalSpy spyCount(model, SIGNAL(countChanged()));
+
+ 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);
+
+ QCOMPARE(spyRemove[0][0].toInt(), 0);
+ QCOMPARE(spyRemove[0][1].toInt(), 9);
}
void tst_qdeclarativexmllistmodel::useKeys()
@@ -368,12 +395,33 @@ void tst_qdeclarativexmllistmodel::useKeys_data()
<< (QList<QDeclarativeXmlListRange>() << qMakePair(0, 1))
<< (QList<QDeclarativeXmlListRange>() << qMakePair(0, 1));
- QTest::newRow("add and remove simultaneously")
+ 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));
+
+ 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
+ << makeItemXmlAndData("name=A,age=25,sport=Football;name=B,age=35,sport=Athletics;name=C,age=45,sport=Curling", &modelData)
+ << modelData
+ << (QList<QDeclarativeXmlListRange>() << qMakePair(0, 2))
+ << (QList<QDeclarativeXmlListRange>() << qMakePair(1, 2));
+
+ QTest::newRow("remove at start, insert at end")
+ << makeItemXmlAndData("name=A,age=25,sport=Football;name=B,age=35,sport=Athletics;name=C,age=45,sport=Curling") << 3
+ << makeItemXmlAndData("name=C,age=45,sport=Curling;name=D,age=55,sport=Golf;name=E,age=65,sport=Fencing", &modelData)
+ << modelData
+ << (QList<QDeclarativeXmlListRange>() << qMakePair(1, 2))
+ << (QList<QDeclarativeXmlListRange>() << qMakePair(0, 2));
+
+ QTest::newRow("all data has changed")
+ << 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));
}
void tst_qdeclarativexmllistmodel::noKeysValueChanges()
diff --git a/tools/qml/main.cpp b/tools/qml/main.cpp
index 9ef02ac..6339813 100644
--- a/tools/qml/main.cpp
+++ b/tools/qml/main.cpp
@@ -324,7 +324,7 @@ int main(int argc, char ** argv)
if (!skin.isEmpty()) {
if (skin == "list") {
foreach (QString s, viewer.builtinSkins())
- qWarning(s.toUtf8());
+ qWarning() << qPrintable(s);
exit(0);
} else {
viewer.setSkin(skin);