Commit 9af456a0 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Port to for(...:...) + use nullptr

parent 6da5a8cf
Pipeline #110810 failed with stage
in 2 minutes and 25 seconds
......@@ -9,7 +9,7 @@ set(RELEASE_SERVICE_VERSION "${RELEASE_SERVICE_VERSION_MAJOR}.${RELEASE_SERVICE_
project(bovo VERSION ${RELEASE_SERVICE_VERSION})
set (QT_MIN_VERSION "5.15.0")
set (KF5_MIN_VERSION "5.83.0")
set (KF5_MIN_VERSION "5.89.0")
  • By bumping to 5.89 this also defaults to KDE_COMPILERSETTINGS_LEVEL 5.89, given it is not set before including ECM. Which then defaults these Qt related preprocessor definitions set:

    • -DQT_NO_CAST_TO_ASCII
    • -DQT_NO_CAST_FROM_ASCII
    • -DQT_NO_URL_CAST_FROM_STRING
    • -DQT_NO_CAST_FROM_BYTEARRAY
    • -DQT_USE_QSTRINGBUILDER
    • -DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT
    • -DQT_NO_KEYWORDS
    • -DQT_NO_FOREACH
    • -DQT_STRICT_ITERATORS

    See also https://api.kde.org/ecm/kde-module/KDECompilerSettings.html

    Thus you could also clean up more of the explicitly set definitions still set.

    BTW, the build is now broken for FreeBSD at least timely after this commit, please have a look.

    Edited by Friedrich W. H. Kossebau
  • https://www.spinics.net/lists/ceph-devel/msg39682.html random_shuffle was removed from freebsd...

Please register or sign in to reply
find_package(ECM ${KF5_MIN_VERSION} REQUIRED CONFIG)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH} )
......@@ -36,15 +36,13 @@ include(ECMAddAppIcon)
kde_enable_exceptions()
add_definitions(
-DQT_USE_FAST_CONCATENATION
-DQT_USE_FAST_OPERATOR_PLUS
-DQT_NO_CAST_FROM_ASCII
-DQT_NO_CAST_TO_ASCII
-DQT_NO_CAST_FROM_BYTEARRAY
-DQT_NO_URL_CAST_FROM_STRING
-DQT_USE_QSTRINGBUILDER
)
add_definitions(-DKF_DISABLE_DEPRECATED_BEFORE_AND_AT=0x055500)
#add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0x050f02)
add_definitions(-DKF_DISABLE_DEPRECATED_BEFORE_AND_AT=0x055900)
set( bovogame_SRCS
......
......@@ -71,7 +71,7 @@ Game::Game(const Dimension& dimension, const QStringList &restoreGame,
m_gameOver = false;
m_stepCount = 0;
m_curPlayer = No;
foreach (const QString &turn, restoreGame) {
for (const QString &turn : restoreGame) {
QStringList tmp = turn.split(QLatin1Char(':'));
if (tmp.count() != 2) {
qFatal("Wrong save file format!");
......@@ -147,7 +147,7 @@ bool Game::save(const QString& filename) const {
QString fileContent;
fileContent.append(QStringLiteral("<bovo width=\"%1\" height=\"%2\">")
.arg(QStringLiteral("")).arg(QStringLiteral("")));
foreach (const Move &move, m_history) {
for (const Move &move : std::as_const(m_history)) {
fileContent.append(QStringLiteral("<move player=\"%1\" x=\"%2\" y=\"%3\" />").
arg(move.player()).arg(move.x()).arg(move.y()));
}
......@@ -157,7 +157,7 @@ bool Game::save(const QString& filename) const {
QStringList Game::saveLast() const {
QStringList save;
foreach (const Move &move, m_history) {
for (const Move &move : std::as_const(m_history)) {
save << QStringLiteral("%1:%2,%3").arg(move.player())
.arg(move.x()).arg(move.y());
}
......@@ -180,7 +180,7 @@ void Game::start() {
void Game::startRestored() {
connect(this, &Game::boardChanged,
m_ai, &Ai::changeBoard);
foreach (const Move &move, m_history) {
for (const Move &move : std::as_const(m_history)) {
Q_EMIT boardChanged(move);
}
connect(this, &Game::oposerTurn, m_ai, &Ai::slotMove,
......
......@@ -125,9 +125,9 @@ void MainWindow::save() const {
void MainWindow::setupThemes() {
QStringList themercs;
const QStringList themeDirs = QStandardPaths::locateAll(QStandardPaths::AppDataLocation, QStringLiteral("themes"), QStandardPaths::LocateDirectory);
Q_FOREACH (const QString &themeDir, themeDirs) {
for (const QString &themeDir : themeDirs) {
const QStringList entries = QDir(themeDir).entryList(QDir::Dirs);
Q_FOREACH(const QString &d, entries) {
for(const QString &d : entries) {
QString themeFile = themeDir + QLatin1Char('/') + d + QLatin1String("/themerc");
if (QFile::exists(themeFile))
themercs.append(themeFile);
......@@ -135,7 +135,7 @@ void MainWindow::setupThemes() {
}
int i = 0;
foreach (const QString &themerc, themercs) {
for (const QString &themerc : std::as_const(themercs)) {
KConfig config(themerc);
KConfigGroup configGroup(&config, "Config");
const QString pathName = configGroup.readEntry("Path", QString());
......@@ -146,7 +146,7 @@ void MainWindow::setupThemes() {
void MainWindow::readConfig() {
const QString themePath = Settings::theme();
foreach (const Theme &tmpTheme, m_themes) {
for (const Theme &tmpTheme : m_themes) {
if (tmpTheme.path() == themePath) {
m_theme = tmpTheme;
break;
......@@ -203,12 +203,12 @@ void MainWindow::setupActions() {
m_themeAct = new KSelectAction(i18n("Theme"), this);
QStringList themes;
foreach (const Theme &theme, m_themes) {
for (const Theme &theme : std::as_const(m_themes)) {
themes << theme.name();
}
m_themeAct->setItems(themes);
int themeId = 0;
foreach (const Theme &theme, m_themes) {
for (const Theme &theme : std::as_const(m_themes)) {
if (theme.path() == m_theme.path()) {
themeId = theme.id();
break;
......@@ -228,9 +228,9 @@ void MainWindow::setupActions() {
}
void MainWindow::hint() {
if (m_game != 0) {
if (m_game != nullptr) {
if (!m_game->computerTurn()) {
if (m_demoAi != 0) {
if (m_demoAi != nullptr) {
m_demoAi->slotMove();
}
}
......@@ -238,7 +238,7 @@ void MainWindow::hint() {
}
void MainWindow::setAnimation(bool enabled) {
if (m_scene != 0) {
if (m_scene != nullptr) {
if (enabled != m_animate) {
m_scene->enableAnimation(enabled);
}
......@@ -249,10 +249,10 @@ void MainWindow::setAnimation(bool enabled) {
void MainWindow::slotNewGame() {
m_demoMode = false;
if (m_game != 0) {
if (m_game != nullptr) {
m_game->cancelAndWait();
if (m_scene != 0) {
disconnect(m_game, 0, m_scene, 0);
if (m_scene != nullptr) {
disconnect(m_game, nullptr, m_scene, 0);
}
if (!m_game->isGameOver() && m_game->history().size() > 1) {
m_lossesLabel->setText(i18n("Losses: %1",++m_losses));
......@@ -261,18 +261,18 @@ void MainWindow::slotNewGame() {
m_computerStarts = !m_computerStarts;
}
m_game->deleteLater();
m_game = 0;
m_game = nullptr;
}
if (m_demoAi != 0) {
if (m_demoAi != nullptr) {
m_demoAi->cancelAndWait();
m_demoAi->deleteLater();
m_demoAi = 0;
m_demoAi = nullptr;
}
QAction* act = actionCollection()->action(QStringLiteral("replay"));
if (act != 0) {
if (act != nullptr) {
act->setEnabled(false);
}
if (m_scene == 0 && (m_lastGame.isEmpty())) { //first time, demo time
if (m_scene == nullptr && (m_lastGame.isEmpty())) { //first time, demo time
m_scene = new Scene(m_theme, m_animate);
m_demoMode = true;
slotNewDemo();
......@@ -280,7 +280,7 @@ void MainWindow::slotNewGame() {
Kg::difficulty()->setGameRunning(true);
Dimension dimension(NUMCOLS, NUMCOLS);
if (m_scene == 0) {
if (m_scene == nullptr) {
m_scene = new Scene(m_theme, m_animate);
if (!m_lastGame.empty()) {
QString tmp = m_lastGame.first();
......@@ -320,13 +320,13 @@ void MainWindow::slotNewDemo() {
// a new game already started, do not start demo
return;
}
if (m_game != 0) {
if (m_game != nullptr) {
m_game->deleteLater();
m_game = 0;
m_game = nullptr;
}
if (m_demoAi != 0) {
if (m_demoAi != nullptr) {
m_demoAi->deleteLater();
m_demoAi = 0;
m_demoAi = nullptr;
}
Dimension dimension(NUMCOLS, NUMCOLS);
m_game = new Game(dimension, O, Kg::difficultyLevel(), Demo, m_playbackSpeed,
......@@ -389,7 +389,7 @@ void MainWindow::slotGameOver() {
increaseLosses();
}
}
disconnect(m_game, 0, m_demoAi, 0);
disconnect(m_game, nullptr, m_demoAi, nullptr);
m_hintAct->setEnabled(false);
actionCollection()->action(QStringLiteral("replay"))->setEnabled(true);
connect(actionCollection()->action(QStringLiteral("replay")), &QAction::triggered,
......@@ -405,7 +405,7 @@ void MainWindow::slotOposerTurn() {
}
void MainWindow::slotUndo() {
if (m_game == 0)
if (m_game == nullptr)
return;
if (m_game->isGameOver()) {
if (!m_game->boardFull()) {
......@@ -434,10 +434,10 @@ void MainWindow::replay() {
disableUndo();
disconnect(actionCollection()->action(QStringLiteral("replay")), &QAction::triggered,
this, &MainWindow::replay);
disconnect(m_game, 0, this, 0);
disconnect(m_game, nullptr, this, nullptr);
connect(m_game, &Game::replayEnd,
this, &MainWindow::reEnableReplay);
disconnect(m_game, 0, m_scene, 0);
disconnect(m_game, nullptr, m_scene, nullptr);
connect(m_game, &Game::replayBegin, m_scene, &Scene::replay);
connect(m_game, &Game::replayEnd, m_scene, &Scene::slotGameOver);
m_game->replay();
......@@ -451,12 +451,12 @@ void MainWindow::reEnableReplay() {
}
void MainWindow::changeSkill() {
if (m_game!=0)
if (m_game!=nullptr)
m_game->setSkill(Kg::difficultyLevel());
}
void MainWindow::changeTheme(int themeId) {
foreach (const Theme &theme, m_themes) {
for (const Theme &theme : std::as_const(m_themes)) {
if (themeId == theme.id()) {
m_theme = theme;
m_scene->setTheme(m_theme);
......
......@@ -45,16 +45,16 @@ using namespace bovo;
namespace gui {
Scene::Scene(const Theme& theme, bool animation)
: m_activate(false), m_game(0), m_curCellSize(10.0), m_player(No), m_animation(animation),
: m_activate(false), m_game(nullptr), m_curCellSize(10.0), m_player(No), m_animation(animation),
m_paintMarker(false), m_showLast(false) {
/** @todo read theme from some configuration, I guess */
/** @todo read file names from from some configuration, I guess */
m_renderer = 0;
m_renderer = nullptr;
loadTheme(theme);
qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
m_hintTimer = new QTimer(this);
m_hintTimer->setSingleShot(true);
m_hintItem = 0;
m_hintItem = nullptr;
setSceneRect( 0, 0, m_curCellSize*(NUMCOLS+2), m_curCellSize*(NUMCOLS+2) );
}
......@@ -80,16 +80,17 @@ void Scene::loadTheme(const Theme& theme) {
m_fill = theme.fill();
QColor color(theme.backgroundColor());
QPalette bgPal;
foreach (QGraphicsView* view, views()) {
const auto vs = views();
for (QGraphicsView* view : vs) {
bgPal.setColor(view->backgroundRole(), color.isValid() ? color : Qt::white);
view->setPalette(bgPal);
}
if (m_renderer == 0)
if (m_renderer == nullptr)
m_renderer = new QSvgRenderer(theme.svg());
else
m_renderer->load(theme.svg());
QList<QGraphicsItem*> allMarks = items();
foreach (QGraphicsItem* item, allMarks) {
const QList<QGraphicsItem*> allMarks = items();
for (QGraphicsItem* item : allMarks) {
if (Mark* mark = qgraphicsitem_cast<Mark *>(item)) {
mark->setFill(m_fill);
mark->update(mark->boundingRect());
......@@ -149,8 +150,8 @@ void Scene::updateBoard(const Move& move) {
invalidate(0, 0, width(), height());
}
removeShowLast();
QList<QGraphicsItem*> allMarks = items();
foreach (QGraphicsItem* item, allMarks) {
const QList<QGraphicsItem*> allMarks = items();
for (QGraphicsItem* item : allMarks) {
if (Mark* mark = qgraphicsitem_cast<Mark *>(item)) {
if (mark->row() == move.y() && mark->col() == move.x()) {
if (m_animation) {
......@@ -342,20 +343,20 @@ void Scene::hint(const Move& hint) {
}
void Scene::destroyHint() {
if (m_hintItem != 0) {
if (m_hintItem != nullptr) {
m_hintTimer->disconnect();
m_hintTimer->stop();
m_hintItem->killAnimation();
removeItem(m_hintItem);
m_hintItem->deleteLater();
m_hintItem = 0;
m_hintItem = nullptr;
}
}
void Scene::hintTimeout() {
if (!m_animation) {
destroyHint();
} else if (m_hintItem != 0) {
} else if (m_hintItem != nullptr) {
connect(m_hintItem, &HintItem::killed, this, &Scene::destroyHint);
m_hintItem->kill();
}
......@@ -369,7 +370,7 @@ void Scene::enableAnimation(bool enabled) {
}
void Scene::killAnimations() {
if (m_hintItem != 0) {
if (m_hintItem != nullptr) {
m_hintItem->killAnimation();
}
}
......@@ -380,8 +381,8 @@ void Scene::killMark(Mark* mark) {
}
void Scene::replay() {
QList<QGraphicsItem*> allMarks = items();
foreach (QGraphicsItem* mark, allMarks) {
const QList<QGraphicsItem*> allMarks = items();
for (QGraphicsItem* mark : allMarks) {
removeItem(mark);
delete mark;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment