From 99aed851ef8abdccb3c13686db61f644a51fe44c Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Fri, 22 Mar 2024 11:26:04 +0100 Subject: [PATCH] Axivion: Improve path mapping If the linked project is not the top level project our path mappings did not work. Try to get the correct file path by using QC internal find functionality. This helps for opening files by activating issues inside the issues table or when clicking links of the issue details. Unfortunately this does not help for the inline annotations or respective marks. Change-Id: Ie34e1b20ff8b1b2b37e9f04c1d41bc2a4c33f260 Reviewed-by: Eike Ziller --- src/plugins/axivion/axivionoutputpane.cpp | 2 +- src/plugins/axivion/axivionplugin.cpp | 24 ++++++++++++++++++++--- src/plugins/axivion/axivionplugin.h | 2 ++ 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/plugins/axivion/axivionoutputpane.cpp b/src/plugins/axivion/axivionoutputpane.cpp index 79c90936cf4..d66468590bf 100644 --- a/src/plugins/axivion/axivionoutputpane.cpp +++ b/src/plugins/axivion/axivionoutputpane.cpp @@ -235,7 +235,7 @@ public: }).link; Project *project = ProjectManager::startupProject(); FilePath baseDir = project ? project->projectDirectory() : FilePath{}; - link.targetFilePath = baseDir.resolvePath(link.targetFilePath); + link.targetFilePath = findFileForIssuePath(link.targetFilePath); if (link.targetFilePath.exists()) EditorManager::openEditorAt(link); } diff --git a/src/plugins/axivion/axivionplugin.cpp b/src/plugins/axivion/axivionplugin.cpp index fa455c07eb9..0f4686e403c 100644 --- a/src/plugins/axivion/axivionplugin.cpp +++ b/src/plugins/axivion/axivionplugin.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -236,6 +237,7 @@ public: TaskTreeRunner m_taskTreeRunner; std::unordered_map> m_docMarksTrees; TaskTreeRunner m_issueInfoRunner; + FileInProjectFinder m_fileFinder; // FIXME maybe obsolete when path mapping is implemented }; static AxivionPluginPrivate *dd = nullptr; @@ -337,10 +339,17 @@ void AxivionPluginPrivate::onStartupProjectChanged(Project *project) m_currentProjectInfo = {}; updateDashboard(); - if (!m_project) + if (!m_project) { + m_fileFinder.setProjectDirectory({}); + m_fileFinder.setProjectFiles({}); return; + } - connect(m_project, &Project::fileListChanged, this, &AxivionPluginPrivate::handleOpenedDocs); + m_fileFinder.setProjectDirectory(m_project->projectDirectory()); + connect(m_project, &Project::fileListChanged, this, [this]{ + m_fileFinder.setProjectFiles(m_project->files(Project::AllFiles)); + handleOpenedDocs(); + }); const AxivionProjectSettings *projSettings = AxivionProjectSettings::projectSettings(m_project); fetchProjectInfo(projSettings->dashboardProjectName()); } @@ -961,7 +970,7 @@ void AxivionPluginPrivate::handleAnchorClicked(const QUrl &url) return; Link link; if (const QString path = query.queryItemValue("filename", QUrl::FullyDecoded); !path.isEmpty()) - link.targetFilePath = m_project->projectDirectory().pathAppended(path); + link.targetFilePath = findFileForIssuePath(FilePath::fromUserInput(path)); if (const QString line = query.queryItemValue("line"); !line.isEmpty()) link.targetLine = line.toInt(); // column entry is wrong - so, ignore it @@ -1040,6 +1049,15 @@ const std::optional currentDashboardInfo() return dd->m_dashboardInfo; } +Utils::FilePath findFileForIssuePath(const Utils::FilePath &issuePath) +{ + QTC_ASSERT(dd, return {}); + const FilePaths result = dd->m_fileFinder.findFile(QUrl::fromLocalFile(issuePath.toString())); + if (result.size() == 1) + return dd->m_project->projectDirectory().resolvePath(result.first()); + return {}; +} + } // Axivion::Internal #include "axivionplugin.moc" diff --git a/src/plugins/axivion/axivionplugin.h b/src/plugins/axivion/axivionplugin.h index db2f8494cb0..059e950ecc4 100644 --- a/src/plugins/axivion/axivionplugin.h +++ b/src/plugins/axivion/axivionplugin.h @@ -79,5 +79,7 @@ void fetchIssueInfo(const QString &id); const std::optional currentDashboardInfo(); +Utils::FilePath findFileForIssuePath(const Utils::FilePath &issuePath); + } // Axivion::Internal