From e8e27210eb9dad362dea845db9b1b708ea939b54 Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Mon, 1 Aug 2011 13:21:01 +0000 Subject: [PATCH] Project: Allow for additional named settings Allow for additional named settings to be saved along with the project data. This allows plugins to save project-specific settings. Change-Id: I6ed24089efad2eb466385ac9ca4c2dde8bf8c2eb Reviewed-on: http://codereview.qt.nokia.com/2443 Reviewed-by: Qt Sanity Bot Reviewed-by: Daniel Teske --- src/plugins/projectexplorer/project.cpp | 23 +++++++++++++++++++++-- src/plugins/projectexplorer/project.h | 6 ++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/plugins/projectexplorer/project.cpp b/src/plugins/projectexplorer/project.cpp index bda3bad535..49275df75e 100644 --- a/src/plugins/projectexplorer/project.cpp +++ b/src/plugins/projectexplorer/project.cpp @@ -72,7 +72,7 @@ const char * const TARGET_KEY_PREFIX("ProjectExplorer.Project.Target."); const char * const TARGET_COUNT_KEY("ProjectExplorer.Project.TargetCount"); const char * const EDITOR_SETTINGS_KEY("ProjectExplorer.Project.EditorSettings"); - +const char * const PLUGIN_SETTINGS_KEY("ProjectExplorer.Project.PluginSettings"); } // namespace namespace ProjectExplorer { @@ -89,6 +89,7 @@ public: EditorConfiguration *m_editorConfiguration; Core::Context m_projectContext; Core::Context m_projectLanguage; + QVariantMap m_pluginSettings; }; ProjectPrivate::ProjectPrivate() : @@ -215,6 +216,7 @@ Target *Project::target(const QString &id) const void Project::saveSettings() { + emit aboutToSaveSettings(); UserFileAccessor accessor; accessor.saveSettings(this, toMap()); } @@ -223,7 +225,10 @@ bool Project::restoreSettings() { UserFileAccessor accessor; QVariantMap map(accessor.restoreSettings(this)); - return fromMap(map); + bool ok = fromMap(map); + if (ok) + emit settingsLoaded(); + return ok; } QList Project::subConfigWidgets() @@ -253,6 +258,7 @@ QVariantMap Project::toMap() const map.insert(QString::fromLatin1(TARGET_KEY_PREFIX) + QString::number(i), ts.at(i)->toMap()); map.insert(QLatin1String(EDITOR_SETTINGS_KEY), d->m_editorConfiguration->toMap()); + map.insert(QLatin1String(PLUGIN_SETTINGS_KEY), d->m_pluginSettings); return map; } @@ -278,6 +284,9 @@ bool Project::fromMap(const QVariantMap &map) d->m_editorConfiguration->fromMap(values); } + if (map.contains(QLatin1String(PLUGIN_SETTINGS_KEY))) + d->m_pluginSettings = map.value(QLatin1String(PLUGIN_SETTINGS_KEY)).toMap(); + bool ok; int maxI(map.value(QLatin1String(TARGET_COUNT_KEY), 0).toInt(&ok)); if (!ok || maxI < 0) @@ -355,4 +364,14 @@ Core::Context Project::projectLanguage() const return d->m_projectLanguage; } +QVariant Project::namedSettings(const QString &name) const +{ + return d->m_pluginSettings.value(name); +} + +void Project::setNamedSettings(const QString &name, QVariant &value) +{ + d->m_pluginSettings.insert(name, value); +} + } // namespace ProjectExplorer diff --git a/src/plugins/projectexplorer/project.h b/src/plugins/projectexplorer/project.h index 99ea476e0d..15d11a369f 100644 --- a/src/plugins/projectexplorer/project.h +++ b/src/plugins/projectexplorer/project.h @@ -114,6 +114,9 @@ public: virtual Core::Context projectContext() const; virtual Core::Context projectLanguage() const; + QVariant namedSettings(const QString &name) const; + void setNamedSettings(const QString &name, QVariant &value); + signals: void fileListChanged(); @@ -127,6 +130,9 @@ signals: void environmentChanged(); void buildConfigurationEnabledChanged(); + void settingsLoaded(); + void aboutToSaveSettings(); + protected: // restore all data from the map. // -- 2.11.0