Make cell a proper QAccessible2Interface.

Change-Id: I9b245037e8448f39ed2cb80d1ef5fb0714173518
Reviewed-by: Jan-Arve Sæther <jan-arve.saether@nokia.com>
This commit is contained in:
Frederik Gladhorn 2011-11-29 14:07:46 +01:00 committed by Qt by Nokia
parent 63fa222e24
commit dd02fcd711
5 changed files with 54 additions and 40 deletions

View File

@ -317,7 +317,8 @@ public:
TableInterface,
ActionInterface,
ImageInterface,
Table2Interface
Table2Interface,
Table2CellInterface
};
typedef QAccessibleInterface*(*InterfaceFactory)(const QString &key, QObject*);
@ -355,6 +356,7 @@ class QAccessibleTableInterface;
class QAccessibleActionInterface;
class QAccessibleImageInterface;
class QAccessibleTable2Interface;
class QAccessibleTable2CellInterface;
class Q_GUI_EXPORT QAccessibleInterface : public QAccessible
{
@ -414,6 +416,9 @@ public:
inline QAccessibleTable2Interface *table2Interface()
{ return reinterpret_cast<QAccessibleTable2Interface *>(interface_cast(QAccessible::Table2Interface)); }
inline QAccessibleTable2CellInterface *table2CellInterface()
{ return reinterpret_cast<QAccessibleTable2CellInterface *>(interface_cast(QAccessible::Table2CellInterface)); }
// FIXME
virtual QVariant virtual_hook(const QVariant &data);
virtual void *interface_cast(QAccessible::InterfaceType)

View File

@ -163,8 +163,6 @@ public:
class Q_GUI_EXPORT QAccessibleTableInterface
{
public:
virtual QAccessibleInterface *accessibleAt(int row, int column) = 0;
virtual QAccessibleInterface *caption() = 0;
virtual int childIndex(int rowIndex, int columnIndex) = 0;
@ -194,7 +192,7 @@ public:
int *columnSpan, bool *isSelected) = 0;
};
class Q_GUI_EXPORT QAccessibleTable2CellInterface: public QAccessibleInterface
class Q_GUI_EXPORT QAccessibleTable2CellInterface
{
public:
// Returns the number of columns occupied by this cell accessible.
@ -217,7 +215,7 @@ public:
// Gets the row and column indexes and extents of this cell accessible and whether or not it is selected.
virtual void rowColumnExtents(int *row, int *column, int *rowExtents, int *columnExtents, bool *selected) const = 0;
// Returns a reference to the accessbile of the containing table.
virtual QAccessibleTable2Interface* table() const = 0;
virtual QAccessibleInterface* table() const = 0;
// #### Qt5 this should not be here but part of the state
virtual bool isExpandable() const = 0;
@ -228,7 +226,7 @@ class Q_GUI_EXPORT QAccessibleTable2Interface
public:
// Returns the cell at the specified row and column in the table.
virtual QAccessibleTable2CellInterface *cellAt (int row, int column) const = 0;
virtual QAccessibleInterface *cellAt (int row, int column) const = 0;
// Returns the caption for the table.
virtual QAccessibleInterface *caption() const = 0;
// Returns the description text of the specified column in the table.
@ -246,7 +244,7 @@ public:
// Returns the description text of the specified row in the table.
virtual QString rowDescription(int row) const = 0;
// Returns a list of accessibles currently selected.
virtual QList<QAccessibleTable2CellInterface*> selectedCells() const = 0;
virtual QList<QAccessibleInterface*> selectedCells() const = 0;
// Returns a list of column indexes currently selected (0 based).
virtual QList<int> selectedColumns() const = 0;
// Returns a list of row indexes currently selected (0 based).

View File

@ -220,7 +220,7 @@ QAccessibleTable2Cell *QAccessibleTable2::cell(const QModelIndex &index) const
return 0;
}
QAccessibleTable2CellInterface *QAccessibleTable2::cellAt(int row, int column) const
QAccessibleInterface *QAccessibleTable2::cellAt(int row, int column) const
{
Q_ASSERT(role() != QAccessible::Tree);
QModelIndex index = view->model()->index(row, column);
@ -272,9 +272,9 @@ QString QAccessibleTable2::rowDescription(int row) const
return view->model()->headerData(row, Qt::Vertical).toString();
}
QList<QAccessibleTable2CellInterface*> QAccessibleTable2::selectedCells() const
QList<QAccessibleInterface *> QAccessibleTable2::selectedCells() const
{
QList<QAccessibleTable2CellInterface*> cells;
QList<QAccessibleInterface*> cells;
Q_FOREACH (const QModelIndex &index, view->selectionModel()->selectedIndexes()) {
cells.append(cell(index));
}
@ -588,7 +588,7 @@ QAccessible::Relation QAccessibleTree::relationTo(const QAccessibleInterface *)
return QAccessible::Unrelated;
}
QAccessibleTable2CellInterface *QAccessibleTree::cellAt(int row, int column) const
QAccessibleInterface *QAccessibleTree::cellAt(int row, int column) const
{
QModelIndex index = indexFromLogical(row, column);
if (!index.isValid()) {
@ -626,6 +626,13 @@ QAccessibleTable2Cell::QAccessibleTable2Cell(QAbstractItemView *view_, const QMo
Q_ASSERT(index_.isValid());
}
void *QAccessibleTable2Cell::interface_cast(QAccessible::InterfaceType t)
{
if (t == QAccessible::Table2CellInterface)
return static_cast<QAccessibleTable2CellInterface*>(this);
return 0;
}
int QAccessibleTable2Cell::columnExtent() const { return 1; }
int QAccessibleTable2Cell::rowExtent() const { return 1; }
@ -705,9 +712,9 @@ void QAccessibleTable2Cell::rowColumnExtents(int *row, int *column, int *rowExte
*selected = isSelected();
}
QAccessibleTable2Interface* QAccessibleTable2Cell::table() const
QAccessibleInterface *QAccessibleTable2Cell::table() const
{
return QAccessible::queryAccessibleInterface(view)->table2Interface();
return QAccessible::queryAccessibleInterface(view);
}
QAccessible::Role QAccessibleTable2Cell::role() const

View File

@ -84,7 +84,7 @@ public:
void *interface_cast(QAccessible::InterfaceType t);
// table2 interface
virtual QAccessibleTable2CellInterface *cellAt(int row, int column) const;
virtual QAccessibleInterface *cellAt(int row, int column) const;
virtual QAccessibleInterface *caption() const;
virtual QAccessibleInterface *summary() const;
virtual QString columnDescription(int column) const;
@ -97,7 +97,7 @@ public:
virtual int selectedCellCount() const;
virtual int selectedColumnCount() const;
virtual int selectedRowCount() const;
virtual QList<QAccessibleTable2CellInterface*> selectedCells() const;
virtual QList<QAccessibleInterface*> selectedCells() const;
virtual QList<int> selectedColumns() const;
virtual QList<int> selectedRows() const;
virtual bool isColumnSelected(int column) const;
@ -163,7 +163,7 @@ public:
Relation relationTo(const QAccessibleInterface *other) const;
// table2 interface
QAccessibleTable2CellInterface *cellAt(int row, int column) const;
QAccessibleInterface *cellAt(int row, int column) const;
QString rowDescription(int row) const;
bool isRowSelected(int row) const;
bool selectRow(int row);
@ -172,11 +172,12 @@ private:
QModelIndex indexFromLogical(int row, int column = 0) const;
};
class QAccessibleTable2Cell: public QAccessibleTable2CellInterface /*), public QAccessibleTextInterface, public QAccessibleSimpleEditableTextInterface*/
class QAccessibleTable2Cell: public QAccessibleInterface, public QAccessibleTable2CellInterface
{
public:
QAccessibleTable2Cell(QAbstractItemView *view, const QModelIndex &m_index, QAccessible::Role role);
void *interface_cast(QAccessible::InterfaceType t);
QObject *object() const { return 0; }
Role role() const;
State state() const;
@ -206,7 +207,7 @@ public:
virtual int rowIndex() const;
virtual bool isSelected() const;
virtual void rowColumnExtents(int *row, int *column, int *rowExtents, int *columnExtents, bool *selected) const;
virtual QAccessibleTable2Interface* table() const;
virtual QAccessibleInterface* table() const;
private:
QHeaderView *verticalHeader() const;
@ -220,7 +221,7 @@ friend class QAccessibleTree;
};
class QAccessibleTable2HeaderCell: public QAccessibleInterface /*), public QAccessibleTextInterface, public QAccessibleSimpleEditableTextInterface*/
class QAccessibleTable2HeaderCell: public QAccessibleInterface
{
public:
// For header cells, pass the header view in addition

View File

@ -2517,16 +2517,19 @@ void tst_QAccessibility::table2ListTest()
QVERIFY(table2);
QCOMPARE(table2->columnCount(), 1);
QCOMPARE(table2->rowCount(), 4);
QAccessibleTable2CellInterface *cell1;
QAccessibleInterface *cell1;
QVERIFY(cell1 = table2->cellAt(0,0));
QCOMPARE(cell1->text(QAccessible::Name), QString("Oslo"));
QAccessibleTable2CellInterface *cell4;
QAccessibleInterface *cell4;
QVERIFY(cell4 = table2->cellAt(3,0));
QCOMPARE(cell4->text(QAccessible::Name), QString("Munich"));
QCOMPARE(cell4->role(), QAccessible::ListItem);
QCOMPARE(cell4->rowIndex(), 3);
QCOMPARE(cell4->columnIndex(), 0);
QVERIFY(!cell4->isExpandable());
QAccessibleTable2CellInterface *cellInterface = cell4->table2CellInterface();
QVERIFY(cellInterface);
QCOMPARE(cellInterface->rowIndex(), 3);
QCOMPARE(cellInterface->columnIndex(), 0);
QVERIFY(!cellInterface->isExpandable());
delete cell4;
delete cell1;
@ -2611,16 +2614,16 @@ void tst_QAccessibility::table2TreeTest()
QVERIFY(table2);
QCOMPARE(table2->columnCount(), 2);
QCOMPARE(table2->rowCount(), 2);
QAccessibleTable2CellInterface *cell1;
QAccessibleInterface *cell1;
QVERIFY(cell1 = table2->cellAt(0,0));
QCOMPARE(cell1->text(QAccessible::Name), QString("Spain"));
QAccessibleTable2CellInterface *cell2;
QAccessibleInterface *cell2;
QVERIFY(cell2 = table2->cellAt(1,0));
QCOMPARE(cell2->text(QAccessible::Name), QString("Austria"));
QCOMPARE(cell2->role(), QAccessible::TreeItem);
QCOMPARE(cell2->rowIndex(), 1);
QCOMPARE(cell2->columnIndex(), 0);
QVERIFY(cell2->isExpandable());
QCOMPARE(cell2->table2CellInterface()->rowIndex(), 1);
QCOMPARE(cell2->table2CellInterface()->columnIndex(), 0);
QVERIFY(cell2->table2CellInterface()->isExpandable());
QCOMPARE(iface->indexOfChild(cell2), 5);
QVERIFY(!(cell2->state() & QAccessible::Expanded));
QCOMPARE(table2->columnDescription(1), QString("Work"));
@ -2642,9 +2645,9 @@ void tst_QAccessibility::table2TreeTest()
cell2 = table2->cellAt(4,0);
QCOMPARE(cell2->text(QAccessible::Name), QString("Klimt"));
QCOMPARE(cell2->role(), QAccessible::TreeItem);
QCOMPARE(cell2->rowIndex(), 4);
QCOMPARE(cell2->columnIndex(), 0);
QVERIFY(!cell2->isExpandable());
QCOMPARE(cell2->table2CellInterface()->rowIndex(), 4);
QCOMPARE(cell2->table2CellInterface()->columnIndex(), 0);
QVERIFY(!cell2->table2CellInterface()->isExpandable());
QCOMPARE(iface->indexOfChild(cell2), 11);
QCOMPARE(table2->columnDescription(0), QString("Artist"));
@ -2703,7 +2706,7 @@ void tst_QAccessibility::table2TableTest()
QVERIFY(child2);
QCOMPARE(iface->indexOfChild(child2), 11);
QCOMPARE(child2->text(QAccessible::Name), QString("1.1"));
QAccessibleTable2CellInterface *cell2Iface = static_cast<QAccessibleTable2CellInterface*>(child2);
QAccessibleTable2CellInterface *cell2Iface = child2->table2CellInterface();
QCOMPARE(cell2Iface->rowIndex(), 1);
QCOMPARE(cell2Iface->columnIndex(), 1);
delete child2;
@ -2720,26 +2723,26 @@ void tst_QAccessibility::table2TableTest()
QVERIFY(table2);
QCOMPARE(table2->columnCount(), 3);
QCOMPARE(table2->rowCount(), 3);
QAccessibleTable2CellInterface *cell1;
QAccessibleInterface *cell1;
QVERIFY(cell1 = table2->cellAt(0,0));
QCOMPARE(cell1->text(QAccessible::Name), QString("0.0"));
QCOMPARE(iface->indexOfChild(cell1), 6);
QAccessibleTable2CellInterface *cell2;
QAccessibleInterface *cell2;
QVERIFY(cell2 = table2->cellAt(0,1));
QCOMPARE(cell2->text(QAccessible::Name), QString("0.1"));
QCOMPARE(cell2->role(), QAccessible::Cell);
QCOMPARE(cell2->rowIndex(), 0);
QCOMPARE(cell2->columnIndex(), 1);
QCOMPARE(cell2->table2CellInterface()->rowIndex(), 0);
QCOMPARE(cell2->table2CellInterface()->columnIndex(), 1);
QCOMPARE(iface->indexOfChild(cell2), 7);
delete cell2;
QAccessibleTable2CellInterface *cell3;
QAccessibleInterface *cell3;
QVERIFY(cell3 = table2->cellAt(1,2));
QCOMPARE(cell3->text(QAccessible::Name), QString("1.2"));
QCOMPARE(cell3->role(), QAccessible::Cell);
QCOMPARE(cell3->rowIndex(), 1);
QCOMPARE(cell3->columnIndex(), 2);
QCOMPARE(cell3->table2CellInterface()->rowIndex(), 1);
QCOMPARE(cell3->table2CellInterface()->columnIndex(), 2);
QCOMPARE(iface->indexOfChild(cell3), 12);
delete cell3;