AutoTest: Provide possibility to copy tree items

This allows to create a copy of an item. Basically it will
copy its member objects, but it does not copy its children.
Preparation for extending grouping support for GTest.

Change-Id: I75f92be53ff4191cacea2944b31641a9292d1e58
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Stenger
2018-03-06 10:38:36 +01:00
parent d6bb6c5018
commit 2945865516
8 changed files with 42 additions and 0 deletions

View File

@@ -47,6 +47,14 @@ static QString gtestFilter(GTestTreeItem::TestStates states)
return QString("%1.%2");
}
TestTreeItem *GTestTreeItem::copyWithoutChildren()
{
GTestTreeItem *copied = new GTestTreeItem;
copied->copyBasicDataFrom(this);
copied->m_state = m_state;
return copied;
}
QVariant GTestTreeItem::data(int column, int role) const
{
switch (role) {

View File

@@ -49,6 +49,7 @@ public:
explicit GTestTreeItem(const QString &name = QString(), const QString &filePath = QString(),
Type type = Root) : TestTreeItem(name, filePath, type), m_state(Enabled) {}
TestTreeItem *copyWithoutChildren() override;
QVariant data(int column, int role) const override;
bool canProvideTestConfiguration() const override { return type() != Root; }
bool canProvideDebugConfiguration() const override { return type() != Root; }

View File

@@ -41,6 +41,14 @@ QtTestTreeItem::QtTestTreeItem(const QString &name, const QString &filePath, Tes
setData(0, Qt::Checked, Qt::CheckStateRole);
}
TestTreeItem *QtTestTreeItem::copyWithoutChildren()
{
QtTestTreeItem *copied = new QtTestTreeItem;
copied->copyBasicDataFrom(this);
copied->m_inherited = m_inherited;
return copied;
}
QVariant QtTestTreeItem::data(int column, int role) const
{
switch (role) {

View File

@@ -36,6 +36,7 @@ public:
explicit QtTestTreeItem(const QString &name = QString(), const QString &filePath = QString(),
Type type = Root);
TestTreeItem *copyWithoutChildren() override;
QVariant data(int column, int role) const override;
Qt::ItemFlags flags(int column) const override;
bool canProvideTestConfiguration() const override;

View File

@@ -35,6 +35,13 @@
namespace Autotest {
namespace Internal {
TestTreeItem *QuickTestTreeItem::copyWithoutChildren()
{
QuickTestTreeItem *copied = new QuickTestTreeItem;
copied->copyBasicDataFrom(this);
return copied;
}
QVariant QuickTestTreeItem::data(int column, int role) const
{
switch (role) {

View File

@@ -36,6 +36,7 @@ public:
explicit QuickTestTreeItem(const QString &name = QString(), const QString &filePath = QString(),
Type type = Root) : TestTreeItem(name, filePath, type) {}
TestTreeItem *copyWithoutChildren() override;
QVariant data(int column, int role) const override;
Qt::ItemFlags flags(int column) const override;
bool canProvideTestConfiguration() const override;

View File

@@ -314,6 +314,20 @@ QSet<QString> TestTreeItem::internalTargets() const
return targets;
}
void TestTreeItem::copyBasicDataFrom(const TestTreeItem *other)
{
if (!other)
return;
m_name = other->m_name;
m_filePath = other->m_filePath;
m_type = other->m_type;
m_checked = other->m_checked;
m_line = other->m_line;
m_column = other->m_column;
m_proFile = other->m_proFile;
m_status = other->m_status;
}
inline bool TestTreeItem::modifyFilePath(const QString &filePath)
{
if (m_filePath != filePath) {

View File

@@ -72,6 +72,7 @@ public:
explicit TestTreeItem(const QString &name = QString(), const QString &filePath = QString(),
Type type = Root);
virtual TestTreeItem *copyWithoutChildren() = 0;
virtual QVariant data(int column, int role) const override;
virtual bool setData(int column, const QVariant &data, int role) override;
virtual Qt::ItemFlags flags(int column) const override;
@@ -119,6 +120,7 @@ public:
virtual TestTreeItem *createParentGroupNode() const = 0;
virtual QSet<QString> internalTargets() const;
protected:
void copyBasicDataFrom(const TestTreeItem *other);
typedef std::function<bool(const TestTreeItem *)> CompareFunction;
TestTreeItem *findChildBy(CompareFunction compare) const;
static QSet<QString> dependingInternalTargets(CppTools::CppModelManager *cppMM,