forked from qt-creator/qt-creator
ProjectExplorer: Move global settings handling to ProjectSettingsWidget
Allows more local use. Change-Id: Ifd65b5b14d6da64c242ba6c37fde355033cbf036 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -3,8 +3,17 @@
|
||||
|
||||
#include "projectsettingswidget.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <utils/layoutbuilder.h>
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QLabel>
|
||||
|
||||
namespace ProjectExplorer {
|
||||
|
||||
const int CONTENTS_MARGIN = 5;
|
||||
|
||||
ProjectSettingsWidget::ProjectSettingsWidget(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{}
|
||||
@@ -30,49 +39,68 @@ void ProjectSettingsWidget::setUseGlobalSettingsCheckBoxEnabled(bool enabled)
|
||||
emit useGlobalSettingsCheckBoxEnabledChanged(enabled);
|
||||
}
|
||||
|
||||
bool ProjectSettingsWidget::isUseGlobalSettingsCheckBoxEnabled() const
|
||||
{
|
||||
return m_useGlobalSettingsCheckBoxEnabled;
|
||||
}
|
||||
|
||||
bool ProjectSettingsWidget::isUseGlobalSettingsCheckBoxVisible() const
|
||||
{
|
||||
return m_useGlobalSettingsCheckBoxVisibleVisible;
|
||||
}
|
||||
|
||||
void ProjectSettingsWidget::setUseGlobalSettingsCheckBoxVisible(bool visible)
|
||||
{
|
||||
m_useGlobalSettingsCheckBoxVisibleVisible = visible;
|
||||
}
|
||||
|
||||
bool ProjectSettingsWidget::isUseGlobalSettingsLabelVisible() const
|
||||
{
|
||||
return m_useGlobalSettingsLabelVisibleVisible;
|
||||
}
|
||||
|
||||
void ProjectSettingsWidget::setUseGlobalSettingsLabelVisible(bool visible)
|
||||
{
|
||||
m_useGlobalSettingsLabelVisibleVisible = visible;
|
||||
}
|
||||
|
||||
Utils::Id ProjectSettingsWidget::globalSettingsId() const
|
||||
{
|
||||
return m_globalSettingsId;
|
||||
}
|
||||
|
||||
void ProjectSettingsWidget::setGlobalSettingsId(Utils::Id globalId)
|
||||
{
|
||||
m_globalSettingsId = globalId;
|
||||
}
|
||||
|
||||
bool ProjectSettingsWidget::expanding() const
|
||||
{
|
||||
return m_expanding;
|
||||
}
|
||||
|
||||
void ProjectSettingsWidget::setExpanding(bool expanding)
|
||||
{
|
||||
m_expanding = expanding;
|
||||
}
|
||||
|
||||
void ProjectSettingsWidget::addToLayout(QBoxLayout *layout)
|
||||
{
|
||||
if (!m_useGlobalSettingsCheckBoxVisibleVisible && !m_useGlobalSettingsLabelVisibleVisible)
|
||||
return;
|
||||
|
||||
const auto useGlobalSettingsCheckBox = new QCheckBox;
|
||||
useGlobalSettingsCheckBox->setChecked(useGlobalSettings());
|
||||
useGlobalSettingsCheckBox->setEnabled(m_useGlobalSettingsCheckBoxEnabled);
|
||||
|
||||
const QString labelText = m_useGlobalSettingsCheckBoxVisibleVisible
|
||||
? QStringLiteral("Use <a href=\"dummy\">global settings</a>")
|
||||
: QStringLiteral("<a href=\"dummy\">Global settings</a>");
|
||||
const auto settingsLabel = new QLabel(labelText);
|
||||
settingsLabel->setEnabled(m_useGlobalSettingsCheckBoxEnabled);
|
||||
|
||||
const auto horizontalLayout = new QHBoxLayout;
|
||||
horizontalLayout->setContentsMargins(0, CONTENTS_MARGIN, 0, CONTENTS_MARGIN);
|
||||
horizontalLayout->setSpacing(CONTENTS_MARGIN);
|
||||
|
||||
if (m_useGlobalSettingsCheckBoxVisibleVisible) {
|
||||
horizontalLayout->addWidget(useGlobalSettingsCheckBox);
|
||||
|
||||
connect(this, &ProjectSettingsWidget::useGlobalSettingsCheckBoxEnabledChanged,
|
||||
this, [useGlobalSettingsCheckBox, settingsLabel](bool enabled) {
|
||||
useGlobalSettingsCheckBox->setEnabled(enabled);
|
||||
settingsLabel->setEnabled(enabled);
|
||||
});
|
||||
connect(useGlobalSettingsCheckBox, &QCheckBox::stateChanged,
|
||||
this, &ProjectSettingsWidget::setUseGlobalSettings);
|
||||
connect(this, &ProjectSettingsWidget::useGlobalSettingsChanged,
|
||||
useGlobalSettingsCheckBox, &QCheckBox::setChecked);
|
||||
}
|
||||
|
||||
if (m_useGlobalSettingsLabelVisibleVisible) {
|
||||
horizontalLayout->addWidget(settingsLabel);
|
||||
connect(settingsLabel, &QLabel::linkActivated, this, [this] {
|
||||
Core::ICore::showOptionsDialog(m_globalSettingsId);
|
||||
});
|
||||
}
|
||||
horizontalLayout->addStretch(1);
|
||||
layout->addLayout(horizontalLayout);
|
||||
layout->addWidget(Layouting::createHr());
|
||||
}
|
||||
|
||||
} // ProjectExplorer
|
||||
|
@@ -7,6 +7,7 @@
|
||||
|
||||
#include <utils/id.h>
|
||||
|
||||
#include <QBoxLayout>
|
||||
#include <QWidget>
|
||||
|
||||
namespace ProjectExplorer {
|
||||
@@ -14,6 +15,7 @@ namespace ProjectExplorer {
|
||||
class PROJECTEXPLORER_EXPORT ProjectSettingsWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ProjectSettingsWidget(QWidget *parent = nullptr);
|
||||
|
||||
@@ -21,15 +23,11 @@ public:
|
||||
bool useGlobalSettings() const;
|
||||
|
||||
void setUseGlobalSettingsCheckBoxEnabled(bool enadled);
|
||||
bool isUseGlobalSettingsCheckBoxEnabled() const;
|
||||
|
||||
bool isUseGlobalSettingsCheckBoxVisible() const;
|
||||
bool isUseGlobalSettingsLabelVisible() const;
|
||||
Utils::Id globalSettingsId() const;
|
||||
|
||||
bool expanding() const;
|
||||
void setExpanding(bool expanding);
|
||||
|
||||
void addToLayout(QBoxLayout *layout);
|
||||
|
||||
protected:
|
||||
void setUseGlobalSettingsCheckBoxVisible(bool visible);
|
||||
void setUseGlobalSettingsLabelVisible(bool visible);
|
||||
|
@@ -88,7 +88,7 @@ const int PanelVMargin = 14;
|
||||
class ProjectPanel final : public QScrollArea
|
||||
{
|
||||
public:
|
||||
explicit ProjectPanel(QWidget *inner, bool addGlobalSettings, bool addStretch)
|
||||
explicit ProjectPanel(QWidget *inner, bool addStretch)
|
||||
{
|
||||
setWindowTitle(inner->windowTitle());
|
||||
setFocusProxy(inner);
|
||||
@@ -96,69 +96,25 @@ public:
|
||||
setWidgetResizable(true);
|
||||
setFocusPolicy(Qt::NoFocus);
|
||||
|
||||
inner->setContentsMargins(0, CONTENTS_MARGIN, 0, BELOW_CONTENTS_MARGIN);
|
||||
|
||||
auto root = new QWidget;
|
||||
root->setFocusPolicy(Qt::NoFocus);
|
||||
root->setContentsMargins(0, 0, 0, 0);
|
||||
setWidget(root);
|
||||
|
||||
// The layout holding the panel.
|
||||
auto topLayout = new QVBoxLayout(root);
|
||||
topLayout->setContentsMargins(PanelVMargin, 0, PanelVMargin, 0);
|
||||
topLayout->setSpacing(0);
|
||||
auto layout = new QVBoxLayout(root);
|
||||
layout->setContentsMargins(PanelVMargin, 0, PanelVMargin, 0);
|
||||
layout->setSpacing(0);
|
||||
|
||||
if (auto widget = dynamic_cast<ProjectSettingsWidget *>(inner))
|
||||
widget->addToLayout(layout);
|
||||
|
||||
layout->addWidget(inner);
|
||||
//layout->addWidget(new FindToolBarPlaceHolder(this));
|
||||
|
||||
if (addGlobalSettings) {
|
||||
auto widget = dynamic_cast<ProjectSettingsWidget *>(inner);
|
||||
if (QTC_GUARD(widget)) {
|
||||
if (widget->isUseGlobalSettingsCheckBoxVisible() || widget->isUseGlobalSettingsLabelVisible()) {
|
||||
const auto useGlobalSettingsCheckBox = new QCheckBox;
|
||||
useGlobalSettingsCheckBox->setChecked(widget->useGlobalSettings());
|
||||
useGlobalSettingsCheckBox->setEnabled(widget->isUseGlobalSettingsCheckBoxEnabled());
|
||||
|
||||
const QString labelText = widget->isUseGlobalSettingsCheckBoxVisible()
|
||||
? QStringLiteral("Use <a href=\"dummy\">global settings</a>")
|
||||
: QStringLiteral("<a href=\"dummy\">Global settings</a>");
|
||||
const auto settingsLabel = new QLabel(labelText);
|
||||
settingsLabel->setEnabled(widget->isUseGlobalSettingsCheckBoxEnabled());
|
||||
|
||||
const auto horizontalLayout = new QHBoxLayout;
|
||||
horizontalLayout->setContentsMargins(0, CONTENTS_MARGIN, 0, CONTENTS_MARGIN);
|
||||
horizontalLayout->setSpacing(CONTENTS_MARGIN);
|
||||
|
||||
if (widget->isUseGlobalSettingsCheckBoxVisible()) {
|
||||
horizontalLayout->addWidget(useGlobalSettingsCheckBox);
|
||||
|
||||
connect(widget, &ProjectSettingsWidget::useGlobalSettingsCheckBoxEnabledChanged,
|
||||
this, [useGlobalSettingsCheckBox, settingsLabel](bool enabled) {
|
||||
useGlobalSettingsCheckBox->setEnabled(enabled);
|
||||
settingsLabel->setEnabled(enabled);
|
||||
});
|
||||
connect(useGlobalSettingsCheckBox, &QCheckBox::stateChanged,
|
||||
widget, &ProjectSettingsWidget::setUseGlobalSettings);
|
||||
connect(widget, &ProjectSettingsWidget::useGlobalSettingsChanged,
|
||||
useGlobalSettingsCheckBox, &QCheckBox::setChecked);
|
||||
}
|
||||
|
||||
if (widget->isUseGlobalSettingsLabelVisible()) {
|
||||
horizontalLayout->addWidget(settingsLabel);
|
||||
connect(settingsLabel, &QLabel::linkActivated, this, [widget] {
|
||||
Core::ICore::showOptionsDialog(widget->globalSettingsId());
|
||||
});
|
||||
}
|
||||
horizontalLayout->addStretch(1);
|
||||
topLayout->addLayout(horizontalLayout);
|
||||
topLayout->addWidget(Layouting::createHr());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inner->setContentsMargins(0, CONTENTS_MARGIN, 0, BELOW_CONTENTS_MARGIN);
|
||||
inner->setParent(root);
|
||||
topLayout->addWidget(inner);
|
||||
|
||||
if (addStretch)
|
||||
topLayout->addStretch(1);
|
||||
layout->addStretch(1);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -583,7 +539,7 @@ QVariant MiscSettingsPanelItem::data(int column, int role) const
|
||||
ProjectPanels MiscSettingsPanelItem::panelWidgets() const
|
||||
{
|
||||
if (!m_widget) {
|
||||
m_widget = new ProjectPanel(m_factory->createWidget(m_project), true, false);
|
||||
m_widget = new ProjectPanel(m_factory->createWidget(m_project), false);
|
||||
m_widget->setWindowTitle(m_factory->displayName());
|
||||
}
|
||||
return {m_widget.get()};
|
||||
@@ -952,9 +908,9 @@ public:
|
||||
ProjectPanels panelWidgets() const final
|
||||
{
|
||||
if (!m_buildSettingsWidget)
|
||||
m_buildSettingsWidget = new ProjectPanel(createBuildSettingsWidget(target()), false, true);
|
||||
m_buildSettingsWidget = new ProjectPanel(createBuildSettingsWidget(target()), true);
|
||||
if (!m_runSettingsWidget)
|
||||
m_runSettingsWidget = new ProjectPanel(createRunSettingsWidget(target()), false, true);
|
||||
m_runSettingsWidget = new ProjectPanel(createRunSettingsWidget(target()), true);
|
||||
|
||||
return { m_buildSettingsWidget.get(), m_runSettingsWidget.get() };
|
||||
}
|
||||
@@ -1160,7 +1116,7 @@ ProjectItemBase *TargetGroupItem::activeItem()
|
||||
ProjectPanels TargetGroupItem::panelWidgets() const
|
||||
{
|
||||
if (!m_targetSetupPage)
|
||||
m_targetSetupPage = new ProjectPanel(new TargetSetupPageWrapper(m_project), false, false);
|
||||
m_targetSetupPage = new ProjectPanel(new TargetSetupPageWrapper(m_project), false);
|
||||
|
||||
return {m_targetSetupPage.get()};
|
||||
}
|
||||
|
Reference in New Issue
Block a user