summaryrefslogtreecommitdiff
path: root/src/plugins/cpptools
diff options
context:
space:
mode:
authorIvan Donchevskii <ivan.donchevskii@qt.io>2018-02-23 11:36:18 +0100
committerIvan Donchevskii <ivan.donchevskii@qt.io>2018-03-19 13:19:00 +0000
commit4d153b4f678a851e3a2f44640d46fb5aed834932 (patch)
tree1d8363fd0ab386a7541978bf406f02cdb8169eb5 /src/plugins/cpptools
parent1e033d8a085ba7373359c84f4afed37c52c5b27e (diff)
downloadqt-creator-4d153b4f678a851e3a2f44640d46fb5aed834932.tar.gz
Clang: Add combobox with tidy configuration options
The old way was not flexible enough. With these options it's possible to just use your config file or set tidy command line yourself. Change-Id: I1bace40986668dee5e1b30c9d03090a3fd22e253 Reviewed-by: Marco Bubke <marco.bubke@qt.io>
Diffstat (limited to 'src/plugins/cpptools')
-rw-r--r--src/plugins/cpptools/clangdiagnosticconfig.cpp32
-rw-r--r--src/plugins/cpptools/clangdiagnosticconfig.h22
-rw-r--r--src/plugins/cpptools/clangdiagnosticconfigswidget.cpp69
-rw-r--r--src/plugins/cpptools/clangdiagnosticconfigswidget.h3
-rw-r--r--src/plugins/cpptools/cppcodemodelsettings.cpp22
-rw-r--r--src/plugins/cpptools/tidychecks.ui263
6 files changed, 306 insertions, 105 deletions
diff --git a/src/plugins/cpptools/clangdiagnosticconfig.cpp b/src/plugins/cpptools/clangdiagnosticconfig.cpp
index c605d12800..724f4404e5 100644
--- a/src/plugins/cpptools/clangdiagnosticconfig.cpp
+++ b/src/plugins/cpptools/clangdiagnosticconfig.cpp
@@ -72,7 +72,9 @@ bool ClangDiagnosticConfig::operator==(const ClangDiagnosticConfig &other) const
return m_id == other.m_id
&& m_displayName == other.m_displayName
&& m_clangOptions == other.m_clangOptions
- && m_clangTidyChecks == other.m_clangTidyChecks
+ && m_clangTidyMode == other.m_clangTidyMode
+ && m_clangTidyChecksPrefixes == other.m_clangTidyChecksPrefixes
+ && m_clangTidyChecksString == other.m_clangTidyChecksString
&& m_clazyChecks == other.m_clazyChecks
&& m_isReadOnly == other.m_isReadOnly;
}
@@ -82,14 +84,34 @@ bool ClangDiagnosticConfig::operator!=(const ClangDiagnosticConfig &other) const
return !(*this == other);
}
-QString ClangDiagnosticConfig::clangTidyChecks() const
+ClangDiagnosticConfig::TidyMode ClangDiagnosticConfig::clangTidyMode() const
{
- return m_clangTidyChecks;
+ return m_clangTidyMode;
}
-void ClangDiagnosticConfig::setClangTidyChecks(const QString &checks)
+void ClangDiagnosticConfig::setClangTidyMode(TidyMode mode)
{
- m_clangTidyChecks = checks;
+ m_clangTidyMode = mode;
+}
+
+QString ClangDiagnosticConfig::clangTidyChecksPrefixes() const
+{
+ return m_clangTidyChecksPrefixes;
+}
+
+void ClangDiagnosticConfig::setClangTidyChecksPrefixes(const QString &checks)
+{
+ m_clangTidyChecksPrefixes = checks;
+}
+
+QString ClangDiagnosticConfig::clangTidyChecksString() const
+{
+ return m_clangTidyChecksString;
+}
+
+void ClangDiagnosticConfig::setClangTidyChecksString(const QString &checks)
+{
+ m_clangTidyChecksString = checks;
}
QString ClangDiagnosticConfig::clazyChecks() const
diff --git a/src/plugins/cpptools/clangdiagnosticconfig.h b/src/plugins/cpptools/clangdiagnosticconfig.h
index 327d2f504e..536ce39606 100644
--- a/src/plugins/cpptools/clangdiagnosticconfig.h
+++ b/src/plugins/cpptools/clangdiagnosticconfig.h
@@ -37,6 +37,14 @@ namespace CppTools {
class CPPTOOLS_EXPORT ClangDiagnosticConfig
{
public:
+ enum class TidyMode
+ {
+ Disabled = 0,
+ ChecksPrefixList,
+ ChecksString,
+ File
+ };
+
Core::Id id() const;
void setId(const Core::Id &id);
@@ -46,8 +54,14 @@ public:
QStringList clangOptions() const;
void setClangOptions(const QStringList &options);
- QString clangTidyChecks() const;
- void setClangTidyChecks(const QString &checks);
+ QString clangTidyChecksPrefixes() const;
+ void setClangTidyChecksPrefixes(const QString &checks);
+
+ QString clangTidyChecksString() const;
+ void setClangTidyChecksString(const QString &checks);
+
+ TidyMode clangTidyMode() const;
+ void setClangTidyMode(TidyMode mode);
QString clazyChecks() const;
void setClazyChecks(const QString &checks);
@@ -62,7 +76,9 @@ private:
Core::Id m_id;
QString m_displayName;
QStringList m_clangOptions;
- QString m_clangTidyChecks;
+ TidyMode m_clangTidyMode;
+ QString m_clangTidyChecksPrefixes;
+ QString m_clangTidyChecksString;
QString m_clazyChecks;
bool m_isReadOnly = false;
};
diff --git a/src/plugins/cpptools/clangdiagnosticconfigswidget.cpp b/src/plugins/cpptools/clangdiagnosticconfigswidget.cpp
index e7705f7460..bf6c055366 100644
--- a/src/plugins/cpptools/clangdiagnosticconfigswidget.cpp
+++ b/src/plugins/cpptools/clangdiagnosticconfigswidget.cpp
@@ -112,15 +112,30 @@ void ClangDiagnosticConfigsWidget::onRemoveButtonClicked()
syncConfigChooserToModel();
}
+void ClangDiagnosticConfigsWidget::onClangTidyModeChanged(int index)
+{
+ ClangDiagnosticConfig config = currentConfig();
+ config.setClangTidyMode(static_cast<ClangDiagnosticConfig::TidyMode>(index));
+ updateConfig(config);
+ syncClangTidyWidgets(config);
+}
+
void ClangDiagnosticConfigsWidget::onClangTidyItemChanged(QListWidgetItem *item)
{
const QString prefix = item->text();
ClangDiagnosticConfig config = currentConfig();
- QString checks = config.clangTidyChecks();
+ QString checks = config.clangTidyChecksPrefixes();
item->checkState() == Qt::Checked
? checks.append(',' + prefix)
: checks.remove(',' + prefix);
- config.setClangTidyChecks(checks);
+ config.setClangTidyChecksPrefixes(checks);
+ updateConfig(config);
+}
+
+void ClangDiagnosticConfigsWidget::onClangTidyLineEdited(const QString &text)
+{
+ ClangDiagnosticConfig config = currentConfig();
+ config.setClangTidyChecksString(text);
updateConfig(config);
}
@@ -271,9 +286,35 @@ void ClangDiagnosticConfigsWidget::syncClangTidyWidgets(const ClangDiagnosticCon
{
disconnectClangTidyItemChanged();
- const QString tidyChecks = config.clangTidyChecks();
- for (int row = 0; row < m_tidyChecks->checksList->count(); ++row) {
- QListWidgetItem *item = m_tidyChecks->checksList->item(row);
+ ClangDiagnosticConfig::TidyMode tidyMode = config.clangTidyMode();
+
+ m_tidyChecks->tidyMode->setCurrentIndex(static_cast<int>(tidyMode));
+ switch (tidyMode) {
+ case ClangDiagnosticConfig::TidyMode::Disabled:
+ case ClangDiagnosticConfig::TidyMode::File:
+ m_tidyChecks->checksString->setVisible(false);
+ m_tidyChecks->checksListWrapper->setCurrentIndex(1);
+ break;
+ case ClangDiagnosticConfig::TidyMode::ChecksString:
+ m_tidyChecks->checksString->setVisible(true);
+ m_tidyChecks->checksListWrapper->setCurrentIndex(1);
+ m_tidyChecks->checksString->setText(config.clangTidyChecksString());
+ break;
+ case ClangDiagnosticConfig::TidyMode::ChecksPrefixList:
+ m_tidyChecks->checksString->setVisible(false);
+ m_tidyChecks->checksListWrapper->setCurrentIndex(0);
+ syncTidyChecksList(config);
+ break;
+ }
+
+ connectClangTidyItemChanged();
+}
+
+void ClangDiagnosticConfigsWidget::syncTidyChecksList(const ClangDiagnosticConfig &config)
+{
+ const QString tidyChecks = config.clangTidyChecksPrefixes();
+ for (int row = 0; row < m_tidyChecks->checksPrefixesList->count(); ++row) {
+ QListWidgetItem *item = m_tidyChecks->checksPrefixesList->item(row);
Qt::ItemFlags flags = item->flags();
flags |= Qt::ItemIsUserCheckable;
@@ -288,8 +329,6 @@ void ClangDiagnosticConfigsWidget::syncClangTidyWidgets(const ClangDiagnosticCon
else
item->setCheckState(Qt::Unchecked);
}
-
- connectClangTidyItemChanged();
}
void ClangDiagnosticConfigsWidget::syncClazyWidgets(const ClangDiagnosticConfig &config)
@@ -362,14 +401,26 @@ void ClangDiagnosticConfigsWidget::updateValidityWidgets(const QString &errorMes
void ClangDiagnosticConfigsWidget::connectClangTidyItemChanged()
{
- connect(m_tidyChecks->checksList, &QListWidget::itemChanged,
+ connect(m_tidyChecks->tidyMode,
+ static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
+ this,
+ &ClangDiagnosticConfigsWidget::onClangTidyModeChanged);
+ connect(m_tidyChecks->checksPrefixesList, &QListWidget::itemChanged,
this, &ClangDiagnosticConfigsWidget::onClangTidyItemChanged);
+ connect(m_tidyChecks->checksString, &QLineEdit::textEdited,
+ this, &ClangDiagnosticConfigsWidget::onClangTidyLineEdited);
}
void ClangDiagnosticConfigsWidget::disconnectClangTidyItemChanged()
{
- disconnect(m_tidyChecks->checksList, &QListWidget::itemChanged,
+ disconnect(m_tidyChecks->tidyMode,
+ static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
+ this,
+ &ClangDiagnosticConfigsWidget::onClangTidyModeChanged);
+ disconnect(m_tidyChecks->checksPrefixesList, &QListWidget::itemChanged,
this, &ClangDiagnosticConfigsWidget::onClangTidyItemChanged);
+ disconnect(m_tidyChecks->checksString, &QLineEdit::textEdited,
+ this, &ClangDiagnosticConfigsWidget::onClangTidyLineEdited);
}
void ClangDiagnosticConfigsWidget::connectClazyRadioButtonClicked(QRadioButton *button)
diff --git a/src/plugins/cpptools/clangdiagnosticconfigswidget.h b/src/plugins/cpptools/clangdiagnosticconfigswidget.h
index 1d57797a56..e9d610f779 100644
--- a/src/plugins/cpptools/clangdiagnosticconfigswidget.h
+++ b/src/plugins/cpptools/clangdiagnosticconfigswidget.h
@@ -76,7 +76,9 @@ private:
void onCurrentConfigChanged(int);
void onCopyButtonClicked();
void onRemoveButtonClicked();
+ void onClangTidyModeChanged(int index);
void onClangTidyItemChanged(QListWidgetItem *item);
+ void onClangTidyLineEdited(const QString &text);
void onClazyRadioButtonChanged(bool checked);
void onDiagnosticOptionsEdited();
@@ -86,6 +88,7 @@ private:
void syncOtherWidgetsToComboBox();
void syncClangTidyWidgets(const ClangDiagnosticConfig &config);
void syncClazyWidgets(const ClangDiagnosticConfig &config);
+ void syncTidyChecksList(const ClangDiagnosticConfig &config);
void updateConfig(const CppTools::ClangDiagnosticConfig &config);
diff --git a/src/plugins/cpptools/cppcodemodelsettings.cpp b/src/plugins/cpptools/cppcodemodelsettings.cpp
index cc39f00129..6b54c266e0 100644
--- a/src/plugins/cpptools/cppcodemodelsettings.cpp
+++ b/src/plugins/cpptools/cppcodemodelsettings.cpp
@@ -55,9 +55,15 @@ static QString clangDiagnosticConfigsArrayDisplayNameKey()
static QString clangDiagnosticConfigsArrayWarningsKey()
{ return QLatin1String("diagnosticOptions"); }
-static QString clangDiagnosticConfigsArrayClangTidyChecksKey()
+static QString clangDiagnosticConfigsArrayClangTidyChecksPrefixesKey()
{ return QLatin1String("clangTidyChecks"); }
+static QString clangDiagnosticConfigsArrayClangTidyChecksStringKey()
+{ return QLatin1String("clangTidyChecksString"); }
+
+static QString clangDiagnosticConfigsArrayClangTidyModeKey()
+{ return QLatin1String("clangTidyMode"); }
+
static QString clangDiagnosticConfigsArrayClazyChecksKey()
{ return QLatin1String("clazyChecks"); }
@@ -88,7 +94,12 @@ static ClangDiagnosticConfigs customDiagnosticConfigsFromSettings(QSettings *s)
config.setId(Core::Id::fromSetting(s->value(clangDiagnosticConfigsArrayIdKey())));
config.setDisplayName(s->value(clangDiagnosticConfigsArrayDisplayNameKey()).toString());
config.setClangOptions(s->value(clangDiagnosticConfigsArrayWarningsKey()).toStringList());
- config.setClangTidyChecks(s->value(clangDiagnosticConfigsArrayClangTidyChecksKey()).toString());
+ config.setClangTidyMode(static_cast<ClangDiagnosticConfig::TidyMode>(
+ s->value(clangDiagnosticConfigsArrayClangTidyModeKey()).toInt()));
+ config.setClangTidyChecksPrefixes(
+ s->value(clangDiagnosticConfigsArrayClangTidyChecksPrefixesKey()).toString());
+ config.setClangTidyChecksString(
+ s->value(clangDiagnosticConfigsArrayClangTidyChecksStringKey()).toString());
config.setClazyChecks(s->value(clangDiagnosticConfigsArrayClazyChecksKey()).toString());
configs.append(config);
}
@@ -144,7 +155,12 @@ void CppCodeModelSettings::toSettings(QSettings *s)
s->setValue(clangDiagnosticConfigsArrayIdKey(), config.id().toSetting());
s->setValue(clangDiagnosticConfigsArrayDisplayNameKey(), config.displayName());
s->setValue(clangDiagnosticConfigsArrayWarningsKey(), config.clangOptions());
- s->setValue(clangDiagnosticConfigsArrayClangTidyChecksKey(), config.clangTidyChecks());
+ s->setValue(clangDiagnosticConfigsArrayClangTidyModeKey(),
+ static_cast<int>(config.clangTidyMode()));
+ s->setValue(clangDiagnosticConfigsArrayClangTidyChecksPrefixesKey(),
+ config.clangTidyChecksPrefixes());
+ s->setValue(clangDiagnosticConfigsArrayClangTidyChecksStringKey(),
+ config.clangTidyChecksString());
s->setValue(clangDiagnosticConfigsArrayClazyChecksKey(), config.clazyChecks());
}
s->endArray();
diff --git a/src/plugins/cpptools/tidychecks.ui b/src/plugins/cpptools/tidychecks.ui
index a9190b894d..0d144f956e 100644
--- a/src/plugins/cpptools/tidychecks.ui
+++ b/src/plugins/cpptools/tidychecks.ui
@@ -15,99 +15,192 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="leftMargin">
- <number>0</number>
+ <number>9</number>
</property>
<property name="topMargin">
- <number>0</number>
+ <number>9</number>
</property>
<property name="rightMargin">
- <number>0</number>
+ <number>9</number>
</property>
<property name="bottomMargin">
- <number>0</number>
+ <number>9</number>
</property>
<item>
- <widget class="QListWidget" name="checksList">
- <item>
- <property name="text">
- <string notr="true">android-*</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string notr="true">boost-*</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string notr="true">bugprone-*</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string notr="true">cert-*</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string notr="true">cppcoreguidelines-*</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string notr="true">clang-analyzer-*</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string notr="true">clang-diagnostic-*</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string notr="true">google-*</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string notr="true">hicpp-*</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string notr="true">llvm-*</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string notr="true">misc-*</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string notr="true">modernize-*</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string notr="true">mpi-*</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string notr="true">objc-*</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string notr="true">performance-*</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string notr="true">readability-*</string>
- </property>
- </item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QComboBox" name="tidyMode">
+ <item>
+ <property name="text">
+ <string>Disable</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Select Clang-Tidy prefixes</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Provide Clang-Tidy checks string</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Use .clang-tidy config file</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="checksString"/>
+ </item>
+ <item>
+ <widget class="QStackedWidget" name="checksListWrapper">
+ <widget class="QWidget" name="checksPage">
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <property name="leftMargin">
+ <number>0</number>
+ </property>
+ <property name="topMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>0</number>
+ </property>
+ <property name="bottomMargin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QListWidget" name="checksPrefixesList">
+ <item>
+ <property name="text">
+ <string>android-*</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>boost-*</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>bugprone-*</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>cert-*</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>cppcoreguidelines-*</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>clang-analyzer-*</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>clang-diagnostic-*</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>google-*</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>hicpp-*</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>llvm-*</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>misc-*</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>modernize-*</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>mpi-*</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>objc-*</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>performance-*</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>readability-*</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="empltyPage">
+ <layout class="QVBoxLayout" name="verticalLayout_3">
+ <property name="leftMargin">
+ <number>0</number>
+ </property>
+ <property name="topMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>0</number>
+ </property>
+ <property name="bottomMargin">
+ <number>0</number>
+ </property>
+ <item>
+ <spacer name="verticalSpacer">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>237</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </widget>
</widget>
</item>
</layout>