statemachine: Small refactoring of animation selection code

QStateMachinePrivate::applyProperties() is an epically long function.
Move the code for selecting animations to a separate function, in
preparation of a larger refactoring.

Change-Id: Ic5846db97dd0cb0d6ad01740f413b233d2a66975
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
This commit is contained in:
Kent Hansen 2012-07-04 21:05:51 +02:00 committed by Qt by Nokia
parent 2f18e72762
commit aa7180ca92
2 changed files with 21 additions and 14 deletions

View File

@ -757,20 +757,7 @@ void QStateMachinePrivate::applyProperties(const QList<QAbstractTransition*> &tr
}
// Find the animations to use for the state change.
QList<QAbstractAnimation*> selectedAnimations;
if (animated) {
for (int i = 0; i < transitionList.size(); ++i) {
QAbstractTransition *transition = transitionList.at(i);
selectedAnimations << transition->animations();
selectedAnimations << defaultAnimationsForSource.values(transition->sourceState());
QList<QAbstractState *> targetStates = transition->targetStates();
for (int j=0; j<targetStates.size(); ++j)
selectedAnimations << defaultAnimationsForTarget.values(targetStates.at(j));
}
selectedAnimations << defaultAnimations;
}
QList<QAbstractAnimation *> selectedAnimations = selectAnimations(transitionList);
// Initialize animations from property assignments.
for (int i = 0; i < selectedAnimations.size(); ++i) {
@ -1153,6 +1140,25 @@ void QStateMachinePrivate::_q_animationFinished()
}
}
QList<QAbstractAnimation *> QStateMachinePrivate::selectAnimations(const QList<QAbstractTransition *> &transitionList) const
{
QList<QAbstractAnimation *> selectedAnimations;
if (animated) {
for (int i = 0; i < transitionList.size(); ++i) {
QAbstractTransition *transition = transitionList.at(i);
selectedAnimations << transition->animations();
selectedAnimations << defaultAnimationsForSource.values(transition->sourceState());
QList<QAbstractState *> targetStates = transition->targetStates();
for (int j=0; j<targetStates.size(); ++j)
selectedAnimations << defaultAnimationsForTarget.values(targetStates.at(j));
}
selectedAnimations << defaultAnimations;
}
return selectedAnimations;
}
#endif // !QT_NO_ANIMATION
namespace {

View File

@ -228,6 +228,7 @@ public:
QMultiHash<QAbstractState *, QAbstractAnimation *> defaultAnimationsForSource;
QMultiHash<QAbstractState *, QAbstractAnimation *> defaultAnimationsForTarget;
QList<QAbstractAnimation *> selectAnimations(const QList<QAbstractTransition *> &transitionList) const;
#endif // QT_NO_ANIMATION
QSignalEventGenerator *signalEventGenerator;