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/sub-attaq/submarine.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/sub-attaq/submarine.cpp')
-rw-r--r-- | examples/widgets/animation/sub-attaq/submarine.cpp | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/examples/widgets/animation/sub-attaq/submarine.cpp b/examples/widgets/animation/sub-attaq/submarine.cpp index 775e75ceed..a4ca376045 100644 --- a/examples/widgets/animation/sub-attaq/submarine.cpp +++ b/examples/widgets/animation/sub-attaq/submarine.cpp @@ -52,15 +52,14 @@ #include "submarine.h" #include "submarine_p.h" #include "torpedo.h" -#include "pixmapitem.h" #include "graphicsscene.h" #include "animationmanager.h" #include "qanimationstate.h" -#include <QtCore/QPropertyAnimation> -#include <QtCore/QStateMachine> -#include <QtCore/QFinalState> -#include <QtCore/QSequentialAnimationGroup> +#include <QFinalState> +#include <QPropertyAnimation> +#include <QStateMachine> +#include <QSequentialAnimationGroup> static QAbstractAnimation *setupDestroyAnimation(SubMarine *sub) { @@ -86,9 +85,8 @@ SubMarine::SubMarine(int type, const QString &name, int points) : PixmapItem(QSt graphicsRotation = new QGraphicsRotation(this); graphicsRotation->setAxis(Qt::YAxis); - graphicsRotation->setOrigin(QVector3D(size().width()/2, size().height()/2, 0)); - QList<QGraphicsTransform *> r; - r.append(graphicsRotation); + graphicsRotation->setOrigin(QVector3D(size().width() / 2, size().height() / 2, 0)); + QList<QGraphicsTransform *> r({graphicsRotation}); setTransformations(r); //We setup the state machine of the submarine @@ -112,7 +110,7 @@ SubMarine::SubMarine(int type, const QString &name, int points) : PixmapItem(QSt machine->setInitialState(moving); //End - QFinalState *final = new QFinalState(machine); + QFinalState *finalState = new QFinalState(machine); //If the moving animation is finished we move to the return state movement->addTransition(movement, &QAnimationState::animationFinished, rotation); @@ -128,7 +126,7 @@ SubMarine::SubMarine(int type, const QString &name, int points) : PixmapItem(QSt moving->addTransition(this, &SubMarine::subMarineDestroyed, destroyedState); //Transition to final state when the destroyed animation is finished - destroyedState->addTransition(destroyedState, &QAnimationState::animationFinished, final); + destroyedState->addTransition(destroyedState, &QAnimationState::animationFinished, finalState); //The machine has finished to be executed, then the submarine is dead connect(machine,&QState::finished,this, &SubMarine::subMarineExecutionFinished); @@ -145,9 +143,8 @@ void SubMarine::setCurrentDirection(SubMarine::Movement direction) { if (this->direction == direction) return; - if (direction == SubMarine::Right && this->direction == SubMarine::None) { + if (direction == SubMarine::Right && this->direction == SubMarine::None) graphicsRotation->setAngle(180); - } this->direction = direction; } @@ -158,9 +155,8 @@ enum SubMarine::Movement SubMarine::currentDirection() const void SubMarine::setCurrentSpeed(int speed) { - if (speed < 0 || speed > 3) { + if (speed < 0 || speed > 3) qWarning("SubMarine::setCurrentSpeed : The speed is invalid"); - } this->speed = speed; emit subMarineStateChanged(); } @@ -172,7 +168,7 @@ int SubMarine::currentSpeed() const void SubMarine::launchTorpedo(int speed) { - Torpedo * torp = new Torpedo(); + Torpedo *torp = new Torpedo; GraphicsScene *scene = static_cast<GraphicsScene *>(this->scene()); scene->addItem(torp); torp->setPos(pos()); |