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

@ -88,10 +88,11 @@ void ChatView::refreshBlockColors()
for (QTextBlock block = doc->begin(); block.isValid(); block = block.next()) {
QTextBlockFormat fmt = block.blockFormat();
if (even)
if (even) {
fmt.setBackground(palette().base());
else
} else {
fmt.setBackground(palette().window());
}
fmt.setForeground(palette().text());
@ -121,10 +122,11 @@ QTextCursor ChatView::prepareBlock(bool same)
cursor.insertHtml("<br>");
} else {
QTextBlockFormat blockFormat;
if (evenNumber)
if (evenNumber) {
blockFormat.setBackground(palette().base());
else
} else {
blockFormat.setBackground(palette().window());
}
evenNumber = !evenNumber;
@ -144,8 +146,9 @@ void ChatView::appendHtml(const QString &html)
{
bool atBottom = verticalScrollBar()->value() >= verticalScrollBar()->maximum();
prepareBlock().insertHtml(html);
if (atBottom)
if (atBottom) {
verticalScrollBar()->setValue(verticalScrollBar()->maximum());
}
}
void ChatView::appendHtmlServerMessage(const QString &html, bool optionalIsBold, QString optionalFontColor)
@ -156,12 +159,14 @@ void ChatView::appendHtmlServerMessage(const QString &html, bool optionalIsBold,
"<font color=" + ((optionalFontColor.size() > 0) ? optionalFontColor : serverMessageColor.name()) + ">" +
QDateTime::currentDateTime().toString("[hh:mm:ss] ") + html + "</font>";
if (optionalIsBold)
if (optionalIsBold) {
htmlText = "<b>" + htmlText + "</b>";
}
prepareBlock().insertHtml(htmlText);
if (atBottom)
if (atBottom) {
verticalScrollBar()->setValue(verticalScrollBar()->maximum());
}
}
void ChatView::appendCardTag(QTextCursor &cursor, const QString &cardName)
@ -180,8 +185,9 @@ void ChatView::appendCardTag(QTextCursor &cursor, const QString &cardName)
void ChatView::appendUrlTag(QTextCursor &cursor, QString url)
{
if (!url.contains("://"))
if (!url.contains("://")) {
url.prepend("https://");
}
QTextCharFormat oldFormat = cursor.charFormat();
QTextCharFormat anchorFormat = oldFormat;
@ -317,8 +323,9 @@ void ChatView::appendMessage(QString message,
}
}
if (atBottom)
if (atBottom) {
verticalScrollBar()->setValue(verticalScrollBar()->maximum());
}
}
void ChatView::checkTag(QTextCursor &cursor, QString &message)
@ -327,10 +334,11 @@ void ChatView::checkTag(QTextCursor &cursor, QString &message)
message = message.mid(6);
int closeTagIndex = message.indexOf("[/card]");
QString cardName = message.left(closeTagIndex);
if (closeTagIndex == -1)
if (closeTagIndex == -1) {
message.clear();
else
} else {
message = message.mid(closeTagIndex + 7);
}
appendCardTag(cursor, cardName);
return;
@ -340,10 +348,11 @@ void ChatView::checkTag(QTextCursor &cursor, QString &message)
message = message.mid(2);
int closeTagIndex = message.indexOf("]]");
QString cardName = message.left(closeTagIndex);
if (closeTagIndex == -1)
if (closeTagIndex == -1) {
message.clear();
else
} else {
message = message.mid(closeTagIndex + 2);
}
appendCardTag(cursor, cardName);
return;
@ -353,10 +362,11 @@ void ChatView::checkTag(QTextCursor &cursor, QString &message)
message = message.mid(5);
int closeTagIndex = message.indexOf("[/url]");
QString url = message.left(closeTagIndex);
if (closeTagIndex == -1)
if (closeTagIndex == -1) {
message.clear();
else
} else {
message = message.mid(closeTagIndex + 6);
}
appendUrlTag(cursor, url);
return;
@ -587,8 +597,9 @@ QTextFragment ChatView::getFragmentUnderMouse(const QPoint &pos) const
QTextBlock::iterator it;
for (it = block.begin(); !(it.atEnd()); ++it) {
QTextFragment frag = it.fragment();
if (frag.contains(cursor.position()))
if (frag.contains(cursor.position())) {
return frag;
}
}
return QTextFragment();
}
@ -604,10 +615,11 @@ void ChatView::mouseMoveEvent(QMouseEvent *event)
if (scheme == "card") {
hoveredItemType = HoveredCard;
emit cardNameHovered(hoveredContent);
} else if (scheme == "user")
} else if (scheme == "user") {
hoveredItemType = HoveredUser;
else
} else {
hoveredItemType = HoveredUrl;
}
viewport()->setCursor(Qt::PointingHandCursor);
} else {
hoveredItemType = HoveredNothing;
@ -650,8 +662,9 @@ void ChatView::mousePressEvent(QMouseEvent *event)
case Qt::LeftButton: {
if (event->modifiers() == Qt::ControlModifier) {
emit openMessageDialog(userName, true);
} else
} else {
emit addMentionTag("@" + userName);
}
break;
}
default:
@ -668,16 +681,18 @@ void ChatView::mousePressEvent(QMouseEvent *event)
void ChatView::mouseReleaseEvent(QMouseEvent *event)
{
if ((event->button() == Qt::MiddleButton) || (event->button() == Qt::LeftButton))
if ((event->button() == Qt::MiddleButton) || (event->button() == Qt::LeftButton)) {
emit deleteCardInfoPopup(QString("_"));
}
QTextBrowser::mouseReleaseEvent(event);
}
void ChatView::openLink(const QUrl &link)
{
if ((link.scheme() == "card") || (link.scheme() == "user"))
if ((link.scheme() == "card") || (link.scheme() == "user")) {
return;
}
QDesktopServices::openUrl(link);
}

View file

@ -61,14 +61,17 @@ GameSelector::GameSelector(AbstractClient *_client,
gameListView->setColumnWidth(3, gameListView->columnWidth(3) * 1.2);
// game type width
gameListView->setColumnWidth(4, gameListView->columnWidth(4) * 1.4);
if (_room)
if (_room) {
gameListView->header()->hideSection(gameListModel->roomColIndex());
}
if (room)
if (room) {
gameTypeMap = gameListModel->getGameTypes().value(room->getRoomId());
}
if (showFilters && restoresettings)
if (showFilters && restoresettings) {
gameListProxyModel->loadFilterParameters(gameTypeMap);
}
gameListView->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
@ -111,8 +114,9 @@ GameSelector::GameSelector(AbstractClient *_client,
buttonLayout->addWidget(clearFilterButton);
}
buttonLayout->addStretch();
if (room)
if (room) {
buttonLayout->addWidget(createButton);
}
buttonLayout->addWidget(joinButton);
if (tabSupervisor->getUserInfo()->user_level() & ServerInfo_User::IsJudge) {
buttonLayout->addWidget(joinAsJudgeButton);
@ -178,8 +182,9 @@ void GameSelector::actSetFilter()
{
DlgFilterGames dlg(gameTypeMap, gameListProxyModel, this);
if (!dlg.exec())
if (!dlg.exec()) {
return;
}
gameListProxyModel->setGameFilters(dlg.getFilters());
gameListProxyModel->saveFilterParameters(gameTypeMap);
@ -373,8 +378,9 @@ void GameSelector::joinGame(const bool asSpectator, const bool asJudge)
void GameSelector::disableButtons()
{
if (createButton)
if (createButton) {
createButton->setEnabled(false);
}
joinButton->setEnabled(false);
spectateButton->setEnabled(false);
@ -382,8 +388,9 @@ void GameSelector::disableButtons()
void GameSelector::enableButtons()
{
if (createButton)
if (createButton) {
createButton->setEnabled(true);
}
// Enable buttons for the currently selected game
enableButtonsForIndex(gameListView->currentIndex());
@ -391,8 +398,9 @@ void GameSelector::enableButtons()
void GameSelector::enableButtonsForIndex(const QModelIndex &current)
{
if (!current.isValid())
if (!current.isValid()) {
return;
}
const ServerInfo_Game &game = gameListModel->getGame(current.data(Qt::UserRole).toInt());
bool overrideRestrictions = !tabSupervisor->getAdminLocked();
@ -405,8 +413,9 @@ void GameSelector::retranslateUi()
{
filterButton->setText(tr("&Filter games"));
clearFilterButton->setText(tr("C&lear filter"));
if (createButton)
if (createButton) {
createButton->setText(tr("C&reate"));
}
joinButton->setText(tr("&Join"));
joinAsJudgeButton->setText(tr("Join as judge"));
spectateButton->setText(tr("J&oin as spectator"));

View file

@ -59,8 +59,9 @@ GameSelectorQuickFilterToolBar::GameSelectorQuickFilterToolBar(QWidget *parent,
if (currentTypes.size() == 1) {
int typeId = *currentTypes.begin();
int index = filterToFormatComboBox->findData(typeId);
if (index >= 0)
if (index >= 0) {
filterToFormatComboBox->setCurrentIndex(index);
}
} else {
filterToFormatComboBox->setCurrentIndex(0); // "All types" by default
}

View file

@ -63,14 +63,18 @@ GamesModel::GamesModel(const QMap<int, QString> &_rooms, const QMap<int, GameTyp
QVariant GamesModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
if (!index.isValid()) {
return QVariant();
if (role == Qt::UserRole)
}
if (role == Qt::UserRole) {
return index.row();
if (role != Qt::DisplayRole && role != SORT_ROLE && role != Qt::DecorationRole && role != Qt::TextAlignmentRole)
}
if (role != Qt::DisplayRole && role != SORT_ROLE && role != Qt::DecorationRole && role != Qt::TextAlignmentRole) {
return QVariant();
if ((index.row() >= gameList.size()) || (index.column() >= columnCount()))
}
if ((index.row() >= gameList.size()) || (index.column() >= columnCount())) {
return QVariant();
}
const ServerInfo_Game &gameentry = gameList[index.row()];
switch (index.column()) {
@ -126,8 +130,9 @@ QVariant GamesModel::data(const QModelIndex &index, int role) const
case Qt::DisplayRole: {
QStringList result;
GameTypeMap gameTypeMap = gameTypes.value(gameentry.room_id());
for (int i = gameentry.game_types_size() - 1; i >= 0; --i)
for (int i = gameentry.game_types_size() - 1; i >= 0; --i) {
result.append(gameTypeMap.value(gameentry.game_types(i)));
}
return result.join(", ");
}
case Qt::TextAlignmentRole:
@ -140,14 +145,18 @@ QVariant GamesModel::data(const QModelIndex &index, int role) const
case SORT_ROLE:
case Qt::DisplayRole: {
QStringList result;
if (gameentry.with_password())
if (gameentry.with_password()) {
result.append(tr("password"));
if (gameentry.only_buddies())
}
if (gameentry.only_buddies()) {
result.append(tr("buddies only"));
if (gameentry.only_registered())
}
if (gameentry.only_registered()) {
result.append(tr("reg. users only"));
if (gameentry.share_decklists_on_load())
}
if (gameentry.share_decklists_on_load()) {
result.append(tr("open decklists"));
}
return result.join(", ");
}
case Qt::DecorationRole: {
@ -205,8 +214,9 @@ QVariant GamesModel::data(const QModelIndex &index, int role) const
QVariant GamesModel::headerData(int section, Qt::Orientation /*orientation*/, int role) const
{
if ((role != Qt::DisplayRole) && (role != Qt::TextAlignmentRole))
if ((role != Qt::DisplayRole) && (role != Qt::TextAlignmentRole)) {
return QVariant();
}
switch (section) {
case ROOM:
return tr("Room");
@ -296,8 +306,9 @@ void GamesProxyModel::setGameFilters(const GameFilterConfigs &_filters)
int GamesProxyModel::getNumFilteredGames() const
{
auto *model = qobject_cast<GamesModel *>(sourceModel());
if (!model)
if (!model) {
return 0;
}
int numFilteredGames = 0;
for (int row = 0; row < model->rowCount(); ++row) {
@ -384,8 +395,9 @@ bool GamesProxyModel::filterAcceptsRow(int sourceRow) const
static const QDate epochDate = QDateTime::fromSecsSinceEpoch(0, Qt::UTC).date();
#endif
auto *model = qobject_cast<GamesModel *>(sourceModel());
if (!model)
if (!model) {
return false;
}
const ServerInfo_Game &game = model->getGame(sourceRow);
@ -403,18 +415,25 @@ bool GamesProxyModel::filterAcceptsRow(int sourceRow) const
!userListProxy->isUserBuddy(QString::fromStdString(game.creator_info().name()))) {
return false;
}
if (filters.hideFullGames && game.player_count() == game.max_players())
if (filters.hideFullGames && game.player_count() == game.max_players()) {
return false;
if (filters.hideGamesThatStarted && game.started())
}
if (filters.hideGamesThatStarted && game.started()) {
return false;
if (!userListProxy->isOwnUserRegistered())
if (game.only_registered())
}
if (!userListProxy->isOwnUserRegistered()) {
if (game.only_registered()) {
return false;
if (filters.hidePasswordProtectedGames && game.with_password())
}
}
if (filters.hidePasswordProtectedGames && game.with_password()) {
return false;
if (!filters.gameNameFilter.isEmpty())
if (!QString::fromStdString(game.description()).contains(filters.gameNameFilter, Qt::CaseInsensitive))
}
if (!filters.gameNameFilter.isEmpty()) {
if (!QString::fromStdString(game.description()).contains(filters.gameNameFilter, Qt::CaseInsensitive)) {
return false;
}
}
if (!filters.creatorNameFilters.isEmpty()) {
bool found = false;
for (const auto &createNameFilter : filters.creatorNameFilters) {
@ -428,15 +447,19 @@ bool GamesProxyModel::filterAcceptsRow(int sourceRow) const
}
QSet<int> gameTypes;
for (int i = 0; i < game.game_types_size(); ++i)
for (int i = 0; i < game.game_types_size(); ++i) {
gameTypes.insert(game.game_types(i));
if (!filters.gameTypeFilter.isEmpty() && gameTypes.intersect(filters.gameTypeFilter).isEmpty())
}
if (!filters.gameTypeFilter.isEmpty() && gameTypes.intersect(filters.gameTypeFilter).isEmpty()) {
return false;
}
if (static_cast<int>(game.max_players()) < filters.maxPlayersFilterMin)
if (static_cast<int>(game.max_players()) < filters.maxPlayersFilterMin) {
return false;
if (static_cast<int>(game.max_players()) > filters.maxPlayersFilterMax)
}
if (static_cast<int>(game.max_players()) > filters.maxPlayersFilterMax) {
return false;
}
if (filters.maxGameAge.isValid()) {
QDateTime now = QDateTime::currentDateTimeUtc();
@ -451,14 +474,18 @@ bool GamesProxyModel::filterAcceptsRow(int sourceRow) const
}
if (filters.showOnlyIfSpectatorsCanWatch) {
if (!game.spectators_allowed())
if (!game.spectators_allowed()) {
return false;
if (!filters.showSpectatorPasswordProtected && game.spectators_need_password())
}
if (!filters.showSpectatorPasswordProtected && game.spectators_need_password()) {
return false;
if (filters.showOnlyIfSpectatorsCanChat && !game.spectators_can_chat())
}
if (filters.showOnlyIfSpectatorsCanChat && !game.spectators_can_chat()) {
return false;
if (filters.showOnlyIfSpectatorsCanSeeHands && !game.spectators_omniscient())
}
if (filters.showOnlyIfSpectatorsCanSeeHands && !game.spectators_omniscient()) {
return false;
}
}
return true;
}

View file

@ -37,13 +37,11 @@ void HandlePublicServers::actFinishParsingDownloadedData()
QVariantMap jsonMap = jsonResponse.toVariant().toMap();
updateServerINISettings(jsonMap);
} else {
qDebug() << "[PUBLIC SERVER HANDLER]"
<< "JSON Parsing Error:" << parseError.errorString();
qDebug() << "[PUBLIC SERVER HANDLER]" << "JSON Parsing Error:" << parseError.errorString();
emit sigPublicServersDownloadedUnsuccessfully(errorCode);
}
} else {
qDebug() << "[PUBLIC SERVER HANDLER]"
<< "Error Downloading Public Servers" << errorCode;
qDebug() << "[PUBLIC SERVER HANDLER]" << "Error Downloading Public Servers" << errorCode;
emit sigPublicServersDownloadedUnsuccessfully(errorCode);
}

View file

@ -22,8 +22,9 @@ RemoteDeckList_TreeModel::DirectoryNode::~DirectoryNode()
void RemoteDeckList_TreeModel::DirectoryNode::clearTree()
{
for (int i = 0; i < size(); ++i)
for (int i = 0; i < size(); ++i) {
delete at(i);
}
clear();
}
@ -31,31 +32,37 @@ QString RemoteDeckList_TreeModel::DirectoryNode::getPath() const
{
if (parent) {
QString parentPath = parent->getPath();
if (parentPath.isEmpty())
if (parentPath.isEmpty()) {
return name;
else
} else {
return parentPath + "/" + name;
} else
}
} else {
return name;
}
}
RemoteDeckList_TreeModel::DirectoryNode *RemoteDeckList_TreeModel::DirectoryNode::getNodeByPath(QStringList path)
{
QString pathItem;
if (parent) {
if (path.isEmpty())
if (path.isEmpty()) {
return this;
}
pathItem = path.takeFirst();
if (pathItem.isEmpty() && name.isEmpty())
if (pathItem.isEmpty() && name.isEmpty()) {
return this;
}
}
for (int i = 0; i < size(); ++i) {
DirectoryNode *node = dynamic_cast<DirectoryNode *>(at(i));
if (!node)
if (!node) {
continue;
if (node->getName() == pathItem)
}
if (node->getName() == pathItem) {
return node->getNodeByPath(path);
}
}
return 0;
}
@ -66,12 +73,14 @@ RemoteDeckList_TreeModel::FileNode *RemoteDeckList_TreeModel::DirectoryNode::get
DirectoryNode *node = dynamic_cast<DirectoryNode *>(at(i));
if (node) {
FileNode *result = node->getNodeById(id);
if (result)
if (result) {
return result;
}
} else {
FileNode *file = dynamic_cast<FileNode *>(at(i));
if (file->getId() == id)
if (file->getId() == id) {
return file;
}
}
}
return 0;
@ -95,10 +104,11 @@ RemoteDeckList_TreeModel::~RemoteDeckList_TreeModel()
int RemoteDeckList_TreeModel::rowCount(const QModelIndex &parent) const
{
DirectoryNode *node = getNode<DirectoryNode *>(parent);
if (node)
if (node) {
return node->size();
else
} else {
return 0;
}
}
int RemoteDeckList_TreeModel::columnCount(const QModelIndex & /*parent*/) const
@ -108,10 +118,12 @@ int RemoteDeckList_TreeModel::columnCount(const QModelIndex & /*parent*/) const
QVariant RemoteDeckList_TreeModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
if (!index.isValid()) {
return QVariant();
if (index.column() >= 3)
}
if (index.column() >= 3) {
return QVariant();
}
Node *temp = static_cast<Node *>(index.internalPointer());
FileNode *file = dynamic_cast<FileNode *>(temp);
@ -157,8 +169,9 @@ QVariant RemoteDeckList_TreeModel::data(const QModelIndex &index, int role) cons
QVariant RemoteDeckList_TreeModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (orientation != Qt::Horizontal)
if (orientation != Qt::Horizontal) {
return QVariant();
}
switch (role) {
case Qt::TextAlignmentRole:
return section == 1 ? Qt::AlignRight : Qt::AlignLeft;
@ -181,20 +194,23 @@ QVariant RemoteDeckList_TreeModel::headerData(int section, Qt::Orientation orien
QModelIndex RemoteDeckList_TreeModel::index(int row, int column, const QModelIndex &parent) const
{
if (!hasIndex(row, column, parent))
if (!hasIndex(row, column, parent)) {
return QModelIndex();
}
DirectoryNode *parentNode = getNode<DirectoryNode *>(parent);
if (row >= parentNode->size())
if (row >= parentNode->size()) {
return QModelIndex();
}
return createIndex(row, column, parentNode->at(row));
}
QModelIndex RemoteDeckList_TreeModel::parent(const QModelIndex &ind) const
{
if (!ind.isValid())
if (!ind.isValid()) {
return QModelIndex();
}
return nodeToIndex(static_cast<Node *>(ind.internalPointer())->getParent());
}
@ -210,8 +226,9 @@ Qt::ItemFlags RemoteDeckList_TreeModel::flags(const QModelIndex &index) const
QModelIndex RemoteDeckList_TreeModel::nodeToIndex(Node *node) const
{
if (node == nullptr || node == root)
if (node == nullptr || node == root) {
return QModelIndex();
}
return createIndex(node->getParent()->indexOf(node), 0, node);
}
@ -233,10 +250,11 @@ void RemoteDeckList_TreeModel::addFolderToTree(const ServerInfo_DeckStorage_Tree
const int folderItemsSize = folderInfo.items_size();
for (int i = 0; i < folderItemsSize; ++i) {
const ServerInfo_DeckStorage_TreeItem &subItem = folderInfo.items(i);
if (subItem.has_folder())
if (subItem.has_folder()) {
addFolderToTree(subItem, newItem);
else
} else {
addFileToTree(subItem, newItem);
}
}
}

View file

@ -75,8 +75,9 @@ public:
template <typename T> [[nodiscard]] T getNode(const QModelIndex &index) const
{
if (!index.isValid())
if (!index.isValid()) {
return dynamic_cast<T>(root);
}
return dynamic_cast<T>(static_cast<Node *>(index.internalPointer()));
}

View file

@ -14,14 +14,16 @@ const int RemoteReplayList_TreeModel::numberOfColumns = 6;
RemoteReplayList_TreeModel::MatchNode::MatchNode(const ServerInfo_ReplayMatch &_matchInfo)
: RemoteReplayList_TreeModel::Node(QString::fromStdString(_matchInfo.game_name())), matchInfo(_matchInfo)
{
for (int i = 0; i < matchInfo.replay_list_size(); ++i)
for (int i = 0; i < matchInfo.replay_list_size(); ++i) {
append(new ReplayNode(matchInfo.replay_list(i), this));
}
}
RemoteReplayList_TreeModel::MatchNode::~MatchNode()
{
for (int i = 0; i < size(); ++i)
for (int i = 0; i < size(); ++i) {
delete at(i);
}
}
void RemoteReplayList_TreeModel::MatchNode::updateMatchInfo(const ServerInfo_ReplayMatch &_matchInfo)
@ -45,22 +47,26 @@ RemoteReplayList_TreeModel::~RemoteReplayList_TreeModel()
int RemoteReplayList_TreeModel::rowCount(const QModelIndex &parent) const
{
if (!parent.isValid())
if (!parent.isValid()) {
return replayMatches.size();
}
auto *matchNode = dynamic_cast<MatchNode *>(static_cast<Node *>(parent.internalPointer()));
if (matchNode)
if (matchNode) {
return matchNode->size();
else
} else {
return 0;
}
}
QVariant RemoteReplayList_TreeModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
if (!index.isValid()) {
return QVariant();
if (index.column() >= numberOfColumns)
}
if (index.column() >= numberOfColumns) {
return QVariant();
}
auto *replayNode = dynamic_cast<ReplayNode *>(static_cast<Node *>(index.internalPointer()));
if (replayNode) {
@ -103,8 +109,9 @@ QVariant RemoteReplayList_TreeModel::data(const QModelIndex &index, int role) co
return QString::fromStdString(matchInfo.game_name());
case 2: {
QStringList playerList;
for (int i = 0; i < matchInfo.player_names_size(); ++i)
for (int i = 0; i < matchInfo.player_names_size(); ++i) {
playerList.append(QString::fromStdString(matchInfo.player_names(i)));
}
return playerList.join(", ");
}
case 4:
@ -131,8 +138,9 @@ QVariant RemoteReplayList_TreeModel::data(const QModelIndex &index, int role) co
QVariant RemoteReplayList_TreeModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (orientation != Qt::Horizontal)
if (orientation != Qt::Horizontal) {
return QVariant();
}
switch (role) {
case Qt::TextAlignmentRole:
switch (section) {
@ -167,17 +175,20 @@ QVariant RemoteReplayList_TreeModel::headerData(int section, Qt::Orientation ori
QModelIndex RemoteReplayList_TreeModel::index(int row, int column, const QModelIndex &parent) const
{
if (!hasIndex(row, column, parent))
if (!hasIndex(row, column, parent)) {
return QModelIndex();
}
auto *matchNode = dynamic_cast<MatchNode *>(static_cast<Node *>(parent.internalPointer()));
if (matchNode) {
if (row >= matchNode->size())
if (row >= matchNode->size()) {
return QModelIndex();
}
return createIndex(row, column, (void *)matchNode->at(row));
} else {
if (row >= replayMatches.size())
if (row >= replayMatches.size()) {
return QModelIndex();
}
return createIndex(row, column, (void *)replayMatches[row]);
}
}
@ -185,9 +196,9 @@ QModelIndex RemoteReplayList_TreeModel::index(int row, int column, const QModelI
QModelIndex RemoteReplayList_TreeModel::parent(const QModelIndex &ind) const
{
MatchNode const *matchNode = dynamic_cast<MatchNode *>(static_cast<Node *>(ind.internalPointer()));
if (matchNode)
if (matchNode) {
return QModelIndex();
else {
} else {
auto *replayNode = dynamic_cast<ReplayNode *>(static_cast<Node *>(ind.internalPointer()));
return createIndex(replayNode->getParent()->indexOf(replayNode), 0, replayNode->getParent());
}
@ -195,45 +206,52 @@ QModelIndex RemoteReplayList_TreeModel::parent(const QModelIndex &ind) const
Qt::ItemFlags RemoteReplayList_TreeModel::flags(const QModelIndex &index) const
{
if (!index.isValid())
if (!index.isValid()) {
return Qt::NoItemFlags;
}
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
}
ServerInfo_Replay const *RemoteReplayList_TreeModel::getReplay(const QModelIndex &index) const
{
if (!index.isValid())
if (!index.isValid()) {
return 0;
}
auto *node = dynamic_cast<ReplayNode *>(static_cast<Node *>(index.internalPointer()));
if (!node)
if (!node) {
return 0;
}
return &node->getReplayInfo();
}
ServerInfo_ReplayMatch const *RemoteReplayList_TreeModel::getReplayMatch(const QModelIndex &index) const
{
if (!index.isValid())
if (!index.isValid()) {
return nullptr;
}
auto *node = dynamic_cast<MatchNode *>(static_cast<Node *>(index.internalPointer()));
if (!node)
if (!node) {
return nullptr;
}
return &node->getMatchInfo();
}
ServerInfo_ReplayMatch const *RemoteReplayList_TreeModel::getEnclosingReplayMatch(const QModelIndex &index) const
{
if (!index.isValid())
if (!index.isValid()) {
return nullptr;
}
auto *node = dynamic_cast<MatchNode *>(static_cast<Node *>(index.internalPointer()));
if (!node) {
auto *_node = dynamic_cast<ReplayNode *>(static_cast<Node *>(index.internalPointer()));
if (!_node)
if (!_node) {
return nullptr;
}
return &_node->getParent()->getMatchInfo();
}
return &node->getMatchInfo();
@ -244,8 +262,9 @@ ServerInfo_ReplayMatch const *RemoteReplayList_TreeModel::getEnclosingReplayMatc
*/
void RemoteReplayList_TreeModel::clearAll()
{
for (int i = 0; i < replayMatches.size(); ++i)
for (int i = 0; i < replayMatches.size(); ++i) {
delete replayMatches[i];
}
replayMatches.clear();
}
@ -275,24 +294,26 @@ void RemoteReplayList_TreeModel::addMatchInfo(const ServerInfo_ReplayMatch &matc
void RemoteReplayList_TreeModel::updateMatchInfo(int gameId, const ServerInfo_ReplayMatch &matchInfo)
{
for (int i = 0; i < replayMatches.size(); ++i)
for (int i = 0; i < replayMatches.size(); ++i) {
if (replayMatches[i]->getMatchInfo().game_id() == gameId) {
replayMatches[i]->updateMatchInfo(matchInfo);
emit dataChanged(createIndex(i, 0, (void *)replayMatches[i]),
createIndex(i, numberOfColumns - 1, (void *)replayMatches[i]));
break;
}
}
}
void RemoteReplayList_TreeModel::removeMatchInfo(int gameId)
{
for (int i = 0; i < replayMatches.size(); ++i)
for (int i = 0; i < replayMatches.size(); ++i) {
if (replayMatches[i]->getMatchInfo().game_id() == gameId) {
beginRemoveRows(QModelIndex(), i, i);
replayMatches.removeAt(i);
endRemoveRows();
break;
}
}
}
void RemoteReplayList_TreeModel::replayListFinished(const Response &r)
@ -302,8 +323,9 @@ void RemoteReplayList_TreeModel::replayListFinished(const Response &r)
beginResetModel();
clearAll();
for (int i = 0; i < resp.match_list_size(); ++i)
for (int i = 0; i < resp.match_list_size(); ++i) {
replayMatches.append(new MatchNode(resp.match_list(i)));
}
endResetModel();
emit treeRefreshed();

View file

@ -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());

View file

@ -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());

View file

@ -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;
}

View file

@ -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()));
}