diff options
author | Frederik Gladhorn <frederik.gladhorn@nokia.com> | 2011-09-28 15:36:52 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-10-03 15:31:42 +0200 |
commit | 5ea2eab00d70c4dfef1050387c5db376aff95b39 (patch) | |
tree | ae208eea2d4756e66938c227487a8c9b03d59b58 | |
parent | 9ac51af0838c87ea0e21a12243ef82513c5df3e5 (diff) |
Simplify QAccessibleAbstractScrollArea and Calendar.
Change-Id: Iea1df37fd9fd486295458ec7627f5b6908053cdf
Reviewed-on: http://codereview.qt-project.org/5727
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Jan-Arve Sæther <jan-arve.saether@nokia.com>
-rw-r--r-- | src/plugins/accessible/widgets/complexwidgets.cpp | 123 | ||||
-rw-r--r-- | src/plugins/accessible/widgets/complexwidgets.h | 9 | ||||
-rw-r--r-- | src/plugins/accessible/widgets/qaccessiblewidgets.cpp | 50 | ||||
-rw-r--r-- | src/plugins/accessible/widgets/qaccessiblewidgets.h | 7 | ||||
-rw-r--r-- | tests/auto/qaccessibility/tst_qaccessibility.cpp | 63 |
5 files changed, 81 insertions, 171 deletions
diff --git a/src/plugins/accessible/widgets/complexwidgets.cpp b/src/plugins/accessible/widgets/complexwidgets.cpp index 52a1ae6fcb..c193fe863c 100644 --- a/src/plugins/accessible/widgets/complexwidgets.cpp +++ b/src/plugins/accessible/widgets/complexwidgets.cpp @@ -1847,57 +1847,14 @@ QAccessibleAbstractScrollArea::QAccessibleAbstractScrollArea(QWidget *widget) Q_ASSERT(qobject_cast<QAbstractScrollArea *>(widget)); } -QString QAccessibleAbstractScrollArea::text(Text textType, int child) const -{ - if (child == Self) - return QAccessibleWidget::text(textType, 0); - QWidgetList children = accessibleChildren(); - if (child < 1 || child > children.count()) - return QString(); - QAccessibleInterface *childInterface = queryAccessibleInterface(children.at(child - 1)); - if (!childInterface) - return QString(); - QString string = childInterface->text(textType, 0); - delete childInterface; - return string; -} - -void QAccessibleAbstractScrollArea::setText(Text textType, int child, const QString &text) -{ - if (text.isEmpty()) - return; - if (child == 0) { - QAccessibleWidget::setText(textType, 0, text); - return; - } - QWidgetList children = accessibleChildren(); - if (child < 1 || child > children.count()) - return; - QAccessibleInterface *childInterface = queryAccessibleInterface(children.at(child - 1)); - if (!childInterface) - return; - childInterface->setText(textType, 0, text); - delete childInterface; -} - -QAccessible::State QAccessibleAbstractScrollArea::state(int child) const +QVariant QAccessibleAbstractScrollArea::invokeMethod(QAccessible::Method, int, const QVariantList &) { - if (child == Self) - return QAccessibleWidget::state(child); - QWidgetList children = accessibleChildren(); - if (child < 1 || child > children.count()) - return QAccessibleWidget::state(Self); - QAccessibleInterface *childInterface = queryAccessibleInterface(children.at(child - 1)); - if (!childInterface) - return QAccessibleWidget::state(Self); - QAccessible::State returnState = childInterface->state(0); - delete childInterface; - return returnState; + return QVariant(); } -QVariant QAccessibleAbstractScrollArea::invokeMethod(QAccessible::Method, int, const QVariantList &) +QAccessibleInterface *QAccessibleAbstractScrollArea::child(int index) const { - return QVariant(); + return QAccessible::queryAccessibleInterface(accessibleChildren().at(index)); } int QAccessibleAbstractScrollArea::childCount() const @@ -1948,9 +1905,10 @@ int QAccessibleAbstractScrollArea::navigate(RelationFlag relation, int entry, QA // to the reader. :-) switch (relation) { case Child: - if (entry > 0) - targetWidget = children.at(entry - 1); - break; + if (entry > 0) { + *target = child(entry - 1); + return *target ? 0 : -1; + } case Left: if (entry < 1) break; @@ -2039,46 +1997,31 @@ int QAccessibleAbstractScrollArea::navigate(RelationFlag relation, int entry, QA return *target ? 0: -1; } -QRect QAccessibleAbstractScrollArea::rect(int child) const -{ - if (!abstractScrollArea()->isVisible()) - return QRect(); - if (child == Self) - return QAccessibleWidget::rect(child); - QWidgetList children = accessibleChildren(); - if (child < 1 || child > children.count()) - return QRect(); - const QWidget *childWidget = children.at(child - 1); - if (!childWidget->isVisible()) - return QRect(); - return QRect(childWidget->mapToGlobal(QPoint(0, 0)), childWidget->size()); -} - -int QAccessibleAbstractScrollArea::childAt(int x, int y) const -{ - if (!abstractScrollArea()->isVisible()) - return -1; -#if 0 - const QRect globalSelfGeometry = rect(Self); - if (!globalSelfGeometry.isValid() || !globalSelfGeometry.contains(QPoint(x, y))) - return -1; - const QWidgetList children = accessibleChildren(); - for (int i = 0; i < children.count(); ++i) { - const QWidget *child = children.at(i); - const QRect globalChildGeometry = QRect(child->mapToGlobal(QPoint(0, 0)), child->size()); - if (globalChildGeometry.contains(QPoint(x, y))) { - return ++i; - } - } - return 0; -#else - for (int i = childCount(); i >= 0; --i) { - if (rect(i).contains(x, y)) - return i; - } - return -1; -#endif -} +//int QAccessibleAbstractScrollArea::childAt(int x, int y) const +//{ +// if (!abstractScrollArea()->isVisible()) +// return -1; +//#if 0 +// const QRect globalSelfGeometry = rect(Self); +// if (!globalSelfGeometry.isValid() || !globalSelfGeometry.contains(QPoint(x, y))) +// return -1; +// const QWidgetList children = accessibleChildren(); +// for (int i = 0; i < children.count(); ++i) { +// const QWidget *child = children.at(i); +// const QRect globalChildGeometry = QRect(child->mapToGlobal(QPoint(0, 0)), child->size()); +// if (globalChildGeometry.contains(QPoint(x, y))) { +// return ++i; +// } +// } +// return 0; +//#else +// for (int i = childCount(); i >= 0; --i) { +// if (rect().contains(x, y)) +// return i; +// } +// return -1; +//#endif +//} QAbstractScrollArea *QAccessibleAbstractScrollArea::abstractScrollArea() const { diff --git a/src/plugins/accessible/widgets/complexwidgets.h b/src/plugins/accessible/widgets/complexwidgets.h index 9abec34510..a8c63a026a 100644 --- a/src/plugins/accessible/widgets/complexwidgets.h +++ b/src/plugins/accessible/widgets/complexwidgets.h @@ -74,16 +74,13 @@ public: Undefined }; - QString text(Text textType, int child) const; - void setText(Text textType, int child, const QString &text); - State state(int child) const; - QVariant invokeMethod(QAccessible::Method method, int child, const QVariantList ¶ms); + QAccessibleInterface *child(int index) const; + QVariant invokeMethod(QAccessible::Method method, int, const QVariantList ¶ms); int childCount() const; int indexOfChild(const QAccessibleInterface *child) const; bool isValid() const; int navigate(RelationFlag relation, int entry, QAccessibleInterface **target) const; - QRect rect(int child) const; - int childAt(int x, int y) const; +// int childAt(int x, int y) const; //protected: QAbstractScrollArea *abstractScrollArea() const; diff --git a/src/plugins/accessible/widgets/qaccessiblewidgets.cpp b/src/plugins/accessible/widgets/qaccessiblewidgets.cpp index 9b3d37f50d..22644aad2b 100644 --- a/src/plugins/accessible/widgets/qaccessiblewidgets.cpp +++ b/src/plugins/accessible/widgets/qaccessiblewidgets.cpp @@ -1200,6 +1200,17 @@ int QAccessibleCalendarWidget::indexOfChild(const QAccessibleInterface *child) c return 1; } +QAccessibleInterface *QAccessibleCalendarWidget::child(int index) const +{ + if (index < 0 || index >= childCount()) + return 0; + + if (childCount() > 1 && index == 0) + return queryAccessibleInterface(navigationBar()); + + return queryAccessibleInterface(calendarView()); +} + int QAccessibleCalendarWidget::navigate(RelationFlag relation, int entry, QAccessibleInterface **target) const { *target = 0; @@ -1208,15 +1219,8 @@ int QAccessibleCalendarWidget::navigate(RelationFlag relation, int entry, QAcces QWidget *targetWidget = 0; switch (relation) { case Child: - if (childCount() == 1) { - targetWidget = calendarView(); - } else { - if (entry == 1) - targetWidget = navigationBar(); - else - targetWidget = calendarView(); - } - break; + *target = child(entry - 1); + return *target ? 0 : -1; case Up: if (entry == 2) targetWidget = navigationBar(); @@ -1229,33 +1233,7 @@ int QAccessibleCalendarWidget::navigate(RelationFlag relation, int entry, QAcces return QAccessibleWidget::navigate(relation, entry, target); } *target = queryAccessibleInterface(targetWidget); - return *target ? 0: -1; -} - -QRect QAccessibleCalendarWidget::rect(int child) const -{ - if (!calendarWidget()->isVisible() || child > childCount()) - return QRect(); - if (child == 0) - return QAccessibleWidget::rect(child); - QWidget *childWidget = 0; - if (childCount() == 2) - childWidget = child == 1 ? navigationBar() : calendarView(); - else - childWidget = calendarView(); - return QRect(childWidget->mapToGlobal(QPoint(0, 0)), childWidget->size()); -} - -int QAccessibleCalendarWidget::childAt(int x, int y) const -{ - const QPoint globalTargetPos = QPoint(x, y); - if (!rect(0).contains(globalTargetPos)) - return -1; - if (rect(1).contains(globalTargetPos)) - return 1; - if (rect(2).contains(globalTargetPos)) - return 2; - return 0; + return *target ? 0 : -1; } QCalendarWidget *QAccessibleCalendarWidget::calendarWidget() const diff --git a/src/plugins/accessible/widgets/qaccessiblewidgets.h b/src/plugins/accessible/widgets/qaccessiblewidgets.h index 2a595d79dd..8d0a13a04a 100644 --- a/src/plugins/accessible/widgets/qaccessiblewidgets.h +++ b/src/plugins/accessible/widgets/qaccessiblewidgets.h @@ -228,13 +228,14 @@ class QAccessibleCalendarWidget : public QAccessibleWidget public: explicit QAccessibleCalendarWidget(QWidget *widget); - QVariant invokeMethod(QAccessible::Method method, int child, const QVariantList ¶ms); int childCount() const; int indexOfChild(const QAccessibleInterface *child) const; int navigate(RelationFlag relation, int entry, QAccessibleInterface **target) const; - QRect rect(int child) const; - int childAt(int x, int y) const; + QAccessibleInterface *child(int index) const; + + + QVariant invokeMethod(QAccessible::Method method, int child, const QVariantList ¶ms); protected: QCalendarWidget *calendarWidget() const; diff --git a/tests/auto/qaccessibility/tst_qaccessibility.cpp b/tests/auto/qaccessibility/tst_qaccessibility.cpp index 89eb4904d7..2ecf270473 100644 --- a/tests/auto/qaccessibility/tst_qaccessibility.cpp +++ b/tests/auto/qaccessibility/tst_qaccessibility.cpp @@ -81,6 +81,32 @@ static inline bool verifyChild(QWidget *child, QAccessibleInterface *interface, return false; } + // Verify that we get a valid QAccessibleInterface for the child. + QAccessibleInterface *childInterface = QAccessible::queryAccessibleInterface(child); + if (!childInterface) { + qWarning("tst_QAccessibility::verifyChild: Failed to retrieve interface for child."); + return false; + } + + // QAccessibleInterface::indexOfChild(): + // Verify that indexOfChild() returns an index equal to the index passed in + int indexFromIndexOfChild = interface->indexOfChild(childInterface); + delete childInterface; + if (indexFromIndexOfChild != index) { + qWarning("tst_QAccessibility::verifyChild (indexOfChild()):"); + qWarning() << "Expected:" << index; + qWarning() << "Actual: " << indexFromIndexOfChild; + return false; + } + + // Navigate to child, compare its object and role with the interface from queryAccessibleInterface(child). + QAccessibleInterface *navigatedChildInterface = interface->child(index - 1); + if (navigatedChildInterface == 0) + return false; + + const QRect rectFromInterface = navigatedChildInterface->rect(); + delete navigatedChildInterface; + // QAccessibleInterface::childAt(): // Calculate global child position and check that the interface // returns the correct index for that position. @@ -97,7 +123,6 @@ static inline bool verifyChild(QWidget *child, QAccessibleInterface *interface, // Calculate global child geometry and check that the interface // returns a QRect which is equal to the calculated QRect. const QRect expectedGlobalRect = QRect(globalChildPos, child->size()); - const QRect rectFromInterface = interface->rect(index); if (expectedGlobalRect != rectFromInterface) { qWarning("tst_QAccessibility::verifyChild (rect()):"); qWarning() << "Expected:" << expectedGlobalRect; @@ -111,39 +136,6 @@ static inline bool verifyChild(QWidget *child, QAccessibleInterface *interface, return false; } - // Verify that we get a valid QAccessibleInterface for the child. - QAccessibleInterface *childInterface = QAccessible::queryAccessibleInterface(child); - if (!childInterface) { - qWarning("tst_QAccessibility::verifyChild: Failed to retrieve interface for child."); - return false; - } - - // QAccessibleInterface::indexOfChild(): - // Verify that indexOfChild() returns an index equal to the index passed by, - // or -1 if child is "Self" (index == 0). - int indexFromIndexOfChild = interface->indexOfChild(childInterface); - delete childInterface; - int expectedIndex = index == 0 ? -1 : index; - if (indexFromIndexOfChild != expectedIndex) { - qWarning("tst_QAccessibility::verifyChild (indexOfChild()):"); - qWarning() << "Expected:" << expectedIndex; - qWarning() << "Actual: " << indexFromIndexOfChild; - return false; - } - - // Navigate to child, compare its object and role with the interface from queryAccessibleInterface(child). - { - QAccessibleInterface *navigatedChildInterface = 0; - const int status = interface->navigate(QAccessible::Child, index, &navigatedChildInterface); - // We are navigating to a separate widget/interface, so status should be 0. - if (status != 0) - return false; - - if (navigatedChildInterface == 0) - return false; - delete navigatedChildInterface; - } - return true; } @@ -2413,7 +2405,6 @@ void tst_QAccessibility::abstractScrollAreaTest() QAccessibleInterface *interface = QAccessible::queryAccessibleInterface(&abstractScrollArea); QVERIFY(interface); QVERIFY(!interface->rect(0).isValid()); - QVERIFY(!interface->rect(1).isValid()); QCOMPARE(interface->childAt(200, 200), -1); abstractScrollArea.resize(400, 400); @@ -3138,7 +3129,7 @@ void tst_QAccessibility::calendarWidgetTest() const QRect globalGeometry = QRect(calendarWidget.mapToGlobal(QPoint(0, 0)), calendarWidget.size()); - QCOMPARE(interface->rect(0), globalGeometry); + QCOMPARE(interface->rect(), globalGeometry); QWidget *navigationBar = 0; foreach (QObject *child, calendarWidget.children()) { |