Commit 1caeb9bb authored by Christian Stenger's avatar Christian Stenger
Browse files

AutoTest: Store referencing file inside test tree item



This duplicates (temporarily) the information for referencing files,
but the cache inside the parser will be removed within a later patch.

Change-Id: I7377864547f0d9ce074fa409b9c12067c4329d40
Reviewed-by: default avatarNiels Weber <niels.weber@theqtcompany.com>
parent 3d5bb6d0
......@@ -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);
}
......
......@@ -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;
......
......@@ -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;
};
......
......@@ -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<TestTreeItem *>(item)) {
if (!testItem->filePath().isEmpty() && !testItem->referencingFile().isEmpty())
m_referencingFiles.insert(testItem->filePath(), testItem->referencingFile());
}
}
QMap<QString, QString> referencingFiles() const { return m_referencingFiles; }
private:
QMap<QString, QString> 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<QString, QString> TestTreeModel::referencingFiles() const
{
ReferencingFilesFinder finder;
rootItem()->walkTree(&finder);
return finder.referencingFiles();
}
void TestTreeModel::addTestTreeItem(TestTreeItem *item, TestTreeModel::Type type)
{
TestTreeItem *parent = rootItemForType(type);
......
......@@ -78,6 +78,8 @@ public:
QMultiMap<QString, int> gtestNamesAndSets() const;
#endif
QMap<QString, QString> referencingFiles() const;
signals:
void testTreeModelChanged();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment