summaryrefslogtreecommitdiffstats
path: root/src/plugins/accessible/widgets/itemviews.cpp
diff options
context:
space:
mode:
authorJosé Millán Soto <fid@gpul.org>2012-09-24 14:16:16 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-12-18 14:06:23 +0100
commit4b7be050581bfef8a064ba867489b7dd7ee7ae47 (patch)
treee41a5568b13bb8b74010d17e345348dc018718bc /src/plugins/accessible/widgets/itemviews.cpp
parent533105cadfde6d0113ea25481b9723e2b06de8e4 (diff)
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 <frederik.gladhorn@digia.com>
Diffstat (limited to 'src/plugins/accessible/widgets/itemviews.cpp')
-rw-r--r--src/plugins/accessible/widgets/itemviews.cpp125
1 files changed, 115 insertions, 10 deletions
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;
}