style: Add braces to all control flow statements (#6887)

* style: Add braces to all control flow statements

  Standardize code style by adding explicit braces to all single-statement
  control flow blocks (if, else, for, while) across the entire codebase.

  Also documents the InsertBraces clang-format option (requires v15+) for
  future automated enforcement.

* InsertBraces-check-enabled
This commit is contained in:
DawnFire42 2026-05-16 13:19:53 -04:00 committed by GitHub
parent 7153f7d4c1
commit aadee34238
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
173 changed files with 2725 additions and 1461 deletions

View file

@ -78,8 +78,9 @@ void GraveyardMenu::populateRevealRandomMenuWithActivePlayers()
const auto &players = player->getGame()->getPlayerManager()->getPlayers().values();
for (auto *other : players) {
if (other == player)
if (other == player) {
continue;
}
QAction *a = mRevealRandomGraveyardCard->addAction(other->getPlayerInfo()->getName());
a->setData(other->getPlayerInfo()->getId());
connect(a, &QAction::triggered, this, &GraveyardMenu::onRevealRandomTriggered);

View file

@ -168,8 +168,9 @@ void HandMenu::populateRevealHandMenuWithActivePlayers()
const auto &players = player->getGame()->getPlayerManager()->getPlayers().values();
for (auto *other : players) {
if (other == player)
if (other == player) {
continue;
}
QAction *a = mRevealHand->addAction(other->getPlayerInfo()->getName());
a->setData(other->getPlayerInfo()->getId());
connect(a, &QAction::triggered, this, &HandMenu::onRevealHandTriggered);
@ -186,8 +187,9 @@ void HandMenu::populateRevealRandomHandCardMenuWithActivePlayers()
const auto &players = player->getGame()->getPlayerManager()->getPlayers().values();
for (auto *other : players) {
if (other == player)
if (other == player) {
continue;
}
QAction *a = mRevealRandomHandCard->addAction(other->getPlayerInfo()->getName());
a->setData(other->getPlayerInfo()->getId());
connect(a, &QAction::triggered, this, &HandMenu::onRevealRandomHandCardTriggered);
@ -197,8 +199,9 @@ void HandMenu::populateRevealRandomHandCardMenuWithActivePlayers()
void HandMenu::onRevealHandTriggered()
{
auto *action = qobject_cast<QAction *>(sender());
if (!action)
if (!action) {
return;
}
const int targetId = action->data().toInt();
player->getPlayerActions()->actRevealHand(targetId);
@ -207,8 +210,9 @@ void HandMenu::onRevealHandTriggered()
void HandMenu::onRevealRandomHandCardTriggered()
{
auto *action = qobject_cast<QAction *>(sender());
if (!action)
if (!action) {
return;
}
const int targetId = action->data().toInt();
player->getPlayerActions()->actRevealRandomHandCard(targetId);

View file

@ -265,8 +265,9 @@ void LibraryMenu::populateRevealLibraryMenuWithActivePlayers()
const auto &players = player->getGame()->getPlayerManager()->getPlayers().values();
for (auto *other : players) {
if (other == player)
if (other == player) {
continue;
}
QAction *a = mRevealLibrary->addAction(other->getPlayerInfo()->getName());
a->setData(other->getPlayerInfo()->getId());
connect(a, &QAction::triggered, this, &LibraryMenu::onRevealLibraryTriggered);
@ -279,8 +280,9 @@ void LibraryMenu::populateLendLibraryMenuWithActivePlayers()
const auto &players = player->getGame()->getPlayerManager()->getPlayers().values();
for (auto *other : players) {
if (other == player)
if (other == player) {
continue;
}
QAction *a = mLendLibrary->addAction(other->getPlayerInfo()->getName());
a->setData(other->getPlayerInfo()->getId());
connect(a, &QAction::triggered, this, &LibraryMenu::onLendLibraryTriggered);
@ -299,8 +301,9 @@ void LibraryMenu::populateRevealTopCardMenuWithActivePlayers()
const auto &players = player->getGame()->getPlayerManager()->getPlayers().values();
for (auto *other : players) {
if (other == player)
if (other == player) {
continue;
}
QAction *a = mRevealTopCard->addAction(other->getPlayerInfo()->getName());
a->setData(other->getPlayerInfo()->getId());
connect(a, &QAction::triggered, this, &LibraryMenu::onRevealTopCardTriggered);

View file

@ -63,8 +63,9 @@ Player::~Player()
qCInfo(PlayerLog) << "Player destructor:" << getPlayerInfo()->getName();
QMapIterator<QString, CardZoneLogic *> i(zones);
while (i.hasNext())
while (i.hasNext()) {
delete i.next().value();
}
zones.clear();
delete playerMenu;

View file

@ -85,8 +85,9 @@ void PlayerActions::playCard(CardItem *card, bool faceDown)
cardToMove->set_pt(info.getPowTough().toStdString());
}
cardToMove->set_tapped(!faceDown && info.getUiAttributes().cipt);
if (tableRow != 3)
if (tableRow != 3) {
cmd.set_target_zone(ZoneNames::TABLE);
}
cmd.set_x(gridPoint.x());
cmd.set_y(gridPoint.y());
}

View file

@ -43,8 +43,9 @@ PlayerListTWI::PlayerListTWI() : QTreeWidgetItem(Type)
bool PlayerListTWI::operator<(const QTreeWidgetItem &other) const
{
// Sort by spectator/player
if (data(1, Qt::UserRole) != other.data(1, Qt::UserRole))
if (data(1, Qt::UserRole) != other.data(1, Qt::UserRole)) {
return data(1, Qt::UserRole).toBool();
}
// Sort by player ID
return data(4, Qt::UserRole + 1).toInt() < other.data(4, Qt::UserRole + 1).toInt();
@ -106,12 +107,14 @@ void PlayerListWidget::addPlayer(const ServerInfo_PlayerProperties &player)
void PlayerListWidget::updatePlayerProperties(const ServerInfo_PlayerProperties &prop, int playerId)
{
if (playerId == -1)
if (playerId == -1) {
playerId = prop.player_id();
}
QTreeWidgetItem *player = players.value(playerId, 0);
if (!player)
if (!player) {
return;
}
bool isSpectator = prop.has_spectator() && prop.spectator();
if (prop.has_judge() || prop.has_spectator()) {
@ -126,13 +129,16 @@ void PlayerListWidget::updatePlayerProperties(const ServerInfo_PlayerProperties
}
if (!isSpectator) {
if (prop.has_conceded())
if (prop.has_conceded()) {
player->setData(2, Qt::UserRole, prop.conceded());
if (prop.has_ready_start())
}
if (prop.has_ready_start()) {
player->setData(2, Qt::UserRole + 1, prop.ready_start());
if (prop.has_conceded() || prop.has_ready_start())
}
if (prop.has_conceded() || prop.has_ready_start()) {
player->setIcon(2, gameStarted ? (prop.conceded() ? concededIcon : QIcon())
: (prop.ready_start() ? readyIcon : notReadyIcon));
}
}
if (prop.has_user_info()) {
player->setData(3, Qt::UserRole, prop.user_info().user_level());
@ -141,30 +147,35 @@ void PlayerListWidget::updatePlayerProperties(const ServerInfo_PlayerProperties
QString::fromStdString(prop.user_info().privlevel())));
player->setText(4, QString::fromStdString(prop.user_info().name()));
const QString country = QString::fromStdString(prop.user_info().country());
if (!country.isEmpty())
if (!country.isEmpty()) {
player->setIcon(4, QIcon(CountryPixmapGenerator::generatePixmap(12, country)));
}
player->setData(4, Qt::UserRole, QString::fromStdString(prop.user_info().name()));
}
if (prop.has_player_id())
if (prop.has_player_id()) {
player->setData(4, Qt::UserRole + 1, prop.player_id());
}
if (!isSpectator) {
if (prop.has_deck_hash()) {
player->setText(5, QString::fromStdString(prop.deck_hash()));
}
if (prop.has_sideboard_locked())
if (prop.has_sideboard_locked()) {
player->setIcon(5, prop.sideboard_locked() ? lockIcon : QIcon());
}
}
if (prop.has_ping_seconds())
if (prop.has_ping_seconds()) {
player->setIcon(0, QIcon(PingPixmapGenerator::generatePixmap(12, prop.ping_seconds(), 10)));
}
}
void PlayerListWidget::removePlayer(int playerId)
{
QTreeWidgetItem *player = players.value(playerId, 0);
if (!player)
if (!player) {
return;
}
players.remove(playerId);
delete takeTopLevelItem(indexOfTopLevelItem(player));
}
@ -193,13 +204,14 @@ void PlayerListWidget::setGameStarted(bool _gameStarted, bool resuming)
QTreeWidgetItem *twi = i.next().value();
bool isPlayer = twi->data(1, Qt::UserRole).toBool();
if (!isPlayer)
if (!isPlayer) {
continue;
}
if (gameStarted) {
if (resuming)
if (resuming) {
twi->setIcon(2, twi->data(2, Qt::UserRole).toBool() ? concededIcon : QIcon());
else {
} else {
twi->setData(2, Qt::UserRole, false);
twi->setIcon(2, QIcon());
}
@ -211,8 +223,9 @@ void PlayerListWidget::setGameStarted(bool _gameStarted, bool resuming)
void PlayerListWidget::showContextMenu(const QPoint &pos, const QModelIndex &index)
{
if (!userContextMenu)
if (!userContextMenu) {
return;
}
const QString &userName = index.sibling(index.row(), 4).data(Qt::UserRole).toString();
int playerId = index.sibling(index.row(), 4).data(Qt::UserRole + 1).toInt();

View file

@ -21,15 +21,18 @@ bool PlayerManager::isMainPlayerConceded() const
Player *PlayerManager::getActiveLocalPlayer(int activePlayer) const
{
Player *active = players.value(activePlayer, 0);
if (active)
if (active->getPlayerInfo()->getLocal())
if (active) {
if (active->getPlayerInfo()->getLocal()) {
return active;
}
}
QMapIterator<int, Player *> playerIterator(players);
while (playerIterator.hasNext()) {
Player *temp = playerIterator.next().value();
if (temp->getPlayerInfo()->getLocal())
if (temp->getPlayerInfo()->getLocal()) {
return temp;
}
}
return nullptr;
@ -66,8 +69,9 @@ void PlayerManager::removePlayer(int playerId)
Player *PlayerManager::getPlayer(int playerId) const
{
Player *player = players.value(playerId, 0);
if (!player)
if (!player) {
return nullptr;
}
return player;
}

View file

@ -128,8 +128,9 @@ void PlayerTarget::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*o
resetPainterTransform(painter);
QString name = QString::fromStdString(info->name());
if (name.size() > 13)
if (name.size() > 13) {
name = name.mid(0, 10) + "...";
}
QFont font;
font.setPixelSize(qMax(qRound(translatedNameRect.height() / 1.5), 9));
@ -144,8 +145,9 @@ void PlayerTarget::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*o
painter->setPen(pen);
painter->drawRect(boundingRect().adjusted(border / 2, border / 2, -border / 2, -border / 2));
if (getBeingPointedAt())
if (getBeingPointedAt()) {
painter->fillRect(boundingRect(), QBrush(QColor(255, 0, 0, 100)));
}
}
AbstractCounter *PlayerTarget::addCounter(int _counterId, const QString &_name, int _value)