Views with no delegate crash when items are inserted.
authorMartin Jones <martin.jones@nokia.com>
Tue, 2 Aug 2011 03:58:49 +0000 (13:58 +1000)
committerQt by Nokia <qt-info@nokia.com>
Tue, 2 Aug 2011 06:50:21 +0000 (08:50 +0200)
Check that we have a valid VisualModel before reacting to model
changes.

Change-Id: I6107e8fb8942a3625e501ab549a337f1affd4fbd
Fixes: QTBUG-20640
Reviewed-on: http://codereview.qt.nokia.com/2481
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Bea Lam <bea.lam@nokia.com>
src/declarative/items/qsggridview.cpp
src/declarative/items/qsglistview.cpp
src/qtquick1/graphicsitems/qdeclarativegridview.cpp
src/qtquick1/graphicsitems/qdeclarativelistview.cpp

index ec22761..ac86ebb 100644 (file)
@@ -1280,7 +1280,7 @@ void QSGGridView::moveCurrentIndexRight()
 void QSGGridView::itemsInserted(int modelIndex, int count)
 {
     Q_D(QSGGridView);
-    if (!isComponentComplete())
+    if (!isComponentComplete() || !d->model || !d->model->isValid())
         return;
 
     int index = d->visibleItems.count() ? d->mapFromModel(modelIndex) : 0;
@@ -1411,7 +1411,7 @@ void QSGGridView::itemsInserted(int modelIndex, int count)
 void QSGGridView::itemsRemoved(int modelIndex, int count)
 {
     Q_D(QSGGridView);
-    if (!isComponentComplete())
+    if (!isComponentComplete() || !d->model || !d->model->isValid())
         return;
 
     d->itemCount -= count;
@@ -1493,7 +1493,7 @@ void QSGGridView::itemsRemoved(int modelIndex, int count)
 void QSGGridView::itemsMoved(int from, int to, int count)
 {
     Q_D(QSGGridView);
-    if (!isComponentComplete())
+    if (!isComponentComplete() || !d->isValid())
         return;
     d->updateUnrequestedIndexes();
 
index 15042be..d9792d1 100644 (file)
@@ -1578,7 +1578,7 @@ void QSGListView::updateSections()
 void QSGListView::itemsInserted(int modelIndex, int count)
 {
     Q_D(QSGListView);
-    if (!isComponentComplete())
+    if (!isComponentComplete() || !d->model || !d->model->isValid())
         return;
     d->updateUnrequestedIndexes();
     d->moveReason = QSGListViewPrivate::Other;
@@ -1718,7 +1718,7 @@ void QSGListView::itemsInserted(int modelIndex, int count)
 void QSGListView::itemsRemoved(int modelIndex, int count)
 {
     Q_D(QSGListView);
-    if (!isComponentComplete())
+    if (!isComponentComplete() || !d->model || !d->model->isValid())
         return;
     d->moveReason = QSGListViewPrivate::Other;
     d->updateUnrequestedIndexes();
@@ -1815,7 +1815,7 @@ void QSGListView::itemsRemoved(int modelIndex, int count)
 void QSGListView::itemsMoved(int from, int to, int count)
 {
     Q_D(QSGListView);
-    if (!isComponentComplete())
+    if (!isComponentComplete() || !d->isValid())
         return;
     d->updateUnrequestedIndexes();
 
index 63b907b..3375aff 100644 (file)
@@ -2748,7 +2748,7 @@ void QDeclarative1GridView::trackedPositionChanged()
 void QDeclarative1GridView::itemsInserted(int modelIndex, int count)
 {
     Q_D(QDeclarative1GridView);
-    if (!isComponentComplete())
+    if (!isComponentComplete() || !d->model || !d->model->isValid())
         return;
 
     int index = d->visibleItems.count() ? d->mapFromModel(modelIndex) : 0;
@@ -2879,7 +2879,7 @@ void QDeclarative1GridView::itemsInserted(int modelIndex, int count)
 void QDeclarative1GridView::itemsRemoved(int modelIndex, int count)
 {
     Q_D(QDeclarative1GridView);
-    if (!isComponentComplete())
+    if (!isComponentComplete() || !d->model || !d->model->isValid())
         return;
 
     d->itemCount -= count;
@@ -2979,7 +2979,7 @@ void QDeclarative1GridView::destroyRemoved()
 void QDeclarative1GridView::itemsMoved(int from, int to, int count)
 {
     Q_D(QDeclarative1GridView);
-    if (!isComponentComplete())
+    if (!isComponentComplete() || !d->isValid())
         return;
     QHash<int,FxGridItem1*> moved;
 
index c58543c..0474591 100644 (file)
@@ -3195,7 +3195,7 @@ void QDeclarative1ListView::trackedPositionChanged()
 void QDeclarative1ListView::itemsInserted(int modelIndex, int count)
 {
     Q_D(QDeclarative1ListView);
-    if (!isComponentComplete())
+    if (!isComponentComplete() || !d->model || !d->model->isValid())
         return;
     d->updateUnrequestedIndexes();
     d->moveReason = QDeclarative1ListViewPrivate::Other;
@@ -3338,7 +3338,7 @@ void QDeclarative1ListView::itemsInserted(int modelIndex, int count)
 void QDeclarative1ListView::itemsRemoved(int modelIndex, int count)
 {
     Q_D(QDeclarative1ListView);
-    if (!isComponentComplete())
+    if (!isComponentComplete() || !d->model || !d->model->isValid())
         return;
     d->moveReason = QDeclarative1ListViewPrivate::Other;
     d->updateUnrequestedIndexes();
@@ -3453,7 +3453,7 @@ void QDeclarative1ListView::destroyRemoved()
 void QDeclarative1ListView::itemsMoved(int from, int to, int count)
 {
     Q_D(QDeclarative1ListView);
-    if (!isComponentComplete())
+    if (!isComponentComplete() || !d->isValid())
         return;
     d->updateUnrequestedIndexes();