From 4b7be050581bfef8a064ba867489b7dd7ee7ae47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Mill=C3=A1n=20Soto?= Date: Mon, 24 Sep 2012 14:16:16 +0200 Subject: Change behaviour of selectRow, selectColumn, unselectRow, unselectColumn According to the comments of selectRow and selectColumn, the expected behaviour of this method was to select a row or a column and unselect any cell that were previously selected. However the actual behavior was to select only one cell and not deselect any cell. Moreover, according to the specification there's no simple way of selecting multiple rows or columns as when one of the methods is called for selecting one row or column the others should be unselected. The specification was changed not to require the rest of the cells to be deselected, although they might be deselected if the selectionMode requires that in order for the new row/column to be selected. The implementation of these methods was changed in QAccessibleTable and QAccessibleTree to select the whole row/column and take into acount selectionMode and selectionBehavior. tst_qaccessibility.cpp was modified to test the new behaviour of the methods. Change-Id: I29635d014792169302435e81704e02c16f951238 Reviewed-by: Frederik Gladhorn --- src/gui/accessible/qaccessible2.h | 4 +- src/plugins/accessible/widgets/itemviews.cpp | 125 ++++++++++++++++++++++++--- 2 files changed, 117 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/gui/accessible/qaccessible2.h b/src/gui/accessible/qaccessible2.h index e93324b4f8..6006e7846c 100644 --- a/src/gui/accessible/qaccessible2.h +++ b/src/gui/accessible/qaccessible2.h @@ -185,9 +185,9 @@ public: virtual bool isColumnSelected(int column) const = 0; // Returns a boolean value indicating whether the specified row is completely selected. virtual bool isRowSelected(int row) const = 0; - // Selects a row and unselects all previously selected rows. + // Selects a row and it might unselect all previously selected rows. virtual bool selectRow(int row) = 0; - // Selects a column and unselects all previously selected columns. + // Selects a column it might unselect all previously selected columns. virtual bool selectColumn(int column) = 0; // Unselects one row, leaving other selected rows selected (if any). virtual bool unselectRow(int row) = 0; diff --git a/src/plugins/accessible/widgets/itemviews.cpp b/src/plugins/accessible/widgets/itemviews.cpp index 301838997f..7130979935 100644 --- a/src/plugins/accessible/widgets/itemviews.cpp +++ b/src/plugins/accessible/widgets/itemviews.cpp @@ -299,9 +299,28 @@ bool QAccessibleTable::selectRow(int row) if (!view()->model() || !view()->selectionModel()) return false; QModelIndex index = view()->model()->index(row, 0, view()->rootIndex()); - if (!index.isValid() || view()->selectionMode() & QAbstractItemView::NoSelection) + + if (!index.isValid() || view()->selectionBehavior() == QAbstractItemView::SelectColumns) + return false; + + switch (view()->selectionMode()) { + case QAbstractItemView::NoSelection: return false; - view()->selectionModel()->select(index, QItemSelectionModel::Select); + case QAbstractItemView::SingleSelection: + if (view()->selectionBehavior() != QAbstractItemView::SelectRows && columnCount() > 1 ) + return false; + view()->clearSelection(); + break; + case QAbstractItemView::ContiguousSelection: + if ((!row || !view()->selectionModel()->isRowSelected(row - 1, view()->rootIndex())) + && !view()->selectionModel()->isRowSelected(row + 1, view()->rootIndex())) + view()->clearSelection(); + break; + default: + break; + } + + view()->selectionModel()->select(index, QItemSelectionModel::Select | QItemSelectionModel::Rows); return true; } @@ -310,9 +329,26 @@ bool QAccessibleTable::selectColumn(int column) if (!view()->model() || !view()->selectionModel()) return false; QModelIndex index = view()->model()->index(0, column, view()->rootIndex()); - if (!index.isValid() || view()->selectionMode() & QAbstractItemView::NoSelection) + + if (!index.isValid() || view()->selectionBehavior() == QAbstractItemView::SelectRows) + return false; + + switch (view()->selectionMode()) { + case QAbstractItemView::NoSelection: return false; - view()->selectionModel()->select(index, QItemSelectionModel::Select); + case QAbstractItemView::SingleSelection: + if (view()->selectionBehavior() != QAbstractItemView::SelectColumns && rowCount() > 1) + return false; + case QAbstractItemView::ContiguousSelection: + if ((!column || !view()->selectionModel()->isColumnSelected(column - 1, view()->rootIndex())) + && !view()->selectionModel()->isColumnSelected(column + 1, view()->rootIndex())) + view()->clearSelection(); + break; + default: + break; + } + + view()->selectionModel()->select(index, QItemSelectionModel::Select | QItemSelectionModel::Columns); return true; } @@ -320,10 +356,35 @@ bool QAccessibleTable::unselectRow(int row) { if (!view()->model() || !view()->selectionModel()) return false; + QModelIndex index = view()->model()->index(row, 0, view()->rootIndex()); - if (!index.isValid() || view()->selectionMode() & QAbstractItemView::NoSelection) + if (!index.isValid()) return false; - view()->selectionModel()->select(index, QItemSelectionModel::Deselect); + + QItemSelection selection(index, index); + + switch (view()->selectionMode()) { + case QAbstractItemView::SingleSelection: + //In SingleSelection and ContiguousSelection once an item + //is selected, there's no way for the user to unselect all items + if (selectedRowCount() == 1) + return false; + break; + case QAbstractItemView::ContiguousSelection: + if (selectedRowCount() == 1) + return false; + + if ((!row || view()->selectionModel()->isRowSelected(row - 1, view()->rootIndex())) + && view()->selectionModel()->isRowSelected(row + 1, view()->rootIndex())) { + //If there are rows selected both up the current row and down the current rown, + //the ones which are down the current row will be deselected + selection = QItemSelection(index, view()->model()->index(rowCount() - 1, 0, view()->rootIndex())); + } + default: + break; + } + + view()->selectionModel()->select(selection, QItemSelectionModel::Deselect | QItemSelectionModel::Rows); return true; } @@ -331,10 +392,35 @@ bool QAccessibleTable::unselectColumn(int column) { if (!view()->model() || !view()->selectionModel()) return false; + QModelIndex index = view()->model()->index(0, column, view()->rootIndex()); - if (!index.isValid() || view()->selectionMode() & QAbstractItemView::NoSelection) + if (!index.isValid()) return false; - view()->selectionModel()->select(index, QItemSelectionModel::Columns & QItemSelectionModel::Deselect); + + QItemSelection selection(index, index); + + switch (view()->selectionMode()) { + case QAbstractItemView::SingleSelection: + //In SingleSelection and ContiguousSelection once an item + //is selected, there's no way for the user to unselect all items + if (selectedColumnCount() == 1) + return false; + break; + case QAbstractItemView::ContiguousSelection: + if (selectedColumnCount() == 1) + return false; + + if ((!column || view()->selectionModel()->isColumnSelected(column - 1, view()->rootIndex())) + && view()->selectionModel()->isColumnSelected(column + 1, view()->rootIndex())) { + //If there are columns selected both at the left of the current row and at the right + //of the current rown, the ones which are at the right will be deselected + selection = QItemSelection(index, view()->model()->index(0, columnCount() - 1, view()->rootIndex())); + } + default: + break; + } + + view()->selectionModel()->select(selection, QItemSelectionModel::Deselect | QItemSelectionModel::Columns); return true; } @@ -576,9 +662,28 @@ bool QAccessibleTree::selectRow(int row) if (!view()->selectionModel()) return false; QModelIndex index = indexFromLogical(row); - if (!index.isValid() || view()->selectionMode() & QAbstractItemView::NoSelection) + + if (!index.isValid() || view()->selectionBehavior() == QAbstractItemView::SelectColumns) return false; - view()->selectionModel()->select(index, QItemSelectionModel::Select); + + switch (view()->selectionMode()) { + case QAbstractItemView::NoSelection: + return false; + case QAbstractItemView::SingleSelection: + if ((view()->selectionBehavior() != QAbstractItemView::SelectRows) && (columnCount() > 1)) + return false; + view()->clearSelection(); + break; + case QAbstractItemView::ContiguousSelection: + if ((!row || !view()->selectionModel()->isRowSelected(row - 1, view()->rootIndex())) + && !view()->selectionModel()->isRowSelected(row + 1, view()->rootIndex())) + view()->clearSelection(); + break; + default: + break; + } + + view()->selectionModel()->select(index, QItemSelectionModel::Select | QItemSelectionModel::Rows); return true; } -- cgit v1.2.3