ClangFormat: Synchronize with C++ code style settings

And remove UI for default code style settings because
it does not affect anything when ClangFormat plugin is
enabled.

Change-Id: Ie348b7d2691b09ea2b4868da987f2a27347ea0f3
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
Ivan Donchevskii
2018-11-08 10:35:23 +01:00
parent 3de607f4e0
commit 0e5c7f51fa
9 changed files with 253 additions and 69 deletions

View File

@@ -138,7 +138,7 @@ void ClangFormatConfigWidget::initialize()
connect(m_ui->createFileButton, &QPushButton::clicked,
this, [this]() {
createStyleFileIfNeeded(m_project->projectDirectory());
createStyleFileIfNeeded(m_project->projectDirectory(), false);
initialize();
});
return;
@@ -146,10 +146,8 @@ void ClangFormatConfigWidget::initialize()
m_ui->createFileButton->hide();
std::string testFilePath;
if (m_project) {
m_ui->projectHasClangFormat->hide();
testFilePath = m_project->projectDirectory().appendPath("t.cpp").toString().toStdString();
connect(m_ui->applyButton, &QPushButton::clicked, this, &ClangFormatConfigWidget::apply);
} else {
const Project *currentProject = SessionManager::startupProject();
@@ -162,34 +160,20 @@ void ClangFormatConfigWidget::initialize()
"and can be configured in Projects > Clang Format."));
}
const QString settingsDir = Core::ICore::userResourcePath();
createStyleFileIfNeeded(Utils::FileName::fromString(settingsDir));
testFilePath = settingsDir.toStdString() + "/t.cpp";
createStyleFileIfNeeded(Utils::FileName::fromString(settingsDir), true);
m_ui->applyButton->hide();
}
fillTable(testFilePath);
fillTable();
}
void ClangFormatConfigWidget::fillTable(const std::string &testFilePath)
void ClangFormatConfigWidget::fillTable()
{
llvm::Expected<clang::format::FormatStyle> formatStyle =
clang::format::getStyle("file", testFilePath, "LLVM");
std::string configText;
bool brokenConfig = false;
if (!formatStyle) {
handleAllErrors(formatStyle.takeError(), [](const llvm::ErrorInfoBase &) {
// do nothing
});
configText = clang::format::configurationAsText(clang::format::getLLVMStyle());
brokenConfig = true;
} else {
configText = clang::format::configurationAsText(*formatStyle);
}
clang::format::FormatStyle style = m_project ? currentProjectStyle() : currentGlobalStyle();
std::string configText = clang::format::configurationAsText(style);
std::istringstream stream(configText);
readTable(m_ui->clangFormatOptionsTable, stream);
if (brokenConfig)
apply();
}