Commit 366ada9f authored by Tobias Hunger's avatar Tobias Hunger

RunConfiguration: Centralize enabled state handling

Centralize handling of enabled state of RunConfiguration widgets.

Remove code that does the same thing in all the different run configuration
widgets.

Change-Id: I175d7e19d031bd28a2b19cd825e0b6568da19bc3
Reviewed-by: Tim Jenssen's avatarTim Jenssen <tim.jenssen@qt.io>
parent 131c7a1c
......@@ -69,9 +69,7 @@ AndroidRunConfigurationWidget::AndroidRunConfigurationWidget(QWidget *parent):
});
}
AndroidRunConfigurationWidget::~AndroidRunConfigurationWidget()
{
}
AndroidRunConfigurationWidget::~AndroidRunConfigurationWidget() = default;
void AndroidRunConfigurationWidget::setAmStartArgs(const QStringList &args)
{
......
......@@ -49,9 +49,6 @@ public:
{ }
BareMetalRunConfiguration * const runConfiguration;
QWidget topWidget;
QLabel disabledIcon;
QLabel disabledReason;
QLineEdit workingDirLineEdit;
QLabel localExecutableLabel;
QFormLayout genericWidgetsLayout;
......@@ -65,11 +62,7 @@ BareMetalRunConfigurationWidget::BareMetalRunConfigurationWidget(BareMetalRunCon
QWidget *parent)
: QWidget(parent), d(new BareMetalRunConfigurationWidgetPrivate(runConfiguration))
{
QVBoxLayout *topLayout = new QVBoxLayout(this);
topLayout->setMargin(0);
addDisabledLabel(topLayout);
topLayout->addWidget(&d->topWidget);
QVBoxLayout *mainLayout = new QVBoxLayout(&d->topWidget);
QVBoxLayout *mainLayout = new QVBoxLayout(this);
mainLayout->setMargin(0);
Utils::DetailsWidget *detailsContainer = new Utils::DetailsWidget(this);
......@@ -97,9 +90,6 @@ BareMetalRunConfigurationWidget::BareMetalRunConfigurationWidget(BareMetalRunCon
this, &BareMetalRunConfigurationWidget::updateTargetInformation);
connect(&d->workingDirLineEdit, &QLineEdit::textEdited,
this, &BareMetalRunConfigurationWidget::handleWorkingDirectoryChanged);
connect(d->runConfiguration, &ProjectExplorer::RunConfiguration::enabledChanged,
this, &BareMetalRunConfigurationWidget::runConfigurationEnabledChange);
runConfigurationEnabledChange();
}
BareMetalRunConfigurationWidget::~BareMetalRunConfigurationWidget()
......@@ -107,18 +97,6 @@ BareMetalRunConfigurationWidget::~BareMetalRunConfigurationWidget()
delete d;
}
void BareMetalRunConfigurationWidget::addDisabledLabel(QVBoxLayout *topLayout)
{
QHBoxLayout * const hl = new QHBoxLayout;
hl->addStretch();
d->disabledIcon.setPixmap(Utils::Icons::WARNING.pixmap());
hl->addWidget(&d->disabledIcon);
d->disabledReason.setVisible(false);
hl->addWidget(&d->disabledReason);
hl->addStretch();
topLayout->addLayout(hl);
}
void BareMetalRunConfigurationWidget::updateTargetInformation()
{
setLabelText(d->localExecutableLabel,
......@@ -138,13 +116,4 @@ void BareMetalRunConfigurationWidget::setLabelText(QLabel &label, const QString
label.setText(regularText.isEmpty() ? errorMessage : regularText);
}
void BareMetalRunConfigurationWidget::runConfigurationEnabledChange()
{
bool enabled = d->runConfiguration->isEnabled();
d->topWidget.setEnabled(enabled);
d->disabledIcon.setVisible(!enabled);
d->disabledReason.setVisible(!enabled);
d->disabledReason.setText(d->runConfiguration->disabledReason());
}
} // namespace BareMetal
......@@ -46,9 +46,6 @@ public:
explicit BareMetalRunConfigurationWidget(BareMetalRunConfiguration *runConfiguration,
QWidget *parent = 0);
~BareMetalRunConfigurationWidget();
void addDisabledLabel(QVBoxLayout *topLayout);
Q_SLOT void runConfigurationEnabledChange();
private:
void updateTargetInformation();
......
......@@ -210,8 +210,6 @@ CMakeRunConfigurationWidget::CMakeRunConfigurationWidget(CMakeRunConfiguration *
auto vbx = new QVBoxLayout(this);
vbx->setMargin(0);
vbx->addWidget(detailsContainer);
setEnabled(cmakeRunConfiguration->isEnabled());
}
// Factory
......
......@@ -45,14 +45,6 @@ NimRunConfigurationWidget::NimRunConfigurationWidget(NimRunConfiguration *rc,
fl->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
rc->extraAspect<ArgumentsAspect>()->addToMainConfigurationWidget(this, fl);
rc->extraAspect<TerminalAspect>()->addToMainConfigurationWidget(this,fl);
connect(rc, &NimRunConfiguration::enabledChanged, this, &NimRunConfigurationWidget::updateUi);
updateUi();
}
void NimRunConfigurationWidget::updateUi()
{
setEnabled(m_rc->isEnabled());
}
}
} // namespace Nim
......@@ -39,9 +39,7 @@ public:
explicit NimRunConfigurationWidget(NimRunConfiguration *rc, QWidget *parent = 0);
private:
void updateUi();
NimRunConfiguration* m_rc;
};
}
} // namespace Nim
......@@ -39,6 +39,7 @@
#include <projectexplorer/buildmanager.h>
#include <utils/algorithm.h>
#include <utils/qtcassert.h>
#include <utils/utilsicons.h>
#include <QVariant>
#include <QAction>
......@@ -184,6 +185,16 @@ RunSettingsWidget::RunSettingsWidget(Target *target) :
m_runLayout->setMargin(0);
m_runLayout->setSpacing(5);
m_disabledIcon = new QLabel;
m_disabledIcon->setPixmap(Utils::Icons::WARNING.pixmap());
m_disabledText = new QLabel;
auto disabledHBox = new QHBoxLayout;
disabledHBox->addWidget(m_disabledIcon);
disabledHBox->addWidget(m_disabledText);
disabledHBox->addStretch(255);
m_runLayout->addLayout(disabledHBox);
m_addRunMenu = new QMenu(m_addRunToolButton);
m_addRunToolButton->setMenu(m_addRunMenu);
RunConfiguration *rc = m_target->activeRunConfiguration();
......@@ -485,9 +496,12 @@ void RunSettingsWidget::setConfigurationWidget(RunConfiguration *rc)
return;
m_runConfigurationWidget = rc->createConfigurationWidget();
m_runConfiguration = rc;
if (m_runConfigurationWidget)
if (m_runConfigurationWidget) {
m_runLayout->addWidget(m_runConfigurationWidget);
updateEnabledState();
connect(m_runConfiguration, &RunConfiguration::enabledChanged,
m_runConfigurationWidget, [this]() { updateEnabledState(); });
}
addRunControlWidgets();
}
......@@ -561,3 +575,15 @@ void RunSettingsWidget::removeSubWidgets()
}
m_subWidgets.clear();
}
void RunSettingsWidget::updateEnabledState()
{
const bool enable = m_runConfiguration ? m_runConfiguration->isEnabled() : false;
const QString reason = m_runConfiguration ? m_runConfiguration->disabledReason() : QString();
m_runConfigurationWidget->setEnabled(enable);
m_disabledIcon->setVisible(!enable && !reason.isEmpty());
m_disabledText->setVisible(!enable && !reason.isEmpty());
m_disabledText->setText(reason);
}
......@@ -80,6 +80,8 @@ private:
void addSubWidget(RunConfigWidget *subWidget);
void removeSubWidgets();
void updateEnabledState();
Target *m_target;
RunConfigurationModel *m_runConfigurationsModel;
DeployConfigurationModel *m_deployConfigurationModel;
......@@ -105,6 +107,8 @@ private:
QPushButton *m_removeRunToolButton;
QPushButton *m_renameRunButton;
QPushButton *m_renameDeployButton;
QLabel *m_disabledIcon;
QLabel *m_disabledText;
};
} // namespace Internal
......
......@@ -270,8 +270,6 @@ PythonRunConfigurationWidget::PythonRunConfigurationWidget(PythonRunConfiguratio
auto vbx = new QVBoxLayout(this);
vbx->setMargin(0);
vbx->addWidget(m_detailsContainer);
setEnabled(runConfiguration->isEnabled());
}
class PythonRunConfigurationFactory : public IRunConfigurationFactory
......
......@@ -313,17 +313,6 @@ QbsRunConfigurationWidget::QbsRunConfigurationWidget(QbsRunConfiguration *rc)
auto vboxTopLayout = new QVBoxLayout(this);
vboxTopLayout->setMargin(0);
auto hl = new QHBoxLayout();
hl->addStretch();
m_disabledIcon = new QLabel(this);
m_disabledIcon->setPixmap(Utils::Icons::WARNING.pixmap());
hl->addWidget(m_disabledIcon);
m_disabledReason = new QLabel(this);
m_disabledReason->setVisible(false);
hl->addWidget(m_disabledReason);
hl->addStretch();
vboxTopLayout->addLayout(hl);
auto detailsContainer = new Utils::DetailsWidget(this);
detailsContainer->setState(Utils::DetailsWidget::NoSummary);
vboxTopLayout->addWidget(detailsContainer);
......@@ -343,23 +332,11 @@ QbsRunConfigurationWidget::QbsRunConfigurationWidget(QbsRunConfiguration *rc)
m_rc->extraAspect<TerminalAspect>()->addToMainConfigurationWidget(this, toplayout);
runConfigurationEnabledChange();
connect(m_rc, &QbsRunConfiguration::targetInformationChanged,
this, &QbsRunConfigurationWidget::targetInformationHasChanged, Qt::QueuedConnection);
connect(m_rc, &RunConfiguration::enabledChanged,
this, &QbsRunConfigurationWidget::runConfigurationEnabledChange);
}
void QbsRunConfigurationWidget::runConfigurationEnabledChange()
{
bool enabled = m_rc->isEnabled();
m_disabledIcon->setVisible(!enabled);
m_disabledReason->setVisible(!enabled);
m_disabledReason->setText(m_rc->disabledReason());
targetInformationHasChanged();
this, &QbsRunConfigurationWidget::targetInformationHasChanged);
}
void QbsRunConfigurationWidget::targetInformationHasChanged()
......
......@@ -113,10 +113,8 @@ private:
void setExecutableLineText(const QString &text = QString());
QbsRunConfiguration *m_rc;
bool m_ignoreChange = false;
QLabel *m_disabledIcon;
QLabel *m_disabledReason;
QLabel *m_executableLineLabel;
bool m_ignoreChange = false;
bool m_isShown = false;
};
......
......@@ -147,17 +147,6 @@ DesktopQmakeRunConfigurationWidget::DesktopQmakeRunConfigurationWidget(DesktopQm
auto vboxTopLayout = new QVBoxLayout(this);
vboxTopLayout->setMargin(0);
auto hl = new QHBoxLayout();
hl->addStretch();
m_disabledIcon = new QLabel(this);
m_disabledIcon->setPixmap(Utils::Icons::WARNING.pixmap());
hl->addWidget(m_disabledIcon);
m_disabledReason = new QLabel(this);
m_disabledReason->setVisible(false);
hl->addWidget(m_disabledReason);
hl->addStretch();
vboxTopLayout->addLayout(hl);
auto detailsContainer = new DetailsWidget(this);
detailsContainer->setState(DetailsWidget::NoSummary);
vboxTopLayout->addWidget(detailsContainer);
......@@ -213,8 +202,6 @@ DesktopQmakeRunConfigurationWidget::DesktopQmakeRunConfigurationWidget(DesktopQm
this, &DesktopQmakeRunConfigurationWidget::usingLibrarySearchPathToggled);
}
runConfigurationEnabledChange();
connect(qmakeRunConfiguration, &DesktopQmakeRunConfiguration::usingDyldImageSuffixChanged,
this, &DesktopQmakeRunConfigurationWidget::usingDyldImageSuffixChanged);
connect(qmakeRunConfiguration, &DesktopQmakeRunConfiguration::usingLibrarySearchPathChanged,
......@@ -222,21 +209,10 @@ DesktopQmakeRunConfigurationWidget::DesktopQmakeRunConfigurationWidget(DesktopQm
connect(qmakeRunConfiguration, &DesktopQmakeRunConfiguration::effectiveTargetInformationChanged,
this, &DesktopQmakeRunConfigurationWidget::effectiveTargetInformationChanged, Qt::QueuedConnection);
connect(qmakeRunConfiguration, &RunConfiguration::enabledChanged,
this, &DesktopQmakeRunConfigurationWidget::runConfigurationEnabledChange);
Core::VariableChooser::addSupportForChildWidgets(this, m_qmakeRunConfiguration->macroExpander());
effectiveTargetInformationChanged();
}
void DesktopQmakeRunConfigurationWidget::runConfigurationEnabledChange()
{
bool enabled = m_qmakeRunConfiguration->isEnabled();
m_disabledIcon->setVisible(!enabled);
m_disabledReason->setVisible(!enabled);
m_disabledReason->setText(m_qmakeRunConfiguration->disabledReason());
}
void DesktopQmakeRunConfigurationWidget::usingDyldImageSuffixToggled(bool state)
{
m_ignoreChange = true;
......
......@@ -120,7 +120,6 @@ public:
explicit DesktopQmakeRunConfigurationWidget(DesktopQmakeRunConfiguration *qmakeRunConfiguration);
private:
void runConfigurationEnabledChange();
void effectiveTargetInformationChanged();
void usingDyldImageSuffixToggled(bool);
void usingDyldImageSuffixChanged(bool);
......@@ -130,8 +129,6 @@ private:
private:
DesktopQmakeRunConfiguration *m_qmakeRunConfiguration = nullptr;
bool m_ignoreChange = false;
QLabel *m_disabledIcon = nullptr;
QLabel *m_disabledReason = nullptr;
QLabel *m_executableLineLabel = nullptr;
QCheckBox *m_useQvfbCheck = nullptr;
QCheckBox *m_usingDyldImageSuffix = nullptr;
......
......@@ -58,9 +58,6 @@ public:
RemoteLinuxRunConfiguration * const runConfiguration;
bool ignoreChange;
QWidget topWidget;
QLabel disabledIcon;
QLabel disabledReason;
QLineEdit argsLineEdit;
QLineEdit workingDirLineEdit;
QLabel localExecutableLabel;
......@@ -79,17 +76,9 @@ RemoteLinuxRunConfigurationWidget::RemoteLinuxRunConfigurationWidget(RemoteLinux
QWidget *parent)
: QWidget(parent), d(new RemoteLinuxRunConfigurationWidgetPrivate(runConfiguration))
{
QVBoxLayout *topLayout = new QVBoxLayout(this);
topLayout->setMargin(0);
addDisabledLabel(topLayout);
topLayout->addWidget(&d->topWidget);
QVBoxLayout *mainLayout = new QVBoxLayout(&d->topWidget);
QVBoxLayout *mainLayout = new QVBoxLayout(this);
mainLayout->setMargin(0);
addGenericWidgets(mainLayout);
connect(d->runConfiguration, &RemoteLinuxRunConfiguration::enabledChanged,
this, &RemoteLinuxRunConfigurationWidget::runConfigurationEnabledChange);
runConfigurationEnabledChange();
}
RemoteLinuxRunConfigurationWidget::~RemoteLinuxRunConfigurationWidget()
......@@ -102,27 +91,6 @@ void RemoteLinuxRunConfigurationWidget::addFormLayoutRow(QWidget *label, QWidget
d->genericWidgetsLayout.addRow(label, field);
}
void RemoteLinuxRunConfigurationWidget::addDisabledLabel(QVBoxLayout *topLayout)
{
QHBoxLayout * const hl = new QHBoxLayout;
hl->addStretch();
d->disabledIcon.setPixmap(Utils::Icons::WARNING.pixmap());
hl->addWidget(&d->disabledIcon);
d->disabledReason.setVisible(false);
hl->addWidget(&d->disabledReason);
hl->addStretch();
topLayout->addLayout(hl);
}
void RemoteLinuxRunConfigurationWidget::runConfigurationEnabledChange()
{
bool enabled = d->runConfiguration->isEnabled();
d->topWidget.setEnabled(enabled);
d->disabledIcon.setVisible(!enabled);
d->disabledReason.setVisible(!enabled);
d->disabledReason.setText(d->runConfiguration->disabledReason());
}
void RemoteLinuxRunConfigurationWidget::addGenericWidgets(QVBoxLayout *mainLayout)
{
Utils::DetailsWidget *detailsContainer = new Utils::DetailsWidget(this);
......
......@@ -49,9 +49,6 @@ public:
void addFormLayoutRow(QWidget *label, QWidget *field);
void addDisabledLabel(QVBoxLayout *topLayout);
void runConfigurationEnabledChange();
private:
void argumentsEdited(const QString &args);
void updateTargetInformation();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment