diff options
Diffstat (limited to 'examples/widgets/animation/stickman')
5 files changed, 21 insertions, 21 deletions
diff --git a/examples/widgets/animation/stickman/animation.cpp b/examples/widgets/animation/stickman/animation.cpp index 94a92749bc..5c2d1682af 100644 --- a/examples/widgets/animation/stickman/animation.cpp +++ b/examples/widgets/animation/stickman/animation.cpp @@ -159,18 +159,16 @@ void Animation::save(QIODevice *device) const QDataStream stream(device); stream << m_name; stream << m_frames.size(); - foreach (Frame *frame, m_frames) { + for (const Frame *frame : qAsConst(m_frames)) { stream << frame->nodeCount(); - for (int i=0; i<frame->nodeCount(); ++i) + for (int i = 0; i < frame->nodeCount(); ++i) stream << frame->nodePos(i); } } void Animation::load(QIODevice *device) { - if (!m_frames.isEmpty()) - qDeleteAll(m_frames); - + qDeleteAll(m_frames); m_frames.clear(); QDataStream stream(device); diff --git a/examples/widgets/animation/stickman/graphicsview.cpp b/examples/widgets/animation/stickman/graphicsview.cpp index 9cb57fcd9e..7058e15345 100644 --- a/examples/widgets/animation/stickman/graphicsview.cpp +++ b/examples/widgets/animation/stickman/graphicsview.cpp @@ -55,7 +55,9 @@ #include <QtWidgets/QGraphicsScene> #include <QtWidgets/QGraphicsView> -GraphicsView::GraphicsView(QWidget *parent) : QGraphicsView(parent), m_editor(0) {} +GraphicsView::GraphicsView(QWidget *parent) + : QGraphicsView(parent), m_editor(nullptr) +{} void GraphicsView::keyPressEvent(QKeyEvent *e) { diff --git a/examples/widgets/animation/stickman/graphicsview.h b/examples/widgets/animation/stickman/graphicsview.h index 56396bb780..361fee219d 100644 --- a/examples/widgets/animation/stickman/graphicsview.h +++ b/examples/widgets/animation/stickman/graphicsview.h @@ -58,7 +58,7 @@ class GraphicsView: public QGraphicsView { Q_OBJECT public: - GraphicsView(QWidget *parent = 0); + GraphicsView(QWidget *parent = nullptr); protected: void resizeEvent(QResizeEvent *event) override; diff --git a/examples/widgets/animation/stickman/lifecycle.cpp b/examples/widgets/animation/stickman/lifecycle.cpp index dbe9a299b4..046e3f4cd1 100644 --- a/examples/widgets/animation/stickman/lifecycle.cpp +++ b/examples/widgets/animation/stickman/lifecycle.cpp @@ -61,11 +61,11 @@ class KeyPressTransition: public QSignalTransition { public: KeyPressTransition(GraphicsView *receiver, Qt::Key key) - : QSignalTransition(receiver, SIGNAL(keyPressed(int))), m_key(key) + : QSignalTransition(receiver, &GraphicsView::keyPressed), m_key(key) { } KeyPressTransition(GraphicsView *receiver, Qt::Key key, QAbstractState *target) - : QSignalTransition(receiver, SIGNAL(keyPressed(int))), m_key(key) + : QSignalTransition(receiver, &GraphicsView::keyPressed), m_key(key) { setTargetState(target); } @@ -132,8 +132,10 @@ LifeCycle::LifeCycle(StickMan *stickMan, GraphicsView *keyReceiver) QTimer *timer = new QTimer(lightningBlink); timer->setSingleShot(true); timer->setInterval(100); - QObject::connect(lightningBlink, SIGNAL(entered()), timer, SLOT(start())); - QObject::connect(lightningBlink, SIGNAL(exited()), timer, SLOT(stop())); + QObject::connect(lightningBlink, &QAbstractState::entered, + timer, QOverload<>::of(&QTimer::start)); + QObject::connect(lightningBlink, &QAbstractState::exited, + timer, &QTimer::stop); //! [5] m_dead = new QState(m_machine); @@ -151,7 +153,7 @@ LifeCycle::LifeCycle(StickMan *stickMan, GraphicsView *keyReceiver) // Lightning strikes at random m_alive->addTransition(new LightningStrikesTransition(lightningBlink)); //! [0] - lightningBlink->addTransition(timer, SIGNAL(timeout()), m_dead); + lightningBlink->addTransition(timer, &QTimer::timeout, m_dead); //! [0] m_machine->setInitialState(m_alive); @@ -173,9 +175,8 @@ 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 != NULL) || (signal != NULL)) { + if (sender || signal) m_alive->addTransition(sender, signal, state); - } } QState *LifeCycle::makeState(QState *parentState, const QString &animationFileName) @@ -190,7 +191,7 @@ QState *LifeCycle::makeState(QState *parentState, const QString &animationFileNa } const int frameCount = animation.totalFrames(); - QState *previousState = 0; + QState *previousState = nullptr; for (int i=0; i<frameCount; ++i) { animation.setCurrentFrame(i); @@ -202,18 +203,18 @@ QState *LifeCycle::makeState(QState *parentState, const QString &animationFileNa //! [1] frameState->setObjectName(QString::fromLatin1("frame %0").arg(i)); - if (previousState == 0) + if (previousState == nullptr) topLevel->setInitialState(frameState); else //! [2] - previousState->addTransition(previousState, SIGNAL(propertiesAssigned()), frameState); + previousState->addTransition(previousState, &QState::propertiesAssigned, frameState); //! [2] previousState = frameState; } // Loop - previousState->addTransition(previousState, SIGNAL(propertiesAssigned()), topLevel->initialState()); + previousState->addTransition(previousState, &QState::propertiesAssigned, topLevel->initialState()); return topLevel; diff --git a/examples/widgets/animation/stickman/stickman.cpp b/examples/widgets/animation/stickman/stickman.cpp index b7a2d87ada..5725f64eec 100644 --- a/examples/widgets/animation/stickman/stickman.cpp +++ b/examples/widgets/animation/stickman/stickman.cpp @@ -126,7 +126,7 @@ StickMan::StickMan() // Set up start position of limbs for (int i=0; i<NodeCount; ++i) { m_nodes[i] = new Node(QPointF(Coords[i * 2], Coords[i * 2 + 1]), this); - connect(m_nodes[i], SIGNAL(positionChanged()), this, SLOT(childPositionChanged())); + connect(m_nodes[i], &Node::positionChanged, this, &StickMan::childPositionChanged); } for (int i=0; i<BoneCount; ++i) { @@ -176,8 +176,7 @@ Node *StickMan::node(int idx) const { if (idx >= 0 && idx < NodeCount) return m_nodes[idx]; - else - return 0; + return nullptr; } void StickMan::timerEvent(QTimerEvent *) |