diff options
author | Tobias Hunger <tobias.hunger@nokia.com> | 2010-01-14 17:41:29 +0100 |
---|---|---|
committer | Tobias Hunger <tobias.hunger@nokia.com> | 2010-02-01 12:23:12 +0100 |
commit | 1726688434b4f974d0179d4ec979ce00f208c9b2 (patch) | |
tree | 502f06910adc0744a1fb13b4f8f1d0d01731b844 /src/plugins | |
parent | c410d268dbe05c26563f4beceab99e2420f7a521 (diff) | |
download | qt-creator-1726688434b4f974d0179d4ec979ce00f208c9b2.tar.gz |
Make use of ProjectConfiguration class in BuildSteps
* Use new BuildSteps interface (as seen in ProjectConfiguration).
* Use new factory to construct/clone/restore them.
Reviewed-by: dt
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/cmakeprojectmanager/makestep.cpp | 140 | ||||
-rw-r--r-- | src/plugins/cmakeprojectmanager/makestep.h | 41 | ||||
-rw-r--r-- | src/plugins/genericprojectmanager/genericmakestep.cpp | 144 | ||||
-rw-r--r-- | src/plugins/genericprojectmanager/genericmakestep.h | 50 | ||||
-rw-r--r-- | src/plugins/projectexplorer/abstractprocessstep.cpp | 12 | ||||
-rw-r--r-- | src/plugins/projectexplorer/abstractprocessstep.h | 9 | ||||
-rw-r--r-- | src/plugins/projectexplorer/buildconfiguration.cpp | 20 | ||||
-rw-r--r-- | src/plugins/projectexplorer/buildstep.cpp | 40 | ||||
-rw-r--r-- | src/plugins/projectexplorer/buildstep.h | 48 | ||||
-rw-r--r-- | src/plugins/projectexplorer/buildstepspage.cpp | 8 | ||||
-rw-r--r-- | src/plugins/projectexplorer/processstep.cpp | 178 | ||||
-rw-r--r-- | src/plugins/projectexplorer/processstep.h | 43 | ||||
-rw-r--r-- | src/plugins/projectexplorer/project.cpp | 139 | ||||
-rw-r--r-- | src/plugins/qt4projectmanager/makestep.cpp | 129 | ||||
-rw-r--r-- | src/plugins/qt4projectmanager/makestep.h | 37 | ||||
-rw-r--r-- | src/plugins/qt4projectmanager/qmakestep.cpp | 116 | ||||
-rw-r--r-- | src/plugins/qt4projectmanager/qmakestep.h | 33 |
17 files changed, 719 insertions, 468 deletions
diff --git a/src/plugins/cmakeprojectmanager/makestep.cpp b/src/plugins/cmakeprojectmanager/makestep.cpp index cd37ee9745..0c3b09843d 100644 --- a/src/plugins/cmakeprojectmanager/makestep.cpp +++ b/src/plugins/cmakeprojectmanager/makestep.cpp @@ -26,7 +26,9 @@ ** contact the sales department at http://qt.nokia.com/contact. ** **************************************************************************/ + #include "makestep.h" + #include "cmakeprojectconstants.h" #include "cmakeproject.h" #include "cmakebuildconfiguration.h" @@ -44,25 +46,48 @@ using namespace CMakeProjectManager; using namespace CMakeProjectManager::Internal; using namespace ProjectExplorer; +namespace { +const char * const MS_ID("CMakeProjectManager.MakeStep"); + +const char * const CLEAN_KEY("CMakeProjectManager.MakeStep.Clean"); +const char * const BUILD_TARGETS_KEY("CMakeProjectManager.MakeStep.BuildTargets"); +const char * const ADDITIONAL_ARGUMENTS_KEY("CMakeProjectManager.MakeStep.AdditionalArguments"); +} + +// TODO: Move progress information into an IOutputParser! + MakeStep::MakeStep(BuildConfiguration *bc) : - AbstractProcessStep(bc), m_clean(false), m_futureInterface(0) + AbstractProcessStep(bc, QLatin1String(MS_ID)), m_clean(false), + m_futureInterface(0) { - m_percentProgress = QRegExp("^\\[\\s*(\\d*)%\\]"); + ctor(); +} + +MakeStep::MakeStep(BuildConfiguration *bc, const QString &id) : + AbstractProcessStep(bc, id), m_clean(false), + m_futureInterface(0) +{ + ctor(); } -MakeStep::MakeStep(MakeStep *bs, BuildConfiguration *bc) : - AbstractProcessStep(bs, bc), +MakeStep::MakeStep(BuildConfiguration *bc, MakeStep *bs) : + AbstractProcessStep(bc, bs), m_clean(bs->m_clean), m_futureInterface(0), m_buildTargets(bs->m_buildTargets), m_additionalArguments(bs->m_buildTargets) { + ctor(); +} +void MakeStep::ctor() +{ + m_percentProgress = QRegExp("^\\[\\s*(\\d*)%\\]"); + setDisplayName(tr("Make", "CMakeProjectManager::MakeStep display name.")); } MakeStep::~MakeStep() { - } CMakeBuildConfiguration *MakeStep::cmakeBuildConfiguration() const @@ -75,31 +100,25 @@ void MakeStep::setClean(bool clean) m_clean = clean; } -void MakeStep::restoreFromGlobalMap(const QMap<QString, QVariant> &map) +QVariantMap MakeStep::toMap() const { - if (map.value("clean").isValid() && map.value("clean").toBool()) - m_clean = true; - AbstractProcessStep::restoreFromGlobalMap(map); + QVariantMap map(AbstractProcessStep::toMap()); + map.insert(QLatin1String(CLEAN_KEY), m_clean); + map.insert(QLatin1String(BUILD_TARGETS_KEY), m_buildTargets); + map.insert(QLatin1String(ADDITIONAL_ARGUMENTS_KEY), m_additionalArguments); + return map; } -void MakeStep::restoreFromLocalMap(const QMap<QString, QVariant> &map) +bool MakeStep::fromMap(const QVariantMap &map) { - m_buildTargets = map["buildTargets"].toStringList(); - m_additionalArguments = map["additionalArguments"].toStringList(); - if (map.value("clean").isValid() && map.value("clean").toBool()) - m_clean = true; - AbstractProcessStep::restoreFromLocalMap(map); -} + m_clean = map.value(QLatin1String(CLEAN_KEY)).toBool(); + m_buildTargets = map.value(QLatin1String(BUILD_TARGETS_KEY)).toStringList(); + m_additionalArguments = map.value(QLatin1String(ADDITIONAL_ARGUMENTS_KEY)).toStringList(); -void MakeStep::storeIntoLocalMap(QMap<QString, QVariant> &map) -{ - map["buildTargets"] = m_buildTargets; - map["additionalArguments"] = m_additionalArguments; - if (m_clean) - map["clean"] = true; - AbstractProcessStep::storeIntoLocalMap(map); + return BuildStep::fromMap(map); } + bool MakeStep::init() { CMakeBuildConfiguration *bc = cmakeBuildConfiguration(); @@ -132,16 +151,6 @@ void MakeStep::run(QFutureInterface<bool> &fi) m_futureInterface = 0; } -QString MakeStep::id() -{ - return Constants::MAKESTEP; -} - -QString MakeStep::displayName() -{ - return QLatin1String("Make"); -} - BuildStepConfigWidget *MakeStep::createConfigWidget() { return new MakeStepConfigWidget(this); @@ -238,7 +247,7 @@ void MakeStepConfigWidget::itemChanged(QListWidgetItem *item) QString MakeStepConfigWidget::displayName() const { - return "Make"; + return tr("Make", "CMakeProjectManager::MakeStepConfigWidget display name."); } void MakeStepConfigWidget::init() @@ -298,31 +307,68 @@ QString MakeStepConfigWidget::summaryText() const // MakeStepFactory // -bool MakeStepFactory::canCreate(const QString &id) const +MakeStepFactory::MakeStepFactory(QObject *parent) : + ProjectExplorer::IBuildStepFactory(parent) { - return (Constants::MAKESTEP == id); } -BuildStep *MakeStepFactory::create(BuildConfiguration *bc, const QString &id) const +MakeStepFactory::~MakeStepFactory() { - Q_ASSERT(id == Constants::MAKESTEP); - return new MakeStep(bc); } -BuildStep *MakeStepFactory::clone(BuildStep *bs, BuildConfiguration *bc) const +bool MakeStepFactory::canCreate(BuildConfiguration *parent, const QString &id) const { - return new MakeStep(static_cast<MakeStep *>(bs), bc); + if (!qobject_cast<CMakeBuildConfiguration *>(parent)) + return false; + return QLatin1String(MS_ID) == id; } -QStringList MakeStepFactory::canCreateForBuildConfiguration(BuildConfiguration *bc) const +BuildStep *MakeStepFactory::create(BuildConfiguration *parent, const QString &id) { - Q_UNUSED(bc); - return QStringList(); + if (!canCreate(parent, id)) + return 0; + return new MakeStep(parent); } -QString MakeStepFactory::displayNameForId(const QString &id) const +bool MakeStepFactory::canClone(BuildConfiguration *parent, BuildStep *source) const +{ + return canCreate(parent, source->id()); +} + +BuildStep *MakeStepFactory::clone(BuildConfiguration *parent, BuildStep *source) +{ + if (!canClone(parent, source)) + return 0; + return new MakeStep(parent, static_cast<MakeStep *>(source)); +} + +bool MakeStepFactory::canRestore(BuildConfiguration *parent, const QVariantMap &map) const { - Q_UNUSED(id); - return "Make"; + QString id(ProjectExplorer::idFromMap(map)); + return canCreate(parent, id); } +BuildStep *MakeStepFactory::restore(BuildConfiguration *parent, const QVariantMap &map) +{ + if (!canRestore(parent, map)) + return 0; + MakeStep *bs(new MakeStep(parent)); + if (bs->fromMap(map)) + return bs; + delete bs; + return 0; +} + +QStringList MakeStepFactory::availableCreationIds(ProjectExplorer::BuildConfiguration *parent) const +{ + if (!qobject_cast<CMakeBuildConfiguration *>(parent)) + return QStringList(); + return QStringList() << QLatin1String(MS_ID); +} + +QString MakeStepFactory::displayNameForId(const QString &id) const +{ + if (id == QLatin1String(MS_ID)) + return tr("Make", "Display name for CMakeProjectManager::MakeStep id."); + return QString(); +} diff --git a/src/plugins/cmakeprojectmanager/makestep.h b/src/plugins/cmakeprojectmanager/makestep.h index a2ab1888dc..2a54a0e0e3 100644 --- a/src/plugins/cmakeprojectmanager/makestep.h +++ b/src/plugins/cmakeprojectmanager/makestep.h @@ -42,16 +42,18 @@ namespace CMakeProjectManager { namespace Internal { class CMakeBuildConfiguration; +class MakeStepFactory; class MakeStep : public ProjectExplorer::AbstractProcessStep { Q_OBJECT + friend class MakeStepFactory; friend class MakeStepConfigWidget; // TODO remove // This is for modifying internal data + public: MakeStep(ProjectExplorer::BuildConfiguration *bc); - MakeStep(MakeStep *bs, ProjectExplorer::BuildConfiguration *bc); - ~MakeStep(); + virtual ~MakeStep(); CMakeBuildConfiguration *cmakeBuildConfiguration() const; @@ -59,8 +61,6 @@ public: virtual void run(QFutureInterface<bool> &fi); - virtual QString id(); - virtual QString displayName(); virtual ProjectExplorer::BuildStepConfigWidget *createConfigWidget(); virtual bool immutable() const; bool buildsTarget(const QString &target) const; @@ -68,17 +68,22 @@ public: QStringList additionalArguments() const; void setAdditionalArguments(const QStringList &list); - virtual void restoreFromGlobalMap(const QMap<QString, QVariant> &map); - - virtual void restoreFromLocalMap(const QMap<QString, QVariant> &map); - virtual void storeIntoLocalMap(QMap<QString, QVariant> &map); - void setClean(bool clean); + QVariantMap toMap() const; + protected: + MakeStep(ProjectExplorer::BuildConfiguration *bc, MakeStep *bs); + MakeStep(ProjectExplorer::BuildConfiguration *bc, const QString &id); + + bool fromMap(const QVariantMap &map); + // For parsing [ 76%] virtual void stdOut(const QString &line); + private: + void ctor(); + bool m_clean; QRegExp m_percentProgress; QFutureInterface<bool> *m_futureInterface; @@ -108,10 +113,20 @@ private: class MakeStepFactory : public ProjectExplorer::IBuildStepFactory { - virtual bool canCreate(const QString &id) const; - virtual ProjectExplorer::BuildStep *create(ProjectExplorer::BuildConfiguration *bc, const QString &id) const; - virtual ProjectExplorer::BuildStep *clone(ProjectExplorer::BuildStep *bs, ProjectExplorer::BuildConfiguration *bc) const; - virtual QStringList canCreateForBuildConfiguration(ProjectExplorer::BuildConfiguration *bc) const; + Q_OBJECT + +public: + explicit MakeStepFactory(QObject *parent = 0); + virtual ~MakeStepFactory(); + + virtual bool canCreate(ProjectExplorer::BuildConfiguration *parent, const QString &id) const; + virtual ProjectExplorer::BuildStep *create(ProjectExplorer::BuildConfiguration *parent, const QString &id); + virtual bool canClone(ProjectExplorer::BuildConfiguration *parent, ProjectExplorer::BuildStep *source) const; + virtual ProjectExplorer::BuildStep *clone(ProjectExplorer::BuildConfiguration *parent, ProjectExplorer::BuildStep *source); + virtual bool canRestore(ProjectExplorer::BuildConfiguration *parent, const QVariantMap &map) const; + virtual ProjectExplorer::BuildStep *restore(ProjectExplorer::BuildConfiguration *parent, const QVariantMap &map); + + virtual QStringList availableCreationIds(ProjectExplorer::BuildConfiguration *bc) const; virtual QString displayNameForId(const QString &id) const; }; diff --git a/src/plugins/genericprojectmanager/genericmakestep.cpp b/src/plugins/genericprojectmanager/genericmakestep.cpp index 7360a95985..4dd38982b0 100644 --- a/src/plugins/genericprojectmanager/genericmakestep.cpp +++ b/src/plugins/genericprojectmanager/genericmakestep.cpp @@ -49,17 +49,41 @@ using namespace GenericProjectManager; using namespace GenericProjectManager::Internal; +namespace { +const char * const GENERIC_MS_ID("GenericProjectManager.GenericMakeStep"); +const char * const GENERIC_MS_DISPLAY_NAME(QT_TRANSLATE_NOOP("GenericProjectManager::Internal::GenericMakeStep", + "Make")); + +const char * const BUILD_TARGETS_KEY("GenericProjectManager.GenericMakeStep.BuildTargets"); +const char * const MAKE_ARGUMENTS_KEY("GenericProjectManager.GenericMakeStep.MakeArguments"); +const char * const MAKE_COMMAND_KEY("GenericProjectManager.GenericMakeStep.MakeCommand"); +} + GenericMakeStep::GenericMakeStep(ProjectExplorer::BuildConfiguration *bc) : - AbstractProcessStep(bc) + AbstractProcessStep(bc, QLatin1String(GENERIC_MS_ID)) +{ + ctor(); +} + +GenericMakeStep::GenericMakeStep(ProjectExplorer::BuildConfiguration *bc, const QString &id) : + AbstractProcessStep(bc, id) +{ + ctor(); +} + +GenericMakeStep::GenericMakeStep(ProjectExplorer::BuildConfiguration *bc, GenericMakeStep *bs) : + AbstractProcessStep(bc, bs), + m_buildTargets(bs->m_buildTargets), + m_makeArguments(bs->m_makeArguments), + m_makeCommand(bs->m_makeCommand) { + ctor(); } -GenericMakeStep::GenericMakeStep(GenericMakeStep *bs, ProjectExplorer::BuildConfiguration *bc) : - AbstractProcessStep(bs, bc) +void GenericMakeStep::ctor() { - m_buildTargets = bs->m_buildTargets; - m_makeArguments = bs->m_makeArguments; - m_makeCommand = bs->m_makeCommand; + setDisplayName(QCoreApplication::translate("GenericProjectManager::Internal::GenericMakeStep", + GENERIC_MS_DISPLAY_NAME)); } GenericMakeStep::~GenericMakeStep() @@ -93,20 +117,23 @@ bool GenericMakeStep::init() return AbstractProcessStep::init(); } -void GenericMakeStep::restoreFromLocalMap(const QMap<QString, QVariant> &map) +QVariantMap GenericMakeStep::toMap() const { - m_buildTargets = map.value("buildTargets").toStringList(); - m_makeArguments = map.value("makeArguments").toStringList(); - m_makeCommand = map.value("makeCommand").toString(); - ProjectExplorer::AbstractProcessStep::restoreFromLocalMap(map); + QVariantMap map(AbstractProcessStep::toMap()); + + map.insert(QLatin1String(BUILD_TARGETS_KEY), m_buildTargets); + map.insert(QLatin1String(MAKE_ARGUMENTS_KEY), m_makeArguments); + map.insert(QLatin1String(MAKE_COMMAND_KEY), m_makeCommand); + return map; } -void GenericMakeStep::storeIntoLocalMap(QMap<QString, QVariant> &map) +bool GenericMakeStep::fromMap(const QVariantMap &map) { - map["buildTargets"] = m_buildTargets; - map["makeArguments"] = m_makeArguments; - map["makeCommand"] = m_makeCommand; - ProjectExplorer::AbstractProcessStep::storeIntoLocalMap(map); + m_buildTargets = map.value(QLatin1String(BUILD_TARGETS_KEY)).toStringList(); + m_makeArguments = map.value(QLatin1String(MAKE_ARGUMENTS_KEY)).toStringList(); + m_makeCommand = map.value(QLatin1String(MAKE_COMMAND_KEY)).toString(); + + return BuildStep::fromMap(map); } QStringList GenericMakeStep::replacedArguments() const @@ -142,16 +169,6 @@ void GenericMakeStep::run(QFutureInterface<bool> &fi) AbstractProcessStep::run(fi); } -QString GenericMakeStep::id() -{ - return Constants::MAKESTEP; -} - -QString GenericMakeStep::displayName() -{ - return "Make"; -} - ProjectExplorer::BuildStepConfigWidget *GenericMakeStep::createConfigWidget() { return new GenericMakeStepConfigWidget(this); @@ -211,7 +228,7 @@ GenericMakeStepConfigWidget::GenericMakeStepConfigWidget(GenericMakeStep *makeSt QString GenericMakeStepConfigWidget::displayName() const { - return "Make"; + return tr("Make", "GenericMakestep display name."); } // TODO: Label should update when tool chain is changed @@ -280,32 +297,77 @@ void GenericMakeStepConfigWidget::makeArgumentsLineEditTextEdited() // GenericMakeStepFactory // -bool GenericMakeStepFactory::canCreate(const QString &id) const +GenericMakeStepFactory::GenericMakeStepFactory(QObject *parent) : + ProjectExplorer::IBuildStepFactory(parent) +{ +} + +GenericMakeStepFactory::~GenericMakeStepFactory() +{ +} + +bool GenericMakeStepFactory::canCreate(ProjectExplorer::BuildConfiguration *parent, const QString &id) const +{ + if (!qobject_cast<GenericBuildConfiguration *>(parent)) + return false; + return id == QLatin1String(GENERIC_MS_ID); +} + +ProjectExplorer::BuildStep *GenericMakeStepFactory::create(ProjectExplorer::BuildConfiguration *parent, + const QString &id) +{ + if (!canCreate(parent, id)) + return 0; + return new GenericMakeStep(parent); +} + +bool GenericMakeStepFactory::canClone(ProjectExplorer::BuildConfiguration *parent, + ProjectExplorer::BuildStep *source) const +{ + const QString id(source->id()); + return canCreate(parent, id); +} + +ProjectExplorer::BuildStep *GenericMakeStepFactory::clone(ProjectExplorer::BuildConfiguration *parent, + ProjectExplorer::BuildStep *source) { - return (Constants::MAKESTEP == id); + if (!canClone(parent, source)) + return 0; + GenericMakeStep *old(qobject_cast<GenericMakeStep *>(source)); + Q_ASSERT(old); + return new GenericMakeStep(parent, old); } -ProjectExplorer::BuildStep *GenericMakeStepFactory::create(ProjectExplorer::BuildConfiguration *bc, - const QString &id) const +bool GenericMakeStepFactory::canRestore(ProjectExplorer::BuildConfiguration *parent, + const QVariantMap &map) const { - Q_ASSERT(id == Constants::MAKESTEP); - return new GenericMakeStep(bc); + QString id(ProjectExplorer::idFromMap(map)); + return canCreate(parent, id); } -ProjectExplorer::BuildStep *GenericMakeStepFactory::clone(ProjectExplorer::BuildStep *bs, - ProjectExplorer::BuildConfiguration *bc) const +ProjectExplorer::BuildStep *GenericMakeStepFactory::restore(ProjectExplorer::BuildConfiguration *parent, + const QVariantMap &map) { - return new GenericMakeStep(static_cast<GenericMakeStep*>(bs), bc); + if (!canRestore(parent, map)) + return 0; + GenericMakeStep *bs(new GenericMakeStep(parent)); + if (bs->fromMap(map)) + return bs; + delete bs; + return 0; } -QStringList GenericMakeStepFactory::canCreateForBuildConfiguration(ProjectExplorer::BuildConfiguration *bc) const +QStringList GenericMakeStepFactory::availableCreationIds(ProjectExplorer::BuildConfiguration *parent) const { - Q_UNUSED(bc); - return QStringList(); + if (!qobject_cast<GenericBuildConfiguration *>(parent)) + return QStringList(); + return QStringList() << QLatin1String(GENERIC_MS_ID); } QString GenericMakeStepFactory::displayNameForId(const QString &id) const { - QTC_ASSERT(id == Constants::MAKESTEP, return QString()); - return "Make"; + if (id == QLatin1String(GENERIC_MS_ID)) + return QCoreApplication::translate("GenericProjectManager::Internal::GenericMakeStep", + GENERIC_MS_DISPLAY_NAME); + return QString(); } diff --git a/src/plugins/genericprojectmanager/genericmakestep.h b/src/plugins/genericprojectmanager/genericmakestep.h index c578bfb3d2..ba3fdde216 100644 --- a/src/plugins/genericprojectmanager/genericmakestep.h +++ b/src/plugins/genericprojectmanager/genericmakestep.h @@ -45,28 +45,24 @@ namespace Internal { class GenericBuildConfiguration; class GenericMakeStepConfigWidget; - -struct GenericMakeStepSettings -{ - -}; +class GenericMakeStepFactory; class GenericMakeStep : public ProjectExplorer::AbstractProcessStep { Q_OBJECT friend class GenericMakeStepConfigWidget; // TODO remove again? + friend class GenericMakeStepFactory; + public: GenericMakeStep(ProjectExplorer::BuildConfiguration *bc); - GenericMakeStep(GenericMakeStep *bs, ProjectExplorer::BuildConfiguration *bc); - ~GenericMakeStep(); + virtual ~GenericMakeStep(); + GenericBuildConfiguration *genericBuildConfiguration() const; virtual bool init(); virtual void run(QFutureInterface<bool> &fi); - virtual QString id(); - virtual QString displayName(); virtual ProjectExplorer::BuildStepConfigWidget *createConfigWidget(); virtual bool immutable() const; bool buildsTarget(const QString &target) const; @@ -74,9 +70,16 @@ public: QStringList replacedArguments() const; QString makeCommand() const; - virtual void restoreFromLocalMap(const QMap<QString, QVariant> &map); - virtual void storeIntoLocalMap(QMap<QString, QVariant> &map); + QVariantMap toMap() const; + +protected: + GenericMakeStep(ProjectExplorer::BuildConfiguration *bc, GenericMakeStep *bs); + GenericMakeStep(ProjectExplorer::BuildConfiguration *bc, const QString &id); + virtual bool fromMap(const QVariantMap &map); + private: + void ctor(); + QStringList m_buildTargets; QStringList m_makeArguments; QString m_makeCommand; @@ -104,12 +107,25 @@ private: class GenericMakeStepFactory : public ProjectExplorer::IBuildStepFactory { - virtual bool canCreate(const QString &id) const; - virtual ProjectExplorer::BuildStep *create(ProjectExplorer::BuildConfiguration *bc, - const QString &id) const; - virtual ProjectExplorer::BuildStep *clone(ProjectExplorer::BuildStep *bs, - ProjectExplorer::BuildConfiguration *bc) const; - virtual QStringList canCreateForBuildConfiguration(ProjectExplorer::BuildConfiguration *bc) const; + Q_OBJECT + +public: + explicit GenericMakeStepFactory(QObject *parent = 0); + virtual ~GenericMakeStepFactory(); + + virtual bool canCreate(ProjectExplorer::BuildConfiguration *parent, const QString &id) const; + virtual ProjectExplorer::BuildStep *create(ProjectExplorer::BuildConfiguration *parent, + const QString &id); + virtual bool canClone(ProjectExplorer::BuildConfiguration *parent, + ProjectExplorer::BuildStep *source) const; + virtual ProjectExplorer::BuildStep *clone(ProjectExplorer::BuildConfiguration *parent, + ProjectExplorer::BuildStep *source); + virtual bool canRestore(ProjectExplorer::BuildConfiguration *parent, + const QVariantMap &map) const; + virtual ProjectExplorer::BuildStep *restore(ProjectExplorer::BuildConfiguration *parent, + const QVariantMap &map); + + virtual QStringList availableCreationIds(ProjectExplorer::BuildConfiguration *bc) const; virtual QString displayNameForId(const QString &id) const; }; diff --git a/src/plugins/projectexplorer/abstractprocessstep.cpp b/src/plugins/projectexplorer/abstractprocessstep.cpp index dbf25eb35d..95ecaf35ff 100644 --- a/src/plugins/projectexplorer/abstractprocessstep.cpp +++ b/src/plugins/projectexplorer/abstractprocessstep.cpp @@ -42,21 +42,19 @@ using namespace ProjectExplorer; -AbstractProcessStep::AbstractProcessStep(BuildConfiguration *bc) : - BuildStep(bc), m_timer(0), m_futureInterface(0), +AbstractProcessStep::AbstractProcessStep(BuildConfiguration *bc, const QString &id) : + BuildStep(bc, id), m_timer(0), m_futureInterface(0), m_enabled(true), m_ignoreReturnValue(false), m_process(0), m_eventLoop(0), m_outputParserChain(0) { - } -AbstractProcessStep::AbstractProcessStep(AbstractProcessStep *bs, - BuildConfiguration *bc) : - BuildStep(bs, bc), m_timer(0), m_futureInterface(0), +AbstractProcessStep::AbstractProcessStep(BuildConfiguration *bc, + AbstractProcessStep *bs) : + BuildStep(bc, bs), m_timer(0), m_futureInterface(0), m_enabled(bs->m_enabled), m_ignoreReturnValue(bs->m_ignoreReturnValue), m_process(0), m_eventLoop(0), m_outputParserChain(0) { - } AbstractProcessStep::~AbstractProcessStep() diff --git a/src/plugins/projectexplorer/abstractprocessstep.h b/src/plugins/projectexplorer/abstractprocessstep.h index 300ed30aed..408069a9ad 100644 --- a/src/plugins/projectexplorer/abstractprocessstep.h +++ b/src/plugins/projectexplorer/abstractprocessstep.h @@ -67,9 +67,8 @@ class IOutputParser; class PROJECTEXPLORER_EXPORT AbstractProcessStep : public BuildStep { Q_OBJECT + public: - AbstractProcessStep(BuildConfiguration *bc); - AbstractProcessStep(AbstractProcessStep *bs, BuildConfiguration *bc); virtual ~AbstractProcessStep(); /// reimplemented from BuildStep::init() @@ -79,9 +78,6 @@ public: /// You need to call this from YourBuildStep::run() virtual void run(QFutureInterface<bool> &); - // pure virtual functions inheritated from BuildStep - virtual QString id() = 0; - virtual QString displayName() = 0; virtual BuildStepConfigWidget *createConfigWidget() = 0; virtual bool immutable() const = 0; @@ -121,6 +117,9 @@ public: ProjectExplorer::IOutputParser *outputParser() const; protected: + AbstractProcessStep(BuildConfiguration *bc, const QString &id); + AbstractProcessStep(BuildConfiguration *bc, AbstractProcessStep *bs); + /// Called after the process is started /// the default implementation adds a process started message to the output message virtual void processStarted(); diff --git a/src/plugins/projectexplorer/buildconfiguration.cpp b/src/plugins/projectexplorer/buildconfiguration.cpp index c62d7a9ab7..847cf4251d 100644 --- a/src/plugins/projectexplorer/buildconfiguration.cpp +++ b/src/plugins/projectexplorer/buildconfiguration.cpp @@ -35,14 +35,16 @@ using namespace ProjectExplorer; -IBuildStepFactory *findFactory(const QString &id) +namespace { +IBuildStepFactory *findCloneFactory(BuildConfiguration *parent, BuildStep *source) { QList<IBuildStepFactory *> factories = ExtensionSystem::PluginManager::instance()->getObjects<IBuildStepFactory>(); foreach(IBuildStepFactory *factory, factories) - if (factory->canCreate(id)) + if (factory->canClone(parent, source)) return factory; return 0; } +} // namespace BuildConfiguration::BuildConfiguration(Project *pro) : m_project(pro) @@ -61,14 +63,16 @@ BuildConfiguration::BuildConfiguration(BuildConfiguration *source) m_project(source->m_project) { foreach(BuildStep *originalbs, source->buildSteps()) { - IBuildStepFactory *factory = findFactory(originalbs->id()); - BuildStep *clonebs = factory->clone(originalbs, this); - m_buildSteps.append(clonebs); + IBuildStepFactory *factory = findCloneFactory(this, originalbs); + BuildStep *clonebs = factory->clone(this, originalbs); + if (clonebs) + m_buildSteps.append(clonebs); } foreach(BuildStep *originalcs, source->cleanSteps()) { - IBuildStepFactory *factory = findFactory(originalcs->id()); - BuildStep *clonecs = factory->clone(originalcs, this); - m_cleanSteps.append(clonecs); + IBuildStepFactory *factory = findCloneFactory(this, originalcs); + BuildStep *clonecs = factory->clone(this, originalcs); + if (clonecs) + m_cleanSteps.append(clonecs); } } diff --git a/src/plugins/projectexplorer/buildstep.cpp b/src/plugins/projectexplorer/buildstep.cpp index 9fd6925b51..9b74cb232b 100644 --- a/src/plugins/projectexplorer/buildstep.cpp +++ b/src/plugins/projectexplorer/buildstep.cpp @@ -28,44 +28,25 @@ **************************************************************************/ #include "buildstep.h" -#include "buildconfiguration.h" -#include "project.h" - -#include <utils/qtcassert.h> -#include <QtGui/QLayout> using namespace ProjectExplorer; -BuildStep::BuildStep(BuildConfiguration *bc) - : m_buildConfiguration(bc) +BuildStep::BuildStep(BuildConfiguration *bc, const QString &id) : + ProjectConfiguration(id), + m_buildConfiguration(bc) { + Q_ASSERT(bc); } -BuildStep::BuildStep(BuildStep *bs, BuildConfiguration *bc) - : m_buildConfiguration(bc) +BuildStep::BuildStep(BuildConfiguration *bc, BuildStep *bs) : + ProjectConfiguration(bs), + m_buildConfiguration(bc) { - Q_UNUSED(bs); + Q_ASSERT(bc); } BuildStep::~BuildStep() { - -} - - -void BuildStep::restoreFromGlobalMap(const QMap<QString, QVariant> &map) -{ - Q_UNUSED(map) -} - -void BuildStep::restoreFromLocalMap(const QMap<QString, QVariant> &map) -{ - Q_UNUSED(map) -} - -void BuildStep::storeIntoLocalMap(QMap<QString, QVariant> &map) -{ - Q_UNUSED(map) } BuildConfiguration *BuildStep::buildConfiguration() const @@ -78,12 +59,11 @@ bool BuildStep::immutable() const return false; } -IBuildStepFactory::IBuildStepFactory() +IBuildStepFactory::IBuildStepFactory(QObject *parent) : + QObject(parent) { - } IBuildStepFactory::~IBuildStepFactory() { - } diff --git a/src/plugins/projectexplorer/buildstep.h b/src/plugins/projectexplorer/buildstep.h index 7ce799ae4b..d6407a43ff 100644 --- a/src/plugins/projectexplorer/buildstep.h +++ b/src/plugins/projectexplorer/buildstep.h @@ -30,6 +30,7 @@ #ifndef BUILDSTEP_H #define BUILDSTEP_H +#include "projectconfiguration.h" #include "projectexplorer_export.h" #include "taskwindow.h" @@ -66,12 +67,13 @@ class BuildConfiguration; class BuildStepConfigWidget; -class PROJECTEXPLORER_EXPORT BuildStep : public QObject +class PROJECTEXPLORER_EXPORT BuildStep : public ProjectConfiguration { Q_OBJECT + protected: - BuildStep(BuildConfiguration *bc); - BuildStep(BuildStep *bs, BuildConfiguration *bc); + BuildStep(BuildConfiguration *bc, const QString &id); + BuildStep(BuildConfiguration *bc, BuildStep *bs); public: virtual ~BuildStep(); @@ -87,11 +89,6 @@ public: // fi.reportResult(true); virtual void run(QFutureInterface<bool> &fi) = 0; - // The internal name - virtual QString id() = 0; - // The name shown to the user - virtual QString displayName() = 0; - // the Widget shown in the project settings dialog for this buildStep // ownership is transferred to the caller virtual BuildStepConfigWidget *createConfigWidget() = 0; @@ -101,12 +98,6 @@ public: // the default implementation returns false virtual bool immutable() const; - // TODO remove after 2.0 - virtual void restoreFromGlobalMap(const QMap<QString, QVariant> &map); - - virtual void restoreFromLocalMap(const QMap<QString, QVariant> &map); - virtual void storeIntoLocalMap(QMap<QString, QVariant> &map); - BuildConfiguration *buildConfiguration() const; signals: @@ -121,26 +112,27 @@ private: BuildConfiguration *m_buildConfiguration; }; -class PROJECTEXPLORER_EXPORT IBuildStepFactory - : public QObject +class PROJECTEXPLORER_EXPORT IBuildStepFactory : + public QObject { Q_OBJECT public: - IBuildStepFactory(); + explicit IBuildStepFactory(QObject *parent = 0); virtual ~IBuildStepFactory(); - /// Called to check whether this factory can restore the named BuildStep - virtual bool canCreate(const QString &id) const = 0; - /// Called to restore a buildstep - virtual BuildStep *create(BuildConfiguration *bc, const QString &id) const = 0; - /// Called by the add BuildStep action to check which BuildSteps could be added - /// to the project by this factory, should return a list of names - virtual QStringList canCreateForBuildConfiguration(BuildConfiguration *bc) const = 0; - /// Called to convert an internal name to a displayName - - /// Called to clone a BuildStep - virtual BuildStep *clone(BuildStep *bs, BuildConfiguration *bc) const = 0; + + // used to show the list of possible additons to a project, returns a list of types + virtual QStringList availableCreationIds(BuildConfiguration *parent) const = 0; + // used to translate the types to names to display to the user virtual QString displayNameForId(const QString &id) const = 0; + + virtual bool canCreate(BuildConfiguration *parent, const QString &id) const = 0; + virtual BuildStep *create(BuildConfiguration *parent, const QString &id) = 0; + // used to recreate the runConfigurations when restoring settings + virtual bool canRestore(BuildConfiguration *parent, const QVariantMap &map) const = 0; + virtual BuildStep *restore(BuildConfiguration *parent, const QVariantMap &map) = 0; + virtual bool canClone(BuildConfiguration *parent, BuildStep *product) const = 0; + virtual BuildStep *clone(BuildConfiguration *parent, BuildStep *product) = 0; }; class PROJECTEXPLORER_EXPORT BuildConfigWidget diff --git a/src/plugins/projectexplorer/buildstepspage.cpp b/src/plugins/projectexplorer/buildstepspage.cpp index afd2dad296..4833254e30 100644 --- a/src/plugins/projectexplorer/buildstepspage.cpp +++ b/src/plugins/projectexplorer/buildstepspage.cpp @@ -119,7 +119,7 @@ void BuildStepsPage::updateAddBuildStepMenu() //Build up a list of possible steps and save map the display names to the (internal) name and factories. QList<IBuildStepFactory *> factories = ExtensionSystem::PluginManager::instance()->getObjects<IBuildStepFactory>(); foreach (IBuildStepFactory *factory, factories) { - QStringList ids = factory->canCreateForBuildConfiguration(m_configuration); + QStringList ids = factory->availableCreationIds(m_configuration); foreach (const QString &id, ids) { map.insert(factory->displayNameForId(id), QPair<QString, IBuildStepFactory *>(id, factory)); } @@ -147,6 +147,9 @@ void BuildStepsPage::addBuildStepWidget(int pos, BuildStep *step) // create everything BuildStepsWidgetStruct s; s.widget = step->createConfigWidget(); + Q_ASSERT(s.widget); + s.widget->init(); + s.detailsWidget = new Utils::DetailsWidget(this); s.detailsWidget->setSummaryText(s.widget->summaryText()); s.detailsWidget->setWidget(s.widget); @@ -155,6 +158,7 @@ void BuildStepsPage::addBuildStepWidget(int pos, BuildStep *step) s.upButton->setArrowType(Qt::UpArrow); s.upButton->setMaximumHeight(22); s.upButton->setMaximumWidth(22); + s.downButton = new QToolButton(this); s.downButton->setArrowType(Qt::DownArrow); s.downButton->setMaximumHeight(22); @@ -209,8 +213,6 @@ void BuildStepsPage::addBuildStep() addBuildStepWidget(pos, newStep); const BuildStepsWidgetStruct s = m_buildSteps.at(pos); - s.widget->init(); - s.detailsWidget->setSummaryText(s.widget->summaryText()); s.detailsWidget->setExpanded(true); } diff --git a/src/plugins/projectexplorer/processstep.cpp b/src/plugins/projectexplorer/processstep.cpp index 910bece73d..b222893ca7 100644 --- a/src/plugins/projectexplorer/processstep.cpp +++ b/src/plugins/projectexplorer/processstep.cpp @@ -41,26 +41,46 @@ using namespace ProjectExplorer; using namespace ProjectExplorer::Internal; -static const char * const PROCESS_COMMAND = "abstractProcess.command"; -static const char * const PROCESS_WORKINGDIRECTORY = "abstractProcess.workingDirectory"; -static const char * const PROCESS_ARGUMENTS = "abstractProcess.arguments"; -static const char * const PROCESS_ENABLED = "abstractProcess.enabled"; +namespace { +const char * const PROCESS_STEP_ID("ProjectExplorer.ProcessStep"); -ProcessStep::ProcessStep(BuildConfiguration *bc) - : AbstractProcessStep(bc) +const char * const PROCESS_COMMAND_KEY("ProjectExplorer.ProcessStep.Command"); +const char * const PROCESS_WORKINGDIRECTORY_KEY("ProjectExplorer.ProcessStep.WorkingDirectory"); +const char * const PROCESS_ARGUMENTS_KEY("ProjectExplorer.ProcessStep.Arguments"); +const char * const PROCESS_ENABLED_KEY("ProjectExplorer.ProcessStep.Enabled"); +} + +ProcessStep::ProcessStep(BuildConfiguration *bc) : + AbstractProcessStep(bc, QLatin1String(PROCESS_STEP_ID)) { + ctor(); +} +ProcessStep::ProcessStep(BuildConfiguration *bc, const QString &id) : + AbstractProcessStep(bc, id) +{ + ctor(); +} + +ProcessStep::ProcessStep(BuildConfiguration *bc, ProcessStep *bs) : + AbstractProcessStep(bc, bs), + m_name(bs->m_name), + m_command(bs->m_command), + m_arguments(bs->m_arguments), + m_workingDirectory(bs->m_workingDirectory), + m_env(bs->m_env), + m_enabled(bs->m_enabled) +{ + ctor(); } -ProcessStep::ProcessStep(ProcessStep *bs, BuildConfiguration *bc) - : AbstractProcessStep(bs, bc) +void ProcessStep::ctor() +{ + setDisplayName(tr("Custom Process Step", "item in combobox")); +} + +ProcessStep::~ProcessStep() { - m_name = bs->m_name; - m_command = bs->m_command; - m_arguments = bs->m_arguments; - m_workingDirectory = bs->m_workingDirectory; - m_env = bs->m_env; - m_enabled = bs->m_enabled; } bool ProcessStep::init() @@ -83,61 +103,6 @@ void ProcessStep::run(QFutureInterface<bool> & fi) return AbstractProcessStep::run(fi); } -QString ProcessStep::id() -{ - return "projectexplorer.processstep"; -} - -void ProcessStep::restoreFromGlobalMap(const QVariantMap &map) -{ - QMap<QString, QVariant>::const_iterator it = map.constFind("ProjectExplorer.ProcessStep.DisplayName"); - if (it != map.constEnd()) - m_name = (*it).toString(); - ProjectExplorer::AbstractProcessStep::restoreFromGlobalMap(map); -} - -void ProcessStep::restoreFromLocalMap(const QVariantMap &map) -{ - // TODO checking for PROCESS_* - setCommand(map.value(PROCESS_COMMAND).toString()); - setWorkingDirectory(map.value(PROCESS_WORKINGDIRECTORY).toString()); - setArguments(map.value(PROCESS_ARGUMENTS).toStringList()); - setEnabled(map.value(PROCESS_ENABLED).toBool()); - - QMap<QString, QVariant>::const_iterator it = map.constFind("ProjectExplorer.ProcessStep.DisplayName"); - if (it != map.constEnd()) - m_name = (*it).toString(); - - ProjectExplorer::AbstractProcessStep::restoreFromLocalMap(map); -} - -void ProcessStep::storeIntoLocalMap(QVariantMap &map) -{ - map[PROCESS_COMMAND] = command(); - map[PROCESS_WORKINGDIRECTORY] = workingDirectory(); - map[PROCESS_ARGUMENTS] = arguments(); - map[PROCESS_ENABLED] = enabled(); - map["ProjectExplorer.ProcessStep.DisplayName"] = m_name; - ProjectExplorer::AbstractProcessStep::storeIntoLocalMap(map); -} - - -void ProcessStep::setDisplayName(const QString &name) -{ - if (name.isEmpty()) - m_name = QString::null; - else - m_name = name; -} - -QString ProcessStep::displayName() -{ - if (!m_name.isEmpty()) - return m_name; - else - return tr("Custom Process Step"); -} - BuildStepConfigWidget *ProcessStep::createConfigWidget() { return new ProcessStepConfigWidget(this); @@ -188,40 +153,91 @@ void ProcessStep::setWorkingDirectory(const QString &workingDirectory) m_workingDirectory = workingDirectory; } +QVariantMap ProcessStep::toMap() const +{ + QVariantMap map(AbstractProcessStep::toMap()); + map.insert(QLatin1String(PROCESS_COMMAND_KEY), command()); + map.insert(QLatin1String(PROCESS_ARGUMENTS_KEY), arguments()); + map.insert(QLatin1String(PROCESS_WORKINGDIRECTORY_KEY), workingDirectory()); + map.insert(QLatin1String(PROCESS_ENABLED_KEY), enabled()); + + return map; +} + +bool ProcessStep::fromMap(const QVariantMap &map) +{ + setCommand(map.value(QLatin1String(PROCESS_COMMAND_KEY)).toString()); + setArguments(map.value(QLatin1String(PROCESS_ARGUMENTS_KEY)).toStringList()); + setWorkingDirectory(map.value(QLatin1String(PROCESS_WORKINGDIRECTORY_KEY)).toString()); + setEnabled(map.value(QLatin1String(PROCESS_ENABLED_KEY), false).toBool()); + return AbstractProcessStep::fromMap(map); +} + //******* // ProcessStepFactory //******* ProcessStepFactory::ProcessStepFactory() { +} + +ProcessStepFactory::~ProcessStepFactory() +{ +} + +bool ProcessStepFactory::canCreate(BuildConfiguration *parent, const QString &id) const +{ + Q_UNUSED(parent); + return id == QLatin1String(PROCESS_STEP_ID); +} + +BuildStep *ProcessStepFactory::create(BuildConfiguration *parent, const QString &id) +{ + if (!canCreate(parent, id)) + return 0; + return new ProcessStep(parent); +} +bool ProcessStepFactory::canClone(BuildConfiguration *parent, BuildStep *bs) const +{ + return canCreate(parent, bs->id()); } -bool ProcessStepFactory::canCreate(const QString &id) const +BuildStep *ProcessStepFactory::clone(BuildConfiguration *parent, BuildStep *bs) { - return id == "projectexplorer.processstep"; + if (!canClone(parent, bs)) + return 0; + return new ProcessStep(parent, static_cast<ProcessStep *>(bs)); } -BuildStep *ProcessStepFactory::create(BuildConfiguration *bc, const QString &id) const +bool ProcessStepFactory::canRestore(BuildConfiguration *parent, const QVariantMap &map) const { - Q_UNUSED(id) - return new ProcessStep(bc); + QString id(ProjectExplorer::idFromMap(map)); + return canCreate(parent, id); } -BuildStep *ProcessStepFactory::clone(BuildStep *bs, BuildConfiguration *bc) const +BuildStep *ProcessStepFactory::restore(BuildConfiguration *parent, const QVariantMap &map) { - return new ProcessStep(static_cast<ProcessStep *>(bs), bc); + if (!canRestore(parent, map)) + return 0; + + ProcessStep *bs(new ProcessStep(parent)); + if (bs->fromMap(map)) + return bs; + delete bs; + return 0; } -QStringList ProcessStepFactory::canCreateForBuildConfiguration(BuildConfiguration *bc) const +QStringList ProcessStepFactory::availableCreationIds(BuildConfiguration *parent) const { - Q_UNUSED(bc) - return QStringList()<<"projectexplorer.processstep"; + Q_UNUSED(parent) + return QStringList() << QLatin1String(PROCESS_STEP_ID); } QString ProcessStepFactory::displayNameForId(const QString &id) const { - Q_UNUSED(id) - return ProcessStep::tr("Custom Process Step", "item in combobox"); + if (id == QLatin1String(PROCESS_STEP_ID)) + return ProcessStep::tr("Custom Process Step", "item in combobox"); + return QString(); } //******* diff --git a/src/plugins/projectexplorer/processstep.h b/src/plugins/projectexplorer/processstep.h index 7032f0d891..3a2fa69a08 100644 --- a/src/plugins/projectexplorer/processstep.h +++ b/src/plugins/projectexplorer/processstep.h @@ -36,41 +36,42 @@ namespace ProjectExplorer { -class Project; - namespace Internal { class ProcessStepFactory : public IBuildStepFactory { + Q_OBJECT + public: ProcessStepFactory(); - virtual bool canCreate(const QString &id) const; - virtual BuildStep *create(BuildConfiguration *bc, const QString &id) const; - virtual BuildStep *clone(BuildStep *bs, BuildConfiguration *bc) const; - virtual QStringList canCreateForBuildConfiguration(BuildConfiguration *pro) const; + ~ProcessStepFactory(); + + virtual QStringList availableCreationIds(BuildConfiguration *parent) const; virtual QString displayNameForId(const QString &id) const; + + virtual bool canCreate(BuildConfiguration *parent, const QString &id) const; + virtual BuildStep *create(BuildConfiguration *parent, const QString &id); + virtual bool canRestore(BuildConfiguration *parent, const QVariantMap &map) const; + virtual BuildStep *restore(BuildConfiguration *parent, const QVariantMap &map); + virtual bool canClone(BuildConfiguration *parent, BuildStep *product) const; + virtual BuildStep *clone(BuildConfiguration *parent, BuildStep *product); }; class ProcessStep : public ProjectExplorer::AbstractProcessStep { Q_OBJECT + friend class ProcessStepFactory; + public: - ProcessStep(BuildConfiguration *bc); - ProcessStep(ProcessStep *bs, BuildConfiguration *bc); + explicit ProcessStep(BuildConfiguration *bc); + virtual ~ProcessStep(); + virtual bool init(); virtual void run(QFutureInterface<bool> &); - virtual QString id(); - void setDisplayName(const QString &name); - virtual QString displayName(); virtual BuildStepConfigWidget *createConfigWidget(); virtual bool immutable() const; - virtual void restoreFromGlobalMap(const QMap<QString, QVariant> &map); - - virtual void restoreFromLocalMap(const QMap<QString, QVariant> &map); - virtual void storeIntoLocalMap(QMap<QString, QVariant> &map); - QString command() const; QStringList arguments() const; bool enabled() const; @@ -81,7 +82,17 @@ public: void setEnabled(bool enabled); void setWorkingDirectory(const QString &workingDirectory); + QVariantMap toMap() const; + +protected: + ProcessStep(BuildConfiguration *bc, ProcessStep *bs); + ProcessStep(BuildConfiguration *bc, const QString &id); + + bool fromMap(const QVariantMap &map); + private: + void ctor(); + QString m_name; QString m_command; QStringList m_arguments; diff --git a/src/plugins/projectexplorer/project.cpp b/src/plugins/projectexplorer/project.cpp index ddc5c71342..27ee707efc 100644 --- a/src/plugins/projectexplorer/project.cpp +++ b/src/plugins/projectexplorer/project.cpp @@ -175,8 +175,7 @@ void Project::saveSettingsImpl(PersistentSettingsWriter &writer) int buildstepnr = 0; foreach (BuildStep *buildStep, bcs.at(i)->buildSteps()) { - QMap<QString, QVariant> temp; - buildStep->storeIntoLocalMap(temp); + QVariantMap temp(buildStep->toMap()); writer.saveValue("buildconfiguration-" + QString::number(i) + "-buildstep" + QString().setNum(buildstepnr), temp); ++buildstepnr; } @@ -191,8 +190,7 @@ void Project::saveSettingsImpl(PersistentSettingsWriter &writer) int cleanstepnr = 0; foreach (BuildStep *cleanStep, bcs.at(i)->cleanSteps()) { - QMap<QString, QVariant> temp; - cleanStep->storeIntoLocalMap(temp); + QVariantMap temp(cleanStep->toMap()); writer.saveValue("buildconfiguration-" + QString::number(i) + "-cleanstep" + QString().setNum(cleanstepnr), temp); ++cleanstepnr; } @@ -234,22 +232,25 @@ bool Project::restoreSettingsImpl(PersistentSettingsReader &reader) int pos = 0; QStringList buildStepNames = buildStepsValueVariant.toStringList(); for (int buildstepnr = 0; buildstepnr < buildStepNames.size(); ++buildstepnr) { - const QString &buildStepName = buildStepNames.at(buildstepnr); + // TODO remove restoreFromGlobalMap after 2.0 + QVariantMap values(reader.restoreValue("buildstep" + QString().setNum(buildstepnr)).toMap()); + QVariantMap localValues(reader.restoreValue("buildconfiguration-" + buildConfigurationName + "-buildstep" + QString().setNum(buildstepnr)).toMap()); + + // override (global)values with what is found in localValues: + for (QVariantMap::const_iterator i = localValues.constBegin(); + i != localValues.constEnd(); ++i) + values.insert(i.key(), i.value()); + + values.insert("ProjectExplorer.ProjectConfiguration.Id", + buildStepNames.at(buildstepnr)); BuildStep *buildStep = 0; foreach (IBuildStepFactory *factory, buildStepFactories) { - if (factory->canCreate(buildStepName)) { - buildStep = factory->create(bc, buildStepName); + if (factory->canRestore(bc, values)) { + buildStep = factory->restore(bc, values); break; } } - // Restoring settings if (buildStep) { - // TODO remove restoreFromGlobalMap after 2.0 - QMap<QString, QVariant> buildStepValues = reader.restoreValue("buildstep" + QString().setNum(buildstepnr)).toMap(); - buildStep->restoreFromGlobalMap(buildStepValues); - buildStepValues = - reader.restoreValue("buildconfiguration-" + buildConfigurationName + "-buildstep" + QString().setNum(buildstepnr)).toMap(); - buildStep->restoreFromLocalMap(buildStepValues); bc->insertBuildStep(pos, buildStep); ++pos; } @@ -261,22 +262,27 @@ bool Project::restoreSettingsImpl(PersistentSettingsReader &reader) int pos = 0; QStringList cleanStepNames = cleanStepsValueVariant.toStringList(); for (int cleanstepnr = 0; cleanstepnr < cleanStepNames.size(); ++cleanstepnr) { - const QString &cleanStepName = cleanStepNames.at(cleanstepnr); + // TODO remove restoreFromGlobalMap after 2.0 + QVariantMap values(reader.restoreValue("cleanstep" + QString().setNum(cleanstepnr)).toMap()); + QVariantMap localValues(reader.restoreValue("buildconfiguration-" + buildConfigurationName + "-cleanstep" + QString().setNum(cleanstepnr)).toMap()); + + // override (global)values with what is found in localValues: + for (QVariantMap::const_iterator i = localValues.constBegin(); + i != localValues.constEnd(); ++i) + values.insert(i.key(), i.value()); + + values.insert("ProjectExplorer.ProjectConfiguration.Id", + cleanStepNames.at(cleanstepnr)); + BuildStep *cleanStep = 0; foreach (IBuildStepFactory *factory, buildStepFactories) { - if (factory->canCreate(cleanStepName)) { - cleanStep = factory->create(bc, cleanStepName); + if (factory->canRestore(bc, values)) { + cleanStep = factory->restore(bc, values); break; } } - // Restoring settings if (cleanStep) { // TODO remove restoreFromGlobalMap after 2.0 - QMap<QString, QVariant> buildStepValues = reader.restoreValue("cleanstep" + QString().setNum(cleanstepnr)).toMap(); - cleanStep->restoreFromGlobalMap(buildStepValues); - buildStepValues = - reader.restoreValue("buildconfiguration-" + buildConfigurationName + "-cleanstep" + QString().setNum(cleanstepnr)).toMap(); - cleanStep->restoreFromLocalMap(buildStepValues); bc->insertCleanStep(pos, cleanStep); ++pos; } @@ -298,6 +304,8 @@ bool Project::restoreSettingsImpl(PersistentSettingsReader &reader) } //Build Settings + QList<BuildConfiguration *> bcs(buildConfigurations()); + QVariant buildStepsVariant = reader.restoreValue("buildsteps"); if (buildStepsVariant.isValid()) { // Old code path for 1.3 compatibility @@ -305,27 +313,31 @@ bool Project::restoreSettingsImpl(PersistentSettingsReader &reader) int pos = 0; QStringList buildStepNames = buildStepsVariant.toStringList(); for (int buildstepnr = 0; buildstepnr < buildStepNames.size(); ++buildstepnr) { - const QString &buildStepName = buildStepNames.at(buildstepnr); - BuildStep *buildStep = 0; - IBuildStepFactory *factory = 0; - foreach (IBuildStepFactory *fac, buildStepFactories) { - if (fac->canCreate(buildStepName)) { - factory = fac; - break; + QVariantMap values(reader.restoreValue("cleanstep" + QString().setNum(buildstepnr)).toMap()); + for (int i = 0; i < bcs.size(); ++i) { + BuildConfiguration *bc = bcs.at(i); + BuildStep *buildStep = 0; + + QVariantMap localValues(reader.restoreValue("buildconfiguration-" + QString::number(pos) + "-cleanstep" + QString().setNum(buildstepnr)).toMap()); + + // override (global)values with what is found in localValues: + for (QVariantMap::const_iterator i = localValues.constBegin(); + i != localValues.constEnd(); ++i) + values.insert(i.key(), i.value()); + + values.insert("ProjectExplorer.ProjectConfiguration.Id", + buildStepNames.at(buildstepnr)); + + foreach (IBuildStepFactory *factory, buildStepFactories) { + if (factory->canRestore(bc, values)) { + buildStep = factory->restore(bc, values); + break; + } } - } - if (factory) { - const QList<BuildConfiguration *> &bcs = buildConfigurations(); - for(int i = 0; i < bcs.size(); ++i) { - buildStep = factory->create(bcs.at(i), buildStepName); - bcs.at(i)->insertBuildStep(pos, buildStep); - QMap<QString, QVariant> buildStepValues = reader.restoreValue("buildstep" + QString().setNum(buildstepnr)).toMap(); - buildStep->restoreFromGlobalMap(buildStepValues); - buildStepValues = - reader.restoreValue("buildconfiguration-" + QString::number(i) + "-buildstep" + QString().setNum(buildstepnr)).toMap(); - buildStep->restoreFromLocalMap(buildStepValues); + if (buildStep) { + bc->insertBuildStep(pos, buildStep); + ++pos; } - ++pos; } } } @@ -337,28 +349,31 @@ bool Project::restoreSettingsImpl(PersistentSettingsReader &reader) // restoring BuildSteps from settings int pos = 0; for (int cleanstepnr = 0; cleanstepnr < cleanStepNames.size(); ++cleanstepnr) { - const QString &cleanStepName = cleanStepNames.at(cleanstepnr); - BuildStep *cleanStep = 0; - IBuildStepFactory *factory = 0; - foreach (IBuildStepFactory *fac, buildStepFactories) { - if (fac->canCreate(cleanStepName)) { - factory = fac; - break; - } - } + QVariantMap values(reader.restoreValue("cleanstep" + QString().setNum(cleanstepnr)).toMap()); + QVariantMap localValues(reader.restoreValue("buildconfiguration-" + QString::number(pos) + "-cleanstep" + QString().setNum(cleanstepnr)).toMap()); + + // override (global)values with what is found in localValues: + for (QVariantMap::const_iterator i = localValues.constBegin(); + i != localValues.constEnd(); ++i) + values.insert(i.key(), i.value()); + + values.insert("ProjectExplorer.ProjectConfiguration.Id", + cleanStepNames.at(cleanstepnr)); + + for (int i = 0; i < bcs.size(); ++i) { + BuildConfiguration *bc = bcs.at(i); + BuildStep *cleanStep = 0; - if (factory) { - const QList<BuildConfiguration *> &bcs = buildConfigurations(); - for (int i = 0; i < bcs.size(); ++i) { - cleanStep = factory->create(bcs.at(i), cleanStepName); - bcs.at(i)->insertCleanStep(pos, cleanStep); - QMap<QString, QVariant> cleanStepValues = reader.restoreValue("cleanstep" + QString().setNum(cleanstepnr)).toMap(); - cleanStep->restoreFromGlobalMap(cleanStepValues); - QMap<QString, QVariant> buildStepValues = - reader.restoreValue("buildconfiguration-" + QString::number(i) + "-cleanstep" + QString().setNum(cleanstepnr)).toMap(); - cleanStep->restoreFromLocalMap(buildStepValues); + foreach (IBuildStepFactory *factory, buildStepFactories) { + if (factory->canRestore(bc, values)) { + cleanStep = factory->restore(bc, values); + break; + } + } + if (cleanStep) { + bc->insertCleanStep(pos, cleanStep); + ++pos; } - ++pos; } } } diff --git a/src/plugins/qt4projectmanager/makestep.cpp b/src/plugins/qt4projectmanager/makestep.cpp index 9166293ac1..3b791d1f21 100644 --- a/src/plugins/qt4projectmanager/makestep.cpp +++ b/src/plugins/qt4projectmanager/makestep.cpp @@ -43,24 +43,44 @@ using ExtensionSystem::PluginManager; using namespace Qt4ProjectManager; using namespace Qt4ProjectManager::Internal; +namespace { +const char * const MAKESTEP_BS_ID("Qt4ProjectManager.MakeStep"); + +const char * const MAKE_ARGUMENTS_KEY("Qt4ProjectManager.MakeStep.MakeArguments"); +const char * const MAKE_COMMAND_KEY("Qt4ProjectManager.MakeStep.MakeCommand"); +const char * const CLEAN_KEY("Qt4ProjectManager.MakeStep.Clean"); +} + MakeStep::MakeStep(ProjectExplorer::BuildConfiguration *bc) : - AbstractProcessStep(bc), m_clean(false) + AbstractProcessStep(bc, QLatin1String(MAKESTEP_BS_ID)), + m_clean(false) { - + ctor(); } -MakeStep::MakeStep(MakeStep *bs, ProjectExplorer::BuildConfiguration *bc) : - AbstractProcessStep(bs, bc), +MakeStep::MakeStep(ProjectExplorer::BuildConfiguration *bc, MakeStep *bs) : + AbstractProcessStep(bc, bs), m_clean(bs->m_clean), m_userArgs(bs->m_userArgs), m_makeCmd(bs->m_makeCmd) { + ctor(); +} +MakeStep::MakeStep(ProjectExplorer::BuildConfiguration *bc, const QString &id) : + AbstractProcessStep(bc, id), + m_clean(false) +{ + ctor(); } -MakeStep::~MakeStep() +void MakeStep::ctor() { + setDisplayName(tr("Make", "Qt4 MakeStep display name.")); +} +MakeStep::~MakeStep() +{ } Qt4BuildConfiguration *MakeStep::qt4BuildConfiguration() const @@ -73,29 +93,22 @@ void MakeStep::setClean(bool clean) m_clean = clean; } -void MakeStep::restoreFromGlobalMap(const QMap<QString, QVariant> &map) +QVariantMap MakeStep::toMap() const { - if (map.value("clean").isValid() && map.value("clean").toBool()) - m_clean = true; - ProjectExplorer::AbstractProcessStep::restoreFromGlobalMap(map); + QVariantMap map(ProjectExplorer::AbstractProcessStep::toMap()); + map.insert(QLatin1String(MAKE_ARGUMENTS_KEY), m_userArgs); + map.insert(QLatin1String(MAKE_COMMAND_KEY), m_makeCmd); + map.insert(QLatin1String(CLEAN_KEY), m_clean); + return map; } -void MakeStep::restoreFromLocalMap(const QMap<QString, QVariant> &map) +bool MakeStep::fromMap(const QVariantMap &map) { - m_userArgs = map.value("makeargs").toStringList(); - m_makeCmd = map.value("makeCmd").toString(); - if (map.value("clean").isValid() && map.value("clean").toBool()) - m_clean = true; - ProjectExplorer::AbstractProcessStep::restoreFromLocalMap(map); -} + m_makeCmd = map.value(QLatin1String(MAKE_COMMAND_KEY)).toString(); + m_userArgs = map.value(QLatin1String(MAKE_ARGUMENTS_KEY)).toStringList(); + m_clean = map.value(QLatin1String(CLEAN_KEY)).toBool(); -void MakeStep::storeIntoLocalMap(QMap<QString, QVariant> &map) -{ - map["makeargs"] = m_userArgs; - map["makeCmd"] = m_makeCmd; - if (m_clean) - map["clean"] = true; - ProjectExplorer::AbstractProcessStep::storeIntoLocalMap(map); + return BuildStep::fromMap(map); } bool MakeStep::init() @@ -170,16 +183,6 @@ void MakeStep::run(QFutureInterface<bool> & fi) AbstractProcessStep::run(fi); } -QString MakeStep::id() -{ - return Constants::MAKESTEP; -} - -QString MakeStep::displayName() -{ - return QLatin1String("Make"); -} - bool MakeStep::immutable() const { return false; @@ -310,10 +313,11 @@ void MakeStepConfigWidget::makeArgumentsLineEdited() } /// -// MakeStep +// MakeStepFactory /// -MakeStepFactory::MakeStepFactory() +MakeStepFactory::MakeStepFactory(QObject *parent) : + ProjectExplorer::IBuildStepFactory(parent) { } @@ -321,32 +325,59 @@ MakeStepFactory::~MakeStepFactory() { } -bool MakeStepFactory::canCreate(const QString &id) const +bool MakeStepFactory::canCreate(ProjectExplorer::BuildConfiguration *parent, const QString &id) const { - return (id == Constants::MAKESTEP); + if (!qobject_cast<Qt4BuildConfiguration *>(parent)) + return false; + return (id == QLatin1String(MAKESTEP_BS_ID)); } -ProjectExplorer::BuildStep *MakeStepFactory::create(ProjectExplorer::BuildConfiguration *bc, const QString &id) const +ProjectExplorer::BuildStep *MakeStepFactory::create(ProjectExplorer::BuildConfiguration *parent, const QString &id) { - Q_UNUSED(id); - return new MakeStep(bc); + if (!canCreate(parent, id)) + return 0; + return new MakeStep(parent); } -ProjectExplorer::BuildStep *MakeStepFactory::clone(ProjectExplorer::BuildStep *bs, ProjectExplorer::BuildConfiguration *bc) const +bool MakeStepFactory::canClone(ProjectExplorer::BuildConfiguration *parent, ProjectExplorer::BuildStep *source) const { - return new MakeStep(static_cast<MakeStep *>(bs), bc); + return canCreate(parent, source->id()); } -QStringList MakeStepFactory::canCreateForBuildConfiguration(ProjectExplorer::BuildConfiguration *pro) const +ProjectExplorer::BuildStep *MakeStepFactory::clone(ProjectExplorer::BuildConfiguration *parent, ProjectExplorer::BuildStep *source) { - if (qobject_cast<Qt4BuildConfiguration *>(pro)) - return QStringList() << Constants::MAKESTEP; - else - return QStringList(); + if (!canClone(parent, source)) + return 0; + return new MakeStep(parent, static_cast<MakeStep *>(source)); +} + +bool MakeStepFactory::canRestore(ProjectExplorer::BuildConfiguration *parent, const QVariantMap &map) const +{ + QString id(ProjectExplorer::idFromMap(map)); + return canCreate(parent, id); +} + +ProjectExplorer::BuildStep *MakeStepFactory::restore(ProjectExplorer::BuildConfiguration *parent, const QVariantMap &map) +{ + if (!canRestore(parent, map)) + return 0; + MakeStep *bs(new MakeStep(parent)); + if (bs->fromMap(map)) + return bs; + delete bs; + return 0; +} + +QStringList MakeStepFactory::availableCreationIds(ProjectExplorer::BuildConfiguration *parent) const +{ + if (qobject_cast<Qt4BuildConfiguration *>(parent)) + return QStringList() << QLatin1String(MAKESTEP_BS_ID); + return QStringList(); } QString MakeStepFactory::displayNameForId(const QString &id) const { - Q_UNUSED(id); - return tr("Make"); + if (id == QLatin1String(MAKESTEP_BS_ID)) + return tr("Make"); + return QString(); } diff --git a/src/plugins/qt4projectmanager/makestep.h b/src/plugins/qt4projectmanager/makestep.h index 2626acaf5f..f341bac6fb 100644 --- a/src/plugins/qt4projectmanager/makestep.h +++ b/src/plugins/qt4projectmanager/makestep.h @@ -49,13 +49,19 @@ class Qt4BuildConfiguration; class MakeStepFactory : public ProjectExplorer::IBuildStepFactory { Q_OBJECT + public: - MakeStepFactory(); + explicit MakeStepFactory(QObject *parent = 0); virtual ~MakeStepFactory(); - bool canCreate(const QString &id) const; - ProjectExplorer::BuildStep *create(ProjectExplorer::BuildConfiguration *bc, const QString &id) const; - ProjectExplorer::BuildStep *clone(ProjectExplorer::BuildStep *bs, ProjectExplorer::BuildConfiguration *bc) const; - QStringList canCreateForBuildConfiguration(ProjectExplorer::BuildConfiguration *bc) const; + + bool canCreate(ProjectExplorer::BuildConfiguration *parent, const QString &id) const; + ProjectExplorer::BuildStep *create(ProjectExplorer::BuildConfiguration *parent, const QString &id); + bool canClone(ProjectExplorer::BuildConfiguration *parent, ProjectExplorer::BuildStep *source) const; + ProjectExplorer::BuildStep *clone(ProjectExplorer::BuildConfiguration *parent, ProjectExplorer::BuildStep *source); + bool canRestore(ProjectExplorer::BuildConfiguration *parent, const QVariantMap &map) const; + ProjectExplorer::BuildStep *restore(ProjectExplorer::BuildConfiguration *parent, const QVariantMap &map); + + QStringList availableCreationIds(ProjectExplorer::BuildConfiguration *parent) const; QString displayNameForId(const QString &id) const; }; } //namespace Internal @@ -65,33 +71,36 @@ class Qt4Project; class MakeStep : public ProjectExplorer::AbstractProcessStep { Q_OBJECT + friend class Internal::MakeStepFactory; friend class MakeStepConfigWidget; // TODO remove this // used to access internal stuff + public: - MakeStep(ProjectExplorer::BuildConfiguration *bc); - MakeStep(MakeStep *bs, ProjectExplorer::BuildConfiguration *bc); - ~MakeStep(); + explicit MakeStep(ProjectExplorer::BuildConfiguration *bc); + virtual ~MakeStep(); Internal::Qt4BuildConfiguration *qt4BuildConfiguration() const; virtual bool init(); virtual void run(QFutureInterface<bool> &); - virtual QString id(); - virtual QString displayName(); virtual ProjectExplorer::BuildStepConfigWidget *createConfigWidget(); virtual bool immutable() const; QStringList userArguments(); void setUserArguments(const QStringList &arguments); void setClean(bool clean); - virtual void restoreFromGlobalMap(const QMap<QString, QVariant> &map); - - virtual void restoreFromLocalMap(const QMap<QString, QVariant> &map); - virtual void storeIntoLocalMap(QMap<QString, QVariant> &map); + QVariantMap toMap() const; signals: void userArgumentsChanged(); + +protected: + MakeStep(ProjectExplorer::BuildConfiguration *bc, MakeStep *bs); + MakeStep(ProjectExplorer::BuildConfiguration *bc, const QString &id); + virtual bool fromMap(const QVariantMap &map); + private: + void ctor(); bool m_clean; QStringList m_userArgs; QString m_makeCmd; diff --git a/src/plugins/qt4projectmanager/qmakestep.cpp b/src/plugins/qt4projectmanager/qmakestep.cpp index 91d1663871..48d001ea77 100644 --- a/src/plugins/qt4projectmanager/qmakestep.cpp +++ b/src/plugins/qt4projectmanager/qmakestep.cpp @@ -46,16 +46,37 @@ using namespace Qt4ProjectManager; using namespace Qt4ProjectManager::Internal; using namespace ProjectExplorer; -QMakeStep::QMakeStep(ProjectExplorer::BuildConfiguration *bc) : - AbstractProcessStep(bc), m_forced(false) +namespace { +const char * const QMAKE_BS_ID("QtProjectManager.QMakeBuildStep"); + +const char * const QMAKE_ARGUMENTS_KEY("QtProjectManager.QMakeBuildStep.QMakeArguments"); +} + +QMakeStep::QMakeStep(Qt4BuildConfiguration *bc) : + AbstractProcessStep(bc, QLatin1String(QMAKE_BS_ID)), + m_forced(false) { + ctor(); } -QMakeStep::QMakeStep(QMakeStep *bs, ProjectExplorer::BuildConfiguration *bc) : - AbstractProcessStep(bs, bc), +QMakeStep::QMakeStep(Qt4BuildConfiguration *bc, const QString &id) : + AbstractProcessStep(bc, id), + m_forced(false) +{ + ctor(); +} + +QMakeStep::QMakeStep(Qt4BuildConfiguration *bc, QMakeStep *bs) : + AbstractProcessStep(bc, bs), m_forced(false), m_userArgs(bs->m_userArgs) { + ctor(); +} + +void QMakeStep::ctor() +{ + setDisplayName(tr("QMake", "QMakeStep display name.")); } QMakeStep::~QMakeStep() @@ -172,16 +193,6 @@ void QMakeStep::run(QFutureInterface<bool> &fi) AbstractProcessStep::run(fi); } -QString QMakeStep::id() -{ - return QLatin1String(Constants::QMAKESTEP); -} - -QString QMakeStep::displayName() -{ - return QLatin1String("QMake"); -} - void QMakeStep::setForced(bool b) { m_forced = b; @@ -232,16 +243,18 @@ QStringList QMakeStep::userArguments() return m_userArgs; } -void QMakeStep::restoreFromLocalMap(const QMap<QString, QVariant> &map) +QVariantMap QMakeStep::toMap() const { - m_userArgs = map.value("qmakeArgs").toStringList(); - AbstractProcessStep::restoreFromLocalMap(map); + QVariantMap map(AbstractProcessStep::toMap()); + map.insert(QLatin1String(QMAKE_ARGUMENTS_KEY), m_userArgs); + return map; } -void QMakeStep::storeIntoLocalMap(QMap<QString, QVariant> &map) +bool QMakeStep::fromMap(const QVariantMap &map) { - map["qmakeArgs"] = m_userArgs; - AbstractProcessStep::storeIntoLocalMap(map); + m_userArgs = map.value(QLatin1String(QMAKE_ARGUMENTS_KEY)).toStringList(); + + return BuildStep::fromMap(map); } //// @@ -382,7 +395,8 @@ void QMakeStepConfigWidget::updateEffectiveQMakeCall() // QMakeStepFactory //// -QMakeStepFactory::QMakeStepFactory() +QMakeStepFactory::QMakeStepFactory(QObject *parent) : + ProjectExplorer::IBuildStepFactory(parent) { } @@ -390,34 +404,66 @@ QMakeStepFactory::~QMakeStepFactory() { } -bool QMakeStepFactory::canCreate(const QString &id) const +bool QMakeStepFactory::canCreate(BuildConfiguration *parent, const QString &id) const { - return (id == Constants::QMAKESTEP); + if (!qobject_cast<Qt4BuildConfiguration *>(parent)) + return false; + return (id == QLatin1String(QMAKE_BS_ID)); } -ProjectExplorer::BuildStep *QMakeStepFactory::create(BuildConfiguration *bc, const QString &id) const +ProjectExplorer::BuildStep *QMakeStepFactory::create(BuildConfiguration *parent, const QString &id) { - Q_UNUSED(id); + if (!canCreate(parent, id)) + return 0; + Qt4BuildConfiguration *bc(qobject_cast<Qt4BuildConfiguration *>(parent)); + Q_ASSERT(bc); return new QMakeStep(bc); } -ProjectExplorer::BuildStep *QMakeStepFactory::clone(ProjectExplorer::BuildStep *bs, ProjectExplorer::BuildConfiguration *bc) const +bool QMakeStepFactory::canClone(BuildConfiguration *parent, BuildStep *source) const { - return new QMakeStep(static_cast<QMakeStep *>(bs), bc); + return canCreate(parent, source->id()); } -QStringList QMakeStepFactory::canCreateForBuildConfiguration(ProjectExplorer::BuildConfiguration *bc) const +ProjectExplorer::BuildStep *QMakeStepFactory::clone(ProjectExplorer::BuildConfiguration *parent, ProjectExplorer::BuildStep *source) { - if (Qt4BuildConfiguration *qt4bc = qobject_cast<Qt4BuildConfiguration *>(bc)) - if (!qt4bc->qmakeStep()) - return QStringList() << Constants::QMAKESTEP; - return QStringList(); + if (!canClone(parent, source)) + return 0; + Qt4BuildConfiguration *bc(qobject_cast<Qt4BuildConfiguration *>(parent)); + Q_ASSERT(bc); + return new QMakeStep(bc, qobject_cast<QMakeStep *>(source)); } -QString QMakeStepFactory::displayNameForId(const QString &id) const +bool QMakeStepFactory::canRestore(ProjectExplorer::BuildConfiguration *parent, const QVariantMap &map) const +{ + QString id(ProjectExplorer::idFromMap(map)); + return canCreate(parent, id); +} + +ProjectExplorer::BuildStep *QMakeStepFactory::restore(ProjectExplorer::BuildConfiguration *parent, const QVariantMap &map) { - Q_UNUSED(id); - return tr("QMake"); + if (!canRestore(parent, map)) + return 0; + Qt4BuildConfiguration *bc(qobject_cast<Qt4BuildConfiguration *>(parent)); + Q_ASSERT(bc); + QMakeStep *bs(new QMakeStep(bc)); + if (bs->fromMap(map)) + return bs; + delete bs; + return 0; } +QStringList QMakeStepFactory::availableCreationIds(ProjectExplorer::BuildConfiguration *parent) const +{ + if (Qt4BuildConfiguration *bc = qobject_cast<Qt4BuildConfiguration *>(parent)) + if (!bc->qmakeStep()) + return QStringList() << QLatin1String(QMAKE_BS_ID); + return QStringList(); +} +QString QMakeStepFactory::displayNameForId(const QString &id) const +{ + if (id == QLatin1String(QMAKE_BS_ID)) + return tr("QMake"); + return QString(); +} diff --git a/src/plugins/qt4projectmanager/qmakestep.h b/src/plugins/qt4projectmanager/qmakestep.h index 53fa52d2e8..009f9be0b1 100644 --- a/src/plugins/qt4projectmanager/qmakestep.h +++ b/src/plugins/qt4projectmanager/qmakestep.h @@ -51,13 +51,17 @@ class Qt4BuildConfiguration; class QMakeStepFactory : public ProjectExplorer::IBuildStepFactory { Q_OBJECT + public: - QMakeStepFactory(); + explicit QMakeStepFactory(QObject *parent = 0); virtual ~QMakeStepFactory(); - bool canCreate(const QString & id) const; - ProjectExplorer::BuildStep *create(ProjectExplorer::BuildConfiguration *bc, const QString &id) const; - ProjectExplorer::BuildStep *clone(ProjectExplorer::BuildStep *bs, ProjectExplorer::BuildConfiguration *bc) const; - QStringList canCreateForBuildConfiguration(ProjectExplorer::BuildConfiguration *bc) const; + bool canCreate(ProjectExplorer::BuildConfiguration *parent, const QString & id) const; + ProjectExplorer::BuildStep *create(ProjectExplorer::BuildConfiguration *parent, const QString &id); + bool canClone(ProjectExplorer::BuildConfiguration *parent, ProjectExplorer::BuildStep *bs) const; + ProjectExplorer::BuildStep *clone(ProjectExplorer::BuildConfiguration *parent, ProjectExplorer::BuildStep *bs); + bool canRestore(ProjectExplorer::BuildConfiguration *parent, const QVariantMap &map) const; + ProjectExplorer::BuildStep *restore(ProjectExplorer::BuildConfiguration *parent, const QVariantMap &map); + QStringList availableCreationIds(ProjectExplorer::BuildConfiguration *bc) const; QString displayNameForId(const QString &id) const; }; @@ -67,15 +71,15 @@ public: class QMakeStep : public ProjectExplorer::AbstractProcessStep { Q_OBJECT + friend class Internal::QMakeStepFactory; + public: - QMakeStep(ProjectExplorer::BuildConfiguration *bc); - QMakeStep(QMakeStep *bs, ProjectExplorer::BuildConfiguration *bc); - ~QMakeStep(); + explicit QMakeStep(Internal::Qt4BuildConfiguration *parent); + virtual ~QMakeStep(); + Internal::Qt4BuildConfiguration *qt4BuildConfiguration() const; virtual bool init(); virtual void run(QFutureInterface<bool> &); - virtual QString id(); - virtual QString displayName(); virtual ProjectExplorer::BuildStepConfigWidget *createConfigWidget(); virtual bool immutable() const; void setForced(bool b); @@ -85,17 +89,22 @@ public: QStringList userArguments(); void setUserArguments(const QStringList &arguments); - virtual void restoreFromLocalMap(const QMap<QString, QVariant> &map); - virtual void storeIntoLocalMap(QMap<QString, QVariant> &map); + QVariantMap toMap() const; signals: void userArgumentsChanged(); protected: + QMakeStep(Internal::Qt4BuildConfiguration *parent, QMakeStep *source); + QMakeStep(Internal::Qt4BuildConfiguration *parent, const QString &id); + virtual bool fromMap(const QVariantMap &map); + virtual void processStartupFailed(); virtual bool processFinished(int exitCode, QProcess::ExitStatus status); private: + void ctor(); + // last values QStringList m_lastEnv; bool m_forced; |