forked from qt-creator/qt-creator
Utils: Make Layouting::Title even less special
This goes a bit in the direction of property settigs for arbitrary layout items. Change-Id: I98500e213e3b22cc99038a1bcf688183588be248 Reviewed-by: Eike Ziller <eike.ziller@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
@@ -460,13 +460,6 @@ LayoutBuilder::Space::Space(int space)
|
||||
specialValue = space;
|
||||
}
|
||||
|
||||
LayoutBuilder::Title::Title(const QString &title, BoolAspect *check)
|
||||
{
|
||||
specialType = SpecialType::Title;
|
||||
specialValue = title;
|
||||
aspect = check;
|
||||
}
|
||||
|
||||
LayoutBuilder::Span::Span(int span_, const LayoutItem &item)
|
||||
{
|
||||
LayoutBuilder::LayoutItem::operator=(item);
|
||||
@@ -482,24 +475,39 @@ LayoutBuilder::AlignAsFormLabel::AlignAsFormLabel(const LayoutItem &item)
|
||||
namespace Layouting {
|
||||
|
||||
Group::Group(const LayoutBuilder &innerLayout)
|
||||
: Group(Title({}), innerLayout)
|
||||
: Group({}, innerLayout)
|
||||
{}
|
||||
|
||||
Group::Group(const LayoutBuilder::Title &title, const LayoutBuilder &innerLayout)
|
||||
Group::Group(const LayoutBuilder::Setters &setters, const LayoutBuilder &innerLayout)
|
||||
{
|
||||
auto box = new QGroupBox;
|
||||
|
||||
box->setTitle(title.specialValue.toString());
|
||||
box->setObjectName(title.specialValue.toString());
|
||||
if (auto check = qobject_cast<BoolAspect *>(title.aspect)) {
|
||||
box->setCheckable(true);
|
||||
box->setChecked(check->value());
|
||||
check->setHandlesGroup(box);
|
||||
}
|
||||
|
||||
innerLayout.attachTo(box, true);
|
||||
for (const LayoutBuilder::Setter &func : setters)
|
||||
func(box);
|
||||
widget = box;
|
||||
}
|
||||
|
||||
LayoutBuilder::Setter Title(const QString &title, BoolAspect *checker)
|
||||
{
|
||||
return Layouting::title(title, checker);
|
||||
}
|
||||
|
||||
LayoutBuilder::Setter title(const QString &title, BoolAspect *checker)
|
||||
{
|
||||
return [title, checker](QObject *target) {
|
||||
if (auto groupBox = qobject_cast<QGroupBox *>(target)) {
|
||||
groupBox->setTitle(title);
|
||||
groupBox->setObjectName(title);
|
||||
if (checker) {
|
||||
groupBox->setCheckable(true);
|
||||
groupBox->setChecked(checker->value());
|
||||
checker->setHandlesGroup(groupBox);
|
||||
}
|
||||
} else {
|
||||
QTC_CHECK(false);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
} // Layouting
|
||||
} // Utils
|
||||
|
||||
@@ -63,7 +63,6 @@ public:
|
||||
Space,
|
||||
Stretch,
|
||||
Break,
|
||||
Title,
|
||||
};
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT LayoutItem
|
||||
@@ -143,10 +142,13 @@ public:
|
||||
Break();
|
||||
};
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT Title : public LayoutItem
|
||||
using Setter = std::function<void(QObject *target)>;
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT Setters : public std::vector<Setter>
|
||||
{
|
||||
public:
|
||||
explicit Title(const QString &title, BoolAspect *check = nullptr);
|
||||
using std::vector<Setter>::vector;
|
||||
Setters(const Setter &setter) { push_back(setter); }
|
||||
};
|
||||
|
||||
protected:
|
||||
@@ -172,11 +174,17 @@ private:
|
||||
|
||||
namespace Layouting {
|
||||
|
||||
QTCREATOR_UTILS_EXPORT LayoutBuilder::Setter title(const QString &title,
|
||||
BoolAspect *checker = nullptr);
|
||||
|
||||
QTCREATOR_UTILS_EXPORT LayoutBuilder::Setter Title(const QString &title,
|
||||
BoolAspect *checker = nullptr); // FIXME: Remove
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT Group : public LayoutBuilder::LayoutItem
|
||||
{
|
||||
public:
|
||||
explicit Group(const LayoutBuilder &innerLayout);
|
||||
Group(const LayoutBuilder::Title &title, const LayoutBuilder &innerLayout);
|
||||
Group(const LayoutBuilder::Setters &setters, const LayoutBuilder &innerLayout);
|
||||
};
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT Column : public LayoutBuilder
|
||||
@@ -212,7 +220,6 @@ using Space = LayoutBuilder::Space;
|
||||
using Span = LayoutBuilder::Span;
|
||||
using AlignAsFormLabel = LayoutBuilder::AlignAsFormLabel;
|
||||
using Break = LayoutBuilder::Break;
|
||||
using Title = LayoutBuilder::Title;
|
||||
|
||||
}
|
||||
} // namespace Utils
|
||||
|
||||
@@ -59,7 +59,7 @@ public:
|
||||
DebuggerSettings &s = *debuggerSettings();
|
||||
|
||||
Group general {
|
||||
Title { Tr::tr("General") },
|
||||
title(Tr::tr("General")),
|
||||
Column {
|
||||
Row { s.gdbWatchdogTimeout, Stretch() },
|
||||
s.skipKnownFrames,
|
||||
@@ -77,11 +77,11 @@ public:
|
||||
|
||||
Column commands {
|
||||
Group {
|
||||
Title { Tr::tr("Additional Startup Commands") },
|
||||
title(Tr::tr("Additional Startup Commands")),
|
||||
Column { s.gdbStartupCommands }
|
||||
},
|
||||
Group {
|
||||
Title { Tr::tr("Additional Attach Commands") },
|
||||
title(Tr::tr("Additional Attach Commands")),
|
||||
Column { s.gdbPostAttachCommands },
|
||||
},
|
||||
Stretch()
|
||||
|
||||
Reference in New Issue
Block a user