aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/clangtools
diff options
context:
space:
mode:
authorDavid Schulz <[email protected]>2020-07-21 13:11:01 +0200
committerDavid Schulz <[email protected]>2020-08-28 07:20:19 +0000
commit7f562c4d33a042fe51946c273581b2e9ad64159f (patch)
tree7ee57da51bee2284d79ad709559eb7d04df88093 /src/plugins/clangtools
parent431479599221e4b62c2fdb501cd8e508e06dce88 (diff)
ClangTools: Add diagnostic mark class
These marks can now be disabled. This greys out the annotation color and the icon of the mark. Change-Id: I5af4591db4baaaef55c986252f77d5d977427b56 Reviewed-by: Christian Stenger <[email protected]>
Diffstat (limited to 'src/plugins/clangtools')
-rw-r--r--src/plugins/clangtools/CMakeLists.txt1
-rw-r--r--src/plugins/clangtools/clangtools.pro2
-rw-r--r--src/plugins/clangtools/clangtools.qbs2
-rw-r--r--src/plugins/clangtools/clangtoolsdiagnostic.cpp15
-rw-r--r--src/plugins/clangtools/clangtoolsdiagnostic.h1
-rw-r--r--src/plugins/clangtools/clangtoolsdiagnosticmodel.cpp125
-rw-r--r--src/plugins/clangtools/clangtoolsdiagnosticmodel.h10
-rw-r--r--src/plugins/clangtools/clangtoolsutils.cpp91
-rw-r--r--src/plugins/clangtools/clangtoolsutils.h18
-rw-r--r--src/plugins/clangtools/diagnosticmark.cpp72
-rw-r--r--src/plugins/clangtools/diagnosticmark.h50
11 files changed, 258 insertions, 129 deletions
diff --git a/src/plugins/clangtools/CMakeLists.txt b/src/plugins/clangtools/CMakeLists.txt
index 702f622c5f8..4ac94e7c253 100644
--- a/src/plugins/clangtools/CMakeLists.txt
+++ b/src/plugins/clangtools/CMakeLists.txt
@@ -31,6 +31,7 @@ add_qtc_plugin(ClangTools
clangtoolsutils.cpp clangtoolsutils.h
clazychecks.ui
diagnosticconfigswidget.cpp diagnosticconfigswidget.h
+ diagnosticmark.cpp diagnosticmark.h
executableinfo.cpp executableinfo.h
filterdialog.cpp filterdialog.h filterdialog.ui
runsettingswidget.cpp runsettingswidget.h runsettingswidget.ui
diff --git a/src/plugins/clangtools/clangtools.pro b/src/plugins/clangtools/clangtools.pro
index 7abb6bc53b6..2d2c3b3c271 100644
--- a/src/plugins/clangtools/clangtools.pro
+++ b/src/plugins/clangtools/clangtools.pro
@@ -29,6 +29,7 @@ SOURCES += \
clangtoolssettings.cpp \
clangtoolsutils.cpp \
diagnosticconfigswidget.cpp \
+ diagnosticmark.cpp \
executableinfo.cpp \
filterdialog.cpp \
runsettingswidget.cpp \
@@ -54,6 +55,7 @@ HEADERS += \
clangtoolssettings.h \
clangtoolsutils.h \
diagnosticconfigswidget.h \
+ diagnosticmark.h \
executableinfo.h \
filterdialog.h \
runsettingswidget.h \
diff --git a/src/plugins/clangtools/clangtools.qbs b/src/plugins/clangtools/clangtools.qbs
index 2d353ab8262..eab5cd240c0 100644
--- a/src/plugins/clangtools/clangtools.qbs
+++ b/src/plugins/clangtools/clangtools.qbs
@@ -66,6 +66,8 @@ QtcPlugin {
"clazychecks.ui",
"diagnosticconfigswidget.cpp",
"diagnosticconfigswidget.h",
+ "diagnosticmark.cpp",
+ "diagnosticmark.h",
"executableinfo.cpp",
"executableinfo.h",
"filterdialog.cpp",
diff --git a/src/plugins/clangtools/clangtoolsdiagnostic.cpp b/src/plugins/clangtools/clangtoolsdiagnostic.cpp
index 1623d2f6b45..7fe7098c22f 100644
--- a/src/plugins/clangtools/clangtoolsdiagnostic.cpp
+++ b/src/plugins/clangtools/clangtoolsdiagnostic.cpp
@@ -25,6 +25,8 @@
#include "clangtoolsdiagnostic.h"
+#include <utils/utilsicons.h>
+
namespace ClangTools {
namespace Internal {
@@ -47,6 +49,19 @@ bool Diagnostic::isValid() const
return !description.isEmpty();
}
+QIcon Diagnostic::icon() const
+{
+ if (type == "warning")
+ return Utils::Icons::CODEMODEL_WARNING.icon();
+ if (type == "error" || type == "fatal")
+ return Utils::Icons::CODEMODEL_ERROR.icon();
+ if (type == "note")
+ return Utils::Icons::INFO.icon();
+ if (type == "fix-it")
+ return Utils::Icons::CODEMODEL_FIXIT.icon();
+ return {};
+}
+
quint32 qHash(const Diagnostic &diagnostic)
{
return qHash(diagnostic.name)
diff --git a/src/plugins/clangtools/clangtoolsdiagnostic.h b/src/plugins/clangtools/clangtoolsdiagnostic.h
index 5c41ec87162..e64d91a29f2 100644
--- a/src/plugins/clangtools/clangtoolsdiagnostic.h
+++ b/src/plugins/clangtools/clangtoolsdiagnostic.h
@@ -53,6 +53,7 @@ class Diagnostic
{
public:
bool isValid() const;
+ QIcon icon() const;
QString name;
QString description;
diff --git a/src/plugins/clangtools/clangtoolsdiagnosticmodel.cpp b/src/plugins/clangtools/clangtoolsdiagnosticmodel.cpp
index 6cf881c1591..4320b760a00 100644
--- a/src/plugins/clangtools/clangtoolsdiagnosticmodel.cpp
+++ b/src/plugins/clangtools/clangtoolsdiagnosticmodel.cpp
@@ -28,6 +28,7 @@
#include "clangtoolsdiagnosticview.h"
#include "clangtoolsprojectsettings.h"
#include "clangtoolsutils.h"
+#include "diagnosticmark.h"
#include <coreplugin/fileiconprovider.h>
#include <projectexplorer/project.h>
@@ -199,95 +200,11 @@ void ClangToolsDiagnosticModel::addWatchedPath(const QString &path)
m_filesWatcher->addPath(path);
}
-static QString fixitStatus(FixitStatus status)
-{
- switch (status) {
- case FixitStatus::NotAvailable:
- return ClangToolsDiagnosticModel::tr("No Fixits");
- case FixitStatus::NotScheduled:
- return ClangToolsDiagnosticModel::tr("Not Scheduled");
- case FixitStatus::Invalidated:
- return ClangToolsDiagnosticModel::tr("Invalidated");
- case FixitStatus::Scheduled:
- return ClangToolsDiagnosticModel::tr("Scheduled");
- case FixitStatus::FailedToApply:
- return ClangToolsDiagnosticModel::tr("Failed to Apply");
- case FixitStatus::Applied:
- return ClangToolsDiagnosticModel::tr("Applied");
- }
- return QString();
-}
-
static QString lineColumnString(const Debugger::DiagnosticLocation &location)
{
return QString("%1:%2").arg(QString::number(location.line), QString::number(location.column));
}
-static QString createDiagnosticToolTipString(
- const Diagnostic &diagnostic,
- Utils::optional<FixitStatus> fixItStatus = Utils::nullopt,
- bool showSteps = true)
-{
- using StringPair = QPair<QString, QString>;
- QList<StringPair> lines;
-
- if (!diagnostic.category.isEmpty()) {
- lines << qMakePair(
- QCoreApplication::translate("ClangTools::Diagnostic", "Category:"),
- diagnostic.category.toHtmlEscaped());
- }
-
- if (!diagnostic.type.isEmpty()) {
- lines << qMakePair(
- QCoreApplication::translate("ClangTools::Diagnostic", "Type:"),
- diagnostic.type.toHtmlEscaped());
- }
-
- if (!diagnostic.description.isEmpty()) {
- lines << qMakePair(
- QCoreApplication::translate("ClangTools::Diagnostic", "Description:"),
- diagnostic.description.toHtmlEscaped());
- }
-
- lines << qMakePair(
- QCoreApplication::translate("ClangTools::Diagnostic", "Location:"),
- createFullLocationString(diagnostic.location));
-
- if (fixItStatus.has_value()) {
- lines << qMakePair(QCoreApplication::translate("ClangTools::Diagnostic", "Fixit status:"),
- fixitStatus(fixItStatus.value()));
- }
-
- if (showSteps && !diagnostic.explainingSteps.isEmpty()) {
- StringPair steps;
- steps.first = QCoreApplication::translate("ClangTools::Diagnostic", "Steps:");
- for (const ExplainingStep &step : diagnostic.explainingSteps) {
- if (!steps.second.isEmpty())
- steps.second += "<br>";
- steps.second += QString("%1:%2: %3")
- .arg(step.location.filePath,
- lineColumnString(step.location),
- step.message);
- }
- lines << steps;
- }
-
- QString html = QLatin1String("<html>"
- "<head>"
- "<style>dt { font-weight:bold; } dd { font-family: monospace; }</style>\n"
- "<body><dl>");
-
- foreach (const StringPair &pair, lines) {
- html += QLatin1String("<dt>");
- html += pair.first;
- html += QLatin1String("</dt><dd>");
- html += pair.second;
- html += QLatin1String("</dd>\n");
- }
- html += QLatin1String("</dl></body></html>");
- return html;
-}
-
static QString createExplainingStepToolTipString(const ExplainingStep &step)
{
using StringPair = QPair<QString, QString>;
@@ -365,47 +282,17 @@ static QString fullText(const Diagnostic &diagnostic)
return text;
}
-static Utils::optional<QIcon> iconForType(const QString &type)
-{
- if (type == "warning")
- return Utils::Icons::CODEMODEL_WARNING.icon();
- if (type == "error" || type == "fatal")
- return Utils::Icons::CODEMODEL_ERROR.icon();
- if (type == "note")
- return Utils::Icons::INFO.icon();
- if (type == "fix-it")
- return Utils::Icons::CODEMODEL_FIXIT.icon();
- return Utils::nullopt;
-}
-
-static TextEditor::TextMark *generateDiagnosticTextMark(const Diagnostic &diag)
-{
- auto mark = new TextEditor::TextMark(Utils::FilePath::fromString(diag.location.filePath),
- diag.location.line,
- Utils::Id("ClangTool.DiagnosticMark"));
- if (diag.type == "error" || diag.type == "fatal")
- mark->setColor(Utils::Theme::CodeModel_Error_TextMarkColor);
- else
- mark->setColor(Utils::Theme::CodeModel_Warning_TextMarkColor);
- mark->setPriority(TextEditor::TextMark::HighPriority);
- mark->setIcon(iconForType(diag.type).value_or(Utils::Icons::CODEMODEL_WARNING.icon()));
- mark->setToolTip(createDiagnosticToolTipString(diag));
- mark->setLineAnnotation(diag.description);
- return mark;
-}
-
DiagnosticItem::DiagnosticItem(const Diagnostic &diag,
const OnFixitStatusChanged &onFixitStatusChanged,
ClangToolsDiagnosticModel *parent)
: m_diagnostic(diag)
, m_onFixitStatusChanged(onFixitStatusChanged)
, m_parentModel(parent)
+ , m_mark(new DiagnosticMark(diag))
{
if (diag.hasFixits)
m_fixitStatus = FixitStatus::NotScheduled;
- m_mark = generateDiagnosticTextMark(diag);
-
// Don't show explaining steps if they add no information.
if (diag.explainingSteps.count() == 1) {
const ExplainingStep &step = diag.explainingSteps.first();
@@ -434,10 +321,10 @@ Qt::ItemFlags DiagnosticItem::flags(int column) const
return itemFlags;
}
-static QVariant iconData(const QString &type)
+static QVariant iconData(const Diagnostic &diagnostic)
{
- Utils::optional<QIcon> icon = iconForType(type);
- return icon.has_value() ? QVariant(*icon) : QVariant();
+ QIcon icon = diagnostic.icon();
+ return icon.isNull() ? QVariant() : QVariant(icon);
}
QVariant DiagnosticItem::data(int column, int role) const
@@ -485,7 +372,7 @@ QVariant DiagnosticItem::data(int column, int role) const
case Qt::ToolTipRole:
return createDiagnosticToolTipString(m_diagnostic, m_fixitStatus, false);
case Qt::DecorationRole:
- return iconData(m_diagnostic.type);
+ return iconData(m_diagnostic);
default:
return QVariant();
}
diff --git a/src/plugins/clangtools/clangtoolsdiagnosticmodel.h b/src/plugins/clangtools/clangtoolsdiagnosticmodel.h
index fe93a6e1ce8..9f4e61ef55f 100644
--- a/src/plugins/clangtools/clangtoolsdiagnosticmodel.h
+++ b/src/plugins/clangtools/clangtoolsdiagnosticmodel.h
@@ -28,6 +28,7 @@
#include "clangfixitsrefactoringchanges.h"
#include "clangtoolsdiagnostic.h"
#include "clangtoolsprojectsettings.h"
+#include "clangtoolsutils.h"
#include <debugger/analyzer/detailederrorview.h>
#include <utils/fileutils.h>
@@ -48,15 +49,6 @@ namespace ProjectExplorer { class Project; }
namespace ClangTools {
namespace Internal {
-enum class FixitStatus {
- NotAvailable,
- NotScheduled,
- Scheduled,
- Applied,
- FailedToApply,
- Invalidated,
-};
-
class ClangToolsDiagnosticModel;
class FilePathItem : public Utils::TreeItem
diff --git a/src/plugins/clangtools/clangtoolsutils.cpp b/src/plugins/clangtools/clangtoolsutils.cpp
index c7f7cac4232..6c394aebc0c 100644
--- a/src/plugins/clangtools/clangtoolsutils.cpp
+++ b/src/plugins/clangtools/clangtoolsutils.cpp
@@ -43,13 +43,102 @@
#include <QFileInfo>
#include <cpptools/clangdiagnosticconfigsmodel.h>
-#include <cpptools/clangdiagnosticconfigsmodel.h>
using namespace CppTools;
namespace ClangTools {
namespace Internal {
+static QString lineColumnString(const Debugger::DiagnosticLocation &location)
+{
+ return QString("%1:%2").arg(QString::number(location.line), QString::number(location.column));
+}
+
+static QString fixitStatus(FixitStatus status)
+{
+ switch (status) {
+ case FixitStatus::NotAvailable:
+ return QCoreApplication::translate("ClangToolsDiagnosticModel", "No Fixits");
+ case FixitStatus::NotScheduled:
+ return QCoreApplication::translate("ClangToolsDiagnosticModel", "Not Scheduled");
+ case FixitStatus::Invalidated:
+ return QCoreApplication::translate("ClangToolsDiagnosticModel", "Invalidated");
+ case FixitStatus::Scheduled:
+ return QCoreApplication::translate("ClangToolsDiagnosticModel", "Scheduled");
+ case FixitStatus::FailedToApply:
+ return QCoreApplication::translate("ClangToolsDiagnosticModel", "Failed to Apply");
+ case FixitStatus::Applied:
+ return QCoreApplication::translate("ClangToolsDiagnosticModel", "Applied");
+ }
+ return QString();
+}
+
+QString createDiagnosticToolTipString(
+ const Diagnostic &diagnostic,
+ Utils::optional<FixitStatus> status,
+ bool showSteps)
+{
+ using StringPair = QPair<QString, QString>;
+ QList<StringPair> lines;
+
+ if (!diagnostic.category.isEmpty()) {
+ lines << qMakePair(
+ QCoreApplication::translate("ClangTools::Diagnostic", "Category:"),
+ diagnostic.category.toHtmlEscaped());
+ }
+
+ if (!diagnostic.type.isEmpty()) {
+ lines << qMakePair(
+ QCoreApplication::translate("ClangTools::Diagnostic", "Type:"),
+ diagnostic.type.toHtmlEscaped());
+ }
+
+ if (!diagnostic.description.isEmpty()) {
+ lines << qMakePair(
+ QCoreApplication::translate("ClangTools::Diagnostic", "Description:"),
+ diagnostic.description.toHtmlEscaped());
+ }
+
+ lines << qMakePair(
+ QCoreApplication::translate("ClangTools::Diagnostic", "Location:"),
+ createFullLocationString(diagnostic.location));
+
+ if (status) {
+ lines << qMakePair(QCoreApplication::translate("ClangTools::Diagnostic", "Fixit status:"),
+ fixitStatus(*status));
+ }
+
+ if (showSteps && !diagnostic.explainingSteps.isEmpty()) {
+ StringPair steps;
+ steps.first = QCoreApplication::translate("ClangTools::Diagnostic", "Steps:");
+ for (const ExplainingStep &step : diagnostic.explainingSteps) {
+ if (!steps.second.isEmpty())
+ steps.second += "<br>";
+ steps.second += QString("%1:%2: %3")
+ .arg(step.location.filePath,
+ lineColumnString(step.location),
+ step.message);
+ }
+ lines << steps;
+ }
+
+ QString html = QLatin1String("<html>"
+ "<head>"
+ "<style>dt { font-weight:bold; } dd { font-family: monospace; }</style>"
+ "</head>\n"
+ "<body><dl>");
+
+ for (const StringPair &pair : qAsConst(lines)) {
+ html += QLatin1String("<dt>");
+ html += pair.first;
+ html += QLatin1String("</dt><dd>");
+ html += pair.second;
+ html += QLatin1String("</dd>\n");
+ }
+ html += QLatin1String("</dl></body></html>");
+ return html;
+}
+
QString createFullLocationString(const Debugger::DiagnosticLocation &location)
{
return location.filePath + QLatin1Char(':') + QString::number(location.line)
diff --git a/src/plugins/clangtools/clangtoolsutils.h b/src/plugins/clangtools/clangtoolsutils.h
index a9a1e3ce934..4aa6f7eac98 100644
--- a/src/plugins/clangtools/clangtoolsutils.h
+++ b/src/plugins/clangtools/clangtoolsutils.h
@@ -27,6 +27,8 @@
#include <cpptools/clangdiagnosticconfig.h>
+#include <utils/optional.h>
+
#include <QtGlobal>
QT_BEGIN_NAMESPACE
@@ -39,6 +41,22 @@ namespace Debugger { class DiagnosticLocation; }
namespace ClangTools {
namespace Internal {
+class Diagnostic;
+
+enum class FixitStatus {
+ NotAvailable,
+ NotScheduled,
+ Scheduled,
+ Applied,
+ FailedToApply,
+ Invalidated,
+};
+
+QString createDiagnosticToolTipString(
+ const Diagnostic &diagnostic,
+ Utils::optional<FixitStatus> status = Utils::nullopt,
+ bool showSteps = true);
+
QString createFullLocationString(const Debugger::DiagnosticLocation &location);
QString hintAboutBuildBeforeAnalysis();
diff --git a/src/plugins/clangtools/diagnosticmark.cpp b/src/plugins/clangtools/diagnosticmark.cpp
new file mode 100644
index 00000000000..127c091f274
--- /dev/null
+++ b/src/plugins/clangtools/diagnosticmark.cpp
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "diagnosticmark.h"
+
+#include "clangtoolsutils.h"
+
+#include <utils/utilsicons.h>
+
+namespace ClangTools {
+namespace Internal {
+
+DiagnosticMark::DiagnosticMark(const Diagnostic &diagnostic)
+ : TextEditor::TextMark(Utils::FilePath::fromString(diagnostic.location.filePath),
+ diagnostic.location.line,
+ Utils::Id("ClangTool.DiagnosticMark"))
+ , m_diagnostic(diagnostic)
+{
+ if (diagnostic.type == "error" || diagnostic.type == "fatal")
+ setColor(Utils::Theme::CodeModel_Error_TextMarkColor);
+ else
+ setColor(Utils::Theme::CodeModel_Warning_TextMarkColor);
+ setPriority(TextEditor::TextMark::HighPriority);
+ QIcon markIcon = diagnostic.icon();
+ setIcon(markIcon.isNull() ? Utils::Icons::CODEMODEL_WARNING.icon() : markIcon);
+ setToolTip(createDiagnosticToolTipString(diagnostic, Utils::nullopt, true));
+ setLineAnnotation(diagnostic.description);
+}
+
+void DiagnosticMark::disable()
+{
+ if (!m_enabled)
+ return;
+ m_enabled = false;
+ if (m_diagnostic.type == "error" || m_diagnostic.type == "fatal")
+ setIcon(Utils::Icons::CODEMODEL_DISABLED_ERROR.icon());
+ else
+ setIcon(Utils::Icons::CODEMODEL_DISABLED_WARNING.icon());
+ setColor(Utils::Theme::Color::IconsDisabledColor);
+ updateMarker();
+}
+
+bool DiagnosticMark::enabled() const
+{
+ return m_enabled;
+}
+
+} // namespace Internal
+} // namespace ClangTools
+
diff --git a/src/plugins/clangtools/diagnosticmark.h b/src/plugins/clangtools/diagnosticmark.h
new file mode 100644
index 00000000000..040ce16adcf
--- /dev/null
+++ b/src/plugins/clangtools/diagnosticmark.h
@@ -0,0 +1,50 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include "clangtoolsdiagnostic.h"
+
+#include <texteditor/textmark.h>
+
+namespace ClangTools {
+namespace Internal {
+
+
+class DiagnosticMark : public TextEditor::TextMark
+{
+public:
+ explicit DiagnosticMark(const Diagnostic &diagnostic);
+
+ void disable();
+ bool enabled() const;
+
+private:
+ const Diagnostic m_diagnostic;
+ bool m_enabled = true;
+};
+
+} // namespace Internal
+} // namespace ClangTools