summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederik Schwarzer <[email protected]>2016-01-08 02:47:01 +0100
committerFrederik Schwarzer <[email protected]>2016-01-08 02:47:01 +0100
commita907bc81cd89ec723c3aa2cf35362a6e6baf9b4e (patch)
tree48517246eec275a5dd15c7a7ec67c00abee532da
parent72aa3bbc5e1e2aa9605f0d851db5307c7ac5b9dd (diff)
Constness.
-rw-r--r--src/game/game.cpp12
-rw-r--r--src/game/score.cpp2
-rw-r--r--src/gui/config/generalconfig.cpp2
-rw-r--r--src/gui/graphicsview/gamescene.cpp46
-rw-r--r--src/gui/graphicsview/gameview.cpp2
-rw-r--r--src/gui/graphicsview/themerenderer.cpp4
-rw-r--r--src/gui/widgets/errorwidget.cpp2
-rw-r--r--src/gui/widgets/gamewidget.cpp13
-rw-r--r--src/gui/widgets/setupwidget.cpp20
9 files changed, 43 insertions, 60 deletions
diff --git a/src/game/game.cpp b/src/game/game.cpp
index 197d15b..0f247a8 100644
--- a/src/game/game.cpp
+++ b/src/game/game.cpp
@@ -81,7 +81,7 @@ bool Game::start(const QString &command)
// Test if we started a GTP-compatible Go game
m_process.write("name\n");
m_process.waitForReadyRead();
- QString response = m_process.readAllStandardOutput();
+ const QString response = m_process.readAllStandardOutput();
if (response.isEmpty() || !response.startsWith(QLatin1String("="))) {
m_response = QLatin1String("Game did not respond to GTP command \"name\"");
//qDebug() << m_response;
@@ -90,7 +90,7 @@ bool Game::start(const QString &command)
} else {
m_engineName = m_response;
}
- ////qDebug() << "Game is a GTP-compatible Go game";
+ //qDebug() << "Game is a GTP-compatible Go game";
m_process.write("version\n");
if (waitResponse()) {
@@ -113,7 +113,7 @@ bool Game::init()
return false;
}
- ////qDebug() << "Init game!";
+ //qDebug() << "Init game!";
m_process.write("clear_board\n");
if (waitResponse()) {
@@ -339,7 +339,7 @@ bool Game::playMove(const Player &player, const Stone &stone, bool undoable)
undoStr = i18n("Black passed");
}
}
- ////qDebug() << "Push new undo command" << undoStr;
+ //qDebug() << "Push new undo command" << undoStr;
m_undoStack.push(new UndoCommand(player, moveType, undoStr));
}
@@ -603,7 +603,7 @@ QList<Stone> Game::bestMoves(const Player &player)
m_process.write("top_moves_black\n");
}
if (waitResponse(true) && !m_response.isEmpty()) {
- QStringList parts = m_response.split(' ');
+ const QStringList parts = m_response.split(' ');
if (parts.size() % 2 == 0) {
for (int i = 0; i < parts.size(); i += 2) {
list.append(Stone(parts[i], QString(parts[i + 1]).toFloat()));
@@ -804,5 +804,3 @@ void Game::setCurrentPlayer(Player &player)
}
} // End of namespace Kigo
-
-
diff --git a/src/game/score.cpp b/src/game/score.cpp
index 8a559b2..20a9b1c 100644
--- a/src/game/score.cpp
+++ b/src/game/score.cpp
@@ -70,5 +70,3 @@ QString Score::toString() const
}
} // End of namespace Kigo
-
-
diff --git a/src/gui/config/generalconfig.cpp b/src/gui/config/generalconfig.cpp
index a629af3..fd6d1b4 100644
--- a/src/gui/config/generalconfig.cpp
+++ b/src/gui/config/generalconfig.cpp
@@ -32,7 +32,7 @@ GeneralConfig::GeneralConfig(QWidget *parent)
setupUi(this);
kcfg_EngineCommand->hide(); // Only used internally
- QString engineCommand = Preferences::engineCommand();
+ const QString engineCommand = Preferences::engineCommand();
engineExecutable->setUrl(QUrl::fromLocalFile(engineCommand.section(' ', 0, 0)));
connect(engineExecutable, &KUrlRequester::textChanged, this, &GeneralConfig::updateEngineCommand);
engineParameters->setText(engineCommand.section(' ', 1));
diff --git a/src/gui/graphicsview/gamescene.cpp b/src/gui/graphicsview/gamescene.cpp
index d920c75..ff66b3f 100644
--- a/src/gui/graphicsview/gamescene.cpp
+++ b/src/gui/graphicsview/gamescene.cpp
@@ -132,7 +132,7 @@ void GameScene::showTerritory(bool show)
void GameScene::updateStoneItems()
{
QGraphicsPixmapItem *item;
- int halfStoneSize = m_stonePixmapSize.width() / 2;
+ const int halfStoneSize = m_stonePixmapSize.width() / 2;
foreach (item, m_stoneItems) { // Clear all stone items
removeItem(item);
@@ -142,7 +142,7 @@ void GameScene::updateStoneItems()
foreach (const Stone &stone, m_game->stones(m_game->blackPlayer())) {
item = addPixmap(ThemeRenderer::self()->renderElement(ThemeRenderer::Element::BlackStone, m_stonePixmapSize));
item->setZValue(2);
- int xOff = stone.x() >= 'I' ? stone.x() - 'A' - 1 : stone.x() - 'A';
+ const int xOff = stone.x() >= 'I' ? stone.x() - 'A' - 1 : stone.x() - 'A';
item->setPos(QPointF(m_gridRect.x() + xOff * m_cellSize - halfStoneSize + 1,
m_gridRect.y() + (m_boardSize - stone.y()) * m_cellSize - halfStoneSize + 1));
m_stoneItems.append(item);
@@ -150,7 +150,7 @@ void GameScene::updateStoneItems()
foreach (const Stone &stone, m_game->stones(m_game->whitePlayer())) {
item = addPixmap(ThemeRenderer::self()->renderElement(ThemeRenderer::Element::WhiteStone, m_stonePixmapSize));
item->setZValue(2);
- int xOff = stone.x() >= 'I' ? stone.x() - 'A' - 1 : stone.x() - 'A';
+ const int xOff = stone.x() >= 'I' ? stone.x() - 'A' - 1 : stone.x() - 'A';
item->setPos(QPointF(m_gridRect.x() + xOff * m_cellSize - halfStoneSize + 1,
m_gridRect.y() + (m_boardSize - stone.y()) * m_cellSize - halfStoneSize + 1));
m_stoneItems.append(item);
@@ -194,7 +194,7 @@ void GameScene::updateHintItems()
m_hintItems.clear();
if (m_showHint) {
- int halfStoneSize = m_stonePixmapSize.width() / 2;
+ const int halfStoneSize = m_stonePixmapSize.width() / 2;
foreach (const Stone &move, m_game->bestMoves(m_game->currentPlayer())) {
QPixmap stonePixmap;
@@ -218,7 +218,7 @@ void GameScene::updateHintItems()
item = addPixmap(stonePixmap);
item->setZValue(4);
- int xOff = move.x() >= 'I' ? move.x() - 'A' - 1 : move.x() - 'A';
+ const int xOff = move.x() >= 'I' ? move.x() - 'A' - 1 : move.x() - 'A';
item->setPos(QPointF(m_gridRect.x() + xOff * m_cellSize - halfStoneSize + 2,
m_gridRect.y() + (m_boardSize - move.y()) * m_cellSize - halfStoneSize + 2));
m_hintItems.append(item);
@@ -237,14 +237,14 @@ void GameScene::updateTerritoryItems()
if (m_showTerritory) {
QPixmap stonePixmap;
- int halfCellSize = m_cellSize / 2;
+ const int halfCellSize = m_cellSize / 2;
//qDebug() << "Fetching territory from engine ...";
stonePixmap = ThemeRenderer::self()->renderElement(ThemeRenderer::Element::WhiteTerritory, QSize(m_cellSize, m_cellSize));
foreach (const Stone &stone, m_game->finalStates(Game::FinalState::FinalWhiteTerritory)) {
item = addPixmap(stonePixmap);
item->setZValue(8);
- int xOff = stone.x() >= 'I' ? stone.x() - 'A' - 1 : stone.x() - 'A';
+ const int xOff = stone.x() >= 'I' ? stone.x() - 'A' - 1 : stone.x() - 'A';
item->setPos(QPointF(m_gridRect.x() + xOff * m_cellSize - halfCellSize + 2,
m_gridRect.y() + (m_boardSize - stone.y()) * m_cellSize - halfCellSize + 2));
m_territoryItems.append(item);
@@ -254,7 +254,7 @@ void GameScene::updateTerritoryItems()
foreach (const Stone &stone, m_game->finalStates(Game::FinalState::FinalBlackTerritory)) {
item = addPixmap(stonePixmap);
item->setZValue(8);
- int xOff = stone.x() >= 'I' ? stone.x() - 'A' - 1 : stone.x() - 'A';
+ const int xOff = stone.x() >= 'I' ? stone.x() - 'A' - 1 : stone.x() - 'A';
item->setPos(QPointF(m_gridRect.x() + xOff * m_cellSize - halfCellSize + 2,
m_gridRect.y() + (m_boardSize - stone.y()) * m_cellSize - halfCellSize + 2));
m_territoryItems.append(item);
@@ -282,11 +282,11 @@ void GameScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
// Show a placement marker at the nearest board intersection
// as a visual aid for the user.
if (m_showPlacementMarker) {
- int row = static_cast<int>((event->scenePos().x() - m_mouseRect.x()) / m_cellSize);
- int col = static_cast<int>((event->scenePos().y() - m_mouseRect.y()) / m_cellSize);
+ const int row = static_cast<int>((event->scenePos().x() - m_mouseRect.x()) / m_cellSize);
+ const int col = static_cast<int>((event->scenePos().y() - m_mouseRect.y()) / m_cellSize);
- int x = m_mouseRect.x() + row * m_cellSize + m_cellSize/2 - m_placementMarkerPixmapSize.width()/2;
- int y = m_mouseRect.y() + col * m_cellSize + m_cellSize/2 - m_placementMarkerPixmapSize.height()/2;
+ const int x = m_mouseRect.x() + row * m_cellSize + m_cellSize/2 - m_placementMarkerPixmapSize.width()/2;
+ const int y = m_mouseRect.y() + col * m_cellSize + m_cellSize/2 - m_placementMarkerPixmapSize.height()/2;
m_placementMarkerItem->setVisible(true);
m_placementMarkerItem->setPos(x, y);
@@ -312,7 +312,7 @@ void GameScene::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if (m_mouseRect.contains(event->scenePos())) {
int row = static_cast<int>((event->scenePos().x() - m_mouseRect.x()) / m_cellSize);
- int col = static_cast<int>((event->scenePos().y() - m_mouseRect.y()) / m_cellSize);
+ const int col = static_cast<int>((event->scenePos().y() - m_mouseRect.y()) / m_cellSize);
if (row < 0 || row >= m_boardSize || col < 0 || col >= m_boardSize) {
return;
}
@@ -331,12 +331,12 @@ void GameScene::drawBackground(QPainter *painter, const QRectF &)
ThemeRenderer::self()->renderElement(ThemeRenderer::Element::Background, painter, sceneRect());
ThemeRenderer::self()->renderElement(ThemeRenderer::Element::Board, painter, m_boardRect);
- int width = m_cellSize / 16;
- QColor color = QColor(20, 30, 20);
+ const int width = m_cellSize / 16;
+ const QColor color = QColor(20, 30, 20);
painter->setPen(QPen(color, width));
for (int i = 0; i < m_boardSize; i++) {
- qreal offset = i * m_cellSize;
+ const qreal offset = i * m_cellSize;
painter->drawLine(QPointF(m_gridRect.left(), m_gridRect.top() + offset),
QPointF(m_gridRect.right(), m_gridRect.top() + offset));
painter->drawLine(QPointF(m_gridRect.left() + offset, m_gridRect.top()),
@@ -349,19 +349,19 @@ void GameScene::drawBackground(QPainter *painter, const QRectF &)
c = QChar('A' + i + 1);
}
- QString n = QString::number(m_boardSize - i);
+ const QString n = QString::number(m_boardSize - i);
QFont f = painter->font();
f.setPointSizeF(m_cellSize / 4);
painter->setFont(f);
- QFontMetrics fm = painter->fontMetrics();
+ const QFontMetrics fm = painter->fontMetrics();
// Draw vertical numbers for board coordinates
- qreal yVert = m_gridRect.top() + offset + fm.descent();
+ const qreal yVert = m_gridRect.top() + offset + fm.descent();
painter->drawText(QPointF(m_gridRect.left() - m_cellSize + 2, yVert), n);
painter->drawText(QPointF(m_gridRect.right() + m_cellSize - fm.width(n) - 3, yVert), n);
// Draw horizontal characters for board coordinates
- qreal xHor = m_gridRect.left() + offset - fm.width(c) / 2;
+ const qreal xHor = m_gridRect.left() + offset - fm.width(c) / 2;
painter->drawText(QPointF(xHor, m_gridRect.top() - m_cellSize + fm.ascent() + 2), QString(c));
painter->drawText(QPointF(xHor, m_gridRect.bottom() + m_cellSize - 3), QString(c));
}
@@ -369,13 +369,13 @@ void GameScene::drawBackground(QPainter *painter, const QRectF &)
// Draw thicker connections on some defined points.
// This is extremely helpful to orientate oneself especially on the 19x19 board.
- int radius = m_cellSize / 10;
+ const int radius = m_cellSize / 10;
painter->setBrush(color);
painter->setRenderHint(QPainter::Antialiasing);
// in order to center properly we need to take line width into account
// if the line has an odd width, we shift 1/5 pixel
- qreal centerOffset = (width % 2) ? 0.5 : 0.0;
+ const qreal centerOffset = (width % 2) ? 0.5 : 0.0;
// only do this for the common board sizes,
// other sizes are a bit odd anyway
@@ -402,5 +402,3 @@ void GameScene::drawBackground(QPainter *painter, const QRectF &)
}
} // End of namespace Kigo
-
-
diff --git a/src/gui/graphicsview/gameview.cpp b/src/gui/graphicsview/gameview.cpp
index 99c418f..825427e 100644
--- a/src/gui/graphicsview/gameview.cpp
+++ b/src/gui/graphicsview/gameview.cpp
@@ -73,5 +73,3 @@ void GameView::resizeEvent(QResizeEvent *event)
}
} // End of namespace Kigo
-
-
diff --git a/src/gui/graphicsview/themerenderer.cpp b/src/gui/graphicsview/themerenderer.cpp
index 0a5269b..82d0e32 100644
--- a/src/gui/graphicsview/themerenderer.cpp
+++ b/src/gui/graphicsview/themerenderer.cpp
@@ -86,7 +86,7 @@ void ThemeRenderer::renderElement(Element element, QPainter *painter, const QRec
if (!m_renderer->isValid() || rect.isEmpty() || painter == 0)
return;
- QPixmap pixmap = renderElement(element, rect.size().toSize());
+ const QPixmap pixmap = renderElement(element, rect.size().toSize());
// Draw pixmap with the parameter provided painter
painter->drawPixmap(static_cast<int>(rect.x()), static_cast<int>(rect.y()), pixmap);
@@ -216,5 +216,3 @@ QSize ThemeRenderer::elementSize(Element element) const
}
} // End of namespace Kigo
-
-
diff --git a/src/gui/widgets/errorwidget.cpp b/src/gui/widgets/errorwidget.cpp
index 43bf1a8..5ec5b20 100644
--- a/src/gui/widgets/errorwidget.cpp
+++ b/src/gui/widgets/errorwidget.cpp
@@ -41,5 +41,3 @@ void ErrorWidget::on_configureButton_clicked()
}
} // End of namespace Kigo
-
-
diff --git a/src/gui/widgets/gamewidget.cpp b/src/gui/widgets/gamewidget.cpp
index 28d3d47..b4407a3 100644
--- a/src/gui/widgets/gamewidget.cpp
+++ b/src/gui/widgets/gamewidget.cpp
@@ -62,9 +62,9 @@ void GameWidget::init()
komiLabel->setText(QString::number(m_game->komi()));
handicapLabel->setText(i18np("%1 Stone", "%1 Stones", m_game->fixedHandicap()));
- QPixmap whiteStone = ThemeRenderer::self()->renderElement(Kigo::ThemeRenderer::Element::WhiteStone, QSize(48, 48));
+ const QPixmap whiteStone = ThemeRenderer::self()->renderElement(Kigo::ThemeRenderer::Element::WhiteStone, QSize(48, 48));
whiteStoneImageLabel->setPixmap(whiteStone);
- QPixmap blackStone = ThemeRenderer::self()->renderElement(Kigo::ThemeRenderer::Element::BlackStone, QSize(48, 48));
+ const QPixmap blackStone = ThemeRenderer::self()->renderElement(Kigo::ThemeRenderer::Element::BlackStone, QSize(48, 48));
blackStoneImageLabel->setPixmap(blackStone);
update();
@@ -75,7 +75,7 @@ void GameWidget::update()
moveLabel->setText(QString::number(m_game->currentMoveNumber()));
if (m_game->moves().size() > 0) {
- Move last = m_game->lastMove();
+ const Move last = m_game->lastMove();
if (last.player()->isWhite()) {
lastMoveLabel->setText(i18nc("Indication who played the last move", "%1 (white)", last.stone().toString()));
} else if (last.player()->isBlack()) {
@@ -86,11 +86,11 @@ void GameWidget::update()
}
if (m_game->currentPlayer().isWhite()) {
- QPixmap whiteStone = ThemeRenderer::self()->renderElement(Kigo::ThemeRenderer::Element::WhiteStone, QSize(64, 64));
+ const QPixmap whiteStone = ThemeRenderer::self()->renderElement(Kigo::ThemeRenderer::Element::WhiteStone, QSize(64, 64));
currentPlayerImageLabel->setPixmap(whiteStone);
currentPlayerLabel->setText(i18n("White's turn"));
} else if (m_game->currentPlayer().isBlack()) {
- QPixmap blackStone = ThemeRenderer::self()->renderElement(Kigo::ThemeRenderer::Element::BlackStone, QSize(64, 64));
+ const QPixmap blackStone = ThemeRenderer::self()->renderElement(Kigo::ThemeRenderer::Element::BlackStone, QSize(64, 64));
currentPlayerImageLabel->setPixmap(blackStone);
currentPlayerLabel->setText(i18n("Black's turn"));
} else {
@@ -113,6 +113,3 @@ void GameWidget::enableFinishButton()
}
} // End of namespace Kigo
-
-
-
diff --git a/src/gui/widgets/setupwidget.cpp b/src/gui/widgets/setupwidget.cpp
index 6c4f7b0..b0507b2 100644
--- a/src/gui/widgets/setupwidget.cpp
+++ b/src/gui/widgets/setupwidget.cpp
@@ -37,9 +37,9 @@ SetupWidget::SetupWidget(Game *game, QWidget *parent)
setupUi(this);
startButton->setIcon(QIcon::fromTheme( QStringLiteral( "media-playback-start" )));
- QPixmap whiteStone = ThemeRenderer::self()->renderElement(Kigo::ThemeRenderer::Element::WhiteStone, QSize(48, 48));
+ const QPixmap whiteStone = ThemeRenderer::self()->renderElement(Kigo::ThemeRenderer::Element::WhiteStone, QSize(48, 48));
whiteStoneImageLabel->setPixmap(whiteStone);
- QPixmap blackStone = ThemeRenderer::self()->renderElement(Kigo::ThemeRenderer::Element::BlackStone, QSize(48, 48));
+ const QPixmap blackStone = ThemeRenderer::self()->renderElement(Kigo::ThemeRenderer::Element::BlackStone, QSize(48, 48));
blackStoneImageLabel->setPixmap(blackStone);
connect(startButton, &QPushButton::clicked, this, &SetupWidget::startClicked);
@@ -81,7 +81,7 @@ void SetupWidget::loadedGame(const QString &fileName)
return;
}
QTextStream in(&file);
- QString content = in.readAll();
+ const QString content = in.readAll();
file.close();
QRegExp re;
@@ -164,10 +164,10 @@ void SetupWidget::loadedGame(const QString &fileName)
re.setPattern(QStringLiteral("TM\\[(\\d+)\\]")); // time limit in seconds
if (re.indexIn(content) > -1) {
- int seconds = re.cap(1).toInt();
- int hours = seconds/3600;
- int minutes = (seconds/60)%60;
- QString minuteString = i18ncp("Time limit of a game in minutes", "%1 minute", "%1 minutes", minutes);
+ const int seconds = re.cap(1).toInt();
+ const int hours = seconds/3600;
+ const int minutes = (seconds/60)%60;
+ const QString minuteString = i18ncp("Time limit of a game in minutes", "%1 minute", "%1 minutes", minutes);
if (hours) {
timeLabel->setText(i18ncp("Time limit of a game, hours, minutes", "%1 hour, %2", "%1 hours, %2", hours, minuteString));
} else {
@@ -190,7 +190,7 @@ void SetupWidget::loadedGame(const QString &fileName)
scoreStaticLabel->setVisible(false);
}
- int count = m_game->moveCount();
+ const int count = m_game->moveCount();
startMoveSpinBox->setSuffix(i18n(" of %1", count));
startMoveSpinBox->setMaximum(count); // And set it as maximum and current
startMoveSpinBox->setValue(count); // move.
@@ -269,7 +269,7 @@ void SetupWidget::on_handicapSpinBox_valueChanged(int value)
void SetupWidget::updateHandicapBox()
{
- int maxFixedHandicap = m_game->fixedHandicapUpperBound();
+ const int maxFixedHandicap = m_game->fixedHandicapUpperBound();
handicapSpinBox->setEnabled(maxFixedHandicap > 0);
handicapSpinBox->setMaximum(maxFixedHandicap);
handicapSpinBox->setValue(m_lastFixedHandicap);
@@ -348,5 +348,3 @@ void SetupWidget::whiteIsComputer(bool computer)
}
} // End of namespace Kigo
-
-