diff options
author | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2019-07-13 20:39:05 +0200 |
---|---|---|
committer | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2019-08-17 09:51:32 +0200 |
commit | 13426aff248c25b44ac377f37dc3e3a54ea0ea86 (patch) | |
tree | 18dfc93c88f5a06460c9adddb681901711dacd30 /examples/widgets/animation/stickman/lifecycle.cpp | |
parent | cb3e1e551f340ce1e6280123d8b5411b3c1c96d8 (diff) |
Cleanup QtWidgets animation examples
Cleanup the QtWidgets animation examples:
- use nullptr
- use normalized includes, remove unused includes
- fix style
- fix crash of sub-attaq when the game ended (error during range-based
for loop porting)
- don't use keyword 'final' for a variable name
Change-Id: Id23be8ff8b1b310da005d13c052fe547f6a0d63a
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'examples/widgets/animation/stickman/lifecycle.cpp')
-rw-r--r-- | examples/widgets/animation/stickman/lifecycle.cpp | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/examples/widgets/animation/stickman/lifecycle.cpp b/examples/widgets/animation/stickman/lifecycle.cpp index 046e3f4cd1..5ad284c590 100644 --- a/examples/widgets/animation/stickman/lifecycle.cpp +++ b/examples/widgets/animation/stickman/lifecycle.cpp @@ -54,8 +54,15 @@ #include "animation.h" #include "graphicsview.h" -#include <QtCore> -#include <QtWidgets> +#include <QEventTransition> +#include <QFile> +#include <QParallelAnimationGroup> +#include <QPropertyAnimation> +#include <QRandomGenerator> +#include <QSignalTransition> +#include <QState> +#include <QStateMachine> +#include <QTimer> class KeyPressTransition: public QSignalTransition { @@ -107,7 +114,7 @@ LifeCycle::LifeCycle(StickMan *stickMan, GraphicsView *keyReceiver) // Create animation group to be used for all transitions m_animationGroup = new QParallelAnimationGroup(); const int stickManNodeCount = m_stickMan->nodeCount(); - for (int i=0; i<stickManNodeCount; ++i) { + for (int i = 0; i < stickManNodeCount; ++i) { QPropertyAnimation *pa = new QPropertyAnimation(m_stickMan->node(i), "pos"); m_animationGroup->addAnimation(pa); } @@ -175,7 +182,7 @@ void LifeCycle::addActivity(const QString &fileName, Qt::Key key, QObject *sende QState *state = makeState(m_alive, fileName); m_alive->addTransition(new KeyPressTransition(m_keyReceiver, key, state)); - if (sender || signal) + if (sender && signal) m_alive->addTransition(sender, signal, state); } @@ -192,13 +199,13 @@ QState *LifeCycle::makeState(QState *parentState, const QString &animationFileNa const int frameCount = animation.totalFrames(); QState *previousState = nullptr; - for (int i=0; i<frameCount; ++i) { + for (int i = 0; i < frameCount; ++i) { animation.setCurrentFrame(i); //! [1] QState *frameState = new QState(topLevel); const int nodeCount = animation.nodeCount(); - for (int j=0; j<nodeCount; ++j) + for (int j = 0; j < nodeCount; ++j) frameState->assignProperty(m_stickMan->node(j), "pos", animation.nodePos(j)); //! [1] |