Don't call componentComplete() on a VDM until its view is complete.
authorAndrew den Exter <andrew.den-exter@nokia.com>
Wed, 5 Oct 2011 06:03:12 +0000 (16:03 +1000)
committerQt by Nokia <qt-info@nokia.com>
Thu, 6 Oct 2011 08:44:27 +0000 (10:44 +0200)
This is more consistent with the behaviour you get when constructing
a VisualDataModel explicitly.

Change-Id: I33e32c7747ff3153449a88b9c7d894807e7e4b9a
Reviewed-on: http://codereview.qt-project.org/6014
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Martin Jones <martin.jones@nokia.com>
src/declarative/items/qsgitemview.cpp
src/declarative/items/qsgpathview.cpp
src/declarative/items/qsgrepeater.cpp
src/declarative/items/qsgvisualdatamodel.cpp
tests/auto/declarative/qsggridview/data/gridview4.qml
tests/auto/declarative/qsggridview/tst_qsggridview.cpp

index 7e77a0a..3224e32 100644 (file)
@@ -201,6 +201,8 @@ void QSGItemView::setModel(const QVariant &model)
         if (!d->ownModel) {
             d->model = new QSGVisualDataModel(qmlContext(this), this);
             d->ownModel = true;
+            if (isComponentComplete())
+                static_cast<QSGVisualDataModel *>(d->model.data())->componentComplete();
         } else {
             d->model = oldModel;
         }
@@ -1080,6 +1082,9 @@ void QSGItemView::updatePolish()
 void QSGItemView::componentComplete()
 {
     Q_D(QSGItemView);
+    if (d->model && d->ownModel)
+        static_cast<QSGVisualDataModel *>(d->model.data())->componentComplete();
+
     QSGFlickable::componentComplete();
 
     updateSections();
@@ -1102,6 +1107,8 @@ void QSGItemView::componentComplete()
         d->moveReason = QSGItemViewPrivate::Other;
         d->fixupPosition();
     }
+    if (d->model && d->model->count())
+        emit countChanged();
 }
 
 
index 6f54d46..faa045a 100644 (file)
@@ -510,6 +510,8 @@ void QSGPathView::setModel(const QVariant &model)
         if (!d->ownModel) {
             d->model = new QSGVisualDataModel(qmlContext(this));
             d->ownModel = true;
+            if (isComponentComplete())
+                static_cast<QSGVisualDataModel *>(d->model.data())->componentComplete();
         }
         if (QSGVisualDataModel *dataModel = qobject_cast<QSGVisualDataModel*>(d->model))
             dataModel->setModel(model);
@@ -1325,7 +1327,11 @@ void QSGPathView::updatePolish()
 void QSGPathView::componentComplete()
 {
     Q_D(QSGPathView);
+    if (d->model && d->ownModel)
+        static_cast<QSGVisualDataModel *>(d->model.data())->componentComplete();
+
     QSGItem::componentComplete();
+
     d->createHighlight();
     // It is possible that a refill has already happended to to Path
     // bindings being handled in the componentComplete().  If so
@@ -1335,6 +1341,9 @@ void QSGPathView::componentComplete()
         d->regenerate();
     }
     d->updateHighlight();
+
+    if (d->modelCount)
+        emit countChanged();
 }
 
 void QSGPathView::refill()
index 0037ea1..10adb75 100644 (file)
@@ -206,6 +206,8 @@ void QSGRepeater::setModel(const QVariant &model)
         if (!d->ownModel) {
             d->model = new QSGVisualDataModel(qmlContext(this));
             d->ownModel = true;
+            if (isComponentComplete())
+                static_cast<QSGVisualDataModel *>(d->model)->componentComplete();
         }
         if (QSGVisualDataModel *dataModel = qobject_cast<QSGVisualDataModel*>(d->model))
             dataModel->setModel(model);
@@ -314,8 +316,13 @@ QSGItem *QSGRepeater::itemAt(int index) const
 
 void QSGRepeater::componentComplete()
 {
+    Q_D(QSGRepeater);
+    if (d->model && d->ownModel)
+        static_cast<QSGVisualDataModel *>(d->model)->componentComplete();
     QSGItem::componentComplete();
     regenerate();
+    if (d->model && d->model->count())
+        emit countChanged();
 }
 
 void QSGRepeater::itemChange(ItemChange change, const ItemChangeData &value)
index 72cebd7..7793230 100644 (file)
@@ -429,7 +429,6 @@ QSGVisualDataModel::QSGVisualDataModel(QDeclarativeContext *ctxt, QObject *paren
 {
     Q_D(QSGVisualDataModel);
     d->init();
-    componentComplete();
 }
 
 QSGVisualDataModel::~QSGVisualDataModel()
@@ -504,6 +503,9 @@ void QSGVisualDataModel::componentComplete()
             &inserts);
     d->itemsInserted(inserts);
     d->emitChanges();
+
+    if (d->m_adaptorModel->canFetchMore())
+        QCoreApplication::postEvent(this, new QEvent(QEvent::UpdateRequest));
 }
 
 /*!
@@ -530,7 +532,7 @@ void QSGVisualDataModel::setModel(const QVariant &model)
 {
     Q_D(QSGVisualDataModel);
     d->m_adaptorModel->setModel(model, d->m_context ? d->m_context->engine() : qmlEngine(this));
-    if (d->m_adaptorModel->canFetchMore())
+    if (d->m_complete && d->m_adaptorModel->canFetchMore())
         QCoreApplication::postEvent(this, new QEvent(QEvent::UpdateRequest));
 }
 
index 01b31da..eed3a2b 100644 (file)
@@ -1,7 +1,7 @@
 import QtQuick 2.0
 
 GridView {
-    width: 400
+    width: 405
     height: 200
     cellWidth: width/9
     cellHeight: height/2
index eab291f..15fee86 100644 (file)
@@ -2798,7 +2798,7 @@ void tst_QSGGridView::columnCount()
 
     QSGGridView *view = qobject_cast<QSGGridView*>(canvas.rootObject());
 
-    QCOMPARE(view->cellWidth(), qreal(400)/qreal(9));
+    QCOMPARE(view->cellWidth(), qreal(405)/qreal(9));
     QCOMPARE(view->cellHeight(), qreal(100));
 
     QList<QSGItem*> items = findItems<QSGItem>(view, "delegate");