forked from qt-creator/qt-creator
Utils: Make LayoutBuilder setter setup less repetitive
Change-Id: I9113f7a97566c21cf83dcb95ce8e75e9707360b4 Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
@@ -339,17 +339,17 @@ void Layout::span(int cols, int rows)
|
|||||||
pendingItems.back().spanRows = rows;
|
pendingItems.back().spanRows = rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Layout::noMargin()
|
void Layout::setNoMargins()
|
||||||
{
|
{
|
||||||
customMargin({});
|
setContentMargins({});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Layout::normalMargin()
|
void Layout::setNormalMargins()
|
||||||
{
|
{
|
||||||
customMargin({9, 9, 9, 9});
|
setContentMargins({9, 9, 9, 9});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Layout::customMargin(const QMargins &margin)
|
void Layout::setContentMargins(const QMargins &margin)
|
||||||
{
|
{
|
||||||
access(this)->setContentsMargins(margin);
|
access(this)->setContentsMargins(margin);
|
||||||
}
|
}
|
||||||
@@ -467,11 +467,11 @@ void addToLayout(Layout *layout, const QString &inner)
|
|||||||
layout->addLayoutItem(item);
|
layout->addLayoutItem(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
void empty(Layout *iface)
|
void empty(Layout *layout)
|
||||||
{
|
{
|
||||||
LayoutItem item;
|
LayoutItem item;
|
||||||
item.empty = true;
|
item.empty = true;
|
||||||
iface->addLayoutItem(item);
|
layout->addLayoutItem(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
void hr(Layout *layout)
|
void hr(Layout *layout)
|
||||||
@@ -479,26 +479,26 @@ void hr(Layout *layout)
|
|||||||
layout->addLayoutItem(createHr());
|
layout->addLayoutItem(createHr());
|
||||||
}
|
}
|
||||||
|
|
||||||
void br(Layout *iface)
|
void br(Layout *layout)
|
||||||
{
|
{
|
||||||
iface->flush();
|
layout->flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
void st(Layout *iface)
|
void st(Layout *layout)
|
||||||
{
|
{
|
||||||
LayoutItem item;
|
LayoutItem item;
|
||||||
item.stretch = 1;
|
item.stretch = 1;
|
||||||
iface->addLayoutItem(item);
|
layout->addLayoutItem(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
void noMargin(Layout *iface)
|
void noMargin(Layout *layout)
|
||||||
{
|
{
|
||||||
iface->noMargin();
|
layout->setNoMargins();
|
||||||
}
|
}
|
||||||
|
|
||||||
void normalMargin(Layout *iface)
|
void normalMargin(Layout *layout)
|
||||||
{
|
{
|
||||||
iface->normalMargin();
|
layout->setNormalMargins();
|
||||||
}
|
}
|
||||||
|
|
||||||
QFormLayout *Layout::asForm()
|
QFormLayout *Layout::asForm()
|
||||||
@@ -612,9 +612,9 @@ void Layout::flush_() const
|
|||||||
const_cast<Layout *>(this)->flush();
|
const_cast<Layout *>(this)->flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
void withFormAlignment(Layout *iface)
|
void withFormAlignment(Layout *layout)
|
||||||
{
|
{
|
||||||
iface->useFormAlignment = true;
|
layout->useFormAlignment = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Flow
|
// Flow
|
||||||
@@ -672,7 +672,7 @@ Form::Form(std::initializer_list<I> ps)
|
|||||||
flush();
|
flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Layout::fieldGrowthPolicy(int policy)
|
void Layout::setFieldGrowthPolicy(int policy)
|
||||||
{
|
{
|
||||||
if (auto lt = asForm())
|
if (auto lt = asForm())
|
||||||
lt->setFieldGrowthPolicy(QFormLayout::FieldGrowthPolicy(policy));
|
lt->setFieldGrowthPolicy(QFormLayout::FieldGrowthPolicy(policy));
|
||||||
@@ -699,7 +699,7 @@ Widget::Widget(std::initializer_list<I> ps)
|
|||||||
apply(this, ps);
|
apply(this, ps);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::resize(int w, int h)
|
void Widget::setSize(int w, int h)
|
||||||
{
|
{
|
||||||
access(this)->resize(w, h);
|
access(this)->resize(w, h);
|
||||||
}
|
}
|
||||||
@@ -724,19 +724,19 @@ void Widget::show()
|
|||||||
access(this)->show();
|
access(this)->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::noMargin(int)
|
void Widget::setNoMargins(int)
|
||||||
{
|
{
|
||||||
customMargin({});
|
setContentMargins({});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::normalMargin(int)
|
void Widget::setNormalMargins(int)
|
||||||
{
|
{
|
||||||
customMargin({9, 9, 9, 9});
|
setContentMargins({9, 9, 9, 9});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::customMargin(const QMargins &margin)
|
void Widget::setContentMargins(const QMargins &margins)
|
||||||
{
|
{
|
||||||
access(this)->setContentsMargins(margin);
|
access(this)->setContentsMargins(margins);
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget *Widget::emerge() const
|
QWidget *Widget::emerge() const
|
||||||
@@ -979,7 +979,7 @@ void addToLayout(Layout *layout, const Span &inner)
|
|||||||
|
|
||||||
LayoutModifier spacing(int space)
|
LayoutModifier spacing(int space)
|
||||||
{
|
{
|
||||||
return [space](Layout *iface) { iface->setSpacing(space); };
|
return [space](Layout *layout) { layout->setSpacing(space); };
|
||||||
}
|
}
|
||||||
|
|
||||||
void addToLayout(Layout *layout, const Space &inner)
|
void addToLayout(Layout *layout, const Space &inner)
|
||||||
|
@@ -139,13 +139,16 @@ public:
|
|||||||
Layout(Implementation *w) { ptr = w; }
|
Layout(Implementation *w) { ptr = w; }
|
||||||
|
|
||||||
void span(int cols, int rows);
|
void span(int cols, int rows);
|
||||||
void noMargin();
|
|
||||||
void normalMargin();
|
void setNoMargins();
|
||||||
void customMargin(const QMargins &margin);
|
void setNormalMargins();
|
||||||
|
void setContentMargins(const QMargins &margin);
|
||||||
void setColumnStretch(int cols, int rows);
|
void setColumnStretch(int cols, int rows);
|
||||||
void setSpacing(int space);
|
void setSpacing(int space);
|
||||||
|
void setFieldGrowthPolicy(int policy);
|
||||||
|
|
||||||
void attachTo(QWidget *);
|
void attachTo(QWidget *);
|
||||||
|
|
||||||
void addItem(I item);
|
void addItem(I item);
|
||||||
void addItems(std::initializer_list<I> items);
|
void addItems(std::initializer_list<I> items);
|
||||||
void addRow(std::initializer_list<I> items);
|
void addRow(std::initializer_list<I> items);
|
||||||
@@ -153,7 +156,6 @@ public:
|
|||||||
|
|
||||||
void flush();
|
void flush();
|
||||||
void flush_() const;
|
void flush_() const;
|
||||||
void fieldGrowthPolicy(int policy);
|
|
||||||
|
|
||||||
QWidget *emerge() const;
|
QWidget *emerge() const;
|
||||||
void show() const;
|
void show() const;
|
||||||
@@ -258,15 +260,15 @@ public:
|
|||||||
Widget(Implementation *w) { ptr = w; }
|
Widget(Implementation *w) { ptr = w; }
|
||||||
|
|
||||||
QWidget *emerge() const;
|
QWidget *emerge() const;
|
||||||
|
|
||||||
void show();
|
void show();
|
||||||
void resize(int, int);
|
|
||||||
void setLayout(const Layout &layout);
|
void setLayout(const Layout &layout);
|
||||||
|
void setSize(int, int);
|
||||||
void setWindowTitle(const QString &);
|
void setWindowTitle(const QString &);
|
||||||
void setToolTip(const QString &);
|
void setToolTip(const QString &);
|
||||||
void noMargin(int = 0);
|
void setNoMargins(int = 0);
|
||||||
void normalMargin(int = 0);
|
void setNormalMargins(int = 0);
|
||||||
void customMargin(const QMargins &margin);
|
void setContentMargins(const QMargins &);
|
||||||
};
|
};
|
||||||
|
|
||||||
class QTCREATOR_UTILS_EXPORT Label : public Widget
|
class QTCREATOR_UTILS_EXPORT Label : public Widget
|
||||||
@@ -439,69 +441,38 @@ void doit(Interface *x, IdId, auto p)
|
|||||||
|
|
||||||
// Setter dispatchers
|
// Setter dispatchers
|
||||||
|
|
||||||
class SizeId {};
|
#define QTCREATOR_SETTER(name, setter) \
|
||||||
auto size(auto w, auto h) { return IdAndArg{SizeId{}, std::pair{w, h}}; }
|
class name##_TAG {}; \
|
||||||
void doit(auto x, SizeId, auto p) { x->resize(p->first, p->second); }
|
inline auto name(auto p) { return IdAndArg{name##_TAG{}, p}; } \
|
||||||
|
inline void doit(auto x, name##_TAG, auto p) { x->setter(p); }
|
||||||
|
|
||||||
class TextId {};
|
#define QTCREATOR_SETTER2(name, setter) \
|
||||||
auto text(auto p) { return IdAndArg{TextId{}, p}; }
|
class name##_TAG {}; \
|
||||||
void doit(auto x, TextId, auto p) { x->setText(p); }
|
inline auto name(auto p1, auto p2) { return IdAndArg{name##_TAG{}, std::pair{p1, p2}}; } \
|
||||||
|
inline void doit(auto x, name##_TAG, auto p) { x->setter(p.first, p.second); }
|
||||||
|
|
||||||
class TitleId {};
|
#define QTCREATOR_TYPED_SETTER(name, setter, type) \
|
||||||
auto title(auto p) { return IdAndArg{TitleId{}, p}; }
|
class name##_TAG {}; \
|
||||||
void doit(auto x, TitleId, auto p) { x->setTitle(p); }
|
inline auto name(type p) { return IdAndArg{name##_TAG{}, p}; } \
|
||||||
|
inline void doit(auto x, name##_TAG, auto p) { x->setter(p); }
|
||||||
|
|
||||||
class TextFormatId {};
|
QTCREATOR_SETTER(fieldGrowthPolicy, setFieldGrowthPolicy);
|
||||||
auto textFormat(auto p) { return IdAndArg{TextFormatId{}, p}; }
|
QTCREATOR_SETTER(groupChecker, setGroupChecker);
|
||||||
void doit(auto x, TextFormatId, auto p) { x->setTextFormat(p); }
|
QTCREATOR_SETTER(openExternalLinks, setOpenExternalLinks);
|
||||||
|
QTCREATOR_SETTER2(size, setSize)
|
||||||
|
QTCREATOR_SETTER(text, setText)
|
||||||
|
QTCREATOR_SETTER(textFormat, setTextFormat);
|
||||||
|
QTCREATOR_SETTER(textInteractionFlags, setTextInteractionFlags);
|
||||||
|
QTCREATOR_SETTER(title, setTitle)
|
||||||
|
QTCREATOR_SETTER(toolTip, setToolTip);
|
||||||
|
QTCREATOR_SETTER(windowTitle, setWindowTitle);
|
||||||
|
QTCREATOR_SETTER(wordWrap, setWordWrap);
|
||||||
|
QTCREATOR_SETTER2(columnStretch, setColumnStretch);
|
||||||
|
QTCREATOR_SETTER2(onClicked, onClicked);
|
||||||
|
QTCREATOR_SETTER2(onLinkHovered, onLinkHovered);
|
||||||
|
QTCREATOR_SETTER2(onTextChanged, onTextChanged);
|
||||||
|
|
||||||
class WordWrapId {};
|
QTCREATOR_TYPED_SETTER(customMargin, setContentMargins, const QMargins &);
|
||||||
auto wordWrap(auto p) { return IdAndArg{WordWrapId{}, p}; }
|
|
||||||
void doit(auto x, WordWrapId, auto p) { x->setWordWrap(p); }
|
|
||||||
|
|
||||||
class TextInteractionFlagId {};
|
|
||||||
auto textInteractionFlags(auto p) { return IdAndArg{TextInteractionFlagId{}, p}; }
|
|
||||||
void doit(auto x, TextInteractionFlagId, auto p) { x->setTextInteractionFlags(p); }
|
|
||||||
|
|
||||||
class OpenExternalLinksId {};
|
|
||||||
auto openExternalLinks(auto p) { return IdAndArg{OpenExternalLinksId{}, p}; }
|
|
||||||
void doit(auto x, OpenExternalLinksId, auto p) { x->setOpenExternalLinks(p); }
|
|
||||||
|
|
||||||
class OnLinkHoveredId {};
|
|
||||||
auto onLinkHovered(auto p, QObject *guard) { return IdAndArg{OnLinkHoveredId{}, std::pair{p, guard}}; }
|
|
||||||
void doit(auto x, OnLinkHoveredId, auto p) { x->onLinkHovered(p.first, p.second); }
|
|
||||||
|
|
||||||
class GroupCheckerId {};
|
|
||||||
auto groupChecker(auto p) { return IdAndArg{GroupCheckerId{}, p}; }
|
|
||||||
void doit(auto x, GroupCheckerId, auto p) { x->setGroupChecker(p); }
|
|
||||||
|
|
||||||
class ToolTipId {};
|
|
||||||
auto toolTip(auto p) { return IdAndArg{ToolTipId{}, p}; }
|
|
||||||
void doit(auto x, ToolTipId, auto p) { x->setToolTip(p); }
|
|
||||||
|
|
||||||
class WindowTitleId {};
|
|
||||||
auto windowTitle(auto p) { return IdAndArg{WindowTitleId{}, p}; }
|
|
||||||
void doit(auto x, WindowTitleId, auto p) { x->setWindowTitle(p); }
|
|
||||||
|
|
||||||
class OnTextChangedId {};
|
|
||||||
auto onTextChanged(auto p) { return IdAndArg{OnTextChangedId{}, p}; }
|
|
||||||
void doit(auto x, OnTextChangedId, auto p) { x->onTextChanged(p); }
|
|
||||||
|
|
||||||
class OnClickedId {};
|
|
||||||
auto onClicked(auto p, auto guard) { return IdAndArg{OnClickedId{}, std::pair{p, guard}}; }
|
|
||||||
void doit(auto x, OnClickedId, auto p) { x->onClicked(p.first, p.second); }
|
|
||||||
|
|
||||||
class CustomMarginId {};
|
|
||||||
inline auto customMargin(const QMargins &p) { return IdAndArg{CustomMarginId{}, p}; }
|
|
||||||
void doit(auto x, CustomMarginId, auto p) { x->customMargin(p); }
|
|
||||||
|
|
||||||
class FieldGrowthPolicyId {};
|
|
||||||
inline auto fieldGrowthPolicy(auto p) { return IdAndArg{FieldGrowthPolicyId{}, p}; }
|
|
||||||
void doit(auto x, FieldGrowthPolicyId, auto p) { x->fieldGrowthPolicy(p); }
|
|
||||||
|
|
||||||
class ColumnStretchId {};
|
|
||||||
inline auto columnStretch(int column, int stretch) { return IdAndArg{ColumnStretchId{}, std::pair{column, stretch}}; }
|
|
||||||
void doit(auto x, ColumnStretchId, auto p) { x->setColumnStretch(p.first, p.second); }
|
|
||||||
|
|
||||||
// Nesting dispatchers
|
// Nesting dispatchers
|
||||||
|
|
||||||
|
@@ -605,7 +605,7 @@ QWidget *CMakeBuildStep::createConfigWidget()
|
|||||||
if (!isCleanStep() && !m_buildPreset.isEmpty())
|
if (!isCleanStep() && !m_buildPreset.isEmpty())
|
||||||
createAndAddEnvironmentWidgets(builder);
|
createAndAddEnvironmentWidgets(builder);
|
||||||
|
|
||||||
builder.noMargin();
|
builder.setNoMargins();
|
||||||
auto widget = builder.emerge();
|
auto widget = builder.emerge();
|
||||||
|
|
||||||
updateDetails();
|
updateDetails();
|
||||||
|
@@ -72,7 +72,7 @@ DebuggerRunConfigurationAspect::DebuggerRunConfigurationAspect(Target *target)
|
|||||||
details->setState(DetailsWidget::Expanded);
|
details->setState(DetailsWidget::Expanded);
|
||||||
auto innerPane = new QWidget;
|
auto innerPane = new QWidget;
|
||||||
details->setWidget(innerPane);
|
details->setWidget(innerPane);
|
||||||
builder.noMargin();
|
builder.setNoMargins();
|
||||||
builder.attachTo(innerPane);
|
builder.attachTo(innerPane);
|
||||||
|
|
||||||
const auto setSummaryText = [this, details] {
|
const auto setSummaryText = [this, details] {
|
||||||
|
@@ -102,7 +102,7 @@ GitLabServerWidget::GitLabServerWidget(Mode m, QWidget *parent)
|
|||||||
m_token, br,
|
m_token, br,
|
||||||
m_port, br,
|
m_port, br,
|
||||||
m_secure,
|
m_secure,
|
||||||
m == Edit ? &Layout::normalMargin : &Layout::noMargin
|
m == Edit ? &Layout::setNormalMargins : &Layout::setNoMargins
|
||||||
},
|
},
|
||||||
}.attachTo(this);
|
}.attachTo(this);
|
||||||
}
|
}
|
||||||
|
@@ -306,8 +306,8 @@ void addGuiModule()
|
|||||||
}),
|
}),
|
||||||
"show",
|
"show",
|
||||||
&Widget::show,
|
&Widget::show,
|
||||||
"resize",
|
"setSize",
|
||||||
&Widget::resize,
|
&Widget::setSize,
|
||||||
sol::base_classes,
|
sol::base_classes,
|
||||||
sol::bases<Object, Thing>());
|
sol::bases<Object, Thing>());
|
||||||
|
|
||||||
|
@@ -326,7 +326,7 @@ NamedWidget *BuildConfiguration::createConfigWidget()
|
|||||||
}
|
}
|
||||||
|
|
||||||
Layouting::Form form;
|
Layouting::Form form;
|
||||||
form.noMargin();
|
form.setNoMargins();
|
||||||
for (BaseAspect *aspect : aspects()) {
|
for (BaseAspect *aspect : aspects()) {
|
||||||
if (aspect->isVisible()) {
|
if (aspect->isVisible()) {
|
||||||
form.addItem(aspect);
|
form.addItem(aspect);
|
||||||
|
@@ -113,7 +113,7 @@ QWidget *BuildStep::doCreateConfigWidget()
|
|||||||
QWidget *BuildStep::createConfigWidget()
|
QWidget *BuildStep::createConfigWidget()
|
||||||
{
|
{
|
||||||
Layouting::Form form;
|
Layouting::Form form;
|
||||||
form.noMargin();
|
form.setNoMargins();
|
||||||
for (BaseAspect *aspect : std::as_const(*this)) {
|
for (BaseAspect *aspect : std::as_const(*this)) {
|
||||||
if (aspect->isVisible()) {
|
if (aspect->isVisible()) {
|
||||||
form.addItem(aspect);
|
form.addItem(aspect);
|
||||||
|
@@ -313,7 +313,7 @@ QWidget *MakeStep::createConfigWidget()
|
|||||||
if (m_disablingForSubDirsSupported)
|
if (m_disablingForSubDirsSupported)
|
||||||
builder.addRow({m_disabledForSubdirsAspect});
|
builder.addRow({m_disabledForSubdirsAspect});
|
||||||
builder.addRow({m_buildTargetsAspect});
|
builder.addRow({m_buildTargetsAspect});
|
||||||
builder.noMargin();
|
builder.setNoMargins();
|
||||||
|
|
||||||
auto widget = builder.emerge();
|
auto widget = builder.emerge();
|
||||||
|
|
||||||
|
@@ -201,7 +201,7 @@ bool RunConfiguration::isEnabled(Utils::Id) const
|
|||||||
QWidget *RunConfiguration::createConfigurationWidget()
|
QWidget *RunConfiguration::createConfigurationWidget()
|
||||||
{
|
{
|
||||||
Layouting::Form form;
|
Layouting::Form form;
|
||||||
form.noMargin();
|
form.setNoMargins();
|
||||||
for (BaseAspect *aspect : std::as_const(*this)) {
|
for (BaseAspect *aspect : std::as_const(*this)) {
|
||||||
if (aspect->isVisible()) {
|
if (aspect->isVisible()) {
|
||||||
form.addItem(aspect);
|
form.addItem(aspect);
|
||||||
|
@@ -428,7 +428,7 @@ QWidget *QMakeStep::createConfigWidget()
|
|||||||
builder.addRow({userArguments});
|
builder.addRow({userArguments});
|
||||||
builder.addRow({effectiveCall});
|
builder.addRow({effectiveCall});
|
||||||
builder.addRow({abisLabel, abisListWidget});
|
builder.addRow({abisLabel, abisListWidget});
|
||||||
builder.noMargin();
|
builder.setNoMargins();
|
||||||
auto widget = builder.emerge();
|
auto widget = builder.emerge();
|
||||||
|
|
||||||
qmakeBuildConfigChanged();
|
qmakeBuildConfigChanged();
|
||||||
|
Reference in New Issue
Block a user