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 <qt_sanity_bot@ovi.com>
Reviewed-by: Daniel Teske <daniel.teske@nokia.com>
This commit is contained in:
Tobias Hunger
2011-08-01 13:21:01 +00:00
parent a91001d44d
commit e8e27210eb
2 changed files with 27 additions and 2 deletions

View File

@@ -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 TARGET_COUNT_KEY("ProjectExplorer.Project.TargetCount");
const char * const EDITOR_SETTINGS_KEY("ProjectExplorer.Project.EditorSettings"); const char * const EDITOR_SETTINGS_KEY("ProjectExplorer.Project.EditorSettings");
const char * const PLUGIN_SETTINGS_KEY("ProjectExplorer.Project.PluginSettings");
} // namespace } // namespace
namespace ProjectExplorer { namespace ProjectExplorer {
@@ -89,6 +89,7 @@ public:
EditorConfiguration *m_editorConfiguration; EditorConfiguration *m_editorConfiguration;
Core::Context m_projectContext; Core::Context m_projectContext;
Core::Context m_projectLanguage; Core::Context m_projectLanguage;
QVariantMap m_pluginSettings;
}; };
ProjectPrivate::ProjectPrivate() : ProjectPrivate::ProjectPrivate() :
@@ -215,6 +216,7 @@ Target *Project::target(const QString &id) const
void Project::saveSettings() void Project::saveSettings()
{ {
emit aboutToSaveSettings();
UserFileAccessor accessor; UserFileAccessor accessor;
accessor.saveSettings(this, toMap()); accessor.saveSettings(this, toMap());
} }
@@ -223,7 +225,10 @@ bool Project::restoreSettings()
{ {
UserFileAccessor accessor; UserFileAccessor accessor;
QVariantMap map(accessor.restoreSettings(this)); QVariantMap map(accessor.restoreSettings(this));
return fromMap(map); bool ok = fromMap(map);
if (ok)
emit settingsLoaded();
return ok;
} }
QList<BuildConfigWidget*> Project::subConfigWidgets() QList<BuildConfigWidget*> 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(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(EDITOR_SETTINGS_KEY), d->m_editorConfiguration->toMap());
map.insert(QLatin1String(PLUGIN_SETTINGS_KEY), d->m_pluginSettings);
return map; return map;
} }
@@ -278,6 +284,9 @@ bool Project::fromMap(const QVariantMap &map)
d->m_editorConfiguration->fromMap(values); d->m_editorConfiguration->fromMap(values);
} }
if (map.contains(QLatin1String(PLUGIN_SETTINGS_KEY)))
d->m_pluginSettings = map.value(QLatin1String(PLUGIN_SETTINGS_KEY)).toMap();
bool ok; bool ok;
int maxI(map.value(QLatin1String(TARGET_COUNT_KEY), 0).toInt(&ok)); int maxI(map.value(QLatin1String(TARGET_COUNT_KEY), 0).toInt(&ok));
if (!ok || maxI < 0) if (!ok || maxI < 0)
@@ -355,4 +364,14 @@ Core::Context Project::projectLanguage() const
return d->m_projectLanguage; 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 } // namespace ProjectExplorer

View File

@@ -114,6 +114,9 @@ public:
virtual Core::Context projectContext() const; virtual Core::Context projectContext() const;
virtual Core::Context projectLanguage() const; virtual Core::Context projectLanguage() const;
QVariant namedSettings(const QString &name) const;
void setNamedSettings(const QString &name, QVariant &value);
signals: signals:
void fileListChanged(); void fileListChanged();
@@ -127,6 +130,9 @@ signals:
void environmentChanged(); void environmentChanged();
void buildConfigurationEnabledChanged(); void buildConfigurationEnabledChanged();
void settingsLoaded();
void aboutToSaveSettings();
protected: protected:
// restore all data from the map. // restore all data from the map.
// //