summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThierry Bastian <thierry.bastian@nokia.com>2009-08-25 12:42:43 +0200
committerThierry Bastian <thierry.bastian@nokia.com>2009-08-25 12:44:24 +0200
commit8a7700ffb5e4959e788861e4862ebc1a7a3ad3b1 (patch)
tree0bd86802c74a38c10dd51d2dde4d8b880c434c07
parent2aeeda9b82440dbcb3564c185003288b83f49683 (diff)
ItemViews: selection not well kept when new rows appear
Task-number: 260134 Reviewed-by: ogoffart
-rw-r--r--src/gui/itemviews/qitemselectionmodel.cpp11
-rw-r--r--tests/auto/qitemselectionmodel/tst_qitemselectionmodel.cpp33
2 files changed, 39 insertions, 5 deletions
diff --git a/src/gui/itemviews/qitemselectionmodel.cpp b/src/gui/itemviews/qitemselectionmodel.cpp
index 841446001..8eb9e21fe 100644
--- a/src/gui/itemviews/qitemselectionmodel.cpp
+++ b/src/gui/itemviews/qitemselectionmodel.cpp
@@ -734,14 +734,15 @@ void QItemSelectionModelPrivate::_q_layoutAboutToBeChanged()
if (ranges.isEmpty() && currentSelection.count() == 1) {
QItemSelectionRange range = currentSelection.first();
QModelIndex parent = range.parent();
- if (range.top() == 0
+ tableRowCount = model->rowCount(parent);
+ tableColCount = model->columnCount(parent);
+ if (tableRowCount * tableColCount > 100
+ && range.top() == 0
&& range.left() == 0
- && range.bottom() == model->rowCount(parent) - 1
- && range.right() == model->columnCount(parent) - 1) {
+ && range.bottom() == tableRowCount - 1
+ && range.right() == tableColCount - 1) {
tableSelected = true;
tableParent = parent;
- tableColCount = model->columnCount(parent);
- tableRowCount = model->rowCount(parent);
return;
}
}
diff --git a/tests/auto/qitemselectionmodel/tst_qitemselectionmodel.cpp b/tests/auto/qitemselectionmodel/tst_qitemselectionmodel.cpp
index 5806ca916..595c757ef 100644
--- a/tests/auto/qitemselectionmodel/tst_qitemselectionmodel.cpp
+++ b/tests/auto/qitemselectionmodel/tst_qitemselectionmodel.cpp
@@ -91,6 +91,7 @@ private slots:
void task119433_isRowSelected();
void task252069_rowIntersectsSelection();
void task232634_childrenDeselectionSignal();
+ void task260134_layoutChangedWithAllSelected();
private:
QAbstractItemModel *model;
@@ -2241,5 +2242,37 @@ void tst_QItemSelectionModel::task232634_childrenDeselectionSignal()
QVERIFY(selectionModel.selection().contains(sel2));
}
+void tst_QItemSelectionModel::task260134_layoutChangedWithAllSelected()
+{
+ QStringListModel model( QStringList() << "foo" << "bar" << "foo2");
+ QSortFilterProxyModel proxy;
+ proxy.setSourceModel(&model);
+ QItemSelectionModel selection(&proxy);
+
+
+ QCOMPARE(model.rowCount(), 3);
+ QCOMPARE(proxy.rowCount(), 3);
+ proxy.setFilterRegExp( QRegExp("f"));
+ QCOMPARE(proxy.rowCount(), 2);
+
+ QList<QPersistentModelIndex> indexList;
+ indexList << proxy.index(0,0) << proxy.index(1,0);
+ selection.select( QItemSelection(indexList.first(), indexList.last()), QItemSelectionModel::Select);
+
+ //let's check the selection hasn't changed
+ QCOMPARE(selection.selectedIndexes().count(), indexList.count());
+ foreach(QPersistentModelIndex index, indexList)
+ QVERIFY(selection.isSelected(index));
+
+ proxy.setFilterRegExp(QRegExp());
+ QCOMPARE(proxy.rowCount(), 3);
+
+ //let's check the selection hasn't changed
+ QCOMPARE(selection.selectedIndexes().count(), indexList.count());
+ foreach(QPersistentModelIndex index, indexList)
+ QVERIFY(selection.isSelected(index));
+}
+
+
QTEST_MAIN(tst_QItemSelectionModel)
#include "tst_qitemselectionmodel.moc"