From 15366ae05397cdf322e0a34e729eb5db2bae9c2a Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Mon, 8 Jun 2009 10:18:59 +0200 Subject: add parent and id properties to QGraphicsObject In addition added documentation for the other properties. Reviewed-by: Andreas --- src/gui/graphicsview/qgraphicsitem.cpp | 73 +++++++++++++++++++++++++++++++++- src/gui/graphicsview/qgraphicsitem.h | 6 ++- 2 files changed, 76 insertions(+), 3 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index 3622c82..0390a83 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -959,6 +959,9 @@ void QGraphicsItemPrivate::setParentItemHelper(QGraphicsItem *newParent) // Deliver post-change notification q->itemChange(QGraphicsItem::ItemParentHasChanged, newParentVariant); + + if (isObject) + emit static_cast(q)->parentChanged(); } /*! @@ -1213,6 +1216,20 @@ QGraphicsItem *QGraphicsItem::topLevelItem() const /*! \since 4.4 + Returns a pointer to the item's parent, cast to a QGraphicsObject. returns 0 if the parent item + is not a QGraphicsObject. + + \sa parentItem(), childItems() +*/ +QGraphicsObject *QGraphicsItem::parentObject() const +{ + QGraphicsItem *p = d_ptr->parent; + return (p && p->d_ptr->isObject) ? static_cast(p) : 0; +} + +/*! + \since 4.4 + Returns a pointer to the item's parent widget. The item's parent widget is the closest parent item that is a widget. @@ -6417,6 +6434,14 @@ QGraphicsObject::QGraphicsObject(QGraphicsItemPrivate &dd, QGraphicsItem *parent } /*! + \property QGraphicsObject::parent + \brief the parent of the item + + \sa QGraphicsItem::setParentItem, QGraphicsItem::parentObject +*/ + + +/*! \property QGraphicsObject::opacity \brief the opacity of the item @@ -6441,13 +6466,57 @@ QGraphicsObject::QGraphicsObject(QGraphicsItemPrivate &dd, QGraphicsItem *parent */ /*! - \fn QGraphicsObject::positionChanged() + \property QGraphicsObject::x + \brief the x position of the item + + Describes the items x position. + + \sa QGraphicsItem::setX, setPos, xChanged +*/ + +/*! + \fn QGraphicsObject::xChanged() + + This signal gets emitted whenever the x position of the item changes + + \sa pos +*/ + +/*! + \property QGraphicsObject:y + \brief the y position of the item + + Describes the items y position. + + \sa QGraphicsItem::setY, setPos, yChanged +*/ + +/*! + \fn QGraphicsObject::yChanged() + + This signal gets emitted whenever the y position of the item changes + + \sa pos +*/ + +/*! + \property QGraphicsObject::z + \brief the z value of the item - This signal gets emitted whenever the position of the item changes + Describes the items z value. + + \sa QGraphicsItem::setZValue, zValue, zChanged +*/ + +/*! + \fn QGraphicsObject::zChanged() + + This signal gets emitted whenever the z value of the item changes \sa pos */ + /*! \property QGraphicsObject::enabled \brief whether the item is enabled or not diff --git a/src/gui/graphicsview/qgraphicsitem.h b/src/gui/graphicsview/qgraphicsitem.h index a69eced..6ea17c2 100644 --- a/src/gui/graphicsview/qgraphicsitem.h +++ b/src/gui/graphicsview/qgraphicsitem.h @@ -151,6 +151,7 @@ public: QGraphicsItem *parentItem() const; QGraphicsItem *topLevelItem() const; + QGraphicsObject *parentObject() const; QGraphicsWidget *parentWidget() const; QGraphicsWidget *topLevelWidget() const; QGraphicsWidget *window() const; @@ -494,10 +495,12 @@ inline QRectF QGraphicsItem::mapRectFromScene(qreal ax, qreal ay, qreal w, qreal class Q_GUI_EXPORT QGraphicsObject : public QObject, public QGraphicsItem { Q_OBJECT + Q_PROPERTY(QGraphicsObject * parent READ parentObject WRITE setParentItem NOTIFY parentChanged DESIGNABLE false) + Q_PROPERTY(QString id READ objectName WRITE setObjectName) Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged) - Q_PROPERTY(QPointF pos READ pos WRITE setPos) Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged) Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged) + Q_PROPERTY(QPointF pos READ pos WRITE setPos) Q_PROPERTY(qreal x READ x WRITE setX NOTIFY xChanged) Q_PROPERTY(qreal y READ y WRITE setY NOTIFY yChanged) Q_PROPERTY(qreal z READ zValue WRITE setZValue NOTIFY zChanged) @@ -505,6 +508,7 @@ public: QGraphicsObject(QGraphicsItem *parent = 0); Q_SIGNALS: + void parentChanged(); void opacityChanged(); void visibleChanged(); void enabledChanged(); -- cgit v0.12