mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-10 08:14:47 -07:00
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:
parent
7153f7d4c1
commit
aadee34238
173 changed files with 2725 additions and 1461 deletions
|
|
@ -261,13 +261,7 @@ void DlgConnect::updateDisplayInfo(const QString &saveName)
|
|||
QStringList _data = uci.getServerInfo(saveName);
|
||||
|
||||
if (_data.isEmpty()) {
|
||||
_data << ""
|
||||
<< ""
|
||||
<< ""
|
||||
<< ""
|
||||
<< ""
|
||||
<< ""
|
||||
<< "";
|
||||
_data << "" << "" << "" << "" << "" << "" << "";
|
||||
}
|
||||
|
||||
bool savePasswordStatus = (_data.at(5) == "1");
|
||||
|
|
|
|||
|
|
@ -215,8 +215,9 @@ DlgCreateGame::DlgCreateGame(const ServerInfo_Game &gameInfo, const QMap<int, QS
|
|||
spectatorsSeeEverythingCheckBox->setChecked(gameInfo.spectators_omniscient());
|
||||
|
||||
QSet<int> types;
|
||||
for (int i = 0; i < gameInfo.game_types_size(); ++i)
|
||||
for (int i = 0; i < gameInfo.game_types_size(); ++i) {
|
||||
types.insert(gameInfo.game_types(i));
|
||||
}
|
||||
|
||||
QMapIterator<int, QString> gameTypeIterator(gameTypes);
|
||||
while (gameTypeIterator.hasNext()) {
|
||||
|
|
@ -316,9 +317,9 @@ void DlgCreateGame::checkResponse(const Response &response)
|
|||
{
|
||||
buttonBox->setEnabled(true);
|
||||
|
||||
if (response.response_code() == Response::RespOk)
|
||||
if (response.response_code() == Response::RespOk) {
|
||||
accept();
|
||||
else {
|
||||
} else {
|
||||
QMessageBox::critical(this, tr("Error"), tr("Server error."));
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,8 +95,9 @@ void DlgDefaultTagsEditor::addItem()
|
|||
// Prevent duplicate tags
|
||||
for (int i = 0; i < listWidget->count(); ++i) {
|
||||
QWidget *widget = listWidget->itemWidget(listWidget->item(i));
|
||||
if (!widget)
|
||||
if (!widget) {
|
||||
continue;
|
||||
}
|
||||
QLineEdit *lineEdit = widget->findChild<QLineEdit *>();
|
||||
if (lineEdit && lineEdit->text() == newTag) {
|
||||
QMessageBox::warning(this, tr("Duplicate Tag"), tr("This tag already exists."));
|
||||
|
|
@ -138,8 +139,9 @@ void DlgDefaultTagsEditor::confirmChanges()
|
|||
QStringList updatedList;
|
||||
for (int i = 0; i < listWidget->count(); ++i) {
|
||||
QWidget *widget = listWidget->itemWidget(listWidget->item(i));
|
||||
if (!widget)
|
||||
if (!widget) {
|
||||
continue;
|
||||
}
|
||||
QLineEdit *lineEdit = widget->findChild<QLineEdit *>();
|
||||
if (lineEdit) {
|
||||
updatedList.append(lineEdit->text());
|
||||
|
|
|
|||
|
|
@ -149,8 +149,9 @@ void DlgEditTokens::actAddToken()
|
|||
QString name;
|
||||
for (;;) {
|
||||
name = getTextWithMax(this, tr("Add token"), tr("Please enter the name of the token:"));
|
||||
if (name.isEmpty())
|
||||
if (name.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (databaseModel->getDatabase()->query()->getCardInfo(name)) {
|
||||
QMessageBox::critical(this, tr("Error"),
|
||||
tr("The chosen name conflicts with an existing card or token.\nMake sure to enable "
|
||||
|
|
@ -181,18 +182,21 @@ void DlgEditTokens::actRemoveToken()
|
|||
|
||||
void DlgEditTokens::colorChanged(int colorIndex)
|
||||
{
|
||||
if (currentCard)
|
||||
if (currentCard) {
|
||||
currentCard->setColors(QString(colorEdit->itemData(colorIndex).toChar()));
|
||||
}
|
||||
}
|
||||
|
||||
void DlgEditTokens::ptChanged(const QString &_pt)
|
||||
{
|
||||
if (currentCard)
|
||||
if (currentCard) {
|
||||
currentCard->setPowTough(_pt);
|
||||
}
|
||||
}
|
||||
|
||||
void DlgEditTokens::annotationChanged(const QString &_annotation)
|
||||
{
|
||||
if (currentCard)
|
||||
if (currentCard) {
|
||||
currentCard->setText(_annotation);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,8 +26,9 @@ DlgEditUser::DlgEditUser(QWidget *parent, QString email, QString country, QStrin
|
|||
int i = 1;
|
||||
for (const QString &c : countries) {
|
||||
countryEdit->addItem(QPixmap("theme:countries/" + c.toLower()), c);
|
||||
if (c == country)
|
||||
if (c == country) {
|
||||
countryEdit->setCurrentIndex(i);
|
||||
}
|
||||
|
||||
++i;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,8 +87,9 @@ DlgFilterGames::DlgFilterGames(const QMap<int, QString> &_allGameTypes,
|
|||
if (!allGameTypes.isEmpty()) {
|
||||
gameTypeFilterGroupBox = new QGroupBox(tr("&Game types"));
|
||||
gameTypeFilterGroupBox->setLayout(gameTypeFilterLayout);
|
||||
} else
|
||||
} else {
|
||||
gameTypeFilterGroupBox = nullptr;
|
||||
}
|
||||
|
||||
auto *maxPlayersFilterMinLabel = new QLabel(tr("at &least:"));
|
||||
maxPlayersFilterMinSpinBox = new QSpinBox;
|
||||
|
|
@ -226,8 +227,9 @@ QSet<int> DlgFilterGames::getGameTypeFilter() const
|
|||
QMapIterator<int, QCheckBox *> i(gameTypeFilterCheckBoxes);
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
if (i.value()->isChecked())
|
||||
if (i.value()->isChecked()) {
|
||||
result.insert(i.key());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -217,8 +217,9 @@ void WndSets::saveHeaderState()
|
|||
|
||||
void WndSets::rebuildMainLayout(int actionToTake)
|
||||
{
|
||||
if (mainLayout == nullptr)
|
||||
if (mainLayout == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (actionToTake) {
|
||||
case NO_SETS_SELECTED:
|
||||
|
|
@ -382,12 +383,14 @@ void WndSets::actUp()
|
|||
std::sort(rows.begin(), rows.end(), std::less<QModelIndex>());
|
||||
QSet<int> newRows;
|
||||
|
||||
if (rows.empty())
|
||||
if (rows.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto i : rows) {
|
||||
if (i.row() <= 0)
|
||||
if (i.row() <= 0) {
|
||||
continue;
|
||||
}
|
||||
int oldRow = displayModel->mapToSource(i).row();
|
||||
int newRow = i.row() - 1;
|
||||
|
||||
|
|
@ -405,12 +408,14 @@ void WndSets::actDown()
|
|||
std::sort(rows.begin(), rows.end(), [](const QModelIndex &a, const QModelIndex &b) { return b < a; });
|
||||
QSet<int> newRows;
|
||||
|
||||
if (rows.empty())
|
||||
if (rows.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto i : rows) {
|
||||
if (i.row() >= displayModel->rowCount() - 1)
|
||||
if (i.row() >= displayModel->rowCount() - 1) {
|
||||
continue;
|
||||
}
|
||||
int oldRow = displayModel->mapToSource(i).row();
|
||||
int newRow = i.row() + 1;
|
||||
|
||||
|
|
@ -428,8 +433,9 @@ void WndSets::actTop()
|
|||
QSet<int> newRows;
|
||||
int newRow = 0;
|
||||
|
||||
if (rows.empty())
|
||||
if (rows.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < rows.length(); i++) {
|
||||
int oldRow = displayModel->mapToSource(rows.at(i)).row();
|
||||
|
|
@ -454,8 +460,9 @@ void WndSets::actBottom()
|
|||
QSet<int> newRows;
|
||||
int newRow = model->rowCount() - 1;
|
||||
|
||||
if (rows.empty())
|
||||
if (rows.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < rows.length(); i++) {
|
||||
int oldRow = displayModel->mapToSource(rows.at(i)).row();
|
||||
|
|
|
|||
|
|
@ -311,8 +311,9 @@ DlgRegister::DlgRegister(QWidget *parent) : QDialog(parent)
|
|||
countryEdit->addItem(QPixmap("theme:countries/zw"), "zw");
|
||||
countryEdit->setCurrentIndex(0);
|
||||
QStringList countries = SettingsCache::instance().getCountries();
|
||||
for (const QString &c : countries)
|
||||
for (const QString &c : countries) {
|
||||
countryEdit->addItem(QPixmap("theme:countries/" + c.toLower()), c);
|
||||
}
|
||||
|
||||
realnameLabel = new QLabel(tr("Real name:"));
|
||||
realnameEdit = new QLineEdit();
|
||||
|
|
|
|||
|
|
@ -237,8 +237,9 @@ QMap<QString, int> DlgSelectSetForCards::getSetsForCards()
|
|||
|
||||
for (auto cardName : cardNames) {
|
||||
CardInfoPtr infoPtr = CardDatabaseManager::query()->getCardInfo(cardName);
|
||||
if (!infoPtr)
|
||||
if (!infoPtr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
SetToPrintingsMap setMap = infoPtr->getSets();
|
||||
for (auto &setName : setMap.keys()) {
|
||||
|
|
@ -359,8 +360,9 @@ QMap<QString, QStringList> DlgSelectSetForCards::getCardsForSets()
|
|||
|
||||
for (auto cardName : cardNames) {
|
||||
CardInfoPtr infoPtr = CardDatabaseManager::query()->getCardInfo(cardName);
|
||||
if (!infoPtr)
|
||||
if (!infoPtr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
SetToPrintingsMap setMap = infoPtr->getSets();
|
||||
for (auto it = setMap.begin(); it != setMap.end(); ++it) {
|
||||
|
|
|
|||
|
|
@ -272,8 +272,9 @@ QString GeneralSettingsPage::languageName(const QString &lang)
|
|||
void GeneralSettingsPage::deckPathButtonClicked()
|
||||
{
|
||||
QString path = QFileDialog::getExistingDirectory(this, tr("Choose path"), deckPathEdit->text());
|
||||
if (path.isEmpty())
|
||||
if (path.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
deckPathEdit->setText(path);
|
||||
SettingsCache::instance().setDeckPath(path);
|
||||
|
|
@ -282,8 +283,9 @@ void GeneralSettingsPage::deckPathButtonClicked()
|
|||
void GeneralSettingsPage::filtersPathButtonClicked()
|
||||
{
|
||||
QString path = QFileDialog::getExistingDirectory(this, tr("Choose path"), filtersPathEdit->text());
|
||||
if (path.isEmpty())
|
||||
if (path.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
filtersPathEdit->setText(path);
|
||||
SettingsCache::instance().setFiltersPath(path);
|
||||
|
|
@ -292,8 +294,9 @@ void GeneralSettingsPage::filtersPathButtonClicked()
|
|||
void GeneralSettingsPage::replaysPathButtonClicked()
|
||||
{
|
||||
QString path = QFileDialog::getExistingDirectory(this, tr("Choose path"), replaysPathEdit->text());
|
||||
if (path.isEmpty())
|
||||
if (path.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
replaysPathEdit->setText(path);
|
||||
SettingsCache::instance().setReplaysPath(path);
|
||||
|
|
@ -302,8 +305,9 @@ void GeneralSettingsPage::replaysPathButtonClicked()
|
|||
void GeneralSettingsPage::picsPathButtonClicked()
|
||||
{
|
||||
QString path = QFileDialog::getExistingDirectory(this, tr("Choose path"), picsPathEdit->text());
|
||||
if (path.isEmpty())
|
||||
if (path.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
picsPathEdit->setText(path);
|
||||
SettingsCache::instance().setPicsPath(path);
|
||||
|
|
@ -312,8 +316,9 @@ void GeneralSettingsPage::picsPathButtonClicked()
|
|||
void GeneralSettingsPage::cardDatabasePathButtonClicked()
|
||||
{
|
||||
QString path = QFileDialog::getOpenFileName(this, tr("Choose path"), cardDatabasePathEdit->text());
|
||||
if (path.isEmpty())
|
||||
if (path.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
cardDatabasePathEdit->setText(path);
|
||||
SettingsCache::instance().setCardDatabasePath(path);
|
||||
|
|
@ -322,8 +327,9 @@ void GeneralSettingsPage::cardDatabasePathButtonClicked()
|
|||
void GeneralSettingsPage::customCardDatabaseButtonClicked()
|
||||
{
|
||||
QString path = QFileDialog::getExistingDirectory(this, tr("Choose path"), customCardDatabasePathEdit->text());
|
||||
if (path.isEmpty())
|
||||
if (path.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
customCardDatabasePathEdit->setText(path);
|
||||
SettingsCache::instance().setCustomCardDatabasePath(path);
|
||||
|
|
@ -332,8 +338,9 @@ void GeneralSettingsPage::customCardDatabaseButtonClicked()
|
|||
void GeneralSettingsPage::tokenDatabasePathButtonClicked()
|
||||
{
|
||||
QString path = QFileDialog::getOpenFileName(this, tr("Choose path"), tokenDatabasePathEdit->text());
|
||||
if (path.isEmpty())
|
||||
if (path.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
tokenDatabasePathEdit->setText(path);
|
||||
SettingsCache::instance().setTokenDatabasePath(path);
|
||||
|
|
@ -418,8 +425,9 @@ AppearanceSettingsPage::AppearanceSettingsPage()
|
|||
QStringList themeDirs = themeManager->getAvailableThemes().keys();
|
||||
for (int i = 0; i < themeDirs.size(); i++) {
|
||||
themeBox.addItem(themeDirs[i]);
|
||||
if (themeDirs[i] == themeName)
|
||||
if (themeDirs[i] == themeName) {
|
||||
themeBox.setCurrentIndex(i);
|
||||
}
|
||||
}
|
||||
|
||||
connect(&themeBox, qOverload<int>(&QComboBox::currentIndexChanged), this, &AppearanceSettingsPage::themeBoxChanged);
|
||||
|
|
@ -560,8 +568,9 @@ AppearanceSettingsPage::AppearanceSettingsPage()
|
|||
auto &cardCounterSettings = SettingsCache::instance().cardCounters();
|
||||
|
||||
auto newColor = QColorDialog::getColor(cardCounterSettings.color(index), this);
|
||||
if (!newColor.isValid())
|
||||
if (!newColor.isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
cardCounterSettings.setColor(index, newColor);
|
||||
});
|
||||
|
|
@ -643,8 +652,9 @@ AppearanceSettingsPage::AppearanceSettingsPage()
|
|||
void AppearanceSettingsPage::themeBoxChanged(int index)
|
||||
{
|
||||
QStringList themeDirs = themeManager->getAvailableThemes().keys();
|
||||
if (index >= 0 && index < themeDirs.count())
|
||||
if (index >= 0 && index < themeDirs.count()) {
|
||||
SettingsCache::instance().setThemeName(themeDirs.at(index));
|
||||
}
|
||||
}
|
||||
|
||||
void AppearanceSettingsPage::openThemeLocation()
|
||||
|
|
@ -1395,8 +1405,9 @@ MessagesSettingsPage::MessagesSettingsPage()
|
|||
messageList = new QListWidget;
|
||||
|
||||
int count = SettingsCache::instance().messages().getCount();
|
||||
for (int i = 0; i < count; i++)
|
||||
for (int i = 0; i < count; i++) {
|
||||
messageList->addItem(SettingsCache::instance().messages().getMessageAt(i));
|
||||
}
|
||||
|
||||
aAdd = new QAction(this);
|
||||
aAdd->setIcon(QPixmap("theme:icons/increment"));
|
||||
|
|
@ -1496,8 +1507,9 @@ void MessagesSettingsPage::updateHighlightPreview()
|
|||
void MessagesSettingsPage::storeSettings()
|
||||
{
|
||||
SettingsCache::instance().messages().setCount(messageList->count());
|
||||
for (int i = 0; i < messageList->count(); i++)
|
||||
for (int i = 0; i < messageList->count(); i++) {
|
||||
SettingsCache::instance().messages().setMessageAt(i, messageList->item(i)->text());
|
||||
}
|
||||
emit SettingsCache::instance().messages().messageMacrosChanged();
|
||||
}
|
||||
|
||||
|
|
@ -1570,8 +1582,9 @@ SoundSettingsPage::SoundSettingsPage()
|
|||
QStringList themeDirs = soundEngine->getAvailableThemes().keys();
|
||||
for (int i = 0; i < themeDirs.size(); i++) {
|
||||
themeBox.addItem(themeDirs[i]);
|
||||
if (themeDirs[i] == themeName)
|
||||
if (themeDirs[i] == themeName) {
|
||||
themeBox.setCurrentIndex(i);
|
||||
}
|
||||
}
|
||||
|
||||
connect(&themeBox, qOverload<int>(&QComboBox::currentIndexChanged), this, &SoundSettingsPage::themeBoxChanged);
|
||||
|
|
@ -1619,8 +1632,9 @@ SoundSettingsPage::SoundSettingsPage()
|
|||
void SoundSettingsPage::themeBoxChanged(int index)
|
||||
{
|
||||
QStringList themeDirs = soundEngine->getAvailableThemes().keys();
|
||||
if (index >= 0 && index < themeDirs.count())
|
||||
if (index >= 0 && index < themeDirs.count()) {
|
||||
SettingsCache::instance().setSoundThemeName(themeDirs.at(index));
|
||||
}
|
||||
}
|
||||
|
||||
void SoundSettingsPage::masterVolumeChanged(int value)
|
||||
|
|
@ -1857,8 +1871,9 @@ void DlgSettings::createIcons()
|
|||
|
||||
void DlgSettings::changePage(QListWidgetItem *current, QListWidgetItem *previous)
|
||||
{
|
||||
if (!current)
|
||||
if (!current) {
|
||||
current = previous;
|
||||
}
|
||||
|
||||
pagesWidget->setCurrentIndex(contentsWidget->row(current));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -154,8 +154,9 @@ void DlgUpdate::finishedUpdateCheck(bool needToUpdate, bool isCompatible, Releas
|
|||
"</a>)<br><br>" + tr("Do you want to update now?"),
|
||||
QMessageBox::Yes | QMessageBox::No);
|
||||
|
||||
if (reply == QMessageBox::Yes)
|
||||
if (reply == QMessageBox::Yes) {
|
||||
downloadUpdate(release->getName());
|
||||
}
|
||||
} else {
|
||||
QMessageBox::information(
|
||||
this, tr("Update Available"),
|
||||
|
|
|
|||
|
|
@ -60,8 +60,9 @@ void DlgViewLog::actCopyToClipboard()
|
|||
void DlgViewLog::loadInitialLogBuffer()
|
||||
{
|
||||
QList<QString> logBuffer = Logger::getInstance().getLogBuffer();
|
||||
for (const QString &message : logBuffer)
|
||||
for (const QString &message : logBuffer) {
|
||||
appendLogEntry(message);
|
||||
}
|
||||
}
|
||||
|
||||
void DlgViewLog::appendLogEntry(const QString &message)
|
||||
|
|
|
|||
|
|
@ -73,8 +73,9 @@ TipsOfTheDay::~TipsOfTheDay()
|
|||
|
||||
QVariant TipsOfTheDay::data(const QModelIndex &index, int /*role*/) const
|
||||
{
|
||||
if (!index.isValid() || index.row() >= tipList->size() || index.column() >= TIPDDBMODEL_COLUMNS)
|
||||
if (!index.isValid() || index.row() >= tipList->size() || index.column() >= TIPDDBMODEL_COLUMNS) {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
TipOfTheDay tip = tipList->at(index.row());
|
||||
switch (index.column()) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue