CppTools: Allow to check whether project code style exists

The calling code can anyways fallback to the global style
without extra help if no project style exists.

It is useful when you want to get the project style if it exists
and understand at the same time that it is not a global one.

Change-Id: I265de3f436f90623385427fc8a1abad09c8c3577
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
Ivan Donchevskii
2018-11-08 16:21:54 +01:00
parent 1787eef68f
commit 8dc566e902
4 changed files with 19 additions and 11 deletions

View File

@@ -118,7 +118,8 @@ static clang::format::FormatStyle constructStyle(bool isGlobal)
FormatStyle style = getLLVMStyle();
const CppCodeStyleSettings codeStyleSettings = isGlobal
? CppCodeStyleSettings::currentGlobalCodeStyle()
: CppCodeStyleSettings::currentProjectCodeStyle();
: CppCodeStyleSettings::currentProjectCodeStyle()
.value_or(CppCodeStyleSettings::currentGlobalCodeStyle());
const TabSettings tabSettings = isGlobal
? CppCodeStyleSettings::currentGlobalTabSettings()
: CppCodeStyleSettings::currentProjectTabSettings();
@@ -171,8 +172,7 @@ clang::format::FormatStyle currentGlobalStyle()
clang::format::FormatStyle currentStyle()
{
const bool isGlobal = (CppCodeStyleSettings::currentProjectCodeStyle()
== CppCodeStyleSettings::currentGlobalCodeStyle());
const bool isGlobal = !CppCodeStyleSettings::currentProjectCodeStyle().has_value();
return currentStyle(isGlobal);
}