forked from qt-creator/qt-creator
ProjectExplorer: Re-organize RunConfiguration constructors
The idea is to massage the setup in a way to make implementation of new configurations less error prone by identifying recurring patterns and sharing repetitive code that tends to be forgotten (see Android cloning). The former two lines of constructors (owner-and-id, owner-and-source) are split into a simple, shared, constructor and new setId() and copyFrom() functions. The change is mostly mechanical, some multiple calls to fromMap have been removed, though, some consts added. Otherwise, to keep the patch small it temporarily introduces two helper templates in IRunConfigurationFactory. Also, setId() signatures have not been unified yet. These won't be needed in the final setup. Change-Id: I8c0734496caae744a9883fe6d92c1d8f8e0234ea Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -51,13 +51,43 @@ namespace QmlProjectManager {
|
||||
|
||||
const char M_CURRENT_FILE[] = "CurrentFile";
|
||||
|
||||
QmlProjectRunConfiguration::QmlProjectRunConfiguration(Target *parent, Id id) :
|
||||
RunConfiguration(parent, id),
|
||||
m_scriptFile(QLatin1String(M_CURRENT_FILE))
|
||||
QmlProjectRunConfiguration::QmlProjectRunConfiguration(Target *target)
|
||||
: RunConfiguration(target)
|
||||
{
|
||||
addExtraAspect(new QmlProjectEnvironmentAspect(this));
|
||||
|
||||
ctor();
|
||||
// reset default settings in constructor
|
||||
connect(EditorManager::instance(), &EditorManager::currentEditorChanged,
|
||||
this, &QmlProjectRunConfiguration::changeCurrentFile);
|
||||
connect(EditorManager::instance(), &EditorManager::currentDocumentStateChanged,
|
||||
this, [this] { changeCurrentFile(); });
|
||||
|
||||
connect(target, &Target::kitChanged,
|
||||
this, &QmlProjectRunConfiguration::updateEnabledState);
|
||||
}
|
||||
|
||||
void QmlProjectRunConfiguration::initialize(Id id)
|
||||
{
|
||||
RunConfiguration::initialize(id);
|
||||
m_scriptFile = M_CURRENT_FILE;
|
||||
|
||||
if (id == Constants::QML_SCENE_RC_ID)
|
||||
setDisplayName(tr("QML Scene", "QMLRunConfiguration display name."));
|
||||
else
|
||||
setDisplayName(tr("QML Viewer", "QMLRunConfiguration display name."));
|
||||
|
||||
updateEnabledState();
|
||||
}
|
||||
|
||||
void QmlProjectRunConfiguration::copyFrom(const QmlProjectRunConfiguration *source)
|
||||
{
|
||||
RunConfiguration::copyFrom(source);
|
||||
m_currentFileFilename = source->m_currentFileFilename;
|
||||
m_mainScriptFilename = source->m_mainScriptFilename;
|
||||
m_scriptFile = source->m_scriptFile;
|
||||
m_qmlViewerArgs = source->m_qmlViewerArgs;
|
||||
|
||||
updateEnabledState();
|
||||
}
|
||||
|
||||
Runnable QmlProjectRunConfiguration::runnable() const
|
||||
@@ -72,17 +102,6 @@ Runnable QmlProjectRunConfiguration::runnable() const
|
||||
return r;
|
||||
}
|
||||
|
||||
QmlProjectRunConfiguration::QmlProjectRunConfiguration(Target *parent,
|
||||
QmlProjectRunConfiguration *source) :
|
||||
RunConfiguration(parent, source),
|
||||
m_currentFileFilename(source->m_currentFileFilename),
|
||||
m_mainScriptFilename(source->m_mainScriptFilename),
|
||||
m_scriptFile(source->m_scriptFile),
|
||||
m_qmlViewerArgs(source->m_qmlViewerArgs)
|
||||
{
|
||||
ctor();
|
||||
}
|
||||
|
||||
QString QmlProjectRunConfiguration::disabledReason() const
|
||||
{
|
||||
if (mainScript().isEmpty())
|
||||
@@ -92,24 +111,6 @@ QString QmlProjectRunConfiguration::disabledReason() const
|
||||
return RunConfiguration::disabledReason();
|
||||
}
|
||||
|
||||
void QmlProjectRunConfiguration::ctor()
|
||||
{
|
||||
// reset default settings in constructor
|
||||
connect(EditorManager::instance(), &EditorManager::currentEditorChanged,
|
||||
this, &QmlProjectRunConfiguration::changeCurrentFile);
|
||||
connect(EditorManager::instance(), &EditorManager::currentDocumentStateChanged,
|
||||
this, [this] { changeCurrentFile(); });
|
||||
|
||||
connect(target(), &Target::kitChanged,
|
||||
this, &QmlProjectRunConfiguration::updateEnabledState);
|
||||
|
||||
if (id() == Constants::QML_SCENE_RC_ID)
|
||||
setDisplayName(tr("QML Scene", "QMLRunConfiguration display name."));
|
||||
else
|
||||
setDisplayName(tr("QML Viewer", "QMLRunConfiguration display name."));
|
||||
updateEnabledState();
|
||||
}
|
||||
|
||||
QString QmlProjectRunConfiguration::executable() const
|
||||
{
|
||||
QtSupport::BaseQtVersion *version = qtVersion();
|
||||
|
||||
@@ -40,20 +40,17 @@ namespace QtSupport { class BaseQtVersion; }
|
||||
namespace QmlProjectManager {
|
||||
class QmlProject;
|
||||
|
||||
namespace Internal {
|
||||
class QmlProjectRunConfigurationFactory;
|
||||
class QmlProjectRunConfigurationWidget;
|
||||
}
|
||||
namespace Internal { class QmlProjectRunConfigurationWidget; }
|
||||
|
||||
class QMLPROJECTMANAGER_EXPORT QmlProjectRunConfiguration : public ProjectExplorer::RunConfiguration
|
||||
{
|
||||
Q_OBJECT
|
||||
friend class Internal::QmlProjectRunConfigurationFactory;
|
||||
friend class ProjectExplorer::IRunConfigurationFactory;
|
||||
friend class Internal::QmlProjectRunConfigurationWidget;
|
||||
friend class QmlProject; // to call updateEnabled()
|
||||
|
||||
public:
|
||||
QmlProjectRunConfiguration(ProjectExplorer::Target *parent, Core::Id id);
|
||||
explicit QmlProjectRunConfiguration(ProjectExplorer::Target *target);
|
||||
|
||||
ProjectExplorer::Runnable runnable() const override;
|
||||
|
||||
@@ -79,13 +76,10 @@ public:
|
||||
signals:
|
||||
void scriptSourceChanged();
|
||||
|
||||
protected:
|
||||
QmlProjectRunConfiguration(ProjectExplorer::Target *parent,
|
||||
QmlProjectRunConfiguration *source);
|
||||
virtual bool fromMap(const QVariantMap &map) override;
|
||||
|
||||
private:
|
||||
void ctor();
|
||||
void initialize(Core::Id id);
|
||||
void copyFrom(const QmlProjectRunConfiguration *source);
|
||||
virtual bool fromMap(const QVariantMap &map) override;
|
||||
|
||||
void changeCurrentFile(Core::IEditor* = 0);
|
||||
void updateEnabledState() final;
|
||||
|
||||
@@ -104,7 +104,7 @@ bool QmlProjectRunConfigurationFactory::canCreate(ProjectExplorer::Target *paren
|
||||
|
||||
ProjectExplorer::RunConfiguration *QmlProjectRunConfigurationFactory::doCreate(ProjectExplorer::Target *parent, Core::Id id)
|
||||
{
|
||||
return new QmlProjectRunConfiguration(parent, id);
|
||||
return createHelper<QmlProjectRunConfiguration>(parent, id);
|
||||
}
|
||||
|
||||
bool QmlProjectRunConfigurationFactory::canRestore(ProjectExplorer::Target *parent, const QVariantMap &map) const
|
||||
@@ -115,7 +115,7 @@ bool QmlProjectRunConfigurationFactory::canRestore(ProjectExplorer::Target *pare
|
||||
ProjectExplorer::RunConfiguration *QmlProjectRunConfigurationFactory::doRestore(ProjectExplorer::Target *parent,
|
||||
const QVariantMap &map)
|
||||
{
|
||||
return new QmlProjectRunConfiguration(parent, ProjectExplorer::idFromMap(map));
|
||||
return createHelper<QmlProjectRunConfiguration>(parent, ProjectExplorer::idFromMap(map));
|
||||
}
|
||||
|
||||
bool QmlProjectRunConfigurationFactory::canClone(ProjectExplorer::Target *parent, ProjectExplorer::RunConfiguration *source) const
|
||||
@@ -128,7 +128,7 @@ ProjectExplorer::RunConfiguration *QmlProjectRunConfigurationFactory::clone(Proj
|
||||
{
|
||||
if (!canClone(parent, source))
|
||||
return 0;
|
||||
return new QmlProjectRunConfiguration(parent, qobject_cast<QmlProjectRunConfiguration *>(source));
|
||||
return cloneHelper<QmlProjectRunConfiguration>(parent, source);
|
||||
}
|
||||
|
||||
bool QmlProjectRunConfigurationFactory::canHandle(ProjectExplorer::Target *parent) const
|
||||
|
||||
Reference in New Issue
Block a user