Commit 374c259e authored by Alexander Lohnau's avatar Alexander Lohnau 💬

Use qAsConst where appropriate

parent bbfca8e3
......@@ -154,14 +154,14 @@ void Board::movePiece(const Move& move) {
}
if ( Settings::showDanger() ) {
bool check = false;
for ( Piece* piece : m_grid ) {
for ( Piece* piece : qAsConst(m_grid) ) {
if ( piece->color() == m_currentPlayer && Manager::self()->rules()->isAttacking ( piece->boardPos() ) ) {
check = true;
addMarker ( piece->boardPos(), Danger );
}
}
if ( check ) {
for ( Piece* piece : m_grid ) {
for ( Piece* piece : qAsConst(m_grid) ) {
if ( piece->color() != m_currentPlayer && piece->pieceType() == King )
addMarker ( piece->boardPos(), Danger );
}
......@@ -242,7 +242,7 @@ void Board::mousePressEvent(QGraphicsSceneMouseEvent* e) {
}
d_piece->setZValue ( dragZValue );
if ( Settings::showMarker() ) {
for ( const Move& t_move : t_legalMoves )
for ( const Move& t_move : qAsConst(t_legalMoves) )
addMarker ( t_move.to(), LegalMove );
}
draggedPiece = d_piece;
......@@ -452,7 +452,7 @@ void Board::updateTheme() {
m_borders << tItem;
m_borders << new Item ( renderer, lrBorderKey, this, Pos() );
for ( Item* item : m_borders )
for ( Item* item : qAsConst(m_borders) )
item->setZValue ( borderZValue );
}
if ( m_displayNotations ) {
......@@ -469,7 +469,7 @@ void Board::updateTheme() {
m_notations << new Item ( renderer, numbersKey, this, Pos() );
m_notations << new Item ( renderer, lettersKey, this, Pos() );
m_notations << new Item ( renderer, numbersKey, this, Pos() );
for ( Item* item : m_notations )
for ( Item* item : qAsConst(m_notations) )
item->setZValue ( notationZValue );
}
addTiles();
......@@ -529,11 +529,11 @@ void Board::updateGraphics() {
QPointF bottomBorderPoint = m_boardRect.bottomLeft() - QPoint ( vBorderMargin, 0 );
QPointF leftBorderPoint = m_boardRect.topLeft() - QPoint ( vBorderMargin, 0 );
for ( Piece* p : m_grid )
for ( Piece* p : qAsConst(m_grid) )
centerAndResize ( p, tSize );
for ( Item* t : m_tiles )
for ( Item* t : qAsConst(m_tiles) )
centerAndResize ( t, tSize, Settings::animateBoard() );
for ( Item* t : markers )
for ( Item* t : qAsConst(markers) )
centerAndResize ( t, tSize );
if ( m_displayBorders ) {
m_borders[0]->moveAndResize ( bottomBorderPoint, m_tileSize, hBorderSize, Settings::animateBoard() );
......@@ -550,12 +550,12 @@ void Board::updateGraphics() {
}
void Board::changeDisplayedPlayer() {
for ( Piece* p : m_grid )
for ( Piece* p : qAsConst(m_grid) )
centerOnPos ( p );
for ( Item* i : markers )
for ( Item* i : qAsConst(markers) )
centerOnPos ( i );
if ( Settings::animateBoard() ) {
for ( Item* i : m_tiles )
for ( Item* i : qAsConst(m_tiles) )
centerOnPos ( i );
}
if ( m_displayNotations ) {
......
......@@ -373,7 +373,7 @@ void MainWindow::protocolInitSuccesful() {
QList<Protocol::ToolWidgetData> list;
list << Protocol::black()->toolWidgets();
list << Protocol::white()->toolWidgets();
for (const auto& data : list) {
for (const auto& data : qAsConst(list)) {
switch(data.type) {
case Protocol::ConsoleToolWidget:
if(data.owner == White) {
......
......@@ -124,7 +124,7 @@ void KnightsView::showAllOffersToggled() {
void KnightsView::popupHidden(int id) {
qCDebug(LOG_KNIGHTS) << m_offerWidgets << id << m_showAllOffers;
for (OfferWidget* widget : m_offerWidgets) {
for (OfferWidget* widget : qAsConst(m_offerWidgets)) {
if ( widget->id() == id )
m_offerWidgets.removeAll(widget);
}
......@@ -141,7 +141,7 @@ void KnightsView::updateOffers() {
return;
ui->showAllOffers->setIcon ( QIcon::fromTheme(QLatin1String( m_showAllOffers ? "arrow-up-double" : "arrow-down-double" )) );
ui->showAllOffers->setVisible ( m_offerWidgets.size() > 1 );
for (OfferWidget* widget : m_offerWidgets) {
for (OfferWidget* widget : qAsConst(m_offerWidgets)) {
layout->removeWidget ( widget );
widget->hide();
}
......
......@@ -94,7 +94,7 @@ void TextProtocol::write(const char* text) {
void TextProtocol::setConsole(ChatWidget* widget) {
m_console = widget;
for ( const ChatWidget::Message& message : messages )
for ( const ChatWidget::Message& message : qAsConst(messages) )
m_console->addText ( message );
messages.clear();
}
......
......@@ -115,7 +115,7 @@ void UciProtocol::requestNextMove() {
if ( !mMoveHistory.isEmpty() ) {
str += QLatin1String(" moves");
for ( const Move& move : mMoveHistory ) {
for ( const Move& move : qAsConst(mMoveHistory) ) {
QString moveString = QLatin1Char(' ') + move.from().string() + move.to().string();
if ( move.promotedType() )
moveString += Piece::charFromType ( move.promotedType() ).toLower();
......
......@@ -128,7 +128,7 @@ QList<Move> ChessRules::legalMoves ( const Pos& pos ) {
Color color = m_grid->value ( pos )->color();
switch ( m_grid->value ( pos )->pieceType() ) {
case King:
for ( const Pos& d : directions ) {
for ( const Pos& d : qAsConst(directions) ) {
for ( const Move& m : movesInDirection ( d, pos, 1 ) )
moves << m;
}
......@@ -136,19 +136,19 @@ QList<Move> ChessRules::legalMoves ( const Pos& pos ) {
moves << castlingMoves ( pos );
break;
case Queen:
for ( const Pos& d : directions )
for ( const Pos& d : qAsConst(directions) )
moves << movesInDirection ( d, pos );
break;
case Bishop:
for ( const Pos& d : diagDirs )
for ( const Pos& d : qAsConst(diagDirs) )
moves << movesInDirection ( d, pos );
break;
case Rook:
for ( const Pos& d : lineDirs )
for ( const Pos& d : qAsConst(lineDirs) )
moves << movesInDirection ( d, pos );
break;
case Knight:
for ( const Pos& d : knightDirs ) {
for ( const Pos& d : qAsConst(knightDirs) ) {
if ( !Board::isInBoard ( pos + d ) )
continue;
if ( !m_grid->contains ( pos + d ) )
......@@ -159,7 +159,7 @@ QList<Move> ChessRules::legalMoves ( const Pos& pos ) {
break;
case Pawn:
moves << pawnMoves ( pos );
for ( const Move& m : m_enPassantMoves ) {
for ( const Move& m : qAsConst(m_enPassantMoves) ) {
if ( m.from() == pos )
moves << m;
}
......@@ -170,7 +170,7 @@ QList<Move> ChessRules::legalMoves ( const Pos& pos ) {
//from the list of possible moves, remove those moves where the king would be under attack
Pos currKingPos = kingPos[color];
for ( const Move& m : moves ) {
for ( const Move& m : qAsConst(moves) ) {
Grid t_grid = *m_grid;
t_grid.insert ( m.to(), t_grid.take ( pos ) );
if ( ( isKingMoving && isAttacked ( m.to(), color, &t_grid ) ) || ( !isKingMoving && isAttacked ( currKingPos, color, &t_grid ) ) ) {
......@@ -187,23 +187,23 @@ QList<Move> ChessRules::legalAttackMoves ( const Pos& pos, Grid* grid ) {
QList<Move> moves;
switch ( grid->value ( pos )->pieceType() ) {
case King:
for ( const Pos& d : directions )
for ( const Pos& d : qAsConst(directions) )
moves << movesInDirection ( d, pos, 1, true, grid );
break;
case Queen:
for ( const Pos& d : directions )
for ( const Pos& d : qAsConst(directions) )
moves << movesInDirection ( d, pos, 8, true, grid );
break;
case Bishop:
for ( const Pos& d : diagDirs )
for ( const Pos& d : qAsConst(diagDirs) )
moves << movesInDirection ( d, pos, 8, true, grid );
break;
case Rook:
for ( const Pos& d : lineDirs )
for ( const Pos& d : qAsConst(lineDirs) )
moves << movesInDirection ( d, pos, 8, true, grid );
break;
case Knight:
for ( const Pos& d : knightDirs ) {
for ( const Pos& d : qAsConst(knightDirs) ) {
if ( Board::isInBoard ( pos + d ) )
moves << Move ( pos, pos + d );
}
......@@ -415,7 +415,7 @@ QList< Move > ChessRules::pawnMoves ( const Pos& pos ) {
list << Move ( pos, pos + 2*forwardDirection );
}
// Normal capturing
for ( const Pos& captureDir : captureDirections ) {
for ( const Pos& captureDir : qAsConst(captureDirections) ) {
if ( m_grid->contains ( pos + captureDir ) && m_grid->value ( pos + captureDir )->color() != m_grid->value ( pos )->color() )
list << Move ( pos, pos + captureDir, Move::Take );
}
......@@ -450,7 +450,7 @@ void ChessRules::moveMade ( const Move& m ) {
if ( length ( m ) == 2 ) {
Pos mid = ( m.to() + m.from() ) / 2;
QList<Direction> dirs = QList<Direction>() << W << E;
for ( Direction dir : dirs )
for ( Direction dir : qAsConst(dirs) )
if ( m_grid->contains ( m.to() + directions[dir] ) ) {
Move enPassantMove;
enPassantMove.setFrom ( m.to() + directions[dir] );
......@@ -635,7 +635,7 @@ void ChessRules::changeNotation ( Move* move, Move::Notation notation, Color col
qCDebug(LOG_KNIGHTS) << possibilities;
for ( const QString& text : possibilities ) {
for ( const QString& text : qAsConst(possibilities) ) {
Move m ( text );
checkSpecialFlags ( &m, color );
if ( m.isValid() ) {
......
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