Consistent naming for (to|from)Is(Defined|Sourced) in animations

To store whether "from" and "to" values are defined and/or sourced,
QQuickPathAnimationUpdater     used fromDefined format,
QQuickAbstractAnimationPrivate used fromIsDefined format,
QQuickAnimationPropertyUpdater used fromIsDefined format,
QQuickAnimatorPrivate          used isFromDefined format,
QQuickBulkValueAnimator        used fromDefined format,
QQuickAnimationPropertyUpdater used fromDefined format.
This patch changes all these to use the variable names
"fromIsDefined", "fromIsSourced", and "toIsDefined".
This makes the code more readable.

Pick-to: 6.0 5.15
Change-Id: Ia6c228208eb651247b0ba70f83afadb5b1027049
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
Andreas Buhr 2021-01-14 16:03:32 +01:00
parent 8deb1b279f
commit 702b00bc8b
6 changed files with 40 additions and 41 deletions

View File

@ -529,8 +529,8 @@ QAbstractAnimationJob* QQuickAnchorAnimation::transition(QQuickStateActions &act
data->interpolatorType = QMetaType::QReal; data->interpolatorType = QMetaType::QReal;
data->interpolator = d->interpolator; data->interpolator = d->interpolator;
data->reverse = direction == Backward ? true : false; data->reverse = direction == Backward ? true : false;
data->fromSourced = false; data->fromIsSourced = false;
data->fromDefined = false; data->fromIsDefined = false;
for (int ii = 0; ii < actions.count(); ++ii) { for (int ii = 0; ii < actions.count(); ++ii) {
QQuickStateAction &action = actions[ii]; QQuickStateAction &action = actions[ii];
@ -543,7 +543,7 @@ QAbstractAnimationJob* QQuickAnchorAnimation::transition(QQuickStateActions &act
QQuickBulkValueAnimator *animator = new QQuickBulkValueAnimator; QQuickBulkValueAnimator *animator = new QQuickBulkValueAnimator;
if (data->actions.count()) { if (data->actions.count()) {
animator->setAnimValue(data); animator->setAnimValue(data);
animator->setFromSourcedValue(&data->fromSourced); animator->setFromIsSourcedValue(&data->fromIsSourced);
} else { } else {
delete data; delete data;
} }
@ -864,9 +864,9 @@ QAbstractAnimationJob* QQuickPathAnimation::transition(QQuickStateActions &actio
data->exitInterval = d->duration ? qreal(d->exitDuration) / d->duration : qreal(0); data->exitInterval = d->duration ? qreal(d->exitDuration) / d->duration : qreal(0);
data->endRotation = d->endRotation; data->endRotation = d->endRotation;
data->reverse = direction == Backward ? true : false; data->reverse = direction == Backward ? true : false;
data->fromSourced = false; data->fromIsSourced = false;
data->fromDefined = (d->path && d->path->hasStartX() && d->path->hasStartY()) ? true : false; data->fromIsDefined = (d->path && d->path->hasStartX() && d->path->hasStartY()) ? true : false;
data->toDefined = d->path ? true : false; data->toIsDefined = d->path ? true : false;
int origModifiedSize = modified.count(); int origModifiedSize = modified.count();
for (int i = 0; i < actions.count(); ++i) { for (int i = 0; i < actions.count(); ++i) {
@ -885,8 +885,7 @@ QAbstractAnimationJob* QQuickPathAnimation::transition(QQuickStateActions &actio
} }
} }
if (target && d->path && if (target && d->path && (modified.count() > origModifiedSize || data->toIsDefined)) {
(modified.count() > origModifiedSize || data->toDefined)) {
data->target = target; data->target = target;
data->path = d->path; data->path = d->path;
data->path->invalidateSequentialHistory(); data->path->invalidateSequentialHistory();
@ -897,13 +896,13 @@ QAbstractAnimationJob* QQuickPathAnimation::transition(QQuickStateActions &actio
// treat interruptions specially, otherwise we end up with strange paths // treat interruptions specially, otherwise we end up with strange paths
if ((data->reverse || prevData.reverse) && prevData.currentV > 0 && prevData.currentV < 1) { if ((data->reverse || prevData.reverse) && prevData.currentV > 0 && prevData.currentV < 1) {
if (!data->fromDefined && !data->toDefined && !prevData.painterPath.isEmpty()) { if (!data->fromIsDefined && !data->toIsDefined && !prevData.painterPath.isEmpty()) {
QPointF pathPos = QQuickPath::sequentialPointAt(prevData.painterPath, prevData.pathLength, prevData.attributePoints, prevData.prevBez, prevData.currentV); QPointF pathPos = QQuickPath::sequentialPointAt(prevData.painterPath, prevData.pathLength, prevData.attributePoints, prevData.prevBez, prevData.currentV);
if (!prevData.anchorPoint.isNull()) if (!prevData.anchorPoint.isNull())
pathPos -= prevData.anchorPoint; pathPos -= prevData.anchorPoint;
if (pathPos == data->target->position()) { //only treat as interruption if we interrupted ourself if (pathPos == data->target->position()) { //only treat as interruption if we interrupted ourself
data->painterPath = prevData.painterPath; data->painterPath = prevData.painterPath;
data->toDefined = data->fromDefined = data->fromSourced = true; data->toIsDefined = data->fromIsDefined = data->fromIsSourced = true;
data->prevBez.isValid = false; data->prevBez.isValid = false;
data->interruptStart = prevData.currentV; data->interruptStart = prevData.currentV;
data->startRotation = prevData.startRotation; data->startRotation = prevData.startRotation;
@ -913,13 +912,13 @@ QAbstractAnimationJob* QQuickPathAnimation::transition(QQuickStateActions &actio
} }
} }
} }
pa->setFromSourcedValue(&data->fromSourced); pa->setFromIsSourcedValue(&data->fromIsSourced);
pa->setAnimValue(data); pa->setAnimValue(data);
pa->setDuration(d->duration); pa->setDuration(d->duration);
pa->setEasingCurve(d->easingCurve); pa->setEasingCurve(d->easingCurve);
return initInstance(pa); return initInstance(pa);
} else { } else {
pa->setFromSourcedValue(nullptr); pa->setFromIsSourcedValue(nullptr);
pa->setAnimValue(nullptr); pa->setAnimValue(nullptr);
delete pa; delete pa;
delete data; delete data;
@ -939,7 +938,7 @@ void QQuickPathAnimationUpdater::setValue(qreal v)
} }
currentV = v; currentV = v;
bool atStart = ((reverse && v == 1.0) || (!reverse && v == 0.0)); bool atStart = ((reverse && v == 1.0) || (!reverse && v == 0.0));
if (!fromSourced && (!fromDefined || !toDefined)) { if (!fromIsSourced && (!fromIsDefined || !toIsDefined)) {
qreal startX = reverse ? toX + anchorPoint.x() : target->x() + anchorPoint.x(); qreal startX = reverse ? toX + anchorPoint.x() : target->x() + anchorPoint.x();
qreal startY = reverse ? toY + anchorPoint.y() : target->y() + anchorPoint.y(); qreal startY = reverse ? toY + anchorPoint.y() : target->y() + anchorPoint.y();
qreal endX = reverse ? target->x() + anchorPoint.x() : toX + anchorPoint.x(); qreal endX = reverse ? target->x() + anchorPoint.x() : toX + anchorPoint.x();
@ -947,7 +946,7 @@ void QQuickPathAnimationUpdater::setValue(qreal v)
prevBez.isValid = false; prevBez.isValid = false;
painterPath = path->createPath(QPointF(startX, startY), QPointF(endX, endY), QStringList(), pathLength, attributePoints); painterPath = path->createPath(QPointF(startX, startY), QPointF(endX, endY), QStringList(), pathLength, attributePoints);
fromSourced = true; fromIsSourced = true;
} }
qreal angle; qreal angle;

View File

@ -92,7 +92,7 @@ class QQuickPathAnimationUpdater : public QQuickBulkValueUpdater
{ {
public: public:
QQuickPathAnimationUpdater() : path(nullptr), pathLength(0), target(nullptr), reverse(false), QQuickPathAnimationUpdater() : path(nullptr), pathLength(0), target(nullptr), reverse(false),
fromSourced(false), fromDefined(false), toDefined(false), fromIsSourced(false), fromIsDefined(false), toIsDefined(false),
toX(0), toY(0), currentV(0), orientation(QQuickPathAnimation::Fixed), toX(0), toY(0), currentV(0), orientation(QQuickPathAnimation::Fixed),
entryInterval(0), exitInterval(0) {} entryInterval(0), exitInterval(0) {}
~QQuickPathAnimationUpdater() {} ~QQuickPathAnimationUpdater() {}
@ -108,9 +108,9 @@ public:
QQuickItem *target; QQuickItem *target;
bool reverse; bool reverse;
bool fromSourced; bool fromIsSourced;
bool fromDefined; bool fromIsDefined;
bool toDefined; bool toIsDefined;
qreal toX; qreal toX;
qreal toY; qreal toY;
qreal currentV; qreal currentV;

View File

@ -1990,7 +1990,7 @@ void QQuickPropertyAnimationPrivate::convertVariant(QVariant &variant, QMetaType
} }
QQuickBulkValueAnimator::QQuickBulkValueAnimator() QQuickBulkValueAnimator::QQuickBulkValueAnimator()
: QAbstractAnimationJob(), animValue(nullptr), fromSourced(nullptr), m_duration(250) : QAbstractAnimationJob(), animValue(nullptr), fromIsSourced(nullptr), m_duration(250)
{ {
} }
@ -2020,8 +2020,8 @@ void QQuickBulkValueAnimator::updateCurrentTime(int currentTime)
void QQuickBulkValueAnimator::topLevelAnimationLoopChanged() void QQuickBulkValueAnimator::topLevelAnimationLoopChanged()
{ {
//check for new from every top-level loop (when the top level animation is started and all subsequent loops) //check for new from every top-level loop (when the top level animation is started and all subsequent loops)
if (fromSourced) if (fromIsSourced)
*fromSourced = false; *fromIsSourced = false;
QAbstractAnimationJob::topLevelAnimationLoopChanged(); QAbstractAnimationJob::topLevelAnimationLoopChanged();
} }
@ -2590,7 +2590,7 @@ void QQuickAnimationPropertyUpdater::setValue(qreal v)
if (v == 1.) { if (v == 1.) {
QQmlPropertyPrivate::write(action.property, action.toValue, QQmlPropertyData::BypassInterceptor | QQmlPropertyData::DontRemoveBinding); QQmlPropertyPrivate::write(action.property, action.toValue, QQmlPropertyData::BypassInterceptor | QQmlPropertyData::DontRemoveBinding);
} else { } else {
if (!fromSourced && !fromDefined) { if (!fromIsSourced && !fromIsDefined) {
action.fromValue = action.property.read(); action.fromValue = action.property.read();
if (interpolatorType) { if (interpolatorType) {
QQuickPropertyAnimationPrivate::convertVariant(action.fromValue, QMetaType(interpolatorType)); QQuickPropertyAnimationPrivate::convertVariant(action.fromValue, QMetaType(interpolatorType));
@ -2610,7 +2610,7 @@ void QQuickAnimationPropertyUpdater::setValue(qreal v)
return; return;
} }
wasDeleted = nullptr; wasDeleted = nullptr;
fromSourced = true; fromIsSourced = true;
} }
void QQuickAnimationPropertyUpdater::debugUpdater(QDebug d, int indentLevel) const void QQuickAnimationPropertyUpdater::debugUpdater(QDebug d, int indentLevel) const
@ -2754,11 +2754,11 @@ QAbstractAnimationJob* QQuickPropertyAnimation::transition(QQuickStateActions &a
data->interpolatorType = d->interpolatorType; data->interpolatorType = d->interpolatorType;
data->interpolator = d->interpolator; data->interpolator = d->interpolator;
data->reverse = direction == Backward ? true : false; data->reverse = direction == Backward ? true : false;
data->fromSourced = false; data->fromIsSourced = false;
data->fromDefined = d->fromIsDefined; data->fromIsDefined = d->fromIsDefined;
data->actions = dataActions; data->actions = dataActions;
animator->setAnimValue(data); animator->setAnimValue(data);
animator->setFromSourcedValue(&data->fromSourced); animator->setFromIsSourcedValue(&data->fromIsSourced);
d->actions = &data->actions; //remove this? d->actions = &data->actions; //remove this?
} }

View File

@ -135,7 +135,7 @@ public:
void setAnimValue(QQuickBulkValueUpdater *value); void setAnimValue(QQuickBulkValueUpdater *value);
QQuickBulkValueUpdater *getAnimValue() const { return animValue; } QQuickBulkValueUpdater *getAnimValue() const { return animValue; }
void setFromSourcedValue(bool *value) { fromSourced = value; } void setFromIsSourcedValue(bool *value) { fromIsSourced = value; }
int duration() const override { return m_duration; } int duration() const override { return m_duration; }
void setDuration(int msecs) { m_duration = msecs; } void setDuration(int msecs) { m_duration = msecs; }
@ -150,7 +150,7 @@ protected:
private: private:
QQuickBulkValueUpdater *animValue; QQuickBulkValueUpdater *animValue;
bool *fromSourced; bool *fromIsSourced;
int m_duration; int m_duration;
QEasingCurve easing; QEasingCurve easing;
}; };
@ -310,7 +310,7 @@ public:
class Q_AUTOTEST_EXPORT QQuickAnimationPropertyUpdater : public QQuickBulkValueUpdater class Q_AUTOTEST_EXPORT QQuickAnimationPropertyUpdater : public QQuickBulkValueUpdater
{ {
public: public:
QQuickAnimationPropertyUpdater() : interpolatorType(0), interpolator(nullptr), prevInterpolatorType(0), reverse(false), fromSourced(false), fromDefined(false), wasDeleted(nullptr) {} QQuickAnimationPropertyUpdater() : interpolatorType(0), interpolator(nullptr), prevInterpolatorType(0), reverse(false), fromIsSourced(false), fromIsDefined(false), wasDeleted(nullptr) {}
~QQuickAnimationPropertyUpdater() override; ~QQuickAnimationPropertyUpdater() override;
void setValue(qreal v) override; void setValue(qreal v) override;
@ -322,8 +322,8 @@ public:
QVariantAnimation::Interpolator interpolator; QVariantAnimation::Interpolator interpolator;
int prevInterpolatorType; //for generic int prevInterpolatorType; //for generic
bool reverse; bool reverse;
bool fromSourced; bool fromIsSourced;
bool fromDefined; bool fromIsDefined;
bool *wasDeleted; bool *wasDeleted;
}; };

View File

@ -176,7 +176,7 @@ void QQuickAnimator::setTo(qreal to)
Q_D(QQuickAnimator); Q_D(QQuickAnimator);
if (to == d->to) if (to == d->to)
return; return;
d->isToDefined = true; d->toIsDefined = true;
d->to = to; d->to = to;
Q_EMIT toChanged(d->to); Q_EMIT toChanged(d->to);
} }
@ -202,7 +202,7 @@ qreal QQuickAnimator::to() const
void QQuickAnimator::setFrom(qreal from) void QQuickAnimator::setFrom(qreal from)
{ {
Q_D(QQuickAnimator); Q_D(QQuickAnimator);
d->isFromDefined = true; d->fromIsDefined = true;
if (from == d->from) if (from == d->from)
return; return;
d->from = from; d->from = from;
@ -231,14 +231,14 @@ void QQuickAnimatorPrivate::apply(QQuickAnimatorJob *job,
job->setTarget(qobject_cast<QQuickItem *>(action.property.object())); job->setTarget(qobject_cast<QQuickItem *>(action.property.object()));
if (isFromDefined) if (fromIsDefined)
job->setFrom(from); job->setFrom(from);
else if (action.fromValue.isValid()) else if (action.fromValue.isValid())
job->setFrom(action.fromValue.toReal()); job->setFrom(action.fromValue.toReal());
else else
job->setFrom(action.property.read().toReal()); job->setFrom(action.property.read().toReal());
if (isToDefined) if (toIsDefined)
job->setTo(to); job->setTo(to);
else if (action.toValue.isValid()) else if (action.toValue.isValid())
job->setTo(action.toValue.toReal()); job->setTo(action.toValue.toReal());
@ -255,7 +255,7 @@ void QQuickAnimatorPrivate::apply(QQuickAnimatorJob *job,
if (modified.isEmpty()) { if (modified.isEmpty()) {
job->setTarget(target); job->setTarget(target);
if (isFromDefined) if (fromIsDefined)
job->setFrom(from); job->setFrom(from);
job->setTo(to); job->setTo(to);
} }
@ -267,7 +267,7 @@ void QQuickAnimatorPrivate::apply(QQuickAnimatorJob *job,
job->setTarget(qobject_cast<QQuickItem *>(defaultTarget)); job->setTarget(qobject_cast<QQuickItem *>(defaultTarget));
} }
if (modified.isEmpty() && !isFromDefined && job->target()) if (modified.isEmpty() && !fromIsDefined && job->target())
job->setFrom(job->target()->property(propertyName.toLatin1()).toReal()); job->setFrom(job->target()->property(propertyName.toLatin1()).toReal());
job->setDuration(duration); job->setDuration(duration);

View File

@ -68,8 +68,8 @@ public:
, duration(250) , duration(250)
, from(0) , from(0)
, to(0) , to(0)
, isFromDefined(false) , fromIsDefined(false)
, isToDefined(false) , toIsDefined(false)
{ {
} }
@ -79,8 +79,8 @@ public:
qreal from; qreal from;
qreal to; qreal to;
uint isFromDefined : 1; uint fromIsDefined : 1;
uint isToDefined : 1; uint toIsDefined : 1;
void apply(QQuickAnimatorJob *job, const QString &propertyName, QQuickStateActions &actions, QQmlProperties &modified, QObject *defaultTarget); void apply(QQuickAnimatorJob *job, const QString &propertyName, QQuickStateActions &actions, QQmlProperties &modified, QObject *defaultTarget);
}; };