diff options
author | Juha Vuolle <juha.vuolle@qt.io> | 2023-03-08 16:24:32 +0200 |
---|---|---|
committer | Juha Vuolle <juha.vuolle@qt.io> | 2023-03-17 13:02:07 +0200 |
commit | 92f96df3b88a99e84737a01deb05a41f199d73b3 (patch) | |
tree | 888b90965d1af4298746c5366f7dbce008dde58a | |
parent | 6c9e0421f9978b08aed615ca29a584c6e9d48493 (diff) |
Revamp scxml sudoku example
Pick-to: 6.5
Task-number: QTBUG-111323
Change-Id: Ica1979864662d36682db9195add36d167fe9264a
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
-rw-r--r-- | examples/scxml/sudoku/CMakeLists.txt | 6 | ||||
-rw-r--r-- | examples/scxml/sudoku/doc/src/sudoku.qdoc | 2 | ||||
-rw-r--r-- | examples/scxml/sudoku/main.cpp | 4 | ||||
-rw-r--r-- | examples/scxml/sudoku/mainwindow.cpp | 54 | ||||
-rw-r--r-- | examples/scxml/sudoku/mainwindow.h | 16 | ||||
-rw-r--r-- | examples/scxml/sudoku/sudoku.js | 2 | ||||
-rw-r--r-- | examples/scxml/sudoku/sudoku.scxml | 2 |
7 files changed, 38 insertions, 48 deletions
diff --git a/examples/scxml/sudoku/CMakeLists.txt b/examples/scxml/sudoku/CMakeLists.txt index 43131da..3ef0749 100644 --- a/examples/scxml/sudoku/CMakeLists.txt +++ b/examples/scxml/sudoku/CMakeLists.txt @@ -4,8 +4,6 @@ cmake_minimum_required(VERSION 3.16) project(sudoku LANGUAGES CXX) -set(CMAKE_AUTOMOC ON) - if(NOT DEFINED INSTALL_EXAMPLESDIR) set(INSTALL_EXAMPLESDIR "examples") endif() @@ -14,6 +12,8 @@ set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/scxml/sudoku") find_package(Qt6 REQUIRED COMPONENTS Core Gui Scxml Widgets) +qt_standard_project_setup() + qt_add_executable(sudoku main.cpp mainwindow.cpp mainwindow.h @@ -24,7 +24,7 @@ set_target_properties(sudoku PROPERTIES MACOSX_BUNDLE TRUE ) -target_link_libraries(sudoku PUBLIC +target_link_libraries(sudoku PRIVATE Qt::Core Qt::Gui Qt::Scxml diff --git a/examples/scxml/sudoku/doc/src/sudoku.qdoc b/examples/scxml/sudoku/doc/src/sudoku.qdoc index 3b896ca..f4aa112 100644 --- a/examples/scxml/sudoku/doc/src/sudoku.qdoc +++ b/examples/scxml/sudoku/doc/src/sudoku.qdoc @@ -1,4 +1,4 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only /*! diff --git a/examples/scxml/sudoku/main.cpp b/examples/scxml/sudoku/main.cpp index 3eea5c3..8cd790d 100644 --- a/examples/scxml/sudoku/main.cpp +++ b/examples/scxml/sudoku/main.cpp @@ -1,10 +1,10 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause #include "mainwindow.h" #include "sudoku.h" -#include <QApplication> +#include <QtWidgets/qapplication.h> int main(int argc, char **argv) { diff --git a/examples/scxml/sudoku/mainwindow.cpp b/examples/scxml/sudoku/mainwindow.cpp index 5d7c9ce..9b45455 100644 --- a/examples/scxml/sudoku/mainwindow.cpp +++ b/examples/scxml/sudoku/mainwindow.cpp @@ -1,21 +1,21 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause #include "mainwindow.h" -#include <QComboBox> -#include <QDir> -#include <QFile> -#include <QGridLayout> -#include <QLabel> -#include <QScxmlStateMachine> -#include <QStringListModel> -#include <QTextStream> -#include <QToolButton> +#include <QtCore/qdir.h> +#include <QtCore/qfile.h> +#include <QtCore/qstringlistmodel.h> +#include <QtCore/qtextstream.h> +#include <QtWidgets/qcombobox.h> +#include <QtWidgets/qgridlayout.h> +#include <QtWidgets/qlabel.h> +#include <QtWidgets/qtoolbutton.h> +#include <QtScxml/qscxmlstatemachine.h> static int Size = 9; -QT_USE_NAMESPACE +using namespace Qt::Literals::StringLiterals; static QVariantList emptyRow() { @@ -33,11 +33,11 @@ static QVariantMap readSudoku(const QString &fileName) const QString data = str.readAll(); QVariantList initRowsVariant; - const QStringList rows = data.split(QLatin1Char('\n')); + const QStringList rows = data.split('\n'_L1); for (int i = 0; i < Size; i++) { if (i < rows.count()) { QVariantList initRowVariant; - const QStringList row = rows.at(i).split(QLatin1Char(',')); + const QStringList row = rows.at(i).split(','_L1); for (int j = 0; j < Size; j++) { const int val = j < row.count() ? row.at(j).toInt() % (Size + 1) : 0; @@ -50,7 +50,7 @@ static QVariantMap readSudoku(const QString &fileName) } QVariantMap dataVariant; - dataVariant.insert(QStringLiteral("initState"), initRowsVariant); + dataVariant.insert(u"initState"_s, initRowsVariant); return dataVariant; } @@ -71,10 +71,10 @@ MainWindow::MainWindow(QScxmlStateMachine *machine, QWidget *parent) : QSizePolicy::Expanding); layout->addWidget(button, i + i / 3, j + j / 3); m_buttons[i][j] = button; - connect(button, &QToolButton::clicked, [this, i, j] () { + connect(button, &QToolButton::clicked, this, [this, i, j]() { QVariantMap data; - data.insert(QStringLiteral("x"), i); - data.insert(QStringLiteral("y"), j); + data.insert(u"x"_s, i); + data.insert(u"y"_s, j); m_machine->submitEvent("tap", data); }); } @@ -98,8 +98,7 @@ MainWindow::MainWindow(QScxmlStateMachine *machine, QWidget *parent) : m_startButton->setText(tr("Start")); layout->addWidget(m_startButton, Size + 3, 0, 1, 3); - connect(m_startButton, &QAbstractButton::clicked, - [this] { + connect(m_startButton, &QAbstractButton::clicked, this, [this]() { if (m_machine->isActive("playing")) m_machine->submitEvent("stop"); else @@ -117,15 +116,14 @@ MainWindow::MainWindow(QScxmlStateMachine *machine, QWidget *parent) : m_undoButton->setEnabled(false); layout->addWidget(m_undoButton, Size + 3, 8, 1, 3); - connect(m_undoButton, &QAbstractButton::clicked, - [this] { + connect(m_undoButton, &QAbstractButton::clicked, this, [this]() { m_machine->submitEvent("undo"); }); m_chooser = new QComboBox(this); layout->addWidget(m_chooser, Size + 4, 0, 1, 11); - QDir dataDir(QLatin1String(":/data")); + QDir dataDir(":/data"_L1); QFileInfoList sudokuFiles = dataDir.entryInfoList(QStringList() << "*.data"); for (const QFileInfo &sudokuFile : sudokuFiles) { @@ -133,8 +131,7 @@ MainWindow::MainWindow(QScxmlStateMachine *machine, QWidget *parent) : sudokuFile.absoluteFilePath()); } - connect(m_chooser, QOverload<int>::of(&QComboBox::currentIndexChanged), - [this] (int index) { + connect(m_chooser, &QComboBox::currentIndexChanged, this, [this](int index) { const QString sudokuFile = m_chooser->itemData(index).toString(); const QVariantMap initValues = readSudoku(sudokuFile); m_machine->submitEvent("setup", initValues); @@ -156,14 +153,14 @@ MainWindow::MainWindow(QScxmlStateMachine *machine, QWidget *parent) : } }); - m_machine->connectToState("solved", [this] (bool solved) { + m_machine->connectToState("solved", [this](bool solved) { if (solved) m_label->setText(tr("SOLVED !!!")); else m_label->setText(tr("unsolved")); }); - m_machine->connectToEvent("updateGUI", [this] (const QScxmlEvent &event) { + m_machine->connectToEvent("updateGUI", [this](const QScxmlEvent &event) { const QVariant data = event.data(); const QVariantList currentRows = data.toMap().value( @@ -193,8 +190,3 @@ MainWindow::MainWindow(QScxmlStateMachine *machine, QWidget *parent) : setLayout(layout); } - -MainWindow::~MainWindow() -{ -} - diff --git a/examples/scxml/sudoku/mainwindow.h b/examples/scxml/sudoku/mainwindow.h index 0bc5df4..b12a6dd 100644 --- a/examples/scxml/sudoku/mainwindow.h +++ b/examples/scxml/sudoku/mainwindow.h @@ -1,10 +1,10 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause #ifndef MAINWINDOW_H #define MAINWINDOW_H -#include <QWidget> +#include <QtWidgets/qwidget.h> QT_BEGIN_NAMESPACE class QToolButton; @@ -13,22 +13,20 @@ class QLabel; class QComboBox; QT_END_NAMESPACE - class MainWindow : public QWidget { Q_OBJECT public: explicit MainWindow(QScxmlStateMachine *machine, QWidget *parent = nullptr); - ~MainWindow(); private: - QScxmlStateMachine *m_machine; + QScxmlStateMachine *m_machine = nullptr; QList<QList<QToolButton *>> m_buttons; - QToolButton *m_startButton; - QToolButton *m_undoButton; - QLabel *m_label; - QComboBox *m_chooser; + QToolButton *m_startButton = nullptr; + QToolButton *m_undoButton = nullptr; + QLabel *m_label = nullptr; + QComboBox *m_chooser = nullptr; }; #endif // MAINWINDOW_H diff --git a/examples/scxml/sudoku/sudoku.js b/examples/scxml/sudoku/sudoku.js index e03e5f5..98abe0a 100644 --- a/examples/scxml/sudoku/sudoku.js +++ b/examples/scxml/sudoku/sudoku.js @@ -1,4 +1,4 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause function restart() { diff --git a/examples/scxml/sudoku/sudoku.scxml b/examples/scxml/sudoku/sudoku.scxml index 708908c..0184c12 100644 --- a/examples/scxml/sudoku/sudoku.scxml +++ b/examples/scxml/sudoku/sudoku.scxml @@ -1,6 +1,6 @@ <?xml version="1.0" ?> <!-- -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause --> <scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" |