Make selectAll() do nothing if the mode is NoSelection.

Task-number: QTBUG-26687

Change-Id: Iaa0197efe64c61505e22e4a63a1f5c012af0bc78
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
This commit is contained in:
Stephen Kelly 2012-08-08 15:50:31 +02:00 committed by Qt by Nokia
parent 43a36a682a
commit d19589b90a
2 changed files with 7 additions and 1 deletions

View File

@ -2599,7 +2599,7 @@ void QTreeView::selectAll()
return; return;
SelectionMode mode = d->selectionMode; SelectionMode mode = d->selectionMode;
d->executePostedLayout(); //make sure we lay out the items d->executePostedLayout(); //make sure we lay out the items
if (mode != SingleSelection && !d->viewItems.isEmpty()) { if (mode != SingleSelection && mode != NoSelection && !d->viewItems.isEmpty()) {
const QModelIndex &idx = d->viewItems.last().index; const QModelIndex &idx = d->viewItems.last().index;
QModelIndex lastItemIndex = idx.sibling(idx.row(), d->model->columnCount(idx.parent()) - 1); QModelIndex lastItemIndex = idx.sibling(idx.row(), d->model->columnCount(idx.parent()) - 1);
d->select(d->viewItems.first().index, lastItemIndex, d->select(d->viewItems.first().index, lastItemIndex,

View File

@ -2365,6 +2365,12 @@ void tst_QTreeView::selectAll()
int selectedCount = view.selectedIndexes().count(); int selectedCount = view.selectedIndexes().count();
view.selectAll(); view.selectAll();
QCOMPARE(view.selectedIndexes().count(), selectedCount); QCOMPARE(view.selectedIndexes().count(), selectedCount);
PublicView view3;
view3.setModel(&model);
view3.setSelectionMode(QAbstractItemView::NoSelection);
view3.selectAll();
QCOMPARE(view3.selectedIndexes().count(), 0);
} }
void tst_QTreeView::extendedSelection_data() void tst_QTreeView::extendedSelection_data()