summaryrefslogtreecommitdiff
path: root/src/plugins/clangcodemodel/clangdiagnostictooltipwidget.cpp
diff options
context:
space:
mode:
authorNikolai Kosjar <nikolai.kosjar@qt.io>2019-01-28 11:43:18 +0100
committerNikolai Kosjar <nikolai.kosjar@qt.io>2019-01-28 14:00:05 +0000
commite5fbeb62190696ec2a067476a7408f7b2370c154 (patch)
tree9a33b6d505df6f51929b6cd5bfc2363e4acab24c /src/plugins/clangcodemodel/clangdiagnostictooltipwidget.cpp
parente648c079b8759707175221c6744430373d2cf954 (diff)
downloadqt-creator-e5fbeb62190696ec2a067476a7408f7b2370c154.tar.gz
Clang: Add API to convert diagnostics to plain text
This is for a follow-up change that will allow to copy the diagnostic text from the tooltip to the clipboard. Change-Id: Iad5343a819c84ca83d562f69dcf2f50e1d4785c4 Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
Diffstat (limited to 'src/plugins/clangcodemodel/clangdiagnostictooltipwidget.cpp')
-rw-r--r--src/plugins/clangcodemodel/clangdiagnostictooltipwidget.cpp48
1 files changed, 28 insertions, 20 deletions
diff --git a/src/plugins/clangcodemodel/clangdiagnostictooltipwidget.cpp b/src/plugins/clangcodemodel/clangdiagnostictooltipwidget.cpp
index d92b5d67ac..9fcec8d6b5 100644
--- a/src/plugins/clangcodemodel/clangdiagnostictooltipwidget.cpp
+++ b/src/plugins/clangcodemodel/clangdiagnostictooltipwidget.cpp
@@ -39,6 +39,7 @@
#include <QFileInfo>
#include <QHash>
#include <QLabel>
+#include <QTextDocument>
#include <QUrl>
using namespace ClangCodeModel;
@@ -101,16 +102,6 @@ public:
bool allowTextSelection;
};
- static QWidget *create(const QVector<ClangBackEnd::DiagnosticContainer> &diagnostics,
- const DisplayHints &displayHints)
- {
- WidgetFromDiagnostics converter(displayHints);
- return converter.createWidget(diagnostics);
- }
-
-private:
- enum class IndentMode { Indent, DoNotIndent };
-
WidgetFromDiagnostics(const DisplayHints &displayHints)
: m_displayHints(displayHints)
{
@@ -177,6 +168,9 @@ private:
return text;
}
+private:
+ enum class IndentMode { Indent, DoNotIndent };
+
static bool isClazyOption(const QString &option) { return option.startsWith("-Wclazy"); }
class DiagnosticTextInfo
@@ -446,18 +440,11 @@ private:
QString m_mainFilePath;
};
-} // anonymous namespace
-
-namespace ClangCodeModel {
-namespace Internal {
-
-QWidget *ClangDiagnosticWidget::create(
- const QVector<ClangBackEnd::DiagnosticContainer> &diagnostics,
- const Destination &destination)
+WidgetFromDiagnostics::DisplayHints toHints(const ClangDiagnosticWidget::Destination &destination)
{
WidgetFromDiagnostics::DisplayHints hints;
- if (destination == ToolTip) {
+ if (destination == ClangDiagnosticWidget::ToolTip) {
hints.showCategoryAndEnableOption = true;
hints.showFileNameInMainDiagnostic = false;
hints.enableClickableFixits = true;
@@ -474,7 +461,28 @@ QWidget *ClangDiagnosticWidget::create(
hints.allowTextSelection = true;
}
- return WidgetFromDiagnostics::create(diagnostics, hints);
+ return hints;
+}
+
+} // anonymous namespace
+
+namespace ClangCodeModel {
+namespace Internal {
+
+QString ClangDiagnosticWidget::createText(
+ const QVector<ClangBackEnd::DiagnosticContainer> &diagnostics,
+ const ClangDiagnosticWidget::Destination &destination)
+{
+ const QString htmlText = WidgetFromDiagnostics(toHints(destination)).htmlText(diagnostics);
+ QTextDocument document;
+ document.setHtml(htmlText);
+ return document.toPlainText();
+}
+
+QWidget *ClangDiagnosticWidget::createWidget(
+ const QVector<ClangBackEnd::DiagnosticContainer> &diagnostics, const Destination &destination)
+{
+ return WidgetFromDiagnostics(toHints(destination)).createWidget(diagnostics);
}
} // namespace Internal