mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-22 01:25:10 -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
|
|
@ -192,13 +192,15 @@ void UserContextMenu::banUserHistory_processResponse(const Response &resp)
|
|||
table->setMinimumSize(table->horizontalHeader()->length() + (table->columnCount() * 5),
|
||||
table->verticalHeader()->length() + (table->rowCount() * 3));
|
||||
table->show();
|
||||
} else
|
||||
} else {
|
||||
QMessageBox::information(static_cast<QWidget *>(parent()), tr("Ban History"),
|
||||
tr("User has never been banned."));
|
||||
}
|
||||
|
||||
} else
|
||||
} else {
|
||||
QMessageBox::critical(static_cast<QWidget *>(parent()), tr("Ban History"),
|
||||
tr("Failed to collect ban information."));
|
||||
}
|
||||
}
|
||||
|
||||
void UserContextMenu::warnUserHistory_processResponse(const Response &resp)
|
||||
|
|
@ -228,13 +230,15 @@ void UserContextMenu::warnUserHistory_processResponse(const Response &resp)
|
|||
table->setMinimumSize(table->horizontalHeader()->length() + (table->columnCount() * 5),
|
||||
table->verticalHeader()->length() + (table->rowCount() * 3));
|
||||
table->show();
|
||||
} else
|
||||
} else {
|
||||
QMessageBox::information(static_cast<QWidget *>(parent()), tr("Warning History"),
|
||||
tr("User has never been warned."));
|
||||
}
|
||||
|
||||
} else
|
||||
} else {
|
||||
QMessageBox::critical(static_cast<QWidget *>(parent()), tr("Warning History"),
|
||||
tr("Failed to collect warning information."));
|
||||
}
|
||||
}
|
||||
|
||||
void UserContextMenu::getAdminNotes_processResponse(const Response &resp)
|
||||
|
|
@ -297,8 +301,9 @@ void UserContextMenu::warnUser_dialogFinished()
|
|||
{
|
||||
auto *dlg = static_cast<WarningDialog *>(sender());
|
||||
|
||||
if (dlg->getName().isEmpty() || userListProxy->getOwnUsername().simplified().isEmpty())
|
||||
if (dlg->getName().isEmpty() || userListProxy->getOwnUsername().simplified().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Command_WarnUser cmd;
|
||||
cmd.set_user_name(dlg->getName().toStdString());
|
||||
|
|
|
|||
|
|
@ -123,17 +123,19 @@ void UserInfoBox::updateInfo(const ServerInfo_User &user)
|
|||
userLevelIcon.setPixmap(UserLevelPixmapGenerator::generatePixmap(15, userLevel, user.pawn_colors(), false,
|
||||
QString::fromStdString(user.privlevel())));
|
||||
QString userLevelText;
|
||||
if (userLevel.testFlag(ServerInfo_User::IsAdmin))
|
||||
if (userLevel.testFlag(ServerInfo_User::IsAdmin)) {
|
||||
userLevelText = tr("Administrator");
|
||||
else if (userLevel.testFlag(ServerInfo_User::IsModerator))
|
||||
} else if (userLevel.testFlag(ServerInfo_User::IsModerator)) {
|
||||
userLevelText = tr("Moderator");
|
||||
else if (userLevel.testFlag(ServerInfo_User::IsRegistered))
|
||||
} else if (userLevel.testFlag(ServerInfo_User::IsRegistered)) {
|
||||
userLevelText = tr("Registered user");
|
||||
else
|
||||
} else {
|
||||
userLevelText = tr("Unregistered user");
|
||||
}
|
||||
|
||||
if (userLevel.testFlag(ServerInfo_User::IsJudge))
|
||||
if (userLevel.testFlag(ServerInfo_User::IsJudge)) {
|
||||
userLevelText += " | " + tr("Judge");
|
||||
}
|
||||
|
||||
if (user.has_privlevel() && user.privlevel() != "NONE") {
|
||||
userLevelText += " | " + QString("%1").arg(user.privlevel().c_str());
|
||||
|
|
@ -152,15 +154,17 @@ void UserInfoBox::updateInfo(const ServerInfo_User &user)
|
|||
QString UserInfoBox::getAgeString(int ageSeconds)
|
||||
{
|
||||
QString accountAgeString = tr("Unknown");
|
||||
if (ageSeconds <= 0)
|
||||
if (ageSeconds <= 0) {
|
||||
return accountAgeString;
|
||||
}
|
||||
|
||||
// secsSinceEpoch is in utc
|
||||
auto secsSinceEpoch = QDateTime::currentSecsSinceEpoch() - ageSeconds;
|
||||
// the date is in local time, fromSecsSinceEpoch expects a timestamp from utc and converts it to local time
|
||||
auto date = QDateTime::fromSecsSinceEpoch(secsSinceEpoch).date();
|
||||
if (!date.isValid())
|
||||
if (!date.isValid()) {
|
||||
return accountAgeString;
|
||||
}
|
||||
|
||||
// now can be local time as the date is also local time
|
||||
auto now = QDate::currentDate();
|
||||
|
|
@ -218,8 +222,9 @@ void UserInfoBox::actEditInternal(const Response &r)
|
|||
QString realName = QString::fromStdString(user.real_name());
|
||||
|
||||
DlgEditUser dlg(this, email, country, realName);
|
||||
if (!dlg.exec())
|
||||
if (!dlg.exec()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Command_AccountEdit cmd;
|
||||
cmd.set_real_name(dlg.getRealName().toStdString());
|
||||
|
|
@ -231,8 +236,9 @@ void UserInfoBox::actEditInternal(const Response &r)
|
|||
getTextWithMax(this, tr("Enter Password"),
|
||||
tr("Password verification is required in order to change your email address"),
|
||||
QLineEdit::Password, "", &ok);
|
||||
if (!ok)
|
||||
if (!ok) {
|
||||
return;
|
||||
}
|
||||
cmd.set_password_check(password.toStdString());
|
||||
cmd.set_email(dlg.getEmail().toStdString());
|
||||
} // servers that support password hash do not require all fields to be filled anymore
|
||||
|
|
@ -250,8 +256,9 @@ void UserInfoBox::actEditInternal(const Response &r)
|
|||
void UserInfoBox::actPassword()
|
||||
{
|
||||
DlgEditPassword dlg(this);
|
||||
if (!dlg.exec())
|
||||
if (!dlg.exec()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto oldPassword = dlg.getOldPassword();
|
||||
auto newPassword = dlg.getNewPassword();
|
||||
|
|
@ -296,8 +303,9 @@ void UserInfoBox::changePassword(const QString &oldPassword, const QString &newP
|
|||
void UserInfoBox::actAvatar()
|
||||
{
|
||||
DlgEditAvatar dlg(this);
|
||||
if (!dlg.exec())
|
||||
if (!dlg.exec()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Command_AccountImage cmd;
|
||||
cmd.set_image(dlg.getImage().data(), dlg.getImage().size());
|
||||
|
|
|
|||
|
|
@ -53,8 +53,9 @@ QStringList UserConnection_Information::getServerInfo(const QString &find)
|
|||
for (int i = 0; i < size; i++) {
|
||||
QString _saveName = servers.getValue(QString("saveName%1").arg(i), "server", "server_details").toString();
|
||||
|
||||
if (find != _saveName)
|
||||
if (find != _saveName) {
|
||||
continue;
|
||||
}
|
||||
|
||||
QString serverName = servers.getValue(QString("server%1").arg(i), "server", "server_details").toString();
|
||||
QString portNum = servers.getValue(QString("port%1").arg(i), "server", "server_details").toString();
|
||||
|
|
@ -73,8 +74,9 @@ QStringList UserConnection_Information::getServerInfo(const QString &find)
|
|||
break;
|
||||
}
|
||||
|
||||
if (_server.empty())
|
||||
if (_server.empty()) {
|
||||
qCWarning(UserInfoConnectionLog) << "There was a problem!";
|
||||
}
|
||||
|
||||
return _server;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,8 +40,9 @@ BanDialog::BanDialog(const ServerInfo_User &info, QWidget *parent) : QDialog(par
|
|||
idBanCheckBox->setChecked(true);
|
||||
idBanEdit = new QLineEdit(QString::fromStdString(info.clientid()));
|
||||
idBanEdit->setMaxLength(MAX_NAME_LENGTH);
|
||||
if (QString::fromStdString(info.clientid()).isEmpty())
|
||||
if (QString::fromStdString(info.clientid()).isEmpty()) {
|
||||
idBanCheckBox->setChecked(false);
|
||||
}
|
||||
|
||||
QGridLayout *banTypeGrid = new QGridLayout;
|
||||
banTypeGrid->addWidget(nameBanCheckBox, 0, 0);
|
||||
|
|
@ -207,27 +208,30 @@ void BanDialog::okClicked()
|
|||
return;
|
||||
}
|
||||
|
||||
if (nameBanCheckBox->isChecked())
|
||||
if (nameBanCheckBox->isChecked()) {
|
||||
if (nameBanEdit->text().simplified() == "") {
|
||||
QMessageBox::critical(this, tr("Error"),
|
||||
tr("You must have a value in the name ban when selecting the name ban checkbox."));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (ipBanCheckBox->isChecked())
|
||||
if (ipBanCheckBox->isChecked()) {
|
||||
if (ipBanEdit->text().simplified() == "") {
|
||||
QMessageBox::critical(this, tr("Error"),
|
||||
tr("You must have a value in the ip ban when selecting the ip ban checkbox."));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (idBanCheckBox->isChecked())
|
||||
if (idBanCheckBox->isChecked()) {
|
||||
if (idBanEdit->text().simplified() == "") {
|
||||
QMessageBox::critical(
|
||||
this, tr("Error"),
|
||||
tr("You must have a value in the clientid ban when selecting the clientid ban checkbox."));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
accept();
|
||||
}
|
||||
|
|
@ -461,14 +465,15 @@ void UserListWidget::processUserInfo(const ServerInfo_User &user, bool online)
|
|||
{
|
||||
const QString userName = QString::fromStdString(user.name());
|
||||
UserListTWI *item = users.value(userName);
|
||||
if (item)
|
||||
if (item) {
|
||||
item->setUserInfo(user);
|
||||
else {
|
||||
} else {
|
||||
item = new UserListTWI(user);
|
||||
users.insert(userName, item);
|
||||
userTree->addTopLevelItem(item);
|
||||
if (online)
|
||||
if (online) {
|
||||
++onlineCount;
|
||||
}
|
||||
updateCount();
|
||||
}
|
||||
item->setOnline(online);
|
||||
|
|
@ -480,8 +485,9 @@ bool UserListWidget::deleteUser(const QString &userName)
|
|||
if (twi) {
|
||||
users.remove(userName);
|
||||
userTree->takeTopLevelItem(userTree->indexOfTopLevelItem(twi));
|
||||
if (twi->data(0, Qt::UserRole + 1).toBool())
|
||||
if (twi->data(0, Qt::UserRole + 1).toBool()) {
|
||||
--onlineCount;
|
||||
}
|
||||
delete twi;
|
||||
updateCount();
|
||||
return true;
|
||||
|
|
@ -493,22 +499,25 @@ bool UserListWidget::deleteUser(const QString &userName)
|
|||
void UserListWidget::setUserOnline(const QString &userName, bool online)
|
||||
{
|
||||
UserListTWI *twi = users.value(userName);
|
||||
if (!twi)
|
||||
if (!twi) {
|
||||
return;
|
||||
}
|
||||
|
||||
twi->setOnline(online);
|
||||
if (online)
|
||||
if (online) {
|
||||
++onlineCount;
|
||||
else
|
||||
} else {
|
||||
--onlineCount;
|
||||
}
|
||||
updateCount();
|
||||
}
|
||||
|
||||
void UserListWidget::updateCount()
|
||||
{
|
||||
QString str = titleStr;
|
||||
if ((type == BuddyList) || (type == IgnoreList))
|
||||
if ((type == BuddyList) || (type == IgnoreList)) {
|
||||
str = str.arg(onlineCount);
|
||||
}
|
||||
setTitle(str.arg(userTree->topLevelItemCount()));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue