Commit fb59a39a authored by Tobias Hunger's avatar Tobias Hunger

Fix saving of XML configuration files

... when removing settings

Change-Id: If85061321082a8cd0e35752f71d2498fd4693dfd
Reviewed-by: default avatarDaniel Teske <daniel.teske@nokia.com>
parent 4e6bec00
......@@ -373,20 +373,12 @@ static void writeVariantValue(QXmlStreamWriter &w, const Context &ctx,
}
PersistentSettingsWriter::PersistentSettingsWriter(const FileName &fileName, const QString &docType) :
m_fileName(fileName), m_docType(docType), m_mustSave(false)
m_fileName(fileName), m_docType(docType)
{ }
void PersistentSettingsWriter::saveValue(const QString &variable, const QVariant &value)
bool PersistentSettingsWriter::save(const QVariantMap &data, QWidget *parent) const
{
if (m_valueMap.contains(variable) && m_valueMap.value(variable) == value)
return;
m_mustSave = true;
m_valueMap.insert(variable, value);
}
bool PersistentSettingsWriter::save(QWidget *parent) const
{
if (!m_mustSave)
if (data == m_savedData)
return true;
QDir tmp;
......@@ -403,8 +395,8 @@ bool PersistentSettingsWriter::save(QWidget *parent) const
arg(QLatin1String(Core::Constants::IDE_VERSION_LONG),
QDateTime::currentDateTime().toString(Qt::ISODate)));
w.writeStartElement(ctx.qtCreatorElement);
const QVariantMap::const_iterator cend = m_valueMap.constEnd();
for (QVariantMap::const_iterator it = m_valueMap.constBegin(); it != cend; ++it) {
const QVariantMap::const_iterator cend = data.constEnd();
for (QVariantMap::const_iterator it = data.constBegin(); it != cend; ++it) {
w.writeStartElement(ctx.dataElement);
w.writeTextElement(ctx.variableElement, it.key());
writeVariantValue(w, ctx, it.value());
......@@ -416,7 +408,7 @@ bool PersistentSettingsWriter::save(QWidget *parent) const
}
bool ok = saver.finalize(parent);
if (ok)
m_mustSave = false;
m_savedData = data;
return ok;
}
......
......@@ -60,16 +60,14 @@ class QTCREATOR_UTILS_EXPORT PersistentSettingsWriter
{
public:
PersistentSettingsWriter(const FileName &fileName, const QString &docType);
void saveValue(const QString &variable, const QVariant &value);
bool save(QWidget *parent) const;
bool save(const QVariantMap &data, QWidget *parent) const;
Utils::FileName fileName() const;
private:
QMap<QString, QVariant> m_valueMap;
const Utils::FileName m_fileName;
const QString m_docType;
mutable bool m_mustSave;
mutable QMap<QString, QVariant> m_savedData;
};
} // namespace Utils
......
......@@ -136,8 +136,9 @@ void DeviceManager::copy(const DeviceManager *source, DeviceManager *target, boo
void DeviceManager::save()
{
d->writer->saveValue(QLatin1String(DeviceManagerKey), toMap());
d->writer->save(Core::ICore::mainWindow());
QVariantMap data;
data.insert(QLatin1String(DeviceManagerKey), toMap());
d->writer->save(data, Core::ICore::mainWindow());
}
void DeviceManager::load()
......
......@@ -227,20 +227,21 @@ void ProfileManager::saveProfiles()
if (!d->m_initialized) // ignore save requests while we are not initialized.
return;
d->m_writer->saveValue(QLatin1String(PROFILE_FILE_VERSION_KEY), 1);
QVariantMap data;
data.insert(QLatin1String(PROFILE_FILE_VERSION_KEY), 1);
int count = 0;
foreach (Profile *p, profiles()) {
QVariantMap tmp = p->toMap();
if (tmp.isEmpty())
continue;
d->m_writer->saveValue(QString::fromLatin1(PROFILE_DATA_KEY) + QString::number(count), tmp);
data.insert(QString::fromLatin1(PROFILE_DATA_KEY) + QString::number(count), tmp);
++count;
}
d->m_writer->saveValue(QLatin1String(PROFILE_COUNT_KEY), count);
d->m_writer->saveValue(QLatin1String(PROFILE_DEFAULT_KEY),
d->m_defaultProfile ? QString::fromLatin1(d->m_defaultProfile->id().name()) : QString());
d->m_writer->save(Core::ICore::mainWindow());
data.insert(QLatin1String(PROFILE_COUNT_KEY), count);
data.insert(QLatin1String(PROFILE_DEFAULT_KEY),
d->m_defaultProfile ? QString::fromLatin1(d->m_defaultProfile->id().name()) : QString());
d->m_writer->save(data, Core::ICore::mainWindow());
}
bool greaterPriority(ProfileInformation *a, ProfileInformation *b)
......
......@@ -312,9 +312,10 @@ bool SessionManager::save()
QLatin1String("QtCreatorSession"));
}
QVariantMap data;
// save the startup project
if (m_startupProject)
m_writer->saveValue(QLatin1String("StartupProject"), m_startupProject->document()->fileName());
data.insert(QLatin1String("StartupProject"), m_startupProject->document()->fileName());
QStringList projectFiles;
foreach (Project *pro, m_projects)
......@@ -326,7 +327,7 @@ bool SessionManager::save()
if (!projectFiles.contains(failed))
projectFiles << failed;
m_writer->saveValue(QLatin1String("ProjectList"), projectFiles);
data.insert(QLatin1String("ProjectList"), projectFiles);
QMap<QString, QVariant> depMap;
QMap<QString, QStringList>::const_iterator i = m_depMap.constBegin();
......@@ -339,7 +340,7 @@ bool SessionManager::save()
depMap.insert(key, values);
++i;
}
m_writer->saveValue(QLatin1String("ProjectDependencies"), QVariant(depMap));
data.insert(QLatin1String("ProjectDependencies"), QVariant(depMap));
int editorCount = 0;
QList<Core::IEditor *> editors = ICore::editorManager()->openedEditors();
......@@ -348,21 +349,20 @@ bool SessionManager::save()
if (!editor->isTemporary())
++editorCount;
}
m_writer->saveValue(QLatin1String("OpenEditors"), editorCount);
m_writer->saveValue(QLatin1String("EditorSettings"),
ICore::editorManager()->saveState().toBase64());
data.insert(QLatin1String("OpenEditors"), editorCount);
data.insert(QLatin1String("EditorSettings"), ICore::editorManager()->saveState().toBase64());
QMap<QString, QVariant>::const_iterator it, end;
end = m_values.constEnd();
QStringList keys;
for (it = m_values.constBegin(); it != end; ++it) {
m_writer->saveValue(QLatin1String("value-") + it.key(), it.value());
data.insert(QLatin1String("value-") + it.key(), it.value());
keys << it.key();
}
m_writer->saveValue(QLatin1String("valueKeys"), keys);
data.insert(QLatin1String("valueKeys"), keys);
bool result = m_writer->save(Core::ICore::mainWindow());
bool result = m_writer->save(data, Core::ICore::mainWindow());
if (!result) {
QMessageBox::warning(0, tr("Error while saving session"),
tr("Could not save session to file %1").arg(m_writer->fileName().toUserOutput()));
......
......@@ -936,18 +936,20 @@ bool SettingsAccessor::FileAccessor::writeFile(const SettingsData *settings) con
m_writer = new Utils::PersistentSettingsWriter(settings->m_fileName, QLatin1String("QtCreatorProject"));
}
QVariantMap data;
for (QVariantMap::const_iterator i = settings->m_map.constBegin();
i != settings->m_map.constEnd();
++i) {
m_writer->saveValue(i.key(), i.value());
data.insert(i.key(), i.value());
}
m_writer->saveValue(QLatin1String(VERSION_KEY), m_accessor->m_lastVersion + 1);
data.insert(QLatin1String(VERSION_KEY), m_accessor->m_lastVersion + 1);
if (m_environmentSpecific)
m_writer->saveValue(QLatin1String(ENVIRONMENT_ID_KEY),
ProjectExplorerPlugin::instance()->projectExplorerSettings().environmentId.toString());
return m_writer->save(Core::ICore::mainWindow());
data.insert(QLatin1String(ENVIRONMENT_ID_KEY),
ProjectExplorerPlugin::instance()->projectExplorerSettings().environmentId.toString());
return m_writer->save(data, Core::ICore::mainWindow());
}
// -------------------------------------------------------------------------
......
......@@ -209,7 +209,8 @@ ToolChainManager::~ToolChainManager()
void ToolChainManager::saveToolChains()
{
d->m_writer->saveValue(QLatin1String(TOOLCHAIN_FILE_VERSION_KEY), 1);
QVariantMap data;
data.insert(QLatin1String(TOOLCHAIN_FILE_VERSION_KEY), 1);
int count = 0;
foreach (ToolChain *tc, d->toolChains()) {
......@@ -217,12 +218,12 @@ void ToolChainManager::saveToolChains()
QVariantMap tmp = tc->toMap();
if (tmp.isEmpty())
continue;
d->m_writer->saveValue(QString::fromLatin1(TOOLCHAIN_DATA_KEY) + QString::number(count), tmp);
data.insert(QString::fromLatin1(TOOLCHAIN_DATA_KEY) + QString::number(count), tmp);
++count;
}
}
d->m_writer->saveValue(QLatin1String(TOOLCHAIN_COUNT_KEY), count);
d->m_writer->save(Core::ICore::mainWindow());
data.insert(QLatin1String(TOOLCHAIN_COUNT_KEY), count);
d->m_writer->save(data, Core::ICore::mainWindow());
// Do not save default debuggers! Those are set by the SDK!
}
......
......@@ -364,7 +364,9 @@ void QtVersionManager::saveQtVersions()
if (!m_writer)
m_writer = new Utils::PersistentSettingsWriter(settingsFileName(QLatin1String(QTVERSION_FILENAME)),
QLatin1String("QtCreatorQtVersions"));
m_writer->saveValue(QLatin1String(QTVERSION_FILE_VERSION_KEY), 1);
QVariantMap data;
data.insert(QLatin1String(QTVERSION_FILE_VERSION_KEY), 1);
int count = 0;
foreach (BaseQtVersion *qtv, m_versions) {
......@@ -372,11 +374,11 @@ void QtVersionManager::saveQtVersions()
if (tmp.isEmpty())
continue;
tmp.insert(QLatin1String(QTVERSION_TYPE_KEY), qtv->type());
m_writer->saveValue(QString::fromLatin1(QTVERSION_DATA_KEY) + QString::number(count), tmp);
data.insert(QString::fromLatin1(QTVERSION_DATA_KEY) + QString::number(count), tmp);
++count;
}
m_writer->save(Core::ICore::mainWindow());
m_writer->save(data, Core::ICore::mainWindow());
}
void QtVersionManager::findSystemQt()
......
......@@ -286,9 +286,11 @@ void CodeStylePool::exportCodeStyle(const Utils::FileName &fileName, ICodeStyleP
{
QVariantMap map;
codeStyle->toMap(QString::null, &map);
QVariantMap tmp;
tmp.insert(QLatin1String(displayNameKey), codeStyle->displayName());
tmp.insert(QLatin1String(codeStyleDataKey), map);
Utils::PersistentSettingsWriter writer(fileName, QLatin1String(codeStyleDocKey));
writer.saveValue(QLatin1String(displayNameKey), codeStyle->displayName());
writer.saveValue(QLatin1String(codeStyleDataKey), map);
writer.save(0);
writer.save(map, 0);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment