Debugger: Use LayoutBuilder for AnalyzerRunConfigWidget

Less noise.

Change-Id: Ieeb853d8bb3661582e7cda275f7c420b8246a046
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2021-03-03 15:47:30 +01:00
parent 641604429a
commit 60c26a4993
2 changed files with 40 additions and 69 deletions

View File

@@ -27,76 +27,62 @@
#include "analyzerrunconfigwidget.h" #include "analyzerrunconfigwidget.h"
#include <utils/detailswidget.h> #include <utils/detailswidget.h>
#include <utils/qtcassert.h> #include <utils/layoutbuilder.h>
#include <QDebug>
#include <QApplication>
#include <QLabel>
#include <QVBoxLayout>
#include <QComboBox> #include <QComboBox>
#include <QLayout>
#include <QPushButton> #include <QPushButton>
using namespace Utils;
namespace Debugger { namespace Debugger {
AnalyzerRunConfigWidget::AnalyzerRunConfigWidget(ProjectExplorer::GlobalOrProjectAspect *aspect) AnalyzerRunConfigWidget::AnalyzerRunConfigWidget(ProjectExplorer::GlobalOrProjectAspect *aspect)
{ {
m_aspect = aspect; using namespace Layouting;
auto globalSetting = new QWidget; auto settingsCombo = new QComboBox;
auto globalSettingLayout = new QHBoxLayout(globalSetting); settingsCombo->addItem(tr("Global"));
globalSettingLayout->setContentsMargins(0, 0, 0, 0); settingsCombo->addItem(tr("Custom"));
m_settingsCombo = new QComboBox(globalSetting); auto restoreButton = new QPushButton(tr("Restore Global"));
m_settingsCombo->addItems(QStringList({
QApplication::translate("ProjectExplorer::Internal::EditorSettingsPropertiesPage", "Global"),
QApplication::translate("ProjectExplorer::Internal::EditorSettingsPropertiesPage", "Custom")
}));
globalSettingLayout->addWidget(m_settingsCombo);
connect(m_settingsCombo, QOverload<int>::of(&QComboBox::activated),
this, &AnalyzerRunConfigWidget::chooseSettings);
m_restoreButton = new QPushButton(
QApplication::translate("ProjectExplorer::Internal::EditorSettingsPropertiesPage", "Restore Global"),
globalSetting);
globalSettingLayout->addWidget(m_restoreButton);
connect(m_restoreButton, &QPushButton::clicked, this, &AnalyzerRunConfigWidget::restoreGlobal);
globalSettingLayout->addStretch(2);
QWidget *innerPane = new QWidget; auto innerPane = new QWidget;
m_configWidget = aspect->projectSettings()->createConfigWidget(); auto configWidget = aspect->projectSettings()->createConfigWidget();
auto layout = new QVBoxLayout(innerPane); auto details = new DetailsWidget;
layout->setContentsMargins(0, 0, 0, 0); details->setWidget(innerPane);
layout->addWidget(globalSetting);
layout->addWidget(m_configWidget);
m_details = new Utils::DetailsWidget; Column {
m_details->setWidget(innerPane); Row { settingsCombo, restoreButton, Stretch() },
configWidget
}.attachTo(innerPane);
auto outerLayout = new QVBoxLayout(this); Column { details }.attachTo(this);
outerLayout->addWidget(m_details);
outerLayout->setContentsMargins(0, 0, 0, 0);
chooseSettings(m_aspect->isUsingGlobalSettings() ? 0 : 1); details->layout()->setContentsMargins(0, 0, 0, 0);
} innerPane->layout()->setContentsMargins(0, 0, 0, 0);
layout()->setContentsMargins(0, 0, 0, 0);
void AnalyzerRunConfigWidget::chooseSettings(int setting) auto chooseSettings = [=](int setting) {
{ const bool isCustom = (setting == 1);
QTC_ASSERT(m_aspect, return);
bool isCustom = (setting == 1);
m_settingsCombo->setCurrentIndex(setting); settingsCombo->setCurrentIndex(setting);
m_aspect->setUsingGlobalSettings(!isCustom); aspect->setUsingGlobalSettings(!isCustom);
m_configWidget->setEnabled(isCustom); configWidget->setEnabled(isCustom);
m_restoreButton->setEnabled(isCustom); restoreButton->setEnabled(isCustom);
m_details->setSummaryText(isCustom details->setSummaryText(isCustom
? tr("Use Customized Settings") ? tr("Use Customized Settings")
: tr("Use Global Settings")); : tr("Use Global Settings"));
} };
void AnalyzerRunConfigWidget::restoreGlobal() chooseSettings(aspect->isUsingGlobalSettings() ? 0 : 1);
{
QTC_ASSERT(m_aspect, return); connect(settingsCombo, QOverload<int>::of(&QComboBox::activated),
m_aspect->resetProjectToGlobalSettings(); this, chooseSettings);
connect(restoreButton, &QPushButton::clicked,
aspect, &ProjectExplorer::GlobalOrProjectAspect::resetProjectToGlobalSettings);
} }
} // namespace Debugger } // namespace Debugger

View File

@@ -30,31 +30,16 @@
#include <projectexplorer/runconfiguration.h> #include <projectexplorer/runconfiguration.h>
QT_BEGIN_NAMESPACE #include <QCoreApplication>
class QComboBox;
class QPushButton;
QT_END_NAMESPACE
namespace Utils { class DetailsWidget; }
namespace Debugger { namespace Debugger {
class DEBUGGER_EXPORT AnalyzerRunConfigWidget : public QWidget class DEBUGGER_EXPORT AnalyzerRunConfigWidget : public QWidget
{ {
Q_OBJECT Q_DECLARE_TR_FUNCTIONS(ProjectExplorer::Internal::EditorSettingsPropertiesPage);
public: public:
AnalyzerRunConfigWidget(ProjectExplorer::GlobalOrProjectAspect *aspect); AnalyzerRunConfigWidget(ProjectExplorer::GlobalOrProjectAspect *aspect);
private:
void chooseSettings(int setting);
void restoreGlobal();
QWidget *m_configWidget;
ProjectExplorer::GlobalOrProjectAspect *m_aspect;
QComboBox *m_settingsCombo;
QPushButton *m_restoreButton;
Utils::DetailsWidget *m_details;
}; };
} // namespace Debugger } // namespace Debugger