Commit 3d57758d authored by Jarek Kobus's avatar Jarek Kobus

Transform always old code style settings

Before, we didn't transform the code style settings
if they were defaults (so no entries were written
for them in the settings). In case someone
changed global tab settings and didn't touch
code style settings in 2.3, the code style settings
were not transformed. Now, we transform them too
so that legacy code style settings in 2.4
(named: "Old Creator") contains old global tab settings.
We also take care of not creating legacy settings
in case neither textTabPreferences nor CppTabPreferences
nor CppCodeStyleSettings were saved (when creator 2.3 used only
defaults or when it's a first run of creator 2.4 without
old settings).
Handle legacy transformation for qml too.
Make a code bit more readable.

Task-number: QTCREATORBUG-6614
Change-Id: I37b8dd4d1170f397b7d304c59575d9ae37884564
Reviewed-by: default avatarLeandro Melo <leandro.melo@nokia.com>
Reviewed-by: default avatarChristian Kamm <christian.d.kamm@nokia.com>
parent 7ff81c43
......@@ -53,25 +53,6 @@ using TextEditor::TabSettings;
namespace CppTools {
namespace Internal {
class LegacySettings
{
public:
LegacySettings()
: m_legacyTransformed(false)
{ }
void fromMap(const QString &prefix, const QVariantMap &map)
{
m_fallbackId = map.value(prefix + QLatin1String("CurrentFallback")).toString();
m_legacyTransformed = map.value(prefix + QLatin1String("LegacyTransformed"), false).toBool();
}
void toMap(const QString &prefix, QVariantMap *map) const
{
map->insert(prefix + QLatin1String("LegacyTransformed"), true);
}
QString m_fallbackId;
bool m_legacyTransformed;
};
class CppToolsSettingsPrivate
{
public:
......@@ -176,40 +157,51 @@ CppToolsSettings::CppToolsSettings(QObject *parent)
if (QSettings *s = Core::ICore::instance()->settings()) {
d->m_globalCodeStyle->fromSettings(CppTools::Constants::CPP_SETTINGS_ID, s);
// legacy handling start (Qt Creator <= 2.3)
Internal::LegacySettings legacySettings;
TabSettings legacyTabSettings;
Utils::fromSettings(QLatin1String("TabPreferences"),
QLatin1String("Cpp"), s, &legacySettings);
if (legacySettings.m_fallbackId == QLatin1String("CppGlobal")) {
Utils::fromSettings(QLatin1String("TabPreferences"),
QLatin1String("Cpp"), s, &legacyTabSettings);
} else {
legacyTabSettings = textEditorSettings->codeStyle()->currentTabSettings();
}
CppCodeStyleSettings legacyCodeStyleSettings;
Utils::fromSettings(QLatin1String("CodeStyleSettings"),
QLatin1String("Cpp"), s, &legacySettings);
if (!legacySettings.m_legacyTransformed
&& legacySettings.m_fallbackId == QLatin1String("CppGlobal")) {
Utils::fromSettings(QLatin1String("CodeStyleSettings"),
QLatin1String("Cpp"), s, &legacyCodeStyleSettings);
// create custom code style out of old settings
QVariant v;
v.setValue(legacyCodeStyleSettings);
TextEditor::ICodeStylePreferences *oldCreator = pool->createCodeStyle(
QLatin1String("legacy"), legacyTabSettings,
v, tr("Old Creator"));
// change the current delegate and save
d->m_globalCodeStyle->setCurrentDelegate(oldCreator);
d->m_globalCodeStyle->toSettings(CppTools::Constants::CPP_SETTINGS_ID, s);
// mark old settings as transformed,
// we create only once "Old Creator" custom settings
Utils::toSettings(QLatin1String("CodeStyleSettings"),
QLatin1String("Cpp"), s, &legacySettings);
// legacy handling start (Qt Creator Version < 2.4)
const bool legacyTransformed =
s->value(QLatin1String("CppCodeStyleSettings/LegacyTransformed"), false).toBool();
if (!legacyTransformed) {
// creator 2.4 didn't mark yet the transformation (first run of creator 2.4)
// we need to transform the settings only if at least one from
// below settings was already written - otherwise we use
// defaults like it would be the first run of creator 2.4 without stored settings
const QStringList groups = s->childGroups();
const bool needTransform = groups.contains(QLatin1String("textTabPreferences")) ||
groups.contains(QLatin1String("CppTabPreferences")) ||
groups.contains(QLatin1String("CppCodeStyleSettings"));
if (needTransform) {
CppCodeStyleSettings legacyCodeStyleSettings;
if (groups.contains(QLatin1String("CppCodeStyleSettings"))) {
Utils::fromSettings(QLatin1String("CppCodeStyleSettings"),
QString(), s, &legacyCodeStyleSettings);
}
const QString currentFallback = s->value(QLatin1String("CppTabPreferences/CurrentFallback")).toString();
TabSettings legacyTabSettings;
if (currentFallback == QLatin1String("CppGlobal")) {
// no delegate, global overwritten
Utils::fromSettings(QLatin1String("CppTabPreferences"),
QString(), s, &legacyTabSettings);
} else {
// delegating to global
legacyTabSettings = textEditorSettings->codeStyle()->currentTabSettings();
}
// create custom code style out of old settings
QVariant v;
v.setValue(legacyCodeStyleSettings);
TextEditor::ICodeStylePreferences *oldCreator = pool->createCodeStyle(
QLatin1String("legacy"), legacyTabSettings,
v, tr("Old Creator"));
// change the current delegate and save
d->m_globalCodeStyle->setCurrentDelegate(oldCreator);
d->m_globalCodeStyle->toSettings(CppTools::Constants::CPP_SETTINGS_ID, s);
}
// mark old settings as transformed
s->setValue(QLatin1String("CppCodeStyleSettings/LegacyTransformed"), true);
}
// legacy handling stop
}
......
......@@ -39,6 +39,7 @@
#include <texteditor/tabsettings.h>
#include <texteditor/codestylepool.h>
#include <utils/settingsutils.h>
#include <utils/qtcassert.h>
#include <coreplugin/icore.h>
......@@ -108,8 +109,48 @@ QmlJSToolsSettings::QmlJSToolsSettings(QObject *parent)
pool->loadCustomCodeStyles();
// load global settings (after built-in settings are added to the pool)
if (const QSettings *s = Core::ICore::instance()->settings()) {
if (QSettings *s = Core::ICore::instance()->settings()) {
d->m_globalCodeStyle->fromSettings(QmlJSTools::Constants::QML_JS_SETTINGS_ID, s);
// legacy handling start (Qt Creator Version < 2.4)
const bool legacyTransformed =
s->value(QLatin1String("QmlJSTabPreferences/LegacyTransformed"), false).toBool();
if (!legacyTransformed) {
// creator 2.4 didn't mark yet the transformation (first run of creator 2.4)
// we need to transform the settings only if at least one from
// below settings was already written - otherwise we use
// defaults like it would be the first run of creator 2.4 without stored settings
const QStringList groups = s->childGroups();
const bool needTransform = groups.contains(QLatin1String("textTabPreferences")) ||
groups.contains(QLatin1String("QmlJSTabPreferences"));
if (needTransform) {
const QString currentFallback = s->value(QLatin1String("QmlJSTabPreferences/CurrentFallback")).toString();
TabSettings legacyTabSettings;
if (currentFallback == QLatin1String("QmlJSGlobal")) {
// no delegate, global overwritten
Utils::fromSettings(QLatin1String("QmlJSTabPreferences"),
QString(), s, &legacyTabSettings);
} else {
// delegating to global
legacyTabSettings = textEditorSettings->codeStyle()->currentTabSettings();
}
// create custom code style out of old settings
TextEditor::ICodeStylePreferences *oldCreator = pool->createCodeStyle(
QLatin1String("legacy"), legacyTabSettings,
QVariant(), tr("Old Creator"));
// change the current delegate and save
d->m_globalCodeStyle->setCurrentDelegate(oldCreator);
d->m_globalCodeStyle->toSettings(QmlJSTools::Constants::QML_JS_SETTINGS_ID, s);
}
// mark old settings as transformed
s->setValue(QLatin1String("QmlJSTabPreferences/LegacyTransformed"), true);
}
// legacy handling stop
}
// mimetypes to be handled
......
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