summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authorhjk <hjk121@nokiamail.com>2014-10-22 18:16:51 +0200
committerhjk <hjk121@nokiamail.com>2014-10-23 12:59:02 +0200
commit8eb08db536f7e06df364689b963be105ce57b7ac (patch)
tree7cc9bd4d4ef8b71a402cb4364ea2d16a418ccfa9 /src/plugins
parent3ce62fc59e8fdda33e254d57fdd39480c77097dd (diff)
downloadqt-creator-8eb08db536f7e06df364689b963be105ce57b7ac.tar.gz
Add MacroExpander member to ProjectConfiguration
Some derived classes already had one, at times. Make it uniformly accessible in the base class. Change-Id: Iccb7ebf9d163daba46a01ae5de150af4a883fad6 Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/projectexplorer/buildconfiguration.cpp48
-rw-r--r--src/plugins/projectexplorer/buildconfiguration.h6
-rw-r--r--src/plugins/projectexplorer/localapplicationrunconfiguration.cpp49
-rw-r--r--src/plugins/projectexplorer/localapplicationrunconfiguration.h9
-rw-r--r--src/plugins/projectexplorer/projectconfiguration.h5
5 files changed, 49 insertions, 68 deletions
diff --git a/src/plugins/projectexplorer/buildconfiguration.cpp b/src/plugins/projectexplorer/buildconfiguration.cpp
index b48d21e7b3..7ae211d4a7 100644
--- a/src/plugins/projectexplorer/buildconfiguration.cpp
+++ b/src/plugins/projectexplorer/buildconfiguration.cpp
@@ -58,8 +58,7 @@ namespace ProjectExplorer {
BuildConfiguration::BuildConfiguration(Target *target, Core::Id id) :
ProjectConfiguration(target, id),
- m_clearSystemEnvironment(false),
- m_macroExpander(0)
+ m_clearSystemEnvironment(false)
{
Q_ASSERT(target);
BuildStepList *bsl = new BuildStepList(this, Core::Id(Constants::BUILDSTEPS_BUILD));
@@ -82,7 +81,6 @@ BuildConfiguration::BuildConfiguration(Target *target, BuildConfiguration *sourc
ProjectConfiguration(target, source),
m_clearSystemEnvironment(source->m_clearSystemEnvironment),
m_userEnvironmentChanges(source->m_userEnvironmentChanges),
- m_macroExpander(0),
m_buildDirectory(source->m_buildDirectory)
{
Q_ASSERT(target);
@@ -96,9 +94,31 @@ BuildConfiguration::BuildConfiguration(Target *target, BuildConfiguration *sourc
this, SLOT(handleKitUpdate()));
}
+void BuildConfiguration::setupMacroExpander()
+{
+ Utils::MacroExpander *expander = macroExpander();
+
+ expander->registerSubProvider(
+ [this] { return target()->kit()->macroExpander(); });
+
+ // Legacy support.
+ expander->registerVariable(Constants::VAR_CURRENTPROJECT_NAME,
+ QCoreApplication::translate("ProjectExplorer", "Name of current project"),
+ [this] { return target()->project()->displayName(); });
+
+ expander->registerVariable(Constants::VAR_CURRENTBUILD_NAME,
+ QCoreApplication::translate("ProjectExplorer", "Name of current build"),
+ [this] { return displayName(); });
+
+ expander->registerVariable("sourceDir", tr("Source directory"),
+ [this] { return target()->project()->projectDirectory().toUserOutput(); });
+
+ expander->registerVariable("buildDir", tr("Build directory"),
+ [this] { return buildDirectory().toUserOutput(); });
+}
+
BuildConfiguration::~BuildConfiguration()
{
- delete m_macroExpander;
}
Utils::FileName BuildConfiguration::buildDirectory() const
@@ -123,26 +143,6 @@ QList<NamedWidget *> BuildConfiguration::createSubConfigWidgets()
return QList<NamedWidget *>() << new BuildEnvironmentWidget(this);
}
-Utils::MacroExpander *BuildConfiguration::macroExpander()
-{
- if (!m_macroExpander) {
- m_macroExpander = new ProjectMacroExpander(target()->project()->displayName(),
- target()->kit(), displayName());
-
- m_macroExpander->registerSubProvider(
- [this]() { return target()->kit()->macroExpander(); });
-
- // Legacy support.
- m_macroExpander->registerVariable("sourceDir", tr("Source directory"),
- [this]() { return target()->project()->projectDirectory().toUserOutput(); });
-
- m_macroExpander->registerVariable("buildDir", tr("Build directory"),
- [this]() { return buildDirectory().toUserOutput(); });
- }
-
- return m_macroExpander;
-}
-
QList<Core::Id> BuildConfiguration::knownStepLists() const
{
return Utils::transform(m_stepLists, &BuildStepList::id);
diff --git a/src/plugins/projectexplorer/buildconfiguration.h b/src/plugins/projectexplorer/buildconfiguration.h
index be9e64d988..283b33a4e8 100644
--- a/src/plugins/projectexplorer/buildconfiguration.h
+++ b/src/plugins/projectexplorer/buildconfiguration.h
@@ -37,8 +37,6 @@
#include <utils/environment.h>
#include <utils/fileutils.h>
-namespace Utils { class MacroExpander; }
-
namespace ProjectExplorer {
class BuildConfiguration;
@@ -83,8 +81,6 @@ public:
virtual bool isEnabled() const;
virtual QString disabledReason() const;
- Utils::MacroExpander *macroExpander();
-
enum BuildType {
Unknown,
Debug,
@@ -111,11 +107,11 @@ private slots:
private:
void emitEnvironmentChanged();
+ void setupMacroExpander();
bool m_clearSystemEnvironment;
QList<Utils::EnvironmentItem> m_userEnvironmentChanges;
QList<BuildStepList *> m_stepLists;
- Utils::MacroExpander *m_macroExpander;
Utils::FileName m_buildDirectory;
Utils::FileName m_lastEmmitedBuildDirectory;
mutable Utils::Environment m_cachedEnvironment;
diff --git a/src/plugins/projectexplorer/localapplicationrunconfiguration.cpp b/src/plugins/projectexplorer/localapplicationrunconfiguration.cpp
index fc770440d2..6c02c78c3c 100644
--- a/src/plugins/projectexplorer/localapplicationrunconfiguration.cpp
+++ b/src/plugins/projectexplorer/localapplicationrunconfiguration.cpp
@@ -40,40 +40,21 @@
#include <QDir>
namespace ProjectExplorer {
-namespace Internal {
-class FallBackMacroExpander : public Utils::MacroExpander
-{
-public:
- explicit FallBackMacroExpander(const Target *target) : m_target(target) {}
- virtual bool resolveMacro(const QString &name, QString *ret) const;
-private:
- const Target *m_target;
-};
-
-bool FallBackMacroExpander::resolveMacro(const QString &name, QString *ret) const
+LocalApplicationRunConfiguration::LocalApplicationRunConfiguration(Target *target, Core::Id id) :
+ RunConfiguration(target, id)
{
- if (name == QLatin1String("sourceDir")) {
- *ret = m_target->project()->projectDirectory().toUserOutput();
- return true;
- }
- return false;
+ setupMacroExpander();
}
-} // namespace Internal
-
-/// LocalApplicationRunConfiguration
-
-LocalApplicationRunConfiguration::LocalApplicationRunConfiguration(Target *target, Core::Id id) :
- RunConfiguration(target, id), m_macroExpander(0)
-{ }
LocalApplicationRunConfiguration::LocalApplicationRunConfiguration(Target *target, LocalApplicationRunConfiguration *rc) :
- RunConfiguration(target, rc), m_macroExpander(0)
-{ }
+ RunConfiguration(target, rc)
+{
+ setupMacroExpander();
+}
LocalApplicationRunConfiguration::~LocalApplicationRunConfiguration()
{
- delete m_macroExpander;
}
void LocalApplicationRunConfiguration::addToBaseEnvironment(Utils::Environment &env) const
@@ -81,13 +62,17 @@ void LocalApplicationRunConfiguration::addToBaseEnvironment(Utils::Environment &
Q_UNUSED(env);
}
-Utils::MacroExpander *LocalApplicationRunConfiguration::macroExpander() const
+void LocalApplicationRunConfiguration::setupMacroExpander()
{
- if (BuildConfiguration *bc = activeBuildConfiguration())
- return bc->macroExpander();
- if (!m_macroExpander)
- m_macroExpander = new Internal::FallBackMacroExpander(target());
- return m_macroExpander;
+ // Legacy
+ macroExpander()->registerSubProvider([this]() -> Utils::MacroExpander * {
+ if (BuildConfiguration *bc = activeBuildConfiguration())
+ return bc->macroExpander();
+ return 0;
+ });
+
+ macroExpander()->registerVariable("sourceDir", tr("Project source directory"),
+ [this] { return target()->project()->projectDirectory().toUserOutput(); });
}
} // namespace ProjectExplorer
diff --git a/src/plugins/projectexplorer/localapplicationrunconfiguration.h b/src/plugins/projectexplorer/localapplicationrunconfiguration.h
index b2d75cf43f..d9b6d15dac 100644
--- a/src/plugins/projectexplorer/localapplicationrunconfiguration.h
+++ b/src/plugins/projectexplorer/localapplicationrunconfiguration.h
@@ -34,10 +34,7 @@
#include "runconfiguration.h"
#include "applicationlauncher.h"
-namespace Utils {
-class MacroExpander;
-class Environment;
-}
+namespace Utils { class Environment; }
namespace ProjectExplorer {
@@ -58,10 +55,8 @@ protected:
explicit LocalApplicationRunConfiguration(Target *target, Core::Id id);
explicit LocalApplicationRunConfiguration(Target *target, LocalApplicationRunConfiguration *rc);
- Utils::MacroExpander *macroExpander() const;
-
private:
- mutable Utils::MacroExpander *m_macroExpander;
+ void setupMacroExpander();
};
} // namespace ProjectExplorer
diff --git a/src/plugins/projectexplorer/projectconfiguration.h b/src/plugins/projectexplorer/projectconfiguration.h
index 3a13070aee..14a3c9e25e 100644
--- a/src/plugins/projectexplorer/projectconfiguration.h
+++ b/src/plugins/projectexplorer/projectconfiguration.h
@@ -34,6 +34,7 @@
#include "projectexplorer_export.h"
#include <coreplugin/id.h>
+#include <utils/macroexpander.h>
#include <QObject>
#include <QString>
@@ -64,6 +65,9 @@ public:
// Note: Make sure subclasses call the superclasses' toMap() function!
virtual QVariantMap toMap() const;
+ Utils::MacroExpander *macroExpander() { return &m_macroExpander; }
+ const Utils::MacroExpander *macroExpander() const { return &m_macroExpander; }
+
signals:
void displayNameChanged();
@@ -75,6 +79,7 @@ private:
Core::Id m_id;
QString m_displayName;
QString m_defaultDisplayName;
+ Utils::MacroExpander m_macroExpander;
};
// helper functions: