diff --git a/src/plugins/autotest/testcodeparser.cpp b/src/plugins/autotest/testcodeparser.cpp index 696780a9501..e5bdb4e70f7 100644 --- a/src/plugins/autotest/testcodeparser.cpp +++ b/src/plugins/autotest/testcodeparser.cpp @@ -971,13 +971,17 @@ void TestCodeParser::updateModelAndCppDocMap(CPlusPlus::Document::Ptr document, foreach (const QString &file, files) { const bool setReferencingFile = (files.size() == 2 && file == declaringFile); ReferencingInfo testInfo; - if (setReferencingFile) + if (setReferencingFile) { testInfo.referencingFile = fileName; + testItem->setReferencingFile(fileName); + } testInfo.type = TestTreeModel::AutoTest; m_referencingFiles.insert(file, testInfo); } emit testItemModified(testItem, TestTreeModel::AutoTest, files); } else { + if (declaringFile != fileName) + testItem->setReferencingFile(fileName); emit testItemCreated(testItem, TestTreeModel::AutoTest); ReferencingInfo testInfo; testInfo.type = TestTreeModel::AutoTest; @@ -1005,6 +1009,7 @@ void TestCodeParser::updateModelAndQuickDocMap(QmlJS::Document::Ptr document, ReferencingInfo testInfo; testInfo.referencingFile = referencingFile; testInfo.type = TestTreeModel::QuickTest; + testItem->setReferencingFile(referencingFile); emit testItemModified(testItem, TestTreeModel::QuickTest, { fileName }); m_referencingFiles.insert(fileName, testInfo); } else { @@ -1015,6 +1020,7 @@ void TestCodeParser::updateModelAndQuickDocMap(QmlJS::Document::Ptr document, ReferencingInfo testInfo; testInfo.referencingFile = referencingFile; testInfo.type = TestTreeModel::QuickTest; + testItem->setReferencingFile(referencingFile); emit testItemCreated(testItem, TestTreeModel::QuickTest); m_referencingFiles.insert(filePath, testInfo); } diff --git a/src/plugins/autotest/testtreeitem.cpp b/src/plugins/autotest/testtreeitem.cpp index 2011b4412cc..679cfc0e19f 100644 --- a/src/plugins/autotest/testtreeitem.cpp +++ b/src/plugins/autotest/testtreeitem.cpp @@ -70,6 +70,7 @@ TestTreeItem::TestTreeItem(const TestTreeItem &other) m_line(other.m_line), m_column(other.m_column), m_mainFile(other.m_mainFile), + m_referencingFile(other.m_referencingFile), m_state(other.m_state) { for (int row = 0, count = other.childCount(); row < count; ++row) @@ -185,6 +186,10 @@ bool TestTreeItem::modifyContent(const TestTreeItem *modified) m_mainFile = modified->m_mainFile; hasBeenModified = true; } + if (m_referencingFile != modified->m_referencingFile) { + m_referencingFile = modified->m_referencingFile; + hasBeenModified = true; + } if (m_type != modified->m_type) { m_type = modified->m_type; hasBeenModified = true; diff --git a/src/plugins/autotest/testtreeitem.h b/src/plugins/autotest/testtreeitem.h index 325486b6694..cf04e780a48 100644 --- a/src/plugins/autotest/testtreeitem.h +++ b/src/plugins/autotest/testtreeitem.h @@ -87,6 +87,8 @@ public: unsigned column() const { return m_column; } QString mainFile() const { return m_mainFile; } void setMainFile(const QString &mainFile) { m_mainFile = mainFile; } + QString referencingFile() const { return m_referencingFile; } + void setReferencingFile(const QString &referencingFile) { m_referencingFile = referencingFile; } void setChecked(const Qt::CheckState checked); Qt::CheckState checked() const; Type type() const { return m_type; } @@ -106,6 +108,7 @@ private: unsigned m_line; unsigned m_column; QString m_mainFile; // main for Quick tests, project file for gtest + QString m_referencingFile; TestStates m_state; }; diff --git a/src/plugins/autotest/testtreemodel.cpp b/src/plugins/autotest/testtreemodel.cpp index 65b7759315e..2f54aa9e1a1 100644 --- a/src/plugins/autotest/testtreemodel.cpp +++ b/src/plugins/autotest/testtreemodel.cpp @@ -42,6 +42,38 @@ namespace Autotest { namespace Internal { +class ReferencingFilesFinder : public Utils::TreeItemVisitor +{ +public: + ReferencingFilesFinder() {} + + bool preVisit(Utils::TreeItem *item) override + { + // 0 = invisible root, 1 = main categories, 2 = test cases, 3 = test functions + return item->level() < 4; + } + + void visit(Utils::TreeItem *item) override + { + // skip invisible root item + if (!item->parent()) + return; + + if (auto testItem = static_cast(item)) { + if (!testItem->filePath().isEmpty() && !testItem->referencingFile().isEmpty()) + m_referencingFiles.insert(testItem->filePath(), testItem->referencingFile()); + } + } + + QMap referencingFiles() const { return m_referencingFiles; } + +private: + QMap m_referencingFiles; + +}; + +/***********************************************************************************************/ + TestTreeModel::TestTreeModel(QObject *parent) : TreeModel(parent), m_autoTestRootItem(new TestTreeItem(tr("Auto Tests"), QString(), TestTreeItem::Root)), @@ -591,6 +623,13 @@ void TestTreeModel::removeGTests(const QString &filePath) emit testTreeModelChanged(); } +QMap TestTreeModel::referencingFiles() const +{ + ReferencingFilesFinder finder; + rootItem()->walkTree(&finder); + return finder.referencingFiles(); +} + void TestTreeModel::addTestTreeItem(TestTreeItem *item, TestTreeModel::Type type) { TestTreeItem *parent = rootItemForType(type); diff --git a/src/plugins/autotest/testtreemodel.h b/src/plugins/autotest/testtreemodel.h index bf96c8e0152..33fafa96422 100644 --- a/src/plugins/autotest/testtreemodel.h +++ b/src/plugins/autotest/testtreemodel.h @@ -78,6 +78,8 @@ public: QMultiMap gtestNamesAndSets() const; #endif + QMap referencingFiles() const; + signals: void testTreeModelChanged();