From d0b419e35521d50f1409de84f99ded3b9a7ab01d Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 7 Oct 2013 00:11:49 +0200 Subject: QGraphicsItemAnimation: save some string data (text size -= 1K) Also changed the 'step' range check to treat NaNs as invalid, too. Change-Id: I993c5efffcf7140fba8f80a7db499cd2335867e0 Reviewed-by: Stephen Kelly --- .../graphicsview/qgraphicsitemanimation.cpp | 63 +++++++++------------- 1 file changed, 26 insertions(+), 37 deletions(-) (limited to 'src/widgets/graphicsview') diff --git a/src/widgets/graphicsview/qgraphicsitemanimation.cpp b/src/widgets/graphicsview/qgraphicsitemanimation.cpp index 5dc3e1159e..ff98c147fe 100644 --- a/src/widgets/graphicsview/qgraphicsitemanimation.cpp +++ b/src/widgets/graphicsview/qgraphicsitemanimation.cpp @@ -97,6 +97,15 @@ QT_BEGIN_NAMESPACE +static inline bool check_step_valid(qreal step, const char *method) +{ + if (!(step >= 0 && step <= 1)) { + qWarning("QGraphicsItemAnimation::%s: invalid step = %f", method, step); + return false; + } + return true; +} + class QGraphicsItemAnimationPrivate { public: @@ -169,10 +178,8 @@ qreal QGraphicsItemAnimationPrivate::linearValueForStep(qreal step, QList void QGraphicsItemAnimationPrivate::insertUniquePair(qreal step, qreal value, QList *binList, const char* method) { - if (step < 0.0 || step > 1.0) { - qWarning("QGraphicsItemAnimation::%s: invalid step = %f", method, step); + if (!check_step_valid(step, method)) return; - } Pair pair(step, value); @@ -259,9 +266,7 @@ void QGraphicsItemAnimation::setTimeLine(QTimeLine *timeLine) */ QPointF QGraphicsItemAnimation::posAt(qreal step) const { - if (step < 0.0 || step > 1.0) - qWarning("QGraphicsItemAnimation::posAt: invalid step = %f", step); - + check_step_valid(step, "posAt"); return QPointF(d->linearValueForStep(step, &d->xPosition, d->startPos.x()), d->linearValueForStep(step, &d->yPosition, d->startPos.y())); } @@ -298,8 +303,7 @@ QList > QGraphicsItemAnimation::posList() const */ QMatrix QGraphicsItemAnimation::matrixAt(qreal step) const { - if (step < 0.0 || step > 1.0) - qWarning("QGraphicsItemAnimation::matrixAt: invalid step = %f", step); + check_step_valid(step, "matrixAt"); QMatrix matrix; if (!d->rotation.isEmpty()) @@ -320,9 +324,7 @@ QMatrix QGraphicsItemAnimation::matrixAt(qreal step) const */ qreal QGraphicsItemAnimation::rotationAt(qreal step) const { - if (step < 0.0 || step > 1.0) - qWarning("QGraphicsItemAnimation::rotationAt: invalid step = %f", step); - + check_step_valid(step, "rotationAt"); return d->linearValueForStep(step, &d->rotation); } @@ -357,9 +359,7 @@ QList > QGraphicsItemAnimation::rotationList() const */ qreal QGraphicsItemAnimation::xTranslationAt(qreal step) const { - if (step < 0.0 || step > 1.0) - qWarning("QGraphicsItemAnimation::xTranslationAt: invalid step = %f", step); - + check_step_valid(step, "xTranslationAt"); return d->linearValueForStep(step, &d->xTranslation); } @@ -370,9 +370,7 @@ qreal QGraphicsItemAnimation::xTranslationAt(qreal step) const */ qreal QGraphicsItemAnimation::yTranslationAt(qreal step) const { - if (step < 0.0 || step > 1.0) - qWarning("QGraphicsItemAnimation::yTranslationAt: invalid step = %f", step); - + check_step_valid(step, "yTranslationAt"); return d->linearValueForStep(step, &d->yTranslation); } @@ -409,8 +407,7 @@ QList > QGraphicsItemAnimation::translationList() const */ qreal QGraphicsItemAnimation::verticalScaleAt(qreal step) const { - if (step < 0.0 || step > 1.0) - qWarning("QGraphicsItemAnimation::verticalScaleAt: invalid step = %f", step); + check_step_valid(step, "verticalScaleAt"); return d->linearValueForStep(step, &d->verticalScale, 1); } @@ -422,9 +419,7 @@ qreal QGraphicsItemAnimation::verticalScaleAt(qreal step) const */ qreal QGraphicsItemAnimation::horizontalScaleAt(qreal step) const { - if (step < 0.0 || step > 1.0) - qWarning("QGraphicsItemAnimation::horizontalScaleAt: invalid step = %f", step); - + check_step_valid(step, "horizontalScaleAt"); return d->linearValueForStep(step, &d->horizontalScale, 1); } @@ -461,9 +456,7 @@ QList > QGraphicsItemAnimation::scaleList() const */ qreal QGraphicsItemAnimation::verticalShearAt(qreal step) const { - if (step < 0.0 || step > 1.0) - qWarning("QGraphicsItemAnimation::verticalShearAt: invalid step = %f", step); - + check_step_valid(step, "verticalShearAt"); return d->linearValueForStep(step, &d->verticalShear, 0); } @@ -474,9 +467,7 @@ qreal QGraphicsItemAnimation::verticalShearAt(qreal step) const */ qreal QGraphicsItemAnimation::horizontalShearAt(qreal step) const { - if (step < 0.0 || step > 1.0) - qWarning("QGraphicsItemAnimation::horizontalShearAt: invalid step = %f", step); - + check_step_valid(step, "horizontalShearAt"); return d->linearValueForStep(step, &d->horizontalShear, 0); } @@ -529,19 +520,17 @@ void QGraphicsItemAnimation::clear() Sets the current \a step value for the animation, causing the transformations scheduled at this step to be performed. */ -void QGraphicsItemAnimation::setStep(qreal x) +void QGraphicsItemAnimation::setStep(qreal step) { - if (x < 0.0 || x > 1.0) { - qWarning("QGraphicsItemAnimation::setStep: invalid step = %f", x); + if (!check_step_valid(step, "setStep")) return; - } - beforeAnimationStep(x); + beforeAnimationStep(step); - d->step = x; + d->step = step; if (d->item) { if (!d->xPosition.isEmpty() || !d->yPosition.isEmpty()) - d->item->setPos(posAt(x)); + d->item->setPos(posAt(step)); if (!d->rotation.isEmpty() || !d->verticalScale.isEmpty() || !d->horizontalScale.isEmpty() @@ -549,11 +538,11 @@ void QGraphicsItemAnimation::setStep(qreal x) || !d->horizontalShear.isEmpty() || !d->xTranslation.isEmpty() || !d->yTranslation.isEmpty()) { - d->item->setMatrix(d->startMatrix * matrixAt(x)); + d->item->setMatrix(d->startMatrix * matrixAt(step)); } } - afterAnimationStep(x); + afterAnimationStep(step); } /*! -- cgit v1.2.3