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>
This commit is contained in:
José Millán Soto 2012-09-24 11:42:33 +02:00 committed by The Qt Project
parent f156e578d7
commit 08bc730b41
3 changed files with 129 additions and 1 deletions

View File

@ -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();

View File

@ -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;
};

View File

@ -2725,6 +2725,41 @@ void tst_QAccessibility::tableTest()
QVERIFY(table2->isColumnSelected(1));
QVERIFY(table2->isRowSelected(1));
QAIPtr cell4(table2->cellAt(2,2));
QVERIFY(cell1->actionInterface());
QVERIFY(cell1->tableCellInterface());
tableView->clearSelection();
tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
tableView->setSelectionMode(QAbstractItemView::SingleSelection);
QVERIFY(!cell1->tableCellInterface()->isSelected());
QVERIFY(cell1->actionInterface()->actionNames().contains(QAccessibleActionInterface::toggleAction()));
cell1->actionInterface()->doAction(QAccessibleActionInterface::toggleAction());
QVERIFY(cell2->tableCellInterface()->isSelected());
tableView->clearSelection();
tableView->setSelectionBehavior(QAbstractItemView::SelectColumns);
cell3->actionInterface()->doAction(QAccessibleActionInterface::toggleAction());
QVERIFY(cell4->tableCellInterface()->isSelected());
tableView->clearSelection();
tableView->setSelectionBehavior(QAbstractItemView::SelectItems);
tableView->setSelectionMode(QAbstractItemView::SingleSelection);
cell1->actionInterface()->doAction(QAccessibleActionInterface::toggleAction());
QVERIFY(cell1->tableCellInterface()->isSelected());
cell2->actionInterface()->doAction(QAccessibleActionInterface::toggleAction());
QVERIFY(!cell1->tableCellInterface()->isSelected());
tableView->clearSelection();
tableView->setSelectionMode(QAbstractItemView::MultiSelection);
cell1->actionInterface()->doAction(QAccessibleActionInterface::toggleAction());
cell2->actionInterface()->doAction(QAccessibleActionInterface::toggleAction());
QVERIFY(cell1->tableCellInterface()->isSelected());
QVERIFY(cell2->tableCellInterface()->isSelected());
cell2->actionInterface()->doAction(QAccessibleActionInterface::toggleAction());
QVERIFY(cell1->tableCellInterface()->isSelected());
QVERIFY(!cell2->tableCellInterface()->isSelected());
delete tableView;
QTestAccessibility::clearEvents();