summaryrefslogtreecommitdiffstats
path: root/src/widgets/accessible
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/accessible')
-rw-r--r--src/widgets/accessible/complexwidgets.cpp209
-rw-r--r--src/widgets/accessible/complexwidgets_p.h21
-rw-r--r--src/widgets/accessible/itemviews.cpp351
-rw-r--r--src/widgets/accessible/itemviews_p.h17
-rw-r--r--src/widgets/accessible/qaccessiblemenu.cpp10
-rw-r--r--src/widgets/accessible/qaccessiblemenu_p.h4
-rw-r--r--src/widgets/accessible/qaccessiblewidget.cpp35
-rw-r--r--src/widgets/accessible/qaccessiblewidget.h4
-rw-r--r--src/widgets/accessible/qaccessiblewidgetfactory.cpp9
-rw-r--r--src/widgets/accessible/qaccessiblewidgets.cpp34
-rw-r--r--src/widgets/accessible/qaccessiblewidgets_p.h5
-rw-r--r--src/widgets/accessible/rangecontrols.cpp4
-rw-r--r--src/widgets/accessible/rangecontrols_p.h4
-rw-r--r--src/widgets/accessible/simplewidgets.cpp74
-rw-r--r--src/widgets/accessible/simplewidgets_p.h17
15 files changed, 566 insertions, 232 deletions
diff --git a/src/widgets/accessible/complexwidgets.cpp b/src/widgets/accessible/complexwidgets.cpp
index 406d70ae09..77bf8504fa 100644
--- a/src/widgets/accessible/complexwidgets.cpp
+++ b/src/widgets/accessible/complexwidgets.cpp
@@ -36,7 +36,7 @@
#endif
#include <QDebug>
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
QT_BEGIN_NAMESPACE
@@ -78,7 +78,9 @@ public:
}
QAccessible::State s = parent()->state();
+ s.selectable = true;
s.focused = (m_index == m_parent->currentIndex());
+ s.selected = s.focused;
return s;
}
QRect rect() const override {
@@ -177,10 +179,18 @@ QAccessibleTabBar::QAccessibleTabBar(QWidget *w)
QAccessibleTabBar::~QAccessibleTabBar()
{
- for (QAccessible::Id id : qAsConst(m_childInterfaces))
+ for (QAccessible::Id id : std::as_const(m_childInterfaces))
QAccessible::deleteAccessibleInterface(id);
}
+void *QAccessibleTabBar::interface_cast(QAccessible::InterfaceType t)
+{
+ if (t == QAccessible::SelectionInterface) {
+ return static_cast<QAccessibleSelectionInterface*>(this);
+ }
+ return QAccessibleWidget::interface_cast(t);
+}
+
/*! Returns the QTabBar. */
QTabBar *QAccessibleTabBar::tabBar() const
{
@@ -258,6 +268,60 @@ QString QAccessibleTabBar::text(QAccessible::Text t) const
return QString();
}
+int QAccessibleTabBar::selectedItemCount() const
+{
+ if (tabBar()->currentIndex() >= 0)
+ return 1;
+ return 0;
+}
+
+QList<QAccessibleInterface*> QAccessibleTabBar::selectedItems() const
+{
+ QList<QAccessibleInterface*> items;
+ QAccessibleInterface *selected = selectedItem(0);
+ if (selected)
+ items.push_back(selected);
+ return items;
+}
+
+QAccessibleInterface* QAccessibleTabBar::selectedItem(int selectionIndex) const
+{
+ const int currentIndex = tabBar()->currentIndex();
+ if (selectionIndex != 0 || currentIndex < 0)
+ return nullptr;
+ return child(currentIndex);
+}
+
+bool QAccessibleTabBar::isSelected(QAccessibleInterface *childItem) const
+{
+ return childItem && selectedItem(0) == childItem;
+}
+
+bool QAccessibleTabBar::select(QAccessibleInterface *childItem)
+{
+ const int childIndex = indexOfChild(childItem);
+ if (childIndex >= 0) {
+ tabBar()->setCurrentIndex(childIndex);
+ return true;
+ }
+ return false;
+}
+
+bool QAccessibleTabBar::unselect(QAccessibleInterface *)
+{
+ return false;
+}
+
+bool QAccessibleTabBar::selectAll()
+{
+ return false;
+}
+
+bool QAccessibleTabBar::clear()
+{
+ return false;
+}
+
#endif // QT_CONFIG(tabbar)
#if QT_CONFIG(combobox)
@@ -283,17 +347,19 @@ QAccessibleComboBox::QAccessibleComboBox(QWidget *w)
*/
QComboBox *QAccessibleComboBox::comboBox() const
{
- return qobject_cast<QComboBox*>(object());
+ return qobject_cast<QComboBox *>(object());
}
QAccessibleInterface *QAccessibleComboBox::child(int index) const
{
- if (index == 0) {
- QAbstractItemView *view = comboBox()->view();
- //QWidget *parent = view ? view->parentWidget() : 0;
- return QAccessible::queryAccessibleInterface(view);
- } else if (index == 1 && comboBox()->isEditable()) {
- return QAccessible::queryAccessibleInterface(comboBox()->lineEdit());
+ if (QComboBox *cBox = comboBox()) {
+ if (index == 0) {
+ QAbstractItemView *view = cBox->view();
+ //QWidget *parent = view ? view->parentWidget() : 0;
+ return QAccessible::queryAccessibleInterface(view);
+ } else if (index == 1 && cBox->isEditable()) {
+ return QAccessible::queryAccessibleInterface(cBox->lineEdit());
+ }
}
return nullptr;
}
@@ -301,55 +367,86 @@ QAccessibleInterface *QAccessibleComboBox::child(int index) const
int QAccessibleComboBox::childCount() const
{
// list and text edit
- return comboBox()->isEditable() ? 2 : 1;
+ if (QComboBox *cBox = comboBox())
+ return (cBox->isEditable()) ? 2 : 1;
+ return 0;
}
QAccessibleInterface *QAccessibleComboBox::childAt(int x, int y) const
{
- if (comboBox()->isEditable() && comboBox()->lineEdit()->rect().contains(x, y))
- return child(1);
+ if (QComboBox *cBox = comboBox()) {
+ if (cBox->isEditable() && cBox->lineEdit()->rect().contains(x, y))
+ return child(1);
+ }
return nullptr;
}
int QAccessibleComboBox::indexOfChild(const QAccessibleInterface *child) const
{
- if (comboBox()->view() == child->object())
- return 0;
- if (comboBox()->isEditable() && comboBox()->lineEdit() == child->object())
- return 1;
+ if (QComboBox *cBox = comboBox()) {
+ if (cBox->view() == child->object())
+ return 0;
+ if (cBox->isEditable() && cBox->lineEdit() == child->object())
+ return 1;
+ }
return -1;
}
+QAccessibleInterface *QAccessibleComboBox::focusChild() const
+{
+ // The editable combobox is the focus proxy of its lineedit, so the
+ // lineedit itself never gets focus. But it is the accessible focus
+ // child of an editable combobox.
+ if (QComboBox *cBox = comboBox()) {
+ if (cBox->isEditable())
+ return child(1);
+ }
+ return nullptr;
+}
+
/*! \reimp */
QString QAccessibleComboBox::text(QAccessible::Text t) const
{
QString str;
-
- switch (t) {
- case QAccessible::Name:
+ if (QComboBox *cBox = comboBox()) {
+ switch (t) {
+ case QAccessible::Name:
#ifndef Q_OS_UNIX // on Linux we use relations for this, name is text (fall through to Value)
str = QAccessibleWidget::text(t);
break;
#endif
- case QAccessible::Value:
- if (comboBox()->isEditable())
- str = comboBox()->lineEdit()->text();
- else
- str = comboBox()->currentText();
- break;
+ case QAccessible::Value:
+ if (cBox->isEditable())
+ str = cBox->lineEdit()->text();
+ else
+ str = cBox->currentText();
+ break;
#ifndef QT_NO_SHORTCUT
- case QAccessible::Accelerator:
- str = QKeySequence(Qt::Key_Down).toString(QKeySequence::NativeText);
- break;
+ case QAccessible::Accelerator:
+ str = QKeySequence(Qt::Key_Down).toString(QKeySequence::NativeText);
+ break;
#endif
- default:
- break;
+ default:
+ break;
+ }
+ if (str.isEmpty())
+ str = QAccessibleWidget::text(t);
}
- if (str.isEmpty())
- str = QAccessibleWidget::text(t);
return str;
}
+QAccessible::State QAccessibleComboBox::state() const
+{
+ QAccessible::State s = QAccessibleWidget::state();
+
+ if (QComboBox *cBox = comboBox()) {
+ s.expandable = true;
+ s.expanded = isValid() && cBox->view()->isVisible();
+ s.editable = cBox->isEditable();
+ }
+ return s;
+}
+
QStringList QAccessibleComboBox::actionNames() const
{
return QStringList() << showMenuAction() << pressAction();
@@ -364,26 +461,28 @@ QString QAccessibleComboBox::localizedActionDescription(const QString &actionNam
void QAccessibleComboBox::doAction(const QString &actionName)
{
- if (actionName == showMenuAction() || actionName == pressAction()) {
- if (comboBox()->view()->isVisible()) {
+ if (QComboBox *cBox = comboBox()) {
+ if (actionName == showMenuAction() || actionName == pressAction()) {
+ if (cBox->view()->isVisible()) {
#if defined(Q_OS_ANDROID)
- const auto list = child(0)->tableInterface();
- if (list && list->selectedRowCount() > 0) {
- comboBox()->setCurrentIndex(list->selectedRows().at(0));
- }
- comboBox()->setFocus();
+ const auto list = child(0)->tableInterface();
+ if (list && list->selectedRowCount() > 0) {
+ cBox->setCurrentIndex(list->selectedRows().at(0));
+ }
+ cBox->setFocus();
#endif
- comboBox()->hidePopup();
- } else {
- comboBox()->showPopup();
+ cBox->hidePopup();
+ } else {
+ cBox->showPopup();
#if defined(Q_OS_ANDROID)
- const auto list = child(0)->tableInterface();
- if (list && list->selectedRowCount() > 0) {
- auto selectedCells = list->selectedCells();
- QAccessibleEvent ev(selectedCells.at(0),QAccessible::Focus);
- QAccessible::updateAccessibility(&ev);
- }
+ const auto list = child(0)->tableInterface();
+ if (list && list->selectedRowCount() > 0) {
+ auto selectedCells = list->selectedCells();
+ QAccessibleEvent ev(selectedCells.at(0),QAccessible::Focus);
+ QAccessible::updateAccessibility(&ev);
+ }
#endif
+ }
}
}
}
@@ -410,7 +509,7 @@ QAccessibleInterface *QAccessibleAbstractScrollArea::child(int index) const
int QAccessibleAbstractScrollArea::childCount() const
{
- return accessibleChildren().count();
+ return accessibleChildren().size();
}
int QAccessibleAbstractScrollArea::indexOfChild(const QAccessibleInterface *child) const
@@ -456,13 +555,19 @@ QWidgetList QAccessibleAbstractScrollArea::accessibleChildren() const
// Horizontal scrollBar container.
QScrollBar *horizontalScrollBar = abstractScrollArea()->horizontalScrollBar();
if (horizontalScrollBar && horizontalScrollBar->isVisible()) {
- children.append(horizontalScrollBar->parentWidget());
+ QWidget *scrollBarParent = horizontalScrollBar->parentWidget();
+ // Add container only if scroll bar is in the container
+ if (elementType(scrollBarParent) == HorizontalContainer)
+ children.append(scrollBarParent);
}
// Vertical scrollBar container.
QScrollBar *verticalScrollBar = abstractScrollArea()->verticalScrollBar();
if (verticalScrollBar && verticalScrollBar->isVisible()) {
- children.append(verticalScrollBar->parentWidget());
+ QWidget *scrollBarParent = verticalScrollBar->parentWidget();
+ // Add container only if scroll bar is in the container
+ if (elementType(scrollBarParent) == VerticalContainer)
+ children.append(scrollBarParent);
}
// CornerWidget.
@@ -508,4 +613,4 @@ QAccessibleScrollArea::QAccessibleScrollArea(QWidget *widget)
QT_END_NAMESPACE
-#endif // QT_NO_ACCESSIBILITY
+#endif // QT_CONFIG(accessibility)
diff --git a/src/widgets/accessible/complexwidgets_p.h b/src/widgets/accessible/complexwidgets_p.h
index aa97dbf0a8..5169aa8243 100644
--- a/src/widgets/accessible/complexwidgets_p.h
+++ b/src/widgets/accessible/complexwidgets_p.h
@@ -24,7 +24,7 @@
QT_BEGIN_NAMESPACE
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
class QAbstractButton;
class QHeaderView;
@@ -70,12 +70,14 @@ public:
#endif // QT_CONFIG(scrollarea)
#if QT_CONFIG(tabbar)
-class QAccessibleTabBar : public QAccessibleWidget
+class QAccessibleTabBar : public QAccessibleWidget, public QAccessibleSelectionInterface
{
public:
explicit QAccessibleTabBar(QWidget *w);
~QAccessibleTabBar();
+ void *interface_cast(QAccessible::InterfaceType t) override;
+
QAccessibleInterface *focusChild() const override;
int childCount() const override;
QString text(QAccessible::Text t) const override;
@@ -83,6 +85,16 @@ public:
QAccessibleInterface* child(int index) const override;
int indexOfChild(const QAccessibleInterface *child) const override;
+ // QAccessibleSelectionInterface
+ int selectedItemCount() const override;
+ QList<QAccessibleInterface*> selectedItems() const override;
+ QAccessibleInterface* selectedItem(int selectionIndex) const override;
+ bool isSelected(QAccessibleInterface *childItem) const override;
+ bool select(QAccessibleInterface *childItem) override;
+ bool unselect(QAccessibleInterface *childItem) override;
+ bool selectAll() override;
+ bool clear() override;
+
protected:
QTabBar *tabBar() const;
mutable QHash<int, QAccessible::Id> m_childInterfaces;
@@ -99,9 +111,12 @@ public:
QAccessibleInterface *childAt(int x, int y) const override;
int indexOfChild(const QAccessibleInterface *child) const override;
QAccessibleInterface* child(int index) const override;
+ QAccessibleInterface* focusChild() const override;
QString text(QAccessible::Text t) const override;
+ QAccessible::State state() const override;
+
// QAccessibleActionInterface
QStringList actionNames() const override;
QString localizedActionDescription(const QString &actionName) const override;
@@ -113,7 +128,7 @@ protected:
};
#endif // QT_CONFIG(combobox)
-#endif // QT_NO_ACCESSIBILITY
+#endif // QT_CONFIG(accessibility)
QT_END_NAMESPACE
diff --git a/src/widgets/accessible/itemviews.cpp b/src/widgets/accessible/itemviews.cpp
index df08c3af1e..aa5f729820 100644
--- a/src/widgets/accessible/itemviews.cpp
+++ b/src/widgets/accessible/itemviews.cpp
@@ -16,7 +16,7 @@
#endif
#include <private/qwidget_p.h>
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
QT_BEGIN_NAMESPACE
@@ -39,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)
@@ -79,7 +84,7 @@ bool QAccessibleTable::isValid() const
QAccessibleTable::~QAccessibleTable()
{
- for (QAccessible::Id id : qAsConst(childToId))
+ for (QAccessible::Id id : std::as_const(childToId))
QAccessible::deleteAccessibleInterface(id);
}
@@ -113,12 +118,14 @@ QHeaderView *QAccessibleTable::verticalHeader() const
QAccessibleInterface *QAccessibleTable::cellAt(int row, int column) const
{
- if (!view()->model())
+ 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();
+ qWarning() << "QAccessibleTable::cellAt: invalid index: " << index << " for " << theView;
return nullptr;
}
return child(logicalIndex(index));
@@ -131,51 +138,59 @@ QAccessibleInterface *QAccessibleTable::caption() const
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
@@ -237,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;
@@ -253,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;
@@ -267,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
@@ -316,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;
@@ -352,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;
@@ -373,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
@@ -382,10 +517,9 @@ 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 nullptr;
}
@@ -400,21 +534,27 @@ QAccessibleInterface *QAccessibleTable::focusChild() const
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);
@@ -424,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 {
@@ -458,14 +598,17 @@ QAccessibleInterface *QAccessibleTable::parent() const
}
return QAccessible::queryAccessibleInterface(view()->parent());
}
- return nullptr;
+ return QAccessible::queryAccessibleInterface(qApp);
}
QAccessibleInterface *QAccessibleTable::child(int logicalIndex) const
{
- if (!view()->model())
+ 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());
@@ -473,7 +616,7 @@ 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;
@@ -483,27 +626,27 @@ QAccessibleInterface *QAccessibleTable::child(int logicalIndex) const
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 nullptr;
}
- iface = new QAccessibleTableCell(view(), index, cellRole());
+ iface = new QAccessibleTableCell(theView, index, cellRole());
}
QAccessible::registerAccessibleInterface(iface);
@@ -513,6 +656,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;
@@ -526,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;
@@ -634,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();
}
@@ -648,34 +793,39 @@ QModelIndex QAccessibleTree::indexFromLogical(int row, int column) const
QAccessibleInterface *QAccessibleTree::childAt(int x, int y) const
{
- if (!view()->model())
+ const QAbstractItemView *theView = view();
+ const QAbstractItemModel *theModel = theView->model();
+ if (!theModel)
return nullptr;
- QPoint viewportOffset = view()->viewport()->mapTo(view(), QPoint(0,0));
- QPoint indexPosition = view()->mapFromGlobal(QPoint(x, y) - viewportOffset);
- 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 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
{
- QModelIndex index = view()->currentIndex();
+ 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*>(view());
- int row = treeView->d_func()->viewIndex(index) + (horizontalHeader() ? 1 : 0);
- int column = index.column();
+ 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 * view()->model()->columnCount() + column;
+ int i = row * theModel->columnCount(theView->rootIndex()) + column;
return child(i);
}
@@ -683,33 +833,37 @@ 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())
+ 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 = 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 nullptr;
iface = new QAccessibleTableCell(view(), modelIndex, cellRole());
@@ -723,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())
@@ -736,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);
@@ -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);
@@ -1198,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
@@ -1235,4 +1396,4 @@ QHeaderView *QAccessibleTableHeaderCell::headerView() const
QT_END_NAMESPACE
-#endif // QT_NO_ACCESSIBILITY
+#endif // QT_CONFIG(accessibility)
diff --git a/src/widgets/accessible/itemviews_p.h b/src/widgets/accessible/itemviews_p.h
index de440bbc42..077f14de1d 100644
--- a/src/widgets/accessible/itemviews_p.h
+++ b/src/widgets/accessible/itemviews_p.h
@@ -26,12 +26,12 @@ QT_REQUIRE_CONFIG(itemviews);
QT_BEGIN_NAMESPACE
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
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;
@@ -135,8 +144,6 @@ public:
private:
QModelIndex indexFromLogical(int row, int column = 0) const;
-
- inline int logicalIndex(const QModelIndex &index) const;
};
#endif
@@ -264,7 +271,7 @@ private:
};
-#endif // QT_NO_ACCESSIBILITY
+#endif // QT_CONFIG(accessibility)
QT_END_NAMESPACE
diff --git a/src/widgets/accessible/qaccessiblemenu.cpp b/src/widgets/accessible/qaccessiblemenu.cpp
index 0ce9a281d4..1d72a82456 100644
--- a/src/widgets/accessible/qaccessiblemenu.cpp
+++ b/src/widgets/accessible/qaccessiblemenu.cpp
@@ -12,7 +12,7 @@
#include <qstyle.h>
#include <private/qwidget_p.h>
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
QT_BEGIN_NAMESPACE
@@ -44,7 +44,7 @@ QMenu *QAccessibleMenu::menu() const
int QAccessibleMenu::childCount() const
{
- return menu()->actions().count();
+ return menu()->actions().size();
}
QAccessibleInterface *QAccessibleMenu::childAt(int x, int y) const
@@ -85,7 +85,7 @@ QAccessibleInterface *QAccessibleMenu::parent() const
const QList<QObject *> associatedObjects = menuAction->associatedObjects();
parentCandidates.reserve(associatedObjects.size() + 1);
parentCandidates << menu()->parentWidget() << associatedObjects;
- for (QObject *object : qAsConst(parentCandidates)) {
+ for (QObject *object : std::as_const(parentCandidates)) {
if (qobject_cast<QMenu*>(object)
#if QT_CONFIG(menubar)
|| qobject_cast<QMenuBar*>(object)
@@ -123,7 +123,7 @@ QMenuBar *QAccessibleMenuBar::menuBar() const
int QAccessibleMenuBar::childCount() const
{
- return menuBar()->actions().count();
+ return menuBar()->actions().size();
}
QAccessibleInterface *QAccessibleMenuBar::child(int index) const
@@ -357,5 +357,5 @@ QWidget *QAccessibleMenuItem::owner() const
QT_END_NAMESPACE
-#endif // QT_NO_ACCESSIBILITY
+#endif // QT_CONFIG(accessibility)
diff --git a/src/widgets/accessible/qaccessiblemenu_p.h b/src/widgets/accessible/qaccessiblemenu_p.h
index cd4c3819b3..8eb9a37e2d 100644
--- a/src/widgets/accessible/qaccessiblemenu_p.h
+++ b/src/widgets/accessible/qaccessiblemenu_p.h
@@ -21,7 +21,7 @@
QT_BEGIN_NAMESPACE
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
#if QT_CONFIG(menu)
class QMenu;
@@ -103,5 +103,5 @@ private:
#endif // QT_CONFIG(menu)
QT_END_NAMESPACE
-#endif // QT_NO_ACCESSIBILITY
+#endif // QT_CONFIG(accessibility)
#endif // QACCESSIBLEMENU_H
diff --git a/src/widgets/accessible/qaccessiblewidget.cpp b/src/widgets/accessible/qaccessiblewidget.cpp
index 88d053965b..b0bb12ea86 100644
--- a/src/widgets/accessible/qaccessiblewidget.cpp
+++ b/src/widgets/accessible/qaccessiblewidget.cpp
@@ -3,7 +3,7 @@
#include "qaccessiblewidget.h"
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
#include "qapplication.h"
#if QT_CONFIG(groupbox)
@@ -34,22 +34,7 @@ QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
-static QList<QWidget*> childWidgets(const QWidget *widget)
-{
- QList<QWidget*> widgets;
- for (QObject *o : widget->children()) {
- QWidget *w = qobject_cast<QWidget *>(o);
- if (w && !w->isWindow()
- && !qobject_cast<QFocusFrame*>(w)
-#if QT_CONFIG(menu)
- && !qobject_cast<QMenu*>(w)
-#endif
- && w->objectName() != "qt_rubberband"_L1
- && w->objectName() != "qt_spinbox_lineedit"_L1)
- widgets.append(w);
- }
- return widgets;
-}
+QWidgetList _q_ac_childWidgets(const QWidget *widget);
static QString buddyString(const QWidget *widget)
{
@@ -87,7 +72,7 @@ static qsizetype qt_accAmpIndex(const QString &text)
qsizetype fa = 0;
while ((fa = text.indexOf(u'&', fa)) != -1) {
++fa;
- if (fa < text.length()) {
+ if (fa < text.size()) {
// ignore "&&"
if (text.at(fa) == u'&') {
@@ -276,7 +261,7 @@ QAccessibleWidget::relations(QAccessible::Relation match /*= QAccessible::AllRel
// first check for all siblings that are labels to us
// ideally we would go through all objects and check, but that
// will be too expensive
- const QList<QWidget*> kids = childWidgets(parent);
+ const QList<QWidget*> kids = _q_ac_childWidgets(parent);
for (QWidget *kid : kids) {
if (QLabel *labelSibling = qobject_cast<QLabel*>(kid)) {
if (labelSibling->buddy() == widget()) {
@@ -299,14 +284,14 @@ QAccessibleWidget::relations(QAccessible::Relation match /*= QAccessible::AllRel
if (match & QAccessible::Controlled) {
QObjectList allReceivers;
QObject *connectionObject = object();
- for (int sig = 0; sig < d->primarySignals.count(); ++sig) {
+ for (int sig = 0; sig < d->primarySignals.size(); ++sig) {
const QObjectList receivers = connectionObject->d_func()->receiverList(d->primarySignals.at(sig).toLatin1());
allReceivers += receivers;
}
allReceivers.removeAll(object()); //### The object might connect to itself internally
- for (int i = 0; i < allReceivers.count(); ++i) {
+ for (int i = 0; i < allReceivers.size(); ++i) {
const QAccessible::Relation rel = QAccessible::Controlled;
QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(allReceivers.at(i));
if (iface)
@@ -327,7 +312,7 @@ QAccessibleInterface *QAccessibleWidget::parent() const
QAccessibleInterface *QAccessibleWidget::child(int index) const
{
Q_ASSERT(widget());
- QWidgetList childList = childWidgets(widget());
+ QWidgetList childList = _q_ac_childWidgets(widget());
if (index >= 0 && index < childList.size())
return QAccessible::queryAccessibleInterface(childList.at(index));
return nullptr;
@@ -355,7 +340,7 @@ QAccessibleInterface *QAccessibleWidget::focusChild() const
/*! \reimp */
int QAccessibleWidget::childCount() const
{
- QWidgetList cl = childWidgets(widget());
+ QWidgetList cl = _q_ac_childWidgets(widget());
return cl.size();
}
@@ -364,7 +349,7 @@ int QAccessibleWidget::indexOfChild(const QAccessibleInterface *child) const
{
if (!child)
return -1;
- QWidgetList cl = childWidgets(widget());
+ QWidgetList cl = _q_ac_childWidgets(widget());
return cl.indexOf(qobject_cast<QWidget *>(child->object()));
}
@@ -498,4 +483,4 @@ void *QAccessibleWidget::interface_cast(QAccessible::InterfaceType t)
QT_END_NAMESPACE
-#endif //QT_NO_ACCESSIBILITY
+#endif // QT_CONFIG(accessibility)
diff --git a/src/widgets/accessible/qaccessiblewidget.h b/src/widgets/accessible/qaccessiblewidget.h
index bba4f54e58..c237e25d4a 100644
--- a/src/widgets/accessible/qaccessiblewidget.h
+++ b/src/widgets/accessible/qaccessiblewidget.h
@@ -10,7 +10,7 @@
QT_BEGIN_NAMESPACE
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
class QAccessibleWidgetPrivate;
@@ -58,7 +58,7 @@ private:
};
-#endif // QT_NO_ACCESSIBILITY
+#endif // QT_CONFIG(accessibility)
QT_END_NAMESPACE
diff --git a/src/widgets/accessible/qaccessiblewidgetfactory.cpp b/src/widgets/accessible/qaccessiblewidgetfactory.cpp
index e1ec02f750..664e35a6e7 100644
--- a/src/widgets/accessible/qaccessiblewidgetfactory.cpp
+++ b/src/widgets/accessible/qaccessiblewidgetfactory.cpp
@@ -20,7 +20,7 @@
#include <qvariant.h>
#include <qaccessible.h>
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
QT_BEGIN_NAMESPACE
@@ -84,8 +84,10 @@ QAccessibleInterface *qAccessibleFactory(const QString &classname, QObject *obje
#endif
} else if (classname == "QDialog"_L1) {
iface = new QAccessibleWidget(widget, QAccessible::Dialog);
+#if QT_CONFIG(messagebox)
} else if (classname == "QMessageBox"_L1) {
- iface = new QAccessibleWidget(widget, QAccessible::AlertMessage);
+ iface = new QAccessibleMessageBox(widget);
+#endif
#if QT_CONFIG(mainwindow)
} else if (classname == "QMainWindow"_L1) {
iface = new QAccessibleMainWindow(widget);
@@ -119,7 +121,6 @@ QAccessibleInterface *qAccessibleFactory(const QString &classname, QObject *obje
#if QT_CONFIG(itemviews)
} else if (classname == "QTableView"_L1 || classname == "QListView"_L1) {
iface = new QAccessibleTable(widget);
- // ### This should be cleaned up. We return the parent for the scrollarea to hide it.
#endif // QT_CONFIG(itemviews)
#if QT_CONFIG(tabbar)
} else if (classname == "QTabBar"_L1) {
@@ -199,4 +200,4 @@ QAccessibleInterface *qAccessibleFactory(const QString &classname, QObject *obje
QT_END_NAMESPACE
-#endif // QT_NO_ACCESSIBILITY
+#endif // QT_CONFIG(accessibility)
diff --git a/src/widgets/accessible/qaccessiblewidgets.cpp b/src/widgets/accessible/qaccessiblewidgets.cpp
index 7ba42989c2..5c2a3bd02b 100644
--- a/src/widgets/accessible/qaccessiblewidgets.cpp
+++ b/src/widgets/accessible/qaccessiblewidgets.cpp
@@ -56,7 +56,7 @@
#include <QMenu>
#endif
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
QT_BEGIN_NAMESPACE
@@ -65,7 +65,7 @@ using namespace Qt::StringLiterals;
QString qt_accStripAmp(const QString &text);
QString qt_accHotKey(const QString &text);
-QList<QWidget*> childWidgets(const QWidget *widget)
+QWidgetList _q_ac_childWidgets(const QWidget *widget)
{
QList<QWidget*> widgets;
if (!widget)
@@ -80,8 +80,10 @@ QList<QWidget*> childWidgets(const QWidget *widget)
#if QT_CONFIG(menu)
&& !qobject_cast<QMenu*>(w)
#endif
+ // Exclude widgets used as implementation details
&& objectName != "qt_rubberband"_L1
- && objectName != "qt_qmainwindow_extended_splitter"_L1) {
+ && objectName != "qt_qmainwindow_extended_splitter"_L1
+ && objectName != "qt_spinbox_lineedit"_L1) {
widgets.append(w);
}
}
@@ -93,7 +95,7 @@ QList<QWidget*> childWidgets(const QWidget *widget)
QAccessiblePlainTextEdit::QAccessiblePlainTextEdit(QWidget* o)
:QAccessibleTextWidget(o)
{
- Q_ASSERT(widget()->inherits("QPlainTextEdit"));
+ Q_ASSERT(qobject_cast<QPlainTextEdit *>(widget()));
}
QPlainTextEdit* QAccessiblePlainTextEdit::plainTextEdit() const
@@ -190,7 +192,7 @@ void QAccessiblePlainTextEdit::scrollToSubstring(int startIndex, int endIndex)
QAccessibleTextEdit::QAccessibleTextEdit(QWidget *o)
: QAccessibleTextWidget(o, QAccessible::EditableText)
{
- Q_ASSERT(widget()->inherits("QTextEdit"));
+ Q_ASSERT(qobject_cast<QTextEdit *>(widget()));
}
/*! Returns the text edit. */
@@ -359,7 +361,7 @@ QAccessibleMdiArea::QAccessibleMdiArea(QWidget *widget)
int QAccessibleMdiArea::childCount() const
{
- return mdiArea()->subWindowList().count();
+ return mdiArea()->subWindowList().size();
}
QAccessibleInterface *QAccessibleMdiArea::child(int index) const
@@ -398,7 +400,7 @@ QString QAccessibleMdiSubWindow::text(QAccessible::Text textType) const
{
if (textType == QAccessible::Name) {
QString title = mdiSubWindow()->windowTitle();
- title.replace("[*]"_L1, ""_L1);
+ title.remove("[*]"_L1);
return title;
}
return QAccessibleWidget::text(textType);
@@ -837,6 +839,8 @@ QString QAccessibleTextWidget::attributes(int offset, int *startOffset, int *end
QFont::Style style = charFormatFont.style();
attrs["font-style"] = QString::fromLatin1((style == QFont::StyleItalic) ? "italic" : ((style == QFont::StyleOblique) ? "oblique": "normal"));
+ attrs["text-line-through-type"] = charFormatFont.strikeOut() ? "single"_L1 : "none"_L1;
+
QTextCharFormat::UnderlineStyle underlineStyle = charFormat.underlineStyle();
if (underlineStyle == QTextCharFormat::NoUnderline && charFormatFont.underline()) // underline could still be set in the default font
underlineStyle = QTextCharFormat::SingleUnderline;
@@ -866,7 +870,7 @@ QString QAccessibleTextWidget::attributes(int offset, int *startOffset, int *end
underlineStyleValue = QStringLiteral("wave"); // this is not correct, but provides good approximation at least
break;
default:
- qWarning() << "Unknown QTextCharFormat::​UnderlineStyle value " << underlineStyle << " could not be translated to IAccessible2 value";
+ qWarning() << "Unknown QTextCharFormat::UnderlineStyle value " << underlineStyle << " could not be translated to IAccessible2 value";
break;
}
if (!underlineStyleValue.isNull()) {
@@ -1071,8 +1075,8 @@ QAccessibleMainWindow::QAccessibleMainWindow(QWidget *widget)
QAccessibleInterface *QAccessibleMainWindow::child(int index) const
{
- QList<QWidget*> kids = childWidgets(mainWindow());
- if (index >= 0 && index < kids.count()) {
+ QList<QWidget*> kids = _q_ac_childWidgets(mainWindow());
+ if (index >= 0 && index < kids.size()) {
return QAccessible::queryAccessibleInterface(kids.at(index));
}
return nullptr;
@@ -1080,13 +1084,13 @@ QAccessibleInterface *QAccessibleMainWindow::child(int index) const
int QAccessibleMainWindow::childCount() const
{
- QList<QWidget*> kids = childWidgets(mainWindow());
- return kids.count();
+ QList<QWidget*> kids = _q_ac_childWidgets(mainWindow());
+ return kids.size();
}
int QAccessibleMainWindow::indexOfChild(const QAccessibleInterface *iface) const
{
- QList<QWidget*> kids = childWidgets(mainWindow());
+ QList<QWidget*> kids = _q_ac_childWidgets(mainWindow());
return kids.indexOf(static_cast<QWidget*>(iface->object()));
}
@@ -1099,7 +1103,7 @@ QAccessibleInterface *QAccessibleMainWindow::childAt(int x, int y) const
if (!QRect(gp.x(), gp.y(), w->width(), w->height()).contains(x, y))
return nullptr;
- const QWidgetList kids = childWidgets(mainWindow());
+ const QWidgetList kids = _q_ac_childWidgets(mainWindow());
QPoint rp = mainWindow()->mapFromGlobal(QPoint(x, y));
for (QWidget *child : kids) {
if (!child->isWindow() && !child->isHidden() && child->geometry().contains(rp)) {
@@ -1118,4 +1122,4 @@ QMainWindow *QAccessibleMainWindow::mainWindow() const
QT_END_NAMESPACE
-#endif // QT_NO_ACCESSIBILITY
+#endif // QT_CONFIG(accessibility)
diff --git a/src/widgets/accessible/qaccessiblewidgets_p.h b/src/widgets/accessible/qaccessiblewidgets_p.h
index 9d4ee4ea62..6d06f294e8 100644
--- a/src/widgets/accessible/qaccessiblewidgets_p.h
+++ b/src/widgets/accessible/qaccessiblewidgets_p.h
@@ -18,10 +18,9 @@
#include <QtWidgets/private/qtwidgetsglobal_p.h>
#include <QtWidgets/qaccessiblewidget.h>
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
#include <QtCore/QPointer>
-#include <QtCore/QPair>
QT_BEGIN_NAMESPACE
@@ -283,7 +282,7 @@ public:
};
#endif // QT_CONFIG(mainwindow)
-#endif // QT_NO_ACCESSIBILITY
+#endif // QT_CONFIG(accessibility)
QT_END_NAMESPACE
diff --git a/src/widgets/accessible/rangecontrols.cpp b/src/widgets/accessible/rangecontrols.cpp
index 51c9bb9448..b172c10044 100644
--- a/src/widgets/accessible/rangecontrols.cpp
+++ b/src/widgets/accessible/rangecontrols.cpp
@@ -31,7 +31,7 @@ QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
#if QT_CONFIG(spinbox)
QAccessibleAbstractSpinBox::QAccessibleAbstractSpinBox(QWidget *w)
@@ -393,6 +393,6 @@ QDial *QAccessibleDial::dial() const
}
#endif // QT_CONFIG(dial)
-#endif // QT_NO_ACCESSIBILITY
+#endif // QT_CONFIG(accessibility)
QT_END_NAMESPACE
diff --git a/src/widgets/accessible/rangecontrols_p.h b/src/widgets/accessible/rangecontrols_p.h
index 0e7ca5720a..162cbbdb34 100644
--- a/src/widgets/accessible/rangecontrols_p.h
+++ b/src/widgets/accessible/rangecontrols_p.h
@@ -20,7 +20,7 @@
QT_BEGIN_NAMESPACE
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
class QAbstractSpinBox;
class QAbstractSlider;
@@ -163,7 +163,7 @@ protected:
};
#endif // QT_CONFIG(dial)
-#endif // QT_NO_ACCESSIBILITY
+#endif // QT_CONFIG(accessibility)
QT_END_NAMESPACE
diff --git a/src/widgets/accessible/simplewidgets.cpp b/src/widgets/accessible/simplewidgets.cpp
index f60678ce34..fbbbab857d 100644
--- a/src/widgets/accessible/simplewidgets.cpp
+++ b/src/widgets/accessible/simplewidgets.cpp
@@ -43,6 +43,9 @@
#ifndef QT_NO_PICTURE
#include <QtGui/qpicture.h>
#endif
+#if QT_CONFIG(messagebox)
+#include <qmessagebox.h>
+#endif
#include <qstyle.h>
#include <qstyleoption.h>
#include <qtextdocument.h>
@@ -59,9 +62,9 @@ QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
-extern QList<QWidget*> childWidgets(const QWidget *widget);
+QWidgetList _q_ac_childWidgets(const QWidget *widget);
QString qt_accStripAmp(const QString &text);
QString qt_accHotKey(const QString &text);
@@ -213,11 +216,9 @@ QStringList QAccessibleButton::actionNames() const
names << toggleAction();
break;
default:
- if (button()->isCheckable()) {
+ if (button()->isCheckable())
names << toggleAction();
- } else {
- names << pressAction();
- }
+ names << pressAction();
break;
}
}
@@ -400,10 +401,10 @@ QAccessible::Role QAccessibleDisplay::role() const
#if QT_CONFIG(label)
QLabel *l = qobject_cast<QLabel*>(object());
if (l) {
- if (!l->pixmap(Qt::ReturnByValue).isNull())
+ if (!l->pixmap().isNull())
return QAccessible::Graphic;
#ifndef QT_NO_PICTURE
- if (!l->picture(Qt::ReturnByValue).isNull())
+ if (!l->picture().isNull())
return QAccessible::Graphic;
#endif
#if QT_CONFIG(movie)
@@ -528,7 +529,7 @@ QSize QAccessibleDisplay::imageSize() const
#endif
return QSize();
#if QT_CONFIG(label)
- return label->pixmap(Qt::ReturnByValue).size();
+ return label->pixmap().size();
#endif
}
@@ -541,7 +542,7 @@ QPoint QAccessibleDisplay::imagePosition() const
#endif
return QPoint();
#if QT_CONFIG(label)
- if (label->pixmap(Qt::ReturnByValue).isNull())
+ if (label->pixmap().isNull())
return QPoint();
return QPoint(label->mapToGlobal(label->pos()));
@@ -604,7 +605,7 @@ QAccessibleGroupBox::relations(QAccessible::Relation match /* = QAccessible::All
QAccessibleWidget::relations(match);
if ((match & QAccessible::Labelled) && (!groupBox()->title().isEmpty())) {
- const QList<QWidget*> kids = childWidgets(widget());
+ const QList<QWidget*> kids = _q_ac_childWidgets(widget());
for (QWidget *kid : kids) {
QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(kid);
if (iface)
@@ -671,7 +672,7 @@ QString QAccessibleLineEdit::text(QAccessible::Text t) const
if (lineEdit()->echoMode() == QLineEdit::Normal)
str = lineEdit()->text();
else if (lineEdit()->echoMode() != QLineEdit::NoEcho)
- str = QString(lineEdit()->text().length(), QChar::fromLatin1('*'));
+ str = QString(lineEdit()->text().size(), QChar::fromLatin1('*'));
break;
default:
break;
@@ -777,7 +778,7 @@ void QAccessibleLineEdit::selection(int selectionIndex, int *startOffset, int *e
return;
*startOffset = lineEdit()->selectionStart();
- *endOffset = *startOffset + lineEdit()->selectedText().length();
+ *endOffset = *startOffset + lineEdit()->selectedText().size();
}
QString QAccessibleLineEdit::text(int startOffset, int endOffset) const
@@ -850,7 +851,7 @@ void QAccessibleLineEdit::setSelection(int selectionIndex, int startOffset, int
int QAccessibleLineEdit::characterCount() const
{
- return lineEdit()->text().length();
+ return lineEdit()->text().size();
}
void QAccessibleLineEdit::scrollToSubstring(int startIndex, int endIndex)
@@ -951,6 +952,49 @@ QWindowContainer *QAccessibleWindowContainer::container() const
return static_cast<QWindowContainer *>(widget());
}
-#endif // QT_NO_ACCESSIBILITY
+#if QT_CONFIG(messagebox)
+/*!
+ \internal
+ Implements QAccessibleWidget for QMessageBox
+*/
+QAccessibleMessageBox::QAccessibleMessageBox(QWidget *widget)
+ : QAccessibleWidget(widget, QAccessible::AlertMessage)
+{
+ Q_ASSERT(qobject_cast<QMessageBox *>(widget));
+}
+
+QMessageBox *QAccessibleMessageBox::messageBox() const
+{
+ return static_cast<QMessageBox *>(widget());
+}
+
+QString QAccessibleMessageBox::text(QAccessible::Text t) const
+{
+ QString str;
+
+ switch (t) {
+ case QAccessible::Name:
+ str = QAccessibleWidget::text(t);
+ if (str.isEmpty()) // implies no title text is set
+ str = messageBox()->text();
+ break;
+ case QAccessible::Description:
+ str = widget()->accessibleDescription();
+ break;
+ case QAccessible::Value:
+ str = messageBox()->text();
+ break;
+ case QAccessible::Help:
+ str = messageBox()->informativeText();
+ break;
+ default:
+ break;
+ }
+
+ return str;
+}
+#endif
+
+#endif // QT_CONFIG(accessibility)
QT_END_NAMESPACE
diff --git a/src/widgets/accessible/simplewidgets_p.h b/src/widgets/accessible/simplewidgets_p.h
index 3810f47339..c9c03b00d8 100644
--- a/src/widgets/accessible/simplewidgets_p.h
+++ b/src/widgets/accessible/simplewidgets_p.h
@@ -21,12 +21,13 @@
QT_BEGIN_NAMESPACE
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
class QAbstractButton;
class QLineEdit;
class QToolButton;
class QGroupBox;
+class QMessageBox;
class QProgressBar;
#if QT_CONFIG(abstractbutton)
@@ -189,7 +190,19 @@ private:
QWindowContainer *container() const;
};
-#endif // QT_NO_ACCESSIBILITY
+#if QT_CONFIG(messagebox)
+class QAccessibleMessageBox : public QAccessibleWidget
+{
+public:
+ explicit QAccessibleMessageBox(QWidget *widget);
+
+ QString text(QAccessible::Text t) const override;
+
+ QMessageBox *messageBox() const;
+};
+#endif
+
+#endif // QT_CONFIG(accessibility)
QT_END_NAMESPACE