Commit ac659dd2 authored by Christian Stenger's avatar Christian Stenger

AutoTest: Create new tree items only if necessary...

...otherwise update existing. This reduces the number of items
that would get created or destroyed especially while modifying
code or just open/close test related documents.

Change-Id: Ia6a03ec33550c8c28e5120422e0f68fa428c1020
Reviewed-by: default avatarDavid Schulz <david.schulz@theqtcompany.com>
Reviewed-by: default avatarChristian Stenger <christian.stenger@theqtcompany.com>
parent 7138d903
......@@ -57,28 +57,6 @@ TestTreeItem::TestTreeItem(const QString &name, const QString &filePath, Type ty
}
}
TestTreeItem::~TestTreeItem()
{
removeChildren();
}
TestTreeItem::TestTreeItem(const TestTreeItem &other)
: 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_referencingFile(other.m_referencingFile),
m_state(other.m_state),
m_markedForRemoval(other.m_markedForRemoval)
{
for (int row = 0, count = other.childCount(); row < count; ++row)
appendChild(new TestTreeItem(*other.childItem(row)));
}
static QIcon testTreeIcon(TestTreeItem::Type type)
{
static QIcon icons[] = {
......@@ -169,39 +147,56 @@ bool TestTreeItem::setData(int /*column*/, const QVariant &data, int role)
return false;
}
bool TestTreeItem::modifyContent(const TestTreeItem *modified)
bool TestTreeItem::modifyTestCaseContent(const QString &name, unsigned line, unsigned column)
{
bool hasBeenModified = false;
if (m_filePath != modified->m_filePath) {
m_filePath = modified->m_filePath;
hasBeenModified = true;
}
if (m_name != modified->m_name) {
m_name = modified->m_name;
hasBeenModified = true;
}
if (m_line != modified->m_line) {
m_line = modified->m_line;
hasBeenModified = true;
}
if (m_mainFile != modified->m_mainFile) {
m_mainFile = modified->m_mainFile;
bool hasBeenModified = modifyName(name);
hasBeenModified |= modifyLineAndColumn(line, column);
return hasBeenModified;
}
bool TestTreeItem::modifyTestFunctionContent(const TestCodeLocationAndType &location)
{
bool hasBeenModified = modifyFilePath(location.m_name);
hasBeenModified |= modifyLineAndColumn(location.m_line, location.m_column);
return hasBeenModified;
}
bool TestTreeItem::modifyDataTagContent(const QString &fileName,
const TestCodeLocationAndType &location)
{
bool hasBeenModified = modifyFilePath(fileName);
hasBeenModified |= modifyName(location.m_name);
hasBeenModified |= modifyLineAndColumn(location.m_line, location.m_column);
return hasBeenModified;
}
bool TestTreeItem::modifyGTestSetContent(const QString &fileName, const QString &referencingFile,
const TestCodeLocationAndType &location)
{
bool hasBeenModified = modifyFilePath(fileName);
if (m_referencingFile != referencingFile) {
m_referencingFile = referencingFile;
hasBeenModified = true;
}
if (m_referencingFile != modified->m_referencingFile) {
m_referencingFile = modified->m_referencingFile;
hasBeenModified |= modifyLineAndColumn(location.m_line, location.m_column);
if (m_state != location.m_state) {
m_state = location.m_state;
hasBeenModified = true;
}
if (m_type != modified->m_type) {
m_type = modified->m_type;
return hasBeenModified;
}
bool TestTreeItem::modifyLineAndColumn(unsigned line, unsigned column)
{
bool hasBeenModified = false;
if (m_line != line) {
m_line = line;
hasBeenModified = true;
}
if (m_state != modified->m_state) {
m_state = modified->m_state;
if (m_column != column) {
m_column = column;
hasBeenModified = true;
}
if (m_markedForRemoval != modified->m_markedForRemoval)
m_markedForRemoval = modified->m_markedForRemoval;
return hasBeenModified;
}
......@@ -268,6 +263,38 @@ TestTreeItem *TestTreeItem::childItem(int row) const
return static_cast<TestTreeItem *>(child(row));
}
TestTreeItem *TestTreeItem::findChildByName(const QString &name)
{
return findChildBy([name](const TestTreeItem *other) -> bool {
return other->name() == name;
});
}
TestTreeItem *TestTreeItem::findChildByFiles(const QString &filePath,
const QString &referencingFile)
{
return findChildBy([filePath, referencingFile](const TestTreeItem *other) -> bool {
return other->filePath() == filePath && other->referencingFile() == referencingFile;
});
}
TestTreeItem *TestTreeItem::findChildByNameAndFile(const QString &name, const QString &filePath)
{
return findChildBy([name, filePath](const TestTreeItem *other) -> bool {
return other->filePath() == filePath && other->name() == name;
});
}
TestTreeItem *TestTreeItem::findChildByNameTypeAndFile(const QString &name, TestTreeItem::Type type,
const QString &referencingFile)
{
return findChildBy([name, type, referencingFile](const TestTreeItem *other) -> bool {
return other->referencingFile() == referencingFile
&& other->name() == name
&& other->type() == type;
});
}
void TestTreeItem::revalidateCheckState()
{
if (childCount() == 0)
......@@ -294,5 +321,33 @@ void TestTreeItem::revalidateCheckState()
m_checked = (foundUnchecked ? Qt::Unchecked : Qt::Checked);
}
inline bool TestTreeItem::modifyFilePath(const QString &filePath)
{
if (m_filePath != filePath) {
m_filePath = filePath;
return true;
}
return false;
}
inline bool TestTreeItem::modifyName(const QString &name)
{
if (m_name != name) {
m_name = name;
return true;
}
return false;
}
TestTreeItem *TestTreeItem::findChildBy(CompareFunction compare)
{
for (int row = 0, count = childCount(); row < count; ++row) {
TestTreeItem *child = childItem(row);
if (compare(child))
return child;
}
return 0;
}
} // namespace Internal
} // namespace Autotest
......@@ -44,6 +44,8 @@ namespace {
namespace Autotest {
namespace Internal {
struct TestCodeLocationAndType;
class TestTreeItem : public Utils::TreeItem
{
......@@ -72,15 +74,20 @@ public:
TestTreeItem(const QString &name = QString(), const QString &filePath = QString(),
Type type = Root);
virtual ~TestTreeItem();
TestTreeItem(const TestTreeItem& other);
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);
bool modifyTestCaseContent(const QString &name, unsigned line, unsigned column);
bool modifyTestFunctionContent(const TestCodeLocationAndType &location);
bool modifyDataTagContent(const QString &fileName, const TestCodeLocationAndType &location);
bool modifyGTestSetContent(const QString &fileName, const QString &referencingFile,
const TestCodeLocationAndType &location);
bool modifyLineAndColumn(unsigned line, unsigned column);
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; }
......@@ -100,8 +107,19 @@ public:
TestTreeItem *parentItem() const;
TestTreeItem *childItem(int row) const;
TestTreeItem *findChildByName(const QString &name);
TestTreeItem *findChildByFiles(const QString &filePath, const QString &referencingFile);
TestTreeItem *findChildByNameAndFile(const QString &name, const QString &filePath);
TestTreeItem *findChildByNameTypeAndFile(const QString &name,
TestTreeItem::Type type, const QString &referencingFile);
private:
void revalidateCheckState();
bool modifyFilePath(const QString &filePath);
bool modifyName(const QString &name);
typedef std::function<bool(const TestTreeItem *)> CompareFunction;
TestTreeItem *findChildBy(CompareFunction compare);
QString m_name;
QString m_filePath;
......
This diff is collapsed.
......@@ -89,21 +89,19 @@ signals:
public slots:
private:
void addTestTreeItem(TestTreeItem *item, Type type);
void onParseResultReady(TestParseResult result);
void handleParseResult(const TestParseResult &result);
void handleUnnamedQuickParseResult(const TestParseResult &result);
void handleGTestParseResult(const TestParseResult &result);
void removeAllTestItems();
void removeFiles(const QStringList &files);
void markForRemoval(const QString &filePath, Type type);
bool sweepChildren(TestTreeItem *item);
TestTreeItem *findTestTreeItemByContent(TestTreeItem *item, TestTreeItem *parent, Type type);
TestTreeItem *unnamedQuickTests() const;
TestTreeItem *rootItemForType(Type type);
explicit TestTreeModel(QObject *parent = 0);
void modifyTestSubtree(QModelIndex &toBeModifiedIndex, const TestTreeItem *newItem);
void processChildren(QModelIndex &parentIndex, const TestTreeItem *newItem,
const int upperBound, const QHash<QString, Qt::CheckState> &checkStates);
void setupParsingConnections();
TestTreeItem *m_autoTestRootItem;
......
Markdown is supported
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