From 8b42e57fe2946f2cd17f538d0dec2ba6edc06a11 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Mon, 11 Jan 2010 10:44:55 +0100 Subject: QTreeView::selectAll() wouldn't work when first column hidden QTreeView::selectAll() called QTreeView::select() on the first column, first and last rows, and rows selection flags. As the first row was hidden, this range spanned to void. We now pass the upper-left and lower-right indices to select(). Auto-test included. Reviewed-by: Olivier Task-number: QTBUG-6450 --- src/gui/itemviews/qtreeview.cpp | 7 +++++-- tests/auto/qtreeview/tst_qtreeview.cpp | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/gui/itemviews/qtreeview.cpp b/src/gui/itemviews/qtreeview.cpp index bf88a75..f25d648 100644 --- a/src/gui/itemviews/qtreeview.cpp +++ b/src/gui/itemviews/qtreeview.cpp @@ -2644,10 +2644,13 @@ void QTreeView::selectAll() return; SelectionMode mode = d->selectionMode; d->executePostedLayout(); //make sure we lay out the items - if (mode != SingleSelection && !d->viewItems.isEmpty()) - d->select(d->viewItems.first().index, d->viewItems.last().index, + if (mode != SingleSelection && !d->viewItems.isEmpty()) { + const QModelIndex &idx = d->viewItems.last().index; + QModelIndex lastItemIndex = idx.sibling(idx.row(), d->model->columnCount(idx.parent()) - 1); + d->select(d->viewItems.first().index, lastItemIndex, QItemSelectionModel::ClearAndSelect |QItemSelectionModel::Rows); + } } /*! diff --git a/tests/auto/qtreeview/tst_qtreeview.cpp b/tests/auto/qtreeview/tst_qtreeview.cpp index 4fc6dd3..06bc93e 100644 --- a/tests/auto/qtreeview/tst_qtreeview.cpp +++ b/tests/auto/qtreeview/tst_qtreeview.cpp @@ -236,6 +236,7 @@ private slots: void task248022_changeSelection(); void task245654_changeModelAndExpandAll(); void doubleClickedWithSpans(); + void taskQTBUG_6450_selectAllWith1stColumnHidden(); }; class QtTestModel: public QAbstractItemModel @@ -3678,5 +3679,26 @@ void tst_QTreeView::doubleClickedWithSpans() QTRY_COMPARE(spy.count(), 2); } +void tst_QTreeView::taskQTBUG_6450_selectAllWith1stColumnHidden() +{ + QTreeWidget tree; + tree.setSelectionMode(QAbstractItemView::MultiSelection); + tree.setColumnCount(2); + QList items; + const int nrRows = 10; + for (int i = 0; i < nrRows; ++i) { + items.append(new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString("item: %1").arg(i)))); + items.last()->setText(1, QString("is an item")); + } + tree.insertTopLevelItems(0, items); + + tree.hideColumn(0); + tree.selectAll(); + + QVERIFY(tree.selectionModel()->hasSelection()); + for (int i = 0; i < nrRows; ++i) + QVERIFY(tree.selectionModel()->isRowSelected(i, QModelIndex())); +} + QTEST_MAIN(tst_QTreeView) #include "tst_qtreeview.moc" -- cgit v0.12