From 2c241d0604be95227ad535e0d5c846d4e7ff685c Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 7 Jan 2013 13:17:38 +0100 Subject: Add QStyleHelper:isInstanceOf() Task-number: QTBUG-28876 Change-Id: I343dff1c47c52e0431c09b6097da09f34e626f54 Reviewed-by: Jonathan Liu Reviewed-by: Jens Bache-Wiig --- src/widgets/styles/qstylehelper.cpp | 18 +++++++++++++++--- src/widgets/styles/qstylehelper_p.h | 1 + 2 files changed, 16 insertions(+), 3 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/styles/qstylehelper.cpp b/src/widgets/styles/qstylehelper.cpp index 1630130de2..ee44d01634 100644 --- a/src/widgets/styles/qstylehelper.cpp +++ b/src/widgets/styles/qstylehelper.cpp @@ -86,6 +86,20 @@ qreal dpiScaled(qreal value) #endif } +bool isInstanceOf(QObject *obj, QAccessible::Role role) +{ + bool match = false; +#ifndef QT_NO_ACCESSIBILITY + QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(obj); + match = iface && iface->role() == role; + delete iface; +#else + Q_UNUSED(obj) + Q_UNUSED(role) +#endif // QT_NO_ACCESSIBILITY + return match; +} + // Searches for an ancestor of a particular accessible role bool hasAncestor(QObject *obj, QAccessible::Role role) { @@ -93,10 +107,8 @@ bool hasAncestor(QObject *obj, QAccessible::Role role) #ifndef QT_NO_ACCESSIBILITY QObject *parent = obj ? obj->parent() : 0; while (parent && !found) { - QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(parent); - if (iface && iface->role() == role) + if (isInstanceOf(parent, role)) found = true; - delete iface; parent = parent->parent(); } #else diff --git a/src/widgets/styles/qstylehelper_p.h b/src/widgets/styles/qstylehelper_p.h index ab6a97e59a..642db68d9e 100644 --- a/src/widgets/styles/qstylehelper_p.h +++ b/src/widgets/styles/qstylehelper_p.h @@ -82,6 +82,7 @@ namespace QStyleHelper void drawBorderPixmap(const QPixmap &pixmap, QPainter *painter, const QRect &rect, int left = 0, int top = 0, int right = 0, int bottom = 0); + bool isInstanceOf(QObject *obj, QAccessible::Role role); bool hasAncestor(QObject *obj, QAccessible::Role role); } -- cgit v1.2.3