mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-18 04:51:33 -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
|
|
@ -27,13 +27,16 @@ ArrowItem::ArrowItem(Player *_player, int _id, ArrowTarget *_startItem, ArrowTar
|
|||
{
|
||||
setZValue(ZValues::ARROWS);
|
||||
|
||||
if (startItem)
|
||||
if (startItem) {
|
||||
startItem->addArrowFrom(this);
|
||||
if (targetItem)
|
||||
}
|
||||
if (targetItem) {
|
||||
targetItem->addArrowTo(this);
|
||||
}
|
||||
|
||||
if (startItem && targetItem)
|
||||
if (startItem && targetItem) {
|
||||
updatePath();
|
||||
}
|
||||
}
|
||||
|
||||
ArrowItem::~ArrowItem()
|
||||
|
|
@ -59,8 +62,9 @@ void ArrowItem::delArrow()
|
|||
|
||||
void ArrowItem::updatePath()
|
||||
{
|
||||
if (!targetItem)
|
||||
if (!targetItem) {
|
||||
return;
|
||||
}
|
||||
|
||||
QPointF endPoint = targetItem->mapToScene(
|
||||
QPointF(targetItem->boundingRect().width() / 2, targetItem->boundingRect().height() / 2));
|
||||
|
|
@ -75,8 +79,9 @@ void ArrowItem::updatePath(const QPointF &endPoint)
|
|||
headWidth / qPow(2, 0.5); // aka headWidth / sqrt (2) but this produces a compile error with MSVC++
|
||||
const double phi = 15;
|
||||
|
||||
if (!startItem)
|
||||
if (!startItem) {
|
||||
return;
|
||||
}
|
||||
|
||||
QPointF startPoint =
|
||||
startItem->mapToScene(QPointF(startItem->boundingRect().width() / 2, startItem->boundingRect().height() / 2));
|
||||
|
|
@ -84,9 +89,9 @@ void ArrowItem::updatePath(const QPointF &endPoint)
|
|||
qreal lineLength = line.length();
|
||||
|
||||
prepareGeometryChange();
|
||||
if (lineLength < 30)
|
||||
if (lineLength < 30) {
|
||||
path = QPainterPath();
|
||||
else {
|
||||
} else {
|
||||
QPointF c(lineLength / 2, qTan(phi * M_PI / 180) * lineLength);
|
||||
|
||||
QPainterPath centerLine;
|
||||
|
|
@ -123,10 +128,11 @@ void ArrowItem::updatePath(const QPointF &endPoint)
|
|||
void ArrowItem::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
|
||||
{
|
||||
QColor paintColor(color);
|
||||
if (fullColor)
|
||||
if (fullColor) {
|
||||
paintColor.setAlpha(200);
|
||||
else
|
||||
} else {
|
||||
paintColor.setAlpha(150);
|
||||
}
|
||||
painter->setBrush(paintColor);
|
||||
painter->drawPath(path);
|
||||
}
|
||||
|
|
@ -168,8 +174,9 @@ void ArrowDragItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|||
{
|
||||
// This ensures that if a mouse move event happens after a call to delArrow(),
|
||||
// the event will be discarded as it would create some stray pointers.
|
||||
if (targetLocked || !startItem)
|
||||
if (targetLocked || !startItem) {
|
||||
return;
|
||||
}
|
||||
|
||||
QPointF endPos = event->scenePos();
|
||||
|
||||
|
|
@ -213,8 +220,9 @@ void ArrowDragItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|||
|
||||
void ArrowDragItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (!startItem)
|
||||
if (!startItem) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (targetItem && (targetItem != startItem)) {
|
||||
CardZoneLogic *startZone = static_cast<CardItem *>(startItem)->getZone();
|
||||
|
|
@ -246,10 +254,11 @@ void ArrowDragItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|||
bool playToStack = SettingsCache::instance().getPlayToStack();
|
||||
if (ci && ((!playToStack && ci->getUiAttributes().tableRow == 3) ||
|
||||
(playToStack && ci->getUiAttributes().tableRow != 0 &&
|
||||
startCard->getZone()->getName() != ZoneNames::STACK)))
|
||||
startCard->getZone()->getName() != ZoneNames::STACK))) {
|
||||
cmd.set_start_zone(ZoneNames::STACK);
|
||||
else
|
||||
} else {
|
||||
cmd.set_start_zone(playToStack ? ZoneNames::STACK : ZoneNames::TABLE);
|
||||
}
|
||||
}
|
||||
|
||||
if (deleteInPhase != 0) {
|
||||
|
|
@ -277,8 +286,9 @@ void ArrowAttachItem::addChildArrow(ArrowAttachItem *childArrow)
|
|||
|
||||
void ArrowAttachItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (targetLocked || !startItem)
|
||||
if (targetLocked || !startItem) {
|
||||
return;
|
||||
}
|
||||
|
||||
QPointF endPos = event->scenePos();
|
||||
|
||||
|
|
@ -343,8 +353,9 @@ void ArrowAttachItem::attachCards(CardItem *startCard, const CardItem *targetCar
|
|||
|
||||
void ArrowAttachItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (!startItem)
|
||||
if (!startItem) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Attaching could move startItem under the current cursor position, causing all children to retarget to it right
|
||||
// before they are processed. Prevent that.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue