forked from qt-creator/qt-creator
Let TestTreeItem handle its parent
Part of preparing to re-use QC's TreeModel/TreeItem for TestTreeModel/TestTreeItem. Change-Id: Ieab26e9061790dd4c3d8dc64ce292727a17977f7 Reviewed-by: Niels Weber <niels.weber@theqtcompany.com> Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
This commit is contained in:
@@ -398,7 +398,7 @@ static TestTreeItem constructTestTreeItem(const QString &fileName,
|
|||||||
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 *treeItemChild = new TestTreeItem(functionName, locationAndType.m_name,
|
TestTreeItem *treeItemChild = new TestTreeItem(functionName, locationAndType.m_name,
|
||||||
locationAndType.m_type, &treeItem);
|
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
|
||||||
@@ -408,7 +408,7 @@ static TestTreeItem constructTestTreeItem(const QString &fileName,
|
|||||||
foreach (const TestCodeLocationAndType &tagLocation, tags) {
|
foreach (const TestCodeLocationAndType &tagLocation, tags) {
|
||||||
TestTreeItem *tagTreeItem = new TestTreeItem(tagLocation.m_name,
|
TestTreeItem *tagTreeItem = new TestTreeItem(tagLocation.m_name,
|
||||||
locationAndType.m_name,
|
locationAndType.m_name,
|
||||||
tagLocation.m_type, treeItemChild);
|
tagLocation.m_type);
|
||||||
tagTreeItem->setLine(tagLocation.m_line);
|
tagTreeItem->setLine(tagLocation.m_line);
|
||||||
tagTreeItem->setColumn(tagLocation.m_column);
|
tagTreeItem->setColumn(tagLocation.m_column);
|
||||||
treeItemChild->appendChild(tagTreeItem);
|
treeItemChild->appendChild(tagTreeItem);
|
||||||
|
@@ -19,15 +19,17 @@
|
|||||||
|
|
||||||
#include "testtreeitem.h"
|
#include "testtreeitem.h"
|
||||||
|
|
||||||
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
namespace Autotest {
|
namespace Autotest {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
TestTreeItem::TestTreeItem(const QString &name, const QString &filePath, Type type, TestTreeItem *parent)
|
TestTreeItem::TestTreeItem(const QString &name, const QString &filePath, Type type)
|
||||||
: m_name(name),
|
: m_name(name),
|
||||||
m_filePath(filePath),
|
m_filePath(filePath),
|
||||||
m_type(type),
|
m_type(type),
|
||||||
m_line(0),
|
m_line(0),
|
||||||
m_parent(parent)
|
m_parent(0)
|
||||||
{
|
{
|
||||||
switch (m_type) {
|
switch (m_type) {
|
||||||
case TEST_CLASS:
|
case TEST_CLASS:
|
||||||
@@ -52,13 +54,10 @@ 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_parent(other.m_parent)
|
m_parent(0)
|
||||||
{
|
{
|
||||||
foreach (const TestTreeItem *child, other.m_children) {
|
foreach (const TestTreeItem *child, other.m_children)
|
||||||
TestTreeItem *reparentedChild = new TestTreeItem(*child);
|
appendChild(new TestTreeItem(*child));
|
||||||
reparentedChild->m_parent = this;
|
|
||||||
m_children.append(reparentedChild);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TestTreeItem *TestTreeItem::child(int row) const
|
TestTreeItem *TestTreeItem::child(int row) const
|
||||||
@@ -73,6 +72,9 @@ TestTreeItem *TestTreeItem::parent() const
|
|||||||
|
|
||||||
void TestTreeItem::appendChild(TestTreeItem *child)
|
void TestTreeItem::appendChild(TestTreeItem *child)
|
||||||
{
|
{
|
||||||
|
QTC_ASSERT(child->m_parent == 0, return);
|
||||||
|
|
||||||
|
child->m_parent = this;
|
||||||
m_children.append(child);
|
m_children.append(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -41,7 +41,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
TestTreeItem(const QString &name = QString(), const QString &filePath = QString(),
|
TestTreeItem(const QString &name = QString(), const QString &filePath = QString(),
|
||||||
Type type = ROOT, TestTreeItem *parent = 0);
|
Type type = ROOT);
|
||||||
virtual ~TestTreeItem();
|
virtual ~TestTreeItem();
|
||||||
TestTreeItem(const TestTreeItem& other);
|
TestTreeItem(const TestTreeItem& other);
|
||||||
|
|
||||||
@@ -67,7 +67,6 @@ public:
|
|||||||
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; }
|
||||||
void setParent(TestTreeItem *parent) { m_parent = parent; }
|
|
||||||
QList<QString> getChildNames() const;
|
QList<QString> getChildNames() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@@ -41,8 +41,8 @@ namespace Internal {
|
|||||||
TestTreeModel::TestTreeModel(QObject *parent) :
|
TestTreeModel::TestTreeModel(QObject *parent) :
|
||||||
QAbstractItemModel(parent),
|
QAbstractItemModel(parent),
|
||||||
m_rootItem(new TestTreeItem(QString(), QString(), TestTreeItem::ROOT)),
|
m_rootItem(new TestTreeItem(QString(), QString(), TestTreeItem::ROOT)),
|
||||||
m_autoTestRootItem(new TestTreeItem(tr("Auto Tests"), QString(), TestTreeItem::ROOT, m_rootItem)),
|
m_autoTestRootItem(new TestTreeItem(tr("Auto Tests"), QString(), TestTreeItem::ROOT)),
|
||||||
m_quickTestRootItem(new TestTreeItem(tr("Qt Quick Tests"), QString(), TestTreeItem::ROOT, m_rootItem)),
|
m_quickTestRootItem(new TestTreeItem(tr("Qt Quick Tests"), QString(), TestTreeItem::ROOT)),
|
||||||
m_parser(new TestCodeParser(this)),
|
m_parser(new TestCodeParser(this)),
|
||||||
m_connectionsInitialized(false)
|
m_connectionsInitialized(false)
|
||||||
{
|
{
|
||||||
@@ -664,7 +664,6 @@ void TestTreeModel::addTestTreeItem(const TestTreeItem &item, TestTreeModel::Typ
|
|||||||
TestTreeItem *parent = rootItemForType(type);
|
TestTreeItem *parent = rootItemForType(type);
|
||||||
QModelIndex index = rootIndexForType(type);
|
QModelIndex index = rootIndexForType(type);
|
||||||
TestTreeItem *toBeAdded = new TestTreeItem(item);
|
TestTreeItem *toBeAdded = new TestTreeItem(item);
|
||||||
toBeAdded->setParent(parent);
|
|
||||||
|
|
||||||
beginInsertRows(index, parent->childCount(), parent->childCount());
|
beginInsertRows(index, parent->childCount(), parent->childCount());
|
||||||
parent->appendChild(toBeAdded);
|
parent->appendChild(toBeAdded);
|
||||||
@@ -680,7 +679,6 @@ void TestTreeModel::addTestTreeItems(const QList<TestTreeItem> &itemList, TestTr
|
|||||||
beginInsertRows(index, parent->childCount(), parent->childCount() + itemList.size() - 1);
|
beginInsertRows(index, parent->childCount(), parent->childCount() + itemList.size() - 1);
|
||||||
foreach (const TestTreeItem &item, itemList) {
|
foreach (const TestTreeItem &item, itemList) {
|
||||||
TestTreeItem *toBeAdded = new TestTreeItem(item);
|
TestTreeItem *toBeAdded = new TestTreeItem(item);
|
||||||
toBeAdded->setParent(parent);
|
|
||||||
parent->appendChild(toBeAdded);
|
parent->appendChild(toBeAdded);
|
||||||
}
|
}
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
@@ -693,12 +691,12 @@ void TestTreeModel::updateUnnamedQuickTest(const QString &fileName, const QStrin
|
|||||||
removeUnnamedQuickTests(fileName);
|
removeUnnamedQuickTests(fileName);
|
||||||
TestTreeItem unnamed = hasUnnamedQuickTests()
|
TestTreeItem unnamed = hasUnnamedQuickTests()
|
||||||
? TestTreeItem(*unnamedQuickTests())
|
? TestTreeItem(*unnamedQuickTests())
|
||||||
: TestTreeItem(QString(), QString(), TestTreeItem::TEST_CLASS, rootItemForType(QuickTest));
|
: TestTreeItem(QString(), QString(), TestTreeItem::TEST_CLASS);
|
||||||
|
|
||||||
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,
|
||||||
locationAndType.m_type, &unnamed);
|
locationAndType.m_type);
|
||||||
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);
|
||||||
@@ -714,7 +712,6 @@ void TestTreeModel::modifyTestTreeItem(TestTreeItem item, TestTreeModel::Type ty
|
|||||||
{
|
{
|
||||||
QModelIndex index = rootIndexForType(type);
|
QModelIndex index = rootIndexForType(type);
|
||||||
TestTreeItem *parent = rootItemForType(type);
|
TestTreeItem *parent = rootItemForType(type);
|
||||||
item.setParent(parent);
|
|
||||||
if (file.isEmpty()) {
|
if (file.isEmpty()) {
|
||||||
if (TestTreeItem *unnamed = unnamedQuickTests()) {
|
if (TestTreeItem *unnamed = unnamedQuickTests()) {
|
||||||
index = index.child(unnamed->row(), 0);
|
index = index.child(unnamed->row(), 0);
|
||||||
@@ -805,7 +802,6 @@ void TestTreeModel::modifyTestSubtree(QModelIndex &toBeModifiedIndex, const Test
|
|||||||
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);
|
||||||
toBeAdded->setParent(toBeModifiedItem);
|
|
||||||
if (checkStates.contains(toBeAdded->name())
|
if (checkStates.contains(toBeAdded->name())
|
||||||
&& checkStates.value(toBeAdded->name()) != Qt::Checked)
|
&& checkStates.value(toBeAdded->name()) != Qt::Checked)
|
||||||
toBeAdded->setChecked(checkStates.value(toBeAdded->name()));
|
toBeAdded->setChecked(checkStates.value(toBeAdded->name()));
|
||||||
|
Reference in New Issue
Block a user