From 656ce9fa9dd1a5cb268f8e3225b2ed65c05365db Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sat, 9 Feb 2019 11:14:37 +0100 Subject: [PATCH] QGraphicsItemAnimation: add transformAt() an deprecate matrixAt() Replace QGraphicsItemAnimation::matrixAt(qreal) with transformAt(qreal) to avoid the usage of QMatrix which is deprecated. Change-Id: Iafcdf8b9b2fbffffa61417601a3ae4272d0176c6 Reviewed-by: Allan Sandfeld Jensen --- src/widgets/doc/snippets/timeline/main.cpp | 4 +-- .../graphicsview/qgraphicsitemanimation.cpp | 33 ++++++++++++++----- .../graphicsview/qgraphicsitemanimation.h | 5 +++ .../tst_qgraphicsitemanimation.cpp | 6 ++-- 4 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src/widgets/doc/snippets/timeline/main.cpp b/src/widgets/doc/snippets/timeline/main.cpp index 74aa749254..4dfa2400d0 100644 --- a/src/widgets/doc/snippets/timeline/main.cpp +++ b/src/widgets/doc/snippets/timeline/main.cpp @@ -48,7 +48,7 @@ ** ****************************************************************************/ -#include +#include #include int main(int argv, char *args[]) @@ -68,7 +68,7 @@ int main(int argv, char *args[]) for (int i = 0; i < 200; ++i) animation->setPosAt(i / 200.0, QPointF(i, i)); - QGraphicsScene *scene = new QGraphicsScene(); + QGraphicsScene *scene = new QGraphicsScene; scene->setSceneRect(0, 0, 250, 250); scene->addItem(ball); diff --git a/src/widgets/graphicsview/qgraphicsitemanimation.cpp b/src/widgets/graphicsview/qgraphicsitemanimation.cpp index 78b91d5c39..ad77e2f260 100644 --- a/src/widgets/graphicsview/qgraphicsitemanimation.cpp +++ b/src/widgets/graphicsview/qgraphicsitemanimation.cpp @@ -115,7 +115,7 @@ public: QGraphicsItem *item; QPointF startPos; - QMatrix startMatrix; + QTransform startTransform; qreal step; @@ -294,23 +294,38 @@ QList > QGraphicsItemAnimation::posList() const return list; } +#if QT_DEPRECATED_SINCE(5, 14) /*! Returns the matrix used to transform the item at the specified \a step value. + + \obsolete Use transformAt() instead */ QMatrix QGraphicsItemAnimation::matrixAt(qreal step) const { check_step_valid(step, "matrixAt"); + return transformAt(step).toAffine(); +} +#endif - QMatrix matrix; +/*! + Returns the transform used for the item at the specified \a step value. + + \since 5.14 +*/ +QTransform QGraphicsItemAnimation::transformAt(qreal step) const +{ + check_step_valid(step, "transformAt"); + + QTransform transform; if (!d->rotation.isEmpty()) - matrix.rotate(rotationAt(step)); + transform.rotate(rotationAt(step)); if (!d->verticalScale.isEmpty()) - matrix.scale(horizontalScaleAt(step), verticalScaleAt(step)); + transform.scale(horizontalScaleAt(step), verticalScaleAt(step)); if (!d->verticalShear.isEmpty()) - matrix.shear(horizontalShearAt(step), verticalShearAt(step)); + transform.shear(horizontalShearAt(step), verticalShearAt(step)); if (!d->xTranslation.isEmpty()) - matrix.translate(xTranslationAt(step), yTranslationAt(step)); - return matrix; + transform.translate(xTranslationAt(step), yTranslationAt(step)); + return transform; } /*! @@ -542,7 +557,7 @@ void QGraphicsItemAnimation::setStep(qreal step) || !d->horizontalShear.isEmpty() || !d->xTranslation.isEmpty() || !d->yTranslation.isEmpty()) { - d->item->setMatrix(d->startMatrix * matrixAt(step)); + d->item->setTransform(d->startTransform * transformAt(step)); } } @@ -562,7 +577,7 @@ void QGraphicsItemAnimation::reset() if (!d->item) return; d->startPos = d->item->pos(); - d->startMatrix = d->item->matrix(); + d->startTransform = d->item->transform(); } #endif diff --git a/src/widgets/graphicsview/qgraphicsitemanimation.h b/src/widgets/graphicsview/qgraphicsitemanimation.h index f983bd8026..3051fb2e2b 100644 --- a/src/widgets/graphicsview/qgraphicsitemanimation.h +++ b/src/widgets/graphicsview/qgraphicsitemanimation.h @@ -51,6 +51,7 @@ class QGraphicsItem; class QMatrix; class QPointF; class QTimeLine; +class QTransform; template struct QPair; class QGraphicsItemAnimationPrivate; @@ -71,7 +72,11 @@ public: QList > posList() const; void setPosAt(qreal step, const QPointF &pos); +#if QT_DEPRECATED_SINCE(5, 14) + QT_DEPRECATED_X("Use transformAt() instead") QMatrix matrixAt(qreal step) const; +#endif + QTransform transformAt(qreal step) const; qreal rotationAt(qreal step) const; QList > rotationList() const; diff --git a/tests/auto/widgets/graphicsview/qgraphicsitemanimation/tst_qgraphicsitemanimation.cpp b/tests/auto/widgets/graphicsview/qgraphicsitemanimation/tst_qgraphicsitemanimation.cpp index dfb2752ee0..ed79904ed8 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitemanimation/tst_qgraphicsitemanimation.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitemanimation/tst_qgraphicsitemanimation.cpp @@ -54,9 +54,9 @@ void tst_QGraphicsItemAnimation::construction() QCOMPARE(animation.posAt(0), QPointF()); QCOMPARE(animation.posAt(0.5), QPointF()); QCOMPARE(animation.posAt(1), QPointF()); - QCOMPARE(animation.matrixAt(0), QMatrix()); - QCOMPARE(animation.matrixAt(0.5), QMatrix()); - QCOMPARE(animation.matrixAt(1), QMatrix()); + QCOMPARE(animation.transformAt(0), QTransform()); + QCOMPARE(animation.transformAt(0.5), QTransform()); + QCOMPARE(animation.transformAt(1), QTransform()); QCOMPARE(animation.rotationAt(0), qreal(0.0)); QCOMPARE(animation.rotationAt(0.5), qreal(0.0)); QCOMPARE(animation.rotationAt(1), qreal(0.0));