mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-15 19:47:46 -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
|
|
@ -140,13 +140,15 @@ void ConnectionController::onConnectionClosedEvent(const Event_ConnectionClosed
|
|||
}
|
||||
case Event_ConnectionClosed::BANNED: {
|
||||
reasonStr = tr("Banned by moderator");
|
||||
if (event.has_end_time())
|
||||
if (event.has_end_time()) {
|
||||
reasonStr.append(
|
||||
"\n" + tr("Expected end time: %1").arg(QDateTime::fromSecsSinceEpoch(event.end_time()).toString()));
|
||||
else
|
||||
} else {
|
||||
reasonStr.append("\n" + tr("This ban lasts indefinitely."));
|
||||
if (event.has_reason_str())
|
||||
}
|
||||
if (event.has_reason_str()) {
|
||||
reasonStr.append("\n\n" + QString::fromStdString(event.reason_str()));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Event_ConnectionClosed::SERVER_SHUTDOWN: {
|
||||
|
|
@ -240,8 +242,9 @@ void ConnectionController::onLoginError(int r,
|
|||
QString bannedStr =
|
||||
endTime ? tr("You are banned until %1.").arg(QDateTime::fromSecsSinceEpoch(endTime).toString())
|
||||
: tr("You are banned indefinitely.");
|
||||
if (!reasonStr.isEmpty())
|
||||
if (!reasonStr.isEmpty()) {
|
||||
bannedStr.append("\n\n" + reasonStr);
|
||||
}
|
||||
QMessageBox::critical(dialogParent, tr("Error"), bannedStr);
|
||||
break;
|
||||
}
|
||||
|
|
@ -354,8 +357,9 @@ void ConnectionController::onRegisterError(int r, QString reasonStr, quint32 end
|
|||
QString bannedStr =
|
||||
endTime ? tr("You are banned until %1.").arg(QDateTime::fromSecsSinceEpoch(endTime).toString())
|
||||
: tr("You are banned indefinitely.");
|
||||
if (!reasonStr.isEmpty())
|
||||
if (!reasonStr.isEmpty()) {
|
||||
bannedStr.append("\n\n" + reasonStr);
|
||||
}
|
||||
QMessageBox::critical(dialogParent, tr("Error"), bannedStr);
|
||||
break;
|
||||
}
|
||||
|
|
@ -545,8 +549,9 @@ QString ConnectionController::extractInvalidUsernameMessage(QString &in)
|
|||
out +=
|
||||
"<li>" + tr("can %1 contain numeric characters").arg((rules.at(4).toInt() > 0) ? "" : tr("NOT")) + "</li>";
|
||||
|
||||
if (rules.at(6).size() > 0)
|
||||
if (rules.at(6).size() > 0) {
|
||||
out += "<li>" + tr("can contain the following punctuation: %1").arg(rules.at(6).toHtmlEscaped()) + "</li>";
|
||||
}
|
||||
|
||||
out += "<li>" +
|
||||
tr("first character can %1 be a punctuation mark").arg((rules.at(5).toInt() > 0) ? "" : tr("NOT")) +
|
||||
|
|
@ -566,10 +571,11 @@ QString ConnectionController::extractInvalidUsernameMessage(QString &in)
|
|||
}
|
||||
}
|
||||
|
||||
if (rules.at(8).size() > 0)
|
||||
if (rules.at(8).size() > 0) {
|
||||
out += "<li>" +
|
||||
tr("can not match any of the following expressions: %1").arg(rules.at(8).toHtmlEscaped()) +
|
||||
"</li>";
|
||||
}
|
||||
}
|
||||
|
||||
out += "</ul>";
|
||||
|
|
|
|||
|
|
@ -99,14 +99,16 @@ void TappedOutInterface::copyDeckSplitMainAndSide(const DeckList &source, DeckLi
|
|||
{
|
||||
auto copyMainOrSide = [this, &mainboard, &sideboard](const auto node, const auto card) {
|
||||
CardInfoPtr dbCard = cardDatabase.query()->getCardInfo(card->getName());
|
||||
if (!dbCard || dbCard->getIsToken())
|
||||
if (!dbCard || dbCard->getIsToken()) {
|
||||
return;
|
||||
}
|
||||
|
||||
DecklistCardNode *addedCard;
|
||||
if (node->getName() == DECK_ZONE_SIDE)
|
||||
if (node->getName() == DECK_ZONE_SIDE) {
|
||||
addedCard = sideboard.addCard(card->getName(), node->getName(), -1);
|
||||
else
|
||||
} else {
|
||||
addedCard = mainboard.addCard(card->getName(), node->getName(), -1);
|
||||
}
|
||||
addedCard->setNumber(card->getNumber());
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -129,8 +129,9 @@ void StableReleaseChannel::releaseListFinished()
|
|||
return;
|
||||
}
|
||||
|
||||
if (!lastRelease)
|
||||
if (!lastRelease) {
|
||||
lastRelease = new Release;
|
||||
}
|
||||
|
||||
lastRelease->setName(resultMap["name"].toString());
|
||||
lastRelease->setDescriptionUrl(resultMap["html_url"].toString());
|
||||
|
|
@ -246,8 +247,9 @@ void BetaReleaseChannel::releaseListFinished()
|
|||
return;
|
||||
}
|
||||
|
||||
if (lastRelease == nullptr)
|
||||
if (lastRelease == nullptr) {
|
||||
lastRelease = new Release;
|
||||
}
|
||||
|
||||
lastRelease->setCommitHash(resultMap["target_commitish"].toString());
|
||||
lastRelease->setPublishDate(resultMap["published_at"].toDate());
|
||||
|
|
|
|||
|
|
@ -10,8 +10,9 @@ UpdateDownloader::UpdateDownloader(QObject *parent) : QObject(parent), response(
|
|||
void UpdateDownloader::beginDownload(QUrl downloadUrl)
|
||||
{
|
||||
// Save the original URL because we need it for the filename
|
||||
if (originalUrl.isEmpty())
|
||||
if (originalUrl.isEmpty()) {
|
||||
originalUrl = downloadUrl;
|
||||
}
|
||||
|
||||
response = netMan->get(QNetworkRequest(downloadUrl));
|
||||
connect(response, &QNetworkReply::finished, this, &UpdateDownloader::fileFinished);
|
||||
|
|
@ -21,8 +22,9 @@ void UpdateDownloader::beginDownload(QUrl downloadUrl)
|
|||
|
||||
void UpdateDownloader::downloadError(QNetworkReply::NetworkError)
|
||||
{
|
||||
if (response == nullptr)
|
||||
if (response == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
emit error(response->errorString().toUtf8());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,10 +24,11 @@ SettingsCache &SettingsCache::instance()
|
|||
|
||||
QString SettingsCache::getDataPath()
|
||||
{
|
||||
if (isPortableBuild)
|
||||
if (isPortableBuild) {
|
||||
return qApp->applicationDirPath() + "/data";
|
||||
else
|
||||
} else {
|
||||
return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation);
|
||||
}
|
||||
}
|
||||
|
||||
QString SettingsCache::getSettingsPath()
|
||||
|
|
@ -37,10 +38,11 @@ QString SettingsCache::getSettingsPath()
|
|||
|
||||
QString SettingsCache::getCachePath() const
|
||||
{
|
||||
if (isPortableBuild)
|
||||
if (isPortableBuild) {
|
||||
return qApp->applicationDirPath() + "/cache";
|
||||
else
|
||||
} else {
|
||||
return QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
|
||||
}
|
||||
}
|
||||
|
||||
QString SettingsCache::getNetworkCachePath() const
|
||||
|
|
@ -50,14 +52,17 @@ QString SettingsCache::getNetworkCachePath() const
|
|||
|
||||
void SettingsCache::translateLegacySettings()
|
||||
{
|
||||
if (isPortableBuild)
|
||||
if (isPortableBuild) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Layouts
|
||||
QFile layoutFile(getSettingsPath() + "layouts/deckLayout.ini");
|
||||
if (layoutFile.exists())
|
||||
if (layoutFile.copy(getSettingsPath() + "layouts.ini"))
|
||||
if (layoutFile.exists()) {
|
||||
if (layoutFile.copy(getSettingsPath() + "layouts.ini")) {
|
||||
layoutFile.remove();
|
||||
}
|
||||
}
|
||||
|
||||
QStringList usedKeys;
|
||||
QSettings legacySetting;
|
||||
|
|
@ -116,10 +121,11 @@ void SettingsCache::translateLegacySettings()
|
|||
gameFilters().setHideIgnoredUserGames(legacySetting.value("hide_ignored_user_games").toBool());
|
||||
gameFilters().setMinPlayers(legacySetting.value("min_players").toInt());
|
||||
|
||||
if (legacySetting.value("max_players").toInt() > 1)
|
||||
if (legacySetting.value("max_players").toInt() > 1) {
|
||||
gameFilters().setMaxPlayers(legacySetting.value("max_players").toInt());
|
||||
else
|
||||
} else {
|
||||
gameFilters().setMaxPlayers(99); // This prevents a bug where no games will show if max was not set before
|
||||
}
|
||||
|
||||
QStringList allFilters = legacySetting.allKeys();
|
||||
for (int i = 0; i < allFilters.size(); ++i) {
|
||||
|
|
@ -135,8 +141,9 @@ void SettingsCache::translateLegacySettings()
|
|||
|
||||
QStringList allLegacyKeys = legacySetting.allKeys();
|
||||
for (int i = 0; i < allLegacyKeys.size(); ++i) {
|
||||
if (usedKeys.contains(allLegacyKeys.at(i)))
|
||||
if (usedKeys.contains(allLegacyKeys.at(i))) {
|
||||
continue;
|
||||
}
|
||||
settings->setValue(allLegacyKeys.at(i), legacySetting.value(allLegacyKeys.at(i)));
|
||||
}
|
||||
}
|
||||
|
|
@ -147,8 +154,9 @@ QString SettingsCache::getSafeConfigPath(QString configEntry, QString defaultPat
|
|||
// if the config settings is empty or refers to a not-existing folder,
|
||||
// ensure that the defaut path exists and return it
|
||||
if (tmp.isEmpty() || !QDir(tmp).exists()) {
|
||||
if (!QDir().mkpath(defaultPath))
|
||||
if (!QDir().mkpath(defaultPath)) {
|
||||
qCInfo(SettingsCacheLog) << "[SettingsCache] Could not create folder:" << defaultPath;
|
||||
}
|
||||
tmp = defaultPath;
|
||||
}
|
||||
return tmp;
|
||||
|
|
@ -159,8 +167,9 @@ QString SettingsCache::getSafeConfigFilePath(QString configEntry, QString defaul
|
|||
QString tmp = settings->value(configEntry).toString();
|
||||
// if the config settings is empty or refers to a not-existing file,
|
||||
// return the default Path
|
||||
if (!QFile::exists(tmp) || tmp.isEmpty())
|
||||
if (!QFile::exists(tmp) || tmp.isEmpty()) {
|
||||
tmp = std::move(defaultPath);
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
|
@ -168,8 +177,9 @@ SettingsCache::SettingsCache()
|
|||
{
|
||||
// first, figure out if we are running in portable mode
|
||||
isPortableBuild = QFile::exists(qApp->applicationDirPath() + "/portable.dat");
|
||||
if (isPortableBuild)
|
||||
if (isPortableBuild) {
|
||||
qCInfo(SettingsCacheLog) << "Portable mode enabled";
|
||||
}
|
||||
|
||||
// define a dummy context that will be used where needed
|
||||
QString dummy = QT_TRANSLATE_NOOP("i18n", "English");
|
||||
|
|
@ -189,8 +199,9 @@ SettingsCache::SettingsCache()
|
|||
|
||||
cardCounterSettings = new CardCounterSettings(settingsPath, this);
|
||||
|
||||
if (!QFile(settingsPath + "global.ini").exists())
|
||||
if (!QFile(settingsPath + "global.ini").exists()) {
|
||||
translateLegacySettings();
|
||||
}
|
||||
|
||||
// updates - don't reorder them or their index in the settings won't match
|
||||
// append channels one by one, or msvc will add them in the wrong order.
|
||||
|
|
@ -257,11 +268,13 @@ SettingsCache::SettingsCache()
|
|||
settings->setValue("personal/pixmapCacheSize", pixmapCacheSize);
|
||||
settings->setValue("personal/picturedownloadhq", false);
|
||||
settings->setValue("revert/pixmapCacheSize", true);
|
||||
} else
|
||||
} else {
|
||||
pixmapCacheSize = settings->value("personal/pixmapCacheSize", PIXMAPCACHE_SIZE_DEFAULT).toInt();
|
||||
}
|
||||
// sanity check
|
||||
if (pixmapCacheSize < PIXMAPCACHE_SIZE_MIN || pixmapCacheSize > PIXMAPCACHE_SIZE_MAX)
|
||||
if (pixmapCacheSize < PIXMAPCACHE_SIZE_MIN || pixmapCacheSize > PIXMAPCACHE_SIZE_MAX) {
|
||||
pixmapCacheSize = PIXMAPCACHE_SIZE_DEFAULT;
|
||||
}
|
||||
|
||||
networkCacheSize = settings->value("personal/networkCacheSize", NETWORK_CACHE_SIZE_DEFAULT).toInt();
|
||||
redirectCacheTtl = settings->value("personal/redirectCacheTtl", NETWORK_REDIRECT_CACHE_TTL_DEFAULT).toInt();
|
||||
|
|
@ -770,8 +783,9 @@ void SettingsCache::setPrintingSelectorCardSize(int _printingSelectorCardSize)
|
|||
|
||||
void SettingsCache::setIncludeRebalancedCards(bool _includeRebalancedCards)
|
||||
{
|
||||
if (includeRebalancedCards == _includeRebalancedCards)
|
||||
if (includeRebalancedCards == _includeRebalancedCards) {
|
||||
return;
|
||||
}
|
||||
|
||||
includeRebalancedCards = _includeRebalancedCards;
|
||||
settings->setValue("cards/includerebalancedcards", includeRebalancedCards);
|
||||
|
|
@ -1310,8 +1324,9 @@ void SettingsCache::setMaxFontSize(int _max)
|
|||
|
||||
void SettingsCache::setRoundCardCorners(bool _roundCardCorners)
|
||||
{
|
||||
if (_roundCardCorners == roundCardCorners)
|
||||
if (_roundCardCorners == roundCardCorners) {
|
||||
return;
|
||||
}
|
||||
|
||||
roundCardCorners = _roundCardCorners;
|
||||
settings->setValue("cards/roundcardcorners", _roundCardCorners);
|
||||
|
|
|
|||
|
|
@ -15,8 +15,9 @@ void CardCounterSettings::setColor(int counterId, const QColor &color)
|
|||
|
||||
QString key = QString("cards/counters/%1/color").arg(counterId);
|
||||
|
||||
if (settings.value(key).value<QColor>() == color)
|
||||
if (settings.value(key).value<QColor>() == color) {
|
||||
return;
|
||||
}
|
||||
|
||||
settings.setValue(key, color);
|
||||
emit colorChanged(counterId, color);
|
||||
|
|
|
|||
|
|
@ -105,8 +105,9 @@ QStringMap &SoundEngine::getAvailableThemes()
|
|||
dir.setPath(SettingsCache::instance().getDataPath() + "/sounds");
|
||||
|
||||
for (const QString &themeName : dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name)) {
|
||||
if (!availableThemes.contains(themeName))
|
||||
if (!availableThemes.contains(themeName)) {
|
||||
availableThemes.insert(themeName, dir.absoluteFilePath(themeName));
|
||||
}
|
||||
}
|
||||
|
||||
// load themes from cockatrice system dir
|
||||
|
|
@ -121,8 +122,9 @@ QStringMap &SoundEngine::getAvailableThemes()
|
|||
);
|
||||
|
||||
for (const QString &themeName : dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name)) {
|
||||
if (!availableThemes.contains(themeName))
|
||||
if (!availableThemes.contains(themeName)) {
|
||||
availableThemes.insert(themeName, dir.absoluteFilePath(themeName));
|
||||
}
|
||||
}
|
||||
|
||||
return availableThemes;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue