Commit feca0292 authored by Tobias Hunger's avatar Tobias Hunger
Browse files

SettingsAccessor: incrementVersion --> upgradeSettings



Also since incrementVersion is always called in a loop, move the loop
inside the function.

Change-Id: I6550a322b2423ed41f05c729b913647e52906cb9
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
parent a2b84448
......@@ -502,6 +502,28 @@ private:
} // namespace
/**
* @brief Upgrade the settings to a target version
*/
void SettingsAccessor::upgradeSettings(SettingsData &data, int toVersion) const
{
if (data.m_map.isEmpty())
return;
if (data.version() >= toVersion
|| data.version() < m_firstVersion
|| toVersion > currentVersion())
return;
for (int i = data.version(); i < toVersion; ++i) {
VersionUpgrader *upgrader = m_handlers.value(data.version());
data.m_map = upgrader->upgrade(data.m_map);
data.m_version++;
}
return;
}
namespace {
// When restoring settings...
......@@ -674,12 +696,6 @@ void SettingsAccessor::backupUserFile() const
QFile::copy(origName, backupName);
}
void SettingsAccessor::incrementVersion(SettingsAccessor::SettingsData &data) const
{
data.m_map = m_handlers.value(data.version())->upgrade(data.m_map);
++data.m_version;
}
SettingsAccessor::SettingsData SettingsAccessor::readUserSettings() const
{
SettingsData result;
......@@ -826,11 +842,8 @@ SettingsAccessor::SettingsData SettingsAccessor::mergeSettings(const SettingsAcc
SettingsData newShared = shared;
SettingsData result;
if (shared.isValid() && user.isValid()) {
while (newUser.version() < newShared.version())
incrementVersion(newUser);
while (newShared.version() < newUser.version())
incrementVersion(newShared);
upgradeSettings(newUser, newShared.version());
upgradeSettings(newShared, newUser.version());
result = newUser;
result.m_map = mergeSharedSettings(newUser.m_map, newShared.m_map);
} else if (shared.isValid()) {
......@@ -845,8 +858,7 @@ SettingsAccessor::SettingsData SettingsAccessor::mergeSettings(const SettingsAcc
return result;
// Update from the base version to Creator's version.
for (int i = result.version(); i < currentVersion(); ++i)
incrementVersion(result);
upgradeSettings(result, currentVersion());
return result;
}
......
......@@ -81,7 +81,7 @@ private:
Utils::FileName m_fileName;
};
void incrementVersion(SettingsData &data) const;
void upgradeSettings(SettingsData &data, int toVersion) const;
SettingsData readUserSettings() const;
SettingsData readSharedSettings() const;
......
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