2021-10-26 03:21:42 +05:30
|
|
|
#include "InstanceView.h"
|
|
|
|
#include "AccessibleInstanceView.h"
|
|
|
|
#include "AccessibleInstanceView_p.h"
|
2019-07-22 00:42:05 +05:30
|
|
|
|
|
|
|
#include <qvariant.h>
|
|
|
|
#include <qaccessible.h>
|
|
|
|
#include <qheaderview.h>
|
|
|
|
|
2019-10-01 17:58:06 +05:30
|
|
|
#ifndef QT_NO_ACCESSIBILITY
|
|
|
|
|
2019-07-22 00:42:05 +05:30
|
|
|
QAccessibleInterface *groupViewAccessibleFactory(const QString &classname, QObject *object)
|
|
|
|
{
|
|
|
|
QAccessibleInterface *iface = 0;
|
|
|
|
if (!object || !object->isWidgetType())
|
|
|
|
return iface;
|
|
|
|
|
|
|
|
QWidget *widget = static_cast<QWidget*>(object);
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
if (classname == QLatin1String("InstanceView")) {
|
|
|
|
iface = new AccessibleInstanceView((InstanceView *)widget);
|
2019-07-22 00:42:05 +05:30
|
|
|
}
|
|
|
|
return iface;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
QAbstractItemView *AccessibleInstanceView::view() const
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
return qobject_cast<QAbstractItemView*>(object());
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
int AccessibleInstanceView::logicalIndex(const QModelIndex &index) const
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
if (!view()->model() || !index.isValid())
|
|
|
|
return -1;
|
|
|
|
return index.row() * (index.model()->columnCount()) + index.column();
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
AccessibleInstanceView::AccessibleInstanceView(QWidget *w)
|
2019-07-22 00:42:05 +05:30
|
|
|
: QAccessibleObject(w)
|
|
|
|
{
|
|
|
|
Q_ASSERT(view());
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
bool AccessibleInstanceView::isValid() const
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
return view();
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
AccessibleInstanceView::~AccessibleInstanceView()
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
2019-07-22 05:14:19 +05:30
|
|
|
for (QAccessible::Id id : childToId) {
|
2019-07-22 00:42:05 +05:30
|
|
|
QAccessible::deleteAccessibleInterface(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
QAccessibleInterface *AccessibleInstanceView::cellAt(int row, int column) const
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
if (!view()->model()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
QModelIndex index = view()->model()->index(row, column, view()->rootIndex());
|
|
|
|
if (Q_UNLIKELY(!index.isValid())) {
|
2021-10-26 03:21:42 +05:30
|
|
|
qWarning() << "AccessibleInstanceView::cellAt: invalid index: " << index << " for " << view();
|
2019-07-22 00:42:05 +05:30
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return child(logicalIndex(index));
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
QAccessibleInterface *AccessibleInstanceView::caption() const
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
QString AccessibleInstanceView::columnDescription(int column) const
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
if (!view()->model())
|
|
|
|
return QString();
|
|
|
|
|
|
|
|
return view()->model()->headerData(column, Qt::Horizontal).toString();
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
int AccessibleInstanceView::columnCount() const
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
if (!view()->model())
|
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
int AccessibleInstanceView::rowCount() const
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
if (!view()->model())
|
|
|
|
return 0;
|
|
|
|
return view()->model()->rowCount();
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
int AccessibleInstanceView::selectedCellCount() const
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
if (!view()->selectionModel())
|
|
|
|
return 0;
|
|
|
|
return view()->selectionModel()->selectedIndexes().count();
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
int AccessibleInstanceView::selectedColumnCount() const
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
if (!view()->selectionModel())
|
|
|
|
return 0;
|
|
|
|
return view()->selectionModel()->selectedColumns().count();
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
int AccessibleInstanceView::selectedRowCount() const
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
if (!view()->selectionModel())
|
|
|
|
return 0;
|
|
|
|
return view()->selectionModel()->selectedRows().count();
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
QString AccessibleInstanceView::rowDescription(int row) const
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
if (!view()->model())
|
|
|
|
return QString();
|
|
|
|
return view()->model()->headerData(row, Qt::Vertical).toString();
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
QList<QAccessibleInterface *> AccessibleInstanceView::selectedCells() const
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
QList<QAccessibleInterface*> cells;
|
|
|
|
if (!view()->selectionModel())
|
|
|
|
return cells;
|
|
|
|
const QModelIndexList selectedIndexes = view()->selectionModel()->selectedIndexes();
|
|
|
|
cells.reserve(selectedIndexes.size());
|
|
|
|
for (const QModelIndex &index : selectedIndexes)
|
|
|
|
cells.append(child(logicalIndex(index)));
|
|
|
|
return cells;
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
QList<int> AccessibleInstanceView::selectedColumns() const
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
if (!view()->selectionModel()) {
|
|
|
|
return QList<int>();
|
|
|
|
}
|
|
|
|
|
|
|
|
const QModelIndexList selectedColumns = view()->selectionModel()->selectedColumns();
|
|
|
|
|
|
|
|
QList<int> columns;
|
|
|
|
columns.reserve(selectedColumns.size());
|
|
|
|
for (const QModelIndex &index : selectedColumns) {
|
|
|
|
columns.append(index.column());
|
|
|
|
}
|
|
|
|
|
|
|
|
return columns;
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
QList<int> AccessibleInstanceView::selectedRows() const
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
if (!view()->selectionModel()) {
|
|
|
|
return QList<int>();
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<int> rows;
|
|
|
|
|
|
|
|
const QModelIndexList selectedRows = view()->selectionModel()->selectedRows();
|
|
|
|
|
|
|
|
rows.reserve(selectedRows.size());
|
|
|
|
for (const QModelIndex &index : selectedRows) {
|
|
|
|
rows.append(index.row());
|
|
|
|
}
|
|
|
|
|
|
|
|
return rows;
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
QAccessibleInterface *AccessibleInstanceView::summary() const
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
bool AccessibleInstanceView::isColumnSelected(int column) const
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
if (!view()->selectionModel()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return view()->selectionModel()->isColumnSelected(column, QModelIndex());
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
bool AccessibleInstanceView::isRowSelected(int row) const
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
if (!view()->selectionModel()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return view()->selectionModel()->isRowSelected(row, QModelIndex());
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
bool AccessibleInstanceView::selectRow(int row)
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
if (!view()->model() || !view()->selectionModel()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
QModelIndex index = view()->model()->index(row, 0, view()->rootIndex());
|
|
|
|
|
|
|
|
if (!index.isValid() || view()->selectionBehavior() == QAbstractItemView::SelectColumns) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (view()->selectionMode()) {
|
|
|
|
case QAbstractItemView::NoSelection: {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
case QAbstractItemView::SingleSelection: {
|
|
|
|
if (view()->selectionBehavior() != QAbstractItemView::SelectRows && columnCount() > 1 )
|
|
|
|
return false;
|
|
|
|
view()->clearSelection();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case QAbstractItemView::ContiguousSelection: {
|
|
|
|
if ((!row || !view()->selectionModel()->isRowSelected(row - 1, view()->rootIndex())) && !view()->selectionModel()->isRowSelected(row + 1, view()->rootIndex())) {
|
|
|
|
view()->clearSelection();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
view()->selectionModel()->select(index, QItemSelectionModel::Select | QItemSelectionModel::Rows);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
bool AccessibleInstanceView::selectColumn(int column)
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
if (!view()->model() || !view()->selectionModel()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
QModelIndex index = view()->model()->index(0, column, view()->rootIndex());
|
|
|
|
|
|
|
|
if (!index.isValid() || view()->selectionBehavior() == QAbstractItemView::SelectRows) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (view()->selectionMode()) {
|
|
|
|
case QAbstractItemView::NoSelection: {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
case QAbstractItemView::SingleSelection: {
|
|
|
|
if (view()->selectionBehavior() != QAbstractItemView::SelectColumns && rowCount() > 1) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-07-22 05:14:19 +05:30
|
|
|
// fallthrough intentional
|
2019-07-22 00:42:05 +05:30
|
|
|
}
|
|
|
|
case QAbstractItemView::ContiguousSelection: {
|
|
|
|
if ((!column || !view()->selectionModel()->isColumnSelected(column - 1, view()->rootIndex())) && !view()->selectionModel()->isColumnSelected(column + 1, view()->rootIndex())) {
|
|
|
|
view()->clearSelection();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
view()->selectionModel()->select(index, QItemSelectionModel::Select | QItemSelectionModel::Columns);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
bool AccessibleInstanceView::unselectRow(int row)
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
if (!view()->model() || !view()->selectionModel()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QModelIndex index = view()->model()->index(row, 0, view()->rootIndex());
|
|
|
|
if (!index.isValid()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QItemSelection selection(index, index);
|
|
|
|
auto selectionModel = view()->selectionModel();
|
|
|
|
|
|
|
|
switch (view()->selectionMode()) {
|
|
|
|
case QAbstractItemView::SingleSelection:
|
|
|
|
// no unselect
|
|
|
|
if (selectedRowCount() == 1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case QAbstractItemView::ContiguousSelection: {
|
|
|
|
// no unselect
|
|
|
|
if (selectedRowCount() == 1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ((!row || selectionModel->isRowSelected(row - 1, view()->rootIndex())) && selectionModel->isRowSelected(row + 1, view()->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()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
selectionModel->select(selection, QItemSelectionModel::Deselect | QItemSelectionModel::Rows);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
bool AccessibleInstanceView::unselectColumn(int column)
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
auto model = view()->model();
|
|
|
|
if (!model || !view()->selectionModel()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QModelIndex index = model->index(0, column, view()->rootIndex());
|
|
|
|
if (!index.isValid()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QItemSelection selection(index, index);
|
|
|
|
|
|
|
|
switch (view()->selectionMode()) {
|
|
|
|
case QAbstractItemView::SingleSelection: {
|
|
|
|
//In SingleSelection and ContiguousSelection once an item
|
|
|
|
//is selected, there's no way for the user to unselect all items
|
|
|
|
if (selectedColumnCount() == 1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case QAbstractItemView::ContiguousSelection:
|
|
|
|
if (selectedColumnCount() == 1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((!column || view()->selectionModel()->isColumnSelected(column - 1, view()->rootIndex()))
|
|
|
|
&& view()->selectionModel()->isColumnSelected(column + 1, view()->rootIndex())) {
|
|
|
|
//If there are columns selected both at the left of the current row and at the right
|
|
|
|
//of the current row, the ones which are at the right will be deselected
|
|
|
|
selection = QItemSelection(index, model->index(0, columnCount() - 1, view()->rootIndex()));
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
view()->selectionModel()->select(selection, QItemSelectionModel::Deselect | QItemSelectionModel::Columns);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
QAccessible::Role AccessibleInstanceView::role() const
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
return QAccessible::List;
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
QAccessible::State AccessibleInstanceView::state() const
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
return QAccessible::State();
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
QAccessibleInterface *AccessibleInstanceView::childAt(int x, int y) const
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
QPoint viewportOffset = view()->viewport()->mapTo(view(), QPoint(0,0));
|
|
|
|
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()) {
|
|
|
|
return child(logicalIndex(index));
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
int AccessibleInstanceView::childCount() const
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
if (!view()->model()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return (view()->model()->rowCount()) * (view()->model()->columnCount());
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
int AccessibleInstanceView::indexOfChild(const QAccessibleInterface *iface) const
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
if (!view()->model())
|
|
|
|
return -1;
|
|
|
|
QAccessibleInterface *parent = iface->parent();
|
|
|
|
if (parent->object() != view())
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
Q_ASSERT(iface->role() != QAccessible::TreeItem); // should be handled by tree class
|
|
|
|
if (iface->role() == QAccessible::Cell || iface->role() == QAccessible::ListItem) {
|
2021-10-26 03:21:42 +05:30
|
|
|
const AccessibleInstanceViewItem* cell = static_cast<const AccessibleInstanceViewItem*>(iface);
|
2019-07-22 00:42:05 +05:30
|
|
|
return logicalIndex(cell->m_index);
|
|
|
|
} else if (iface->role() == QAccessible::Pane) {
|
|
|
|
return 0; // corner button
|
|
|
|
} else {
|
2021-10-26 03:21:42 +05:30
|
|
|
qWarning() << "AccessibleInstanceView::indexOfChild has a child with unknown role..." << iface->role() << iface->text(QAccessible::Name);
|
2019-07-22 00:42:05 +05:30
|
|
|
}
|
|
|
|
// FIXME: we are in denial of our children. this should stop.
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
QString AccessibleInstanceView::text(QAccessible::Text t) const
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
if (t == QAccessible::Description)
|
|
|
|
return view()->accessibleDescription();
|
|
|
|
return view()->accessibleName();
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
QRect AccessibleInstanceView::rect() const
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
if (!view()->isVisible())
|
|
|
|
return QRect();
|
|
|
|
QPoint pos = view()->mapToGlobal(QPoint(0, 0));
|
|
|
|
return QRect(pos.x(), pos.y(), view()->width(), view()->height());
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
QAccessibleInterface *AccessibleInstanceView::parent() const
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
if (view() && view()->parent()) {
|
|
|
|
if (qstrcmp("QComboBoxPrivateContainer", view()->parent()->metaObject()->className()) == 0) {
|
|
|
|
return QAccessible::queryAccessibleInterface(view()->parent()->parent());
|
|
|
|
}
|
|
|
|
return QAccessible::queryAccessibleInterface(view()->parent());
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
QAccessibleInterface *AccessibleInstanceView::child(int logicalIndex) const
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
if (!view()->model())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
auto id = childToId.constFind(logicalIndex);
|
|
|
|
if (id != childToId.constEnd())
|
|
|
|
return QAccessible::accessibleInterface(id.value());
|
|
|
|
|
|
|
|
int columns = view()->model()->columnCount();
|
|
|
|
|
|
|
|
int row = logicalIndex / columns;
|
|
|
|
int column = logicalIndex % columns;
|
|
|
|
|
|
|
|
QAccessibleInterface *iface = 0;
|
|
|
|
|
|
|
|
QModelIndex index = view()->model()->index(row, column, view()->rootIndex());
|
|
|
|
if (Q_UNLIKELY(!index.isValid())) {
|
2021-10-26 03:21:42 +05:30
|
|
|
qWarning("AccessibleInstanceView::child: Invalid index at: %d %d", row, column);
|
2019-07-22 00:42:05 +05:30
|
|
|
return 0;
|
|
|
|
}
|
2021-10-26 03:21:42 +05:30
|
|
|
iface = new AccessibleInstanceViewItem(view(), index);
|
2019-07-22 00:42:05 +05:30
|
|
|
|
|
|
|
QAccessible::registerAccessibleInterface(iface);
|
|
|
|
childToId.insert(logicalIndex, QAccessible::uniqueId(iface));
|
|
|
|
return iface;
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
void *AccessibleInstanceView::interface_cast(QAccessible::InterfaceType t)
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
if (t == QAccessible::TableInterface)
|
|
|
|
return static_cast<QAccessibleTableInterface*>(this);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
void AccessibleInstanceView::modelChange(QAccessibleTableModelChangeEvent *event)
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
// if there is no cache yet, we don't update anything
|
|
|
|
if (childToId.isEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (event->modelChangeType()) {
|
|
|
|
case QAccessibleTableModelChangeEvent::ModelReset:
|
2019-07-22 05:14:19 +05:30
|
|
|
for (QAccessible::Id id : childToId)
|
2019-07-22 00:42:05 +05:30
|
|
|
QAccessible::deleteAccessibleInterface(id);
|
|
|
|
childToId.clear();
|
|
|
|
break;
|
|
|
|
|
|
|
|
// rows are inserted: move every row after that
|
|
|
|
case QAccessibleTableModelChangeEvent::RowsInserted:
|
|
|
|
case QAccessibleTableModelChangeEvent::ColumnsInserted: {
|
|
|
|
|
|
|
|
ChildCache newCache;
|
|
|
|
ChildCache::ConstIterator iter = childToId.constBegin();
|
|
|
|
|
|
|
|
while (iter != childToId.constEnd()) {
|
|
|
|
QAccessible::Id id = iter.value();
|
|
|
|
QAccessibleInterface *iface = QAccessible::accessibleInterface(id);
|
|
|
|
Q_ASSERT(iface);
|
|
|
|
if (indexOfChild(iface) >= 0) {
|
|
|
|
newCache.insert(indexOfChild(iface), id);
|
|
|
|
} else {
|
|
|
|
// ### This should really not happen,
|
|
|
|
// but it might if the view has a root index set.
|
|
|
|
// This needs to be fixed.
|
|
|
|
QAccessible::deleteAccessibleInterface(id);
|
|
|
|
}
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
childToId = newCache;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case QAccessibleTableModelChangeEvent::ColumnsRemoved:
|
|
|
|
case QAccessibleTableModelChangeEvent::RowsRemoved: {
|
|
|
|
ChildCache newCache;
|
|
|
|
ChildCache::ConstIterator iter = childToId.constBegin();
|
|
|
|
while (iter != childToId.constEnd()) {
|
|
|
|
QAccessible::Id id = iter.value();
|
|
|
|
QAccessibleInterface *iface = QAccessible::accessibleInterface(id);
|
|
|
|
Q_ASSERT(iface);
|
|
|
|
if (iface->role() == QAccessible::Cell || iface->role() == QAccessible::ListItem) {
|
|
|
|
Q_ASSERT(iface->tableCellInterface());
|
2021-10-26 03:21:42 +05:30
|
|
|
AccessibleInstanceViewItem *cell = static_cast<AccessibleInstanceViewItem*>(iface->tableCellInterface());
|
2019-07-22 00:42:05 +05:30
|
|
|
// Since it is a QPersistentModelIndex, we only need to check if it is valid
|
|
|
|
if (cell->m_index.isValid())
|
|
|
|
newCache.insert(indexOfChild(cell), id);
|
|
|
|
else
|
|
|
|
QAccessible::deleteAccessibleInterface(id);
|
|
|
|
}
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
childToId = newCache;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case QAccessibleTableModelChangeEvent::DataChanged:
|
|
|
|
// nothing to do in this case
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TABLE CELL
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
AccessibleInstanceViewItem::AccessibleInstanceViewItem(QAbstractItemView *view_, const QModelIndex &index_)
|
2019-07-22 00:42:05 +05:30
|
|
|
: view(view_), m_index(index_)
|
|
|
|
{
|
|
|
|
if (Q_UNLIKELY(!index_.isValid()))
|
2021-10-26 03:21:42 +05:30
|
|
|
qWarning() << "AccessibleInstanceViewItem::AccessibleInstanceViewItem with invalid index: " << index_;
|
2019-07-22 00:42:05 +05:30
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
void *AccessibleInstanceViewItem::interface_cast(QAccessible::InterfaceType t)
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
if (t == QAccessible::TableCellInterface)
|
|
|
|
return static_cast<QAccessibleTableCellInterface*>(this);
|
|
|
|
if (t == QAccessible::ActionInterface)
|
|
|
|
return static_cast<QAccessibleActionInterface*>(this);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
int AccessibleInstanceViewItem::columnExtent() const { return 1; }
|
|
|
|
int AccessibleInstanceViewItem::rowExtent() const { return 1; }
|
2019-07-22 00:42:05 +05:30
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
QList<QAccessibleInterface*> AccessibleInstanceViewItem::rowHeaderCells() const
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
QList<QAccessibleInterface*> AccessibleInstanceViewItem::columnHeaderCells() const
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
int AccessibleInstanceViewItem::columnIndex() const
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
if (!isValid()) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_index.column();
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
int AccessibleInstanceViewItem::rowIndex() const
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
if (!isValid()) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_index.row();
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
bool AccessibleInstanceViewItem::isSelected() const
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
if (!isValid()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return view->selectionModel()->isSelected(m_index);
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
QStringList AccessibleInstanceViewItem::actionNames() const
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
QStringList names;
|
|
|
|
names << toggleAction();
|
|
|
|
return names;
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
void AccessibleInstanceViewItem::doAction(const QString& actionName)
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
if (actionName == toggleAction()) {
|
|
|
|
if (isSelected()) {
|
|
|
|
unselectCell();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
selectCell();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
QStringList AccessibleInstanceViewItem::keyBindingsForAction(const QString &) const
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
return QStringList();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
void AccessibleInstanceViewItem::selectCell()
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
if (!isValid()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QAbstractItemView::SelectionMode selectionMode = view->selectionMode();
|
|
|
|
if (selectionMode == QAbstractItemView::NoSelection) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Q_ASSERT(table());
|
|
|
|
QAccessibleTableInterface *cellTable = table()->tableInterface();
|
|
|
|
|
|
|
|
switch (view->selectionBehavior()) {
|
|
|
|
case QAbstractItemView::SelectItems:
|
|
|
|
break;
|
|
|
|
case QAbstractItemView::SelectColumns:
|
|
|
|
if (cellTable)
|
|
|
|
cellTable->selectColumn(m_index.column());
|
|
|
|
return;
|
|
|
|
case QAbstractItemView::SelectRows:
|
|
|
|
if (cellTable)
|
|
|
|
cellTable->selectRow(m_index.row());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selectionMode == QAbstractItemView::SingleSelection) {
|
|
|
|
view->clearSelection();
|
|
|
|
}
|
|
|
|
|
|
|
|
view->selectionModel()->select(m_index, QItemSelectionModel::Select);
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
void AccessibleInstanceViewItem::unselectCell()
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
if (!isValid())
|
|
|
|
return;
|
|
|
|
QAbstractItemView::SelectionMode selectionMode = view->selectionMode();
|
|
|
|
if (selectionMode == QAbstractItemView::NoSelection)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QAccessibleTableInterface *cellTable = table()->tableInterface();
|
|
|
|
|
|
|
|
switch (view->selectionBehavior()) {
|
|
|
|
case QAbstractItemView::SelectItems:
|
|
|
|
break;
|
|
|
|
case QAbstractItemView::SelectColumns:
|
|
|
|
if (cellTable)
|
|
|
|
cellTable->unselectColumn(m_index.column());
|
|
|
|
return;
|
|
|
|
case QAbstractItemView::SelectRows:
|
|
|
|
if (cellTable)
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
QAccessibleInterface *AccessibleInstanceViewItem::table() const
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
return QAccessible::queryAccessibleInterface(view);
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
QAccessible::Role AccessibleInstanceViewItem::role() const
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
return QAccessible::ListItem;
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
QAccessible::State AccessibleInstanceViewItem::state() const
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
QAccessible::State st;
|
|
|
|
if (!isValid())
|
|
|
|
return st;
|
|
|
|
|
|
|
|
QRect globalRect = view->rect();
|
|
|
|
globalRect.translate(view->mapToGlobal(QPoint(0,0)));
|
|
|
|
if (!globalRect.intersects(rect()))
|
|
|
|
st.invisible = true;
|
|
|
|
|
|
|
|
if (view->selectionModel()->isSelected(m_index))
|
|
|
|
st.selected = true;
|
|
|
|
if (view->selectionModel()->currentIndex() == m_index)
|
|
|
|
st.focused = true;
|
|
|
|
if (m_index.model()->data(m_index, Qt::CheckStateRole).toInt() == Qt::Checked)
|
|
|
|
st.checked = true;
|
|
|
|
|
|
|
|
Qt::ItemFlags flags = m_index.flags();
|
|
|
|
if (flags & Qt::ItemIsSelectable) {
|
|
|
|
st.selectable = true;
|
|
|
|
st.focusable = true;
|
|
|
|
if (view->selectionMode() == QAbstractItemView::MultiSelection)
|
|
|
|
st.multiSelectable = true;
|
|
|
|
if (view->selectionMode() == QAbstractItemView::ExtendedSelection)
|
|
|
|
st.extSelectable = true;
|
|
|
|
}
|
|
|
|
return st;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
QRect AccessibleInstanceViewItem::rect() const
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
QRect r;
|
|
|
|
if (!isValid())
|
|
|
|
return r;
|
|
|
|
r = view->visualRect(m_index);
|
|
|
|
|
|
|
|
if (!r.isNull()) {
|
|
|
|
r.translate(view->viewport()->mapTo(view, QPoint(0,0)));
|
|
|
|
r.translate(view->mapToGlobal(QPoint(0, 0)));
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
QString AccessibleInstanceViewItem::text(QAccessible::Text t) const
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
QString value;
|
|
|
|
if (!isValid())
|
|
|
|
return value;
|
|
|
|
QAbstractItemModel *model = view->model();
|
|
|
|
switch (t) {
|
|
|
|
case QAccessible::Name:
|
|
|
|
value = model->data(m_index, Qt::AccessibleTextRole).toString();
|
|
|
|
if (value.isEmpty())
|
|
|
|
value = model->data(m_index, Qt::DisplayRole).toString();
|
|
|
|
break;
|
|
|
|
case QAccessible::Description:
|
|
|
|
value = model->data(m_index, Qt::AccessibleDescriptionRole).toString();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
void AccessibleInstanceViewItem::setText(QAccessible::Text /*t*/, const QString &text)
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
if (!isValid() || !(m_index.flags() & Qt::ItemIsEditable))
|
|
|
|
return;
|
|
|
|
view->model()->setData(m_index, text);
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
bool AccessibleInstanceViewItem::isValid() const
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
return view && view->model() && m_index.isValid();
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
QAccessibleInterface *AccessibleInstanceViewItem::parent() const
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
return QAccessible::queryAccessibleInterface(view);
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:21:42 +05:30
|
|
|
QAccessibleInterface *AccessibleInstanceViewItem::child(int) const
|
2019-07-22 00:42:05 +05:30
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2019-10-01 17:58:06 +05:30
|
|
|
|
|
|
|
#endif /* !QT_NO_ACCESSIBILITY */
|