From eec7339af3bd8e7be8343325306be6faae513d1c Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Thu, 25 Jan 2024 15:39:32 +0100 Subject: [PATCH] Axivion: Make issues clickable For now just a simple approach of using the base directory using the given path and line information. Depending on the issue kind there might be multiple locations but for now only handle one of them. Change-Id: I046b7c42593aa4c30b843fa8f9145fae35e869d4 Reviewed-by: Reviewed-by: Jarek Kobus --- src/plugins/axivion/axivionoutputpane.cpp | 65 ++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/src/plugins/axivion/axivionoutputpane.cpp b/src/plugins/axivion/axivionoutputpane.cpp index 10e2bd7ebe4..b1fe15719eb 100644 --- a/src/plugins/axivion/axivionoutputpane.cpp +++ b/src/plugins/axivion/axivionoutputpane.cpp @@ -7,6 +7,12 @@ #include "axiviontr.h" #include "dashboard/dto.h" +#include + +#include +#include + +#include #include #include #include @@ -173,6 +179,31 @@ void DashboardWidget::updateUi() addValuesWidgets(Tr::tr("Total:"), allTotal, allAdded, allRemoved, row); } +class IssueTreeItem : public Utils::StaticTreeItem +{ +public: + IssueTreeItem(const QStringList &data, const QStringList &toolTips) + : Utils::StaticTreeItem(data, toolTips) + {} + + void setLinks(const Utils::Links &links) { m_links = links; } + + bool setData(int column, const QVariant &value, int role) override + { + if (role == Utils::BaseTreeView::ItemActivatedRole && !m_links.isEmpty()) { + // TODO for now only simple - just the first.. + const Utils::Link link = m_links.first(); + if (link.targetFilePath.exists()) + Core::EditorManager::openEditorAt(link); + return true; + } + return false; + } + +private: + Utils::Links m_links; +}; + class IssuesWidget : public QScrollArea { public: @@ -362,11 +393,42 @@ static QString anyToSimpleString(const Dto::Any &any) return QString(); } +static Utils::Links linksForIssue(const std::map &issueRow, + const Utils::FilePath &baseDir) +{ + Utils::Links links; + + auto end = issueRow.end(); + auto findAndAppend = [&links, &issueRow, &end, &baseDir](const QString &path, + const QString &line) { + auto it = issueRow.find(path); + if (it != end) { + const Utils::FilePath fp = baseDir.pathAppended(it->second.getString()); + Utils::Link link{fp}; + it = issueRow.find(line); + if (it != end) + link.targetLine = it->second.getDouble(); + links.append(link); + } + }; + // do these always? or just for their "expected" kind + findAndAppend("path", "line"); + findAndAppend("sourcePath", "sourceLine"); + findAndAppend("targetPath", "targetLine"); + findAndAppend("leftPath", "leftLine"); + findAndAppend("rightPath", "rightLine"); + + return links; +} + void IssuesWidget::addIssues(const Dto::IssueTableDto &dto) { QTC_ASSERT(m_currentTableInfo.has_value(), return); // handle added/removed/total ? + ProjectExplorer::Project *project = ProjectExplorer::ProjectManager::startupProject(); + Utils::FilePath baseDir = project ? project->projectDirectory() : Utils::FilePath{}; + const std::vector tableColumns = m_currentTableInfo->columns; // const std::vector columns = dto.columns.value(); const std::vector> rows = dto.rows; @@ -381,7 +443,8 @@ void IssuesWidget::addIssues(const Dto::IssueTableDto &dto) data << value; } } - Utils::StaticTreeItem *it = new Utils::StaticTreeItem(data, data); + IssueTreeItem *it = new IssueTreeItem(data, data); + it->setLinks(linksForIssue(row, baseDir)); m_issuesModel->rootItem()->appendChild(it); } m_issuesView->hideProgressIndicator();