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 <allan.jensen@qt.io>
This commit is contained in:
Christian Ehrlicher 2019-02-09 11:14:37 +01:00
parent 2be7746e09
commit 656ce9fa9d
4 changed files with 34 additions and 14 deletions

View File

@ -48,7 +48,7 @@
**
****************************************************************************/
#include <QtGui>
#include <QtWidgets>
#include <math.h>
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);

View File

@ -115,7 +115,7 @@ public:
QGraphicsItem *item;
QPointF startPos;
QMatrix startMatrix;
QTransform startTransform;
qreal step;
@ -294,23 +294,38 @@ QList<QPair<qreal, QPointF> > 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

View File

@ -51,6 +51,7 @@ class QGraphicsItem;
class QMatrix;
class QPointF;
class QTimeLine;
class QTransform;
template <class T1, class T2> struct QPair;
class QGraphicsItemAnimationPrivate;
@ -71,7 +72,11 @@ public:
QList<QPair<qreal, QPointF> > 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<QPair<qreal, qreal> > rotationList() const;

View File

@ -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));