From 63823a55acf2739c77a27a1b56ecf4c5a3f52ad7 Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Tue, 21 Jul 2020 12:42:37 +0200 Subject: [PATCH] AutoTest: Display relative path for file nodes Using the full path for the file nodes may be quite long depending on the location of the project. Display its name relative to the project directory or the parent group node instead. Fixes: QTCREATORBUG-24374 Change-Id: I4ce57a0940008d99c51e63c2265a371a0ffe20ef Reviewed-by: David Schulz --- src/plugins/autotest/catch/catchtreeitem.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/plugins/autotest/catch/catchtreeitem.cpp b/src/plugins/autotest/catch/catchtreeitem.cpp index cdd48d85368..e62cbe0da78 100644 --- a/src/plugins/autotest/catch/catchtreeitem.cpp +++ b/src/plugins/autotest/catch/catchtreeitem.cpp @@ -27,6 +27,7 @@ #include "catchconfiguration.h" #include "catchframework.h" +#include #include #include @@ -38,14 +39,26 @@ QString CatchTreeItem::testCasesString() const return m_state & CatchTreeItem::Parameterized ? QString(name() + " -*") : name(); } +static QString nonRootDisplayName(const CatchTreeItem *it) +{ + if (it->type() != TestTreeItem::TestSuite) + return it->name(); + ProjectExplorer::Project *project = ProjectExplorer::SessionManager::startupProject(); + if (!project) + return it->name(); + TestTreeItem *parent = it->parentItem(); + int baseDirSize = (parent->type() == TestTreeItem::GroupNode) + ? parent->filePath().size() : project->projectDirectory().toString().size(); + return it->name().mid(baseDirSize + 1); +} + QVariant CatchTreeItem::data(int column, int role) const { - switch (role) { case Qt::DisplayRole: if (type() == Root) break; - return QString(name() + stateSuffix()); + return QString(nonRootDisplayName(this) + stateSuffix()); case Qt::CheckStateRole: switch (type()) { case Root: