forked from qt-creator/qt-creator
		
	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>
This commit is contained in:
		@@ -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
 | 
			
		||||
    {
 | 
			
		||||
        if (!index.isValid() || role == Qt::DecorationRole)
 | 
			
		||||
        return 2;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    QVariant data(const QModelIndex &fullIndex, int role = Qt::DisplayRole) const final
 | 
			
		||||
    {
 | 
			
		||||
        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"));
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user