Fix casting. Casting is now done through the virtual interface_cast.

Change interface_cast to return void* to avoid using virtual
inheritance.
Get rid of the magic Q_ACCESSIBLE_OBJECT macro.

Change-Id: I94b824aef53f2ba657d39d406b387c8681d47ee4
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@nokia.com>
This commit is contained in:
Jan-Arve Saether 2011-11-30 09:48:51 +01:00 committed by Qt by Nokia
parent 55c3799bd3
commit 84e66f69ae
18 changed files with 112 additions and 104 deletions

View File

@ -1203,12 +1203,6 @@ QVariant QAccessibleInterface::virtual_hook(const QVariant &)
return QVariant();
}
/*! \internal */
QAccessible2Interface *QAccessibleInterface::cast_helper(QAccessible2::InterfaceType t)
{
return interface_cast(t);
}
#ifndef QT_NO_DEBUG_STREAM
Q_GUI_EXPORT QDebug operator<<(QDebug d, const QAccessibleInterface *iface)
{

View File

@ -309,6 +309,17 @@ public:
BackgroundColor = 4
};
enum InterfaceType
{
TextInterface,
EditableTextInterface,
ValueInterface,
TableInterface,
ActionInterface,
ImageInterface,
Table2Interface
};
typedef QAccessibleInterface*(*InterfaceFactory)(const QString &key, QObject*);
typedef void(*UpdateHandler)(QObject*, int who, Event reason);
typedef void(*RootObjectHandler)(QObject*);
@ -336,20 +347,6 @@ QT_END_NAMESPACE
Q_DECLARE_METATYPE(QSet<QAccessible::Method>)
QT_BEGIN_NAMESPACE
namespace QAccessible2
{
enum InterfaceType
{
TextInterface,
EditableTextInterface,
ValueInterface,
TableInterface,
ActionInterface,
ImageInterface,
Table2Interface
};
}
class QAccessible2Interface;
class QAccessibleTextInterface;
class QAccessibleEditableTextInterface;
@ -397,33 +394,31 @@ public:
{ return qvariant_cast<QSet<Method> >(invokeMethod(ListSupportedMethods)); }
inline QAccessibleTextInterface *textInterface()
{ return reinterpret_cast<QAccessibleTextInterface *>(cast_helper(QAccessible2::TextInterface)); }
{ return reinterpret_cast<QAccessibleTextInterface *>(interface_cast(QAccessible::TextInterface)); }
inline QAccessibleEditableTextInterface *editableTextInterface()
{ return reinterpret_cast<QAccessibleEditableTextInterface *>(cast_helper(QAccessible2::EditableTextInterface)); }
{ return reinterpret_cast<QAccessibleEditableTextInterface *>(interface_cast(QAccessible::EditableTextInterface)); }
inline QAccessibleValueInterface *valueInterface()
{ return reinterpret_cast<QAccessibleValueInterface *>(cast_helper(QAccessible2::ValueInterface)); }
{ return reinterpret_cast<QAccessibleValueInterface *>(interface_cast(QAccessible::ValueInterface)); }
inline QAccessibleTableInterface *tableInterface()
{ return reinterpret_cast<QAccessibleTableInterface *>(cast_helper(QAccessible2::TableInterface)); }
{ return reinterpret_cast<QAccessibleTableInterface *>(interface_cast(QAccessible::TableInterface)); }
inline QAccessibleActionInterface *actionInterface()
{ return reinterpret_cast<QAccessibleActionInterface *>(cast_helper(QAccessible2::ActionInterface)); }
{ return reinterpret_cast<QAccessibleActionInterface *>(interface_cast(QAccessible::ActionInterface)); }
inline QAccessibleImageInterface *imageInterface()
{ return reinterpret_cast<QAccessibleImageInterface *>(cast_helper(QAccessible2::ImageInterface)); }
{ return reinterpret_cast<QAccessibleImageInterface *>(interface_cast(QAccessible::ImageInterface)); }
inline QAccessibleTable2Interface *table2Interface()
{ return reinterpret_cast<QAccessibleTable2Interface *>(cast_helper(QAccessible2::Table2Interface)); }
{ return reinterpret_cast<QAccessibleTable2Interface *>(interface_cast(QAccessible::Table2Interface)); }
// FIXME
virtual QVariant virtual_hook(const QVariant &data);
virtual QAccessible2Interface *interface_cast(QAccessible2::InterfaceType)
virtual void *interface_cast(QAccessible::InterfaceType)
{ return 0; }
private:
QAccessible2Interface *cast_helper(QAccessible2::InterfaceType);
};
class QAccessibleEvent : public QEvent

View File

@ -91,50 +91,9 @@ namespace QAccessible2
};
}
class Q_GUI_EXPORT QAccessible2Interface
class Q_GUI_EXPORT QAccessibleTextInterface
{
public:
virtual ~QAccessible2Interface() {}
};
// catch-all functions. If an accessible class doesn't implement interface T, return 0
inline QAccessible2Interface *qAccessibleValueCastHelper() { return 0; }
inline QAccessible2Interface *qAccessibleTextCastHelper() { return 0; }
inline QAccessible2Interface *qAccessibleEditableTextCastHelper() { return 0; }
inline QAccessible2Interface *qAccessibleTableCastHelper() { return 0; }
inline QAccessible2Interface *qAccessibleActionCastHelper() { return 0; }
inline QAccessible2Interface *qAccessibleImageCastHelper() { return 0; }
inline QAccessible2Interface *qAccessibleTable2CastHelper() { return 0; }
#define Q_ACCESSIBLE_OBJECT \
public: \
QAccessible2Interface *interface_cast(QAccessible2::InterfaceType t) \
{ \
switch (t) { \
case QAccessible2::TextInterface: \
return qAccessibleTextCastHelper(); \
case QAccessible2::EditableTextInterface: \
return qAccessibleEditableTextCastHelper(); \
case QAccessible2::ValueInterface: \
return qAccessibleValueCastHelper(); \
case QAccessible2::TableInterface: \
return qAccessibleTableCastHelper(); \
case QAccessible2::ActionInterface: \
return qAccessibleActionCastHelper(); \
case QAccessible2::ImageInterface: \
return qAccessibleImageCastHelper(); \
case QAccessible2::Table2Interface: \
return qAccessibleTable2CastHelper(); \
} \
return 0; \
} \
private:
class Q_GUI_EXPORT QAccessibleTextInterface: public QAccessible2Interface
{
public:
inline QAccessible2Interface *qAccessibleTextCastHelper() { return this; }
virtual ~QAccessibleTextInterface() {}
virtual void addSelection(int startOffset, int endOffset) = 0;
@ -158,11 +117,9 @@ public:
virtual void scrollToSubstring(int startIndex, int endIndex) = 0;
};
class Q_GUI_EXPORT QAccessibleEditableTextInterface: public QAccessible2Interface
class Q_GUI_EXPORT QAccessibleEditableTextInterface
{
public:
inline QAccessible2Interface *qAccessibleEditableTextCastHelper() { return this; }
virtual ~QAccessibleEditableTextInterface() {}
virtual void copyText(int startOffset, int endOffset) = 0;
@ -177,7 +134,7 @@ public:
class Q_GUI_EXPORT QAccessibleSimpleEditableTextInterface: public QAccessibleEditableTextInterface
{
public:
QAccessibleSimpleEditableTextInterface(QAccessibleInterface *accessibleInterface);
QAccessibleSimpleEditableTextInterface(QAccessibleInterface *accessibleInterface); //###
void copyText(int startOffset, int endOffset);
void deleteText(int startOffset, int endOffset);
@ -191,10 +148,9 @@ private:
QAccessibleInterface *iface;
};
class Q_GUI_EXPORT QAccessibleValueInterface: public QAccessible2Interface
class Q_GUI_EXPORT QAccessibleValueInterface
{
public:
inline QAccessible2Interface *qAccessibleValueCastHelper() { return this; }
virtual ~QAccessibleValueInterface() {}
@ -204,10 +160,10 @@ public:
virtual QVariant minimumValue() = 0;
};
class Q_GUI_EXPORT QAccessibleTableInterface: public QAccessible2Interface
class Q_GUI_EXPORT QAccessibleTableInterface
{
public:
inline QAccessible2Interface *qAccessibleTableCastHelper() { return this; }
virtual QAccessibleInterface *accessibleAt(int row, int column) = 0;
virtual QAccessibleInterface *caption() = 0;
@ -267,10 +223,9 @@ public:
virtual bool isExpandable() const = 0;
};
class Q_GUI_EXPORT QAccessibleTable2Interface: public QAccessible2Interface
class Q_GUI_EXPORT QAccessibleTable2Interface
{
public:
inline QAccessible2Interface *qAccessibleTable2CastHelper() { return this; }
// Returns the cell at the specified row and column in the table.
virtual QAccessibleTable2CellInterface *cellAt (int row, int column) const = 0;
@ -327,11 +282,10 @@ friend class QAbstractItemView;
friend class QAbstractItemViewPrivate;
};
class Q_GUI_EXPORT QAccessibleActionInterface: public QAccessible2Interface
class Q_GUI_EXPORT QAccessibleActionInterface
{
Q_DECLARE_TR_FUNCTIONS(QAccessibleActionInterface)
public:
inline QAccessible2Interface *qAccessibleActionCastHelper() { return this; }
virtual QStringList actionNames() const = 0;
virtual QString localizedActionName(const QString &name) const;
@ -348,10 +302,9 @@ public:
static const QString &uncheckAction();
};
class Q_GUI_EXPORT QAccessibleImageInterface : public QAccessible2Interface
class Q_GUI_EXPORT QAccessibleImageInterface
{
public:
inline QAccessible2Interface *qAccessibleImageCastHelper() { return this; }
virtual QString imageDescription() = 0;
virtual QSize imageSize() = 0;

View File

@ -78,7 +78,6 @@ private:
class Q_GUI_EXPORT QAccessibleApplication : public QAccessibleObject
{
Q_ACCESSIBLE_OBJECT
public:
QAccessibleApplication();

View File

@ -1451,12 +1451,18 @@ QAccessible::State QAccessibleHeader::state(int child) const
class QAccessibleTabButton: public QAccessibleInterface, public QAccessibleActionInterface
{
Q_ACCESSIBLE_OBJECT
public:
QAccessibleTabButton(QTabBar *parent, int index)
: m_parent(parent), m_index(index)
{}
void *interface_cast(QAccessible::InterfaceType t) {
if (t == QAccessible::ActionInterface) {
return static_cast<QAccessibleActionInterface*>(this);
}
return 0;
}
QObject *object() const { return 0; }
Role role() const { return QAccessible::PageTab; }
State state() const {

View File

@ -103,7 +103,6 @@ public:
#ifndef QT_NO_ITEMVIEWS
class QAccessibleHeader : public QAccessibleWidget
{
Q_ACCESSIBLE_OBJECT
public:
explicit QAccessibleHeader(QWidget *w);
@ -162,7 +161,6 @@ private:
class QAccessibleItemView: public QAccessibleAbstractScrollArea, public QAccessibleTableInterface
{
Q_ACCESSIBLE_OBJECT
public:
explicit QAccessibleItemView(QWidget *w);
@ -232,7 +230,6 @@ private:
#ifndef QT_NO_TABBAR
class QAccessibleTabBar : public QAccessibleWidget
{
Q_ACCESSIBLE_OBJECT
public:
explicit QAccessibleTabBar(QWidget *w);
@ -254,7 +251,6 @@ protected:
#ifndef QT_NO_COMBOBOX
class QAccessibleComboBox : public QAccessibleWidget
{
Q_ACCESSIBLE_OBJECT
public:
explicit QAccessibleComboBox(QWidget *w);

View File

@ -470,6 +470,13 @@ QAccessible::Relation QAccessibleTable2::relationTo(const QAccessibleInterface *
return QAccessible::Unrelated;
}
void *QAccessibleTable2::interface_cast(QAccessible::InterfaceType t)
{
if (t == QAccessible::Table2Interface)
return static_cast<QAccessibleTable2Interface*>(this);
return 0;
}
// TREE VIEW
QModelIndex QAccessibleTree::indexFromLogical(int row, int column) const

View File

@ -60,7 +60,6 @@ class QAccessibleTable2HeaderCell;
class QAccessibleTable2 :public QAccessibleTable2Interface, public QAccessibleObject
{
Q_ACCESSIBLE_OBJECT
public:
explicit QAccessibleTable2(QWidget *w);
@ -82,6 +81,7 @@ public:
Relation relationTo(const QAccessibleInterface *other) const;
QVariant invokeMethod(Method, const QVariantList &) { return QVariant(); }
void *interface_cast(QAccessible::InterfaceType t);
// table2 interface
virtual QAccessibleTable2CellInterface *cellAt(int row, int column) const;

View File

@ -277,6 +277,13 @@ int QAccessibleMenuItem::navigate(RelationFlag relation, int entry, QAccessibleI
return *target ? 0 : -1;
}
void *QAccessibleMenuItem::interface_cast(QAccessible::InterfaceType t)
{
if (t == QAccessible::ActionInterface)
return static_cast<QAccessibleActionInterface*>(this);
return 0;
}
QObject *QAccessibleMenuItem::object() const
{
return m_action;

View File

@ -92,11 +92,12 @@ protected:
class QAccessibleMenuItem : public QAccessibleInterface, public QAccessibleActionInterface
{
Q_ACCESSIBLE_OBJECT
public:
explicit QAccessibleMenuItem(QWidget *owner, QAction *w);
virtual ~QAccessibleMenuItem();
void *interface_cast(QAccessible::InterfaceType t);
virtual int childAt(int x, int y) const;
virtual int childCount() const;
virtual int indexOfChild(const QAccessibleInterface * child) const;

View File

@ -302,6 +302,15 @@ QVariant QAccessibleTextEdit::invokeMethod(QAccessible::Method method,
}
}
void *QAccessibleTextEdit::interface_cast(QAccessible::InterfaceType t)
{
if (t == QAccessible::TextInterface)
return static_cast<QAccessibleTextInterface*>(this);
else if (t == QAccessible::EditableTextInterface)
return static_cast<QAccessibleEditableTextInterface*>(this);
return QAccessibleWidget::interface_cast(t);
}
void QAccessibleTextEdit::addSelection(int startOffset, int endOffset)
{
setSelection(0, startOffset, endOffset);

View File

@ -69,7 +69,6 @@ class QMainWindow;
class QAccessibleTextEdit : public QAccessibleWidget, public QAccessibleTextInterface,
public QAccessibleEditableTextInterface
{
Q_ACCESSIBLE_OBJECT
public:
explicit QAccessibleTextEdit(QWidget *o);
@ -77,6 +76,7 @@ public:
void setText(Text t, const QString &text);
QVariant invokeMethod(QAccessible::Method method, const QVariantList &params);
void *interface_cast(QAccessible::InterfaceType t);
// QAccessibleTextInterface
void addSelection(int startOffset, int endOffset);
@ -118,7 +118,6 @@ private:
class QAccessibleStackedWidget : public QAccessibleWidget
{
Q_ACCESSIBLE_OBJECT
public:
explicit QAccessibleStackedWidget(QWidget *widget);
@ -135,7 +134,6 @@ protected:
class QAccessibleToolBox : public QAccessibleWidget
{
Q_ACCESSIBLE_OBJECT
public:
explicit QAccessibleToolBox(QWidget *widget);

View File

@ -87,6 +87,13 @@ QString QAccessibleAbstractSpinBox::text(Text t) const
return QAccessibleWidget::text(t);
}
void *QAccessibleAbstractSpinBox::interface_cast(QAccessible::InterfaceType t)
{
if (t == QAccessible::ValueInterface)
return static_cast<QAccessibleValueInterface*>(this);
return QAccessibleWidget::interface_cast(t);
}
QVariant QAccessibleAbstractSpinBox::currentValue()
{
QVariant result = abstractSpinBox()->property("value");
@ -244,6 +251,13 @@ QAccessibleAbstractSlider::QAccessibleAbstractSlider(QWidget *w, Role r)
Q_ASSERT(qobject_cast<QAbstractSlider *>(w));
}
void *QAccessibleAbstractSlider::interface_cast(QAccessible::InterfaceType t)
{
if (t == QAccessible::ValueInterface)
return static_cast<QAccessibleValueInterface*>(this);
return QAccessibleWidget::interface_cast(t);
}
QVariant QAccessibleAbstractSlider::currentValue()
{
return abstractSlider()->value();

View File

@ -60,11 +60,11 @@ class QDial;
#ifndef QT_NO_SPINBOX
class QAccessibleAbstractSpinBox: public QAccessibleWidget, public QAccessibleValueInterface // TODO, public QAccessibleActionInterface
{
Q_ACCESSIBLE_OBJECT
public:
explicit QAccessibleAbstractSpinBox(QWidget *w);
QString text(Text t) const;
void *interface_cast(QAccessible::InterfaceType t);
// QAccessibleValueInterface
QVariant currentValue();
@ -101,9 +101,9 @@ protected:
class QAccessibleAbstractSlider: public QAccessibleWidget, public QAccessibleValueInterface
{
Q_ACCESSIBLE_OBJECT
public:
explicit QAccessibleAbstractSlider(QWidget *w, Role r = Slider);
void *interface_cast(QAccessible::InterfaceType t);
// QAccessibleValueInterface
QVariant currentValue();

View File

@ -474,6 +474,13 @@ int QAccessibleDisplay::navigate(RelationFlag rel, int entry, QAccessibleInterfa
return QAccessibleWidget::navigate(rel, entry, target);
}
void *QAccessibleDisplay::interface_cast(QAccessible::InterfaceType t)
{
if (t == QAccessible::ImageInterface)
return static_cast<QAccessibleImageInterface*>(this);
return QAccessibleWidget::interface_cast(t);
}
/*! \internal */
QString QAccessibleDisplay::imageDescription()
{
@ -614,6 +621,15 @@ QVariant QAccessibleLineEdit::invokeMethod(QAccessible::Method method,
}
}
void *QAccessibleLineEdit::interface_cast(QAccessible::InterfaceType t)
{
if (t == QAccessible::TextInterface)
return static_cast<QAccessibleTextInterface*>(this);
else if (t == QAccessible::EditableTextInterface)
return static_cast<QAccessibleEditableTextInterface*>(this);
return QAccessibleWidget::interface_cast(t);
}
void QAccessibleLineEdit::addSelection(int startOffset, int endOffset)
{
setSelection(0, startOffset, endOffset);
@ -743,6 +759,13 @@ QAccessibleProgressBar::QAccessibleProgressBar(QWidget *o)
Q_ASSERT(progressBar());
}
void *QAccessibleProgressBar::interface_cast(QAccessible::InterfaceType t)
{
if (t == QAccessible::ValueInterface)
return static_cast<QAccessibleValueInterface*>(this);
return QAccessibleDisplay::interface_cast(t);
}
QVariant QAccessibleProgressBar::currentValue()
{
return progressBar()->value();

View File

@ -57,7 +57,6 @@ class QProgressBar;
class QAccessibleButton : public QAccessibleWidget
{
Q_ACCESSIBLE_OBJECT
Q_DECLARE_TR_FUNCTIONS(QAccessibleButton)
public:
QAccessibleButton(QWidget *w, Role r);
@ -99,7 +98,6 @@ protected:
class QAccessibleDisplay : public QAccessibleWidget, public QAccessibleImageInterface
{
Q_ACCESSIBLE_OBJECT
public:
explicit QAccessibleDisplay(QWidget *w, Role role = StaticText);
@ -108,6 +106,7 @@ public:
Relation relationTo(const QAccessibleInterface *other) const;
int navigate(RelationFlag, int entry, QAccessibleInterface **target) const;
void *interface_cast(QAccessible::InterfaceType t);
// QAccessibleImageInterface
QString imageDescription();
@ -119,7 +118,6 @@ public:
class QAccessibleLineEdit : public QAccessibleWidget, public QAccessibleTextInterface,
public QAccessibleSimpleEditableTextInterface
{
Q_ACCESSIBLE_OBJECT
public:
explicit QAccessibleLineEdit(QWidget *o, const QString &name = QString());
@ -127,6 +125,7 @@ public:
void setText(Text t, const QString &text);
State state() const;
QVariant invokeMethod(QAccessible::Method method, const QVariantList &params);
void *interface_cast(QAccessible::InterfaceType t);
// QAccessibleTextInterface
void addSelection(int startOffset, int endOffset);
@ -157,9 +156,9 @@ protected:
#ifndef QT_NO_PROGRESSBAR
class QAccessibleProgressBar : public QAccessibleDisplay, public QAccessibleValueInterface
{
Q_ACCESSIBLE_OBJECT
public:
explicit QAccessibleProgressBar(QWidget *o);
void *interface_cast(QAccessible::InterfaceType t);
// QAccessibleValueInterface
QVariant currentValue();

View File

@ -875,6 +875,13 @@ QColor QAccessibleWidget::backgroundColor() const
return widget()->palette().color(widget()->backgroundRole());
}
void *QAccessibleWidget::interface_cast(QAccessible::InterfaceType t)
{
if (t == QAccessible::ActionInterface)
return static_cast<QAccessibleActionInterface*>(this);
return 0;
}
QT_END_NAMESPACE
#endif //QT_NO_ACCESSIBILITY

View File

@ -56,7 +56,6 @@ class QAccessibleWidgetPrivate;
class Q_WIDGETS_EXPORT QAccessibleWidget : public QAccessibleObject, public QAccessibleActionInterface
{
Q_ACCESSIBLE_OBJECT
public:
explicit QAccessibleWidget(QWidget *o, Role r = Client, const QString& name = QString());
@ -79,6 +78,7 @@ public:
QColor foregroundColor() const;
QColor backgroundColor() const;
void *interface_cast(QAccessible::InterfaceType t);
// QAccessibleActionInterface
QStringList actionNames() const;