forked from qt-creator/qt-creator
Use pointers for test tree items
Part of preparing to re-use QC's TreeModel/TreeItem for TestTreeModel/TestTreeItem. Change-Id: I8699405c3dcad88df67171af2d542bc8e3fd2fc0 Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
This commit is contained in:
@@ -63,7 +63,7 @@ AutotestPlugin::AutotestPlugin()
|
||||
{
|
||||
// needed to be used in QueuedConnection connects
|
||||
qRegisterMetaType<TestResult>();
|
||||
qRegisterMetaType<TestTreeItem>();
|
||||
qRegisterMetaType<TestTreeItem *>();
|
||||
qRegisterMetaType<TestCodeLocationAndType>();
|
||||
qRegisterMetaType<TestTreeModel::Type>();
|
||||
|
||||
|
@@ -382,18 +382,17 @@ static QMap<QString, TestCodeLocationList> checkForDataTags(const QString &fileN
|
||||
return QMap<QString, TestCodeLocationList>();
|
||||
}
|
||||
|
||||
|
||||
static TestTreeItem constructTestTreeItem(const QString &fileName,
|
||||
const QString &mainFile, // used for Quick Tests only
|
||||
const QString &testCaseName,
|
||||
int line, int column,
|
||||
const QMap<QString, TestCodeLocationAndType> functions,
|
||||
const QMap<QString, TestCodeLocationList> dataTags = QMap<QString, TestCodeLocationList>())
|
||||
static TestTreeItem *constructTestTreeItem(const QString &fileName,
|
||||
const QString &mainFile, // used for Quick Tests only
|
||||
const QString &testCaseName,
|
||||
int line, int column,
|
||||
const QMap<QString, TestCodeLocationAndType> &functions,
|
||||
const QMap<QString, TestCodeLocationList> dataTags = QMap<QString, TestCodeLocationList>())
|
||||
{
|
||||
TestTreeItem treeItem(testCaseName, fileName, TestTreeItem::TEST_CLASS);
|
||||
treeItem.setMainFile(mainFile); // used for Quick Tests only
|
||||
treeItem.setLine(line);
|
||||
treeItem.setColumn(column);
|
||||
TestTreeItem *treeItem = new TestTreeItem(testCaseName, fileName, TestTreeItem::TEST_CLASS);
|
||||
treeItem->setMainFile(mainFile); // used for Quick Tests only
|
||||
treeItem->setLine(line);
|
||||
treeItem->setColumn(column);
|
||||
|
||||
foreach (const QString &functionName, functions.keys()) {
|
||||
const TestCodeLocationAndType locationAndType = functions.value(functionName);
|
||||
@@ -401,6 +400,7 @@ static TestTreeItem constructTestTreeItem(const QString &fileName,
|
||||
locationAndType.m_type);
|
||||
treeItemChild->setLine(locationAndType.m_line);
|
||||
treeItemChild->setColumn(locationAndType.m_column);
|
||||
|
||||
// check for data tags and if there are any for this function add them
|
||||
const QString qualifiedFunctionName = testCaseName + QLatin1String("::") + functionName;
|
||||
if (dataTags.contains(qualifiedFunctionName)) {
|
||||
@@ -415,7 +415,7 @@ static TestTreeItem constructTestTreeItem(const QString &fileName,
|
||||
}
|
||||
}
|
||||
|
||||
treeItem.appendChild(treeItemChild);
|
||||
treeItem->appendChild(treeItemChild);
|
||||
}
|
||||
return treeItem;
|
||||
}
|
||||
@@ -482,9 +482,10 @@ void TestCodeParser::checkDocumentForTestCode(CPlusPlus::Document::Ptr document)
|
||||
|
||||
const QMap<QString, TestCodeLocationList> dataTags =
|
||||
checkForDataTags(declaringDoc->fileName(), testFunctions);
|
||||
TestTreeItem item = constructTestTreeItem(declaringDoc->fileName(), QString(),
|
||||
testCaseName, line, column, testFunctions,
|
||||
dataTags);
|
||||
TestTreeItem *item = constructTestTreeItem(declaringDoc->fileName(), QString(),
|
||||
testCaseName, line, column, testFunctions,
|
||||
dataTags);
|
||||
|
||||
updateModelAndCppDocMap(document, declaringDoc->fileName(), item);
|
||||
return;
|
||||
}
|
||||
@@ -532,7 +533,7 @@ void TestCodeParser::handleQtQuickTest(CPlusPlus::Document::Ptr document)
|
||||
} // end of handling test cases without name property
|
||||
|
||||
// construct new/modified TestTreeItem
|
||||
TestTreeItem testTreeItem
|
||||
TestTreeItem *testTreeItem
|
||||
= constructTestTreeItem(tcLocationAndType.m_name, cppFileName, testCaseName,
|
||||
tcLocationAndType.m_line, tcLocationAndType.m_column,
|
||||
testFunctions);
|
||||
@@ -761,14 +762,11 @@ void TestCodeParser::removeTestsIfNecessary(const QString &fileName)
|
||||
// unnamed Quick Tests must be handled separately
|
||||
if (fileName.endsWith(QLatin1String(".qml"))) {
|
||||
removeUnnamedQuickTestsByName(fileName);
|
||||
emit unnamedQuickTestsRemoved(fileName);
|
||||
} else {
|
||||
QSet<QString> filePaths;
|
||||
m_model->qmlFilesForMainFile(fileName, &filePaths);
|
||||
foreach (const QString &file, filePaths) {
|
||||
foreach (const QString &file, filePaths)
|
||||
removeUnnamedQuickTestsByName(file);
|
||||
emit unnamedQuickTestsRemoved(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -862,37 +860,37 @@ void TestCodeParser::updateUnnamedQuickTests(const QString &fileName, const QStr
|
||||
m_unnamedQuickDocList.append(info);
|
||||
}
|
||||
|
||||
emit unnamedQuickTestsUpdated(fileName, mainFile, functions);
|
||||
emit unnamedQuickTestsUpdated(mainFile, functions);
|
||||
}
|
||||
|
||||
void TestCodeParser::updateModelAndCppDocMap(CPlusPlus::Document::Ptr document,
|
||||
const QString &declaringFile, TestTreeItem &testItem)
|
||||
const QString &declaringFile, TestTreeItem *testItem)
|
||||
{
|
||||
const CppTools::CppModelManager *cppMM = CppTools::CppModelManager::instance();
|
||||
const QString fileName = document->fileName();
|
||||
const QString testCaseName = testItem.name();
|
||||
const QString testCaseName = testItem->name();
|
||||
QString proFile;
|
||||
const QList<CppTools::ProjectPart::Ptr> ppList = cppMM->projectPart(fileName);
|
||||
if (ppList.size())
|
||||
proFile = ppList.at(0)->projectFile;
|
||||
|
||||
if (m_cppDocMap.contains(fileName)) {
|
||||
QStringList files = QStringList() << fileName;
|
||||
QStringList files = { fileName };
|
||||
if (fileName != declaringFile)
|
||||
files << declaringFile;
|
||||
foreach (const QString &file, files) {
|
||||
const bool setReferencingFile = (files.size() == 2 && file == declaringFile);
|
||||
emit testItemModified(testItem, TestTreeModel::AutoTest, file);
|
||||
TestInfo testInfo(testCaseName, testItem.getChildNames(),
|
||||
TestInfo testInfo(testCaseName, testItem->getChildNames(),
|
||||
document->revision(), document->editorRevision());
|
||||
testInfo.setProfile(proFile);
|
||||
if (setReferencingFile)
|
||||
testInfo.setReferencingFile(fileName);
|
||||
m_cppDocMap.insert(file, testInfo);
|
||||
}
|
||||
emit testItemModified(testItem, TestTreeModel::AutoTest, files);
|
||||
} else {
|
||||
emit testItemCreated(testItem, TestTreeModel::AutoTest);
|
||||
TestInfo ti(testCaseName, testItem.getChildNames(),
|
||||
TestInfo ti(testCaseName, testItem->getChildNames(),
|
||||
document->revision(), document->editorRevision());
|
||||
ti.setProfile(proFile);
|
||||
m_cppDocMap.insert(fileName, ti);
|
||||
@@ -905,7 +903,7 @@ void TestCodeParser::updateModelAndCppDocMap(CPlusPlus::Document::Ptr document,
|
||||
|
||||
void TestCodeParser::updateModelAndQuickDocMap(QmlJS::Document::Ptr document,
|
||||
const QString &referencingFile,
|
||||
TestTreeItem &testItem)
|
||||
TestTreeItem *testItem)
|
||||
{
|
||||
const CppTools::CppModelManager *cppMM = CppTools::CppModelManager::instance();
|
||||
const QString fileName = document->fileName();
|
||||
@@ -915,21 +913,21 @@ void TestCodeParser::updateModelAndQuickDocMap(QmlJS::Document::Ptr document,
|
||||
proFile = ppList.at(0)->projectFile;
|
||||
|
||||
if (m_quickDocMap.contains(fileName)) {
|
||||
emit testItemModified(testItem, TestTreeModel::QuickTest, fileName);
|
||||
TestInfo testInfo(testItem.name(), testItem.getChildNames(), 0, document->editorRevision());
|
||||
TestInfo testInfo(testItem->name(), testItem->getChildNames(), 0, document->editorRevision());
|
||||
testInfo.setReferencingFile(referencingFile);
|
||||
testInfo.setProfile(proFile);
|
||||
emit testItemModified(testItem, TestTreeModel::QuickTest, { fileName });
|
||||
m_quickDocMap.insert(fileName, testInfo);
|
||||
} else {
|
||||
// if it was formerly unnamed remove the respective items
|
||||
removeUnnamedQuickTestsByName(fileName);
|
||||
emit unnamedQuickTestsRemoved(fileName);
|
||||
|
||||
emit testItemCreated(testItem, TestTreeModel::QuickTest);
|
||||
TestInfo testInfo(testItem.name(), testItem.getChildNames(), 0, document->editorRevision());
|
||||
const QString &filePath = testItem->filePath();
|
||||
TestInfo testInfo(testItem->name(), testItem->getChildNames(), 0, document->editorRevision());
|
||||
testInfo.setReferencingFile(referencingFile);
|
||||
testInfo.setProfile(proFile);
|
||||
m_quickDocMap.insert(testItem.filePath(), testInfo);
|
||||
emit testItemCreated(testItem, TestTreeModel::QuickTest);
|
||||
m_quickDocMap.insert(filePath, testInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -939,6 +937,7 @@ void TestCodeParser::removeUnnamedQuickTestsByName(const QString &fileName)
|
||||
if (m_unnamedQuickDocList.at(i).fileName() == fileName)
|
||||
m_unnamedQuickDocList.removeAt(i);
|
||||
}
|
||||
emit unnamedQuickTestsRemoved(fileName);
|
||||
}
|
||||
|
||||
#ifdef WITH_TESTS
|
||||
|
@@ -66,11 +66,11 @@ public:
|
||||
|
||||
signals:
|
||||
void cacheCleared();
|
||||
void testItemCreated(const TestTreeItem &item, TestTreeModel::Type type);
|
||||
void testItemCreated(TestTreeItem *item, TestTreeModel::Type type);
|
||||
void testItemsCreated(const QList<TestTreeItem> &itemList, TestTreeModel::Type type);
|
||||
void testItemModified(TestTreeItem tItem, TestTreeModel::Type type, const QString &file);
|
||||
void testItemModified(TestTreeItem *tItem, TestTreeModel::Type type, const QStringList &file);
|
||||
void testItemsRemoved(const QString &filePath, TestTreeModel::Type type);
|
||||
void unnamedQuickTestsUpdated(const QString &filePath, const QString &mainFile,
|
||||
void unnamedQuickTestsUpdated(const QString &mainFile,
|
||||
const QMap<QString, TestCodeLocationAndType> &functions);
|
||||
void unnamedQuickTestsRemoved(const QString &filePath);
|
||||
void parsingStarted();
|
||||
@@ -103,9 +103,9 @@ private:
|
||||
void updateUnnamedQuickTests(const QString &fileName, const QString &mainFile,
|
||||
const QMap<QString, TestCodeLocationAndType> &functions);
|
||||
void updateModelAndCppDocMap(CPlusPlus::Document::Ptr document,
|
||||
const QString &declaringFile, TestTreeItem &testItem);
|
||||
const QString &declaringFile, TestTreeItem *testItem);
|
||||
void updateModelAndQuickDocMap(QmlJS::Document::Ptr document,
|
||||
const QString &referencingFile, TestTreeItem &testItem);
|
||||
const QString &referencingFile, TestTreeItem *testItem);
|
||||
void removeUnnamedQuickTestsByName(const QString &fileName);
|
||||
|
||||
TestTreeModel *m_model;
|
||||
|
@@ -95,7 +95,7 @@ typedef QVector<TestCodeLocationAndType> TestCodeLocationList;
|
||||
} // namespace Internal
|
||||
} // namespace Autotest
|
||||
|
||||
Q_DECLARE_METATYPE(Autotest::Internal::TestTreeItem)
|
||||
Q_DECLARE_METATYPE(Autotest::Internal::TestTreeItem *)
|
||||
Q_DECLARE_METATYPE(Autotest::Internal::TestCodeLocationAndType)
|
||||
|
||||
#endif // TESTTREEITEM_H
|
||||
|
@@ -659,14 +659,13 @@ void TestTreeModel::removeUnnamedQuickTests(const QString &filePath)
|
||||
emit testTreeModelChanged();
|
||||
}
|
||||
|
||||
void TestTreeModel::addTestTreeItem(const TestTreeItem &item, TestTreeModel::Type type)
|
||||
void TestTreeModel::addTestTreeItem(TestTreeItem *item, TestTreeModel::Type type)
|
||||
{
|
||||
TestTreeItem *parent = rootItemForType(type);
|
||||
QModelIndex index = rootIndexForType(type);
|
||||
TestTreeItem *toBeAdded = new TestTreeItem(item);
|
||||
|
||||
beginInsertRows(index, parent->childCount(), parent->childCount());
|
||||
parent->appendChild(toBeAdded);
|
||||
parent->appendChild(item);
|
||||
endInsertRows();
|
||||
emit testTreeModelChanged();
|
||||
}
|
||||
@@ -682,17 +681,21 @@ void TestTreeModel::addTestTreeItems(const QList<TestTreeItem> &itemList, TestTr
|
||||
parent->appendChild(toBeAdded);
|
||||
}
|
||||
endInsertRows();
|
||||
emit testTreeModelChanged();
|
||||
}
|
||||
|
||||
void TestTreeModel::updateUnnamedQuickTest(const QString &fileName, const QString &mainFile,
|
||||
void TestTreeModel::updateUnnamedQuickTest(const QString &mainFile,
|
||||
const QMap<QString, TestCodeLocationAndType> &functions)
|
||||
{
|
||||
removeUnnamedQuickTests(fileName);
|
||||
TestTreeItem unnamed = hasUnnamedQuickTests()
|
||||
? TestTreeItem(*unnamedQuickTests())
|
||||
: TestTreeItem(QString(), QString(), TestTreeItem::TEST_CLASS);
|
||||
if (functions.isEmpty())
|
||||
return;
|
||||
|
||||
if (!hasUnnamedQuickTests())
|
||||
addTestTreeItem(new TestTreeItem(QString(), QString(), TestTreeItem::TEST_CLASS), QuickTest);
|
||||
|
||||
TestTreeItem *unnamed = unnamedQuickTests();
|
||||
QModelIndex unnamedIndex = index(unnamed->row(), 0, rootIndexForType(QuickTest));
|
||||
|
||||
beginInsertRows(unnamedIndex, unnamed->childCount(), unnamed->childCount() + functions.size());
|
||||
foreach (const QString &functionName, functions.keys()) {
|
||||
const TestCodeLocationAndType locationAndType = functions.value(functionName);
|
||||
TestTreeItem *testFunction = new TestTreeItem(functionName, locationAndType.m_name,
|
||||
@@ -700,32 +703,35 @@ void TestTreeModel::updateUnnamedQuickTest(const QString &fileName, const QStrin
|
||||
testFunction->setLine(locationAndType.m_line);
|
||||
testFunction->setColumn(locationAndType.m_column);
|
||||
testFunction->setMainFile(mainFile);
|
||||
unnamed.appendChild(testFunction);
|
||||
unnamed->appendChild(testFunction);
|
||||
}
|
||||
if (hasUnnamedQuickTests())
|
||||
modifyTestTreeItem(unnamed, QuickTest, QString());
|
||||
else
|
||||
addTestTreeItem(unnamed, QuickTest);
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
void TestTreeModel::modifyTestTreeItem(TestTreeItem item, TestTreeModel::Type type, const QString &file)
|
||||
void TestTreeModel::modifyTestTreeItem(TestTreeItem *item, TestTreeModel::Type type, const QStringList &files)
|
||||
{
|
||||
QModelIndex index = rootIndexForType(type);
|
||||
TestTreeItem *parent = rootItemForType(type);
|
||||
if (file.isEmpty()) {
|
||||
if (files.isEmpty()) {
|
||||
if (TestTreeItem *unnamed = unnamedQuickTests()) {
|
||||
if (unnamed == item) // no need to update or delete
|
||||
return;
|
||||
|
||||
index = index.child(unnamed->row(), 0);
|
||||
modifyTestSubtree(index, item);
|
||||
}
|
||||
} else {
|
||||
for (int row = 0; row < parent->childCount(); ++row) {
|
||||
if (parent->child(row)->filePath() == file) {
|
||||
if (files.contains(parent->child(row)->filePath())) {
|
||||
index = index.child(row, 0);
|
||||
modifyTestSubtree(index, item);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// item was created as temporary, destroy it if it won't get destroyed by its parent
|
||||
if (!item->parent())
|
||||
delete item;
|
||||
}
|
||||
|
||||
void TestTreeModel::removeAllTestItems()
|
||||
@@ -774,19 +780,19 @@ QModelIndex TestTreeModel::rootIndexForType(TestTreeModel::Type type)
|
||||
QTC_ASSERT(false, return QModelIndex());
|
||||
}
|
||||
|
||||
void TestTreeModel::modifyTestSubtree(QModelIndex &toBeModifiedIndex, const TestTreeItem &newItem)
|
||||
void TestTreeModel::modifyTestSubtree(QModelIndex &toBeModifiedIndex, const TestTreeItem *newItem)
|
||||
{
|
||||
if (!toBeModifiedIndex.isValid())
|
||||
return;
|
||||
|
||||
TestTreeItem *toBeModifiedItem = static_cast<TestTreeItem *>(toBeModifiedIndex.internalPointer());
|
||||
if (toBeModifiedItem->modifyContent(&newItem))
|
||||
if (toBeModifiedItem->modifyContent(newItem))
|
||||
emit dataChanged(toBeModifiedIndex, toBeModifiedIndex,
|
||||
QVector<int>() << Qt::DisplayRole << Qt::ToolTipRole << LinkRole);
|
||||
|
||||
// process sub-items as well...
|
||||
const int childCount = toBeModifiedItem->childCount();
|
||||
const int newChildCount = newItem.childCount();
|
||||
const int newChildCount = newItem->childCount();
|
||||
|
||||
// for keeping the CheckState on modifications
|
||||
// TODO might still fail for duplicate entries
|
||||
@@ -800,7 +806,7 @@ void TestTreeModel::modifyTestSubtree(QModelIndex &toBeModifiedIndex, const Test
|
||||
processChildren(toBeModifiedIndex, newItem, childCount, checkStates);
|
||||
// add additional items
|
||||
for (int row = childCount; row < newChildCount; ++row) {
|
||||
TestTreeItem *newChild = newItem.child(row);
|
||||
TestTreeItem *newChild = newItem->child(row);
|
||||
TestTreeItem *toBeAdded = new TestTreeItem(*newChild);
|
||||
if (checkStates.contains(toBeAdded->name())
|
||||
&& checkStates.value(toBeAdded->name()) != Qt::Checked)
|
||||
@@ -817,7 +823,7 @@ void TestTreeModel::modifyTestSubtree(QModelIndex &toBeModifiedIndex, const Test
|
||||
emit testTreeModelChanged();
|
||||
}
|
||||
|
||||
void TestTreeModel::processChildren(QModelIndex &parentIndex, const TestTreeItem &newItem,
|
||||
void TestTreeModel::processChildren(QModelIndex &parentIndex, const TestTreeItem *newItem,
|
||||
const int upperBound,
|
||||
const QHash<QString, Qt::CheckState> &checkStates)
|
||||
{
|
||||
@@ -827,7 +833,7 @@ void TestTreeModel::processChildren(QModelIndex &parentIndex, const TestTreeItem
|
||||
for (int row = 0; row < upperBound; ++row) {
|
||||
QModelIndex child = parentIndex.child(row, 0);
|
||||
TestTreeItem *toBeModifiedChild = toBeModifiedItem->child(row);
|
||||
TestTreeItem *modifiedChild = newItem.child(row);
|
||||
TestTreeItem *modifiedChild = newItem->child(row);
|
||||
if (toBeModifiedChild->modifyContent(modifiedChild))
|
||||
emit dataChanged(child, child, modificationRoles);
|
||||
|
||||
|
@@ -91,11 +91,11 @@ signals:
|
||||
public slots:
|
||||
|
||||
private:
|
||||
void addTestTreeItem(const TestTreeItem &item, Type type);
|
||||
void addTestTreeItem(TestTreeItem *item, Type type);
|
||||
void addTestTreeItems(const QList<TestTreeItem> &itemList, Type type);
|
||||
void updateUnnamedQuickTest(const QString &fileName, const QString &mainFile,
|
||||
void updateUnnamedQuickTest(const QString &mainFile,
|
||||
const QMap<QString, TestCodeLocationAndType> &functions);
|
||||
void modifyTestTreeItem(TestTreeItem item, Type type, const QString &file);
|
||||
void modifyTestTreeItem(TestTreeItem *item, Type type, const QStringList &file);
|
||||
void removeAllTestItems();
|
||||
void removeTestTreeItems(const QString &filePath, Type type);
|
||||
void removeUnnamedQuickTests(const QString &filePath);
|
||||
@@ -105,8 +105,8 @@ private:
|
||||
QModelIndex rootIndexForType(Type type);
|
||||
|
||||
explicit TestTreeModel(QObject *parent = 0);
|
||||
void modifyTestSubtree(QModelIndex &toBeModifiedIndex, const TestTreeItem &newItem);
|
||||
void processChildren(QModelIndex &parentIndex, const TestTreeItem &newItem,
|
||||
void modifyTestSubtree(QModelIndex &toBeModifiedIndex, const TestTreeItem *newItem);
|
||||
void processChildren(QModelIndex &parentIndex, const TestTreeItem *newItem,
|
||||
const int upperBound, const QHash<QString, Qt::CheckState> &checkStates);
|
||||
|
||||
TestTreeItem *m_rootItem;
|
||||
|
Reference in New Issue
Block a user