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,20 +88,27 @@ static void setupParserRules()
const auto arg = std::any_cast<int>(sv[1]);
const auto op = std::any_cast<QString>(sv[0]);
if (op == ">")
if (op == ">") {
return [=](const int s) { return s > arg; };
if (op == ">=")
}
if (op == ">=") {
return [=](const int s) { return s >= arg; };
if (op == "<")
}
if (op == "<") {
return [=](const int s) { return s < arg; };
if (op == "<=")
}
if (op == "<=") {
return [=](const int s) { return s <= arg; };
if (op == "=")
}
if (op == "=") {
return [=](const int s) { return s == arg; };
if (op == ":")
}
if (op == ":") {
return [=](const int s) { return s == arg; };
if (op == "!=")
}
if (op == "!=") {
return [=](const int s) { return s != arg; };
}
return [](int) { return false; };
};

View file

@ -11,13 +11,15 @@ FilterBuilder::FilterBuilder(QWidget *parent) : QWidget(parent)
{
filterCombo = new QComboBox;
filterCombo->setObjectName("filterCombo");
for (int i = 0; i < CardFilter::AttrEnd; i++)
for (int i = 0; i < CardFilter::AttrEnd; i++) {
filterCombo->addItem(CardFilter::attrName(static_cast<CardFilter::Attr>(i)), QVariant(i));
}
typeCombo = new QComboBox;
typeCombo->setObjectName("typeCombo");
for (int i = 0; i < CardFilter::TypeEnd; i++)
for (int i = 0; i < CardFilter::TypeEnd; i++) {
typeCombo->addItem(CardFilter::typeName(static_cast<CardFilter::Type>(i)), QVariant(i));
}
QPushButton *ok = new QPushButton(QPixmap("theme:icons/increment"), QString());
ok->setObjectName("ok");
@ -53,8 +55,9 @@ FilterBuilder::~FilterBuilder()
void FilterBuilder::destroyFilter()
{
if (fltr)
if (fltr) {
delete fltr;
}
}
static int comboCurrentIntData(const QComboBox *combo)
@ -67,8 +70,9 @@ void FilterBuilder::emit_add()
QString txt;
txt = edit->text();
if (txt.length() < 1)
if (txt.length() < 1) {
return;
}
destroyFilter();
fltr = new CardFilter(txt, static_cast<CardFilter::Type>(comboCurrentIntData(typeCombo)),

View file

@ -23,8 +23,9 @@ void FilterTreeModel::proxyBeginInsertRow(const FilterTreeNode *node, int i)
int idx;
idx = node->index();
if (idx >= 0)
if (idx >= 0) {
beginInsertRows(createIndex(idx, 0, (void *)node), i, i);
}
}
void FilterTreeModel::proxyEndInsertRow(const FilterTreeNode *node, int)
@ -32,8 +33,9 @@ void FilterTreeModel::proxyEndInsertRow(const FilterTreeNode *node, int)
int idx;
idx = node->index();
if (idx >= 0)
if (idx >= 0) {
endInsertRows();
}
}
void FilterTreeModel::proxyBeginRemoveRow(const FilterTreeNode *node, int i)
@ -41,8 +43,9 @@ void FilterTreeModel::proxyBeginRemoveRow(const FilterTreeNode *node, int i)
int idx;
idx = node->index();
if (idx >= 0)
if (idx >= 0) {
beginRemoveRows(createIndex(idx, 0, (void *)node), i, i);
}
}
void FilterTreeModel::proxyEndRemoveRow(const FilterTreeNode *node, int)
@ -50,8 +53,9 @@ void FilterTreeModel::proxyEndRemoveRow(const FilterTreeNode *node, int)
int idx;
idx = node->index();
if (idx >= 0)
if (idx >= 0) {
endRemoveRows();
}
}
FilterTreeNode *FilterTreeModel::indexToNode(const QModelIndex &idx) const
@ -59,12 +63,14 @@ FilterTreeNode *FilterTreeModel::indexToNode(const QModelIndex &idx) const
void *ip;
FilterTreeNode *node;
if (!idx.isValid())
if (!idx.isValid()) {
return fTree;
}
ip = idx.internalPointer();
if (ip == NULL)
if (ip == NULL) {
return fTree;
}
node = static_cast<FilterTreeNode *>(ip);
return node;
@ -145,14 +151,16 @@ int FilterTreeModel::rowCount(const QModelIndex &parent) const
const FilterTreeNode *node;
int result;
if (parent.column() > 0)
if (parent.column() > 0) {
return 0;
}
node = indexToNode(parent);
if (node)
if (node) {
result = node->childCount();
else
} else {
result = 0;
}
return result;
}
@ -166,14 +174,17 @@ QVariant FilterTreeModel::data(const QModelIndex &index, int role) const
{
const FilterTreeNode *node;
if (!index.isValid())
if (!index.isValid()) {
return QVariant();
if (index.column() >= columnCount())
}
if (index.column() >= columnCount()) {
return QVariant();
}
node = indexToNode(index);
if (node == NULL)
if (node == NULL) {
return QVariant();
}
switch (role) {
case Qt::FontRole:
@ -190,10 +201,11 @@ QVariant FilterTreeModel::data(const QModelIndex &index, int role) const
case Qt::WhatsThisRole:
return node->text();
case Qt::CheckStateRole:
if (node->isEnabled())
if (node->isEnabled()) {
return Qt::Checked;
else
} else {
return Qt::Unchecked;
}
default:
return QVariant();
}
@ -205,22 +217,27 @@ bool FilterTreeModel::setData(const QModelIndex &index, const QVariant &value, i
{
FilterTreeNode *node;
if (!index.isValid())
if (!index.isValid()) {
return false;
if (index.column() >= columnCount())
}
if (index.column() >= columnCount()) {
return false;
if (role != Qt::CheckStateRole)
}
if (role != Qt::CheckStateRole) {
return false;
}
node = indexToNode(index);
if (node == NULL || node == fTree)
if (node == NULL || node == fTree) {
return false;
}
Qt::CheckState state = static_cast<Qt::CheckState>(value.toInt());
if (state == Qt::Checked)
if (state == Qt::Checked) {
node->enable();
else
} else {
node->disable();
}
emit dataChanged(index, index);
return true;
@ -231,16 +248,19 @@ Qt::ItemFlags FilterTreeModel::flags(const QModelIndex &index) const
const FilterTreeNode *node;
Qt::ItemFlags result;
if (!index.isValid())
if (!index.isValid()) {
return Qt::NoItemFlags;
}
node = indexToNode(index);
if (node == NULL)
if (node == NULL) {
return Qt::NoItemFlags;
}
result = Qt::ItemIsEnabled;
if (node == fTree)
if (node == fTree) {
return result;
}
result |= Qt::ItemIsSelectable;
result |= Qt::ItemIsUserCheckable;
@ -252,8 +272,9 @@ QModelIndex FilterTreeModel::nodeIndex(const FilterTreeNode *node, int row, int
{
FilterTreeNode *child;
if (column > 0 || row >= node->childCount())
if (column > 0 || row >= node->childCount()) {
return QModelIndex();
}
child = node->nodeAt(row);
return createIndex(row, column, child);
@ -263,12 +284,14 @@ QModelIndex FilterTreeModel::index(int row, int column, const QModelIndex &paren
{
const FilterTreeNode *node;
if (!hasIndex(row, column, parent))
if (!hasIndex(row, column, parent)) {
return QModelIndex();
}
node = indexToNode(parent);
if (node == NULL)
if (node == NULL) {
return QModelIndex();
}
return nodeIndex(node, row, column);
}
@ -279,18 +302,21 @@ QModelIndex FilterTreeModel::parent(const QModelIndex &ind) const
FilterTreeNode *parent;
QModelIndex idx;
if (!ind.isValid())
if (!ind.isValid()) {
return QModelIndex();
}
node = indexToNode(ind);
if (node == NULL || node == fTree)
if (node == NULL || node == fTree) {
return QModelIndex();
}
parent = node->parent();
if (parent) {
int row = parent->index();
if (row < 0)
if (row < 0) {
return QModelIndex();
}
idx = createIndex(row, 0, parent);
return idx;
}
@ -304,18 +330,22 @@ bool FilterTreeModel::removeRows(int row, int count, const QModelIndex &parent)
int i, last;
last = row + count - 1;
if (!parent.isValid() || count < 1 || row < 0)
if (!parent.isValid() || count < 1 || row < 0) {
return false;
}
node = indexToNode(parent);
if (node == NULL || last >= node->childCount())
if (node == NULL || last >= node->childCount()) {
return false;
}
for (i = 0; i < count; i++)
for (i = 0; i < count; i++) {
node->deleteAt(row);
}
if (node != fTree && node->childCount() < 1)
if (node != fTree && node->childCount() < 1) {
return removeRow(parent.row(), parent.parent());
}
return true;
}