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

@ -40,8 +40,9 @@ public:
static QString toId(Type type)
{
for (const auto &e : all()) {
if (e.type == type)
if (e.type == type) {
return e.id;
}
}
return {};
}
@ -49,8 +50,9 @@ public:
static Type fromId(const QString &id)
{
for (const auto &e : all()) {
if (id == e.id)
if (id == e.id) {
return e.type;
}
}
return Theme; // default
}
@ -58,8 +60,9 @@ public:
static QString toDisplay(Type type)
{
for (const auto &e : all()) {
if (e.type == type)
if (e.type == type) {
return QObject::tr(e.trKey);
}
}
return {};
}

View file

@ -52,8 +52,9 @@ void BarChartWidget::paintEvent(QPaintEvent *)
int barAreaWidth = right - left;
int barCount = bars.size();
if (barCount == 0)
if (barCount == 0) {
return;
}
int spacing = 6;
int barWidth = (barAreaWidth - (barCount - 1) * spacing) / barCount;
@ -91,8 +92,9 @@ void BarChartWidget::paintEvent(QPaintEvent *)
for (int j = 0; j < bar.segments.size(); j++) {
const auto &seg = bar.segments[j];
int segHeight = (seg.value * barAreaHeight / highest);
if (segHeight < 2 && seg.value > 0)
if (segHeight < 2 && seg.value > 0) {
segHeight = 2;
}
int topY = yCurrent - segHeight;
@ -189,8 +191,9 @@ void BarChartWidget::mouseMoveEvent(QMouseEvent *e)
for (int i = 0; i < segments.size(); i++) {
const auto &seg = segments[i];
int segHeight = (seg.value * barAreaHeight / highest);
if (segHeight < 2 && seg.value > 0)
if (segHeight < 2 && seg.value > 0) {
segHeight = 2;
}
int topY = yCurrent - segHeight;
int bottomY = yCurrent;

View file

@ -26,16 +26,19 @@ QSize ColorBar::minimumSizeHint() const
void ColorBar::paintEvent(QPaintEvent *)
{
if (colors.isEmpty())
if (colors.isEmpty()) {
return;
}
int total = 0;
for (const auto &pair : colors)
for (const auto &pair : colors) {
total += pair.second;
}
// Prevent divide-by-zero
if (total == 0)
if (total == 0) {
return;
}
QPainter p(this);
p.setRenderHint(QPainter::Antialiasing, true);
@ -63,8 +66,9 @@ void ColorBar::paintEvent(QPaintEvent *)
int segmentWidth = int(ratio * w);
// Ensure the segment width is at least 1 to avoid degenerate rectangles
if (segmentWidth < 1)
if (segmentWidth < 1) {
segmentWidth = 1;
}
QColor base = colorFromName(key);
@ -100,8 +104,9 @@ void ColorBar::leaveEvent(QEvent *)
void ColorBar::mouseMoveEvent(QMouseEvent *event)
{
if (!isHovered || colors.isEmpty())
if (!isHovered || colors.isEmpty()) {
return;
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
int x = int(event->position().x());
@ -112,18 +117,21 @@ void ColorBar::mouseMoveEvent(QMouseEvent *event)
#endif
QString text = tooltipForPosition(x);
if (!text.isEmpty())
if (!text.isEmpty()) {
QToolTip::showText(gp, text, this);
}
}
QString ColorBar::tooltipForPosition(int x) const
{
int total = 0;
for (const auto &pair : colors)
for (const auto &pair : colors) {
total += pair.second;
}
if (total == 0)
if (total == 0) {
return {};
}
int pos = 0;
@ -149,12 +157,14 @@ QColor ColorBar::colorFromName(const QString &name) const
{"W", QColor(235, 235, 230)}, {"B", QColor(30, 30, 30)},
};
if (map.contains(name))
if (map.contains(name)) {
return map[name];
}
QColor c(name);
if (!c.isValid())
if (!c.isValid()) {
c = Qt::gray;
}
return c;
}

View file

@ -44,8 +44,9 @@ void SegmentedBarWidget::paintEvent(QPaintEvent *)
const auto &seg = segments[i];
int segHeight = total > 0 ? (seg.value * barHeight / total) : 0;
if (segHeight < 2)
if (segHeight < 2) {
segHeight = 2;
}
QRect r(barX, yCurrent - segHeight, barWidth, segHeight);
bool isTop = (i == segments.size() - 1);
@ -110,8 +111,9 @@ int SegmentedBarWidget::segmentAt(int y) const
int top = currentTop - segHeight;
int bottom = currentTop;
if (y >= top && y <= bottom)
if (y >= top && y <= bottom) {
return i;
}
currentTop -= segHeight;
}

View file

@ -157,8 +157,9 @@ QString ColorPie::tooltipForPoint(const QPoint &pt) const
QPointF v = pt - center;
double distance = std::hypot(v.x(), v.y());
if (distance > size / 2.0)
if (distance > size / 2.0) {
return {};
}
double angle = std::atan2(-v.y(), v.x()) * 180.0 / M_PI;
if (angle < 0) {

View file

@ -139,8 +139,9 @@ void HomeWidget::updateRandomCard()
}
break;
}
if (!newCard)
if (!newCard) {
return;
}
connect(newCard.getCardPtr().data(), &CardInfo::pixmapUpdated, this, &HomeWidget::updateBackgroundProperties);
backgroundSourceCard->setCard(newCard);