diff options
author | José Millán Soto <fid@gpul.org> | 2012-09-24 11:42:33 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-01-11 21:24:23 +0100 |
commit | 08bc730b4199bad839543fe17a5464cf8d547ca8 (patch) | |
tree | 6e560cb66c8c568bbc97a91318d8c04c5187fe3d /src/plugins/accessible | |
parent | f156e578d7f4b05f44a6e84b2173f1e69b856442 (diff) |
Implement QAccessibleActionInterface in QAccessibleTableCell
Implemented QAccessibleActionInterface in QAccessibleTableCell to allow
selecting and unselecting table cells, as there was no way of selecting
or deselecting a simple cell using accessible tools.
tst_qaccessibility.cpp was modified to test the new methods.
Change-Id: I7bdfe0b363a9813d4a7c62e96b6c924b163f2121
Reviewed-by: Jan Arve Sæther <jan-arve.saether@digia.com>
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@digia.com>
Diffstat (limited to 'src/plugins/accessible')
-rw-r--r-- | src/plugins/accessible/widgets/itemviews.cpp | 85 | ||||
-rw-r--r-- | src/plugins/accessible/widgets/itemviews.h | 10 |
2 files changed, 94 insertions, 1 deletions
diff --git a/src/plugins/accessible/widgets/itemviews.cpp b/src/plugins/accessible/widgets/itemviews.cpp index 7130979935..92ba03753a 100644 --- a/src/plugins/accessible/widgets/itemviews.cpp +++ b/src/plugins/accessible/widgets/itemviews.cpp @@ -700,6 +700,8 @@ void *QAccessibleTableCell::interface_cast(QAccessible::InterfaceType t) { if (t == QAccessible::TableCellInterface) return static_cast<QAccessibleTableCellInterface*>(this); + if (t == QAccessible::ActionInterface) + return static_cast<QAccessibleActionInterface*>(this); return 0; } @@ -773,6 +775,89 @@ bool QAccessibleTableCell::isSelected() const return view->selectionModel()->isSelected(m_index); } +QStringList QAccessibleTableCell::actionNames() const +{ + QStringList names; + names << toggleAction(); + return names; +} + +void QAccessibleTableCell::doAction(const QString& actionName) +{ + if (actionName == toggleAction()) { + if (isSelected()) + unselectCell(); + else + selectCell(); + } +} + +QStringList QAccessibleTableCell::keyBindingsForAction(const QString& actionName) const +{ + return QStringList(); +} + + +void QAccessibleTableCell::selectCell() +{ + QAbstractItemView::SelectionMode selectionMode = view->selectionMode(); + if (!m_index.isValid() || (selectionMode == QAbstractItemView::NoSelection)) + return; + + QSharedPointer<QAccessibleTableInterface> cellTable(table()->tableInterface()); + + switch (view->selectionBehavior()) { + case QAbstractItemView::SelectItems: + break; + case QAbstractItemView::SelectColumns: + if (cellTable.data()) + cellTable->selectColumn(m_index.column()); + return; + case QAbstractItemView::SelectRows: + if (cellTable.data()) + cellTable->selectRow(m_index.row()); + return; + } + + if (selectionMode == QAbstractItemView::SingleSelection) { + view->clearSelection(); + } + + view->selectionModel()->select(m_index, QItemSelectionModel::Select); +} + +void QAccessibleTableCell::unselectCell() +{ + + QAbstractItemView::SelectionMode selectionMode = view->selectionMode(); + if (!m_index.isValid() || (selectionMode & QAbstractItemView::NoSelection)) + return; + + QSharedPointer<QAccessibleTableInterface> cellTable(table()->tableInterface()); + + switch (view->selectionBehavior()) { + case QAbstractItemView::SelectItems: + break; + case QAbstractItemView::SelectColumns: + if (cellTable.data()) + cellTable->unselectColumn(m_index.column()); + return; + case QAbstractItemView::SelectRows: + if (cellTable.data()) + cellTable->unselectRow(m_index.row()); + return; + } + + //If the mode is not MultiSelection or ExtendedSelection and only + //one cell is selected it cannot be unselected by the user + if ((selectionMode != QAbstractItemView::MultiSelection) + && (selectionMode != QAbstractItemView::ExtendedSelection) + && (view->selectionModel()->selectedIndexes().count() <= 1)) + return; + + view->selectionModel()->select(m_index, QItemSelectionModel::Deselect); +} + void QAccessibleTableCell::rowColumnExtents(int *row, int *column, int *rowExtents, int *columnExtents, bool *selected) const { *row = m_index.row(); diff --git a/src/plugins/accessible/widgets/itemviews.h b/src/plugins/accessible/widgets/itemviews.h index 5ae13a8035..99c995dba8 100644 --- a/src/plugins/accessible/widgets/itemviews.h +++ b/src/plugins/accessible/widgets/itemviews.h @@ -159,7 +159,7 @@ private: QModelIndex indexFromLogical(int row, int column = 0) const; }; -class QAccessibleTableCell: public QAccessibleInterface, public QAccessibleTableCellInterface +class QAccessibleTableCell: public QAccessibleInterface, public QAccessibleTableCellInterface, public QAccessibleActionInterface { public: QAccessibleTableCell(QAbstractItemView *view, const QModelIndex &m_index, QAccessible::Role role); @@ -192,6 +192,11 @@ public: virtual void rowColumnExtents(int *row, int *column, int *rowExtents, int *columnExtents, bool *selected) const; virtual QAccessibleInterface* table() const; + //action interface + virtual QStringList actionNames() const; + virtual void doAction(const QString &actionName); + virtual QStringList keyBindingsForAction(const QString &actionName) const; + private: QHeaderView *verticalHeader() const; QHeaderView *horizontalHeader() const; @@ -199,6 +204,9 @@ private: QModelIndex m_index; QAccessible::Role m_role; + void selectCell(); + void unselectCell(); + friend class QAccessibleTable; friend class QAccessibleTree; }; |