summaryrefslogtreecommitdiffstats
path: root/src/widgets/accessible
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/accessible')
-rw-r--r--src/widgets/accessible/accessible.pri26
-rw-r--r--src/widgets/accessible/complexwidgets.cpp283
-rw-r--r--src/widgets/accessible/complexwidgets_p.h62
-rw-r--r--src/widgets/accessible/itemviews.cpp475
-rw-r--r--src/widgets/accessible/itemviews_p.h59
-rw-r--r--src/widgets/accessible/qaccessiblemenu.cpp84
-rw-r--r--src/widgets/accessible/qaccessiblemenu_p.h44
-rw-r--r--src/widgets/accessible/qaccessiblewidget.cpp120
-rw-r--r--src/widgets/accessible/qaccessiblewidget.h47
-rw-r--r--src/widgets/accessible/qaccessiblewidgetfactory.cpp153
-rw-r--r--src/widgets/accessible/qaccessiblewidgetfactory_p.h45
-rw-r--r--src/widgets/accessible/qaccessiblewidgets.cpp132
-rw-r--r--src/widgets/accessible/qaccessiblewidgets_p.h45
-rw-r--r--src/widgets/accessible/rangecontrols.cpp58
-rw-r--r--src/widgets/accessible/rangecontrols_p.h44
-rw-r--r--src/widgets/accessible/simplewidgets.cpp151
-rw-r--r--src/widgets/accessible/simplewidgets_p.h63
-rw-r--r--src/widgets/accessible/widgets.pro25
18 files changed, 860 insertions, 1056 deletions
diff --git a/src/widgets/accessible/accessible.pri b/src/widgets/accessible/accessible.pri
deleted file mode 100644
index 06467d0ff0..0000000000
--- a/src/widgets/accessible/accessible.pri
+++ /dev/null
@@ -1,26 +0,0 @@
-# Qt accessibility module
-
-qtConfig(accessibility) {
- HEADERS += \
- accessible/qaccessiblewidget.h \
- accessible/qaccessiblewidgetfactory_p.h \
- accessible/complexwidgets_p.h \
- accessible/qaccessiblemenu_p.h \
- accessible/qaccessiblewidgets_p.h \
- accessible/rangecontrols_p.h \
- accessible/simplewidgets_p.h
-
- SOURCES += \
- accessible/qaccessiblewidget.cpp \
- accessible/qaccessiblewidgetfactory.cpp \
- accessible/complexwidgets.cpp \
- accessible/qaccessiblemenu.cpp \
- accessible/qaccessiblewidgets.cpp \
- accessible/rangecontrols.cpp \
- accessible/simplewidgets.cpp
-
- qtConfig(itemviews) {
- HEADERS += accessible/itemviews_p.h
- SOURCES += accessible/itemviews.cpp
- }
-}
diff --git a/src/widgets/accessible/complexwidgets.cpp b/src/widgets/accessible/complexwidgets.cpp
index 63c6fbb9bb..77bf8504fa 100644
--- a/src/widgets/accessible/complexwidgets.cpp
+++ b/src/widgets/accessible/complexwidgets.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 "complexwidgets_p.h"
@@ -57,7 +21,9 @@
#endif
#include <qstyle.h>
#include <qstyleoption.h>
+#if QT_CONFIG(tooltip)
#include <qtooltip.h>
+#endif
#if QT_CONFIG(whatsthis)
#include <qwhatsthis.h>
#endif
@@ -70,10 +36,12 @@
#endif
#include <QDebug>
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
QString qt_accStripAmp(const QString &text);
QString qt_accHotKey(const QString &text);
@@ -97,10 +65,10 @@ public:
if (t == QAccessible::ActionInterface) {
return static_cast<QAccessibleActionInterface*>(this);
}
- return 0;
+ return nullptr;
}
- QObject *object() const override { return 0; }
+ QObject *object() const override { return nullptr; }
QAccessible::Role role() const override { return QAccessible::PageTab; }
QAccessible::State state() const override {
if (!isValid()) {
@@ -108,7 +76,12 @@ public:
s.invalid = true;
return s;
}
- return parent()->state();
+
+ 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 {
if (!isValid())
@@ -129,7 +102,7 @@ public:
return false;
}
- QAccessibleInterface *childAt(int, int) const override { return 0; }
+ QAccessibleInterface *childAt(int, int) const override { return nullptr; }
int childCount() const override { return 0; }
int indexOfChild(const QAccessibleInterface *) const override { return -1; }
@@ -168,7 +141,7 @@ public:
QAccessibleInterface *parent() const override {
return QAccessible::queryAccessibleInterface(m_parent.data());
}
- QAccessibleInterface *child(int) const override { return 0; }
+ QAccessibleInterface *child(int) const override { return nullptr; }
// action interface
QStringList actionNames() const override
@@ -206,16 +179,34 @@ 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
{
return qobject_cast<QTabBar*>(object());
}
+QAccessibleInterface* QAccessibleTabBar::focusChild() const
+{
+ for (int i = 0; i < childCount(); ++i) {
+ if (child(i)->state().focused)
+ return child(i);
+ }
+
+ return nullptr;
+}
+
QAccessibleInterface* QAccessibleTabBar::child(int index) const
{
if (QAccessible::Id id = m_childInterfaces.value(index))
@@ -237,7 +228,7 @@ QAccessibleInterface* QAccessibleTabBar::child(int index) const
return QAccessible::queryAccessibleInterface(tabBar()->d_func()->rightB);
}
}
- return 0;
+ return nullptr;
}
int QAccessibleTabBar::indexOfChild(const QAccessibleInterface *child) const
@@ -277,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)
@@ -302,73 +347,106 @@ 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 0;
+ return nullptr;
}
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);
- return 0;
+ 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();
@@ -383,11 +461,28 @@ QString QAccessibleComboBox::localizedActionDescription(const QString &actionNam
void QAccessibleComboBox::doAction(const QString &actionName)
{
- if (actionName == showMenuAction() || actionName == pressAction()) {
- if (comboBox()->view()->isVisible()) {
- comboBox()->hidePopup();
- } else {
- comboBox()->showPopup();
+ 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) {
+ cBox->setCurrentIndex(list->selectedRows().at(0));
+ }
+ cBox->setFocus();
+#endif
+ 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);
+ }
+#endif
+ }
}
}
}
@@ -414,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
@@ -432,7 +527,7 @@ bool QAccessibleAbstractScrollArea::isValid() const
QAccessibleInterface *QAccessibleAbstractScrollArea::childAt(int x, int y) const
{
if (!abstractScrollArea()->isVisible())
- return 0;
+ return nullptr;
for (int i = 0; i < childCount(); ++i) {
QPoint wpos = accessibleChildren().at(i)->mapToGlobal(QPoint(0, 0));
@@ -440,7 +535,7 @@ QAccessibleInterface *QAccessibleAbstractScrollArea::childAt(int x, int y) const
if (rect.contains(x, y))
return child(i);
}
- return 0;
+ return nullptr;
}
QAbstractScrollArea *QAccessibleAbstractScrollArea::abstractScrollArea() const
@@ -460,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.
@@ -487,9 +588,9 @@ QAccessibleAbstractScrollArea::elementType(QWidget *widget) const
return Self;
if (widget == abstractScrollArea()->viewport())
return Viewport;
- if (widget->objectName() == QLatin1String("qt_scrollarea_hcontainer"))
+ if (widget->objectName() == "qt_scrollarea_hcontainer"_L1)
return HorizontalContainer;
- if (widget->objectName() == QLatin1String("qt_scrollarea_vcontainer"))
+ if (widget->objectName() == "qt_scrollarea_vcontainer"_L1)
return VerticalContainer;
if (widget == abstractScrollArea()->cornerWidget())
return CornerWidget;
@@ -512,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 e7a32c7264..5169aa8243 100644
--- a/src/widgets/accessible/complexwidgets_p.h
+++ b/src/widgets/accessible/complexwidgets_p.h
@@ -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
#ifndef COMPLEXWIDGETS_H
#define COMPLEXWIDGETS_H
@@ -60,7 +24,7 @@
QT_BEGIN_NAMESPACE
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
class QAbstractButton;
class QHeaderView;
@@ -106,18 +70,31 @@ 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;
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;
@@ -134,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;
@@ -148,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 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)
diff --git a/src/widgets/accessible/itemviews_p.h b/src/widgets/accessible/itemviews_p.h
index 683ae9c948..077f14de1d 100644
--- a/src/widgets/accessible/itemviews_p.h
+++ b/src/widgets/accessible/itemviews_p.h
@@ -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
#ifndef ACCESSIBLE_ITEMVIEWS_H
#define ACCESSIBLE_ITEMVIEWS_H
@@ -62,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);
@@ -79,6 +43,7 @@ public:
QRect rect() const override;
QAccessibleInterface *childAt(int x, int y) const override;
+ QAccessibleInterface *focusChild() const override;
int childCount() const override;
int indexOfChild(const QAccessibleInterface *) const override;
@@ -110,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;
@@ -154,6 +128,7 @@ public:
QAccessibleInterface *childAt(int x, int y) const override;
+ QAccessibleInterface *focusChild() const override;
int childCount() const override;
QAccessibleInterface *child(int index) const override;
@@ -169,8 +144,6 @@ public:
private:
QModelIndex indexFromLogical(int row, int column = 0) const;
-
- inline int logicalIndex(const QModelIndex &index) const;
};
#endif
@@ -298,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 7f87288520..1d72a82456 100644
--- a/src/widgets/accessible/qaccessiblemenu.cpp
+++ b/src/widgets/accessible/qaccessiblemenu.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 "qaccessiblemenu_p.h"
@@ -45,11 +9,10 @@
#if QT_CONFIG(menubar)
#include <qmenubar.h>
#endif
-#include <QtWidgets/QAction>
#include <qstyle.h>
#include <private/qwidget_p.h>
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
QT_BEGIN_NAMESPACE
@@ -81,15 +44,15 @@ QMenu *QAccessibleMenu::menu() const
int QAccessibleMenu::childCount() const
{
- return menu()->actions().count();
+ return menu()->actions().size();
}
QAccessibleInterface *QAccessibleMenu::childAt(int x, int y) const
{
QAction *act = menu()->actionAt(menu()->mapFromGlobal(QPoint(x,y)));
- if(act && act->isSeparator())
- act = 0;
- return act ? getOrCreateMenu(menu(), act) : 0;
+ if (act && act->isSeparator())
+ act = nullptr;
+ return act ? getOrCreateMenu(menu(), act) : nullptr;
}
QString QAccessibleMenu::text(QAccessible::Text t) const
@@ -112,22 +75,25 @@ QAccessibleInterface *QAccessibleMenu::child(int index) const
{
if (index < childCount())
return getOrCreateMenu(menu(), menu()->actions().at(index));
- return 0;
+ return nullptr;
}
QAccessibleInterface *QAccessibleMenu::parent() const
{
if (QAction *menuAction = menu()->menuAction()) {
- const QList<QWidget*> parentCandidates =
- QList<QWidget*>() << menu()->parentWidget() << menuAction->associatedWidgets();
- for (QWidget *w : parentCandidates) {
- if (qobject_cast<QMenu*>(w)
+ QList<QObject *> parentCandidates;
+ const QList<QObject *> associatedObjects = menuAction->associatedObjects();
+ parentCandidates.reserve(associatedObjects.size() + 1);
+ parentCandidates << menu()->parentWidget() << associatedObjects;
+ for (QObject *object : std::as_const(parentCandidates)) {
+ if (qobject_cast<QMenu*>(object)
#if QT_CONFIG(menubar)
- || qobject_cast<QMenuBar*>(w)
+ || qobject_cast<QMenuBar*>(object)
#endif
) {
- if (w->actions().indexOf(menuAction) != -1)
- return getOrCreateMenu(w, menuAction);
+ QWidget *widget = static_cast<QWidget*>(object);
+ if (widget->actions().indexOf(menuAction) != -1)
+ return getOrCreateMenu(widget, menuAction);
}
}
}
@@ -157,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
@@ -165,7 +131,7 @@ QAccessibleInterface *QAccessibleMenuBar::child(int index) const
if (index < childCount()) {
return getOrCreateMenu(menuBar(), menuBar()->actions().at(index));
}
- return 0;
+ return nullptr;
}
int QAccessibleMenuBar::indexOfChild(const QAccessibleInterface *child) const
@@ -195,7 +161,7 @@ QAccessibleInterface *QAccessibleMenuItem::childAt(int x, int y ) const
return childInterface;
}
}
- return 0;
+ return nullptr;
}
int QAccessibleMenuItem::childCount() const
@@ -224,14 +190,14 @@ QAccessibleInterface *QAccessibleMenuItem::child(int index) const
{
if (index == 0 && action()->menu())
return QAccessible::queryAccessibleInterface(action()->menu());
- return 0;
+ return nullptr;
}
void *QAccessibleMenuItem::interface_cast(QAccessible::InterfaceType t)
{
if (t == QAccessible::ActionInterface)
return static_cast<QAccessibleActionInterface*>(this);
- return 0;
+ return nullptr;
}
QObject *QAccessibleMenuItem::object() const
@@ -299,6 +265,8 @@ QAccessible::State QAccessibleMenuItem::state() const
s.disabled = true;
if (m_action->isChecked())
s.checked = true;
+ if (m_action->isCheckable())
+ s.checkable = true;
return s;
}
@@ -389,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 9acd2a42f9..8eb9a37e2d 100644
--- a/src/widgets/accessible/qaccessiblemenu_p.h
+++ b/src/widgets/accessible/qaccessiblemenu_p.h
@@ -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
#ifndef QACCESSIBLEMENU_H
#define QACCESSIBLEMENU_H
@@ -57,7 +21,7 @@
QT_BEGIN_NAMESPACE
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
#if QT_CONFIG(menu)
class QMenu;
@@ -139,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 27e6b09dc7..b0bb12ea86 100644
--- a/src/widgets/accessible/qaccessiblewidget.cpp
+++ b/src/widgets/accessible/qaccessiblewidget.cpp
@@ -1,47 +1,10 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWidgets module 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 "qaccessiblewidget.h"
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
-#include "qaction.h"
#include "qapplication.h"
#if QT_CONFIG(groupbox)
#include "qgroupbox.h"
@@ -49,7 +12,9 @@
#if QT_CONFIG(label)
#include "qlabel.h"
#endif
+#if QT_CONFIG(tooltip)
#include "qtooltip.h"
+#endif
#if QT_CONFIG(whatsthis)
#include "qwhatsthis.h"
#endif
@@ -67,22 +32,9 @@
QT_BEGIN_NAMESPACE
-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() != QLatin1String("qt_rubberband")
- && w->objectName() != QLatin1String("qt_spinbox_lineedit"))
- widgets.append(w);
- }
- return widgets;
-}
+using namespace Qt::StringLiterals;
+
+QWidgetList _q_ac_childWidgets(const QWidget *widget);
static QString buddyString(const QWidget *widget)
{
@@ -111,18 +63,18 @@ static QString buddyString(const QWidget *widget)
/* This function will return the offset of the '&' in the text that would be
preceding the accelerator character.
If this text does not have an accelerator, -1 will be returned. */
-static int qt_accAmpIndex(const QString &text)
+static qsizetype qt_accAmpIndex(const QString &text)
{
#ifndef QT_NO_SHORTCUT
if (text.isEmpty())
return -1;
- int fa = 0;
- while ((fa = text.indexOf(QLatin1Char('&'), fa)) != -1) {
+ qsizetype fa = 0;
+ while ((fa = text.indexOf(u'&', fa)) != -1) {
++fa;
- if (fa < text.length()) {
+ if (fa < text.size()) {
// ignore "&&"
- if (text.at(fa) == QLatin1Char('&')) {
+ if (text.at(fa) == u'&') {
++fa;
continue;
@@ -143,21 +95,21 @@ static int qt_accAmpIndex(const QString &text)
QString qt_accStripAmp(const QString &text)
{
QString newText(text);
- int ampIndex = qt_accAmpIndex(newText);
+ qsizetype ampIndex = qt_accAmpIndex(newText);
if (ampIndex != -1)
newText.remove(ampIndex, 1);
- return newText.replace(QLatin1String("&&"), QLatin1String("&"));
+ return newText.replace("&&"_L1, "&"_L1);
}
QString qt_accHotKey(const QString &text)
{
#ifndef QT_NO_SHORTCUT
- int ampIndex = qt_accAmpIndex(text);
+ qsizetype ampIndex = qt_accAmpIndex(text);
if (ampIndex != -1)
return QKeySequence(Qt::ALT).toString(QKeySequence::NativeText) + text.at(ampIndex + 1);
#else
- Q_UNUSED(text)
+ Q_UNUSED(text);
#endif
return QString();
@@ -284,7 +236,7 @@ void QAccessibleWidget::addControllingSignal(const QString &signal)
QByteArray s = QMetaObject::normalizedSignature(signal.toLatin1());
if (Q_UNLIKELY(object()->metaObject()->indexOfSignal(s) < 0))
qWarning("Signal %s unknown in %s", s.constData(), object()->metaObject()->className());
- d->primarySignals << QLatin1String(s);
+ d->primarySignals << QLatin1StringView(s);
}
static inline bool isAncestor(const QObject *obj, const QObject *child)
@@ -298,10 +250,10 @@ static inline bool isAncestor(const QObject *obj, const QObject *child)
}
/*! \reimp */
-QVector<QPair<QAccessibleInterface*, QAccessible::Relation> >
+QList<QPair<QAccessibleInterface *, QAccessible::Relation>>
QAccessibleWidget::relations(QAccessible::Relation match /*= QAccessible::AllRelations*/) const
{
- QVector<QPair<QAccessibleInterface*, QAccessible::Relation> > rels;
+ QList<QPair<QAccessibleInterface *, QAccessible::Relation>> rels;
if (match & QAccessible::Label) {
const QAccessible::Relation rel = QAccessible::Label;
if (QWidget *parent = widget()->parentWidget()) {
@@ -309,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()) {
@@ -332,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)
@@ -360,10 +312,10 @@ 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 0;
+ return nullptr;
}
/*! \reimp */
@@ -374,17 +326,21 @@ QAccessibleInterface *QAccessibleWidget::focusChild() const
QWidget *fw = widget()->focusWidget();
if (!fw)
- return 0;
+ return nullptr;
- if (isAncestor(widget(), fw) || fw == widget())
- return QAccessible::queryAccessibleInterface(fw);
- return 0;
+ if (isAncestor(widget(), fw)) {
+ QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(fw);
+ if (!iface || iface == this || !iface->focusChild())
+ return iface;
+ return iface->focusChild();
+ }
+ return nullptr;
}
/*! \reimp */
int QAccessibleWidget::childCount() const
{
- QWidgetList cl = childWidgets(widget());
+ QWidgetList cl = _q_ac_childWidgets(widget());
return cl.size();
}
@@ -393,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()));
}
@@ -422,7 +378,7 @@ QString QAccessibleWidget::text(QAccessible::Text t) const
break;
case QAccessible::Description:
str = widget()->accessibleDescription();
-#ifndef QT_NO_TOOLTIP
+#if QT_CONFIG(tooltip)
if (str.isEmpty())
str = widget()->toolTip();
#endif
@@ -522,9 +478,9 @@ void *QAccessibleWidget::interface_cast(QAccessible::InterfaceType t)
{
if (t == QAccessible::ActionInterface)
return static_cast<QAccessibleActionInterface*>(this);
- return 0;
+ return nullptr;
}
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 63789a595f..c237e25d4a 100644
--- a/src/widgets/accessible/qaccessiblewidget.h
+++ b/src/widgets/accessible/qaccessiblewidget.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWidgets module 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
#ifndef QACCESSIBLEWIDGET_H
#define QACCESSIBLEWIDGET_H
@@ -46,7 +10,7 @@
QT_BEGIN_NAMESPACE
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
class QAccessibleWidgetPrivate;
@@ -59,7 +23,8 @@ public:
QWindow *window() const override;
int childCount() const override;
int indexOfChild(const QAccessibleInterface *child) const override;
- QVector<QPair<QAccessibleInterface*, QAccessible::Relation> > relations(QAccessible::Relation match = QAccessible::AllRelations) const override;
+ QList<QPair<QAccessibleInterface *, QAccessible::Relation>>
+ relations(QAccessible::Relation match = QAccessible::AllRelations) const override;
QAccessibleInterface *focusChild() const override;
QRect rect() const override;
@@ -93,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 0bac45de27..664e35a6e7 100644
--- a/src/widgets/accessible/qaccessiblewidgetfactory.cpp
+++ b/src/widgets/accessible/qaccessiblewidgetfactory.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 "qaccessiblewidgets_p.h"
#include "qaccessiblemenu_p.h"
@@ -56,13 +20,15 @@
#include <qvariant.h>
#include <qaccessible.h>
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
QAccessibleInterface *qAccessibleFactory(const QString &classname, QObject *object)
{
- QAccessibleInterface *iface = 0;
+ QAccessibleInterface *iface = nullptr;
if (!object || !object->isWidgetType())
return iface;
@@ -77,156 +43,155 @@ QAccessibleInterface *qAccessibleFactory(const QString &classname, QObject *obje
if (false) {
#if QT_CONFIG(lineedit)
- } else if (classname == QLatin1String("QLineEdit")) {
- if (widget->objectName() == QLatin1String("qt_spinbox_lineedit"))
- iface = 0;
+ } else if (classname == "QLineEdit"_L1) {
+ if (widget->objectName() == "qt_spinbox_lineedit"_L1)
+ iface = nullptr;
else
iface = new QAccessibleLineEdit(widget);
#endif
#if QT_CONFIG(combobox)
- } else if (classname == QLatin1String("QComboBox")) {
+ } else if (classname == "QComboBox"_L1) {
iface = new QAccessibleComboBox(widget);
#endif
#if QT_CONFIG(spinbox)
- } else if (classname == QLatin1String("QAbstractSpinBox")) {
+ } else if (classname == "QAbstractSpinBox"_L1) {
iface = new QAccessibleAbstractSpinBox(widget);
- } else if (classname == QLatin1String("QSpinBox")) {
+ } else if (classname == "QSpinBox"_L1) {
iface = new QAccessibleSpinBox(widget);
- } else if (classname == QLatin1String("QDoubleSpinBox")) {
+ } else if (classname == "QDoubleSpinBox"_L1) {
iface = new QAccessibleDoubleSpinBox(widget);
#endif
#if QT_CONFIG(scrollbar)
- } else if (classname == QLatin1String("QScrollBar")) {
+ } else if (classname == "QScrollBar"_L1) {
iface = new QAccessibleScrollBar(widget);
#endif
#if QT_CONFIG(slider)
- } else if (classname == QLatin1String("QAbstractSlider")) {
+ } else if (classname == "QAbstractSlider"_L1) {
iface = new QAccessibleAbstractSlider(widget);
- } else if (classname == QLatin1String("QSlider")) {
+ } else if (classname == "QSlider"_L1) {
iface = new QAccessibleSlider(widget);
#endif
#if QT_CONFIG(toolbutton)
- } else if (classname == QLatin1String("QToolButton")) {
+ } else if (classname == "QToolButton"_L1) {
iface = new QAccessibleToolButton(widget);
#endif // QT_CONFIG(toolbutton)
#if QT_CONFIG(abstractbutton)
- } else if (classname == QLatin1String("QCheckBox")
- || classname == QLatin1String("QRadioButton")
- || classname == QLatin1String("QPushButton")
- || classname == QLatin1String("QAbstractButton")) {
+ } else if (classname == "QCheckBox"_L1
+ || classname == "QRadioButton"_L1
+ || classname == "QPushButton"_L1
+ || classname == "QAbstractButton"_L1) {
iface = new QAccessibleButton(widget);
#endif
- } else if (classname == QLatin1String("QDialog")) {
+ } else if (classname == "QDialog"_L1) {
iface = new QAccessibleWidget(widget, QAccessible::Dialog);
- } else if (classname == QLatin1String("QMessageBox")) {
- iface = new QAccessibleWidget(widget, QAccessible::AlertMessage);
+#if QT_CONFIG(messagebox)
+ } else if (classname == "QMessageBox"_L1) {
+ iface = new QAccessibleMessageBox(widget);
+#endif
#if QT_CONFIG(mainwindow)
- } else if (classname == QLatin1String("QMainWindow")) {
+ } else if (classname == "QMainWindow"_L1) {
iface = new QAccessibleMainWindow(widget);
#endif
- } else if (classname == QLatin1String("QLabel") || classname == QLatin1String("QLCDNumber")) {
+ } else if (classname == "QLabel"_L1 || classname == "QLCDNumber"_L1) {
iface = new QAccessibleDisplay(widget);
#if QT_CONFIG(groupbox)
- } else if (classname == QLatin1String("QGroupBox")) {
+ } else if (classname == "QGroupBox"_L1) {
iface = new QAccessibleGroupBox(widget);
#endif
- } else if (classname == QLatin1String("QStatusBar")) {
+ } else if (classname == "QStatusBar"_L1) {
iface = new QAccessibleDisplay(widget);
#if QT_CONFIG(progressbar)
- } else if (classname == QLatin1String("QProgressBar")) {
+ } else if (classname == "QProgressBar"_L1) {
iface = new QAccessibleProgressBar(widget);
#endif
- } else if (classname == QLatin1String("QToolBar")) {
+ } else if (classname == "QToolBar"_L1) {
iface = new QAccessibleWidget(widget, QAccessible::ToolBar, widget->windowTitle());
#if QT_CONFIG(menubar)
- } else if (classname == QLatin1String("QMenuBar")) {
+ } else if (classname == "QMenuBar"_L1) {
iface = new QAccessibleMenuBar(widget);
#endif
#if QT_CONFIG(menu)
- } else if (classname == QLatin1String("QMenu")) {
+ } else if (classname == "QMenu"_L1) {
iface = new QAccessibleMenu(widget);
#endif
#if QT_CONFIG(treeview)
- } else if (classname == QLatin1String("QTreeView")) {
+ } else if (classname == "QTreeView"_L1) {
iface = new QAccessibleTree(widget);
#endif // QT_CONFIG(treeview)
#if QT_CONFIG(itemviews)
- } else if (classname == QLatin1String("QTableView") || classname == QLatin1String("QListView")) {
+ } 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 == QLatin1String("QTabBar")) {
+ } else if (classname == "QTabBar"_L1) {
iface = new QAccessibleTabBar(widget);
#endif
- } else if (classname == QLatin1String("QSizeGrip")) {
+ } else if (classname == "QSizeGrip"_L1) {
iface = new QAccessibleWidget(widget, QAccessible::Grip);
#if QT_CONFIG(splitter)
- } else if (classname == QLatin1String("QSplitter")) {
+ } else if (classname == "QSplitter"_L1) {
iface = new QAccessibleWidget(widget, QAccessible::Splitter);
- } else if (classname == QLatin1String("QSplitterHandle")) {
+ } else if (classname == "QSplitterHandle"_L1) {
iface = new QAccessibleWidget(widget, QAccessible::Grip);
#endif
#if QT_CONFIG(textedit) && !defined(QT_NO_CURSOR)
- } else if (classname == QLatin1String("QTextEdit")) {
+ } else if (classname == "QTextEdit"_L1) {
iface = new QAccessibleTextEdit(widget);
- } else if (classname == QLatin1String("QPlainTextEdit")) {
+ } else if (classname == "QPlainTextEdit"_L1) {
iface = new QAccessiblePlainTextEdit(widget);
#endif
- } else if (classname == QLatin1String("QTipLabel")) {
+ } else if (classname == "QTipLabel"_L1) {
iface = new QAccessibleDisplay(widget, QAccessible::ToolTip);
- } else if (classname == QLatin1String("QFrame")) {
+ } else if (classname == "QFrame"_L1) {
iface = new QAccessibleWidget(widget, QAccessible::Border);
#if QT_CONFIG(stackedwidget)
- } else if (classname == QLatin1String("QStackedWidget")) {
+ } else if (classname == "QStackedWidget"_L1) {
iface = new QAccessibleStackedWidget(widget);
#endif
#if QT_CONFIG(toolbox)
- } else if (classname == QLatin1String("QToolBox")) {
+ } else if (classname == "QToolBox"_L1) {
iface = new QAccessibleToolBox(widget);
#endif
#if QT_CONFIG(mdiarea)
- } else if (classname == QLatin1String("QMdiArea")) {
+ } else if (classname == "QMdiArea"_L1) {
iface = new QAccessibleMdiArea(widget);
- } else if (classname == QLatin1String("QMdiSubWindow")) {
+ } else if (classname == "QMdiSubWindow"_L1) {
iface = new QAccessibleMdiSubWindow(widget);
#endif
#if QT_CONFIG(dialogbuttonbox)
- } else if (classname == QLatin1String("QDialogButtonBox")) {
+ } else if (classname == "QDialogButtonBox"_L1) {
iface = new QAccessibleDialogButtonBox(widget);
#endif
#if QT_CONFIG(dial)
- } else if (classname == QLatin1String("QDial")) {
+ } else if (classname == "QDial"_L1) {
iface = new QAccessibleDial(widget);
#endif
#if QT_CONFIG(rubberband)
- } else if (classname == QLatin1String("QRubberBand")) {
+ } else if (classname == "QRubberBand"_L1) {
iface = new QAccessibleWidget(widget, QAccessible::Border);
#endif
#if QT_CONFIG(textbrowser) && !defined(QT_NO_CURSOR)
- } else if (classname == QLatin1String("QTextBrowser")) {
+ } else if (classname == "QTextBrowser"_L1) {
iface = new QAccessibleTextBrowser(widget);
#endif
#if QT_CONFIG(scrollarea)
- } else if (classname == QLatin1String("QAbstractScrollArea")) {
+ } else if (classname == "QAbstractScrollArea"_L1) {
iface = new QAccessibleAbstractScrollArea(widget);
- } else if (classname == QLatin1String("QScrollArea")) {
+ } else if (classname == "QScrollArea"_L1) {
iface = new QAccessibleScrollArea(widget);
#endif
#if QT_CONFIG(calendarwidget)
- } else if (classname == QLatin1String("QCalendarWidget")) {
+ } else if (classname == "QCalendarWidget"_L1) {
iface = new QAccessibleCalendarWidget(widget);
#endif
#if QT_CONFIG(dockwidget)
- } else if (classname == QLatin1String("QDockWidget")) {
+ } else if (classname == "QDockWidget"_L1) {
iface = new QAccessibleDockWidget(widget);
#endif
- } else if (classname == QLatin1String("QDesktopScreenWidget")) {
- iface = 0;
- } else if (classname == QLatin1String("QWidget")) {
+ } else if (classname == "QWidget"_L1) {
iface = new QAccessibleWidget(widget);
- } else if (classname == QLatin1String("QWindowContainer")) {
+ } else if (classname == "QWindowContainer"_L1) {
iface = new QAccessibleWindowContainer(widget);
}
@@ -235,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/qaccessiblewidgetfactory_p.h b/src/widgets/accessible/qaccessiblewidgetfactory_p.h
index 5da609ddca..eb37b33ff7 100644
--- a/src/widgets/accessible/qaccessiblewidgetfactory_p.h
+++ b/src/widgets/accessible/qaccessiblewidgetfactory_p.h
@@ -1,44 +1,7 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWidgets module 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 <QtWidgets/private/qtwidgetsglobal_p.h>
-#include <QtGui/qaccessible.h>
#ifndef QACCESSIBLEWIDGETFACTORY_H
#define QACCESSIBLEWIDGETFACTORY_H
@@ -56,6 +19,10 @@
QT_BEGIN_NAMESPACE
+class QObject;
+class QAccessibleInterface;
+class QString;
+
QAccessibleInterface *qAccessibleFactory(const QString &classname, QObject *object);
QT_END_NAMESPACE
diff --git a/src/widgets/accessible/qaccessiblewidgets.cpp b/src/widgets/accessible/qaccessiblewidgets.cpp
index 52c953ed3a..5c2a3bd02b 100644
--- a/src/widgets/accessible/qaccessiblewidgets.cpp
+++ b/src/widgets/accessible/qaccessiblewidgets.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 "qaccessiblewidgets_p.h"
#include "qabstracttextdocumentlayout.h"
@@ -92,14 +56,16 @@
#include <QMenu>
#endif
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
QT_BEGIN_NAMESPACE
+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)
@@ -114,8 +80,10 @@ QList<QWidget*> childWidgets(const QWidget *widget)
#if QT_CONFIG(menu)
&& !qobject_cast<QMenu*>(w)
#endif
- && objectName != QLatin1String("qt_rubberband")
- && objectName != QLatin1String("qt_qmainwindow_extended_splitter")) {
+ // Exclude widgets used as implementation details
+ && objectName != "qt_rubberband"_L1
+ && objectName != "qt_qmainwindow_extended_splitter"_L1
+ && objectName != "qt_spinbox_lineedit"_L1) {
widgets.append(w);
}
}
@@ -127,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
@@ -224,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. */
@@ -332,14 +300,14 @@ QAccessibleStackedWidget::QAccessibleStackedWidget(QWidget *widget)
QAccessibleInterface *QAccessibleStackedWidget::childAt(int x, int y) const
{
if (!stackedWidget()->isVisible())
- return 0;
+ return nullptr;
QWidget *currentWidget = stackedWidget()->currentWidget();
if (!currentWidget)
- return 0;
+ return nullptr;
QPoint position = currentWidget->mapFromGlobal(QPoint(x, y));
if (currentWidget->rect().contains(position))
return child(stackedWidget()->currentIndex());
- return 0;
+ return nullptr;
}
int QAccessibleStackedWidget::childCount() const
@@ -359,7 +327,7 @@ int QAccessibleStackedWidget::indexOfChild(const QAccessibleInterface *child) co
QAccessibleInterface *QAccessibleStackedWidget::child(int index) const
{
if (index < 0 || index >= stackedWidget()->count())
- return 0;
+ return nullptr;
return QAccessible::queryAccessibleInterface(stackedWidget()->widget(index));
}
@@ -393,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
@@ -401,7 +369,7 @@ QAccessibleInterface *QAccessibleMdiArea::child(int index) const
QList<QMdiSubWindow *> subWindows = mdiArea()->subWindowList();
QWidget *targetObject = subWindows.value(index);
if (!targetObject)
- return 0;
+ return nullptr;
return QAccessible::queryAccessibleInterface(targetObject);
}
@@ -432,7 +400,7 @@ QString QAccessibleMdiSubWindow::text(QAccessible::Text textType) const
{
if (textType == QAccessible::Name) {
QString title = mdiSubWindow()->windowTitle();
- title.replace(QLatin1String("[*]"), QLatin1String(""));
+ title.remove("[*]"_L1);
return title;
}
return QAccessibleWidget::text(textType);
@@ -478,7 +446,7 @@ QAccessibleInterface *QAccessibleMdiSubWindow::child(int index) const
{
QMdiSubWindow *source = mdiSubWindow();
if (index != 0 || !source->widget())
- return 0;
+ return nullptr;
return QAccessible::queryAccessibleInterface(source->widget());
}
@@ -554,7 +522,7 @@ int QAccessibleCalendarWidget::indexOfChild(const QAccessibleInterface *child) c
QAccessibleInterface *QAccessibleCalendarWidget::child(int index) const
{
if (index < 0 || index >= childCount())
- return 0;
+ return nullptr;
if (childCount() > 1 && index == 0)
return QAccessible::queryAccessibleInterface(navigationBar());
@@ -570,19 +538,19 @@ QCalendarWidget *QAccessibleCalendarWidget::calendarWidget() const
QAbstractItemView *QAccessibleCalendarWidget::calendarView() const
{
for (QObject *child : calendarWidget()->children()) {
- if (child->objectName() == QLatin1String("qt_calendar_calendarview"))
+ if (child->objectName() == "qt_calendar_calendarview"_L1)
return static_cast<QAbstractItemView *>(child);
}
- return 0;
+ return nullptr;
}
QWidget *QAccessibleCalendarWidget::navigationBar() const
{
for (QObject *child : calendarWidget()->children()) {
- if (child->objectName() == QLatin1String("qt_calendar_navigationbar"))
+ if (child->objectName() == "qt_calendar_navigationbar"_L1)
return static_cast<QWidget *>(child);
}
- return 0;
+ return nullptr;
}
#endif // QT_CONFIG(calendarwidget)
@@ -624,7 +592,7 @@ QAccessibleInterface *QAccessibleDockWidget::child(int index) const
if (item)
return QAccessible::queryAccessibleInterface(item->widget());
}
- return 0;
+ return nullptr;
}
int QAccessibleDockWidget::indexOfChild(const QAccessibleInterface *child) const
@@ -761,7 +729,7 @@ class AttributeFormatterRef {
public:
template <typename RHS>
void operator=(RHS &&rhs)
- { string += QLatin1String(key) + QLatin1Char(':') + std::forward<RHS>(rhs) + QLatin1Char(';'); }
+ { string += QLatin1StringView(key) + u':' + std::forward<RHS>(rhs) + u';'; }
};
/*!
@@ -769,7 +737,7 @@ public:
\brief Small string-builder class that supports a map-like API to serialize key-value pairs.
\code
AttributeFormatter attrs;
- attrs["foo"] = QLatinString("hello") + world + QLatin1Char('!');
+ attrs["foo"] = QLatinString("hello") + world + u'!';
\endcode
The key type is always \c{const char*}, and the right-hand-side can
be any QStringBuilder expression.
@@ -850,15 +818,15 @@ QString QAccessibleTextWidget::attributes(int offset, int *startOffset, int *end
const QFont charFormatFont = charFormat.font();
AttributeFormatter attrs;
- QString family = charFormatFont.family();
+ QString family = charFormatFont.families().value(0, QString());
if (!family.isEmpty()) {
- family = family.replace('\\', QLatin1String("\\\\"));
- family = family.replace(':', QLatin1String("\\:"));
- family = family.replace(',', QLatin1String("\\,"));
- family = family.replace('=', QLatin1String("\\="));
- family = family.replace(';', QLatin1String("\\;"));
- family = family.replace('\"', QLatin1String("\\\""));
- attrs["font-family"] = QLatin1Char('"') + family + QLatin1Char('"');
+ family = family.replace(u'\\', "\\\\"_L1);
+ family = family.replace(u':', "\\:"_L1);
+ family = family.replace(u',', "\\,"_L1);
+ family = family.replace(u'=', "\\="_L1);
+ family = family.replace(u';', "\\;"_L1);
+ family = family.replace(u'\"', "\\\""_L1);
+ attrs["font-family"] = u'"' + family + u'"';
}
int fontSize = int(charFormatFont.pointSize());
@@ -871,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;
@@ -900,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()) {
@@ -966,7 +936,7 @@ QString QAccessibleTextWidget::text(int startOffset, int endOffset) const
cursor.setPosition(startOffset, QTextCursor::MoveAnchor);
cursor.setPosition(endOffset, QTextCursor::KeepAnchor);
- return cursor.selectedText().replace(QChar(QChar::ParagraphSeparator), QLatin1Char('\n'));
+ return cursor.selectedText().replace(QChar(QChar::ParagraphSeparator), u'\n');
}
QPoint QAccessibleTextWidget::scrollBarPosition() const
@@ -1105,22 +1075,22 @@ 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 0;
+ return nullptr;
}
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()));
}
@@ -1128,19 +1098,19 @@ QAccessibleInterface *QAccessibleMainWindow::childAt(int x, int y) const
{
QWidget *w = widget();
if (!w->isVisible())
- return 0;
+ return nullptr;
QPoint gp = w->mapToGlobal(QPoint(0, 0));
if (!QRect(gp.x(), gp.y(), w->width(), w->height()).contains(x, y))
- return 0;
+ 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)) {
return QAccessible::queryAccessibleInterface(child);
}
}
- return 0;
+ return nullptr;
}
QMainWindow *QAccessibleMainWindow::mainWindow() const
@@ -1152,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 87f0b888a0..6d06f294e8 100644
--- a/src/widgets/accessible/qaccessiblewidgets_p.h
+++ b/src/widgets/accessible/qaccessiblewidgets_p.h
@@ -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
#ifndef QACCESSIBLEWIDGETS_H
#define QACCESSIBLEWIDGETS_H
@@ -54,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
@@ -319,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 b5b8608418..b172c10044 100644
--- a/src/widgets/accessible/rangecontrols.cpp
+++ b/src/widgets/accessible/rangecontrols.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 "rangecontrols_p.h"
@@ -65,7 +29,9 @@
QT_BEGIN_NAMESPACE
-#ifndef QT_NO_ACCESSIBILITY
+using namespace Qt::StringLiterals;
+
+#if QT_CONFIG(accessibility)
#if QT_CONFIG(spinbox)
QAccessibleAbstractSpinBox::QAccessibleAbstractSpinBox(QWidget *w)
@@ -253,8 +219,7 @@ QAccessibleSpinBox::QAccessibleSpinBox(QWidget *w)
: QAccessibleAbstractSpinBox(w)
{
Q_ASSERT(spinBox());
- addControllingSignal(QLatin1String("valueChanged(int)"));
- addControllingSignal(QLatin1String("valueChanged(QString)"));
+ addControllingSignal("valueChanged(int)"_L1);
}
/*!
@@ -271,8 +236,7 @@ QAccessibleDoubleSpinBox::QAccessibleDoubleSpinBox(QWidget *widget)
: QAccessibleAbstractSpinBox(widget)
{
Q_ASSERT(qobject_cast<QDoubleSpinBox *>(widget));
- addControllingSignal(QLatin1String("valueChanged(double)"));
- addControllingSignal(QLatin1String("valueChanged(QString)"));
+ addControllingSignal("valueChanged(double)"_L1);
}
/*!
@@ -309,7 +273,7 @@ QAccessibleScrollBar::QAccessibleScrollBar(QWidget *w)
: QAccessibleAbstractSlider(w, QAccessible::ScrollBar)
{
Q_ASSERT(scrollBar());
- addControllingSignal(QLatin1String("valueChanged(int)"));
+ addControllingSignal("valueChanged(int)"_L1);
}
/*! Returns the scroll bar. */
@@ -344,7 +308,7 @@ QAccessibleSlider::QAccessibleSlider(QWidget *w)
: QAccessibleAbstractSlider(w)
{
Q_ASSERT(slider());
- addControllingSignal(QLatin1String("valueChanged(int)"));
+ addControllingSignal("valueChanged(int)"_L1);
}
/*! Returns the slider. */
@@ -412,7 +376,7 @@ QAccessibleDial::QAccessibleDial(QWidget *widget)
: QAccessibleAbstractSlider(widget, QAccessible::Dial)
{
Q_ASSERT(qobject_cast<QDial *>(widget));
- addControllingSignal(QLatin1String("valueChanged(int)"));
+ addControllingSignal("valueChanged(int)"_L1);
}
QString QAccessibleDial::text(QAccessible::Text textType) const
@@ -429,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 1eada8e456..162cbbdb34 100644
--- a/src/widgets/accessible/rangecontrols_p.h
+++ b/src/widgets/accessible/rangecontrols_p.h
@@ -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
#ifndef RANGECONTROLS_H
#define RANGECONTROLS_H
@@ -56,7 +20,7 @@
QT_BEGIN_NAMESPACE
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
class QAbstractSpinBox;
class QAbstractSlider;
@@ -199,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 ca74ee4b12..fbbbab857d 100644
--- a/src/widgets/accessible/simplewidgets.cpp
+++ b/src/widgets/accessible/simplewidgets.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 "simplewidgets_p.h"
@@ -76,6 +40,12 @@
#include <qlineedit.h>
#include <private/qlineedit_p.h>
#endif
+#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>
@@ -90,9 +60,11 @@
QT_BEGIN_NAMESPACE
-#ifndef QT_NO_ACCESSIBILITY
+using namespace Qt::StringLiterals;
-extern QList<QWidget*> childWidgets(const QWidget *widget);
+#if QT_CONFIG(accessibility)
+
+QWidgetList _q_ac_childWidgets(const QWidget *widget);
QString qt_accStripAmp(const QString &text);
QString qt_accHotKey(const QString &text);
@@ -117,9 +89,9 @@ QAccessibleButton::QAccessibleButton(QWidget *w)
// FIXME: The checkable state of the button is dynamic,
// while we only update the controlling signal once :(
if (button()->isCheckable())
- addControllingSignal(QLatin1String("toggled(bool)"));
+ addControllingSignal("toggled(bool)"_L1);
else
- addControllingSignal(QLatin1String("clicked()"));
+ addControllingSignal("clicked()"_L1);
}
/*! Returns the button. */
@@ -244,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;
}
}
@@ -362,9 +332,9 @@ QAccessibleInterface *QAccessibleToolButton::child(int index) const
return QAccessible::queryAccessibleInterface(toolButton()->menu());
}
#else
- Q_UNUSED(index)
+ Q_UNUSED(index);
#endif
- return 0;
+ return nullptr;
}
/*
@@ -431,10 +401,10 @@ QAccessible::Role QAccessibleDisplay::role() const
#if QT_CONFIG(label)
QLabel *l = qobject_cast<QLabel*>(object());
if (l) {
- if (l->pixmap())
+ if (!l->pixmap().isNull())
return QAccessible::Graphic;
#ifndef QT_NO_PICTURE
- if (l->picture())
+ if (!l->picture().isNull())
return QAccessible::Graphic;
#endif
#if QT_CONFIG(movie)
@@ -516,11 +486,12 @@ QString QAccessibleDisplay::text(QAccessible::Text t) const
}
/*! \reimp */
-QVector<QPair<QAccessibleInterface*, QAccessible::Relation> >
+QList<QPair<QAccessibleInterface *, QAccessible::Relation>>
QAccessibleDisplay::relations(QAccessible::Relation match /* = QAccessible::AllRelations */) const
{
- QVector<QPair<QAccessibleInterface*, QAccessible::Relation> > rels = QAccessibleWidget::relations(match);
-#if QT_CONFIG(shortcut) && QT_CONFIG(label)
+ QList<QPair<QAccessibleInterface *, QAccessible::Relation>> rels =
+ QAccessibleWidget::relations(match);
+# if QT_CONFIG(shortcut) && QT_CONFIG(label)
if (match & QAccessible::Labelled) {
if (QLabel *label = qobject_cast<QLabel*>(object())) {
const QAccessible::Relation rel = QAccessible::Labelled;
@@ -542,7 +513,7 @@ void *QAccessibleDisplay::interface_cast(QAccessible::InterfaceType t)
/*! \internal */
QString QAccessibleDisplay::imageDescription() const
{
-#ifndef QT_NO_TOOLTIP
+#if QT_CONFIG(tooltip)
return widget()->toolTip();
#else
return QString();
@@ -558,10 +529,7 @@ QSize QAccessibleDisplay::imageSize() const
#endif
return QSize();
#if QT_CONFIG(label)
- const QPixmap *pixmap = label->pixmap();
- if (!pixmap)
- return QSize();
- return pixmap->size();
+ return label->pixmap().size();
#endif
}
@@ -574,8 +542,7 @@ QPoint QAccessibleDisplay::imagePosition() const
#endif
return QPoint();
#if QT_CONFIG(label)
- const QPixmap *pixmap = label->pixmap();
- if (!pixmap)
+ if (label->pixmap().isNull())
return QPoint();
return QPoint(label->mapToGlobal(label->pos()));
@@ -631,13 +598,14 @@ QAccessible::Role QAccessibleGroupBox::role() const
return groupBox()->isCheckable() ? QAccessible::CheckBox : QAccessible::Grouping;
}
-QVector<QPair<QAccessibleInterface*, QAccessible::Relation> >
+QList<QPair<QAccessibleInterface *, QAccessible::Relation>>
QAccessibleGroupBox::relations(QAccessible::Relation match /* = QAccessible::AllRelations */) const
{
- QVector<QPair<QAccessibleInterface*, QAccessible::Relation> > rels = QAccessibleWidget::relations(match);
+ QList<QPair<QAccessibleInterface *, QAccessible::Relation>> rels =
+ 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)
@@ -686,8 +654,8 @@ QStringList QAccessibleGroupBox::keyBindingsForAction(const QString &) const
QAccessibleLineEdit::QAccessibleLineEdit(QWidget *w, const QString &name)
: QAccessibleWidget(w, QAccessible::EditableText, name)
{
- addControllingSignal(QLatin1String("textChanged(const QString&)"));
- addControllingSignal(QLatin1String("returnPressed()"));
+ addControllingSignal("textChanged(const QString&)"_L1);
+ addControllingSignal("returnPressed()"_L1);
}
/*! Returns the line edit. */
@@ -704,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;
@@ -810,7 +778,7 @@ void QAccessibleLineEdit::selection(int selectionIndex, int *startOffset, int *e
return;
*startOffset = lineEdit()->selectionStart();
- *endOffset = *startOffset + lineEdit()->selectedText().count();
+ *endOffset = *startOffset + lineEdit()->selectedText().size();
}
QString QAccessibleLineEdit::text(int startOffset, int endOffset) const
@@ -883,7 +851,7 @@ void QAccessibleLineEdit::setSelection(int selectionIndex, int startOffset, int
int QAccessibleLineEdit::characterCount() const
{
- return lineEdit()->text().count();
+ return lineEdit()->text().size();
}
void QAccessibleLineEdit::scrollToSubstring(int startIndex, int endIndex)
@@ -976,7 +944,7 @@ QAccessibleInterface *QAccessibleWindowContainer::child(int i) const
{
if (i == 0)
return QAccessible::queryAccessibleInterface(container()->containedWindow());
- return 0;
+ return nullptr;
}
QWindowContainer *QAccessibleWindowContainer::container() const
@@ -984,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 73572e3059..c9c03b00d8 100644
--- a/src/widgets/accessible/simplewidgets_p.h
+++ b/src/widgets/accessible/simplewidgets_p.h
@@ -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
#ifndef SIMPLEWIDGETS_H
#define SIMPLEWIDGETS_H
@@ -57,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)
@@ -118,7 +83,8 @@ public:
QAccessible::Role role() const override;
QAccessible::State state() const override;
- QVector<QPair<QAccessibleInterface*, QAccessible::Relation> >relations(QAccessible::Relation match = QAccessible::AllRelations) const override;
+ QList<QPair<QAccessibleInterface *, QAccessible::Relation>>
+ relations(QAccessible::Relation match = QAccessible::AllRelations) const override;
void *interface_cast(QAccessible::InterfaceType t) override;
// QAccessibleImageInterface
@@ -137,7 +103,8 @@ public:
QAccessible::Role role() const override;
QString text(QAccessible::Text t) const override;
- QVector<QPair<QAccessibleInterface*, QAccessible::Relation> >relations(QAccessible::Relation match = QAccessible::AllRelations) const override;
+ QList<QPair<QAccessibleInterface *, QAccessible::Relation>>
+ relations(QAccessible::Relation match = QAccessible::AllRelations) const override;
//QAccessibleActionInterface
QStringList actionNames() const override;
@@ -223,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
diff --git a/src/widgets/accessible/widgets.pro b/src/widgets/accessible/widgets.pro
deleted file mode 100644
index d04d0da3cc..0000000000
--- a/src/widgets/accessible/widgets.pro
+++ /dev/null
@@ -1,25 +0,0 @@
-TARGET = qtaccessiblewidgets
-
-QT += core-private gui-private widgets-private
-
-QTDIR_build:REQUIRES += "qtConfig(accessibility)"
-
-SOURCES += main.cpp \
- simplewidgets.cpp \
- rangecontrols.cpp \
- complexwidgets.cpp \
- qaccessiblewidgets.cpp \
- qaccessiblemenu.cpp \
- itemviews.cpp
-
-HEADERS += qaccessiblewidgets.h \
- simplewidgets.h \
- rangecontrols.h \
- complexwidgets.h \
- qaccessiblemenu.h \
- itemviews.h
-
-PLUGIN_TYPE = accessible
-PLUGIN_EXTENDS = widgets
-PLUGIN_CLASS_NAME = AccessibleFactory
-load(qt_plugin)