aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhjk <[email protected]>2025-07-04 14:25:37 +0200
committerhjk <[email protected]>2025-07-07 07:16:09 +0000
commit7705bdf54b3a6319067e4817aa9348b56a9d9970 (patch)
treef37326dbb731f336a933a05c8e4fa12f7a732ac3
parent06960a450b7b8c6eb8b4b145402bfb716ed971c0 (diff)
Utils: Change 'If' syntax in LayoutBuilderHEADmaster
Instead of If (cond, { then-stuff } [, { else-stuff }) use If (cond) >> Then { then-stuff } >> Else { else-stuff } It's a bit more verbose, but easier to reason about, and more similar to what TaskTree does with When >> Do etc. Change-Id: I0ae69ea566ee42a4e75bcdfc3173e744b812785e Reviewed-by: Jarek Kobus <[email protected]>
-rw-r--r--src/libs/utils/aspects.cpp8
-rw-r--r--src/libs/utils/layoutbuilder.cpp25
-rw-r--r--src/libs/utils/layoutbuilder.h34
-rw-r--r--src/libs/utils/passworddialog.cpp18
-rw-r--r--src/plugins/coreplugin/progressmanager/progressmanager.cpp4
-rw-r--r--src/plugins/docker/dockerdevicewidget.cpp4
-rw-r--r--src/plugins/fakevim/fakevimactions.cpp4
-rw-r--r--src/plugins/learning/qtacademywelcomepage.cpp34
-rw-r--r--src/plugins/projectexplorer/projectexplorersettings.cpp4
9 files changed, 87 insertions, 48 deletions
diff --git a/src/libs/utils/aspects.cpp b/src/libs/utils/aspects.cpp
index 21687ccab85..8c4aff8c7d5 100644
--- a/src/libs/utils/aspects.cpp
+++ b/src/libs/utils/aspects.cpp
@@ -2898,13 +2898,13 @@ void StringListAspect::addToLayoutImpl(Layout &parent)
createLabel(),
Row {
editor,
- If { d->allowAdding || d->allowRemoving, {
+ If (d->allowAdding || d->allowRemoving) >> Then {
Column {
- If { d->allowAdding, {add}, {}},
- If { d->allowRemoving, {remove}, {}},
+ If (d->allowAdding) >> Then {add},
+ If (d->allowRemoving) >> Then {remove},
st,
}
- }, {}},
+ },
}
} // clang-format on
);
diff --git a/src/libs/utils/layoutbuilder.cpp b/src/libs/utils/layoutbuilder.cpp
index 988e0ea1a98..3ab50dd07d4 100644
--- a/src/libs/utils/layoutbuilder.cpp
+++ b/src/libs/utils/layoutbuilder.cpp
@@ -1336,16 +1336,27 @@ void Canvas::setPaintFunction(const CanvasWidget::PaintFunction &paintFunction)
// Special If
-If::If(
- bool condition,
- const std::initializer_list<Layout::I> ifcase,
- const std::initializer_list<Layout::I> elsecase)
- : used(condition ? ifcase : elsecase)
+If::If(bool condition)
+ : condition(condition)
{}
-void addToLayout(Layout *layout, const If &inner)
+If::If(bool condition, const Items &list)
+ : condition(condition), list(list)
+{}
+
+If operator>>(const If &if_, const Then &then_)
+{
+ return If(if_.condition, if_.condition ? then_.list : If::Items());
+}
+
+If operator>>(const If &if_, const Else &else_)
+{
+ return If(if_.condition, if_.condition ? If::Items() : else_.list);
+}
+
+void addToLayout(Layout *layout, const If &if_)
{
- for (const Layout::I &item : inner.used)
+ for (const Layout::I &item : if_.list)
item.apply(layout);
}
diff --git a/src/libs/utils/layoutbuilder.h b/src/libs/utils/layoutbuilder.h
index 31a788bb7ee..566a6610f51 100644
--- a/src/libs/utils/layoutbuilder.h
+++ b/src/libs/utils/layoutbuilder.h
@@ -546,14 +546,40 @@ public:
// Special
+class QTCREATOR_UTILS_EXPORT Then
+{
+public:
+ Then(std::initializer_list<Layout::I> list) : list(list) {}
+
+ const QList<Layout::I> list;
+};
+
+class QTCREATOR_UTILS_EXPORT Else
+{
+public:
+ Else(std::initializer_list<Layout::I> list) : list(list) {}
+
+ const QList<Layout::I> list;
+};
+
class QTCREATOR_UTILS_EXPORT If
{
public:
- If(bool condition,
- const std::initializer_list<Layout::I> ifcase,
- const std::initializer_list<Layout::I> elsecase = {});
+ explicit If(bool condition);
+
+private:
+ friend class Then;
+ friend class Else;
+ friend void addToLayout(Layout *layout, const If &if_);
+
+ using Items = QList<Layout::I>;
+ If(bool condition, const Items &list);
+
+ friend QTCREATOR_UTILS_EXPORT If operator>>(const If &if_, const Then &then_);
+ friend QTCREATOR_UTILS_EXPORT If operator>>(const If &if_, const Else &else_);
- const std::initializer_list<Layout::I> used;
+ const bool condition;
+ const QList<Layout::I> list;
};
//
diff --git a/src/libs/utils/passworddialog.cpp b/src/libs/utils/passworddialog.cpp
index 61bb58cd304..e33d1e828ed 100644
--- a/src/libs/utils/passworddialog.cpp
+++ b/src/libs/utils/passworddialog.cpp
@@ -113,17 +113,15 @@ PasswordDialog::PasswordDialog(const QString &title,
// clang-format off
Column {
prompt,
- If {
- withUsername, {
- Form {
- Tr::tr("User:"), d->m_userNameLineEdit, br,
- Tr::tr("Password:"), Row { d->m_passwordLineEdit, showPasswordButton }, br,
- }
- }, {
- Row {
- d->m_passwordLineEdit, showPasswordButton,
- },
+ If (withUsername) >> Then {
+ Form {
+ Tr::tr("User:"), d->m_userNameLineEdit, br,
+ Tr::tr("Password:"), Row { d->m_passwordLineEdit, showPasswordButton }, br,
}
+ } >> Else {
+ Row {
+ d->m_passwordLineEdit, showPasswordButton,
+ },
},
Row {
d->m_checkBox,
diff --git a/src/plugins/coreplugin/progressmanager/progressmanager.cpp b/src/plugins/coreplugin/progressmanager/progressmanager.cpp
index b92f0e49ba3..df8f7b529fb 100644
--- a/src/plugins/coreplugin/progressmanager/progressmanager.cpp
+++ b/src/plugins/coreplugin/progressmanager/progressmanager.cpp
@@ -194,7 +194,9 @@ InfoWidget::InfoWidget(const InfoBarEntry &info, QPointer<InfoBar> infoBar)
Row {
Label { bindTo(&titleLabel), text(info.title()) },
st,
- If { info.hasCancelButton(), { ToolButton { bindTo(&infoWidgetCloseButton) } } }
+ If (info.hasCancelButton()) >> Then {
+ ToolButton { bindTo(&infoWidgetCloseButton) }
+ }
},
Row {
Label { wordWrap(true), text(info.text()) }
diff --git a/src/plugins/docker/dockerdevicewidget.cpp b/src/plugins/docker/dockerdevicewidget.cpp
index 0a18f58a24c..5140e933b05 100644
--- a/src/plugins/docker/dockerdevicewidget.cpp
+++ b/src/plugins/docker/dockerdevicewidget.cpp
@@ -186,7 +186,9 @@ DockerDeviceWidget::DockerDeviceWidget(const IDevice::Ptr &device)
dockerDevice->mounts,
}, br,
dockerDevice->portMappings, br,
- If { dockerDevice->isAutoDetected(), {}, {detectionControls} },
+ If (!dockerDevice->isAutoDetected()) >> Then {
+ detectionControls
+ },
}, br,
Tr::tr("Command line:"), createLineLabel, br,
}.attachTo(this);
diff --git a/src/plugins/fakevim/fakevimactions.cpp b/src/plugins/fakevim/fakevimactions.cpp
index de43e2529e5..67fe11d1bd8 100644
--- a/src/plugins/fakevim/fakevimactions.cpp
+++ b/src/plugins/fakevim/fakevimactions.cpp
@@ -140,7 +140,9 @@ FakeVimSettings::FakeVimSettings()
startOfLine,
passKeys,
blinkingCursor,
- If { HostOsInfo::isWindowsHost(), { systemEncoding } }
+ If (HostOsInfo::isWindowsHost()) >> Then {
+ systemEncoding
+ }
},
Column {
incSearch,
diff --git a/src/plugins/learning/qtacademywelcomepage.cpp b/src/plugins/learning/qtacademywelcomepage.cpp
index 34f6076a0f7..9fcaf33179e 100644
--- a/src/plugins/learning/qtacademywelcomepage.cpp
+++ b/src/plugins/learning/qtacademywelcomepage.cpp
@@ -347,23 +347,21 @@ static Layouting::Grid createDetailWidget(const CourseItem *course)
Align(Qt::AlignCenter, blackLabel(difficultyLevelTr(course))),
}
},
- If(course->reviews.has_value(),
- {
- Row {
- Label {
- text(QString("%1")
- .arg(qFloor((reviews.value*5.0) * 10.0) / 10.0, 0, 'g', 2)),
- },
- Canvas {
- fixedSize(QSize{100, 20}),
- paint(paintRating),
- },
- Label {
- text(QString("(%1)").arg(reviews.numReviews)),
- },
- }
+ If (course->reviews.has_value()) >> Then {
+ Row {
+ Label {
+ text(QString("%1")
+ .arg(qFloor((reviews.value*5.0) * 10.0) / 10.0, 0, 'g', 2)),
+ },
+ Canvas {
+ fixedSize(QSize{100, 20}),
+ paint(paintRating),
+ },
+ Label {
+ text(QString("(%1)").arg(reviews.numReviews)),
+ },
}
- ),
+ },
st
},
Row {
@@ -392,7 +390,7 @@ static Layouting::Grid createDetailWidget(const CourseItem *course)
st,
}
},
- If (hasObjectives, {
+ If (hasObjectives) >> Then {
Column {
heading(Tr::tr("Objectives")),
Label {
@@ -401,7 +399,7 @@ static Layouting::Grid createDetailWidget(const CourseItem *course)
},
st
}
- }),
+ },
};
// clang-format on
}
diff --git a/src/plugins/projectexplorer/projectexplorersettings.cpp b/src/plugins/projectexplorer/projectexplorersettings.cpp
index 5e7e6894e6c..b9ee81ec6d2 100644
--- a/src/plugins/projectexplorer/projectexplorersettings.cpp
+++ b/src/plugins/projectexplorer/projectexplorersettings.cpp
@@ -290,7 +290,7 @@ ProjectExplorerSettingsWidget::ProjectExplorerSettingsWidget()
s.terminalMode, br,
s.reaperTimeoutInSeconds, st, br,
},
- If { HostOsInfo::isWindowsHost(), {
+ If (HostOsInfo::isWindowsHost()) >> Then {
Label {
text("<i>jom</i> is a drop-in replacement for <i>nmake</i> which "
"distributes the compilation process to multiple CPU cores. "
@@ -301,7 +301,7 @@ ProjectExplorerSettingsWidget::ProjectExplorerSettingsWidget()
wordWrap(true)
},
s.useJom,
- }}
+ }
},
},
st,