Commit e17627fc authored by Andrius Štikonas's avatar Andrius Štikonas

Port away from Q_FOREACH.

parent 165b779c
project(konquest)
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")
find_package(ECM 1.7.0 REQUIRED CONFIG)
......
......@@ -130,7 +130,7 @@ FleetDlg::setupTable()
void
FleetDlg::update()
{
AttackFleetList fleets = m_standingOrders + m_newFleetList + m_fleetList;
const AttackFleetList fleets = m_standingOrders + m_newFleetList + m_fleetList;
const int standingOrders = m_standingOrders.count();
const int newFleets = standingOrders + m_newFleetList.count();
......@@ -139,7 +139,7 @@ FleetDlg::update()
int row = 0;
QTableWidgetItem *item;
foreach (AttackFleet *curFleet, fleets) {
for (AttackFleet *curFleet : fleets) {
item = new QTableWidgetItem();
if( row < newFleets) {
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
......
......@@ -161,7 +161,7 @@ public:
{
// The player controller changed.
QString playerGuiName = value.toString();
foreach (PlayerGui *playerGui, m_selectablePlayer)
for (PlayerGui *playerGui : qAsConst(m_selectablePlayer))
{
if (playerGui->guiName() == playerGuiName) {
Player *newPlayer = getNewPlayerByGui(playerGui, player->name(), player->color());
......@@ -291,7 +291,7 @@ public:
if (index.column() != 0) {
QComboBox *cbox = static_cast<QComboBox*>(editor);
foreach (PlayerGui* playerGui, m_selectablePlayer) {
for (PlayerGui* playerGui : qAsConst(m_selectablePlayer)) {
cbox->addItem(playerGui->guiName());
}
......@@ -399,7 +399,7 @@ NewGameDlg::updateOwnerCB()
m_w->OwnerCB->clear();
m_w->OwnerCB->addItem(i18n("vacant"));
foreach(Player *player, m_game->players())
for (Player* player : m_game->players())
m_w->OwnerCB->addItem(player->name());
m_w->OwnerCB->addItem(i18n("neutral"));
}
......@@ -656,7 +656,7 @@ NewGameDlg::updateButtonOk()
int nonSpectatorCount = 0;
bool isSaneConfiguration = true;
foreach (Player *player, m_game->players()) {
for (Player *player : m_game->players()) {
if (player->isSpectator()) {
// Spectator player controllers can be completely ignored here as
......@@ -670,7 +670,7 @@ NewGameDlg::updateButtonOk()
bool foundPlanet = false;
foreach (Planet *planet, m_game->planets()) {
for (Planet *planet : m_game->planets()) {
if (planet->player() == player) {
foundPlanet = true;
break;
......
......@@ -40,7 +40,7 @@ Game::Game(QObject *parent) :
connect(&m_gameMachine, SIGNAL(finished()), this, SIGNAL(finished()));
}
QList<Planet*> Game::planets()
const QList<Planet*> Game::planets()
{
return m_map->planets();
}
......@@ -179,7 +179,7 @@ void Game::findWinner()
//qDebug() << "Searching for survivors";
// Check for survivors
Player *winner = 0;
foreach (Player *player, m_players) {
for (Player *player : players()) {
if (player->isNeutral() || player->isSpectator()) {
continue;
}
......
......@@ -65,13 +65,13 @@ public:
static Coordinate generatePlanetCoordinates (int rows, int cols);
static double generateKillPercentage();
static int generatePlanetProduction();
QList<Planet *> planets();
const QList<Planet *> planets();
Map *map() { return m_map; }
Player *currentPlayer() { return m_currentPlayer; }
QList<Player *> players() { return m_players; }
const QList<Player *> players() { return m_players; }
void findWinner();
......
......@@ -231,7 +231,7 @@ GameView::keyPressEvent( QKeyEvent *e )
planetName += e->text().toUpper();
foreach (Planet *p, m_game->planets()) {
for (Planet *p : m_game->planets()) {
if( p->name() == planetName ) {
if ( m_showInformations ) {
m_mapScene->selectPlanet(p);
......@@ -485,7 +485,7 @@ GameView::startNewGame()
delete newGame;
foreach (Player *player, m_game->players()) {
for (Player *player : m_game->players()) {
if (player->isSpectator()) {
// All planets a spectator player has assigned are turned into
......@@ -732,8 +732,8 @@ GameView::showFleets()
FleetDlg *fleetDlg = new FleetDlg( this, current->attackList(),
current->newAttacks(), current->standingOrders());
if (fleetDlg->exec()) {
AttackFleetList *deleteAttacks = fleetDlg->uncheckedFleets();
foreach(AttackFleet *curFleet, *deleteAttacks) {
const AttackFleetList *deleteAttacks = fleetDlg->uncheckedFleets();
for (AttackFleet *curFleet : *deleteAttacks) {
current->cancelNewAttack(curFleet);
}
delete deleteAttacks;
......
......@@ -88,7 +88,7 @@ Map::addNeutralPlanetSomewhere(Player *neutral)
bool
Map::removePlayerPlanet(Player *player)
{
foreach (Planet *planet, planets()) {
for (Planet *planet : planets()) {
if (planet->player() == player) {
delete planet;
return true;
......@@ -108,7 +108,7 @@ Map::removePlayerPlanets(Player *player)
void
Map::turnOverPlayerPlanets(Player* owner, Player* newOwner)
{
foreach (Planet *planet, planets()) {
for (Planet *planet : planets()) {
if (planet->player() == owner) {
planet->setOwner(newOwner);
}
......@@ -120,7 +120,7 @@ int
Map::playerPlanetCount(Player *player)
{
int count = 0;
foreach (Planet *planet, planets()) {
for (Planet *planet : planets()) {
if (planet->player() == player) {
count++;
}
......@@ -147,7 +147,7 @@ Map::UniquePlanetName(void)
{
char c = 'A';
again:
foreach(Planet *planet, planets()) {
for (Planet *planet : planets()) {
if (planet->name().at(0).toLatin1() == c) {
c++;
goto again;
......@@ -161,7 +161,7 @@ void
Map::populateMap(const QList<Player *> &players, Player *neutral, int numNeutralPlanets)
{
// Create a planet for each player.
foreach (Player *player, players) {
for (Player *player : players) {
addPlayerPlanetSomewhere(player);
}
......@@ -188,8 +188,8 @@ Map::distance(Planet *p1, Planet *p2)
Sector*
Map::findRandomFreeSector()
{
foreach (const QList<Sector> &i, m_grid) {
foreach (const Sector &j, i) {
for (const QList<Sector> &i : qAsConst(m_grid)) {
for (const Sector &j : i) {
if (!j.hasPlanet()) {
goto freesectorexists;
}
......@@ -217,12 +217,12 @@ Map::childSectorUpdate()
}
QList <Planet*>
const QList <Planet*>
Map::planets()
{
QList <Planet*>planets;
foreach (const QList<Sector> &i, m_grid) {
foreach (const Sector &j, i) {
for (const QList<Sector> &i : qAsConst(m_grid)) {
for (const Sector &j : i) {
if (j.hasPlanet()) {
planets += j.planet();
}
......
......@@ -67,7 +67,7 @@ public:
return NULL;
}
QList<Planet*> planets();
const QList<Planet*> planets();
protected slots:
void childSectorUpdate();
......
......@@ -235,7 +235,7 @@ void PlanetInfoItem::setPlanet (Planet *planet)
if( m_game->currentPlayer() == planet->player() )
{
int shipsNeeded = 0; // determine how many ships will be needed by standing orders
foreach(AttackFleet* fleet, planet->player()->standingOrders()) {
for (AttackFleet* fleet : planet->player()->standingOrders()) {
if(fleet->source == planet)
shipsNeeded += fleet->shipCount();
}
......
......@@ -67,7 +67,7 @@ void
MapScene::selectPlanet(Planet *planet)
{
unselectPlanet();
foreach (PlanetItem *item, m_planetItems) {
for (PlanetItem *item : qAsConst(m_planetItems)) {
if (item->sector() == planet->sector()) {
item->select();
m_selectedPlanetItem = item;
......
......@@ -105,7 +105,7 @@ AiBecai::play()
* day. Or maybe but them into an own class.
*/
foreach (Fleet *fleet, this->attackList()) {
for (Fleet *fleet : this->attackList()) {
totalOwnFleet += fleet->shipCount();
}
......@@ -120,7 +120,7 @@ AiBecai::play()
double totalKillPercentage = 0;
foreach (Planet *planet, m_game->planets()) {
for (Planet *planet : m_game->planets()) {
totalTotalPlanets += 1;
if (planet->player() == this) {
......@@ -160,7 +160,7 @@ AiBecai::play()
int averageNonOwnPlanetDefenceFleetSize = 0;
foreach (int fleetSize, nonOwnPlanetDefenceFleetSizeList) {
for (const int &fleetSize : qAsConst(nonOwnPlanetDefenceFleetSizeList)) {
averageNonOwnPlanetDefenceFleetSize += fleetSize;
}
......@@ -276,7 +276,7 @@ AiBecai::play()
minimumBaseDefenceFleetSize = totalOwnFleet / totalOwnPlanets;
}
foreach (Planet *home, m_game->planets()) {
for (Planet *home : m_game->planets()) {
if (home->player() != this) {
continue;
}
......@@ -292,7 +292,7 @@ AiBecai::play()
QMultiMap<double, TargetPlanet> targetList;
foreach (Planet *other, m_game->planets()) {
for (Planet *other : m_game->planets()) {
if (other->player() == this) {
if (other != home) {
......@@ -333,7 +333,7 @@ AiBecai::play()
bool found = false;
foreach (AttackFleet *fleet, this->attackList() + this->newAttacks()) {
for (AttackFleet *fleet : this->attackList() + this->newAttacks()) {
if (fleet->destination == other) {
found = true;
break;
......@@ -539,7 +539,7 @@ AiBecai::play()
bool skip = false;
foreach (AttackFleet *fleet, this->attackList() + this->newAttacks()) {
for (AttackFleet *fleet : this->attackList() + this->newAttacks()) {
if ((fleet->destination == closestSupportPlanet) && (fleet->owner == this)) {
skip = true;
break;
......
......@@ -61,7 +61,7 @@ void AiDefault::play()
break;
}
foreach (Planet *home, m_game->planets()) {
for (Planet *home : m_game->planets()) {
if (home->player() == this) {
bool hasAttack = false;
ships = (int)floor(home->ships() * 0.7 );
......@@ -69,7 +69,7 @@ void AiDefault::play()
if (ships >= minimumShips) {
double minDistance = 100;
foreach (Planet *attack, m_game->planets()) {
for (Planet *attack : m_game->planets()) {
if (attack->player() == this)
continue;
......@@ -77,7 +77,7 @@ void AiDefault::play()
double dist = m_game->map()->distance( home, attack );
if (dist < minDistance && attack->ships() < ships ) {
foreach (AttackFleet *curFleet, attackList()) {
for (AttackFleet *curFleet : attackList()) {
if (curFleet->destination == attack) {
skip = true;
break;
......@@ -99,7 +99,7 @@ void AiDefault::play()
int shipsToSend = 0;
bool hasDestination = false;
foreach (Planet *attack, m_game->planets()) {
for (Planet *attack : m_game->planets()) {
bool skip = false;
double dist = m_game->map()->distance( home, attack );
int homeships = (int)floor(home->ships() * 0.5 );
......@@ -107,7 +107,7 @@ void AiDefault::play()
if (dist < minDistance
&& attack->player() == this
&& attack->ships() < homeships ) {
foreach (AttackFleet *curFleet, attackList()) {
for (AttackFleet *curFleet : attackList()) {
if (curFleet->destination == attack) {
skip = true;
break;
......
......@@ -41,10 +41,10 @@ void NeutralPlayer::play()
//qDebug() << "NeutralPlayer::play";
// Go on each attack...
foreach (Player *player, m_game->players()) {
for (Player *player : m_game->players()) {
player->resetTurnStats();
foreach (AttackFleet *fleet, player->attackList()) {
for (AttackFleet *fleet : player->attackList()) {
if (m_game->doFleetArrival(fleet)) {
player->attackDone(fleet);
fleet->deleteLater();
......@@ -60,7 +60,7 @@ void NeutralPlayer::play()
}
// Go over each planet, adding its ships
foreach (Planet *planet, m_game->map()->planets()) {
for (Planet *planet : m_game->map()->planets()) {
//qDebug() << "Turn for planet " << planet->name();
planet->turn(m_game->options());
}
......
......@@ -73,7 +73,7 @@ bool Player::isDead()
{
if (m_attackList.count() > 0)
return false;
foreach (Planet *planet, m_game->planets())
for (Planet *planet : m_game->planets())
if (planet->player() == this)
return false;
return true;
......
......@@ -66,9 +66,9 @@ public:
long long turnProduction() const { return m_turnProduction; }
long long turnShips() const { return m_turnShips; }
AttackFleetList attackList() { return m_attackList; }
AttackFleetList newAttacks() { return m_newAttacks; }
AttackFleetList standingOrders() { return m_standingOrders; }
const AttackFleetList attackList() { return m_attackList; }
const AttackFleetList newAttacks() { return m_newAttacks; }
const AttackFleetList standingOrders() { return m_standingOrders; }
void attackDone(AttackFleet *fleet);
void addAttackFleet(AttackFleet *fleet);
......
......@@ -90,7 +90,7 @@ StandingsWidget::update(const QList<Player *> players )
int row = 0;
QTableWidgetItem *item;
foreach (Player *curPlayer, players) {
for (Player *curPlayer : players) {
item = new QTableWidgetItem();
item->setData(Qt::DisplayRole, curPlayer->name());
item->setData(Qt::DecorationRole, curPlayer->color());
......
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