forked from qt-creator/qt-creator
ClangTools: Finish "disable checks" logic
- Take project settings into account. - Fix some bugs in the initial implementation. Task-number: QTCREATORBUG-24852 Change-Id: I4960fc68ef0b27777a152ca871dfa554fea72c51 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -173,9 +173,9 @@ DiagnosticView::DiagnosticView(QWidget *parent)
|
|||||||
connect(m_suppressAction, &QAction::triggered,
|
connect(m_suppressAction, &QAction::triggered,
|
||||||
this, &DiagnosticView::suppressCurrentDiagnostic);
|
this, &DiagnosticView::suppressCurrentDiagnostic);
|
||||||
|
|
||||||
m_disableGloballyAction = new QAction(this);
|
m_disableChecksAction = new QAction(this);
|
||||||
connect(m_disableGloballyAction, &QAction::triggered,
|
connect(m_disableChecksAction, &QAction::triggered,
|
||||||
this, &DiagnosticView::disableCheckForCurrentDiagnosticGlobally);
|
this, &DiagnosticView::disableCheckForCurrentDiagnostic);
|
||||||
|
|
||||||
installEventFilter(this);
|
installEventFilter(this);
|
||||||
|
|
||||||
@@ -239,14 +239,20 @@ void DiagnosticView::suppressCurrentDiagnostic()
|
|||||||
filterModel->addSuppressedDiagnostics(diags);
|
filterModel->addSuppressedDiagnostics(diags);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiagnosticView::disableCheckForCurrentDiagnosticGlobally()
|
void DiagnosticView::disableCheckForCurrentDiagnostic()
|
||||||
{
|
{
|
||||||
ClangToolsSettings * const settings = ClangToolsSettings::instance();
|
ClangToolsSettings * const settings = ClangToolsSettings::instance();
|
||||||
ClangDiagnosticConfigs configs = settings->diagnosticConfigs();
|
ClangDiagnosticConfigs configs = settings->diagnosticConfigs();
|
||||||
|
Utils::Id activeConfigId = settings->runSettings().diagnosticConfigId();
|
||||||
|
ClangToolsProjectSettings::ClangToolsProjectSettingsPtr projectSettings;
|
||||||
|
if (ProjectExplorer::Project * const project
|
||||||
|
= static_cast<DiagnosticFilterModel *>(model())->project()) {
|
||||||
|
projectSettings = ClangToolsProjectSettings::getSettings(project);
|
||||||
|
if (!projectSettings->useGlobalSettings())
|
||||||
|
activeConfigId = projectSettings->runSettings().diagnosticConfigId();
|
||||||
|
}
|
||||||
ClangDiagnosticConfig config = Utils::findOrDefault(configs,
|
ClangDiagnosticConfig config = Utils::findOrDefault(configs,
|
||||||
[settings](const ClangDiagnosticConfig &c) {
|
[activeConfigId](const ClangDiagnosticConfig &c) { return c.id() == activeConfigId; });
|
||||||
return c.id() == settings->runSettings().diagnosticConfigId();
|
|
||||||
});
|
|
||||||
const bool defaultWasActive = !config.id().isValid();
|
const bool defaultWasActive = !config.id().isValid();
|
||||||
if (defaultWasActive) {
|
if (defaultWasActive) {
|
||||||
QTC_ASSERT(configs.isEmpty(), return);
|
QTC_ASSERT(configs.isEmpty(), return);
|
||||||
@@ -255,6 +261,14 @@ void DiagnosticView::disableCheckForCurrentDiagnosticGlobally()
|
|||||||
config.setId(Utils::Id::fromString(QUuid::createUuid().toString()));
|
config.setId(Utils::Id::fromString(QUuid::createUuid().toString()));
|
||||||
config.setDisplayName(tr("Custom Configuration"));
|
config.setDisplayName(tr("Custom Configuration"));
|
||||||
configs << config;
|
configs << config;
|
||||||
|
RunSettings runSettings = settings->runSettings();
|
||||||
|
runSettings.setDiagnosticConfigId(config.id());
|
||||||
|
settings->setRunSettings(runSettings);
|
||||||
|
if (projectSettings && !projectSettings->useGlobalSettings()) {
|
||||||
|
runSettings = projectSettings->runSettings();
|
||||||
|
runSettings.setDiagnosticConfigId(config.id());
|
||||||
|
projectSettings->setRunSettings(runSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::set<QString> handledNames;
|
std::set<QString> handledNames;
|
||||||
@@ -268,10 +282,18 @@ void DiagnosticView::disableCheckForCurrentDiagnosticGlobally()
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (diag.name.startsWith("clazy-")) {
|
if (diag.name.startsWith("clazy-")) {
|
||||||
|
if (config.clazyMode() == ClangDiagnosticConfig::ClazyMode::UseDefaultChecks) {
|
||||||
config.setClazyMode(ClangDiagnosticConfig::ClazyMode::UseCustomChecks);
|
config.setClazyMode(ClangDiagnosticConfig::ClazyMode::UseCustomChecks);
|
||||||
|
const ClazyStandaloneInfo clazyInfo(clazyStandaloneExecutable());
|
||||||
|
config.setClazyChecks(clazyInfo.defaultChecks.join(','));
|
||||||
|
}
|
||||||
config.setClazyChecks(removeClazyCheck(config.clazyChecks(), diag.name));
|
config.setClazyChecks(removeClazyCheck(config.clazyChecks(), diag.name));
|
||||||
} else if (config.clangTidyMode() != ClangDiagnosticConfig::TidyMode::UseConfigFile) {
|
} else if (config.clangTidyMode() != ClangDiagnosticConfig::TidyMode::UseConfigFile) {
|
||||||
|
if (config.clangTidyMode() == ClangDiagnosticConfig::TidyMode::UseDefaultChecks) {
|
||||||
config.setClangTidyMode(ClangDiagnosticConfig::TidyMode::UseCustomChecks);
|
config.setClangTidyMode(ClangDiagnosticConfig::TidyMode::UseCustomChecks);
|
||||||
|
const ClangTidyInfo tidyInfo(clangTidyExecutable());
|
||||||
|
config.setClangTidyChecks(tidyInfo.defaultChecks.join(','));
|
||||||
|
}
|
||||||
config.setClangTidyChecks(removeClangTidyCheck(config.clangTidyChecks(), diag.name));
|
config.setClangTidyChecks(removeClangTidyCheck(config.clangTidyChecks(), diag.name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -338,7 +360,7 @@ QModelIndex DiagnosticView::getTopLevelIndex(const QModelIndex &index, Direction
|
|||||||
return model()->index(row, 0);
|
return model()->index(row, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DiagnosticView::disableGloballyEnabled() const
|
bool DiagnosticView::disableChecksEnabled() const
|
||||||
{
|
{
|
||||||
const QList<QModelIndex> indexes = selectionModel()->selectedIndexes();
|
const QList<QModelIndex> indexes = selectionModel()->selectedIndexes();
|
||||||
if (indexes.isEmpty())
|
if (indexes.isEmpty())
|
||||||
@@ -348,10 +370,15 @@ bool DiagnosticView::disableGloballyEnabled() const
|
|||||||
|
|
||||||
ClangToolsSettings * const settings = ClangToolsSettings::instance();
|
ClangToolsSettings * const settings = ClangToolsSettings::instance();
|
||||||
const ClangDiagnosticConfigs configs = settings->diagnosticConfigs();
|
const ClangDiagnosticConfigs configs = settings->diagnosticConfigs();
|
||||||
|
Utils::Id activeConfigId = settings->runSettings().diagnosticConfigId();
|
||||||
|
if (ProjectExplorer::Project * const project
|
||||||
|
= static_cast<DiagnosticFilterModel *>(model())->project()) {
|
||||||
|
const auto projectSettings = ClangToolsProjectSettings::getSettings(project);
|
||||||
|
if (!projectSettings->useGlobalSettings())
|
||||||
|
activeConfigId = projectSettings->runSettings().diagnosticConfigId();
|
||||||
|
}
|
||||||
const ClangDiagnosticConfig activeConfig = Utils::findOrDefault(configs,
|
const ClangDiagnosticConfig activeConfig = Utils::findOrDefault(configs,
|
||||||
[settings](const ClangDiagnosticConfig &c) {
|
[activeConfigId](const ClangDiagnosticConfig &c) { return c.id() == activeConfigId; });
|
||||||
return c.id() == settings->runSettings().diagnosticConfigId();
|
|
||||||
});
|
|
||||||
|
|
||||||
// If the user has not created any custom configuration yet, then we'll do that for
|
// If the user has not created any custom configuration yet, then we'll do that for
|
||||||
// them as an act of kindness. But if custom configurations exist and the default
|
// them as an act of kindness. But if custom configurations exist and the default
|
||||||
@@ -385,9 +412,9 @@ QList<QAction *> DiagnosticView::customActions() const
|
|||||||
m_suppressAction->setEnabled(isDiagnosticItem || hasMultiSelection);
|
m_suppressAction->setEnabled(isDiagnosticItem || hasMultiSelection);
|
||||||
m_suppressAction->setText(hasMultiSelection ? tr("Suppress Selected Diagnostics")
|
m_suppressAction->setText(hasMultiSelection ? tr("Suppress Selected Diagnostics")
|
||||||
: tr("Suppress This Diagnostic"));
|
: tr("Suppress This Diagnostic"));
|
||||||
m_disableGloballyAction->setEnabled(disableGloballyEnabled());
|
m_disableChecksAction->setEnabled(disableChecksEnabled());
|
||||||
m_disableGloballyAction->setText(hasMultiSelection ? tr("Disable These Checks Globally")
|
m_disableChecksAction->setText(hasMultiSelection ? tr("Disable These Checks")
|
||||||
: tr("Disable This Check Globally"));
|
: tr("Disable This Check"));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
m_help,
|
m_help,
|
||||||
@@ -398,7 +425,7 @@ QList<QAction *> DiagnosticView::customActions() const
|
|||||||
m_filterOutCurrentKind,
|
m_filterOutCurrentKind,
|
||||||
m_separator2,
|
m_separator2,
|
||||||
m_suppressAction,
|
m_suppressAction,
|
||||||
m_disableGloballyAction
|
m_disableChecksAction
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,13 +61,12 @@ private:
|
|||||||
|
|
||||||
void openEditorForCurrentIndex();
|
void openEditorForCurrentIndex();
|
||||||
void suppressCurrentDiagnostic();
|
void suppressCurrentDiagnostic();
|
||||||
void disableCheckForCurrentDiagnosticGlobally();
|
void disableCheckForCurrentDiagnostic();
|
||||||
enum Direction { Next = 1, Previous = -1 };
|
enum Direction { Next = 1, Previous = -1 };
|
||||||
QModelIndex getIndex(const QModelIndex &index, Direction direction) const;
|
QModelIndex getIndex(const QModelIndex &index, Direction direction) const;
|
||||||
QModelIndex getTopLevelIndex(const QModelIndex &index, Direction direction) const;
|
QModelIndex getTopLevelIndex(const QModelIndex &index, Direction direction) const;
|
||||||
|
|
||||||
private:
|
bool disableChecksEnabled() const;
|
||||||
bool disableGloballyEnabled() const;
|
|
||||||
|
|
||||||
QAction *m_help = nullptr;
|
QAction *m_help = nullptr;
|
||||||
|
|
||||||
@@ -77,7 +76,7 @@ private:
|
|||||||
QAction *m_filterOutCurrentKind = nullptr;
|
QAction *m_filterOutCurrentKind = nullptr;
|
||||||
|
|
||||||
QAction *m_suppressAction = nullptr;
|
QAction *m_suppressAction = nullptr;
|
||||||
QAction *m_disableGloballyAction = nullptr;
|
QAction *m_disableChecksAction = nullptr;
|
||||||
|
|
||||||
QAction *m_separator = nullptr;
|
QAction *m_separator = nullptr;
|
||||||
QAction *m_separator2 = nullptr;
|
QAction *m_separator2 = nullptr;
|
||||||
|
|||||||
Reference in New Issue
Block a user