forked from qt-creator/qt-creator
Utils: Make the second parameter to LayoutBuilder::attach() an enum
More explicit and more potential options (e.g. "treat grid as form") than a bool. Change-Id: I89413efe30410160c38b0e524ba64288dde2332e Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -137,12 +137,6 @@ QLayout *LayoutBuilder::createLayout() const
|
|||||||
return layout;
|
return layout;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setMargins(bool on, QLayout *layout)
|
|
||||||
{
|
|
||||||
if (!on)
|
|
||||||
layout->setContentsMargins(0, 0, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static QWidget *widgetForItem(QLayoutItem *item)
|
static QWidget *widgetForItem(QLayoutItem *item)
|
||||||
{
|
{
|
||||||
if (QWidget *w = item->widget())
|
if (QWidget *w = item->widget())
|
||||||
@@ -384,13 +378,14 @@ LayoutBuilder &LayoutBuilder::addItem(const LayoutItem &item)
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayoutBuilder::doLayout(QWidget *parent, bool withMargins) const
|
void LayoutBuilder::doLayout(QWidget *parent, Layouting::AttachType attachType) const
|
||||||
{
|
{
|
||||||
QLayout *layout = createLayout();
|
QLayout *layout = createLayout();
|
||||||
parent->setLayout(layout);
|
parent->setLayout(layout);
|
||||||
|
|
||||||
doLayoutHelper(layout, m_items);
|
doLayoutHelper(layout, m_items);
|
||||||
setMargins(withMargins, layout);
|
if (attachType == Layouting::WithoutMargins)
|
||||||
|
layout->setContentsMargins(0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -408,15 +403,15 @@ LayoutBuilder &LayoutBuilder::addItems(const LayoutItems &items)
|
|||||||
|
|
||||||
This operation can only be performed once per LayoutBuilder instance.
|
This operation can only be performed once per LayoutBuilder instance.
|
||||||
*/
|
*/
|
||||||
void LayoutBuilder::attachTo(QWidget *w, bool withMargins) const
|
void LayoutBuilder::attachTo(QWidget *w, Layouting::AttachType attachType) const
|
||||||
{
|
{
|
||||||
doLayout(w, withMargins);
|
doLayout(w, attachType);
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget *LayoutBuilder::emerge(bool withMargins)
|
QWidget *LayoutBuilder::emerge(Layouting::AttachType attachType)
|
||||||
{
|
{
|
||||||
auto w = new QWidget;
|
auto w = new QWidget;
|
||||||
doLayout(w, withMargins);
|
doLayout(w, attachType);
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -481,7 +476,7 @@ Group::Group(const LayoutBuilder &innerLayout)
|
|||||||
Group::Group(const LayoutBuilder::Setters &setters, const LayoutBuilder &innerLayout)
|
Group::Group(const LayoutBuilder::Setters &setters, const LayoutBuilder &innerLayout)
|
||||||
{
|
{
|
||||||
widget = new QGroupBox;
|
widget = new QGroupBox;
|
||||||
innerLayout.attachTo(widget, true);
|
innerLayout.attachTo(widget, AttachType::WithMargins);
|
||||||
for (const LayoutBuilder::Setter &func : setters)
|
for (const LayoutBuilder::Setter &func : setters)
|
||||||
func(widget);
|
func(widget);
|
||||||
}
|
}
|
||||||
|
@@ -43,6 +43,15 @@ namespace Utils {
|
|||||||
class BaseAspect;
|
class BaseAspect;
|
||||||
class BoolAspect;
|
class BoolAspect;
|
||||||
|
|
||||||
|
namespace Layouting {
|
||||||
|
|
||||||
|
enum AttachType {
|
||||||
|
WithMargins,
|
||||||
|
WithoutMargins,
|
||||||
|
};
|
||||||
|
|
||||||
|
} // Layouting
|
||||||
|
|
||||||
class QTCREATOR_UTILS_EXPORT LayoutBuilder
|
class QTCREATOR_UTILS_EXPORT LayoutBuilder
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -111,8 +120,8 @@ public:
|
|||||||
|
|
||||||
LayoutType layoutType() const { return m_layoutType; }
|
LayoutType layoutType() const { return m_layoutType; }
|
||||||
|
|
||||||
void attachTo(QWidget *w, bool withMargins = true) const;
|
void attachTo(QWidget *w, Layouting::AttachType attachType = Layouting::WithMargins) const;
|
||||||
QWidget *emerge(bool withMargins = true);
|
QWidget *emerge(Layouting::AttachType attachType = Layouting::WithMargins);
|
||||||
|
|
||||||
class QTCREATOR_UTILS_EXPORT Space : public LayoutItem
|
class QTCREATOR_UTILS_EXPORT Space : public LayoutItem
|
||||||
{
|
{
|
||||||
@@ -157,7 +166,7 @@ protected:
|
|||||||
explicit LayoutBuilder(); // Adds to existing layout.
|
explicit LayoutBuilder(); // Adds to existing layout.
|
||||||
|
|
||||||
QLayout *createLayout() const;
|
QLayout *createLayout() const;
|
||||||
void doLayout(QWidget *parent, bool withMargins) const;
|
void doLayout(QWidget *parent, Layouting::AttachType attachType) const;
|
||||||
|
|
||||||
LayoutItems m_items;
|
LayoutItems m_items;
|
||||||
LayoutType m_layoutType;
|
LayoutType m_layoutType;
|
||||||
|
@@ -54,7 +54,7 @@ ConfigurationPanel::ConfigurationPanel(QWidget *parent)
|
|||||||
m_edit,
|
m_edit,
|
||||||
m_remove,
|
m_remove,
|
||||||
add
|
add
|
||||||
}.attachTo(this, false);
|
}.attachTo(this, WithoutMargins);
|
||||||
|
|
||||||
connect(add, &QPushButton::clicked, this, &ConfigurationPanel::add);
|
connect(add, &QPushButton::clicked, this, &ConfigurationPanel::add);
|
||||||
connect(m_edit, &QPushButton::clicked, this, &ConfigurationPanel::edit);
|
connect(m_edit, &QPushButton::clicked, this, &ConfigurationPanel::edit);
|
||||||
|
@@ -105,7 +105,7 @@ ClangToolsProjectSettingsWidget::ClangToolsProjectSettingsWidget(ProjectExplorer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.attachTo(this, false);
|
}.attachTo(this, WithoutMargins);
|
||||||
|
|
||||||
setUseGlobalSettings(m_projectSettings->useGlobalSettings());
|
setUseGlobalSettings(m_projectSettings->useGlobalSettings());
|
||||||
onGlobalCustomChanged();
|
onGlobalCustomChanged();
|
||||||
|
@@ -363,7 +363,7 @@ CMakeBuildSettingsWidget::CMakeBuildSettingsWidget(CMakeBuildSystem *bs) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.setSpacing(0)
|
}.setSpacing(0)
|
||||||
}.attachTo(details, false);
|
}.attachTo(details, WithoutMargins);
|
||||||
|
|
||||||
updateAdvancedCheckBox();
|
updateAdvancedCheckBox();
|
||||||
setError(m_buildSystem->error());
|
setError(m_buildSystem->error());
|
||||||
|
@@ -181,7 +181,7 @@ DebuggerRunConfigurationAspect::DebuggerRunConfigurationAspect(Target *target)
|
|||||||
static const QByteArray env = qgetenv("QTC_DEBUGGER_MULTIPROCESS");
|
static const QByteArray env = qgetenv("QTC_DEBUGGER_MULTIPROCESS");
|
||||||
if (env.toInt())
|
if (env.toInt())
|
||||||
builder.addRow(m_multiProcessAspect);
|
builder.addRow(m_multiProcessAspect);
|
||||||
return builder.emerge(false);
|
return builder.emerge(Layouting::WithoutMargins);
|
||||||
});
|
});
|
||||||
|
|
||||||
addDataExtractor(this, &DebuggerRunConfigurationAspect::useCppDebugger, &Data::useCppDebugger);
|
addDataExtractor(this, &DebuggerRunConfigurationAspect::useCppDebugger, &Data::useCppDebugger);
|
||||||
|
@@ -450,7 +450,7 @@ void FakeVimOptionPage::layoutPage(QWidget *widget)
|
|||||||
Row { copyTextEditorSettings, setQtStyle, setPlainStyle, st },
|
Row { copyTextEditorSettings, setQtStyle, setPlainStyle, st },
|
||||||
st
|
st
|
||||||
|
|
||||||
}.attachTo(widget, true);
|
}.attachTo(widget);
|
||||||
|
|
||||||
s.vimRcPath.setEnabler(&s.readVimRc);
|
s.vimRcPath.setEnabler(&s.readVimRc);
|
||||||
|
|
||||||
|
@@ -45,6 +45,8 @@
|
|||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
|
|
||||||
|
using namespace Utils;
|
||||||
|
|
||||||
namespace GitLab {
|
namespace GitLab {
|
||||||
|
|
||||||
static bool hostValid(const QString &host)
|
static bool hostValid(const QString &host)
|
||||||
@@ -92,7 +94,7 @@ GitLabServerWidget::GitLabServerWidget(Mode m, QWidget *parent)
|
|||||||
m_secure.setDefaultValue(true);
|
m_secure.setDefaultValue(true);
|
||||||
m_secure.setEnabled(m == Edit);
|
m_secure.setEnabled(m == Edit);
|
||||||
|
|
||||||
using namespace Utils::Layouting;
|
using namespace Layouting;
|
||||||
|
|
||||||
Row {
|
Row {
|
||||||
Form {
|
Form {
|
||||||
@@ -102,7 +104,7 @@ GitLabServerWidget::GitLabServerWidget(Mode m, QWidget *parent)
|
|||||||
m_port,
|
m_port,
|
||||||
m_secure
|
m_secure
|
||||||
},
|
},
|
||||||
}.attachTo(this, m == Edit);
|
}.attachTo(this, m == Edit ? WithMargins : WithoutMargins);
|
||||||
}
|
}
|
||||||
|
|
||||||
GitLabServer GitLabServerWidget::gitLabServer() const
|
GitLabServer GitLabServerWidget::gitLabServer() const
|
||||||
|
@@ -112,7 +112,7 @@ QWidget *NimbleTaskStep::createConfigWidget()
|
|||||||
auto widget = Form {
|
auto widget = Form {
|
||||||
m_taskArgs,
|
m_taskArgs,
|
||||||
tr("Tasks:"), taskList
|
tr("Tasks:"), taskList
|
||||||
}.emerge(false);
|
}.emerge(WithoutMargins);
|
||||||
|
|
||||||
auto buildSystem = dynamic_cast<NimbleBuildSystem *>(this->buildSystem());
|
auto buildSystem = dynamic_cast<NimbleBuildSystem *>(this->buildSystem());
|
||||||
QTC_ASSERT(buildSystem, return widget);
|
QTC_ASSERT(buildSystem, return widget);
|
||||||
|
@@ -350,7 +350,7 @@ NamedWidget *BuildConfiguration::createConfigWidget()
|
|||||||
if (aspect->isVisible())
|
if (aspect->isVisible())
|
||||||
aspect->addToLayout(builder.finishRow());
|
aspect->addToLayout(builder.finishRow());
|
||||||
}
|
}
|
||||||
builder.attachTo(widget, false);
|
builder.attachTo(widget, Layouting::WithoutMargins);
|
||||||
|
|
||||||
return named;
|
return named;
|
||||||
}
|
}
|
||||||
|
@@ -185,7 +185,7 @@ QWidget *BuildStep::createConfigWidget()
|
|||||||
if (aspect->isVisible())
|
if (aspect->isVisible())
|
||||||
aspect->addToLayout(builder.finishRow());
|
aspect->addToLayout(builder.finishRow());
|
||||||
}
|
}
|
||||||
auto widget = builder.emerge(false);
|
auto widget = builder.emerge(Layouting::WithoutMargins);
|
||||||
|
|
||||||
if (m_addMacroExpander)
|
if (m_addMacroExpander)
|
||||||
VariableChooser::addSupportForChildWidgets(widget, macroExpander());
|
VariableChooser::addSupportForChildWidgets(widget, macroExpander());
|
||||||
|
@@ -72,7 +72,7 @@ CodeStyleSettingsWidget::CodeStyleSettingsWidget(Project *project)
|
|||||||
Column {
|
Column {
|
||||||
Row { new QLabel(tr("Language:")), languageComboBox, st },
|
Row { new QLabel(tr("Language:")), languageComboBox, st },
|
||||||
stackedWidget
|
stackedWidget
|
||||||
}.attachTo(this, false);
|
}.attachTo(this, WithoutMargins);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // ProjectExplorer::Internal
|
} // ProjectExplorer::Internal
|
||||||
|
@@ -80,7 +80,7 @@ EditorSettingsWidget::EditorSettingsWidget(Project *project) : m_project(project
|
|||||||
m_displaySettings,
|
m_displaySettings,
|
||||||
m_behaviorSettings,
|
m_behaviorSettings,
|
||||||
st,
|
st,
|
||||||
}.attachTo(this, false);
|
}.attachTo(this, WithoutMargins);
|
||||||
|
|
||||||
const EditorConfiguration *config = m_project->editorConfiguration();
|
const EditorConfiguration *config = m_project->editorConfiguration();
|
||||||
settingsToUi(config);
|
settingsToUi(config);
|
||||||
|
@@ -354,7 +354,7 @@ QWidget *MakeStep::createConfigWidget()
|
|||||||
builder.addRow(m_disabledForSubdirsAspect);
|
builder.addRow(m_disabledForSubdirsAspect);
|
||||||
builder.addRow(m_buildTargetsAspect);
|
builder.addRow(m_buildTargetsAspect);
|
||||||
|
|
||||||
auto widget = builder.emerge(false);
|
auto widget = builder.emerge(Layouting::WithoutMargins);
|
||||||
|
|
||||||
VariableChooser::addSupportForChildWidgets(widget, macroExpander());
|
VariableChooser::addSupportForChildWidgets(widget, macroExpander());
|
||||||
|
|
||||||
|
@@ -245,7 +245,7 @@ QWidget *RunConfiguration::createConfigurationWidget()
|
|||||||
aspect->addToLayout(builder.finishRow());
|
aspect->addToLayout(builder.finishRow());
|
||||||
}
|
}
|
||||||
|
|
||||||
auto widget = builder.emerge(false);
|
auto widget = builder.emerge(Layouting::WithoutMargins);
|
||||||
|
|
||||||
VariableChooser::addSupportForChildWidgets(widget, &m_expander);
|
VariableChooser::addSupportForChildWidgets(widget, &m_expander);
|
||||||
|
|
||||||
|
@@ -114,7 +114,7 @@ public:
|
|||||||
Form {
|
Form {
|
||||||
Tr::tr("Name:"), m_name, br,
|
Tr::tr("Name:"), m_name, br,
|
||||||
Tr::tr("Executable"), m_executable
|
Tr::tr("Executable"), m_executable
|
||||||
}.attachTo(this, false);
|
}.attachTo(this, WithoutMargins);
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateInterpreter(const Interpreter &interpreter)
|
void updateInterpreter(const Interpreter &interpreter)
|
||||||
|
@@ -687,7 +687,7 @@ QbsBuildStepConfigWidget::QbsBuildStepConfigWidget(QbsBuildStep *step)
|
|||||||
|
|
||||||
builder.addRow({tr("Installation directory:"), installDirChooser});
|
builder.addRow({tr("Installation directory:"), installDirChooser});
|
||||||
builder.addRow(m_qbsStep->m_commandLine);
|
builder.addRow(m_qbsStep->m_commandLine);
|
||||||
builder.attachTo(this, false);
|
builder.attachTo(this, Layouting::WithoutMargins);
|
||||||
|
|
||||||
propertyEdit->setToolTip(tr("Properties to pass to the project."));
|
propertyEdit->setToolTip(tr("Properties to pass to the project."));
|
||||||
defaultInstallDirCheckBox->setText(tr("Use default location"));
|
defaultInstallDirCheckBox->setText(tr("Use default location"));
|
||||||
|
@@ -529,7 +529,7 @@ QWidget *QMakeStep::createConfigWidget()
|
|||||||
builder.addRow(m_userArgs);
|
builder.addRow(m_userArgs);
|
||||||
builder.addRow(m_effectiveCall);
|
builder.addRow(m_effectiveCall);
|
||||||
builder.addRow({abisLabel, abisListWidget});
|
builder.addRow({abisLabel, abisListWidget});
|
||||||
auto widget = builder.emerge(false);
|
auto widget = builder.emerge(Layouting::WithoutMargins);
|
||||||
|
|
||||||
qmakeBuildConfigChanged();
|
qmakeBuildConfigChanged();
|
||||||
|
|
||||||
|
@@ -290,7 +290,7 @@ QtOptionsPageWidget::QtOptionsPageWidget()
|
|||||||
Tr::tr("Name:"), m_nameEdit, br,
|
Tr::tr("Name:"), m_nameEdit, br,
|
||||||
Tr::tr("qmake path:"), Row { m_qmakePath, m_editPathPushButton }, br,
|
Tr::tr("qmake path:"), Row { m_qmakePath, m_editPathPushButton }, br,
|
||||||
Span(2, m_errorLabel)
|
Span(2, m_errorLabel)
|
||||||
}.attachTo(versionInfoWidget, false);
|
}.attachTo(versionInfoWidget, WithoutMargins);
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
m_formLayout = qobject_cast<QFormLayout*>(versionInfoWidget->layout());
|
m_formLayout = qobject_cast<QFormLayout*>(versionInfoWidget->layout());
|
||||||
|
@@ -257,7 +257,7 @@ BehaviorSettingsWidget::BehaviorSettingsWidget(QWidget *parent)
|
|||||||
Row {
|
Row {
|
||||||
Column { d->tabPreferencesWidget, d->groupBoxTyping, st },
|
Column { d->tabPreferencesWidget, d->groupBoxTyping, st },
|
||||||
Column { d->groupBoxStorageSettings, d->groupBoxEncodings, d->groupBoxMouse, st }
|
Column { d->groupBoxStorageSettings, d->groupBoxEncodings, d->groupBoxMouse, st }
|
||||||
}.attachTo(this, false);
|
}.attachTo(this, WithoutMargins);
|
||||||
|
|
||||||
connect(d->cleanWhitespace, &QCheckBox::toggled,
|
connect(d->cleanWhitespace, &QCheckBox::toggled,
|
||||||
d->inEntireDocument, &QCheckBox::setEnabled);
|
d->inEntireDocument, &QCheckBox::setEnabled);
|
||||||
|
@@ -185,7 +185,6 @@ CodeStyleSelectorWidget::CodeStyleSelectorWidget(ICodeStylePreferencesFactory *f
|
|||||||
m_importButton = new QPushButton(tr("Import..."));
|
m_importButton = new QPushButton(tr("Import..."));
|
||||||
m_importButton->setEnabled(false);
|
m_importButton->setEnabled(false);
|
||||||
|
|
||||||
|
|
||||||
using namespace Utils::Layouting;
|
using namespace Utils::Layouting;
|
||||||
|
|
||||||
Column {
|
Column {
|
||||||
@@ -202,7 +201,7 @@ CodeStyleSelectorWidget::CodeStyleSelectorWidget(ICodeStylePreferencesFactory *f
|
|||||||
m_importButton
|
m_importButton
|
||||||
},
|
},
|
||||||
|
|
||||||
}.attachTo(this, false);
|
}.attachTo(this, WithoutMargins);
|
||||||
|
|
||||||
connect(m_delegateComboBox, &QComboBox::activated,
|
connect(m_delegateComboBox, &QComboBox::activated,
|
||||||
this, &CodeStyleSelectorWidget::slotComboBoxActivated);
|
this, &CodeStyleSelectorWidget::slotComboBoxActivated);
|
||||||
|
Reference in New Issue
Block a user