From 8eececaa96153c69c11ac42c4b09e5b1944f9d4e Mon Sep 17 00:00:00 2001 From: Ivan Donchevskii Date: Thu, 2 Nov 2017 16:26:17 +0100 Subject: Clang: add clang plugins checks to code model settings Add UI controls to change settings and apply them together with warnings and command line options. Current settings are not very flexible but should be easy to test and use without reading tidy/clazy help. Change-Id: I1ca6b49a42a1169b34a703dd50de0bbc105df28f Reviewed-by: Leena Miettinen Reviewed-by: Nikolai Kosjar --- src/plugins/cpptools/cppcodemodelsettingspage.cpp | 71 +++++++++++++++++++++++ 1 file changed, 71 insertions(+) (limited to 'src/plugins/cpptools/cppcodemodelsettingspage.cpp') diff --git a/src/plugins/cpptools/cppcodemodelsettingspage.cpp b/src/plugins/cpptools/cppcodemodelsettingspage.cpp index e6af115aed..d9bc8c9370 100644 --- a/src/plugins/cpptools/cppcodemodelsettingspage.cpp +++ b/src/plugins/cpptools/cppcodemodelsettingspage.cpp @@ -29,6 +29,8 @@ #include "cppmodelmanager.h" #include "cpptoolsconstants.h" #include "ui_cppcodemodelsettingspage.h" +#include "ui_clazychecks.h" +#include "ui_tidychecks.h" #include #include @@ -84,6 +86,65 @@ void CppCodeModelSettingsWidget::setupClangCodeModelWidgets() diagnosticConfigsModel, m_settings->clangDiagnosticConfigId()); m_ui->clangSettingsGroupBox->layout()->addWidget(m_clangDiagnosticConfigsWidget); + + setupPluginsWidgets(); +} + +void CppCodeModelSettingsWidget::setupPluginsWidgets() +{ + m_clazyChecks.reset(new CppTools::Ui::ClazyChecks); + m_clazyChecksWidget = new QWidget(); + m_clazyChecks->setupUi(m_clazyChecksWidget); + + m_tidyChecks.reset(new CppTools::Ui::TidyChecks); + m_tidyChecksWidget = new QWidget(); + m_tidyChecks->setupUi(m_tidyChecksWidget); + + m_ui->pluginChecks->layout()->addWidget(m_tidyChecksWidget); + m_ui->pluginChecks->layout()->addWidget(m_clazyChecksWidget); + m_clazyChecksWidget->setVisible(false); + connect(m_ui->pluginSelection, + static_cast(&QComboBox::currentIndexChanged), + [this](int index) { + (index ? m_clazyChecksWidget : m_tidyChecksWidget)->setVisible(true); + (!index ? m_clazyChecksWidget : m_tidyChecksWidget)->setVisible(false); + }); + + setupTidyChecks(); + setupClazyChecks(); +} + +void CppCodeModelSettingsWidget::setupTidyChecks() +{ + m_currentTidyChecks = m_settings->tidyChecks(); + for (QObject *child : m_tidyChecksWidget->children()) { + auto *check = qobject_cast(child); + if (!check) + continue; + if (m_currentTidyChecks.indexOf(check->text()) != -1) + check->setChecked(true); + connect(check, &QCheckBox::clicked, [this, check](bool checked) { + const QString prefix = check->text(); + checked ? m_currentTidyChecks.append(',' + prefix) + : m_currentTidyChecks.remove(',' + prefix); + }); + } +} + +void CppCodeModelSettingsWidget::setupClazyChecks() +{ + m_currentClazyChecks = m_settings->clazyChecks(); + if (!m_currentClazyChecks.isEmpty()) + m_clazyChecks->clazyLevel->setCurrentText(m_currentClazyChecks); + connect(m_clazyChecks->clazyLevel, + static_cast(&QComboBox::currentIndexChanged), + [this](int index) { + if (index == 0) { + m_currentClazyChecks.clear(); + return; + } + m_currentClazyChecks = m_clazyChecks->clazyLevel->itemText(index); + }); } void CppCodeModelSettingsWidget::setupGeneralWidgets() @@ -117,6 +178,16 @@ bool CppCodeModelSettingsWidget::applyClangCodeModelWidgetsToSettings() const settingsChanged = true; } + if (m_settings->tidyChecks() != m_currentTidyChecks) { + m_settings->setTidyChecks(m_currentTidyChecks); + settingsChanged = true; + } + + if (m_settings->clazyChecks() != m_currentClazyChecks) { + m_settings->setClazyChecks(m_currentClazyChecks); + settingsChanged = true; + } + return settingsChanged; } -- cgit v1.2.1