a11y: Implement QAccessibleSelectionInterface for item views
In QAccessibleTable's model, cells (rather than rows or columns) are direct children of the table and therefore items handled in the selection, so forward/make use of the corresponding methods that handle cells. (In QAccessibleTable::select and QAccessibleTable::unselect, cast the child cell to QAccessibleTableCell*, as is already done in QAccessibleTable::indexOfChild and QAccessibleTree::indexOfChild.) This can be tested e.g. by calling the methods from the AT-SPI Selection interface using Accerciser and the "interview" example (qtbase/examples/widgets/itemviews/interview/interview). Change-Id: Ic650a8a01b56653cae4f2cb26e28aed4dc566a7e Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
This commit is contained in:
parent
5d95205bae
commit
092bbc9ad3
@ -366,6 +366,85 @@ bool QAccessibleTable::unselectColumn(int column)
|
||||
return true;
|
||||
}
|
||||
|
||||
int QAccessibleTable::selectedItemCount() const
|
||||
{
|
||||
return selectedCellCount();
|
||||
}
|
||||
|
||||
QList<QAccessibleInterface*> QAccessibleTable::selectedItems() const
|
||||
{
|
||||
return selectedCells();
|
||||
}
|
||||
|
||||
bool QAccessibleTable::isSelected(QAccessibleInterface *childCell) const
|
||||
{
|
||||
if (!childCell || childCell->parent() != this) {
|
||||
qWarning() << "QAccessibleTable::isSelected: Accessible interface must be a direct child of the table interface.";
|
||||
return false;
|
||||
}
|
||||
|
||||
const QAccessibleTableCellInterface *cell = childCell->tableCellInterface();
|
||||
if (cell)
|
||||
return cell->isSelected();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool QAccessibleTable::select(QAccessibleInterface *childCell)
|
||||
{
|
||||
if (!childCell || childCell->parent() != this) {
|
||||
qWarning() << "QAccessibleTable::select: Accessible interface must be a direct child of the table interface.";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!childCell->tableCellInterface()) {
|
||||
qWarning() << "QAccessibleTable::select: Accessible interface doesn't implement table cell interface.";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (childCell->role() == QAccessible::Cell || childCell->role() == QAccessible::ListItem || childCell->role() == QAccessible::TreeItem) {
|
||||
QAccessibleTableCell* cell = static_cast<QAccessibleTableCell*>(childCell);
|
||||
cell->selectCell();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool QAccessibleTable::unselect(QAccessibleInterface *childCell)
|
||||
{
|
||||
if (!childCell || childCell->parent() != this) {
|
||||
qWarning() << "QAccessibleTable::select: Accessible interface must be a direct child of the table interface.";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!childCell->tableCellInterface()) {
|
||||
qWarning() << "QAccessibleTable::unselect: Accessible interface doesn't implement table cell interface.";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (childCell->role() == QAccessible::Cell || childCell->role() == QAccessible::ListItem || childCell->role() == QAccessible::TreeItem) {
|
||||
QAccessibleTableCell* cell = static_cast<QAccessibleTableCell*>(childCell);
|
||||
cell->unselectCell();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool QAccessibleTable::selectAll()
|
||||
{
|
||||
view()->selectAll();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool QAccessibleTable::clear()
|
||||
{
|
||||
view()->selectionModel()->clearSelection();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
QAccessible::Role QAccessibleTable::role() const
|
||||
{
|
||||
return m_role;
|
||||
@ -533,6 +612,8 @@ QAccessibleInterface *QAccessibleTable::child(int logicalIndex) const
|
||||
|
||||
void *QAccessibleTable::interface_cast(QAccessible::InterfaceType t)
|
||||
{
|
||||
if (t == QAccessible::SelectionInterface)
|
||||
return static_cast<QAccessibleSelectionInterface*>(this);
|
||||
if (t == QAccessible::TableInterface)
|
||||
return static_cast<QAccessibleTableInterface*>(this);
|
||||
return nullptr;
|
||||
|
@ -31,7 +31,7 @@ QT_BEGIN_NAMESPACE
|
||||
class QAccessibleTableCell;
|
||||
class QAccessibleTableHeaderCell;
|
||||
|
||||
class QAccessibleTable :public QAccessibleTableInterface, public QAccessibleObject
|
||||
class QAccessibleTable :public QAccessibleTableInterface, public QAccessibleSelectionInterface, public QAccessibleObject
|
||||
{
|
||||
public:
|
||||
explicit QAccessibleTable(QWidget *w);
|
||||
@ -75,6 +75,15 @@ public:
|
||||
virtual bool unselectRow(int row) override;
|
||||
virtual bool unselectColumn(int column) override;
|
||||
|
||||
// QAccessibleSelectionInterface
|
||||
virtual int selectedItemCount() const override;
|
||||
virtual QList<QAccessibleInterface*> selectedItems() const override;
|
||||
virtual bool isSelected(QAccessibleInterface *childCell) const override;
|
||||
virtual bool select(QAccessibleInterface *childCell) override;
|
||||
virtual bool unselect(QAccessibleInterface *childCell) override;
|
||||
virtual bool selectAll() override;
|
||||
virtual bool clear() override;
|
||||
|
||||
QAbstractItemView *view() const;
|
||||
|
||||
void modelChange(QAccessibleTableModelChangeEvent *event) override;
|
||||
|
Loading…
Reference in New Issue
Block a user