From b8952aef84c78949959728674db39eafb19efee7 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Fri, 26 Mar 2010 17:02:53 +1000 Subject: Test and fix order of transform application. Remove Translate.z since Qt cannot sensibly support it yet. --- src/declarative/graphicsitems/qdeclarativeitem.cpp | 9 +++--- .../graphicsitems/qdeclarativetranslate.cpp | 33 +++------------------- .../graphicsitems/qdeclarativetranslate_p.h | 4 --- src/gui/graphicsview/qgraphicsitem.cpp | 16 +++++++++++ src/gui/graphicsview/qgraphicsitem_p.h | 1 + .../qdeclarativeitem/tst_qdeclarativeitem.cpp | 14 ++++++--- 6 files changed, 36 insertions(+), 41 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp index 048e1a8..611535c 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp @@ -89,11 +89,12 @@ QT_BEGIN_NAMESPACE /*! \qmlclass Translate QGraphicsTranslate \since 4.7 - \brief The Translate object provides a way to move an Item without changing its x or y. + \brief The Translate object provides a way to move an Item without changing its x or y properties. The Translate object independent control over position in addition to the Item's x and y properties. - The following example moves the X axis of the Rectangle, relative to its interior point 25, 25: + The following example moves the Y axis of the Rectangles while still allowing the Row element + to lay the items out as if they had not been transformed: \qml Row { Rectangle { @@ -1562,8 +1563,8 @@ int QDeclarativeItemPrivate::transform_count(QDeclarativeListProperty *list, QGraphicsTransform *item) { QGraphicsObject *object = qobject_cast(list->object); - if (object) - QGraphicsItemPrivate::get(object)->appendGraphicsTransform(item); + if (object) // QGraphicsItem applies the list in the wrong order, so we prepend. + QGraphicsItemPrivate::get(object)->prependGraphicsTransform(item); } QGraphicsTransform *QDeclarativeItemPrivate::transform_at(QDeclarativeListProperty *list, int idx) diff --git a/src/declarative/graphicsitems/qdeclarativetranslate.cpp b/src/declarative/graphicsitems/qdeclarativetranslate.cpp index dd6ca92..1c96fa4 100644 --- a/src/declarative/graphicsitems/qdeclarativetranslate.cpp +++ b/src/declarative/graphicsitems/qdeclarativetranslate.cpp @@ -50,10 +50,9 @@ class QDeclarativeTranslatePrivate : public QGraphicsTransformPrivate { public: QDeclarativeTranslatePrivate() - : x(0), y(0), z(0) {} + : x(0), y(0) {} qreal x; qreal y; - qreal z; }; /*! @@ -77,7 +76,7 @@ QDeclarativeTranslate::~QDeclarativeTranslate() The translation can be any real number; the default value is 0.0. - \sa y, z + \sa y */ qreal QDeclarativeTranslate::x() const { @@ -100,7 +99,7 @@ void QDeclarativeTranslate::setX(qreal x) The translation can be any real number; the default value is 0.0. - \sa x, z + \sa x */ qreal QDeclarativeTranslate::y() const { @@ -118,35 +117,12 @@ void QDeclarativeTranslate::setY(qreal y) } /*! - \property QDeclarativeTranslate::z - \brief the depth translation. - - The translation can be any real number; the default value is 0.0. - - \sa x, y -*/ -qreal QDeclarativeTranslate::z() const -{ - Q_D(const QDeclarativeTranslate); - return d->z; -} -void QDeclarativeTranslate::setZ(qreal z) -{ - Q_D(QDeclarativeTranslate); - if (d->z == z) - return; - d->z = z; - update(); - emit positionChanged(); -} - -/*! \reimp */ void QDeclarativeTranslate::applyTo(QMatrix4x4 *matrix) const { Q_D(const QDeclarativeTranslate); - matrix->translate(d->x, d->y, d->z); + matrix->translate(d->x, d->y, 0); } /*! @@ -155,7 +131,6 @@ void QDeclarativeTranslate::applyTo(QMatrix4x4 *matrix) const QDeclarativeTranslate emits this signal when its position changes. \sa QDeclarativeTranslate::x, QDeclarativeTranslate::y - \sa QDeclarativeTranslate::z */ QT_END_NAMESPACE diff --git a/src/declarative/graphicsitems/qdeclarativetranslate_p.h b/src/declarative/graphicsitems/qdeclarativetranslate_p.h index 54bfc3d..1371f71 100644 --- a/src/declarative/graphicsitems/qdeclarativetranslate_p.h +++ b/src/declarative/graphicsitems/qdeclarativetranslate_p.h @@ -58,7 +58,6 @@ class Q_GUI_EXPORT QDeclarativeTranslate : public QGraphicsTransform Q_PROPERTY(qreal x READ x WRITE setX NOTIFY positionChanged) Q_PROPERTY(qreal y READ y WRITE setY NOTIFY positionChanged) - Q_PROPERTY(qreal z READ z WRITE setZ NOTIFY positionChanged) public: QDeclarativeTranslate(QObject *parent = 0); @@ -70,9 +69,6 @@ public: qreal y() const; void setY(qreal); - qreal z() const; - void setZ(qreal); - void applyTo(QMatrix4x4 *matrix) const; Q_SIGNALS: diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index b407eef..36203de 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -3843,6 +3843,22 @@ void QGraphicsItem::setTransformations(const QList &transf /*! \internal */ +void QGraphicsItemPrivate::prependGraphicsTransform(QGraphicsTransform *t) +{ + if (!transformData) + transformData = new QGraphicsItemPrivate::TransformData; + if (!transformData->graphicsTransforms.contains(t)) + transformData->graphicsTransforms.prepend(t); + + Q_Q(QGraphicsItem); + t->d_func()->setItem(q); + transformData->onlyTransform = false; + dirtySceneTransform = 1; +} + +/*! + \internal +*/ void QGraphicsItemPrivate::appendGraphicsTransform(QGraphicsTransform *t) { if (!transformData) diff --git a/src/gui/graphicsview/qgraphicsitem_p.h b/src/gui/graphicsview/qgraphicsitem_p.h index b53c545..b6be79d 100644 --- a/src/gui/graphicsview/qgraphicsitem_p.h +++ b/src/gui/graphicsview/qgraphicsitem_p.h @@ -276,6 +276,7 @@ public: virtual void setPosHelper(const QPointF &pos); void setTransformHelper(const QTransform &transform); + void prependGraphicsTransform(QGraphicsTransform *t); void appendGraphicsTransform(QGraphicsTransform *t); void setVisibleHelper(bool newVisible, bool explicitly, bool update = true); void setEnabledHelper(bool newEnabled, bool explicitly, bool update = true); diff --git a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp index d800411..46f3517 100644 --- a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp +++ b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp @@ -408,9 +408,14 @@ void tst_QDeclarativeItem::transforms_data() { QTest::addColumn("qml"); QTest::addColumn("matrix"); - QTest::newRow("translate") << QByteArray("import Qt 4.6\nItem { transform: Translate { x: 10; y: 20 } }") << QMatrix(1,0,0,1,10,20); - QTest::newRow("rotation") << QByteArray("import Qt 4.6\nItem { transform: Rotation { angle: 90 } }") << QMatrix(0,1,-1,0,0,0); - QTest::newRow("scale") << QByteArray("import Qt 4.6\nItem { transform: Scale { xScale: 1.5; yScale: -2 } }") << QMatrix(1.5,0,0,-2,0,0); + QTest::newRow("translate") << QByteArray("Translate { x: 10; y: 20 }") + << QMatrix(1,0,0,1,10,20); + QTest::newRow("rotation") << QByteArray("Rotation { angle: 90 }") + << QMatrix(0,1,-1,0,0,0); + QTest::newRow("scale") << QByteArray("Scale { xScale: 1.5; yScale: -2 }") + << QMatrix(1.5,0,0,-2,0,0); + QTest::newRow("sequence") << QByteArray("[ Translate { x: 10; y: 20 }, Scale { xScale: 1.5; yScale: -2 } ]") + << QMatrix(1,0,0,1,10,20) * QMatrix(1.5,0,0,-2,0,0); } void tst_QDeclarativeItem::transforms() @@ -418,8 +423,9 @@ void tst_QDeclarativeItem::transforms() QFETCH(QByteArray, qml); QFETCH(QMatrix, matrix); QDeclarativeComponent component(&engine); - component.setData(qml, QUrl::fromLocalFile("")); + component.setData("import Qt 4.6\nItem { transform: "+qml+"}", QUrl::fromLocalFile("")); QDeclarativeItem *item = qobject_cast(component.create()); + QVERIFY(item); QCOMPARE(item->sceneMatrix(), matrix); } -- cgit v0.12