From 7020b0a44aff47736e12bf711fffb1fd73f62517 Mon Sep 17 00:00:00 2001 From: Artem Sokolovskii Date: Wed, 1 Jun 2022 14:51:07 +0200 Subject: [PATCH] ClangFormat: Convert old settings to a new ones Added possibility to convert old setting to new one out of the box. So now, if options FormattingInsteadOfIndentting or FormatOnSave was set the mode will be set to Formatting. Change-Id: I3c30ca8543d4fe25d1a44665d286f27ac2102c52 Reviewed-by: Christian Kandeler Reviewed-by: --- .../clangformat/clangformatsettings.cpp | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/plugins/clangformat/clangformatsettings.cpp b/src/plugins/clangformat/clangformatsettings.cpp index 66c20760038..2326f7b8ce1 100644 --- a/src/plugins/clangformat/clangformatsettings.cpp +++ b/src/plugins/clangformat/clangformatsettings.cpp @@ -29,6 +29,9 @@ #include namespace ClangFormat { +static const char FORMAT_CODE_INSTEAD_OF_INDENT_ID[] = "ClangFormat.FormatCodeInsteadOfIndent"; +static const char FORMAT_CODE_ON_SAVE_ID[] = "ClangFormat.FormatCodeOnSave"; +static const char FORMAT_WHILE_TYPING_ID[] = "ClangFormat.FormatWhileTyping"; ClangFormatSettings &ClangFormatSettings::instance() { @@ -42,9 +45,25 @@ ClangFormatSettings::ClangFormatSettings() settings->beginGroup(QLatin1String(Constants::SETTINGS_ID)); m_overrideDefaultFile = settings->value(QLatin1String(Constants::OVERRIDE_FILE_ID), false) .toBool(); - m_mode = static_cast( - settings->value(QLatin1String(Constants::MODE_ID), ClangFormatSettings::Mode::Indenting) - .toInt()); + + // Convert old settings to new ones. New settings were added to QtC 8.0 + bool isOldFormattingOn + = settings->value(QLatin1String(FORMAT_CODE_INSTEAD_OF_INDENT_ID), false).toBool() + || settings->value(QLatin1String(FORMAT_CODE_ON_SAVE_ID), false).toBool(); + + Core::ICore::settings()->remove(QLatin1String(FORMAT_CODE_INSTEAD_OF_INDENT_ID)); + Core::ICore::settings()->remove(QLatin1String(FORMAT_CODE_ON_SAVE_ID)); + Core::ICore::settings()->remove(QLatin1String(FORMAT_WHILE_TYPING_ID)); + + if (isOldFormattingOn) { + settings->setValue(QLatin1String(Constants::MODE_ID), + static_cast(ClangFormatSettings::Mode::Formatting)); + m_mode = ClangFormatSettings::Mode::Formatting; + } else + m_mode = static_cast( + settings->value(QLatin1String(Constants::MODE_ID), ClangFormatSettings::Mode::Indenting) + .toInt()); + settings->endGroup(); }