Commit 14eb1f66 authored by dt's avatar dt
Browse files

Remove BuildConfiguration::setValue/value

parent 4d93981b
......@@ -35,15 +35,46 @@ using namespace CMakeProjectManager;
using namespace Internal;
CMakeBuildConfiguration::CMakeBuildConfiguration(CMakeProject *pro)
: BuildConfiguration(pro), m_toolChain(0)
: BuildConfiguration(pro),
m_toolChain(0),
m_clearSystemEnvironment(false)
{
}
CMakeBuildConfiguration::CMakeBuildConfiguration(BuildConfiguration *source)
: BuildConfiguration(source), m_toolChain(0)
CMakeBuildConfiguration::CMakeBuildConfiguration(CMakeProject *pro, const QMap<QString, QVariant> &map)
: BuildConfiguration(pro, map),
m_toolChain(0)
{
QMap<QString, QVariant>::const_iterator it = map.constFind("clearSystemEnvironment");
m_clearSystemEnvironment = (it != map.constEnd() && it.value().toBool());
m_userEnvironmentChanges =
ProjectExplorer::EnvironmentItem::fromStringList(
map.value("userEnvironmentChanges").toStringList());
m_msvcVersion = map.value("msvcVersion").toString();
m_buildDirectory = map.value("buildDirectory").toString();
}
CMakeBuildConfiguration::CMakeBuildConfiguration(CMakeBuildConfiguration *source)
: BuildConfiguration(source),
m_toolChain(0),
m_clearSystemEnvironment(source->m_clearSystemEnvironment),
m_userEnvironmentChanges(source->m_userEnvironmentChanges),
m_buildDirectory(source->m_buildDirectory),
m_msvcVersion(source->m_msvcVersion)
{
}
void CMakeBuildConfiguration::toMap(QMap<QString, QVariant> &map) const
{
map.insert("userEnvironmentChanges",
ProjectExplorer::EnvironmentItem::toStringList(m_userEnvironmentChanges));
map.insert("msvcVersion", m_msvcVersion);
map.insert("buildDirectory", m_buildDirectory);
BuildConfiguration::toMap(map);
}
CMakeBuildConfiguration::~CMakeBuildConfiguration()
......@@ -73,36 +104,33 @@ ProjectExplorer::Environment CMakeBuildConfiguration::environment() const
void CMakeBuildConfiguration::setUseSystemEnvironment(bool b)
{
if (b == useSystemEnvironment())
if (b == m_clearSystemEnvironment)
return;
setValue("clearSystemEnvironment", !b);
m_clearSystemEnvironment = !b;
emit environmentChanged();
}
bool CMakeBuildConfiguration::useSystemEnvironment() const
{
bool b = !(value("clearSystemEnvironment").isValid() &&
value("clearSystemEnvironment").toBool());
return b;
return !m_clearSystemEnvironment;
}
QList<ProjectExplorer::EnvironmentItem> CMakeBuildConfiguration::userEnvironmentChanges() const
{
return ProjectExplorer::EnvironmentItem::fromStringList(value("userEnvironmentChanges").toStringList());
return m_userEnvironmentChanges;
}
void CMakeBuildConfiguration::setUserEnvironmentChanges(const QList<ProjectExplorer::EnvironmentItem> &diff)
{
QStringList list = ProjectExplorer::EnvironmentItem::toStringList(diff);
if (list == value("userEnvironmentChanges"))
if (m_userEnvironmentChanges == diff)
return;
setValue("userEnvironmentChanges", list);
m_userEnvironmentChanges = diff;
emit environmentChanged();
}
QString CMakeBuildConfiguration::buildDirectory() const
{
QString buildDirectory = value("buildDirectory").toString();
QString buildDirectory = m_buildDirectory;
if (buildDirectory.isEmpty())
buildDirectory = cmakeProject()->sourceDirectory() + "/qtcreator-build";
return buildDirectory;
......@@ -146,7 +174,7 @@ void CMakeBuildConfiguration::updateToolChain() const
newToolChain = ProjectExplorer::ToolChain::createGccToolChain("gcc");
#endif
} else { // msvc
newToolChain = ProjectExplorer::ToolChain::createMSVCToolChain(value("msvcVersion").toString(), false);
newToolChain = ProjectExplorer::ToolChain::createMSVCToolChain(m_msvcVersion, false);
}
if (ProjectExplorer::ToolChain::equals(newToolChain, m_toolChain)) {
......@@ -160,22 +188,22 @@ void CMakeBuildConfiguration::updateToolChain() const
void CMakeBuildConfiguration::setBuildDirectory(const QString &buildDirectory)
{
if (value("buildDirectory") == buildDirectory)
if (m_buildDirectory == buildDirectory)
return;
setValue("buildDirectory", buildDirectory);
m_buildDirectory = buildDirectory;
emit buildDirectoryChanged();
}
QString CMakeBuildConfiguration::msvcVersion() const
{
return value("msvcVersion").toString();
return m_msvcVersion;
}
void CMakeBuildConfiguration::setMsvcVersion(const QString &msvcVersion)
{
if (value("msvcVersion").toString() == msvcVersion)
if (m_msvcVersion == msvcVersion)
return;
setValue("msvcVersion", msvcVersion);
m_msvcVersion = msvcVersion;
updateToolChain();
emit msvcVersionChanged();
......
......@@ -43,7 +43,8 @@ class CMakeBuildConfiguration : public ProjectExplorer::BuildConfiguration
Q_OBJECT
public:
CMakeBuildConfiguration(CMakeProject *pro);
CMakeBuildConfiguration(BuildConfiguration *source);
CMakeBuildConfiguration(CMakeProject *pro, const QMap<QString, QVariant> &map);
CMakeBuildConfiguration(CMakeBuildConfiguration *source);
~CMakeBuildConfiguration();
CMakeProject *cmakeProject() const;
......@@ -67,12 +68,18 @@ public:
QString msvcVersion() const;
void setMsvcVersion(const QString &msvcVersion);
void toMap(QMap<QString, QVariant> &map) const;
signals:
void msvcVersionChanged();
private:
void updateToolChain() const;
mutable ProjectExplorer::ToolChain *m_toolChain;
bool m_clearSystemEnvironment;
QList<ProjectExplorer::EnvironmentItem> m_userEnvironmentChanges;
QString m_buildDirectory;
QString m_msvcVersion;
};
......
......@@ -141,9 +141,9 @@ BuildConfiguration *CMakeBuildConfigurationFactory::clone(ProjectExplorer::Build
return bc;
}
BuildConfiguration *CMakeBuildConfigurationFactory::restore() const
BuildConfiguration *CMakeBuildConfigurationFactory::restore(const QMap<QString, QVariant> &map) const
{
CMakeBuildConfiguration *bc = new CMakeBuildConfiguration(m_project);
CMakeBuildConfiguration *bc = new CMakeBuildConfiguration(m_project, map);
return bc;
}
......
......@@ -76,7 +76,7 @@ public:
ProjectExplorer::BuildConfiguration *create(const QString &type) const;
ProjectExplorer::BuildConfiguration *clone(ProjectExplorer::BuildConfiguration *source) const;
ProjectExplorer::BuildConfiguration *restore() const;
ProjectExplorer::BuildConfiguration *restore(const QMap<QString, QVariant> &map) const;
private:
CMakeProject *m_project;
......
......@@ -40,12 +40,24 @@ GenericBuildConfiguration::GenericBuildConfiguration(GenericProject *pro)
}
GenericBuildConfiguration::GenericBuildConfiguration(GenericProject *pro, const QMap<QString, QVariant> &map)
: BuildConfiguration(pro, map)
{
m_buildDirectory = map.value("buildDirectory").toString();
}
GenericBuildConfiguration::GenericBuildConfiguration(GenericBuildConfiguration *source)
: BuildConfiguration(source)
: BuildConfiguration(source),
m_buildDirectory(source->m_buildDirectory)
{
}
void GenericBuildConfiguration::toMap(QMap<QString, QVariant> &map) const
{
map.insert("buildDirectory", m_buildDirectory);
}
ProjectExplorer::Environment GenericBuildConfiguration::environment() const
{
return ProjectExplorer::Environment::systemEnvironment();
......@@ -53,22 +65,20 @@ ProjectExplorer::Environment GenericBuildConfiguration::environment() const
QString GenericBuildConfiguration::buildDirectory() const
{
QString buildDirectory = value("buildDirectory").toString();
QString buildDirectory = m_buildDirectory;
if (buildDirectory.isEmpty()) {
QFileInfo fileInfo(project()->file()->fileName());
buildDirectory = fileInfo.absolutePath();
}
return buildDirectory;
}
void GenericBuildConfiguration::setBuildDirectory(const QString &buildDirectory)
{
if (value("buildDirectory").toString() == buildDirectory)
if (m_buildDirectory == buildDirectory)
return;
setValue("buildDirectory", buildDirectory);
m_buildDirectory = buildDirectory;
emit buildDirectoryChanged();
}
......
......@@ -43,6 +43,7 @@ class GenericBuildConfiguration : public ProjectExplorer::BuildConfiguration
Q_OBJECT
public:
GenericBuildConfiguration(GenericProject *pro);
GenericBuildConfiguration(GenericProject *pro, const QMap<QString, QVariant> &map);
GenericBuildConfiguration(GenericBuildConfiguration *source);
GenericProject *genericProject() const;
......@@ -50,6 +51,9 @@ public:
virtual ProjectExplorer::Environment environment() const;
virtual QString buildDirectory() const;
void setBuildDirectory(const QString &buildDirectory);
void toMap(QMap<QString, QVariant> &map) const;
private:
QString m_buildDirectory;
};
} // namespace GenericProjectManager
......
......@@ -162,9 +162,9 @@ BuildConfiguration *GenericBuildConfigurationFactory::clone(BuildConfiguration *
return bc;
}
BuildConfiguration *GenericBuildConfigurationFactory::restore() const
BuildConfiguration *GenericBuildConfigurationFactory::restore(const QMap<QString, QVariant> &map) const
{
GenericBuildConfiguration *bc = new GenericBuildConfiguration(m_project);
GenericBuildConfiguration *bc = new GenericBuildConfiguration(m_project, map);
return bc;
}
......
......@@ -69,7 +69,7 @@ public:
ProjectExplorer::BuildConfiguration *create(const QString &type) const;
ProjectExplorer::BuildConfiguration *clone(ProjectExplorer::BuildConfiguration *source) const;
ProjectExplorer::BuildConfiguration *restore() const;
ProjectExplorer::BuildConfiguration *restore(const QMap<QString, QVariant> &map) const;
private:
GenericProject *m_project;
......
......@@ -50,8 +50,15 @@ BuildConfiguration::BuildConfiguration(Project *pro)
}
BuildConfiguration::BuildConfiguration(Project *pro, const QMap<QString, QVariant> &map)
: m_project(pro)
{
m_displayName = map.value("ProjectExplorer.BuildConfiguration.DisplayName").toString();
}
BuildConfiguration::BuildConfiguration(BuildConfiguration *source)
: m_values(source->m_values), m_project(source->m_project)
: m_displayName(source->m_displayName),
m_project(source->m_project)
{
foreach(BuildStep *originalbs, source->buildSteps()) {
IBuildStepFactory *factory = findFactory(originalbs->name());
......@@ -73,49 +80,20 @@ BuildConfiguration::~BuildConfiguration()
QString BuildConfiguration::displayName() const
{
QVariant v = value("ProjectExplorer.BuildConfiguration.DisplayName");
QTC_ASSERT(v.isValid(), return QString());
return v.toString();
return m_displayName;
}
void BuildConfiguration::setDisplayName(const QString &name)
{
if (value("ProjectExplorer.BuildConfiguration.DisplayName").toString() == name)
if (m_displayName == name)
return;
setValue("ProjectExplorer.BuildConfiguration.DisplayName", name);
m_displayName = name;
emit displayNameChanged();
}
QVariant BuildConfiguration::value(const QString & key) const
{
QHash<QString, QVariant>::const_iterator it = m_values.find(key);
if (it != m_values.constEnd())
return *it;
else
return QVariant();
}
void BuildConfiguration::setValue(const QString & key, QVariant value)
{
m_values[key] = value;
}
void BuildConfiguration::setValuesFromMap(QMap<QString, QVariant> map)
{
QMap<QString, QVariant>::const_iterator it, end;
end = map.constEnd();
for (it = map.constBegin(); it != end; ++it)
setValue(it.key(), it.value());
}
QMap<QString, QVariant> BuildConfiguration::toMap() const
void BuildConfiguration::toMap(QMap<QString, QVariant> &map) const
{
QMap<QString, QVariant> result;
QHash<QString, QVariant>::const_iterator it, end;
end = m_values.constEnd();
for (it = m_values.constBegin(); it != end; ++it)
result.insert(it.key(), it.value());
return result;
map.insert("ProjectExplorer.BuildConfiguration.DisplayName", m_displayName);
}
QList<BuildStep *> BuildConfiguration::buildSteps() const
......
......@@ -57,8 +57,7 @@ public:
QString displayName() const;
void setDisplayName(const QString &name);
QMap<QString, QVariant> toMap() const;
void setValuesFromMap(QMap<QString, QVariant> map);
virtual void toMap(QMap<QString, QVariant> &map) const;
QList<BuildStep *> buildSteps() const;
void insertBuildStep(int position, BuildStep *step);
......@@ -82,16 +81,13 @@ signals:
protected:
BuildConfiguration(Project *project);
BuildConfiguration(Project *project, const QMap<QString, QVariant> &map);
BuildConfiguration(BuildConfiguration *source);
// TODO remove those
QVariant value(const QString &key) const;
void setValue(const QString &key, QVariant value);
private:
QList<BuildStep *> m_buildSteps;
QList<BuildStep *> m_cleanSteps;
QHash<QString, QVariant> m_values;
QString m_displayName;
Project *m_project;
};
......@@ -117,7 +113,7 @@ public:
virtual BuildConfiguration *clone(BuildConfiguration *source) const = 0;
// restores a BuildConfiguration with the name and adds it to the project
virtual BuildConfiguration *restore() const = 0;
virtual BuildConfiguration *restore(const QMap<QString, QVariant> &values) const = 0;
signals:
void availableCreationTypesChanged();
......
......@@ -147,7 +147,8 @@ void Project::saveSettingsImpl(PersistentSettingsWriter &writer)
//save buildsettings
QStringList buildConfigurationNames;
for(int i=0; i < bcs.size(); ++i) {
QMap<QString, QVariant> temp = bcs.at(i)->toMap();
QMap<QString, QVariant> temp;
bcs.at(i)->toMap(temp);
writer.saveValue("buildConfiguration-" + QString::number(i), temp);
buildConfigurationNames << QString::number(i);
}
......@@ -211,12 +212,10 @@ bool Project::restoreSettingsImpl(PersistentSettingsReader &reader)
const QStringList buildConfigurationNames = reader.restoreValue("buildconfigurations").toStringList();
foreach (const QString &buildConfigurationName, buildConfigurationNames) {
BuildConfiguration *bc = buildConfigurationFactory()->restore();
QMap<QString, QVariant> temp =
reader.restoreValue("buildConfiguration-" + buildConfigurationName).toMap();
bc->setValuesFromMap(temp);
BuildConfiguration *bc = buildConfigurationFactory()->restore(temp);
// Restore build steps
QVariant buildStepsValueVariant = reader.restoreValue("buildconfiguration-" + buildConfigurationName + "-buildsteps");
if(buildStepsValueVariant.isValid()) {
......
......@@ -43,13 +43,42 @@ namespace {
}
Qt4BuildConfiguration::Qt4BuildConfiguration(Qt4Project *pro)
: BuildConfiguration(pro)
: BuildConfiguration(pro),
m_clearSystemEnvironment(false),
m_shadowBuild(false),
m_qtVersion(0),
m_toolChainType(-1), // toolChainType() makes sure to return the default toolchainType
m_qmakeBuildConfiguration(0)
{
init();
}
Qt4BuildConfiguration::Qt4BuildConfiguration(Qt4Project *pro, const QMap<QString, QVariant> &map)
: BuildConfiguration(pro, map)
{
init();
QMap<QString, QVariant>::const_iterator it;
it = map.constFind("clearSystemEnvironment");
m_clearSystemEnvironment = (it != map.constEnd() && it.value().toBool());
m_userEnvironmentChanges =
EnvironmentItem::fromStringList(map.value("userEnvironmentChanges").toStringList());
m_shadowBuild = map.value("useShadowBuild").toBool();
m_buildDirectory = map.value("buildDirectory").toString();
m_qtVersion = map.value(KEY_QT_VERSION_ID).toInt();
m_toolChainType = map.value("ToolChain").toInt();
m_qmakeBuildConfiguration = QtVersion::QmakeBuildConfigs(map.value("buildConfiguration").toInt());
}
Qt4BuildConfiguration::Qt4BuildConfiguration(Qt4BuildConfiguration *source)
: BuildConfiguration(source)
: BuildConfiguration(source),
m_clearSystemEnvironment(source->m_clearSystemEnvironment),
m_userEnvironmentChanges(source->m_userEnvironmentChanges),
m_shadowBuild(source->m_shadowBuild),
m_buildDirectory(source->m_buildDirectory),
m_qtVersion(source->m_qtVersion),
m_toolChainType(source->m_toolChainType),
m_qmakeBuildConfiguration(source->m_qmakeBuildConfiguration)
{
init();
}
......@@ -59,6 +88,18 @@ Qt4BuildConfiguration::~Qt4BuildConfiguration()
}
void Qt4BuildConfiguration::toMap(QMap<QString, QVariant> &map) const
{
map.insert("clearSystemEnvironment", m_clearSystemEnvironment);
map.insert("userEnvironmentChanges", EnvironmentItem::toStringList(m_userEnvironmentChanges));
map.insert("useShadowBuild", m_shadowBuild);
map.insert("buildDirectory", m_buildDirectory);
map.insert(KEY_QT_VERSION_ID, m_qtVersion);
map.insert("ToolChain", m_toolChainType);
map.insert("buildConfiguration", int(m_qmakeBuildConfiguration));
BuildConfiguration::toMap(map);
}
void Qt4BuildConfiguration::init()
{
QtVersionManager *vm = QtVersionManager::instance();
......@@ -94,28 +135,25 @@ void Qt4BuildConfiguration::setUseSystemEnvironment(bool b)
{
if (useSystemEnvironment() == b)
return;
setValue("clearSystemEnvironment", !b);
m_clearSystemEnvironment = !b;
emit environmentChanged();
}
bool Qt4BuildConfiguration::useSystemEnvironment() const
{
bool b = !(value("clearSystemEnvironment").isValid()
&& value("clearSystemEnvironment").toBool());
return b;
return !m_clearSystemEnvironment;
}
QList<ProjectExplorer::EnvironmentItem> Qt4BuildConfiguration::userEnvironmentChanges() const
{
return EnvironmentItem::fromStringList(value("userEnvironmentChanges").toStringList());
return m_userEnvironmentChanges;
}
void Qt4BuildConfiguration::setUserEnvironmentChanges(const QList<ProjectExplorer::EnvironmentItem> &diff)
{
QStringList list = EnvironmentItem::toStringList(diff);
if (list == value("userEnvironmentChanges").toStringList())
if (m_userEnvironmentChanges == diff)
return;
setValue("userEnvironmentChanges", list);
m_userEnvironmentChanges = diff;
emit environmentChanged();
}
......@@ -123,8 +161,8 @@ void Qt4BuildConfiguration::setUserEnvironmentChanges(const QList<ProjectExplore
QString Qt4BuildConfiguration::buildDirectory() const
{
QString workingDirectory;
if (value("useShadowBuild").toBool())
workingDirectory = value("buildDirectory").toString();
if (m_shadowBuild)
workingDirectory = m_buildDirectory;
if (workingDirectory.isEmpty())
workingDirectory = QFileInfo(project()->file()->fileName()).absolutePath();
return workingDirectory;
......@@ -136,23 +174,22 @@ QString Qt4BuildConfiguration::buildDirectory() const
/// still be a insource build
bool Qt4BuildConfiguration::shadowBuild() const
{
return value("useShadowBuild").toBool();
return m_shadowBuild;
}
/// returns the shadow build directory if set
/// \note buildDirectory() is probably the function you want to call
QString Qt4BuildConfiguration::shadowBuildDirectory() const
{
return value("buildDirectory").toString();
return m_buildDirectory;
}
void Qt4BuildConfiguration::setShadowBuildAndDirectory(bool shadowBuild, const QString &buildDirectory)
{
if (value("useShadowBuild").toBool() == shadowBuild
&& value("buildDirectory").toString() == buildDirectory)
if (m_shadowBuild == shadowBuild && m_buildDirectory == buildDirectory)
return;
setValue("useShadowBuild", shadowBuild);
setValue("buildDirectory", buildDirectory);
m_shadowBuild = shadowBuild;
m_buildDirectory = buildDirectory;
emit buildDirectoryChanged();
emit targetInformationChanged();
}
......@@ -216,22 +253,12 @@ int Qt4BuildConfiguration::qtVersionId() const
QtVersionManager *vm = QtVersionManager::instance();
if (debug)
qDebug()<<"Looking for qtVersion ID of "<<displayName();
int id = 0;
QVariant vid = value(KEY_QT_VERSION_ID);
if (vid.isValid()) {
id = vid.toInt();
if (vm->version(id)->isValid()) {
return id;
} else {
const_cast<Qt4BuildConfiguration *>(this)->setValue(KEY_QT_VERSION_ID, 0);
return 0;
}
if (vm->version(m_qtVersion)->isValid()) {
return m_qtVersion;
} else {
m_qtVersion = 0;
return 0;
}
if (debug)
qDebug()<<" using qtversion with id ="<<id;
// Nothing found, reset to default
const_cast<Qt4BuildConfiguration *>(this)->setValue(KEY_QT_VERSION_ID, id);
return id;
}
void Qt4BuildConfiguration::setQtVersion(int id)
......@@ -239,7 +266,7 @@ void Qt4BuildConfiguration::setQtVersion(int id)
if (qtVersionId() == id)
return;
setValue(KEY_QT_VERSION_ID, id);
m_qtVersion = id;
emit qtVersionChanged();