summaryrefslogtreecommitdiffstats
path: root/src/corelib/statemachine/qstatemachine.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/statemachine/qstatemachine.cpp')
-rw-r--r--src/corelib/statemachine/qstatemachine.cpp121
1 files changed, 62 insertions, 59 deletions
diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp
index 63cf7672cf..62a4c03d26 100644
--- a/src/corelib/statemachine/qstatemachine.cpp
+++ b/src/corelib/statemachine/qstatemachine.cpp
@@ -1,31 +1,37 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL21$
+** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
@@ -294,7 +300,7 @@ static inline bool isDescendant(const QAbstractState *state1, const QAbstractSta
static bool containsDecendantOf(const QSet<QAbstractState *> &states, const QAbstractState *node)
{
- foreach (QAbstractState *s, states)
+ for (QAbstractState *s : states)
if (isDescendant(s, node))
return true;
@@ -361,7 +367,8 @@ static QList<QAbstractState *> getEffectiveTargetStates(QAbstractTransition *tra
return targetsList;
QSet<QAbstractState *> targets;
- foreach (QAbstractState *s, transition->targetStates()) {
+ const auto targetStates = transition->targetStates();
+ for (QAbstractState *s : targetStates) {
if (QHistoryState *historyState = QStateMachinePrivate::toHistoryState(s)) {
QList<QAbstractState*> historyConfiguration = QHistoryStatePrivate::get(historyState)->configuration;
if (!historyConfiguration.isEmpty()) {
@@ -547,7 +554,7 @@ QList<QAbstractTransition*> QStateMachinePrivate::selectTransitions(QEvent *even
Q_Q(const QStateMachine);
QVarLengthArray<QAbstractState *> configuration_sorted;
- foreach (QAbstractState *s, configuration) {
+ for (QAbstractState *s : qAsConst(configuration)) {
if (isAtomic(s))
configuration_sorted.append(s);
}
@@ -555,7 +562,7 @@ QList<QAbstractTransition*> QStateMachinePrivate::selectTransitions(QEvent *even
QList<QAbstractTransition*> enabledTransitions;
const_cast<QStateMachine*>(q)->beginSelectTransitions(event);
- foreach (QAbstractState *state, configuration_sorted) {
+ for (QAbstractState *state : qAsConst(configuration_sorted)) {
QVector<QState*> lst = getProperAncestors(state, Q_NULLPTR);
if (QState *grp = toStandardState(state))
lst.prepend(grp);
@@ -622,7 +629,7 @@ void QStateMachinePrivate::removeConflictingTransitions(QList<QAbstractTransitio
filteredTransitions.reserve(enabledTransitions.size());
std::sort(enabledTransitions.begin(), enabledTransitions.end(), transitionStateEntryLessThan);
- foreach (QAbstractTransition *t1, enabledTransitions) {
+ for (QAbstractTransition *t1 : qAsConst(enabledTransitions)) {
bool t1Preempted = false;
const QSet<QAbstractState*> exitSetT1 = computeExitSet_Unordered(t1, cache);
QList<QAbstractTransition*>::iterator t2It = filteredTransitions.begin();
@@ -747,7 +754,7 @@ QSet<QAbstractState*> QStateMachinePrivate::computeExitSet_Unordered(const QList
Q_ASSERT(cache);
QSet<QAbstractState*> statesToExit;
- foreach (QAbstractTransition *t, enabledTransitions)
+ for (QAbstractTransition *t : enabledTransitions)
statesToExit.unite(computeExitSet_Unordered(t, cache));
return statesToExit;
}
@@ -780,7 +787,7 @@ QSet<QAbstractState*> QStateMachinePrivate::computeExitSet_Unordered(QAbstractTr
Q_ASSERT(domain != 0);
}
- foreach (QAbstractState* s, configuration) {
+ for (QAbstractState* s : qAsConst(configuration)) {
if (isDescendant(s, domain))
statesToExit.insert(s);
}
@@ -854,16 +861,15 @@ QList<QAbstractState*> QStateMachinePrivate::computeEntrySet(const QList<QAbstra
QSet<QAbstractState*> statesToEnter;
if (pendingErrorStates.isEmpty()) {
- foreach (QAbstractTransition *t, enabledTransitions) {
- foreach (QAbstractState *s, t->targetStates()) {
+ for (QAbstractTransition *t : enabledTransitions) {
+ const auto targetStates = t->targetStates();
+ for (QAbstractState *s : targetStates)
addDescendantStatesToEnter(s, statesToEnter, statesForDefaultEntry);
- }
- QList<QAbstractState *> effectiveTargetStates = getEffectiveTargetStates(t, cache);
+ const QList<QAbstractState *> effectiveTargetStates = getEffectiveTargetStates(t, cache);
QAbstractState *ancestor = getTransitionDomain(t, effectiveTargetStates, cache);
- foreach (QAbstractState *s, effectiveTargetStates) {
+ for (QAbstractState *s : effectiveTargetStates)
addAncestorStatesToEnter(s, ancestor, statesToEnter, statesForDefaultEntry);
- }
}
}
@@ -914,7 +920,7 @@ QAbstractState *QStateMachinePrivate::getTransitionDomain(QAbstractTransition *t
if (QState *tSource = t->sourceState()) {
if (isCompound(tSource)) {
bool allDescendants = true;
- foreach (QAbstractState *s, effectiveTargetStates) {
+ for (QAbstractState *s : effectiveTargetStates) {
if (!isDescendant(s, tSource)) {
allDescendants = false;
break;
@@ -1090,11 +1096,11 @@ void QStateMachinePrivate::addDescendantStatesToEnter(QAbstractState *state,
QSet<QAbstractState*> &statesForDefaultEntry)
{
if (QHistoryState *h = toHistoryState(state)) {
- QList<QAbstractState*> historyConfiguration = QHistoryStatePrivate::get(h)->configuration;
+ const QList<QAbstractState*> historyConfiguration = QHistoryStatePrivate::get(h)->configuration;
if (!historyConfiguration.isEmpty()) {
- foreach (QAbstractState *s, historyConfiguration)
+ for (QAbstractState *s : historyConfiguration)
addDescendantStatesToEnter(s, statesToEnter, statesForDefaultEntry);
- foreach (QAbstractState *s, historyConfiguration)
+ for (QAbstractState *s : historyConfiguration)
addAncestorStatesToEnter(s, state->parentState(), statesToEnter, statesForDefaultEntry);
#ifdef QSTATEMACHINE_DEBUG
@@ -1110,9 +1116,9 @@ void QStateMachinePrivate::addDescendantStatesToEnter(QAbstractState *state,
if (defaultHistoryContent.isEmpty()) {
setError(QStateMachine::NoDefaultStateInHistoryStateError, h);
} else {
- foreach (QAbstractState *s, defaultHistoryContent)
+ for (QAbstractState *s : qAsConst(defaultHistoryContent))
addDescendantStatesToEnter(s, statesToEnter, statesForDefaultEntry);
- foreach (QAbstractState *s, defaultHistoryContent)
+ for (QAbstractState *s : qAsConst(defaultHistoryContent))
addAncestorStatesToEnter(s, state->parentState(), statesToEnter, statesForDefaultEntry);
#ifdef QSTATEMACHINE_DEBUG
qDebug() << q_func() << ": initial history targets for" << state << ':' << defaultHistoryContent;
@@ -1145,7 +1151,8 @@ void QStateMachinePrivate::addDescendantStatesToEnter(QAbstractState *state,
}
} else if (isParallel(state)) {
QState *grp = toStandardState(state);
- foreach (QAbstractState *child, QStatePrivate::get(grp)->childStates()) {
+ const auto childStates = QStatePrivate::get(grp)->childStates();
+ for (QAbstractState *child : childStates) {
if (!containsDecendantOf(statesToEnter, child))
addDescendantStatesToEnter(child, statesToEnter, statesForDefaultEntry);
}
@@ -1168,12 +1175,14 @@ void QStateMachinePrivate::addAncestorStatesToEnter(QAbstractState *s, QAbstract
QSet<QAbstractState*> &statesToEnter,
QSet<QAbstractState*> &statesForDefaultEntry)
{
- foreach (QState *anc, getProperAncestors(s, ancestor)) {
+ const auto properAncestors = getProperAncestors(s, ancestor);
+ for (QState *anc : properAncestors) {
if (!anc->parentState())
continue;
statesToEnter.insert(anc);
if (isParallel(anc)) {
- foreach (QAbstractState *child, QStatePrivate::get(anc)->childStates()) {
+ const auto childStates = QStatePrivate::get(anc)->childStates();
+ for (QAbstractState *child : childStates) {
if (!containsDecendantOf(statesToEnter, child))
addDescendantStatesToEnter(child, statesToEnter, statesForDefaultEntry);
}
@@ -1341,9 +1350,8 @@ void QStateMachinePrivate::unregisterRestorables(const QList<QAbstractState *> &
if (it == registeredRestorablesForState.end())
continue;
QHash<RestorableId, QVariant> &restorables = it.value();
- QHash<RestorableId, QVariant>::iterator it2;
- it2 = restorables.find(id);
- if (it2 == restorables.end())
+ const auto it2 = restorables.constFind(id);
+ if (it2 == restorables.cend())
continue;
#ifdef QSTATEMACHINE_RESTORE_PROPERTIES_DEBUG
qDebug() << q_func() << ": unregistered for" << s;
@@ -1500,8 +1508,7 @@ void QStateMachinePrivate::setError(QStateMachine::Error errorCode, QAbstractSta
pendingErrorStates.insert(currentErrorState);
addDescendantStatesToEnter(currentErrorState, pendingErrorStates, pendingErrorStatesForDefaultEntry);
addAncestorStatesToEnter(currentErrorState, rootState(), pendingErrorStates, pendingErrorStatesForDefaultEntry);
- foreach (QAbstractState *s, configuration)
- pendingErrorStates.remove(s);
+ pendingErrorStates -= configuration;
} else {
qWarning("Unrecoverable error detected in running state machine: %s",
qPrintable(errorString));
@@ -1511,20 +1518,18 @@ void QStateMachinePrivate::setError(QStateMachine::Error errorCode, QAbstractSta
#ifndef QT_NO_ANIMATION
-QPair<QList<QAbstractAnimation*>, QList<QAbstractAnimation*> >
+QStateMachinePrivate::InitializeAnimationResult
QStateMachinePrivate::initializeAnimation(QAbstractAnimation *abstractAnimation,
const QPropertyAssignment &prop)
{
- QList<QAbstractAnimation*> handledAnimations;
- QList<QAbstractAnimation*> localResetEndValues;
+ InitializeAnimationResult result;
QAnimationGroup *group = qobject_cast<QAnimationGroup*>(abstractAnimation);
if (group) {
for (int i = 0; i < group->animationCount(); ++i) {
QAbstractAnimation *animationChild = group->animationAt(i);
- QPair<QList<QAbstractAnimation*>, QList<QAbstractAnimation*> > ret;
- ret = initializeAnimation(animationChild, prop);
- handledAnimations << ret.first;
- localResetEndValues << ret.second;
+ const auto ret = initializeAnimation(animationChild, prop);
+ result.handledAnimations << ret.handledAnimations;
+ result.localResetEndValues << ret.localResetEndValues;
}
} else {
QPropertyAnimation *animation = qobject_cast<QPropertyAnimation *>(abstractAnimation);
@@ -1535,12 +1540,12 @@ QStateMachinePrivate::initializeAnimation(QAbstractAnimation *abstractAnimation,
// Only change end value if it is undefined
if (!animation->endValue().isValid()) {
animation->setEndValue(prop.value);
- localResetEndValues.append(animation);
+ result.localResetEndValues.append(animation);
}
- handledAnimations.append(animation);
+ result.handledAnimations.append(animation);
}
}
- return qMakePair(handledAnimations, localResetEndValues);
+ return result;
}
void QStateMachinePrivate::_q_animationFinished()
@@ -1651,13 +1656,11 @@ void QStateMachinePrivate::initializeAnimations(QAbstractState *state, const QLi
QAbstractAnimation *anim = selectedAnimations.at(i);
QVector<QPropertyAssignment>::iterator it;
for (it = assignments.begin(); it != assignments.end(); ) {
- QPair<QList<QAbstractAnimation*>, QList<QAbstractAnimation*> > ret;
const QPropertyAssignment &assn = *it;
- ret = initializeAnimation(anim, assn);
- QList<QAbstractAnimation*> handlers = ret.first;
- if (!handlers.isEmpty()) {
- for (int j = 0; j < handlers.size(); ++j) {
- QAbstractAnimation *a = handlers.at(j);
+ const auto ret = initializeAnimation(anim, assn);
+ if (!ret.handledAnimations.isEmpty()) {
+ for (int j = 0; j < ret.handledAnimations.size(); ++j) {
+ QAbstractAnimation *a = ret.handledAnimations.at(j);
propertyForAnimation.insert(a, assn);
stateForAnimation.insert(a, state);
animationsForState[state].append(a);
@@ -1674,8 +1677,8 @@ void QStateMachinePrivate::initializeAnimations(QAbstractState *state, const QLi
} else {
++it;
}
- for (int j = 0; j < ret.second.size(); ++j)
- resetAnimationEndValues.insert(ret.second.at(j));
+ for (int j = 0; j < ret.localResetEndValues.size(); ++j)
+ resetAnimationEndValues.insert(ret.localResetEndValues.at(j));
}
// We require that at least one animation is valid.
// ### generalize