diff options
author | Warwick Allison <warwick.allison@nokia.com> | 2009-11-04 06:19:09 (GMT) |
---|---|---|
committer | Warwick Allison <warwick.allison@nokia.com> | 2009-11-04 06:19:09 (GMT) |
commit | 4d16a2d4ebc9029d76ba4557346701aae33800ae (patch) | |
tree | a5cecdc1d19052c944a4cd70e42a1b7cb8663bc9 | |
parent | 9c817b7a6959a7c8bade12de71d3629fae9b5859 (diff) | |
parent | 0ced984d3e2cb2a7a1a219ae7a9b09ff4e15a55c (diff) | |
download | Qt-4d16a2d4ebc9029d76ba4557346701aae33800ae.zip Qt-4d16a2d4ebc9029d76ba4557346701aae33800ae.tar.gz Qt-4d16a2d4ebc9029d76ba4557346701aae33800ae.tar.bz2 |
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
12 files changed, 318 insertions, 48 deletions
diff --git a/src/declarative/graphicsitems/qmlgraphicslistview.cpp b/src/declarative/graphicsitems/qmlgraphicslistview.cpp index a393cb1..efe047a 100644 --- a/src/declarative/graphicsitems/qmlgraphicslistview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicslistview.cpp @@ -398,7 +398,7 @@ public: QmlComponent *highlightComponent; FxListItem *highlight; FxListItem *trackedItem; - enum MovementReason { Other, Key, Mouse }; + enum MovementReason { Other, SetIndex, Mouse }; MovementReason moveReason; int buffer; QmlEaseFollow *highlightPosAnimator; @@ -422,6 +422,7 @@ void QmlGraphicsListViewPrivate::init() q->setFlag(QGraphicsItem::ItemIsFocusScope); QObject::connect(q, SIGNAL(heightChanged()), q, SLOT(refill())); QObject::connect(q, SIGNAL(widthChanged()), q, SLOT(refill())); + QObject::connect(q, SIGNAL(movementEnded()), q, SLOT(animStopped())); } void QmlGraphicsListViewPrivate::clear() @@ -1178,8 +1179,8 @@ int QmlGraphicsListView::currentIndex() const void QmlGraphicsListView::setCurrentIndex(int index) { Q_D(QmlGraphicsListView); - d->moveReason = QmlGraphicsListViewPrivate::Other; if (d->isValid() && index != d->currentIndex && index < d->model->count() && index >= 0) { + d->moveReason = QmlGraphicsListViewPrivate::SetIndex; cancelFlick(); d->updateCurrent(index); } else { @@ -1516,18 +1517,20 @@ void QmlGraphicsListView::viewportMoved() refill(); if (isFlicking() || d->moving) d->moveReason = QmlGraphicsListViewPrivate::Mouse; - if (d->moveReason == QmlGraphicsListViewPrivate::Mouse) { + if (d->moveReason != QmlGraphicsListViewPrivate::SetIndex) { if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange && d->highlight) { - int idx = d->snapIndex(); - if (idx >= 0 && idx != d->currentIndex) - d->updateCurrent(idx); - - qreal pos = d->currentItem->position(); + // reposition highlight + qreal pos = d->highlight->position(); if (pos > d->position() + d->highlightRangeEnd - 1 - d->highlight->size()) pos = d->position() + d->highlightRangeEnd - 1 - d->highlight->size(); if (pos < d->position() + d->highlightRangeStart) pos = d->position() + d->highlightRangeStart; d->highlight->setPosition(pos); + + // update current index + int idx = d->snapIndex(); + if (idx >= 0 && idx != d->currentIndex) + d->updateCurrent(idx); } } } @@ -1599,7 +1602,6 @@ void QmlGraphicsListView::keyPressEvent(QKeyEvent *event) if ((d->orient == QmlGraphicsListView::Horizontal && event->key() == Qt::Key_Left) || (d->orient == QmlGraphicsListView::Vertical && event->key() == Qt::Key_Up)) { if (currentIndex() > 0 || (d->wrap && !event->isAutoRepeat())) { - d->moveReason = QmlGraphicsListViewPrivate::Key; decrementCurrentIndex(); event->accept(); return; @@ -1610,7 +1612,6 @@ void QmlGraphicsListView::keyPressEvent(QKeyEvent *event) } else if ((d->orient == QmlGraphicsListView::Horizontal && event->key() == Qt::Key_Right) || (d->orient == QmlGraphicsListView::Vertical && event->key() == Qt::Key_Down)) { if (currentIndex() < d->model->count() - 1 || (d->wrap && !event->isAutoRepeat())) { - d->moveReason = QmlGraphicsListViewPrivate::Key; incrementCurrentIndex(); event->accept(); return; @@ -1634,6 +1635,7 @@ void QmlGraphicsListView::incrementCurrentIndex() { Q_D(QmlGraphicsListView); if (currentIndex() < d->model->count() - 1 || d->wrap) { + d->moveReason = QmlGraphicsListViewPrivate::SetIndex; int index = currentIndex()+1; cancelFlick(); d->updateCurrent(index < d->model->count() ? index : 0); @@ -1650,6 +1652,7 @@ void QmlGraphicsListView::decrementCurrentIndex() { Q_D(QmlGraphicsListView); if (currentIndex() > 0 || d->wrap) { + d->moveReason = QmlGraphicsListViewPrivate::SetIndex; int index = currentIndex()-1; cancelFlick(); d->updateCurrent(index >= 0 ? index : d->model->count()-1); @@ -2024,6 +2027,12 @@ void QmlGraphicsListView::destroyingItem(QmlGraphicsItem *item) d->unrequestedItems.remove(item); } +void QmlGraphicsListView::animStopped() +{ + Q_D(QmlGraphicsListView); + d->moveReason = QmlGraphicsListViewPrivate::Other; +} + QmlGraphicsListViewAttached *QmlGraphicsListView::qmlAttachedProperties(QObject *obj) { return QmlGraphicsListViewAttached::properties(obj); diff --git a/src/declarative/graphicsitems/qmlgraphicslistview_p.h b/src/declarative/graphicsitems/qmlgraphicslistview_p.h index 115cad9..446d71a 100644 --- a/src/declarative/graphicsitems/qmlgraphicslistview_p.h +++ b/src/declarative/graphicsitems/qmlgraphicslistview_p.h @@ -174,6 +174,7 @@ private Q_SLOTS: void destroyRemoved(); void createdItem(int index, QmlGraphicsItem *item); void destroyingItem(QmlGraphicsItem *item); + void animStopped(); }; QT_END_NAMESPACE diff --git a/src/declarative/qml/qmlcontextscriptclass.cpp b/src/declarative/qml/qmlcontextscriptclass.cpp index 4615764..fda284a 100644 --- a/src/declarative/qml/qmlcontextscriptclass.cpp +++ b/src/declarative/qml/qmlcontextscriptclass.cpp @@ -219,6 +219,7 @@ QScriptValue QmlContextScriptClass::property(Object *object, const Identifier &n void QmlContextScriptClass::setProperty(Object *object, const Identifier &name, const QScriptValue &value) { + Q_UNUSED(object); Q_ASSERT(lastScopeObject || lastDefaultObject != -1); QmlContext *bindContext = lastContext; diff --git a/src/declarative/qml/qmlglobalscriptclass.cpp b/src/declarative/qml/qmlglobalscriptclass.cpp index a9c5d3d..fd270e3 100644 --- a/src/declarative/qml/qmlglobalscriptclass.cpp +++ b/src/declarative/qml/qmlglobalscriptclass.cpp @@ -70,10 +70,10 @@ QmlGlobalScriptClass::queryProperty(const QScriptValue &object, const QScriptString &name, QueryFlags flags, uint *id) { - Q_UNUSED(object) - Q_UNUSED(name) - Q_UNUSED(flags) - Q_UNUSED(id) + Q_UNUSED(object); + Q_UNUSED(name); + Q_UNUSED(flags); + Q_UNUSED(id); return HandlesReadAccess | HandlesWriteAccess; } @@ -82,9 +82,9 @@ QmlGlobalScriptClass::property(const QScriptValue &object, const QScriptString &name, uint id) { - Q_UNUSED(object) - Q_UNUSED(name) - Q_UNUSED(id) + Q_UNUSED(object); + Q_UNUSED(name); + Q_UNUSED(id); return engine()->undefinedValue(); } @@ -92,8 +92,9 @@ void QmlGlobalScriptClass::setProperty(QScriptValue &object, const QScriptString &name, uint id, const QScriptValue &value) { - Q_UNUSED(object) - Q_UNUSED(value) + Q_UNUSED(object); + Q_UNUSED(id); + Q_UNUSED(value); QString error = QLatin1String("Invalid write to global property \"") + name.toString() + QLatin1String("\""); engine()->currentContext()->throwError(error); diff --git a/src/declarative/qml/qmllistscriptclass.cpp b/src/declarative/qml/qmllistscriptclass.cpp index f067db6..a180e49 100644 --- a/src/declarative/qml/qmllistscriptclass.cpp +++ b/src/declarative/qml/qmllistscriptclass.cpp @@ -54,6 +54,7 @@ QmlListScriptClass::QmlListScriptClass(QmlEngine *e) : QScriptDeclarativeClass(QmlEnginePrivate::getScriptEngine(e)), engine(e) { QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine); + Q_UNUSED(scriptEngine); m_lengthId = createPersistentIdentifier(QLatin1String("length")); } @@ -81,6 +82,8 @@ QScriptClass::QueryFlags QmlListScriptClass::queryProperty(Object *object, const Identifier &name, QScriptClass::QueryFlags flags) { + Q_UNUSED(object); + Q_UNUSED(flags); if (name == m_lengthId.identifier) return QScriptClass::HandlesReadAccess; @@ -115,9 +118,11 @@ QScriptValue QmlListScriptClass::property(Object *obj, const Identifier &name) if (data->type == QListPtr) { const QList<QObject *> &qlist = *((QList<QObject *>*)list); - if (name == m_lengthId.identifier) - return qlist.count(); - else if (lastIndex < qlist.count()) + quint32 count = qlist.count(); + + if (name == m_lengthId.identifier) + return count; + else if (lastIndex < count) return enginePriv->objectClass->newQObject(qlist.at(lastIndex)); else return scriptEngine->undefinedValue(); @@ -126,9 +131,9 @@ QScriptValue QmlListScriptClass::property(Object *obj, const Identifier &name) Q_ASSERT(data->type == QmlListPtr); const QmlList<QObject *> &qmllist = *((QmlList<QObject *>*)list); - int count = qmllist.count(); + quint32 count = qmllist.count(); - if (name == m_lengthId.identifier) + if (name == m_lengthId.identifier) return count; else if (lastIndex < count) return enginePriv->objectClass->newQObject(qmllist.at(lastIndex)); diff --git a/tests/auto/declarative/listview/data/listview-enforcerange.qml b/tests/auto/declarative/listview/data/listview-enforcerange.qml new file mode 100644 index 0000000..46fddae --- /dev/null +++ b/tests/auto/declarative/listview/data/listview-enforcerange.qml @@ -0,0 +1,55 @@ +import Qt 4.6 + +Rectangle { + width: 240 + height: 320 + color: "#ffffff" + Component { + id: myDelegate + Item { + id: wrapper + objectName: "wrapper" + height: 20 + width: 240 + Text { + text: index + } + Text { + x: 30 + id: textName + objectName: "textName" + text: name + } + Text { + x: 120 + id: textNumber + objectName: "textNumber" + text: number + } + Text { + x: 200 + text: wrapper.y + } + } + } + + Component { + id: myHighlight + Rectangle { + color: "lightsteelblue" + } + } + + ListView { + id: list + objectName: "list" + width: 240 + height: 320 + model: testModel + delegate: myDelegate + highlight: myHighlight + preferredHighlightBegin: 100 + preferredHighlightEnd: 100 + highlightRangeMode: "StrictlyEnforceRange" + } +} diff --git a/tests/auto/declarative/listview/tst_listview.cpp b/tests/auto/declarative/listview/tst_listview.cpp index e61dd55..6bf1080 100644 --- a/tests/auto/declarative/listview/tst_listview.cpp +++ b/tests/auto/declarative/listview/tst_listview.cpp @@ -69,6 +69,8 @@ private slots: void qListModelInterface_moved(); void qAbstractItemModel_moved(); + void enforceRange(); + private: template <class T> void items(); template <class T> void changed(); @@ -239,12 +241,13 @@ void tst_QmlGraphicsListView::items() canvas->execute(); qApp->processEvents(); - QmlGraphicsFlickable *listview = findItem<QmlGraphicsFlickable>(canvas->root(), "list"); + QmlGraphicsListView *listview = findItem<QmlGraphicsListView>(canvas->root(), "list"); QVERIFY(listview != 0); QmlGraphicsItem *viewport = listview->viewport(); QVERIFY(viewport != 0); + QCOMPARE(listview->count(), model.count()); QCOMPARE(viewport->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item for (int i = 0; i < model.count(); ++i) { @@ -256,6 +259,11 @@ void tst_QmlGraphicsListView::items() QCOMPARE(number->text(), model.number(i)); } + listview->incrementCurrentIndex(); + QCOMPARE(listview->currentIndex(), 1); + listview->decrementCurrentIndex(); + QCOMPARE(listview->currentIndex(), 0); + delete canvas; } @@ -583,6 +591,47 @@ void tst_QmlGraphicsListView::moved() delete canvas; } +void tst_QmlGraphicsListView::enforceRange() +{ + QmlView *canvas = createView(SRCDIR "/data/listview-enforcerange.qml"); + + TestModel model; + for (int i = 0; i < 30; i++) + model.addItem("Item" + QString::number(i), ""); + + QmlContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testModel", &model); + + canvas->execute(); + qApp->processEvents(); + + QmlGraphicsListView *listview = findItem<QmlGraphicsListView>(canvas->root(), "list"); + QVERIFY(listview != 0); + + QmlGraphicsItem *viewport = listview->viewport(); + QVERIFY(viewport != 0); + + // view should be positioned at the top of the range. + QmlGraphicsItem *item = findItem<QmlGraphicsItem>(viewport, "wrapper", 0); + QVERIFY(item); + QCOMPARE(listview->viewportY(), -100.0); + + QmlGraphicsText *name = findItem<QmlGraphicsText>(viewport, "textName", 0); + QVERIFY(name != 0); + QCOMPARE(name->text(), model.name(0)); + QmlGraphicsText *number = findItem<QmlGraphicsText>(viewport, "textNumber", 0); + QVERIFY(number != 0); + QCOMPARE(number->text(), model.number(0)); + + // Check currentIndex is updated when viewport moves + listview->setViewportY(20); + QTest::qWait(1000); + + QCOMPARE(listview->currentIndex(), 6); + + delete canvas; +} + void tst_QmlGraphicsListView::qListModelInterface_items() { items<TestModel>(); diff --git a/tests/auto/declarative/qmlxmllistmodel/data/model.qml b/tests/auto/declarative/qmlxmllistmodel/data/model.qml index 199a447..2cbb027 100644 --- a/tests/auto/declarative/qmlxmllistmodel/data/model.qml +++ b/tests/auto/declarative/qmlxmllistmodel/data/model.qml @@ -2,7 +2,7 @@ import Qt 4.6 XmlListModel { source: "model.xml" - query: "/ListModel/ListElement" + query: "/Pets/Pet" XmlRole { name: "name"; query: "name/string()" } XmlRole { name: "type"; query: "type/string()" } XmlRole { name: "age"; query: "age/number()" } diff --git a/tests/auto/declarative/qmlxmllistmodel/data/model.xml b/tests/auto/declarative/qmlxmllistmodel/data/model.xml index f1fe742..40cd6d0 100644 --- a/tests/auto/declarative/qmlxmllistmodel/data/model.xml +++ b/tests/auto/declarative/qmlxmllistmodel/data/model.xml @@ -1,56 +1,54 @@ -<ListModel> - <ListElement> +<Pets> + <Pet> <name>Polly</name> <type>Parrot</type> <age>12</age> <size>Small</size> - </ListElement> - <ListElement> + </Pet> + <Pet> <name>Penny</name> <type>Turtle</type> <age>4</age> <size>Small</size> - </ListElement> - <ListElement> + </Pet> + <Pet> <name>Warren</name> <type>Rabbit</type> <age>2</age> <size>Small</size> - </ListElement> - <ListElement> + </Pet> + <Pet> <name>Spot</name> <type>Dog</type> <age>9</age> <size>Medium</size> - </ListElement> - <ListElement> + </Pet> + <Pet> <name>Whiskers</name> <type>Cat</type> <age>2</age> <size>Medium</size> - </ListElement> - <ListElement> + </Pet> + <Pet> <name>Joey</name> <type>Kangaroo</type> <age>1</age> - <size>Medium</size> - </ListElement> - <ListElement> + </Pet> + <Pet> <name>Kimba</name> <type>Bunny</type> <age>65</age> <size>Large</size> - </ListElement> - <ListElement> + </Pet> + <Pet> <name>Rover</name> <type>Dog</type> - <age>5</age> <size>Large</size> - </ListElement> - <ListElement> + </Pet> + <Pet> <name>Tiny</name> <type>Elephant</type> <age>15</age> <size>Large</size> - </ListElement> -</ListModel> + </Pet> +</Pets> diff --git a/tests/auto/declarative/qmlxmllistmodel/data/recipes.qml b/tests/auto/declarative/qmlxmllistmodel/data/recipes.qml new file mode 100644 index 0000000..13dea91 --- /dev/null +++ b/tests/auto/declarative/qmlxmllistmodel/data/recipes.qml @@ -0,0 +1,10 @@ +import Qt 4.6 + +XmlListModel { + source: "recipes.xml" + query: "/recipes/recipe" + XmlRole { name: "title"; query: "@title/string()" } + XmlRole { name: "picture"; query: "picture/string()" } + XmlRole { name: "ingredients"; query: "ingredients/string()" } + XmlRole { name: "preparation"; query: "method/string()" } +} diff --git a/tests/auto/declarative/qmlxmllistmodel/data/recipes.xml b/tests/auto/declarative/qmlxmllistmodel/data/recipes.xml new file mode 100644 index 0000000..d71de60 --- /dev/null +++ b/tests/auto/declarative/qmlxmllistmodel/data/recipes.xml @@ -0,0 +1,90 @@ +<recipes> + <recipe title="Pancakes"> + <picture>content/pics/pancakes.jpg</picture> + <ingredients><![CDATA[<html> + <ul> + <li> 1 cup (150g) self-raising flour + <li> 1 tbs caster sugar + <li> 3/4 cup (185ml) milk + <li> 1 egg + </ul> + </html> + ]]></ingredients> + <method><![CDATA[<html> + <ol> + <li> Sift flour and sugar together into a bowl. Add a pinch of salt. + <li> Beat milk and egg together, then add to dry ingredients. Beat until smooth. + <li> Pour mixture into a pan on medium heat and cook until bubbles appear on the surface. + <li> Turn over and cook other side until golden. + </ol> + </html> + ]]></method> + </recipe> + <recipe title="Fruit Salad"> + <picture>content/pics/fruit-salad.jpg</picture> + <ingredients><![CDATA[* Seasonal Fruit]]></ingredients> + <method><![CDATA[* Chop fruit and place in a bowl.]]></method> + </recipe> + <recipe title="Vegetable Soup"> + <picture>content/pics/vegetable-soup.jpg</picture> + <ingredients><![CDATA[<html> + <ul> + <li> 1 onion + <li> 1 turnip + <li> 1 potato + <li> 1 carrot + <li> 1 head of celery + <li> 1 1/2 litres of water + </ul> + </html> + ]]></ingredients> + <method><![CDATA[<html> + <ol> + <li> Chop vegetables. + <li> Boil in water until vegetables soften. + <li> Season with salt and pepper to taste. + </ol> + </html> + ]]></method> + </recipe> + <recipe title="Hamburger"> + <picture>content/pics/hamburger.jpg</picture> + <ingredients><![CDATA[<html> + <ul> + <li> 500g minced beef + <li> Seasoning + <li> lettuce, tomato, onion, cheese + <li> 1 hamburger bun for each burger + </ul> + </html> + ]]></ingredients> + <method><![CDATA[<html> + <ol> + <li> Mix the beef, together with seasoning, in a food processor. + <li> Shape the beef into burgers. + <li> Grill the burgers for about 5 mins on each side (until cooked through) + <li> Serve each burger on a bun with ketchup, cheese, lettuce, tomato and onion. + </ol> + </html> + ]]></method> + </recipe> + <recipe title="Lemonade"> + <picture>content/pics/lemonade.jpg</picture> + <ingredients><![CDATA[<html> + <ul> + <li> 1 cup Lemon Juice + <li> 1 cup Sugar + <li> 6 Cups of Water (2 cups warm water, 4 cups cold water) + </ul> + </html> + ]]></ingredients> + <method><![CDATA[<html> + <ol> + <li> Pour 2 cups of warm water into a pitcher and stir in sugar until it dissolves. + <li> Pour in lemon juice, stir again, and add 4 cups of cold water. + <li> Chill or serve over ice cubes. + </ol> + </html> + ]]></method> + </recipe> +</recipes> diff --git a/tests/auto/declarative/qmlxmllistmodel/tst_qmlxmllistmodel.cpp b/tests/auto/declarative/qmlxmllistmodel/tst_qmlxmllistmodel.cpp index 0fc9006..4898686 100644 --- a/tests/auto/declarative/qmlxmllistmodel/tst_qmlxmllistmodel.cpp +++ b/tests/auto/declarative/qmlxmllistmodel/tst_qmlxmllistmodel.cpp @@ -53,6 +53,9 @@ public: private slots: void buildModel(); + void missingFields(); + void cdata(); + void attributes(); private: QmlEngine engine; @@ -75,6 +78,54 @@ void tst_qmlxmllistmodel::buildModel() QCOMPARE(data.value(Qt::UserRole+3).toString(), QLatin1String("Medium")); } +void tst_qmlxmllistmodel::missingFields() +{ + QmlComponent component(&engine, QUrl("file://" SRCDIR "/data/model2.qml")); + QmlXmlListModel *listModel = qobject_cast<QmlXmlListModel*>(component.create()); + QVERIFY(listModel != 0); + QTRY_COMPARE(listModel->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); + 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); + QVERIFY(data.count() == 5); + QCOMPARE(data.value(Qt::UserRole+2).toString(), QLatin1String("")); +} + +void tst_qmlxmllistmodel::cdata() +{ + QmlComponent component(&engine, QUrl("file://" SRCDIR "/data/recipes.qml")); + QmlXmlListModel *listModel = qobject_cast<QmlXmlListModel*>(component.create()); + QVERIFY(listModel != 0); + QTRY_COMPARE(listModel->count(), 5); + + QList<int> roles; + roles << Qt::UserRole + 2; + QHash<int, QVariant> data = listModel->data(2, roles); + QVERIFY(data.count() == 1); + QVERIFY(data.value(Qt::UserRole+2).toString().startsWith(QLatin1String("<html>"))); +} + +void tst_qmlxmllistmodel::attributes() +{ + QmlComponent component(&engine, QUrl("file://" SRCDIR "/data/recipes.qml")); + QmlXmlListModel *listModel = qobject_cast<QmlXmlListModel*>(component.create()); + QVERIFY(listModel != 0); + QTRY_COMPARE(listModel->count(), 5); + + QList<int> roles; + roles << Qt::UserRole; + QHash<int, QVariant> data = listModel->data(2, roles); + QVERIFY(data.count() == 1); + QCOMPARE(data.value(Qt::UserRole).toString(), QLatin1String("Vegetable Soup")); +} + + QTEST_MAIN(tst_qmlxmllistmodel) #include "tst_qmlxmllistmodel.moc" |