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