diff options
author | Lars Knoll <lars.knoll@nokia.com> | 2009-06-03 12:14:09 (GMT) |
---|---|---|
committer | Andreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com> | 2009-06-11 09:49:23 (GMT) |
commit | 05cb12eb18605aa32ff7a6761ff82d86aa339995 (patch) | |
tree | bb21b0addc7407361071d95daedd1466f0851dc4 /src | |
parent | 615f8a53355ea501e489eecddab1d5c4295cab80 (diff) | |
download | Qt-05cb12eb18605aa32ff7a6761ff82d86aa339995.zip Qt-05cb12eb18605aa32ff7a6761ff82d86aa339995.tar.gz Qt-05cb12eb18605aa32ff7a6761ff82d86aa339995.tar.bz2 |
add a QGraphicsObject class and change QGraphicsWidget and QGraphicsTextItem to inherit from it
This changes the inheritance hierarchy of QGraphicsWidget from
multiply inheriting from QObject, QGraphicsItem and QGraphicsLayoutItem
to inherit from QGraphicsObject and QGraphicsLayoutItem. QGraphicsObject
then simply inherits from QObject and QGraphicsItem.
This change is binary compatible as it will leave the vtable layout
unchanged and as the parent class doesn't appear in the C++ name
mangling on any of our platforms. It's also source compatible as
it isn't noticable by existing code.
The restriction we have on QGraphicsObject is that we can not add any
new virtual methods to it, or add data members to the class. We can however
implement a QGraphicsObjectprivate inheriting from QGraphicsItemPrivate
if there is a need to add data members to the class.
This change will allow us to now have one single base for all QGraphicsItems
that inherit from QObject: QGraphicsTextItem, QGraphicsWidget and in the
future QFxItem. Having that single base class will significantly simplify
our work in the qml engine.
Reviewed-by: Andreas
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/graphicsview/graphicsview.pri | 77 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicsitem.cpp | 16 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicsitem.h | 12 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicswidget.cpp | 4 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicswidget.h | 3 |
5 files changed, 63 insertions, 49 deletions
diff --git a/src/gui/graphicsview/graphicsview.pri b/src/gui/graphicsview/graphicsview.pri index 02d9bb1..4cee6d6 100644 --- a/src/gui/graphicsview/graphicsview.pri +++ b/src/gui/graphicsview/graphicsview.pri @@ -1,46 +1,37 @@ # Qt graphicsview module - -HEADERS += \ - graphicsview/qgraphicsitem.h \ - graphicsview/qgraphicsitem_p.h \ - graphicsview/qgraphicsitemanimation.h \ - graphicsview/qgraphicsscene.h \ - graphicsview/qgraphicsscene_p.h \ - graphicsview/qgraphicsscene_bsp_p.h \ - graphicsview/qgraphicssceneevent.h \ - graphicsview/qgraphicsview_p.h \ - graphicsview/qgraphicsview.h - -SOURCES += \ - graphicsview/qgraphicsitem.cpp \ - graphicsview/qgraphicsitemanimation.cpp \ - graphicsview/qgraphicsscene.cpp \ - graphicsview/qgraphicsscene_bsp.cpp \ - graphicsview/qgraphicssceneevent.cpp \ - graphicsview/qgraphicsview.cpp +HEADERS += graphicsview/qgraphicsitem.h \ + graphicsview/qgraphicsitem_p.h \ + graphicsview/qgraphicsitemanimation.h \ + graphicsview/qgraphicsscene.h \ + graphicsview/qgraphicsscene_p.h \ + graphicsview/qgraphicsscene_bsp_p.h \ + graphicsview/qgraphicssceneevent.h \ + graphicsview/qgraphicsview_p.h \ + graphicsview/qgraphicsview.h +SOURCES += graphicsview/qgraphicsitem.cpp \ + graphicsview/qgraphicsitemanimation.cpp \ + graphicsview/qgraphicsscene.cpp \ + graphicsview/qgraphicsscene_bsp.cpp \ + graphicsview/qgraphicssceneevent.cpp \ + graphicsview/qgraphicsview.cpp # Widgets on the canvas - -HEADERS += \ - graphicsview/qgraphicslayout.h \ - graphicsview/qgraphicslayout_p.h \ - graphicsview/qgraphicslayoutitem.h \ - graphicsview/qgraphicslayoutitem_p.h \ - graphicsview/qgraphicslinearlayout.h \ - graphicsview/qgraphicswidget.h \ - graphicsview/qgraphicswidget_p.h \ - graphicsview/qgridlayoutengine_p.h \ - graphicsview/qgraphicsproxywidget.h \ - graphicsview/qgraphicsgridlayout.h - -SOURCES += \ - graphicsview/qgraphicslayout.cpp \ - graphicsview/qgraphicslayout_p.cpp \ - graphicsview/qgraphicslayoutitem.cpp \ - graphicsview/qgraphicslinearlayout.cpp \ - graphicsview/qgraphicswidget.cpp \ - graphicsview/qgraphicswidget_p.cpp \ - graphicsview/qgridlayoutengine.cpp \ - graphicsview/qgraphicsproxywidget.cpp \ - graphicsview/qgraphicsgridlayout.cpp - +HEADERS += graphicsview/qgraphicslayout.h \ + graphicsview/qgraphicslayout_p.h \ + graphicsview/qgraphicslayoutitem.h \ + graphicsview/qgraphicslayoutitem_p.h \ + graphicsview/qgraphicslinearlayout.h \ + graphicsview/qgraphicswidget.h \ + graphicsview/qgraphicswidget_p.h \ + graphicsview/qgridlayoutengine_p.h \ + graphicsview/qgraphicsproxywidget.h \ + graphicsview/qgraphicsgridlayout.h +SOURCES += graphicsview/qgraphicslayout.cpp \ + graphicsview/qgraphicslayout_p.cpp \ + graphicsview/qgraphicslayoutitem.cpp \ + graphicsview/qgraphicslinearlayout.cpp \ + graphicsview/qgraphicswidget.cpp \ + graphicsview/qgraphicswidget_p.cpp \ + graphicsview/qgridlayoutengine.cpp \ + graphicsview/qgraphicsproxywidget.cpp \ + graphicsview/qgraphicsgridlayout.cpp diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index eae2bf3..b83f9db 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -8147,6 +8147,18 @@ public: QGraphicsTextItem *qq; }; + +QGraphicsObject::QGraphicsObject(QGraphicsItem *parent) + : QGraphicsItem(parent) +{ +} + +QGraphicsObject::QGraphicsObject(QGraphicsItemPrivate &dd, QGraphicsItem *parent, QGraphicsScene *scene) + : QGraphicsItem(dd, parent, scene) +{ +} + + /*! Constructs a QGraphicsTextItem, using \a text as the default plain text. \a parent is passed to QGraphicsItem's constructor. @@ -8159,7 +8171,7 @@ QGraphicsTextItem::QGraphicsTextItem(const QString &text, QGraphicsItem *parent , QGraphicsScene *scene #endif ) - : QGraphicsItem(parent, scene), dd(new QGraphicsTextItemPrivate) + : QGraphicsObject(*new QGraphicsItemPrivate, parent, scene), dd(new QGraphicsTextItemPrivate) { dd->qq = this; if (!text.isEmpty()) @@ -8181,7 +8193,7 @@ QGraphicsTextItem::QGraphicsTextItem(QGraphicsItem *parent , QGraphicsScene *scene #endif ) - : QGraphicsItem(parent, scene), dd(new QGraphicsTextItemPrivate) + : QGraphicsObject(*new QGraphicsItemPrivate, parent, scene), dd(new QGraphicsTextItemPrivate) { dd->qq = this; setAcceptDrops(true); diff --git a/src/gui/graphicsview/qgraphicsitem.h b/src/gui/graphicsview/qgraphicsitem.h index cff4f1f..a9b5d71 100644 --- a/src/gui/graphicsview/qgraphicsitem.h +++ b/src/gui/graphicsview/qgraphicsitem.h @@ -832,10 +832,20 @@ private: inline void QGraphicsPixmapItem::setOffset(qreal ax, qreal ay) { setOffset(QPointF(ax, ay)); } +class Q_GUI_EXPORT QGraphicsObject : public QObject, public QGraphicsItem +{ + Q_OBJECT + Q_INTERFACES(QGraphicsItem) +public: + QGraphicsObject(QGraphicsItem *parent = 0); +protected: + QGraphicsObject(QGraphicsItemPrivate &dd, QGraphicsItem *parent, QGraphicsScene *scene); +}; + class QGraphicsTextItemPrivate; class QTextDocument; class QTextCursor; -class Q_GUI_EXPORT QGraphicsTextItem : public QObject, public QGraphicsItem +class Q_GUI_EXPORT QGraphicsTextItem : public QGraphicsObject { Q_OBJECT QDOC_PROPERTY(bool openExternalLinks READ openExternalLinks WRITE setOpenExternalLinks) diff --git a/src/gui/graphicsview/qgraphicswidget.cpp b/src/gui/graphicsview/qgraphicswidget.cpp index 7314167..84434db 100644 --- a/src/gui/graphicsview/qgraphicswidget.cpp +++ b/src/gui/graphicsview/qgraphicswidget.cpp @@ -257,7 +257,7 @@ QT_BEGIN_NAMESPACE window, a tool, a popup, etc). */ QGraphicsWidget::QGraphicsWidget(QGraphicsItem *parent, Qt::WindowFlags wFlags) - : QGraphicsItem(*new QGraphicsWidgetPrivate, 0, 0), QGraphicsLayoutItem(0, false) + : QGraphicsObject(*new QGraphicsWidgetPrivate, 0, 0), QGraphicsLayoutItem(0, false) { Q_D(QGraphicsWidget); d->init(parent, wFlags); @@ -269,7 +269,7 @@ QGraphicsWidget::QGraphicsWidget(QGraphicsItem *parent, Qt::WindowFlags wFlags) Constructs a new QGraphicsWidget, using \a dd as parent. */ QGraphicsWidget::QGraphicsWidget(QGraphicsWidgetPrivate &dd, QGraphicsItem *parent, QGraphicsScene *scene, Qt::WindowFlags wFlags) - : QGraphicsItem(dd, 0, scene), QGraphicsLayoutItem(0, false) + : QGraphicsObject(dd, 0, scene), QGraphicsLayoutItem(0, false) { Q_D(QGraphicsWidget); d->init(parent, wFlags); diff --git a/src/gui/graphicsview/qgraphicswidget.h b/src/gui/graphicsview/qgraphicswidget.h index a5c9068..6f324cf 100644 --- a/src/gui/graphicsview/qgraphicswidget.h +++ b/src/gui/graphicsview/qgraphicswidget.h @@ -66,9 +66,10 @@ class QStyleOption; class QGraphicsWidgetPrivate; -class Q_GUI_EXPORT QGraphicsWidget : public QObject, public QGraphicsItem, public QGraphicsLayoutItem +class Q_GUI_EXPORT QGraphicsWidget : public QGraphicsObject, public QGraphicsLayoutItem { Q_OBJECT + Q_INTERFACES(QGraphicsLayoutItem) Q_PROPERTY(QPalette palette READ palette WRITE setPalette) Q_PROPERTY(QFont font READ font WRITE setFont) Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection RESET unsetLayoutDirection) |