Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Reuse the OObject* in QAccessibleObject
Saves a few bytes per interface....

Change-Id: I2d66a563d28b94e08179bc43d4465509e0cb88f2
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@nokia.com>
  • Loading branch information
Jan-Arve Saether authored and Qt by Nokia committed Jan 6, 2012
1 parent 0888e43 commit 72ae9e8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 31 deletions.
45 changes: 22 additions & 23 deletions src/plugins/accessible/quick/qaccessiblequickitem.cpp
Expand Up @@ -48,7 +48,6 @@ QT_BEGIN_NAMESPACE

QAccessibleQuickItem::QAccessibleQuickItem(QQuickItem *item)
: QDeclarativeAccessible(item)
, m_item(item)
{
}

Expand All @@ -61,55 +60,55 @@ QRect QAccessibleQuickItem::rect() const
{
// ### no canvas in some cases.
// ### Should we really check for 0 opacity?
if (!m_item->canvas() ||!m_item->isVisible() || qFuzzyIsNull(m_item->opacity())) {
if (!item()->canvas() ||!item()->isVisible() || qFuzzyIsNull(item()->opacity())) {
return QRect();
}

QSizeF size = QSizeF(m_item->width(), m_item->height());
QSizeF size = QSizeF(item()->width(), item()->height());
// ### If the bounding rect fails, we first try the implicit size, then we go for the
// parent size. WE MIGHT HAVE TO REVISIT THESE FALLBACKS.
if (size.isEmpty()) {
size = QSizeF(m_item->implicitWidth(), m_item->implicitHeight());
size = QSizeF(item()->implicitWidth(), item()->implicitHeight());
if (size.isEmpty())
// ### Seems that the above fallback is not enough, fallback to use the parent size...
size = QSizeF(m_item->parentItem()->width(), m_item->parentItem()->height());
size = QSizeF(item()->parentItem()->width(), item()->parentItem()->height());
}

QRectF sceneRect = m_item->mapRectToScene(QRectF(QPointF(0, 0), size));
QPoint screenPos = m_item->canvas()->mapToGlobal(sceneRect.topLeft().toPoint());
QRectF sceneRect = item()->mapRectToScene(QRectF(QPointF(0, 0), size));
QPoint screenPos = item()->canvas()->mapToGlobal(sceneRect.topLeft().toPoint());

QRect r = QRect(screenPos, sceneRect.size().toSize());

if (!r.isValid()) {
qWarning() << m_item->metaObject()->className() << m_item->property("accessibleText") << r;
qWarning() << item()->metaObject()->className() << item()->property("accessibleText") << r;
}
return r;
}

QRect QAccessibleQuickItem::viewRect() const
{
// ### no canvas in some cases.
if (!m_item->canvas()) {
if (!item()->canvas()) {
return QRect();
}

QQuickCanvas *canvas = m_item->canvas();
QQuickCanvas *canvas = item()->canvas();
QPoint screenPos = canvas->mapToGlobal(QPoint(0,0));
return QRect(screenPos, canvas->size());
}


bool QAccessibleQuickItem::clipsChildren() const
{
return static_cast<QQuickItem *>(m_item)->clip();
return static_cast<QQuickItem *>(item())->clip();
}


QAccessibleInterface *QAccessibleQuickItem::parent() const
{
QQuickItem *parent = m_item->parentItem();
QQuickItem *parent = item()->parentItem();
if (parent) {
QQuickCanvas *canvas = m_item->canvas();
QQuickCanvas *canvas = item()->canvas();
// Jump out to the scene widget if the parent is the root item.
// There are two root items, QQuickCanvas::rootItem and
// QQuickView::declarativeRoot. The former is the true root item,
Expand Down Expand Up @@ -146,7 +145,7 @@ int QAccessibleQuickItem::navigate(QAccessible::RelationFlag rel, int entry, QAc
Q_UNUSED(target);
*target = 0;
if (entry == 0) {
*target = new QAccessibleQuickItem(m_item);
*target = new QAccessibleQuickItem(item());
return 0;
}
return -1;
Expand All @@ -172,14 +171,14 @@ QList<QQuickItem *> QAccessibleQuickItem::childItems() const
role() == QAccessible::PageTab ||
role() == QAccessible::ProgressBar)
return QList<QQuickItem *>();
return m_item->childItems();
return item()->childItems();
}

QFlags<QAccessible::StateFlag> QAccessibleQuickItem::state() const
{
QAccessible::State state = QAccessible::Normal;

if (m_item->hasActiveFocus()) {
if (item()->hasActiveFocus()) {
state |= QAccessible::Focused;
}
return state;
Expand All @@ -191,10 +190,10 @@ QAccessible::Role QAccessibleQuickItem::role() const
// Workaround for setAccessibleRole() not working for
// Text items. Text items are special since they are defined
// entirely from C++ (setting the role from QML works.)
if (qobject_cast<QQuickText*>(const_cast<QQuickItem *>(m_item)))
if (qobject_cast<QQuickText*>(const_cast<QQuickItem *>(item())))
return QAccessible::StaticText;

QVariant v = QQuickAccessibleAttached::property(m_item, "role");
QVariant v = QQuickAccessibleAttached::property(item(), "role");
bool ok;
QAccessible::Role role = (QAccessible::Role)v.toInt(&ok);
if (!ok) // Not sure if this check is needed.
Expand All @@ -204,7 +203,7 @@ QAccessible::Role QAccessibleQuickItem::role() const

bool QAccessibleQuickItem::isAccessible() const
{
return m_item->d_func()->isAccessible;
return item()->d_func()->isAccessible;
}

QString QAccessibleQuickItem::text(QAccessible::Text textType) const
Expand Down Expand Up @@ -263,22 +262,22 @@ void *QAccessibleQuickItemValueInterface::interface_cast(QAccessible::InterfaceT

QVariant QAccessibleQuickItemValueInterface::currentValue()
{
return m_item->property("value");
return item()->property("value");
}

void QAccessibleQuickItemValueInterface::setCurrentValue(const QVariant &value)
{
m_item->setProperty("value", value);
item()->setProperty("value", value);
}

QVariant QAccessibleQuickItemValueInterface::maximumValue()
{
return m_item->property("maximumValue");
return item()->property("maximumValue");
}

QVariant QAccessibleQuickItemValueInterface::minimumValue()
{
return m_item->property("minimumValue");
return item()->property("minimumValue");
}


Expand Down
2 changes: 1 addition & 1 deletion src/plugins/accessible/quick/qaccessiblequickitem.h
Expand Up @@ -74,7 +74,7 @@ class QAccessibleQuickItem : public QDeclarativeAccessible
bool isAccessible() const;

protected:
QQuickItem *m_item;
QQuickItem *item() const { return static_cast<QQuickItem*>(object()); }
};

class QAccessibleQuickItemValueInterface: public QAccessibleQuickItem, public QAccessibleValueInterface
Expand Down
11 changes: 5 additions & 6 deletions src/plugins/accessible/quick/qaccessiblequickview.cpp
Expand Up @@ -53,12 +53,11 @@ QT_BEGIN_NAMESPACE
QAccessibleQuickView::QAccessibleQuickView(QQuickView *object)
:QAccessibleObject(object)
{
m_view = static_cast<QQuickView *>(object);
}

int QAccessibleQuickView::childCount() const
{
return m_view->rootItem() ? 1 : 0;
return view()->rootItem() ? 1 : 0;
}

QAccessibleInterface *QAccessibleQuickView::parent() const
Expand All @@ -70,7 +69,7 @@ QAccessibleInterface *QAccessibleQuickView::parent() const
QAccessibleInterface *QAccessibleQuickView::child(int index) const
{
if (index == 0) {
QQuickItem *declarativeRoot = m_view->rootObject();
QQuickItem *declarativeRoot = view()->rootObject();
return new QAccessibleQuickItem(declarativeRoot);
}
return 0;
Expand All @@ -88,7 +87,7 @@ QAccessible::State QAccessibleQuickView::state() const

QRect QAccessibleQuickView::rect() const
{
return QRect(m_view->x(), m_view->y(), m_view->width(), m_view->height());
return QRect(view()->x(), view()->y(), view()->width(), view()->height());
}

int QAccessibleQuickView::navigate(QAccessible::RelationFlag rel, int entry, QAccessibleInterface **target) const
Expand All @@ -106,7 +105,7 @@ QString QAccessibleQuickView::text(QAccessible::Text text) const
return QString::fromAscii(object()->metaObject()->className()) ;
}
#endif
return m_view->windowTitle();
return view()->windowTitle();
}

QAccessibleInterface *QAccessibleQuickView::childAt(int x, int y) const
Expand All @@ -119,7 +118,7 @@ QAccessibleInterface *QAccessibleQuickView::childAt(int x, int y) const
int QAccessibleQuickView::indexOfChild(const QAccessibleInterface *iface) const
{
if (iface) {
QQuickItem *declarativeRoot = m_view->rootObject();
QQuickItem *declarativeRoot = view()->rootObject();
if (declarativeRoot == iface->object())
return 1;
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/accessible/quick/qaccessiblequickview.h
Expand Up @@ -68,7 +68,7 @@ class QAccessibleQuickView : public QAccessibleObject
QString text(QAccessible::Text text) const;
QAccessibleInterface *childAt(int x, int y) const;
private:
QQuickView *m_view;
QQuickView *view() const { return static_cast<QQuickView*>(object()); }
};

#endif // QT_NO_ACCESSIBILITY
Expand Down

0 comments on commit 72ae9e8

Please sign in to comment.