Commit 23132eee authored by Andrius Štikonas's avatar Andrius Štikonas

Port away from Q_FOREACH.

parent 3f29d795
project(kgoldrunner) project(kgoldrunner)
cmake_minimum_required (VERSION 2.8.12 FATAL_ERROR) cmake_minimum_required (VERSION 2.8.12 FATAL_ERROR)
set (QT_MIN_VERSION "5.3.0") set (QT_MIN_VERSION "5.7.0")
set (KF5_MIN_VERSION "5.15.0") set (KF5_MIN_VERSION "5.15.0")
find_package(ECM 1.7.0 REQUIRED CONFIG) find_package(ECM 1.7.0 REQUIRED CONFIG)
......
#include "kgrdebug.h"
/**************************************************************************** /****************************************************************************
* Copyright 2009 Ian Wadham <iandw.au@gmail.com> * * Copyright 2009 Ian Wadham <iandw.au@gmail.com> *
* * * *
...@@ -17,6 +15,7 @@ ...@@ -17,6 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * * along with this program. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************/ ****************************************************************************/
#include "kgrdebug.h"
#include "kgreditor.h" #include "kgreditor.h"
#include "kgrscene.h" #include "kgrscene.h"
#include "kgrview.h" #include "kgrview.h"
...@@ -772,7 +771,7 @@ bool KGrEditor::ownerOK (Owner o) ...@@ -772,7 +771,7 @@ bool KGrEditor::ownerOK (Owner o)
// Check that this owner has at least one set of game data. // Check that this owner has at least one set of game data.
bool OK = false; bool OK = false;
foreach (KGrGameData * d, gameList) { for (KGrGameData * d : qAsConst(gameList)) {
if (d->owner == o) { if (d->owner == o) {
OK = true; OK = true;
break; break;
...@@ -809,7 +808,7 @@ bool KGrEditor::saveGameData (Owner o) ...@@ -809,7 +808,7 @@ bool KGrEditor::saveGameData (Owner o)
int i, len; int i, len;
char ch; char ch;
foreach (KGrGameData * gData, gameList) { for (KGrGameData * gData : qAsConst(gameList)) {
if (gData->owner == o) { if (gData->owner == o) {
line = QString ("%1 %2 %3 %4\n") line = QString ("%1 %2 %3 %4\n")
.arg (gData->nLevels, 3, 10, QChar('0')) // int 00n .arg (gData->nLevels, 3, 10, QChar('0')) // int 00n
......
#include "kgrdebug.h"
/**************************************************************************** /****************************************************************************
* Copyright 2003 Marco Krüger <grisuji@gmx.de> * * Copyright 2003 Marco Krüger <grisuji@gmx.de> *
* Copyright 2003,2009 Ian Wadham <iandw.au@gmail.com> * * Copyright 2003,2009 Ian Wadham <iandw.au@gmail.com> *
...@@ -18,6 +16,7 @@ ...@@ -18,6 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * * along with this program. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************/ ****************************************************************************/
#include "kgrdebug.h"
#include "kgrgame.h" #include "kgrgame.h"
#include "kgrview.h" #include "kgrview.h"
...@@ -448,7 +447,7 @@ void KGrGame::initGame() ...@@ -448,7 +447,7 @@ void KGrGame::initGame()
level = 1; level = 1;
int n = 0; int n = 0;
dbk1 << gameIndex << level << "Search:" << prevGamePrefix << prevLevel; dbk1 << gameIndex << level << "Search:" << prevGamePrefix << prevLevel;
foreach (KGrGameData * gameData, gameList) { for (KGrGameData * gameData : qAsConst(gameList)) {
dbk1 << "Trying:" << n << gameData->prefix; dbk1 << "Trying:" << n << gameData->prefix;
if (gameData->prefix == prevGamePrefix) { if (gameData->prefix == prevGamePrefix) {
gameIndex = n; gameIndex = n;
......
...@@ -47,7 +47,7 @@ IOStatus KGrGameIO::fetchGameListData ...@@ -47,7 +47,7 @@ IOStatus KGrGameIO::fetchGameListData
} }
// Loop to read each file containing game-data. // Loop to read each file containing game-data.
foreach (const QString &filename, files) { for (const QString &filename : qAsConst(files)) {
if (filename == "game_ende.txt") { if (filename == "game_ende.txt") {
continue; // Skip the "ENDE" file. continue; // Skip the "ENDE" file.
} }
......
...@@ -196,7 +196,7 @@ void KGrLevelGrid::calculateCellAccess (const int i, const int j) ...@@ -196,7 +196,7 @@ void KGrLevelGrid::calculateCellAccess (const int i, const int j)
void KGrLevelGrid::placeHiddenLadders() void KGrLevelGrid::placeHiddenLadders()
{ {
foreach (int offset, hiddenLadders) { for (const int &offset : qAsConst(hiddenLadders)) {
int i = offset % width; int i = offset % width;
int j = offset / width; int j = offset / width;
changeCellAt (i, j, LADDER); changeCellAt (i, j, LADDER);
......
#include "kgrdebug.h"
/**************************************************************************** /****************************************************************************
* Copyright 2009 Ian Wadham <iandw.au@gmail.com> * * Copyright 2009 Ian Wadham <iandw.au@gmail.com> *
* * * *
...@@ -30,6 +28,7 @@ ...@@ -30,6 +28,7 @@
#include "kgrrulebook.h" #include "kgrrulebook.h"
#include "kgrlevelgrid.h" #include "kgrlevelgrid.h"
#include "kgrrunner.h" #include "kgrrunner.h"
#include "kgrdebug.h"
#include "kgoldrunner_debug.h" #include "kgoldrunner_debug.h"
#include <KMessageBox> // TODO - Remove. #include <KMessageBox> // TODO - Remove.
...@@ -231,7 +230,7 @@ void KGrLevelPlayer::init (KGrView * view, ...@@ -231,7 +230,7 @@ void KGrLevelPlayer::init (KGrView * view,
view->gameScene(), SLOT (startAnimation (int, bool, int, int, view->gameScene(), SLOT (startAnimation (int, bool, int, int,
int, Direction, AnimationType))); int, Direction, AnimationType)));
foreach (KGrEnemy * enemy, enemies) { for (KGrEnemy * enemy : qAsConst(enemies)) {
connect (enemy, SIGNAL (startAnimation (int, bool, int, int, connect (enemy, SIGNAL (startAnimation (int, bool, int, int,
int, Direction, AnimationType)), int, Direction, AnimationType)),
view->gameScene(), SLOT (startAnimation (int, bool, int, int, view->gameScene(), SLOT (startAnimation (int, bool, int, int,
...@@ -241,7 +240,7 @@ void KGrLevelPlayer::init (KGrView * view, ...@@ -241,7 +240,7 @@ void KGrLevelPlayer::init (KGrView * view,
// Connect the scoring. // Connect the scoring.
connect (hero, SIGNAL (incScore(int)), connect (hero, SIGNAL (incScore(int)),
game, SLOT (incScore(int))); game, SLOT (incScore(int)));
foreach (KGrEnemy * enemy, enemies) { for (KGrEnemy * enemy : qAsConst(enemies)) {
connect (enemy, SIGNAL (incScore(int)), connect (enemy, SIGNAL (incScore(int)),
game, SLOT (incScore(int))); game, SLOT (incScore(int)));
} }
...@@ -614,7 +613,7 @@ bool KGrLevelPlayer::heroCaught (const int heroX, const int heroY) ...@@ -614,7 +613,7 @@ bool KGrLevelPlayer::heroCaught (const int heroX, const int heroY)
return false; return false;
} }
int enemyX, enemyY, pointsPerCell_1; int enemyX, enemyY, pointsPerCell_1;
foreach (KGrEnemy * enemy, enemies) { for (KGrEnemy * enemy : qAsConst(enemies)) {
pointsPerCell_1 = enemy->whereAreYou (enemyX, enemyY) - 1; pointsPerCell_1 = enemy->whereAreYou (enemyX, enemyY) - 1;
if (((heroX < enemyX) ? ((heroX + pointsPerCell_1) >= enemyX) : if (((heroX < enemyX) ? ((heroX + pointsPerCell_1) >= enemyX) :
(heroX <= (enemyX + pointsPerCell_1))) && (heroX <= (enemyX + pointsPerCell_1))) &&
...@@ -636,7 +635,7 @@ KGrEnemy * KGrLevelPlayer::standOnEnemy (const int spriteId, ...@@ -636,7 +635,7 @@ KGrEnemy * KGrLevelPlayer::standOnEnemy (const int spriteId,
return 0; return 0;
} }
int enemyX, enemyY, pointsPerCell; int enemyX, enemyY, pointsPerCell;
foreach (KGrEnemy * enemy, enemies) { for (KGrEnemy * enemy : qAsConst(enemies)) {
pointsPerCell = enemy->whereAreYou (enemyX, enemyY); pointsPerCell = enemy->whereAreYou (enemyX, enemyY);
if (((enemyY == (y + pointsPerCell)) || if (((enemyY == (y + pointsPerCell)) ||
(enemyY == (y + pointsPerCell - 1))) && (enemyY == (y + pointsPerCell - 1))) &&
...@@ -789,7 +788,7 @@ void KGrLevelPlayer::tick (bool missed, int scaledTime) ...@@ -789,7 +788,7 @@ void KGrLevelPlayer::tick (bool missed, int scaledTime)
return; return;
} }
foreach (KGrEnemy * enemy, enemies) { for (KGrEnemy * enemy : qAsConst(enemies)) {
enemy->run (scaledTime); enemy->run (scaledTime);
} }
...@@ -1220,7 +1219,7 @@ void KGrLevelPlayer::startLogging() ...@@ -1220,7 +1219,7 @@ void KGrLevelPlayer::startLogging()
void KGrLevelPlayer::showFigurePositions() void KGrLevelPlayer::showFigurePositions()
{ {
hero->showState(); hero->showState();
foreach (KGrEnemy * enemy, enemies) { for (KGrEnemy * enemy : qAsConst(enemies)) {
enemy->showState(); enemy->showState();
} }
} }
......
...@@ -87,7 +87,8 @@ void KGrRenderer::matchThemes (const KgTheme * currentSetTheme) ...@@ -87,7 +87,8 @@ void KGrRenderer::matchThemes (const KgTheme * currentSetTheme)
// Start of game or change of theme: initialise the counts of pixmap keys. // Start of game or change of theme: initialise the counts of pixmap keys.
initPixmapKeys(); initPixmapKeys();
foreach (const KgTheme * actorsTheme, m_actorsProvider->themes()) { const auto themes = m_actorsProvider->themes();
for (const KgTheme * actorsTheme : themes) {
if (actorsTheme->customData("Set") == if (actorsTheme->customData("Set") ==
currentSetTheme->customData("Set")) { currentSetTheme->customData("Set")) {
m_actorsProvider->setCurrentTheme (actorsTheme); m_actorsProvider->setCurrentTheme (actorsTheme);
......
...@@ -135,13 +135,13 @@ void KGrScene::redrawScene () ...@@ -135,13 +135,13 @@ void KGrScene::redrawScene ()
m_gradient.setColorAt (0.85, QColor (0, 0, 0, 0)); m_gradient.setColorAt (0.85, QColor (0, 0, 0, 0));
int index = 0; int index = 0;
foreach (KGameRenderedItem * tile, m_tiles) { for (KGameRenderedItem * tile : qAsConst(m_tiles)) {
if (tile) { if (tile) {
setTile (tile, tileSize, index/m_tilesHigh, index%m_tilesHigh); setTile (tile, tileSize, index/m_tilesHigh, index%m_tilesHigh);
} }
index++; index++;
} }
foreach (KGrSprite * sprite, m_sprites) { for (KGrSprite * sprite : qAsConst(m_sprites)) {
if (sprite) { if (sprite) {
sprite->changeCoordinateSystem sprite->changeCoordinateSystem
(m_topLeftX, m_topLeftY, tileSize); (m_topLeftX, m_topLeftY, tileSize);
...@@ -483,7 +483,7 @@ int KGrScene::makeSprite (const char type, int i, int j) ...@@ -483,7 +483,7 @@ int KGrScene::makeSprite (const char type, int i, int j)
void KGrScene::animate (bool missed) void KGrScene::animate (bool missed)
{ {
foreach (KGrSprite * sprite, m_sprites) { for (KGrSprite * sprite : qAsConst(m_sprites)) {
if (sprite != 0) { if (sprite != 0) {
sprite->animate (missed); sprite->animate (missed);
} }
...@@ -561,7 +561,7 @@ void KGrScene::gotGold (const int spriteId, const int i, const int j, ...@@ -561,7 +561,7 @@ void KGrScene::gotGold (const int spriteId, const int i, const int j,
void KGrScene::showHiddenLadders (const QList<int> & ladders, const int width) void KGrScene::showHiddenLadders (const QList<int> & ladders, const int width)
{ {
foreach (int offset, ladders) { for (const int &offset : ladders) {
int i = offset % width; int i = offset % width;
int j = offset / width; int j = offset / width;
paintCell (i, j, LADDER); paintCell (i, j, LADDER);
......
...@@ -358,8 +358,8 @@ void KGrSLDialog::slSetGames (int cIndex) ...@@ -358,8 +358,8 @@ void KGrSLDialog::slSetGames (int cIndex)
sortOrder1 << 'N' << 'C' << 'T'; sortOrder1 << 'N' << 'C' << 'T';
sortOrder2 << 'T' << 'K'; sortOrder2 << 'T' << 'K';
foreach (char sortItem1, sortOrder1) { for (char sortItem1 : qAsConst(sortOrder1)) {
foreach (char sortItem2, sortOrder2) { for (char sortItem2 : qAsConst(sortOrder2)) {
for (i = 0; i < imax; i++) { for (i = 0; i < imax; i++) {
if ((myGameList.at (i)->skill == sortItem1) && if ((myGameList.at (i)->skill == sortItem1) &&
(myGameList.at (i)->rules == sortItem2)) { (myGameList.at (i)->rules == sortItem2)) {
......
Markdown is supported
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