Replace long for-loop-headers with short modern version

Change-Id: I0bf037e0a2483cc6e98a3336f878c46b31f92447
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
Matthias Rauter 2025-05-06 15:20:20 +02:00
parent f9af480ed2
commit 64693034ae

View File

@ -69,8 +69,8 @@ int QParallelAnimationGroup::duration() const
Q_D(const QParallelAnimationGroup); Q_D(const QParallelAnimationGroup);
int ret = 0; int ret = 0;
for (AnimationListConstIt it = d->animations.constBegin(), cend = d->animations.constEnd(); it != cend; ++it) { for (auto ani : std::as_const(d->animations)) {
const int currentDuration = (*it)->totalDuration(); const int currentDuration = ani->totalDuration();
if (currentDuration == -1) if (currentDuration == -1)
return -1; // Undetermined length return -1; // Undetermined length
@ -93,16 +93,14 @@ void QParallelAnimationGroup::updateCurrentTime(int currentTime)
// simulate completion of the loop // simulate completion of the loop
int dura = duration(); int dura = duration();
if (dura > 0) { if (dura > 0) {
for (AnimationListConstIt it = d->animations.constBegin(), cend = d->animations.constEnd(); it != cend; ++it) { for (auto animation : std::as_const(d->animations)) {
QAbstractAnimation *animation = (*it);
if (animation->state() != QAbstractAnimation::Stopped) if (animation->state() != QAbstractAnimation::Stopped)
animation->setCurrentTime(dura); // will stop animation->setCurrentTime(dura); // will stop
} }
} }
} else if (d->currentLoop < d->lastLoop) { } else if (d->currentLoop < d->lastLoop) {
// simulate completion of the loop seeking backwards // simulate completion of the loop seeking backwards
for (AnimationListConstIt it = d->animations.constBegin(), cend = d->animations.constEnd(); it != cend; ++it) { for (auto animation : std::as_const(d->animations)) {
QAbstractAnimation *animation = *it;
//we need to make sure the animation is in the right state //we need to make sure the animation is in the right state
//and then rewind it //and then rewind it
d->applyGroupState(animation); d->applyGroupState(animation);
@ -116,8 +114,7 @@ void QParallelAnimationGroup::updateCurrentTime(int currentTime)
__LINE__, d->currentTime, d->currentLoop, d->lastLoop, timeFwd, d->lastCurrentTime, state()); __LINE__, d->currentTime, d->currentLoop, d->lastLoop, timeFwd, d->lastCurrentTime, state());
#endif #endif
// finally move into the actual time of the current loop // finally move into the actual time of the current loop
for (AnimationListConstIt it = d->animations.constBegin(), cend = d->animations.constEnd(); it != cend; ++it) { for (auto animation : std::as_const(d->animations)) {
QAbstractAnimation *animation = *it;
const int dura = animation->totalDuration(); const int dura = animation->totalDuration();
//if the loopcount is bigger we should always start all animations //if the loopcount is bigger we should always start all animations
if (d->currentLoop > d->lastLoop if (d->currentLoop > d->lastLoop
@ -148,20 +145,19 @@ void QParallelAnimationGroup::updateState(QAbstractAnimation::State newState,
switch (newState) { switch (newState) {
case Stopped: case Stopped:
for (AnimationListConstIt it = d->animations.constBegin(), cend = d->animations.constEnd(); it != cend; ++it) for (auto ani : std::as_const(d->animations))
(*it)->stop(); ani->stop();
d->disconnectUncontrolledAnimations(); d->disconnectUncontrolledAnimations();
break; break;
case Paused: case Paused:
for (AnimationListConstIt it = d->animations.constBegin(), cend = d->animations.constEnd(); it != cend; ++it) { for (auto ani : std::as_const(d->animations)) {
if ((*it)->state() == Running) if (ani->state() == Running)
(*it)->pause(); ani->pause();
} }
break; break;
case Running: case Running:
d->connectUncontrolledAnimations(); d->connectUncontrolledAnimations();
for (AnimationListConstIt it = d->animations.constBegin(), cend = d->animations.constEnd(); it != cend; ++it) { for (auto animation : std::as_const(d->animations)) {
QAbstractAnimation *animation = *it;
if (oldState == Stopped) if (oldState == Stopped)
animation->stop(); animation->stop();
animation->setDirection(d->direction); animation->setDirection(d->direction);
@ -194,8 +190,8 @@ void QParallelAnimationGroupPrivate::_q_uncontrolledAnimationFinished()
return; return;
int maxDuration = 0; int maxDuration = 0;
for (AnimationListConstIt it = animations.constBegin(), cend = animations.constEnd(); it != cend; ++it) for (auto ani : std::as_const(animations))
maxDuration = qMax(maxDuration, (*it)->totalDuration()); maxDuration = qMax(maxDuration, ani->totalDuration());
if (currentTime >= maxDuration) if (currentTime >= maxDuration)
q->stop(); q->stop();
@ -211,8 +207,7 @@ void QParallelAnimationGroupPrivate::disconnectUncontrolledAnimations()
void QParallelAnimationGroupPrivate::connectUncontrolledAnimations() void QParallelAnimationGroupPrivate::connectUncontrolledAnimations()
{ {
for (AnimationListConstIt it = animations.constBegin(), cend = animations.constEnd(); it != cend; ++it) { for (auto animation : std::as_const(animations)) {
QAbstractAnimation *animation = *it;
if (animation->duration() == -1 || animation->loopCount() < 0) { if (animation->duration() == -1 || animation->loopCount() < 0) {
uncontrolledFinishTime[animation] = -1; uncontrolledFinishTime[animation] = -1;
connectUncontrolledAnimation(animation); connectUncontrolledAnimation(animation);
@ -270,8 +265,8 @@ void QParallelAnimationGroup::updateDirection(QAbstractAnimation::Direction dire
Q_D(QParallelAnimationGroup); Q_D(QParallelAnimationGroup);
//we need to update the direction of the current animation //we need to update the direction of the current animation
if (state() != Stopped) { if (state() != Stopped) {
for (AnimationListConstIt it = d->animations.constBegin(), cend = d->animations.constEnd(); it != cend; ++it) for (auto ani : std::as_const(d->animations))
(*it)->setDirection(direction); ani->setDirection(direction);
} else { } else {
if (direction == Forward) { if (direction == Forward) {
d->lastLoop = 0; d->lastLoop = 0;