diff options
author | Tobias Hunger <tobias.hunger@qt.io> | 2019-04-16 16:32:08 +0200 |
---|---|---|
committer | Tobias Hunger <tobias.hunger@qt.io> | 2019-04-16 16:32:08 +0200 |
commit | 6630937e63ae5797487b86743a7733c8ae5cc42c (patch) | |
tree | 3d53dacf6430f9099e1fb20835881205de674961 /examples/widgets/statemachine | |
parent | 37ed6dae00640f9cc980ffda05347c12a7eb5d7e (diff) | |
parent | c7af193d2e49e9f10b86262e63d8d13abf72b5cf (diff) |
Merge commit 'dev' into 'wip/cmake-merge'
Change-Id: I176c40d031be26a1dd1cf08843e448a660598783
Diffstat (limited to 'examples/widgets/statemachine')
6 files changed, 22 insertions, 23 deletions
diff --git a/examples/widgets/statemachine/factorial/factorial.pro b/examples/widgets/statemachine/factorial/factorial.pro index f200c738ba..bf285acf4d 100644 --- a/examples/widgets/statemachine/factorial/factorial.pro +++ b/examples/widgets/statemachine/factorial/factorial.pro @@ -1,6 +1,5 @@ QT = core -win32: CONFIG += console -mac:CONFIG -= app_bundle +CONFIG += cmdline SOURCES += main.cpp diff --git a/examples/widgets/statemachine/factorial/main.cpp b/examples/widgets/statemachine/factorial/main.cpp index f100aa0110..e9431596fe 100644 --- a/examples/widgets/statemachine/factorial/main.cpp +++ b/examples/widgets/statemachine/factorial/main.cpp @@ -49,7 +49,6 @@ ****************************************************************************/ #include <QtCore> -#include <stdio.h> //! [0] class Factorial : public QObject @@ -100,7 +99,7 @@ class FactorialLoopTransition : public QSignalTransition { public: FactorialLoopTransition(Factorial *fact) - : QSignalTransition(fact, SIGNAL(xChanged(int))), m_fact(fact) + : QSignalTransition(fact, &Factorial::xChanged), m_fact(fact) {} bool eventTest(QEvent *e) override @@ -130,7 +129,7 @@ class FactorialDoneTransition : public QSignalTransition { public: FactorialDoneTransition(Factorial *fact) - : QSignalTransition(fact, SIGNAL(xChanged(int))), m_fact(fact) + : QSignalTransition(fact, &Factorial::xChanged), m_fact(fact) {} bool eventTest(QEvent *e) override @@ -143,7 +142,7 @@ public: void onTransition(QEvent *) override { - fprintf(stdout, "%d\n", m_fact->property("fac").toInt()); + qInfo() << m_fact->property("fac").toInt(); } private: diff --git a/examples/widgets/statemachine/pingpong/pingpong.pro b/examples/widgets/statemachine/pingpong/pingpong.pro index 7cc27a13f5..18dee0400d 100644 --- a/examples/widgets/statemachine/pingpong/pingpong.pro +++ b/examples/widgets/statemachine/pingpong/pingpong.pro @@ -1,6 +1,5 @@ QT = core -win32: CONFIG += console -mac:CONFIG -= app_bundle +CONFIG += cmdline SOURCES = main.cpp diff --git a/examples/widgets/statemachine/rogue/window.cpp b/examples/widgets/statemachine/rogue/window.cpp index 059fbf1003..a5363e2758 100644 --- a/examples/widgets/statemachine/rogue/window.cpp +++ b/examples/widgets/statemachine/rogue/window.cpp @@ -66,7 +66,8 @@ Window::Window() font = QFont("Monospace"); } else { - foreach (QString family, database.families()) { + const QStringList fontFamilies = database.families(); + for (const QString &family : fontFamilies ) { if (database.isFixedPitch(family)) { font = QFont(family); break; @@ -217,7 +218,8 @@ void Window::buildMachine() //![5] machine->setInitialState(inputState); - connect(machine, SIGNAL(finished()), qApp, SLOT(quit())); + connect(machine, &QStateMachine::finished, + qApp, &QApplication::quit); machine->start(); } diff --git a/examples/widgets/statemachine/trafficlight/main.cpp b/examples/widgets/statemachine/trafficlight/main.cpp index 21df91d8b0..1a7050c28d 100644 --- a/examples/widgets/statemachine/trafficlight/main.cpp +++ b/examples/widgets/statemachine/trafficlight/main.cpp @@ -132,11 +132,11 @@ QState *createLightState(LightWidget *light, int duration, QState *parent = 0) timer->setInterval(duration); timer->setSingleShot(true); QState *timing = new QState(lightState); - QObject::connect(timing, SIGNAL(entered()), light, SLOT(turnOn())); - QObject::connect(timing, SIGNAL(entered()), timer, SLOT(start())); - QObject::connect(timing, SIGNAL(exited()), light, SLOT(turnOff())); + QObject::connect(timing, &QAbstractState::entered, light, &LightWidget::turnOn); + QObject::connect(timing, &QAbstractState::entered, timer, QOverload<>::of(&QTimer::start)); + QObject::connect(timing, &QAbstractState::exited, light, &LightWidget::turnOff); QFinalState *done = new QFinalState(lightState); - timing->addTransition(timer, SIGNAL(timeout()), done); + timing->addTransition(timer, &QTimer::timeout, done); lightState->setInitialState(timing); return lightState; } @@ -146,27 +146,27 @@ QState *createLightState(LightWidget *light, int duration, QState *parent = 0) class TrafficLight : public QWidget { public: - TrafficLight(QWidget *parent = 0) + TrafficLight(QWidget *parent = nullptr) : QWidget(parent) { QVBoxLayout *vbox = new QVBoxLayout(this); - TrafficLightWidget *widget = new TrafficLightWidget(); + TrafficLightWidget *widget = new TrafficLightWidget; vbox->addWidget(widget); - vbox->setMargin(0); + vbox->setContentsMargins(QMargins()); QStateMachine *machine = new QStateMachine(this); QState *redGoingYellow = createLightState(widget->redLight(), 3000); redGoingYellow->setObjectName("redGoingYellow"); QState *yellowGoingGreen = createLightState(widget->yellowLight(), 1000); yellowGoingGreen->setObjectName("yellowGoingGreen"); - redGoingYellow->addTransition(redGoingYellow, SIGNAL(finished()), yellowGoingGreen); + redGoingYellow->addTransition(redGoingYellow, &QState::finished, yellowGoingGreen); QState *greenGoingYellow = createLightState(widget->greenLight(), 3000); greenGoingYellow->setObjectName("greenGoingYellow"); - yellowGoingGreen->addTransition(yellowGoingGreen, SIGNAL(finished()), greenGoingYellow); + yellowGoingGreen->addTransition(yellowGoingGreen, &QState::finished, greenGoingYellow); QState *yellowGoingRed = createLightState(widget->yellowLight(), 1000); yellowGoingRed->setObjectName("yellowGoingRed"); - greenGoingYellow->addTransition(greenGoingYellow, SIGNAL(finished()), yellowGoingRed); - yellowGoingRed->addTransition(yellowGoingRed, SIGNAL(finished()), redGoingYellow); + greenGoingYellow->addTransition(greenGoingYellow, &QState::finished, yellowGoingRed); + yellowGoingRed->addTransition(yellowGoingRed, &QState::finished, redGoingYellow); machine->addState(redGoingYellow); machine->addState(yellowGoingGreen); diff --git a/examples/widgets/statemachine/twowaybutton/main.cpp b/examples/widgets/statemachine/twowaybutton/main.cpp index 5c778aba70..3d4fef3bbe 100644 --- a/examples/widgets/statemachine/twowaybutton/main.cpp +++ b/examples/widgets/statemachine/twowaybutton/main.cpp @@ -69,8 +69,8 @@ int main(int argc, char **argv) //! [1] //! [2] - off->addTransition(&button, SIGNAL(clicked()), on); - on->addTransition(&button, SIGNAL(clicked()), off); + off->addTransition(&button, &QAbstractButton::clicked, on); + on->addTransition(&button, &QAbstractButton::clicked, off); //! [2] //! [3] |