forked from qt-creator/qt-creator
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: Niels Weber <niels.weber@theqtcompany.com>
This commit is contained in:
@@ -971,13 +971,17 @@ void TestCodeParser::updateModelAndCppDocMap(CPlusPlus::Document::Ptr document,
|
|||||||
foreach (const QString &file, files) {
|
foreach (const QString &file, files) {
|
||||||
const bool setReferencingFile = (files.size() == 2 && file == declaringFile);
|
const bool setReferencingFile = (files.size() == 2 && file == declaringFile);
|
||||||
ReferencingInfo testInfo;
|
ReferencingInfo testInfo;
|
||||||
if (setReferencingFile)
|
if (setReferencingFile) {
|
||||||
testInfo.referencingFile = fileName;
|
testInfo.referencingFile = fileName;
|
||||||
|
testItem->setReferencingFile(fileName);
|
||||||
|
}
|
||||||
testInfo.type = TestTreeModel::AutoTest;
|
testInfo.type = TestTreeModel::AutoTest;
|
||||||
m_referencingFiles.insert(file, testInfo);
|
m_referencingFiles.insert(file, testInfo);
|
||||||
}
|
}
|
||||||
emit testItemModified(testItem, TestTreeModel::AutoTest, files);
|
emit testItemModified(testItem, TestTreeModel::AutoTest, files);
|
||||||
} else {
|
} else {
|
||||||
|
if (declaringFile != fileName)
|
||||||
|
testItem->setReferencingFile(fileName);
|
||||||
emit testItemCreated(testItem, TestTreeModel::AutoTest);
|
emit testItemCreated(testItem, TestTreeModel::AutoTest);
|
||||||
ReferencingInfo testInfo;
|
ReferencingInfo testInfo;
|
||||||
testInfo.type = TestTreeModel::AutoTest;
|
testInfo.type = TestTreeModel::AutoTest;
|
||||||
@@ -1005,6 +1009,7 @@ void TestCodeParser::updateModelAndQuickDocMap(QmlJS::Document::Ptr document,
|
|||||||
ReferencingInfo testInfo;
|
ReferencingInfo testInfo;
|
||||||
testInfo.referencingFile = referencingFile;
|
testInfo.referencingFile = referencingFile;
|
||||||
testInfo.type = TestTreeModel::QuickTest;
|
testInfo.type = TestTreeModel::QuickTest;
|
||||||
|
testItem->setReferencingFile(referencingFile);
|
||||||
emit testItemModified(testItem, TestTreeModel::QuickTest, { fileName });
|
emit testItemModified(testItem, TestTreeModel::QuickTest, { fileName });
|
||||||
m_referencingFiles.insert(fileName, testInfo);
|
m_referencingFiles.insert(fileName, testInfo);
|
||||||
} else {
|
} else {
|
||||||
@@ -1015,6 +1020,7 @@ void TestCodeParser::updateModelAndQuickDocMap(QmlJS::Document::Ptr document,
|
|||||||
ReferencingInfo testInfo;
|
ReferencingInfo testInfo;
|
||||||
testInfo.referencingFile = referencingFile;
|
testInfo.referencingFile = referencingFile;
|
||||||
testInfo.type = TestTreeModel::QuickTest;
|
testInfo.type = TestTreeModel::QuickTest;
|
||||||
|
testItem->setReferencingFile(referencingFile);
|
||||||
emit testItemCreated(testItem, TestTreeModel::QuickTest);
|
emit testItemCreated(testItem, TestTreeModel::QuickTest);
|
||||||
m_referencingFiles.insert(filePath, testInfo);
|
m_referencingFiles.insert(filePath, testInfo);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ TestTreeItem::TestTreeItem(const TestTreeItem &other)
|
|||||||
m_line(other.m_line),
|
m_line(other.m_line),
|
||||||
m_column(other.m_column),
|
m_column(other.m_column),
|
||||||
m_mainFile(other.m_mainFile),
|
m_mainFile(other.m_mainFile),
|
||||||
|
m_referencingFile(other.m_referencingFile),
|
||||||
m_state(other.m_state)
|
m_state(other.m_state)
|
||||||
{
|
{
|
||||||
for (int row = 0, count = other.childCount(); row < count; ++row)
|
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;
|
m_mainFile = modified->m_mainFile;
|
||||||
hasBeenModified = true;
|
hasBeenModified = true;
|
||||||
}
|
}
|
||||||
|
if (m_referencingFile != modified->m_referencingFile) {
|
||||||
|
m_referencingFile = modified->m_referencingFile;
|
||||||
|
hasBeenModified = true;
|
||||||
|
}
|
||||||
if (m_type != modified->m_type) {
|
if (m_type != modified->m_type) {
|
||||||
m_type = modified->m_type;
|
m_type = modified->m_type;
|
||||||
hasBeenModified = true;
|
hasBeenModified = true;
|
||||||
|
|||||||
@@ -87,6 +87,8 @@ public:
|
|||||||
unsigned column() const { return m_column; }
|
unsigned column() const { return m_column; }
|
||||||
QString mainFile() const { return m_mainFile; }
|
QString mainFile() const { return m_mainFile; }
|
||||||
void setMainFile(const QString &mainFile) { m_mainFile = 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);
|
void setChecked(const Qt::CheckState checked);
|
||||||
Qt::CheckState checked() const;
|
Qt::CheckState checked() const;
|
||||||
Type type() const { return m_type; }
|
Type type() const { return m_type; }
|
||||||
@@ -106,6 +108,7 @@ private:
|
|||||||
unsigned m_line;
|
unsigned m_line;
|
||||||
unsigned m_column;
|
unsigned m_column;
|
||||||
QString m_mainFile; // main for Quick tests, project file for gtest
|
QString m_mainFile; // main for Quick tests, project file for gtest
|
||||||
|
QString m_referencingFile;
|
||||||
TestStates m_state;
|
TestStates m_state;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -42,6 +42,38 @@
|
|||||||
namespace Autotest {
|
namespace Autotest {
|
||||||
namespace Internal {
|
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) :
|
TestTreeModel::TestTreeModel(QObject *parent) :
|
||||||
TreeModel(parent),
|
TreeModel(parent),
|
||||||
m_autoTestRootItem(new TestTreeItem(tr("Auto Tests"), QString(), TestTreeItem::Root)),
|
m_autoTestRootItem(new TestTreeItem(tr("Auto Tests"), QString(), TestTreeItem::Root)),
|
||||||
@@ -591,6 +623,13 @@ void TestTreeModel::removeGTests(const QString &filePath)
|
|||||||
emit testTreeModelChanged();
|
emit testTreeModelChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QMap<QString, QString> TestTreeModel::referencingFiles() const
|
||||||
|
{
|
||||||
|
ReferencingFilesFinder finder;
|
||||||
|
rootItem()->walkTree(&finder);
|
||||||
|
return finder.referencingFiles();
|
||||||
|
}
|
||||||
|
|
||||||
void TestTreeModel::addTestTreeItem(TestTreeItem *item, TestTreeModel::Type type)
|
void TestTreeModel::addTestTreeItem(TestTreeItem *item, TestTreeModel::Type type)
|
||||||
{
|
{
|
||||||
TestTreeItem *parent = rootItemForType(type);
|
TestTreeItem *parent = rootItemForType(type);
|
||||||
|
|||||||
@@ -78,6 +78,8 @@ public:
|
|||||||
QMultiMap<QString, int> gtestNamesAndSets() const;
|
QMultiMap<QString, int> gtestNamesAndSets() const;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
QMap<QString, QString> referencingFiles() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void testTreeModelChanged();
|
void testTreeModelChanged();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user