forked from qt-creator/qt-creator
ProjectExplorer: Introduce base class for enabled/disabled project configuration
... and use this as a base for all RunConfigurations. Clean out code in the individual run configurations dealing with their enabled/disabled state. Change-Id: Icc2ea136b056f7aea7ce96480b4402459d7ac0ce Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -152,7 +152,7 @@ void CMakeProject::updateProjectData(CMakeBuildConfiguration *bc)
|
||||
}
|
||||
|
||||
updateApplicationAndDeploymentTargets();
|
||||
updateTargetRunConfigurations(t);
|
||||
t->updateDefaultRunConfigurations();
|
||||
|
||||
createGeneratedCodeModelSupport();
|
||||
|
||||
@@ -446,35 +446,6 @@ QStringList CMakeProject::filesGeneratedFrom(const QString &sourceFile) const
|
||||
}
|
||||
}
|
||||
|
||||
void CMakeProject::updateTargetRunConfigurations(Target *t)
|
||||
{
|
||||
// *Update* existing runconfigurations (no need to update new ones!):
|
||||
QHash<QString, const CMakeBuildTarget *> buildTargetHash;
|
||||
const QList<CMakeBuildTarget> buildTargetList = buildTargets();
|
||||
foreach (const CMakeBuildTarget &bt, buildTargetList) {
|
||||
if (bt.targetType != ExecutableType || bt.executable.isEmpty())
|
||||
continue;
|
||||
|
||||
buildTargetHash.insert(bt.title, &bt);
|
||||
}
|
||||
|
||||
foreach (RunConfiguration *rc, t->runConfigurations()) {
|
||||
auto cmakeRc = qobject_cast<CMakeRunConfiguration *>(rc);
|
||||
if (!cmakeRc)
|
||||
continue;
|
||||
|
||||
auto btIt = buildTargetHash.constFind(cmakeRc->title());
|
||||
cmakeRc->setEnabled(btIt != buildTargetHash.constEnd());
|
||||
if (btIt != buildTargetHash.constEnd()) {
|
||||
cmakeRc->setExecutable(btIt.value()->executable.toString());
|
||||
cmakeRc->setBaseWorkingDirectory(btIt.value()->workingDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
// create new and remove obsolete RCs using the factories
|
||||
t->updateDefaultRunConfigurations();
|
||||
}
|
||||
|
||||
void CMakeProject::updateApplicationAndDeploymentTargets()
|
||||
{
|
||||
Target *t = activeTarget();
|
||||
|
||||
@@ -122,7 +122,6 @@ private:
|
||||
|
||||
void createGeneratedCodeModelSupport();
|
||||
QStringList filesGeneratedFrom(const QString &sourceFile) const final;
|
||||
void updateTargetRunConfigurations(ProjectExplorer::Target *t);
|
||||
void updateApplicationAndDeploymentTargets();
|
||||
|
||||
ProjectExplorer::Target *m_connectedTarget = nullptr;
|
||||
|
||||
@@ -82,8 +82,7 @@ CMakeRunConfiguration::CMakeRunConfiguration(Target *parent, CMakeRunConfigurati
|
||||
RunConfiguration(parent, source),
|
||||
m_buildSystemTarget(source->m_buildSystemTarget),
|
||||
m_executable(source->m_executable),
|
||||
m_title(source->m_title),
|
||||
m_enabled(source->m_enabled)
|
||||
m_title(source->m_title)
|
||||
{
|
||||
ctor();
|
||||
}
|
||||
@@ -144,12 +143,16 @@ QString CMakeRunConfiguration::defaultDisplayName() const
|
||||
{
|
||||
if (m_title.isEmpty())
|
||||
return tr("Run CMake kit");
|
||||
QString result = m_title;
|
||||
if (!m_enabled) {
|
||||
result += QLatin1Char(' ');
|
||||
result += tr("(disabled)");
|
||||
}
|
||||
return result;
|
||||
return m_title;
|
||||
}
|
||||
|
||||
void CMakeRunConfiguration::updateEnabledState()
|
||||
{
|
||||
auto cp = qobject_cast<CMakeProject *>(target()->project());
|
||||
if (!cp->hasBuildTarget(m_buildSystemTarget))
|
||||
setEnabled(false);
|
||||
else
|
||||
RunConfiguration::updateEnabledState();
|
||||
}
|
||||
|
||||
QWidget *CMakeRunConfiguration::createConfigurationWidget()
|
||||
@@ -157,25 +160,14 @@ QWidget *CMakeRunConfiguration::createConfigurationWidget()
|
||||
return new CMakeRunConfigurationWidget(this);
|
||||
}
|
||||
|
||||
void CMakeRunConfiguration::setEnabled(bool b)
|
||||
{
|
||||
if (m_enabled == b)
|
||||
return;
|
||||
m_enabled = b;
|
||||
emit enabledChanged();
|
||||
setDefaultDisplayName(defaultDisplayName());
|
||||
}
|
||||
|
||||
bool CMakeRunConfiguration::isEnabled() const
|
||||
{
|
||||
return m_enabled;
|
||||
}
|
||||
|
||||
QString CMakeRunConfiguration::disabledReason() const
|
||||
{
|
||||
if (!m_enabled)
|
||||
return tr("The executable is not built by the current build configuration");
|
||||
return QString();
|
||||
auto cp = qobject_cast<CMakeProject *>(target()->project());
|
||||
QTC_ASSERT(cp, return QString());
|
||||
|
||||
if (cp->hasParsingData() && !cp->hasBuildTarget(m_buildSystemTarget))
|
||||
return tr("The project no longer builds the target associated with this run configuration.");
|
||||
return RunConfiguration::disabledReason();
|
||||
}
|
||||
|
||||
static void updateExecutable(CMakeRunConfiguration *rc, Utils::FancyLineEdit *fle)
|
||||
|
||||
@@ -51,9 +51,6 @@ public:
|
||||
|
||||
QVariantMap toMap() const override;
|
||||
|
||||
void setEnabled(bool b);
|
||||
|
||||
bool isEnabled() const override;
|
||||
QString disabledReason() const override;
|
||||
|
||||
QString buildSystemTarget() const final { return m_buildSystemTarget; }
|
||||
@@ -63,6 +60,8 @@ protected:
|
||||
bool fromMap(const QVariantMap &map) override;
|
||||
QString defaultDisplayName() const;
|
||||
|
||||
void updateEnabledState() final;
|
||||
|
||||
private:
|
||||
QString baseWorkingDirectory() const;
|
||||
void ctor();
|
||||
@@ -70,7 +69,6 @@ private:
|
||||
const QString m_buildSystemTarget;
|
||||
QString m_executable;
|
||||
QString m_title;
|
||||
bool m_enabled = true;
|
||||
};
|
||||
|
||||
class CMakeRunConfigurationWidget : public QWidget
|
||||
|
||||
Reference in New Issue
Block a user