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