diff options
Diffstat (limited to 'src/widgets/accessible/itemviews.cpp')
-rw-r--r-- | src/widgets/accessible/itemviews.cpp | 475 |
1 files changed, 320 insertions, 155 deletions
diff --git a/src/widgets/accessible/itemviews.cpp b/src/widgets/accessible/itemviews.cpp index 3bfe215c05..aa5f729820 100644 --- a/src/widgets/accessible/itemviews.cpp +++ b/src/widgets/accessible/itemviews.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "itemviews_p.h" @@ -52,7 +16,7 @@ #endif #include <private/qwidget_p.h> -#ifndef QT_NO_ACCESSIBILITY +#if QT_CONFIG(accessibility) QT_BEGIN_NAMESPACE @@ -75,11 +39,16 @@ QAbstractItemView *QAccessibleTable::view() const int QAccessibleTable::logicalIndex(const QModelIndex &index) const { - if (!view()->model() || !index.isValid()) + const QAbstractItemView *theView = view(); + const QAbstractItemModel *theModel = index.model(); + if (!theModel || !index.isValid()) return -1; - int vHeader = verticalHeader() ? 1 : 0; - int hHeader = horizontalHeader() ? 1 : 0; - return (index.row() + hHeader)*(index.model()->columnCount() + vHeader) + (index.column() + vHeader); + + const QModelIndex rootIndex = theView->rootIndex(); + const int vHeader = verticalHeader() ? 1 : 0; + const int hHeader = horizontalHeader() ? 1 : 0; + return (index.row() + hHeader) * (theModel->columnCount(rootIndex) + vHeader) + + (index.column() + vHeader); } QAccessibleTable::QAccessibleTable(QWidget *w) @@ -115,13 +84,13 @@ bool QAccessibleTable::isValid() const QAccessibleTable::~QAccessibleTable() { - for (QAccessible::Id id : qAsConst(childToId)) + for (QAccessible::Id id : std::as_const(childToId)) QAccessible::deleteAccessibleInterface(id); } QHeaderView *QAccessibleTable::horizontalHeader() const { - QHeaderView *header = 0; + QHeaderView *header = nullptr; if (false) { #if QT_CONFIG(tableview) } else if (const QTableView *tv = qobject_cast<const QTableView*>(view())) { @@ -137,7 +106,7 @@ QHeaderView *QAccessibleTable::horizontalHeader() const QHeaderView *QAccessibleTable::verticalHeader() const { - QHeaderView *header = 0; + QHeaderView *header = nullptr; if (false) { #if QT_CONFIG(tableview) } else if (const QTableView *tv = qobject_cast<const QTableView*>(view())) { @@ -149,69 +118,79 @@ QHeaderView *QAccessibleTable::verticalHeader() const QAccessibleInterface *QAccessibleTable::cellAt(int row, int column) const { - if (!view()->model()) - return 0; + const QAbstractItemView *theView = view(); + const QAbstractItemModel *theModel = theView->model(); + if (!theModel) + return nullptr; Q_ASSERT(role() != QAccessible::Tree); - QModelIndex index = view()->model()->index(row, column, view()->rootIndex()); + QModelIndex index = theModel->index(row, column, theView->rootIndex()); if (Q_UNLIKELY(!index.isValid())) { - qWarning() << "QAccessibleTable::cellAt: invalid index: " << index << " for " << view(); - return 0; + qWarning() << "QAccessibleTable::cellAt: invalid index: " << index << " for " << theView; + return nullptr; } return child(logicalIndex(index)); } QAccessibleInterface *QAccessibleTable::caption() const { - return 0; + return nullptr; } QString QAccessibleTable::columnDescription(int column) const { - if (!view()->model()) + const QAbstractItemView *theView = view(); + const QAbstractItemModel *theModel = theView->model(); + if (!theModel) return QString(); - return view()->model()->headerData(column, Qt::Horizontal).toString(); + return theModel->headerData(column, Qt::Horizontal).toString(); } int QAccessibleTable::columnCount() const { - if (!view()->model()) + const QAbstractItemView *theView = view(); + const QAbstractItemModel *theModel = theView->model(); + if (!theModel) return 0; - return view()->model()->columnCount(); + return theModel->columnCount(theView->rootIndex()); } int QAccessibleTable::rowCount() const { - if (!view()->model()) + const QAbstractItemView *theView = view(); + const QAbstractItemModel *theModel = theView->model(); + if (!theModel) return 0; - return view()->model()->rowCount(); + return theModel->rowCount(theView->rootIndex()); } int QAccessibleTable::selectedCellCount() const { if (!view()->selectionModel()) return 0; - return view()->selectionModel()->selectedIndexes().count(); + return view()->selectionModel()->selectedIndexes().size(); } int QAccessibleTable::selectedColumnCount() const { if (!view()->selectionModel()) return 0; - return view()->selectionModel()->selectedColumns().count(); + return view()->selectionModel()->selectedColumns().size(); } int QAccessibleTable::selectedRowCount() const { if (!view()->selectionModel()) return 0; - return view()->selectionModel()->selectedRows().count(); + return view()->selectionModel()->selectedRows().size(); } QString QAccessibleTable::rowDescription(int row) const { - if (!view()->model()) + const QAbstractItemView *theView = view(); + const QAbstractItemModel *theModel = theView->model(); + if (!theModel) return QString(); - return view()->model()->headerData(row, Qt::Vertical).toString(); + return theModel->headerData(row, Qt::Vertical).toString(); } QList<QAccessibleInterface *> QAccessibleTable::selectedCells() const @@ -254,7 +233,7 @@ QList<int> QAccessibleTable::selectedRows() const QAccessibleInterface *QAccessibleTable::summary() const { - return 0; + return nullptr; } bool QAccessibleTable::isColumnSelected(int column) const @@ -273,9 +252,13 @@ bool QAccessibleTable::isRowSelected(int row) const bool QAccessibleTable::selectRow(int row) { - if (!view()->model() || !view()->selectionModel()) + QAbstractItemView *theView = view(); + const QAbstractItemModel *theModel = theView->model(); + if (!theModel || !view()->selectionModel()) return false; - QModelIndex index = view()->model()->index(row, 0, view()->rootIndex()); + + const QModelIndex rootIndex = theView->rootIndex(); + const QModelIndex index = theModel->index(row, 0, rootIndex); if (!index.isValid() || view()->selectionBehavior() == QAbstractItemView::SelectColumns) return false; @@ -289,9 +272,10 @@ bool QAccessibleTable::selectRow(int row) view()->clearSelection(); break; case QAbstractItemView::ContiguousSelection: - if ((!row || !view()->selectionModel()->isRowSelected(row - 1, view()->rootIndex())) - && !view()->selectionModel()->isRowSelected(row + 1, view()->rootIndex())) - view()->clearSelection(); + if ((!row || !theView->selectionModel()->isRowSelected(row - 1, rootIndex)) + && !theView->selectionModel()->isRowSelected(row + 1, rootIndex)) { + theView->clearSelection(); + } break; default: break; @@ -303,45 +287,55 @@ bool QAccessibleTable::selectRow(int row) bool QAccessibleTable::selectColumn(int column) { - if (!view()->model() || !view()->selectionModel()) + QAbstractItemView *theView = view(); + const QAbstractItemModel *theModel = theView->model(); + auto *selectionModel = theView->selectionModel(); + if (!theModel || !selectionModel) return false; - QModelIndex index = view()->model()->index(0, column, view()->rootIndex()); + + const QModelIndex rootIndex = theView->rootIndex(); + const QModelIndex index = theModel->index(0, column, rootIndex); if (!index.isValid() || view()->selectionBehavior() == QAbstractItemView::SelectRows) return false; - switch (view()->selectionMode()) { + switch (theView->selectionMode()) { case QAbstractItemView::NoSelection: return false; case QAbstractItemView::SingleSelection: - if (view()->selectionBehavior() != QAbstractItemView::SelectColumns && rowCount() > 1) + if (theView->selectionBehavior() != QAbstractItemView::SelectColumns && rowCount() > 1) return false; Q_FALLTHROUGH(); case QAbstractItemView::ContiguousSelection: - if ((!column || !view()->selectionModel()->isColumnSelected(column - 1, view()->rootIndex())) - && !view()->selectionModel()->isColumnSelected(column + 1, view()->rootIndex())) - view()->clearSelection(); + if ((!column || !selectionModel->isColumnSelected(column - 1, rootIndex)) + && !selectionModel->isColumnSelected(column + 1, rootIndex)) { + theView->clearSelection(); + } break; default: break; } - view()->selectionModel()->select(index, QItemSelectionModel::Select | QItemSelectionModel::Columns); + selectionModel->select(index, QItemSelectionModel::Select | QItemSelectionModel::Columns); return true; } bool QAccessibleTable::unselectRow(int row) { - if (!view()->model() || !view()->selectionModel()) + const QAbstractItemView *theView = view(); + const QAbstractItemModel *theModel = theView->model(); + auto *selectionModel = theView->selectionModel(); + if (!theModel || !selectionModel) return false; - QModelIndex index = view()->model()->index(row, 0, view()->rootIndex()); + const QModelIndex rootIndex = theView->rootIndex(); + const QModelIndex index = view()->model()->index(row, 0, rootIndex); if (!index.isValid()) return false; QItemSelection selection(index, index); - switch (view()->selectionMode()) { + switch (theView->selectionMode()) { case QAbstractItemView::SingleSelection: //In SingleSelection and ContiguousSelection once an item //is selected, there's no way for the user to unselect all items @@ -352,26 +346,31 @@ bool QAccessibleTable::unselectRow(int row) if (selectedRowCount() == 1) return false; - if ((!row || view()->selectionModel()->isRowSelected(row - 1, view()->rootIndex())) - && view()->selectionModel()->isRowSelected(row + 1, view()->rootIndex())) { + if ((!row || selectionModel->isRowSelected(row - 1, rootIndex)) + && selectionModel->isRowSelected(row + 1, rootIndex)) { //If there are rows selected both up the current row and down the current rown, //the ones which are down the current row will be deselected - selection = QItemSelection(index, view()->model()->index(rowCount() - 1, 0, view()->rootIndex())); + selection = QItemSelection(index, theModel->index(rowCount() - 1, 0, rootIndex)); } + break; default: break; } - view()->selectionModel()->select(selection, QItemSelectionModel::Deselect | QItemSelectionModel::Rows); + selectionModel->select(selection, QItemSelectionModel::Deselect | QItemSelectionModel::Rows); return true; } bool QAccessibleTable::unselectColumn(int column) { - if (!view()->model() || !view()->selectionModel()) + const QAbstractItemView *theView = view(); + const QAbstractItemModel *theModel = theView->model(); + auto *selectionModel = theView->selectionModel(); + if (!theModel || !selectionModel) return false; - QModelIndex index = view()->model()->index(0, column, view()->rootIndex()); + const QModelIndex rootIndex = theView->rootIndex(); + const QModelIndex index = view()->model()->index(0, column, rootIndex); if (!index.isValid()) return false; @@ -388,20 +387,100 @@ bool QAccessibleTable::unselectColumn(int column) if (selectedColumnCount() == 1) return false; - if ((!column || view()->selectionModel()->isColumnSelected(column - 1, view()->rootIndex())) - && view()->selectionModel()->isColumnSelected(column + 1, view()->rootIndex())) { + if ((!column || selectionModel->isColumnSelected(column - 1, rootIndex)) + && selectionModel->isColumnSelected(column + 1, rootIndex)) { //If there are columns selected both at the left of the current row and at the right //of the current rown, the ones which are at the right will be deselected - selection = QItemSelection(index, view()->model()->index(0, columnCount() - 1, view()->rootIndex())); + selection = QItemSelection(index, theModel->index(0, columnCount() - 1, rootIndex)); } + break; default: break; } - view()->selectionModel()->select(selection, QItemSelectionModel::Deselect | QItemSelectionModel::Columns); + selectionModel->select(selection, QItemSelectionModel::Deselect | QItemSelectionModel::Columns); + 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; @@ -409,7 +488,27 @@ QAccessible::Role QAccessibleTable::role() const QAccessible::State QAccessibleTable::state() const { - return QAccessible::State(); + QAccessible::State state; + const auto *w = view(); + + if (w->testAttribute(Qt::WA_WState_Visible) == false) + state.invisible = true; + if (w->focusPolicy() != Qt::NoFocus) + state.focusable = true; + if (w->hasFocus()) + state.focused = true; + if (!w->isEnabled()) + state.disabled = true; + if (w->isWindow()) { + if (w->windowFlags() & Qt::WindowSystemMenuHint) + state.movable = true; + if (w->minimumSize() != w->maximumSize()) + state.sizeable = true; + if (w->isActiveWindow()) + state.active = true; + } + + return state; } QAccessibleInterface *QAccessibleTable::childAt(int x, int y) const @@ -418,30 +517,44 @@ QAccessibleInterface *QAccessibleTable::childAt(int x, int y) const QPoint indexPosition = view()->mapFromGlobal(QPoint(x, y) - viewportOffset); // FIXME: if indexPosition < 0 in one coordinate, return header - QModelIndex index = view()->indexAt(indexPosition); - if (index.isValid()) { + const QModelIndex index = view()->indexAt(indexPosition); + if (index.isValid()) return child(logicalIndex(index)); - } - return 0; + return nullptr; +} + +QAccessibleInterface *QAccessibleTable::focusChild() const +{ + QModelIndex index = view()->currentIndex(); + if (!index.isValid()) + return nullptr; + + return child(logicalIndex(index)); } int QAccessibleTable::childCount() const { - if (!view()->model()) + const QAbstractItemView *theView = view(); + const QAbstractItemModel *theModel = theView->model(); + if (!theModel) return 0; + const QModelIndex rootIndex = theView->rootIndex(); int vHeader = verticalHeader() ? 1 : 0; int hHeader = horizontalHeader() ? 1 : 0; - return (view()->model()->rowCount()+hHeader) * (view()->model()->columnCount()+vHeader); + return (theModel->rowCount(rootIndex) + hHeader) * (theModel->columnCount(rootIndex) + vHeader); } int QAccessibleTable::indexOfChild(const QAccessibleInterface *iface) const { - if (!view()->model()) + const QAbstractItemView *theView = view(); + const QAbstractItemModel *theModel = theView->model(); + if (!theModel) return -1; QAccessibleInterface *parent = iface->parent(); - if (parent->object() != view()) + if (parent->object() != theView) return -1; + const QModelIndex rootIndex = theView->rootIndex(); Q_ASSERT(iface->role() != QAccessible::TreeItem); // should be handled by tree class if (iface->role() == QAccessible::Cell || iface->role() == QAccessible::ListItem) { const QAccessibleTableCell* cell = static_cast<const QAccessibleTableCell*>(iface); @@ -451,7 +564,7 @@ int QAccessibleTable::indexOfChild(const QAccessibleInterface *iface) const return cell->index + (verticalHeader() ? 1 : 0); } else if (iface->role() == QAccessible::RowHeader){ const QAccessibleTableHeaderCell* cell = static_cast<const QAccessibleTableHeaderCell*>(iface); - return (cell->index + 1) * (view()->model()->columnCount() + 1); + return (cell->index + 1) * (theModel->columnCount(rootIndex) + 1); } else if (iface->role() == QAccessible::Pane) { return 0; // corner button } else { @@ -485,14 +598,17 @@ QAccessibleInterface *QAccessibleTable::parent() const } return QAccessible::queryAccessibleInterface(view()->parent()); } - return 0; + return QAccessible::queryAccessibleInterface(qApp); } QAccessibleInterface *QAccessibleTable::child(int logicalIndex) const { - if (!view()->model()) - return 0; + QAbstractItemView *theView = view(); + const QAbstractItemModel *theModel = theView->model(); + if (!theModel) + return nullptr; + const QModelIndex rootIndex = theView->rootIndex(); auto id = childToId.constFind(logicalIndex); if (id != childToId.constEnd()) return QAccessible::accessibleInterface(id.value()); @@ -500,37 +616,37 @@ QAccessibleInterface *QAccessibleTable::child(int logicalIndex) const int vHeader = verticalHeader() ? 1 : 0; int hHeader = horizontalHeader() ? 1 : 0; - int columns = view()->model()->columnCount() + vHeader; + int columns = theModel->columnCount(rootIndex) + vHeader; int row = logicalIndex / columns; int column = logicalIndex % columns; - QAccessibleInterface *iface = 0; + QAccessibleInterface *iface = nullptr; if (vHeader) { if (column == 0) { if (hHeader && row == 0) { - iface = new QAccessibleTableCornerButton(view()); + iface = new QAccessibleTableCornerButton(theView); } else { - iface = new QAccessibleTableHeaderCell(view(), row - hHeader, Qt::Vertical); + iface = new QAccessibleTableHeaderCell(theView, row - hHeader, Qt::Vertical); } } --column; } if (!iface && hHeader) { if (row == 0) { - iface = new QAccessibleTableHeaderCell(view(), column, Qt::Horizontal); + iface = new QAccessibleTableHeaderCell(theView, column, Qt::Horizontal); } --row; } if (!iface) { - QModelIndex index = view()->model()->index(row, column, view()->rootIndex()); + QModelIndex index = theModel->index(row, column, rootIndex); if (Q_UNLIKELY(!index.isValid())) { qWarning("QAccessibleTable::child: Invalid index at: %d %d", row, column); - return 0; + return nullptr; } - iface = new QAccessibleTableCell(view(), index, cellRole()); + iface = new QAccessibleTableCell(theView, index, cellRole()); } QAccessible::registerAccessibleInterface(iface); @@ -540,9 +656,11 @@ 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 0; + return nullptr; } void QAccessibleTable::modelChange(QAccessibleTableModelChangeEvent *event) @@ -553,7 +671,7 @@ void QAccessibleTable::modelChange(QAccessibleTableModelChangeEvent *event) switch (event->modelChangeType()) { case QAccessibleTableModelChangeEvent::ModelReset: - for (QAccessible::Id id : qAsConst(childToId)) + for (QAccessible::Id id : std::as_const(childToId)) QAccessible::deleteAccessibleInterface(id); childToId.clear(); break; @@ -661,7 +779,7 @@ QModelIndex QAccessibleTree::indexFromLogical(int row, int column) const return QModelIndex(); const QTreeView *treeView = qobject_cast<const QTreeView*>(view()); - if (Q_UNLIKELY(row < 0 || column < 0 || treeView->d_func()->viewItems.count() <= row)) { + if (Q_UNLIKELY(row < 0 || column < 0 || treeView->d_func()->viewItems.size() <= row)) { qWarning() << "QAccessibleTree::indexFromLogical: invalid index: " << row << column << " for " << treeView; return QModelIndex(); } @@ -675,20 +793,39 @@ QModelIndex QAccessibleTree::indexFromLogical(int row, int column) const QAccessibleInterface *QAccessibleTree::childAt(int x, int y) const { - if (!view()->model()) - return 0; - QPoint viewportOffset = view()->viewport()->mapTo(view(), QPoint(0,0)); - QPoint indexPosition = view()->mapFromGlobal(QPoint(x, y) - viewportOffset); + const QAbstractItemView *theView = view(); + const QAbstractItemModel *theModel = theView->model(); + if (!theModel) + return nullptr; - QModelIndex index = view()->indexAt(indexPosition); + const QPoint viewportOffset = theView->viewport()->mapTo(view(), QPoint(0, 0)); + const QPoint indexPosition = theView->mapFromGlobal(QPoint(x, y) - viewportOffset); + + const QModelIndex index = theView->indexAt(indexPosition); if (!index.isValid()) - return 0; + return nullptr; - const QTreeView *treeView = qobject_cast<const QTreeView*>(view()); + const QTreeView *treeView = qobject_cast<const QTreeView *>(theView); int row = treeView->d_func()->viewIndex(index) + (horizontalHeader() ? 1 : 0); int column = index.column(); - int i = row * view()->model()->columnCount() + column; + int i = row * theModel->columnCount(theView->rootIndex()) + column; + return child(i); +} + +QAccessibleInterface *QAccessibleTree::focusChild() const +{ + const QAbstractItemView *theView = view(); + const QAbstractItemModel *theModel = theView->model(); + const QModelIndex index = theView->currentIndex(); + if (!index.isValid()) + return nullptr; + + const QTreeView *treeView = qobject_cast<const QTreeView *>(theView); + const int row = treeView->d_func()->viewIndex(index) + (horizontalHeader() ? 1 : 0); + const int column = index.column(); + + int i = row * theModel->columnCount(theView->rootIndex()) + column; return child(i); } @@ -696,35 +833,39 @@ int QAccessibleTree::childCount() const { const QTreeView *treeView = qobject_cast<const QTreeView*>(view()); Q_ASSERT(treeView); - if (!view()->model()) + const QAbstractItemModel *theModel = treeView->model(); + if (!theModel) return 0; int hHeader = horizontalHeader() ? 1 : 0; - return (treeView->d_func()->viewItems.count() + hHeader)* view()->model()->columnCount(); + return (treeView->d_func()->viewItems.size() + hHeader) + * theModel->columnCount(treeView->rootIndex()); } QAccessibleInterface *QAccessibleTree::child(int logicalIndex) const { - if (logicalIndex < 0 || !view()->model() || !view()->model()->columnCount()) - return 0; + const QAbstractItemView *theView = view(); + const QAbstractItemModel *theModel = theView->model(); + const QModelIndex rootIndex = theView->rootIndex(); + if (logicalIndex < 0 || !theModel || !theModel->columnCount(rootIndex)) + return nullptr; - QAccessibleInterface *iface = 0; + QAccessibleInterface *iface = nullptr; int index = logicalIndex; if (horizontalHeader()) { - if (index < view()->model()->columnCount()) { + if (index < theModel->columnCount(rootIndex)) iface = new QAccessibleTableHeaderCell(view(), index, Qt::Horizontal); - } else { - index -= view()->model()->columnCount(); - } + else + index -= theModel->columnCount(rootIndex); } if (!iface) { - int row = index / view()->model()->columnCount(); - int column = index % view()->model()->columnCount(); - QModelIndex modelIndex = indexFromLogical(row, column); + const int row = index / theModel->columnCount(rootIndex); + const int column = index % theModel->columnCount(rootIndex); + const QModelIndex modelIndex = indexFromLogical(row, column); if (!modelIndex.isValid()) - return 0; + return nullptr; iface = new QAccessibleTableCell(view(), modelIndex, cellRole()); } QAccessible::registerAccessibleInterface(iface); @@ -736,12 +877,14 @@ int QAccessibleTree::rowCount() const { const QTreeView *treeView = qobject_cast<const QTreeView*>(view()); Q_ASSERT(treeView); - return treeView->d_func()->viewItems.count(); + return treeView->d_func()->viewItems.size(); } int QAccessibleTree::indexOfChild(const QAccessibleInterface *iface) const { - if (!view()->model()) + const QAbstractItemView *theView = view(); + const QAbstractItemModel *theModel = theView->model(); + if (!theModel) return -1; QAccessibleInterface *parent = iface->parent(); if (parent->object() != view()) @@ -749,12 +892,12 @@ int QAccessibleTree::indexOfChild(const QAccessibleInterface *iface) const if (iface->role() == QAccessible::TreeItem) { const QAccessibleTableCell* cell = static_cast<const QAccessibleTableCell*>(iface); - const QTreeView *treeView = qobject_cast<const QTreeView*>(view()); + const QTreeView *treeView = qobject_cast<const QTreeView *>(theView); Q_ASSERT(treeView); int row = treeView->d_func()->viewIndex(cell->m_index) + (horizontalHeader() ? 1 : 0); int column = cell->m_index.column(); - int index = row * view()->model()->columnCount() + column; + int index = row * theModel->columnCount(theView->rootIndex()) + column; return index; } else if (iface->role() == QAccessible::ColumnHeader){ const QAccessibleTableHeaderCell* cell = static_cast<const QAccessibleTableHeaderCell*>(iface); @@ -772,7 +915,7 @@ QAccessibleInterface *QAccessibleTree::cellAt(int row, int column) const QModelIndex index = indexFromLogical(row, column); if (Q_UNLIKELY(!index.isValid())) { qWarning("Requested invalid tree cell: %d %d", row, column); - return 0; + return nullptr; } const QTreeView *treeView = qobject_cast<const QTreeView*>(view()); Q_ASSERT(treeView); @@ -841,7 +984,7 @@ void *QAccessibleTableCell::interface_cast(QAccessible::InterfaceType t) return static_cast<QAccessibleTableCellInterface*>(this); if (t == QAccessible::ActionInterface) return static_cast<QAccessibleActionInterface*>(this); - return 0; + return nullptr; } int QAccessibleTableCell::columnExtent() const { return 1; } @@ -869,7 +1012,7 @@ QList<QAccessibleInterface*> QAccessibleTableCell::columnHeaderCells() const QHeaderView *QAccessibleTableCell::horizontalHeader() const { - QHeaderView *header = 0; + QHeaderView *header = nullptr; if (false) { #if QT_CONFIG(tableview) @@ -887,7 +1030,7 @@ QHeaderView *QAccessibleTableCell::horizontalHeader() const QHeaderView *QAccessibleTableCell::verticalHeader() const { - QHeaderView *header = 0; + QHeaderView *header = nullptr; #if QT_CONFIG(tableview) if (const QTableView *tv = qobject_cast<const QTableView*>(view)) header = tv->verticalHeader(); @@ -934,10 +1077,23 @@ QStringList QAccessibleTableCell::actionNames() const void QAccessibleTableCell::doAction(const QString& actionName) { if (actionName == toggleAction()) { - if (isSelected()) +#if defined(Q_OS_ANDROID) + QAccessibleInterface *parentInterface = parent(); + while (parentInterface){ + if (parentInterface->role() == QAccessible::ComboBox) { + selectCell(); + parentInterface->actionInterface()->doAction(pressAction()); + return; + } else { + parentInterface = parentInterface->parent(); + } + } +#endif + if (isSelected()) { unselectCell(); - else + } else { selectCell(); + } } } @@ -1004,7 +1160,7 @@ void QAccessibleTableCell::unselectCell() //one cell is selected it cannot be unselected by the user if ((selectionMode != QAbstractItemView::MultiSelection) && (selectionMode != QAbstractItemView::ExtendedSelection) - && (view->selectionModel()->selectedIndexes().count() <= 1)) + && (view->selectionModel()->selectedIndexes().size() <= 1)) return; view->selectionModel()->select(m_index, QItemSelectionModel::Deselect); @@ -1035,10 +1191,14 @@ QAccessible::State QAccessibleTableCell::state() const st.selected = true; if (view->selectionModel()->currentIndex() == m_index) st.focused = true; - if (m_index.model()->data(m_index, Qt::CheckStateRole).toInt() == Qt::Checked) + + QVariant checkState = m_index.model()->data(m_index, Qt::CheckStateRole); + if (checkState.toInt() == Qt::Checked) st.checked = true; Qt::ItemFlags flags = m_index.flags(); + if ((flags & Qt::ItemIsUserCheckable) && checkState.isValid()) + st.checkable = true; if (flags & Qt::ItemIsSelectable) { st.selectable = true; st.focusable = true; @@ -1115,7 +1275,7 @@ QAccessibleInterface *QAccessibleTableCell::parent() const QAccessibleInterface *QAccessibleTableCell::child(int) const { - return 0; + return nullptr; } QAccessibleTableHeaderCell::QAccessibleTableHeaderCell(QAbstractItemView *view_, int index_, Qt::Orientation orientation_) @@ -1143,7 +1303,7 @@ QAccessible::State QAccessibleTableHeaderCell::state() const QRect QAccessibleTableHeaderCell::rect() const { - QHeaderView *header = 0; + QHeaderView *header = nullptr; if (false) { #if QT_CONFIG(tableview) } else if (const QTableView *tv = qobject_cast<const QTableView*>(view)) { @@ -1194,9 +1354,14 @@ void QAccessibleTableHeaderCell::setText(QAccessible::Text, const QString &) bool QAccessibleTableHeaderCell::isValid() const { - return view && !qt_widget_private(view)->data.in_destructor - && view->model() && (index >= 0) - && ((orientation == Qt::Horizontal) ? (index < view->model()->columnCount()) : (index < view->model()->rowCount())); + const QAbstractItemModel *theModel = view && !qt_widget_private(view)->data.in_destructor + ? view->model() : nullptr; + if (!theModel) + return false; + const QModelIndex rootIndex = view->rootIndex(); + return (index >= 0) && ((orientation == Qt::Horizontal) + ? (index < theModel->columnCount(rootIndex)) + : (index < theModel->rowCount(rootIndex))); } QAccessibleInterface *QAccessibleTableHeaderCell::parent() const @@ -1206,12 +1371,12 @@ QAccessibleInterface *QAccessibleTableHeaderCell::parent() const QAccessibleInterface *QAccessibleTableHeaderCell::child(int) const { - return 0; + return nullptr; } QHeaderView *QAccessibleTableHeaderCell::headerView() const { - QHeaderView *header = 0; + QHeaderView *header = nullptr; if (false) { #if QT_CONFIG(tableview) } else if (const QTableView *tv = qobject_cast<const QTableView*>(view)) { @@ -1231,4 +1396,4 @@ QHeaderView *QAccessibleTableHeaderCell::headerView() const QT_END_NAMESPACE -#endif // QT_NO_ACCESSIBILITY +#endif // QT_CONFIG(accessibility) |