Commit 55f3dcb6 authored by Christian Stenger's avatar Christian Stenger
Browse files

Re-use QC's TreeItem/TreeModel for TestTreeItem/TestTreeModel



Change-Id: Ied35f808311392dcace1dca35796223369b37e0b
Reviewed-by: default avatarNiels Weber <niels.weber@theqtcompany.com>
parent 9a193f7a
......@@ -23,7 +23,6 @@
#include <utils/qtcassert.h>
#include <QIcon>
#include <QVariant>
#include <texteditor/texteditor.h>
......@@ -31,11 +30,11 @@ namespace Autotest {
namespace Internal {
TestTreeItem::TestTreeItem(const QString &name, const QString &filePath, Type type)
: m_name(name),
: TreeItem( { name } ),
m_name(name),
m_filePath(filePath),
m_type(type),
m_line(0),
m_parent(0)
m_line(0)
{
switch (m_type) {
case TEST_CLASS:
......@@ -53,35 +52,17 @@ TestTreeItem::~TestTreeItem()
}
TestTreeItem::TestTreeItem(const TestTreeItem &other)
: m_name(other.m_name),
: TreeItem( { other.m_name } ),
m_name(other.m_name),
m_filePath(other.m_filePath),
m_checked(other.m_checked),
m_type(other.m_type),
m_line(other.m_line),
m_column(other.m_column),
m_mainFile(other.m_mainFile),
m_parent(0)
m_mainFile(other.m_mainFile)
{
foreach (const TestTreeItem *child, other.m_children)
appendChild(new TestTreeItem(*child));
}
TestTreeItem *TestTreeItem::child(int row) const
{
return m_children.at(row);
}
TestTreeItem *TestTreeItem::parent() const
{
return m_parent;
}
void TestTreeItem::appendChild(TestTreeItem *child)
{
QTC_ASSERT(child->m_parent == 0, return);
child->m_parent = this;
m_children.append(child);
for (int row = 0, count = other.childCount(); row < count; ++row)
appendChild(new TestTreeItem(*childItem(row)));
}
static QIcon testTreeIcon(TestTreeItem::Type type)
......@@ -124,7 +105,7 @@ QVariant TestTreeItem::data(int /*column*/, int role) const
case TEST_CLASS:
return m_name.isEmpty() ? QVariant() : checked();
case TEST_FUNCTION:
if (m_parent && m_parent->name().isEmpty())
if (parentItem() && parentItem()->name().isEmpty())
return QVariant();
return checked();
default:
......@@ -143,7 +124,7 @@ QVariant TestTreeItem::data(int /*column*/, int role) const
case TEST_CLASS:
return m_name.isEmpty();
case TEST_FUNCTION:
return m_parent ? m_parent->name().isEmpty() : false;
return parentItem() ? parentItem()->name().isEmpty() : false;
default:
return false;
}
......@@ -163,34 +144,6 @@ bool TestTreeItem::setData(int /*column*/, const QVariant &data, int role)
return false;
}
int TestTreeItem::row() const
{
if (m_parent)
return m_parent->m_children.indexOf(const_cast<TestTreeItem *>(this));
return 0;
}
int TestTreeItem::childCount() const
{
return m_children.size();
}
void TestTreeItem::removeChildren()
{
qDeleteAll(m_children);
m_children.clear();
}
bool TestTreeItem::removeChild(int row)
{
if (row < 0 || row >= m_children.size())
return false;
TestTreeItem *child = m_children.at(row);
m_children.removeAt(row);
delete child;
return true;
}
bool TestTreeItem::modifyContent(const TestTreeItem *modified)
{
bool hasBeenModified = false;
......@@ -222,14 +175,13 @@ void TestTreeItem::setChecked(const Qt::CheckState checkState)
switch (m_type) {
case TEST_FUNCTION: {
m_checked = (checkState == Qt::Unchecked ? Qt::Unchecked : Qt::Checked);
m_parent->revalidateCheckState();
parentItem()->revalidateCheckState();
break;
}
case TEST_CLASS: {
Qt::CheckState usedState = (checkState == Qt::Unchecked ? Qt::Unchecked : Qt::Checked);
foreach (TestTreeItem *child, m_children) {
child->setChecked(usedState);
}
for (int row = 0, count = childCount(); row < count; ++row)
childItem(row)->setChecked(usedState);
m_checked = usedState;
}
default:
......@@ -247,8 +199,8 @@ Qt::CheckState TestTreeItem::checked() const
case TEST_SPECIALFUNCTION:
return Qt::Unchecked;
default:
if (m_parent)
return m_parent->m_checked;
if (parent())
return parentItem()->m_checked;
}
return Qt::Unchecked;
}
......@@ -256,18 +208,29 @@ Qt::CheckState TestTreeItem::checked() const
QList<QString> TestTreeItem::getChildNames() const
{
QList<QString> names;
foreach (TestTreeItem *item, m_children)
names << item->name();
for (int row = 0, count = childCount(); row < count; ++row)
names << childItem(row)->name();
return names;
}
TestTreeItem *TestTreeItem::parentItem() const
{
return static_cast<TestTreeItem *>(parent());
}
TestTreeItem *TestTreeItem::childItem(int row) const
{
return static_cast<TestTreeItem *>(child(row));
}
void TestTreeItem::revalidateCheckState()
{
if (m_children.size() == 0)
if (childCount() == 0)
return;
bool foundChecked = false;
bool foundUnchecked = false;
foreach (const TestTreeItem *child, m_children) {
for (int row = 0, count = childCount(); row < count; ++row) {
TestTreeItem *child = childItem(row);
switch (child->type()) {
case TEST_DATAFUNCTION:
case TEST_SPECIALFUNCTION:
......
......@@ -20,14 +20,12 @@
#ifndef TESTTREEITEM_H
#define TESTTREEITEM_H
#include <utils/treemodel.h>
#include <QList>
#include <QString>
#include <QMetaType>
QT_BEGIN_NAMESPACE
class QVariant;
QT_END_NAMESPACE
namespace {
enum ItemRole {
LinkRole = Qt::UserRole + 2, // can be removed if AnnotationRole comes back
......@@ -39,7 +37,7 @@ namespace {
namespace Autotest {
namespace Internal {
class TestTreeItem
class TestTreeItem : public Utils::TreeItem
{
public:
......@@ -57,21 +55,12 @@ public:
virtual ~TestTreeItem();
TestTreeItem(const TestTreeItem& other);
TestTreeItem *child(int row) const;
TestTreeItem *parent() const;
void appendChild(TestTreeItem *child);
QVariant data(int column, int role) const;
bool setData(int column, const QVariant &data, int role);
int row() const;
int childCount() const;
void removeChildren();
bool removeChild(int row);
virtual QVariant data(int column, int role) const override;
virtual bool setData(int column, const QVariant &data, int role) override;
bool modifyContent(const TestTreeItem *modified);
const QString name() const { return m_name; }
void setName(const QString &name) { m_name = name; }
const QString filePath() const { return m_filePath; }
void setFilePath(const QString &filePath) { m_filePath = filePath; }
void setLine(unsigned line) { m_line = line;}
unsigned line() const { return m_line; }
void setColumn(unsigned column) { m_column = column; }
......@@ -82,6 +71,8 @@ public:
Qt::CheckState checked() const;
Type type() const { return m_type; }
QList<QString> getChildNames() const;
TestTreeItem *parentItem() const;
TestTreeItem *childItem(int row) const;
private:
void revalidateCheckState();
......@@ -93,8 +84,6 @@ private:
unsigned m_line;
unsigned m_column;
QString m_mainFile;
TestTreeItem *m_parent;
QList<TestTreeItem *> m_children;
};
struct TestCodeLocationAndType {
......
This diff is collapsed.
......@@ -24,7 +24,8 @@
#include <cplusplus/CppDocument.h>
#include <QAbstractItemModel>
#include <utils/treemodel.h>
#include <QSortFilterProxyModel>
namespace Autotest {
......@@ -35,7 +36,7 @@ class TestCodeParser;
class TestInfo;
class TestTreeItem;
class TestTreeModel : public QAbstractItemModel
class TestTreeModel : public Utils::TreeModel
{
Q_OBJECT
public:
......@@ -49,15 +50,8 @@ public:
void enableParsing();
void disableParsing();
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
QModelIndex parent(const QModelIndex &index) const;
bool hasChildren(const QModelIndex &parent) const;
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
bool setData(const QModelIndex &index, const QVariant &value, int role);
Qt::ItemFlags flags(const QModelIndex &index) const;
bool removeRows(int row, int count, const QModelIndex &parent);
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
TestCodeParser *parser() const { return m_parser; }
bool hasTests() const;
......@@ -98,7 +92,6 @@ private:
void processChildren(QModelIndex &parentIndex, const TestTreeItem *newItem,
const int upperBound, const QHash<QString, Qt::CheckState> &checkStates);
TestTreeItem *m_rootItem;
TestTreeItem *m_autoTestRootItem;
TestTreeItem *m_quickTestRootItem;
TestCodeParser *m_parser;
......
Supports Markdown
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