diff options
author | Ivan Donchevskii <ivan.donchevskii@qt.io> | 2018-05-29 14:38:57 +0200 |
---|---|---|
committer | Ivan Donchevskii <ivan.donchevskii@qt.io> | 2018-05-31 12:43:45 +0000 |
commit | 95aa52707d16f238119657c5237eeebb6833bc78 (patch) | |
tree | 79303695cb83c488f6006bc5a65a4024d7e37eb6 /src/plugins/cpptools/clangdiagnosticconfigswidget.cpp | |
parent | 2defef3d6f8048dacc8072b1f23ba72d6388b5c1 (diff) | |
download | qt-creator-95aa52707d16f238119657c5237eeebb6833bc78.tar.gz |
Clang: Add links to web pages in Clang-Tidy configuration
Each Clang-Tidy check get the separate link except
clang-analyzer which has only a whole group page.
Change-Id: I0b63cce8475109812280d9d44ac2d36aaa66e03b
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
Diffstat (limited to 'src/plugins/cpptools/clangdiagnosticconfigswidget.cpp')
-rw-r--r-- | src/plugins/cpptools/clangdiagnosticconfigswidget.cpp | 68 |
1 files changed, 59 insertions, 9 deletions
diff --git a/src/plugins/cpptools/clangdiagnosticconfigswidget.cpp b/src/plugins/cpptools/clangdiagnosticconfigswidget.cpp index 22b2950e5a..6b5e0d7334 100644 --- a/src/plugins/cpptools/clangdiagnosticconfigswidget.cpp +++ b/src/plugins/cpptools/clangdiagnosticconfigswidget.cpp @@ -27,6 +27,7 @@ #include "cppcodemodelsettings.h" #include "cpptools_clangtidychecks.h" +#include "cpptoolsconstants.h" #include "cpptoolsreuse.h" #include "ui_clangdiagnosticconfigswidget.h" #include "ui_clangbasechecks.h" @@ -40,6 +41,7 @@ #include <utils/utilsicons.h> #include <QDebug> +#include <QDesktopServices> #include <QDialogButtonBox> #include <QInputDialog> #include <QPushButton> @@ -47,6 +49,9 @@ namespace CppTools { +static constexpr const char CLANG_STATIC_ANALYZER_URL[] + = "https://clang-analyzer.llvm.org/available_checks.html"; + static void buildTree(ProjectExplorer::Tree *parent, ProjectExplorer::Tree *current, const Constants::TidyNode &node) @@ -64,6 +69,12 @@ static void buildTree(ProjectExplorer::Tree *parent, buildTree(current, new ProjectExplorer::Tree, nodeChild); } +static bool needsLink(ProjectExplorer::Tree *node) { + if (node->name == "clang-analyzer-") + return true; + return !node->isDir && !node->fullPath.toString().startsWith("clang-analyzer-"); +} + class TidyChecksTreeModel final : public ProjectExplorer::SelectableFilesModel { Q_OBJECT @@ -108,14 +119,45 @@ public: } } - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const final + int columnCount(const QModelIndex &/*parent*/) const override + { + return 2; + } + + QVariant data(const QModelIndex &fullIndex, int role = Qt::DisplayRole) const final { - if (!index.isValid() || role == Qt::DecorationRole) + if (!fullIndex.isValid() || role == Qt::DecorationRole) + return QVariant(); + QModelIndex index = this->index(fullIndex.row(), 0, fullIndex.parent()); + auto *node = static_cast<ProjectExplorer::Tree *>(index.internalPointer()); + + if (fullIndex.column() == 1) { + if (!needsLink(node)) + return QVariant(); + switch (role) { + case Qt::DisplayRole: + return tr("Web Page"); + case Qt::FontRole: { + QFont font = QApplication::font(); + font.setUnderline(true); + return font; + } + case Qt::ForegroundRole: + return QApplication::palette().link().color(); + case Qt::UserRole: { + // 'clang-analyzer-' group + if (node->isDir) + return QString::fromUtf8(CLANG_STATIC_ANALYZER_URL); + return QString::fromUtf8(Constants::TIDY_DOCUMENTATION_URL_TEMPLATE) + .arg(node->fullPath.toString()); + } + } return QVariant(); - if (role == Qt::DisplayRole) { - auto *node = static_cast<ProjectExplorer::Tree *>(index.internalPointer()); - return node->isDir ? (node->name + "*") : node->name; } + + if (role == Qt::DisplayRole) + return node->isDir ? (node->name + "*") : node->name; + return ProjectExplorer::SelectableFilesModel::data(index, role); } @@ -160,10 +202,7 @@ private: return false; } - if (!check.startsWith(nodeName)) - return false; - - return true; + return check.startsWith(nodeName); }); return result; } @@ -203,6 +242,15 @@ ClangDiagnosticConfigsWidget::ClangDiagnosticConfigsWidget(const Core::Id &confi this, &ClangDiagnosticConfigsWidget::onRemoveButtonClicked); connectDiagnosticOptionsChanged(); + connect(m_tidyChecks->checksPrefixesTree, &QTreeView::clicked, + [this](const QModelIndex &index) { + const QString link = m_tidyTreeModel->data(index, Qt::UserRole).toString(); + if (link.isEmpty()) + return; + + QDesktopServices::openUrl(QUrl(link)); + }); + syncWidgetsToModel(configToSelect); } @@ -599,6 +647,8 @@ void ClangDiagnosticConfigsWidget::setupTabs() m_tidyChecks->setupUi(m_tidyChecksWidget); m_tidyChecks->checksPrefixesTree->setModel(m_tidyTreeModel.get()); m_tidyChecks->checksPrefixesTree->expandToDepth(0); + m_tidyChecks->checksPrefixesTree->header()->setStretchLastSection(false); + m_tidyChecks->checksPrefixesTree->header()->setSectionResizeMode(0, QHeaderView::Stretch); connect(m_tidyChecks->plainTextEditButton, &QPushButton::clicked, this, [this]() { QDialog dialog; dialog.setWindowTitle(tr("Checks")); |