summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2010-08-24 00:25:13 (GMT)
committerMichael Brasser <michael.brasser@nokia.com>2010-08-24 00:27:34 (GMT)
commit35db70bf1c046f880861bbf4f48b8741ced405c4 (patch)
treebe12bd794d3d9c6265bd17e123ab27766b295d2c
parent0d2e88f417275a85b4e22a274fa04bc80742382e (diff)
downloadQt-35db70bf1c046f880861bbf4f48b8741ced405c4.zip
Qt-35db70bf1c046f880861bbf4f48b8741ced405c4.tar.gz
Qt-35db70bf1c046f880861bbf4f48b8741ced405c4.tar.bz2
Fix PathView when setting an empty model that is later filled.
Task-number: QTBUG-13017 Reviewed-by: Martin Jones
-rw-r--r--src/declarative/graphicsitems/qdeclarativepathview.cpp3
-rw-r--r--tests/auto/declarative/qdeclarativepathview/data/emptymodel.qml5
-rw-r--r--tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp24
3 files changed, 30 insertions, 2 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativepathview.cpp b/src/declarative/graphicsitems/qdeclarativepathview.cpp
index 535fb90..4b97505 100644
--- a/src/declarative/graphicsitems/qdeclarativepathview.cpp
+++ b/src/declarative/graphicsitems/qdeclarativepathview.cpp
@@ -480,7 +480,8 @@ void QDeclarativePathView::setModel(const QVariant &model)
connect(d->model, SIGNAL(modelReset()), this, SLOT(modelReset()));
connect(d->model, SIGNAL(createdItem(int, QDeclarativeItem*)), this, SLOT(createdItem(int,QDeclarativeItem*)));
}
- d->offset = qmlMod(d->offset, qreal(d->model->count()));
+ if (d->model->count())
+ d->offset = qmlMod(d->offset, qreal(d->model->count()));
if (d->offset < 0)
d->offset = d->model->count() + d->offset;
d->regenerate();
diff --git a/tests/auto/declarative/qdeclarativepathview/data/emptymodel.qml b/tests/auto/declarative/qdeclarativepathview/data/emptymodel.qml
new file mode 100644
index 0000000..177c405
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativepathview/data/emptymodel.qml
@@ -0,0 +1,5 @@
+import Qt 4.7
+
+PathView {
+ model: emptyModel
+}
diff --git a/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp b/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp
index fdbb16d..e2ccfd2 100644
--- a/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp
+++ b/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp
@@ -84,7 +84,7 @@ private slots:
void modelChanges();
void pathUpdateOnStartChanged();
void package();
-
+ void emptyModel();
private:
QDeclarativeView *createView();
@@ -755,6 +755,28 @@ void tst_QDeclarativePathView::package()
delete canvas;
}
+//QTBUG-13017
+void tst_QDeclarativePathView::emptyModel()
+{
+ QDeclarativeView *canvas = createView();
+
+ QStringListModel model;
+
+ QDeclarativeContext *ctxt = canvas->rootContext();
+ ctxt->setContextProperty("emptyModel", &model);
+
+ canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/emptymodel.qml"));
+ qApp->processEvents();
+
+ QDeclarativePathView *pathview = qobject_cast<QDeclarativePathView*>(canvas->rootObject());
+ QVERIFY(pathview != 0);
+
+ QCOMPARE(pathview->offset(), qreal(0.0));
+
+ delete canvas;
+}
+
+
QDeclarativeView *tst_QDeclarativePathView::createView()
{
QDeclarativeView *canvas = new QDeclarativeView(0);