From 950f3849e3bd2edd6bcc2784dbeadcb604c38e2d Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 25 Feb 2010 10:21:52 +1000 Subject: React to QAbstractItemModel::modelReset() signal. Task-number: QTBUG-8494 --- .../graphicsitems/qdeclarativegridview.cpp | 12 +++++ .../graphicsitems/qdeclarativegridview_p.h | 1 + .../graphicsitems/qdeclarativelistview.cpp | 12 +++++ .../graphicsitems/qdeclarativelistview_p.h | 1 + .../graphicsitems/qdeclarativepathview.cpp | 10 +++- .../graphicsitems/qdeclarativepathview_p.h | 1 + .../graphicsitems/qdeclarativerepeater.cpp | 7 +++ .../graphicsitems/qdeclarativerepeater_p.h | 1 + .../graphicsitems/qdeclarativevisualitemmodel.cpp | 8 +++ .../graphicsitems/qdeclarativevisualitemmodel_p.h | 2 + .../qdeclarativegridview/data/displaygrid.qml | 39 ++++++++++++++ .../tst_qdeclarativegridview.cpp | 43 ++++++++++++++++ .../qdeclarativelistview/data/displaylist.qml | 43 ++++++++++++++++ .../tst_qdeclarativelistview.cpp | 43 ++++++++++++++++ .../qdeclarativepathview/data/displaypath.qml | 60 ++++++++++++++++++++++ .../tst_qdeclarativepathview.cpp | 41 +++++++++++++++ 16 files changed, 323 insertions(+), 1 deletion(-) create mode 100644 tests/auto/declarative/qdeclarativegridview/data/displaygrid.qml create mode 100644 tests/auto/declarative/qdeclarativelistview/data/displaylist.qml create mode 100644 tests/auto/declarative/qdeclarativepathview/data/displaypath.qml diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index 2ef6305..b378db2 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -787,6 +787,7 @@ void QDeclarativeGridView::setModel(const QVariant &model) disconnect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); disconnect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); disconnect(d->model, SIGNAL(itemsMoved(int,int,int)), this, SLOT(itemsMoved(int,int,int))); + disconnect(d->model, SIGNAL(modelReset()), this, SLOT(modelReset())); disconnect(d->model, SIGNAL(createdItem(int, QDeclarativeItem*)), this, SLOT(createdItem(int,QDeclarativeItem*))); disconnect(d->model, SIGNAL(destroyingItem(QDeclarativeItem*)), this, SLOT(destroyingItem(QDeclarativeItem*))); } @@ -821,6 +822,7 @@ void QDeclarativeGridView::setModel(const QVariant &model) connect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); connect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); connect(d->model, SIGNAL(itemsMoved(int,int,int)), this, SLOT(itemsMoved(int,int,int))); + connect(d->model, SIGNAL(modelReset()), this, SLOT(modelReset())); connect(d->model, SIGNAL(createdItem(int, QDeclarativeItem*)), this, SLOT(createdItem(int,QDeclarativeItem*))); connect(d->model, SIGNAL(destroyingItem(QDeclarativeItem*)), this, SLOT(destroyingItem(QDeclarativeItem*))); emit countChanged(); @@ -1688,6 +1690,16 @@ void QDeclarativeGridView::itemsMoved(int from, int to, int count) d->layout(removedBeforeVisible); } +void QDeclarativeGridView::modelReset() +{ + Q_D(QDeclarativeGridView); + d->clear(); + refill(); + d->moveReason = QDeclarativeGridViewPrivate::SetIndex; + d->updateCurrent(d->currentIndex); + emit countChanged(); +} + void QDeclarativeGridView::createdItem(int index, QDeclarativeItem *item) { Q_D(QDeclarativeGridView); diff --git a/src/declarative/graphicsitems/qdeclarativegridview_p.h b/src/declarative/graphicsitems/qdeclarativegridview_p.h index b36c4aa..b488475 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview_p.h +++ b/src/declarative/graphicsitems/qdeclarativegridview_p.h @@ -144,6 +144,7 @@ private Q_SLOTS: void itemsInserted(int index, int count); void itemsRemoved(int index, int count); void itemsMoved(int from, int to, int count); + void modelReset(); void destroyRemoved(); void createdItem(int index, QDeclarativeItem *item); void destroyingItem(QDeclarativeItem *item); diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index 77e3a15..bd2f4fc 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -1477,6 +1477,7 @@ void QDeclarativeListView::setModel(const QVariant &model) disconnect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); disconnect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); disconnect(d->model, SIGNAL(itemsMoved(int,int,int)), this, SLOT(itemsMoved(int,int,int))); + disconnect(d->model, SIGNAL(modelReset()), this, SLOT(modelReset())); disconnect(d->model, SIGNAL(createdItem(int, QDeclarativeItem*)), this, SLOT(createdItem(int,QDeclarativeItem*))); disconnect(d->model, SIGNAL(destroyingItem(QDeclarativeItem*)), this, SLOT(destroyingItem(QDeclarativeItem*))); } @@ -1511,6 +1512,7 @@ void QDeclarativeListView::setModel(const QVariant &model) connect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); connect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); connect(d->model, SIGNAL(itemsMoved(int,int,int)), this, SLOT(itemsMoved(int,int,int))); + connect(d->model, SIGNAL(modelReset()), this, SLOT(modelReset())); connect(d->model, SIGNAL(createdItem(int, QDeclarativeItem*)), this, SLOT(createdItem(int,QDeclarativeItem*))); connect(d->model, SIGNAL(destroyingItem(QDeclarativeItem*)), this, SLOT(destroyingItem(QDeclarativeItem*))); emit countChanged(); @@ -2684,6 +2686,16 @@ void QDeclarativeListView::itemsMoved(int from, int to, int count) d->layout(); } +void QDeclarativeListView::modelReset() +{ + Q_D(QDeclarativeListView); + d->clear(); + refill(); + d->moveReason = QDeclarativeListViewPrivate::SetIndex; + d->updateCurrent(d->currentIndex); + emit countChanged(); +} + void QDeclarativeListView::createdItem(int index, QDeclarativeItem *item) { Q_D(QDeclarativeListView); diff --git a/src/declarative/graphicsitems/qdeclarativelistview_p.h b/src/declarative/graphicsitems/qdeclarativelistview_p.h index 1b6276e..5e3edb0 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview_p.h +++ b/src/declarative/graphicsitems/qdeclarativelistview_p.h @@ -221,6 +221,7 @@ private Q_SLOTS: void itemsInserted(int index, int count); void itemsRemoved(int index, int count); void itemsMoved(int from, int to, int count); + void modelReset(); void destroyRemoved(); void createdItem(int index, QDeclarativeItem *item); void destroyingItem(QDeclarativeItem *item); diff --git a/src/declarative/graphicsitems/qdeclarativepathview.cpp b/src/declarative/graphicsitems/qdeclarativepathview.cpp index b9e38ef..c131f4c 100644 --- a/src/declarative/graphicsitems/qdeclarativepathview.cpp +++ b/src/declarative/graphicsitems/qdeclarativepathview.cpp @@ -206,6 +206,7 @@ void QDeclarativePathView::setModel(const QVariant &model) if (d->model) { disconnect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); disconnect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); + disconnect(d->model, SIGNAL(modelReset()), this, SLOT(modelReset())); disconnect(d->model, SIGNAL(createdItem(int, QDeclarativeItem*)), this, SLOT(createdItem(int,QDeclarativeItem*))); for (int i=0; iitems.count(); i++){ QDeclarativeItem *p = d->items[i]; @@ -234,6 +235,7 @@ void QDeclarativePathView::setModel(const QVariant &model) if (d->model) { connect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); connect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); + connect(d->model, SIGNAL(modelReset()), this, SLOT(modelReset())); connect(d->model, SIGNAL(createdItem(int, QDeclarativeItem*)), this, SLOT(createdItem(int,QDeclarativeItem*))); } d->firstIndex = 0; @@ -782,7 +784,7 @@ void QDeclarativePathView::itemsRemoved(int modelIndex, int count) if (!d->isValid() || !isComponentComplete()) return; if (d->pathItems == -1) { - for (int i = 0; i < count; ++i) { + for (int i = 0; i < count && d->items.count() > modelIndex; ++i) { QDeclarativeItem* p = d->items.takeAt(modelIndex); d->model->release(p); } @@ -812,6 +814,12 @@ void QDeclarativePathView::itemsRemoved(int modelIndex, int count) d->moveOffset.setValue(targetOffset); } +void QDeclarativePathView::modelReset() +{ + Q_D(QDeclarativePathView); + d->regenerate(); +} + void QDeclarativePathView::createdItem(int index, QDeclarativeItem *item) { Q_D(QDeclarativePathView); diff --git a/src/declarative/graphicsitems/qdeclarativepathview_p.h b/src/declarative/graphicsitems/qdeclarativepathview_p.h index d351a4e..709a4fc 100644 --- a/src/declarative/graphicsitems/qdeclarativepathview_p.h +++ b/src/declarative/graphicsitems/qdeclarativepathview_p.h @@ -115,6 +115,7 @@ private Q_SLOTS: void ticked(); void itemsInserted(int index, int count); void itemsRemoved(int index, int count); + void modelReset(); void createdItem(int index, QDeclarativeItem *item); void destroyingItem(QDeclarativeItem *item); diff --git a/src/declarative/graphicsitems/qdeclarativerepeater.cpp b/src/declarative/graphicsitems/qdeclarativerepeater.cpp index ca57d3c..e4cd499 100644 --- a/src/declarative/graphicsitems/qdeclarativerepeater.cpp +++ b/src/declarative/graphicsitems/qdeclarativerepeater.cpp @@ -166,6 +166,7 @@ void QDeclarativeRepeater::setModel(const QVariant &model) disconnect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); disconnect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); disconnect(d->model, SIGNAL(itemsMoved(int,int,int)), this, SLOT(itemsMoved(int,int,int))); + disconnect(d->model, SIGNAL(modelReset()), this, SLOT(modelReset())); /* disconnect(d->model, SIGNAL(createdItem(int, QDeclarativeItem*)), this, SLOT(createdItem(int,QDeclarativeItem*))); disconnect(d->model, SIGNAL(destroyingItem(QDeclarativeItem*)), this, SLOT(destroyingItem(QDeclarativeItem*))); @@ -193,6 +194,7 @@ void QDeclarativeRepeater::setModel(const QVariant &model) connect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); connect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); connect(d->model, SIGNAL(itemsMoved(int,int,int)), this, SLOT(itemsMoved(int,int,int))); + connect(d->model, SIGNAL(modelReset()), this, SLOT(modelReset())); /* connect(d->model, SIGNAL(createdItem(int, QDeclarativeItem*)), this, SLOT(createdItem(int,QDeclarativeItem*))); connect(d->model, SIGNAL(destroyingItem(QDeclarativeItem*)), this, SLOT(destroyingItem(QDeclarativeItem*))); @@ -325,4 +327,9 @@ void QDeclarativeRepeater::itemsMoved(int,int,int) regenerate(); } +void QDeclarativeRepeater::modelReset() +{ + regenerate(); +} + QT_END_NAMESPACE diff --git a/src/declarative/graphicsitems/qdeclarativerepeater_p.h b/src/declarative/graphicsitems/qdeclarativerepeater_p.h index f58d1b6..db46699 100644 --- a/src/declarative/graphicsitems/qdeclarativerepeater_p.h +++ b/src/declarative/graphicsitems/qdeclarativerepeater_p.h @@ -88,6 +88,7 @@ private Q_SLOTS: void itemsInserted(int,int); void itemsRemoved(int,int); void itemsMoved(int,int,int); + void modelReset(); private: Q_DISABLE_COPY(QDeclarativeRepeater) diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp index bfe8db9..8114f9b 100644 --- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp @@ -660,6 +660,7 @@ void QDeclarativeVisualDataModel::setModel(const QVariant &model) this, SLOT(_q_dataChanged(const QModelIndex&,const QModelIndex&))); QObject::disconnect(d->m_abstractItemModel, SIGNAL(rowsMoved(const QModelIndex&,int,int,const QModelIndex&,int)), this, SLOT(_q_rowsMoved(const QModelIndex&,int,int,const QModelIndex&,int))); + QObject::disconnect(d->m_abstractItemModel, SIGNAL(modelReset()), this, SLOT(_q_modelReset())); } else if (d->m_visualItemModel) { QObject::disconnect(d->m_visualItemModel, SIGNAL(itemsInserted(int,int)), this, SIGNAL(itemsInserted(int,int))); @@ -705,6 +706,7 @@ void QDeclarativeVisualDataModel::setModel(const QVariant &model) this, SLOT(_q_dataChanged(const QModelIndex&,const QModelIndex&))); QObject::connect(d->m_abstractItemModel, SIGNAL(rowsMoved(const QModelIndex&,int,int,const QModelIndex&,int)), this, SLOT(_q_rowsMoved(const QModelIndex&,int,int,const QModelIndex&,int))); + QObject::connect(d->m_abstractItemModel, SIGNAL(modelReset()), this, SLOT(_q_modelReset())); d->m_metaDataCacheable = true; return; } @@ -1237,6 +1239,12 @@ void QDeclarativeVisualDataModel::_q_dataChanged(const QModelIndex &begin, const _q_itemsChanged(begin.row(), end.row() - begin.row() + 1, d->m_roles); } +void QDeclarativeVisualDataModel::_q_modelReset() +{ + Q_D(QDeclarativeVisualDataModel); + emit modelReset(); +} + void QDeclarativeVisualDataModel::_q_createdPackage(int index, QDeclarativePackage *package) { Q_D(QDeclarativeVisualDataModel); diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel_p.h b/src/declarative/graphicsitems/qdeclarativevisualitemmodel_p.h index 76c8994..d34bcaf 100644 --- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel_p.h +++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel_p.h @@ -93,6 +93,7 @@ Q_SIGNALS: void itemsInserted(int index, int count); void itemsRemoved(int index, int count); void itemsMoved(int from, int to, int count); + void modelReset(); void createdItem(int index, QDeclarativeItem *item); void destroyingItem(QDeclarativeItem *item); @@ -195,6 +196,7 @@ private Q_SLOTS: void _q_rowsRemoved(const QModelIndex &,int,int); void _q_rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int); void _q_dataChanged(const QModelIndex&,const QModelIndex&); + void _q_modelReset(); void _q_createdPackage(int index, QDeclarativePackage *package); void _q_destroyingPackage(QDeclarativePackage *package); diff --git a/tests/auto/declarative/qdeclarativegridview/data/displaygrid.qml b/tests/auto/declarative/qdeclarativegridview/data/displaygrid.qml new file mode 100644 index 0000000..d3cdcd8 --- /dev/null +++ b/tests/auto/declarative/qdeclarativegridview/data/displaygrid.qml @@ -0,0 +1,39 @@ +import Qt 4.6 + +Rectangle { + width: 240 + height: 320 + color: "#ffffff" + resources: [ + Component { + id: myDelegate + Rectangle { + id: wrapper + objectName: "wrapper" + width: 80 + height: 60 + border.color: "blue" + Text { + text: index + } + Text { + y: 20 + id: displayText + objectName: "displayText" + text: display + } + color: GridView.isCurrentItem ? "lightsteelblue" : "white" + } + } + ] + GridView { + id: grid + objectName: "grid" + width: 240 + height: 320 + cellWidth: 80 + cellHeight: 60 + model: testModel + delegate: myDelegate + } +} diff --git a/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp b/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp index 9c7468d..9c9d1d3 100644 --- a/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp +++ b/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp @@ -41,6 +41,7 @@ #include #include +#include #include #include #include @@ -66,6 +67,7 @@ private slots: void defaultValues(); void properties(); void positionViewAtIndex(); + void resetModel(); void QTBUG_8456(); private: @@ -884,6 +886,47 @@ void tst_QDeclarativeGridView::positionViewAtIndex() delete canvas; } +void tst_QDeclarativeGridView::resetModel() +{ + QDeclarativeView *canvas = createView(); + + QStringList strings; + strings << "one" << "two" << "three"; + QStringListModel model(strings); + + QDeclarativeContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testModel", &model); + + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/displaygrid.qml")); + qApp->processEvents(); + + QDeclarativeGridView *gridview = findItem(canvas->rootObject(), "grid"); + QVERIFY(gridview != 0); + + QDeclarativeItem *viewport = gridview->viewport(); + QVERIFY(viewport != 0); + + QCOMPARE(gridview->count(), model.rowCount()); + + for (int i = 0; i < model.rowCount(); ++i) { + QDeclarativeText *display = findItem(viewport, "displayText", i); + QVERIFY(display != 0); + QCOMPARE(display->text(), strings.at(i)); + } + + strings.clear(); + strings << "four" << "five" << "six" << "seven"; + model.setStringList(strings); + + QCOMPARE(gridview->count(), model.rowCount()); + + for (int i = 0; i < model.rowCount(); ++i) { + QDeclarativeText *display = findItem(viewport, "displayText", i); + QVERIFY(display != 0); + QCOMPARE(display->text(), strings.at(i)); + } +} + void tst_QDeclarativeGridView::QTBUG_8456() { QDeclarativeView *canvas = createView(); diff --git a/tests/auto/declarative/qdeclarativelistview/data/displaylist.qml b/tests/auto/declarative/qdeclarativelistview/data/displaylist.qml new file mode 100644 index 0000000..7b124a5 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelistview/data/displaylist.qml @@ -0,0 +1,43 @@ +import Qt 4.6 + +Rectangle { + width: 240 + height: 320 + color: "#ffffff" + resources: [ + Component { + id: myDelegate + Rectangle { + id: wrapper + objectName: "wrapper" + height: 20 + width: 240 + Text { + text: index + } + Text { + x: 30 + objectName: "displayText" + text: display + } + color: ListView.isCurrentItem ? "lightsteelblue" : "white" + } + }, + Component { + id: myHighlight + Rectangle { color: "green" } + } + ] + ListView { + id: list + objectName: "list" + focus: true + width: 240 + height: 320 + model: testModel + delegate: myDelegate + highlight: myHighlight + highlightMoveSpeed: 1000 + highlightResizeSpeed: 1000 + } +} diff --git a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp index daa40d1..9100522 100644 --- a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp +++ b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp @@ -39,6 +39,7 @@ ** ****************************************************************************/ #include +#include #include #include #include @@ -80,6 +81,7 @@ private slots: void sections(); void cacheBuffer(); void positionViewAtIndex(); + void resetModel(); private: template void items(); @@ -1232,6 +1234,47 @@ void tst_QDeclarativeListView::positionViewAtIndex() delete canvas; } +void tst_QDeclarativeListView::resetModel() +{ + QDeclarativeView *canvas = createView(); + + QStringList strings; + strings << "one" << "two" << "three"; + QStringListModel model(strings); + + QDeclarativeContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testModel", &model); + + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/displaylist.qml")); + qApp->processEvents(); + + QDeclarativeListView *listview = findItem(canvas->rootObject(), "list"); + QVERIFY(listview != 0); + + QDeclarativeItem *viewport = listview->viewport(); + QVERIFY(viewport != 0); + + QCOMPARE(listview->count(), model.rowCount()); + + for (int i = 0; i < model.rowCount(); ++i) { + QDeclarativeText *display = findItem(viewport, "displayText", i); + QVERIFY(display != 0); + QCOMPARE(display->text(), strings.at(i)); + } + + strings.clear(); + strings << "four" << "five" << "six" << "seven"; + model.setStringList(strings); + + QCOMPARE(listview->count(), model.rowCount()); + + for (int i = 0; i < model.rowCount(); ++i) { + QDeclarativeText *display = findItem(viewport, "displayText", i); + QVERIFY(display != 0); + QCOMPARE(display->text(), strings.at(i)); + } +} + void tst_QDeclarativeListView::qListModelInterface_items() { items(); diff --git a/tests/auto/declarative/qdeclarativepathview/data/displaypath.qml b/tests/auto/declarative/qdeclarativepathview/data/displaypath.qml new file mode 100644 index 0000000..627f38a --- /dev/null +++ b/tests/auto/declarative/qdeclarativepathview/data/displaypath.qml @@ -0,0 +1,60 @@ +import Qt 4.6 + +Rectangle { + width: 240 + height: 320 + color: "#ffffff" + resources: [ + Component { + id: delegate + Rectangle { + id: wrapper + objectName: "wrapper" + height: 20 + width: 60 + color: "white" + border.color: "black" + Text { + text: index + } + Text { + x: 20 + id: displayText + objectName: "displayText" + text: display + } + } + } + ] + PathView { + id: view + objectName: "view" + width: 240 + height: 320 + model: testModel + delegate: delegate + snapPosition: 0.01 + path: Path { + startY: 120 + startX: 160 + PathQuad { + y: 120 + x: 80 + controlY: 330 + controlX: 100 + } + PathLine { + y: 160 + x: 20 + } + PathCubic { + y: 120 + x: 160 + control1Y: 0 + control1X: 100 + control2Y: 000 + control2X: 200 + } + } + } +} diff --git a/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp b/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp index 09f0f79..79bc607 100644 --- a/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp +++ b/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp @@ -49,6 +49,7 @@ #include #include #include +#include #include #include #include "../../../shared/util.h" @@ -67,6 +68,7 @@ private slots: void pathview3(); void path(); void pathMoved(); + void resetModel(); private: QDeclarativeView *createView(); @@ -425,6 +427,45 @@ void tst_QDeclarativePathView::pathMoved() delete canvas; } +void tst_QDeclarativePathView::resetModel() +{ + QDeclarativeView *canvas = createView(); + + QStringList strings; + strings << "one" << "two" << "three"; + QStringListModel model(strings); + + QDeclarativeContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testModel", &model); + + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/displaypath.qml")); + qApp->processEvents(); + + QDeclarativePathView *pathview = findItem(canvas->rootObject(), "view"); + QVERIFY(pathview != 0); + + QCOMPARE(pathview->count(), model.rowCount()); + + for (int i = 0; i < model.rowCount(); ++i) { + QDeclarativeText *display = findItem(pathview, "displayText", i); + QVERIFY(display != 0); + QCOMPARE(display->text(), strings.at(i)); + } + + strings.clear(); + strings << "four" << "five" << "six" << "seven"; + model.setStringList(strings); + + QCOMPARE(pathview->count(), model.rowCount()); + + for (int i = 0; i < model.rowCount(); ++i) { + QDeclarativeText *display = findItem(pathview, "displayText", i); + QVERIFY(display != 0); + QCOMPARE(display->text(), strings.at(i)); + } +} + + QDeclarativeView *tst_QDeclarativePathView::createView() { QDeclarativeView *canvas = new QDeclarativeView(0); -- cgit v0.12 From 9616583e19bb642da8f2d2f4305ddef8ee16feb3 Mon Sep 17 00:00:00 2001 From: Leonardo Sobral Cunha Date: Thu, 25 Feb 2010 15:25:41 +1000 Subject: Fix QDeclarativePropertyAnimation to avoid property writes while stopped Avoid changing the value of the property, while the animation is stopped. This was triggered while changing the duration of the animation, while it was stopped. Task-number: QTBUG-8507 Reviewed-by: Michael Brasser --- src/declarative/util/qdeclarativeanimation_p_p.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/declarative/util/qdeclarativeanimation_p_p.h b/src/declarative/util/qdeclarativeanimation_p_p.h index bb81fb3..65c9807 100644 --- a/src/declarative/util/qdeclarativeanimation_p_p.h +++ b/src/declarative/util/qdeclarativeanimation_p_p.h @@ -165,6 +165,9 @@ public: protected: virtual void updateCurrentValue(const QVariant &value) { + if (state() == QAbstractAnimation::Stopped) + return; + if (animValue) animValue->setValue(value.toReal()); } -- cgit v0.12 From d16d34a90d20e326a38b890e3665b3b8656ee414 Mon Sep 17 00:00:00 2001 From: Leonardo Sobral Cunha Date: Thu, 25 Feb 2010 15:51:14 +1000 Subject: Recfactor in declarative snake demo Avoid having 2 'states' that have 'when' conditions that can be 'true' at the same time. --- demos/declarative/snake/snake.qml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/demos/declarative/snake/snake.qml b/demos/declarative/snake/snake.qml index 3bec747..09b6b7f 100644 --- a/demos/declarative/snake/snake.qml +++ b/demos/declarative/snake/snake.qml @@ -172,14 +172,14 @@ Rectangle { states: [ State { name: "starting" - when: startHeartbeatTimer.running; + when: startHeartbeatTimer.running PropertyChanges {target: progressIndicator; width: 200} PropertyChanges {target: title; opacity: 0} PropertyChanges {target: progressBar; opacity: 1} }, State { name: "running" - when: heartbeat.running + when: (heartbeat.running && !startHeartbeatTimer.running) PropertyChanges {target: progressIndicator; width: 200} PropertyChanges {target: title; opacity: 0} PropertyChanges {target: skull; row: 0; column: 0; } -- cgit v0.12 From b3613f3f3135afeaa9425b1791567185cbc38435 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 25 Feb 2010 16:05:19 +1000 Subject: Document Package --- doc/src/declarative/elements.qdoc | 1 + .../graphicsitems/qdeclarativevisualitemmodel.cpp | 27 ++++++++++++++++++++++ src/declarative/util/qdeclarativepackage.cpp | 27 ++++++++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/doc/src/declarative/elements.qdoc b/doc/src/declarative/elements.qdoc index 470a78c..da96b8e 100644 --- a/doc/src/declarative/elements.qdoc +++ b/doc/src/declarative/elements.qdoc @@ -89,6 +89,7 @@ The following table lists the QML elements provided by the Qt Declarative module \o \l ListModel, \l ListElement \o \l VisualItemModel \o \l VisualDataModel +\o \l Package \o \l XmlListModel and XmlRole \o \l DateTimeFormatter \o \l NumberFormatter diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp index 8114f9b..2402648 100644 --- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp @@ -929,6 +929,33 @@ QDeclarativeVisualDataModel::ReleaseFlags QDeclarativeVisualDataModel::release(Q return stat; } +/*! + \qmlproperty object VisualDataModel::parts + + The \a parts property selects a VisualDataModel which creates + delegates from the part named. This is used in conjunction with + the Package element. + + For example, the code below selects a model which creates + delegates named \e list from a Package: + + \code + VisualDataModel { + id: visualModel + delegate: Package { + Item { Package.name: "list" } + } + model: myModel + } + + ListView { + width: 200; height:200 + model: visualModel.parts.list + } + \endcode + + \sa Package +*/ QObject *QDeclarativeVisualDataModel::parts() { Q_D(QDeclarativeVisualDataModel); diff --git a/src/declarative/util/qdeclarativepackage.cpp b/src/declarative/util/qdeclarativepackage.cpp index 356d7a1..34ae466 100644 --- a/src/declarative/util/qdeclarativepackage.cpp +++ b/src/declarative/util/qdeclarativepackage.cpp @@ -46,6 +46,33 @@ QT_BEGIN_NAMESPACE +/*! + \qmlclass Package QDeclarativePackage + \brief Package provides a collection of named items + + The Package class is currently used in conjunction with + VisualDataModel to enable delegates with a shared context + to be provided to multiple views. + + Any item within a Package may be assigned a name via the + \e {Package.name} attached property. + + The example below creates a Package containing two named items; + \e list and \e grid. The third element in the package is parented to whichever + delegate it should appear in. This allows an item to move + between views. + + \snippet examples/declarative/package/Delegate.qml 0 + + These named items are used as the delegates by the two views who + reference the special VisualDataModel.parts property to select + a model which provides the chosen delegate. + + \snippet examples/declarative/package/view.qml 0 + +*/ + + class QDeclarativePackagePrivate : public QObjectPrivate { public: -- cgit v0.12 From 7c589d3584045f2f3eaac7d9eb36c5a17f8f2067 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 25 Feb 2010 16:06:13 +1000 Subject: Add simple Package example. --- examples/declarative/package/Delegate.qml | 44 +++++++++++++++++++++++++++++++ examples/declarative/package/view.qml | 35 ++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 examples/declarative/package/Delegate.qml create mode 100644 examples/declarative/package/view.qml diff --git a/examples/declarative/package/Delegate.qml b/examples/declarative/package/Delegate.qml new file mode 100644 index 0000000..4109633 --- /dev/null +++ b/examples/declarative/package/Delegate.qml @@ -0,0 +1,44 @@ +import Qt 4.6 + +//![0] +Package { + Text { id: listDelegate; width: 200; height: 25; text: "Empty"; Package.name: "list" } + Text { id: gridDelegate; width: 100; height: 50; text: "Empty"; Package.name: "grid" } + + Rectangle { + id: wrapper + width: 200; height: 25 + color: "lightsteelblue" + Text { text: display; anchors.centerIn: parent } + MouseRegion { + anchors.fill: parent + onClicked: { + if (wrapper.state == "inList") + wrapper.state = "inGrid"; + else + wrapper.state = "inList"; + } + } + state: "inList" + states: [ + State { + name: 'inList' + ParentChange { target: wrapper; parent: listDelegate } + }, + State { + name: 'inGrid' + ParentChange { target: wrapper; parent: gridDelegate } + PropertyChanges { target: wrapper; x: 0; y: 0; width: gridDelegate.width; height: gridDelegate.height } + } + ] + transitions: [ + Transition { + SequentialAnimation { + ParentAction { target: wrapper } + NumberAnimation { targets: wrapper; properties: 'x,y,width,height'; duration: 300 } + } + } + ] + } +} +//![0] diff --git a/examples/declarative/package/view.qml b/examples/declarative/package/view.qml new file mode 100644 index 0000000..07bba0c --- /dev/null +++ b/examples/declarative/package/view.qml @@ -0,0 +1,35 @@ +import Qt 4.6 + +Item { + width: 400 + height: 200 + + ListModel { + id: myModel + ListElement { display: "One" } + ListElement { display: "Two" } + ListElement { display: "Three" } + ListElement { display: "Four" } + ListElement { display: "Five" } + ListElement { display: "Six" } + ListElement { display: "Seven" } + ListElement { display: "Eight" } + } + //![0] + VisualDataModel { + id: visualModel + delegate: Delegate {} + model: myModel + } + + ListView { + width: 200; height:200 + model: visualModel.parts.list + } + GridView { + x: 200; width: 200; height:200 + cellHeight: 50 + model: visualModel.parts.grid + } + //![0] +} -- cgit v0.12 From c58554711e678421cd70f103ad78506b3e1f8d85 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 25 Feb 2010 16:12:02 +1000 Subject: Fix documentation following MouseRegion -> MouseArea change --- .../graphicsitems/qdeclarativemousearea.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativemousearea.cpp b/src/declarative/graphicsitems/qdeclarativemousearea.cpp index ab6be1c..ec7aa62 100644 --- a/src/declarative/graphicsitems/qdeclarativemousearea.cpp +++ b/src/declarative/graphicsitems/qdeclarativemousearea.cpp @@ -143,7 +143,7 @@ QDeclarativeMouseAreaPrivate::~QDeclarativeMouseAreaPrivate() /*! - \qmlclass MouseRegion QDeclarativeMouseRegion + \qmlclass MouseArea QDeclarativeMouseArea \since 4.7 \brief The MouseArea item enables simple mouse handling. \inherits Item @@ -172,7 +172,7 @@ QDeclarativeMouseAreaPrivate::~QDeclarativeMouseAreaPrivate() /*! \qmlsignal MouseArea::onEntered() - This handler is called when the mouse enters the mouse region. + This handler is called when the mouse enters the mouse area. By default the onEntered handler is only called while a button is pressed. Setting hoverEnabled to true enables handling of @@ -184,7 +184,7 @@ QDeclarativeMouseAreaPrivate::~QDeclarativeMouseAreaPrivate() /*! \qmlsignal MouseArea::onExited() - This handler is called when the mouse exists the mouse region. + This handler is called when the mouse exists the mouse area. By default the onExited handler is only called while a button is pressed. Setting hoverEnabled to true enables handling of @@ -295,12 +295,12 @@ QDeclarativeMouseArea::~QDeclarativeMouseArea() If the hoverEnabled property is false then these properties will only be valid while a button is pressed, and will remain valid as long as the button is held - even if the mouse is moved outside the region. + even if the mouse is moved outside the area. If hoverEnabled is true then these properties will be valid: \list \i when no button is pressed, but the mouse is within the MouseArea (containsMouse is true). - \i if a button is pressed and held, even if it has since moved out of the region. + \i if a button is pressed and held, even if it has since moved out of the area. \endlist The coordinates are relative to the MouseArea. @@ -567,9 +567,9 @@ void QDeclarativeMouseArea::timerEvent(QTimerEvent *event) /*! \qmlproperty bool MouseArea::containsMouse - This property holds whether the mouse is currently inside the mouse region. + This property holds whether the mouse is currently inside the mouse area. - \warning This property is not updated if the region moves under the mouse: \e containsMouse will not change. + \warning This property is not updated if the area moves under the mouse: \e containsMouse will not change. In addition, if hoverEnabled is false, containsMouse will only be valid when the mouse is pressed. */ bool QDeclarativeMouseArea::hovered() const @@ -580,7 +580,7 @@ bool QDeclarativeMouseArea::hovered() const /*! \qmlproperty bool MouseArea::pressed - This property holds whether the mouse region is currently pressed. + This property holds whether the mouse area is currently pressed. */ bool QDeclarativeMouseArea::pressed() const { @@ -600,7 +600,7 @@ void QDeclarativeMouseArea::setHovered(bool h) /*! \qmlproperty Qt::MouseButtons MouseArea::acceptedButtons - This property holds the mouse buttons that the mouse region reacts to. + This property holds the mouse buttons that the mouse area reacts to. The available buttons are: \list -- cgit v0.12