Add QStyleHelper:isInstanceOf()

Task-number: QTBUG-28876
Change-Id: I343dff1c47c52e0431c09b6097da09f34e626f54
Reviewed-by: Jonathan Liu <net147@gmail.com>
Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@digia.com>
This commit is contained in:
J-P Nurmi 2013-01-07 13:17:38 +01:00 committed by The Qt Project
parent 99e5496ff7
commit 2c241d0604
2 changed files with 16 additions and 3 deletions

View File

@ -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

View File

@ -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);
}