QAccessibleInterface *QAccessibleTree::child(int logicalIndex) const { if (logicalIndex < 0 || !view()->model() || !view()->model()->columnCount()) return 0; QAccessibleInterface *iface = 0; int index = logicalIndex; if (horizontalHeader()) { if (index < view()->model()->columnCount()) { iface = new QAccessibleTableHeaderCell(view(), index, Qt::Horizontal); } else { index -= view()->model()->columnCount(); } } if (!iface) { int row = index / view()->model()->columnCount(); int column = index % view()->model()->columnCount(); QModelIndex modelIndex = indexFromLogical(row, column); if (!modelIndex.isValid()) return 0; iface = new QAccessibleTableCell(view(), modelIndex, cellRole()); } QAccessible::registerAccessibleInterface(iface); // ### FIXME: get interfaces from the cache instead of re-creating them return iface; }
QAccessibleInterface *QAccessibleTable::childFromLogical(int logicalIndex) const { logicalIndex--; // one based counting ftw int vHeader = verticalHeader() ? 1 : 0; int hHeader = horizontalHeader() ? 1 : 0; int columns = view->model()->columnCount() + vHeader; int row = logicalIndex / columns; int column = logicalIndex % columns; if (vHeader) { if (column == 0) { if (row == 0) { return new QAccessibleTableCornerButton(view); } return new QAccessibleTableHeaderCell(view, row-1, Qt::Vertical); } --column; } if (hHeader) { if (row == 0) { return new QAccessibleTableHeaderCell(view, column, Qt::Horizontal); } --row; } return new QAccessibleTableCell(view, view->model()->index(row, column), cellRole()); }
QAccessibleInterface *QAccessibleTree::cellAt(int row, int column) const { QModelIndex index = indexFromLogical(row, column); if (!index.isValid()) { qWarning() << "Requested invalid tree cell: " << row << column; return 0; } return new QAccessibleTableCell(view, index, cellRole()); }
QAccessibleInterface *QAccessibleTable::child(int logicalIndex) const { if (!view()->model()) return 0; if (childToId.contains(logicalIndex)) { QAccessible::Id id = childToId.value(logicalIndex); return QAccessible::accessibleInterface(id); } int vHeader = verticalHeader() ? 1 : 0; int hHeader = horizontalHeader() ? 1 : 0; int columns = view()->model()->columnCount() + vHeader; int row = logicalIndex / columns; int column = logicalIndex % columns; QAccessibleInterface *iface = 0; if (vHeader) { if (column == 0) { if (hHeader && row == 0) { iface = new QAccessibleTableCornerButton(view()); } else { iface = new QAccessibleTableHeaderCell(view(), row - hHeader, Qt::Vertical); } } --column; } if (!iface && hHeader) { if (row == 0) { iface = new QAccessibleTableHeaderCell(view(), column, Qt::Horizontal); } --row; } if (!iface) { QModelIndex index = view()->model()->index(row, column, view()->rootIndex()); if (!index.isValid()) { qWarning() << "QAccessibleTable::child: Invalid index at: " << row << column; return 0; } iface = new QAccessibleTableCell(view(), index, cellRole()); } QAccessible::registerAccessibleInterface(iface); childToId.insert(logicalIndex, QAccessible::uniqueId(iface)); return iface; }
QAccessibleInterface *QAccessibleTable2::childFromLogical(int logicalIndex) const { if (!view()->model()) return 0; logicalIndex--; // one based counting ftw int vHeader = verticalHeader() ? 1 : 0; int hHeader = horizontalHeader() ? 1 : 0; int columns = view()->model()->columnCount() + vHeader; int row = logicalIndex / columns; int column = logicalIndex % columns; if (vHeader) { if (column == 0) { if (row == 0) { return new QAccessibleTable2CornerButton(view()); } return new QAccessibleTable2HeaderCell(view(), row-1, Qt::Vertical); } --column; } if (hHeader) { if (row == 0) { return new QAccessibleTable2HeaderCell(view(), column, Qt::Horizontal); } --row; } QModelIndex index = view()->model()->index(row, column, view()->rootIndex()); if (!index.isValid()) { qWarning() << "QAccessibleTable2::childFromLogical: Invalid index at: " << row << column; return 0; } return new QAccessibleTable2Cell(view(), index, cellRole()); }
QAccessibleTableCell *QAccessibleTable::cell(const QModelIndex &index) const { if (index.isValid()) return new QAccessibleTableCell(view, index, cellRole()); return 0; }