summaryrefslogtreecommitdiffstats
path: root/src/gui/graphicsview
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@nokia.com>2009-06-04 12:38:05 (GMT)
committerAndreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com>2009-06-11 09:49:24 (GMT)
commitb3ff3392128c9c701b687887ef2c21b000209908 (patch)
tree3a89eb4bab5234c4458040d80cbb87c5d4e2f6c0 /src/gui/graphicsview
parente9876fdfaece0dcb09188cb4ddd5801ebb588647 (diff)
downloadQt-b3ff3392128c9c701b687887ef2c21b000209908.zip
Qt-b3ff3392128c9c701b687887ef2c21b000209908.tar.gz
Qt-b3ff3392128c9c701b687887ef2c21b000209908.tar.bz2
added properties for x,y and z. Removed the notify for the pos property,
add auto tests for QGraphicsObject FX items are better off with property notifications on each component rather than on the position. Added some basic testing for QGraphicsObject and fixed the failures exposed. Reviewed-by: Andreas
Diffstat (limited to 'src/gui/graphicsview')
-rw-r--r--src/gui/graphicsview/qgraphicsitem.cpp47
-rw-r--r--src/gui/graphicsview/qgraphicsitem.h13
-rw-r--r--src/gui/graphicsview/qgraphicswidget.h1
3 files changed, 49 insertions, 12 deletions
diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp
index 6d87c36..3622c82 100644
--- a/src/gui/graphicsview/qgraphicsitem.cpp
+++ b/src/gui/graphicsview/qgraphicsitem.cpp
@@ -1789,6 +1789,9 @@ void QGraphicsItemPrivate::setVisibleHelper(bool newVisible, bool explicitly, bo
// Deliver post-change notification.
q_ptr->itemChange(QGraphicsItem::ItemVisibleHasChanged, newVisibleVariant);
+
+ if (isObject)
+ emit static_cast<QGraphicsObject *>(q_ptr)->visibleChanged();
}
/*!
@@ -1821,9 +1824,6 @@ void QGraphicsItemPrivate::setVisibleHelper(bool newVisible, bool explicitly, bo
void QGraphicsItem::setVisible(bool visible)
{
d_ptr->setVisibleHelper(visible, /* explicit = */ true);
-
- if (d_ptr->isObject)
- emit static_cast<QGraphicsObject *>(this)->visibleChanged();
}
/*!
@@ -1912,6 +1912,9 @@ void QGraphicsItemPrivate::setEnabledHelper(bool newEnabled, bool explicitly, bo
// Deliver post-change notification.
q_ptr->itemChange(QGraphicsItem::ItemEnabledHasChanged, newEnabledVariant);
+
+ if (isObject)
+ emit static_cast<QGraphicsObject *>(q_ptr)->enabledChanged();
}
/*!
@@ -1945,9 +1948,6 @@ void QGraphicsItemPrivate::setEnabledHelper(bool newEnabled, bool explicitly, bo
void QGraphicsItem::setEnabled(bool enabled)
{
d_ptr->setEnabledHelper(enabled, /* explicitly = */ true);
-
- if (d_ptr->isObject)
- emit static_cast<QGraphicsObject *>(this)->enabledChanged();
}
/*!
@@ -2110,6 +2110,7 @@ void QGraphicsItem::setOpacity(qreal opacity)
/*maybeDirtyClipPath=*/false,
/*force=*/false,
/*ignoreOpacity=*/true);
+
if (d_ptr->isObject)
emit static_cast<QGraphicsObject *>(this)->opacityChanged();
}
@@ -2520,6 +2521,17 @@ QPointF QGraphicsItem::pos() const
\sa y()
*/
+/*
+ Set's the x coordinate of the item's position. Equivalent to
+ calling setPos(x, y()).
+
+ \sa x(), setPos()
+*/
+void QGraphicsItem::setX(qreal x)
+{
+ d_ptr->setPosHelper(QPointF(x, d_ptr->pos.y()));
+}
+
/*!
\fn QGraphicsItem::y() const
@@ -2528,6 +2540,17 @@ QPointF QGraphicsItem::pos() const
\sa x()
*/
+/*
+ Set's the y coordinate of the item's position. Equivalent to
+ calling setPos(x(), y).
+
+ \sa x(), setPos()
+*/
+void QGraphicsItem::setY(qreal y)
+{
+ d_ptr->setPosHelper(QPointF(d_ptr->pos.x(), y));
+}
+
/*!
Returns the item's position in scene coordinates. This is
equivalent to calling \c mapToScene(0, 0).
@@ -2551,11 +2574,16 @@ void QGraphicsItemPrivate::setPosHelper(const QPointF &pos)
updateCachedClipPathFromSetPosHelper(pos);
if (scene)
q->prepareGeometryChange();
+ QPointF oldPos = this->pos;
this->pos = pos;
dirtySceneTransform = 1;
inSetPosHelper = 0;
- if (isObject)
- emit static_cast<QGraphicsObject *>(q)->positionChanged();
+ if (isObject) {
+ if (pos.x() != oldPos.x())
+ emit static_cast<QGraphicsObject *>(q_ptr)->xChanged();
+ if (pos.y() != oldPos.y())
+ emit static_cast<QGraphicsObject *>(q_ptr)->yChanged();
+ }
}
/*!
@@ -3535,6 +3563,9 @@ void QGraphicsItem::setZValue(qreal z)
}
itemChange(ItemZValueHasChanged, newZVariant);
+
+ if (d_ptr->isObject)
+ emit static_cast<QGraphicsObject *>(this)->zChanged();
}
/*!
diff --git a/src/gui/graphicsview/qgraphicsitem.h b/src/gui/graphicsview/qgraphicsitem.h
index a5ccef2..a69eced 100644
--- a/src/gui/graphicsview/qgraphicsitem.h
+++ b/src/gui/graphicsview/qgraphicsitem.h
@@ -227,7 +227,9 @@ public:
// Positioning in scene coordinates
QPointF pos() const;
inline qreal x() const { return pos().x(); }
+ void setX(qreal x);
inline qreal y() const { return pos().y(); }
+ void setY(qreal y);
QPointF scenePos() const;
void setPos(const QPointF &pos);
inline void setPos(qreal x, qreal y);
@@ -492,11 +494,13 @@ inline QRectF QGraphicsItem::mapRectFromScene(qreal ax, qreal ay, qreal w, qreal
class Q_GUI_EXPORT QGraphicsObject : public QObject, public QGraphicsItem
{
Q_OBJECT
- Q_INTERFACES(QGraphicsItem)
Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged)
- Q_PROPERTY(QPointF pos READ pos WRITE setPos NOTIFY positionChanged)
+ 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(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)
public:
QGraphicsObject(QGraphicsItem *parent = 0);
@@ -504,12 +508,15 @@ Q_SIGNALS:
void opacityChanged();
void visibleChanged();
void enabledChanged();
- void positionChanged();
+ void xChanged();
+ void yChanged();
+ void zChanged();
protected:
QGraphicsObject(QGraphicsItemPrivate &dd, QGraphicsItem *parent, QGraphicsScene *scene);
private:
friend class QGraphicsItem;
+ friend class QGraphicsItemPrivate;
};
diff --git a/src/gui/graphicsview/qgraphicswidget.h b/src/gui/graphicsview/qgraphicswidget.h
index e19513d..337490c 100644
--- a/src/gui/graphicsview/qgraphicswidget.h
+++ b/src/gui/graphicsview/qgraphicswidget.h
@@ -69,7 +69,6 @@ class QGraphicsWidgetPrivate;
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)