forked from qt-creator/qt-creator
AutoTest: Make test tree root items checkable
This allows (de)selecting of all test cases of a specific test framework. Change-Id: I21357d3dbcfce73387f157b1b40686f437fa260b Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -57,6 +57,7 @@ QVariant GTestTreeItem::data(int column, int role) const
|
|||||||
}
|
}
|
||||||
case Qt::CheckStateRole:
|
case Qt::CheckStateRole:
|
||||||
switch (type()) {
|
switch (type()) {
|
||||||
|
case Root:
|
||||||
case TestCase:
|
case TestCase:
|
||||||
case TestFunctionOrSet:
|
case TestFunctionOrSet:
|
||||||
return checked();
|
return checked();
|
||||||
|
|||||||
@@ -49,7 +49,6 @@ QVariant QtTestTreeItem::data(int column, int role) const
|
|||||||
return QVariant(name() + nameSuffix());
|
return QVariant(name() + nameSuffix());
|
||||||
case Qt::CheckStateRole:
|
case Qt::CheckStateRole:
|
||||||
switch (type()) {
|
switch (type()) {
|
||||||
case Root:
|
|
||||||
case TestDataFunction:
|
case TestDataFunction:
|
||||||
case TestSpecialFunction:
|
case TestSpecialFunction:
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|||||||
@@ -50,7 +50,6 @@ QVariant QuickTestTreeItem::data(int column, int role) const
|
|||||||
break;
|
break;
|
||||||
case Qt::CheckStateRole:
|
case Qt::CheckStateRole:
|
||||||
switch (type()) {
|
switch (type()) {
|
||||||
case Root:
|
|
||||||
case TestDataFunction:
|
case TestDataFunction:
|
||||||
case TestSpecialFunction:
|
case TestSpecialFunction:
|
||||||
case TestDataTag:
|
case TestDataTag:
|
||||||
|
|||||||
@@ -42,7 +42,8 @@ TestTreeItem::TestTreeItem(const QString &name, const QString &filePath, Type ty
|
|||||||
m_filePath(filePath),
|
m_filePath(filePath),
|
||||||
m_type(type)
|
m_type(type)
|
||||||
{
|
{
|
||||||
m_checked = (m_type == TestCase || m_type == TestFunctionOrSet) ? Qt::Checked : Qt::Unchecked;
|
m_checked = (m_type == TestCase || m_type == TestFunctionOrSet || m_type == Root)
|
||||||
|
? Qt::Checked : Qt::Unchecked;
|
||||||
}
|
}
|
||||||
|
|
||||||
static QIcon testTreeIcon(TestTreeItem::Type type)
|
static QIcon testTreeIcon(TestTreeItem::Type type)
|
||||||
@@ -103,7 +104,7 @@ Qt::ItemFlags TestTreeItem::flags(int /*column*/) const
|
|||||||
static const Qt::ItemFlags defaultFlags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
static const Qt::ItemFlags defaultFlags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||||
switch (m_type) {
|
switch (m_type) {
|
||||||
case Root:
|
case Root:
|
||||||
return Qt::ItemIsEnabled;
|
return Qt::ItemIsEnabled | Qt::ItemIsAutoTristate | Qt::ItemIsUserCheckable;
|
||||||
case TestCase:
|
case TestCase:
|
||||||
return defaultFlags | Qt::ItemIsAutoTristate | Qt::ItemIsUserCheckable;
|
return defaultFlags | Qt::ItemIsAutoTristate | Qt::ItemIsUserCheckable;
|
||||||
case TestFunctionOrSet:
|
case TestFunctionOrSet:
|
||||||
@@ -161,13 +162,14 @@ void TestTreeItem::setChecked(const Qt::CheckState checkState)
|
|||||||
parent->revalidateCheckState();
|
parent->revalidateCheckState();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case Root:
|
||||||
case TestFunctionOrSet:
|
case TestFunctionOrSet:
|
||||||
case TestCase: {
|
case TestCase: {
|
||||||
Qt::CheckState usedState = (checkState == Qt::Unchecked ? Qt::Unchecked : Qt::Checked);
|
Qt::CheckState usedState = (checkState == Qt::Unchecked ? Qt::Unchecked : Qt::Checked);
|
||||||
for (int row = 0, count = childCount(); row < count; ++row)
|
for (int row = 0, count = childCount(); row < count; ++row)
|
||||||
childItem(row)->setChecked(usedState);
|
childItem(row)->setChecked(usedState);
|
||||||
m_checked = usedState;
|
m_checked = usedState;
|
||||||
if (m_type == TestFunctionOrSet) {
|
if (m_type != Root) {
|
||||||
if (auto parent = parentItem())
|
if (auto parent = parentItem())
|
||||||
parent->revalidateCheckState();
|
parent->revalidateCheckState();
|
||||||
}
|
}
|
||||||
@@ -181,6 +183,7 @@ void TestTreeItem::setChecked(const Qt::CheckState checkState)
|
|||||||
Qt::CheckState TestTreeItem::checked() const
|
Qt::CheckState TestTreeItem::checked() const
|
||||||
{
|
{
|
||||||
switch (m_type) {
|
switch (m_type) {
|
||||||
|
case Root:
|
||||||
case TestCase:
|
case TestCase:
|
||||||
case TestFunctionOrSet:
|
case TestFunctionOrSet:
|
||||||
case TestDataTag:
|
case TestDataTag:
|
||||||
@@ -295,7 +298,7 @@ QSet<QString> TestTreeItem::internalTargets() const
|
|||||||
void TestTreeItem::revalidateCheckState()
|
void TestTreeItem::revalidateCheckState()
|
||||||
{
|
{
|
||||||
const Type ttiType = type();
|
const Type ttiType = type();
|
||||||
if (ttiType != TestCase && ttiType != TestFunctionOrSet)
|
if (ttiType != TestCase && ttiType != TestFunctionOrSet && ttiType != Root)
|
||||||
return;
|
return;
|
||||||
if (childCount() == 0) // can this happen? (we're calling revalidateCS() on parentItem()
|
if (childCount() == 0) // can this happen? (we're calling revalidateCS() on parentItem()
|
||||||
return;
|
return;
|
||||||
@@ -317,13 +320,13 @@ void TestTreeItem::revalidateCheckState()
|
|||||||
foundPartiallyChecked |= (child->checked() == Qt::PartiallyChecked);
|
foundPartiallyChecked |= (child->checked() == Qt::PartiallyChecked);
|
||||||
if (foundPartiallyChecked || (foundChecked && foundUnchecked)) {
|
if (foundPartiallyChecked || (foundChecked && foundUnchecked)) {
|
||||||
m_checked = Qt::PartiallyChecked;
|
m_checked = Qt::PartiallyChecked;
|
||||||
if (ttiType == TestFunctionOrSet)
|
if (ttiType == TestFunctionOrSet || ttiType == TestCase)
|
||||||
parentItem()->revalidateCheckState();
|
parentItem()->revalidateCheckState();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_checked = (foundUnchecked ? Qt::Unchecked : Qt::Checked);
|
m_checked = (foundUnchecked ? Qt::Unchecked : Qt::Checked);
|
||||||
if (ttiType == TestFunctionOrSet)
|
if (ttiType == TestFunctionOrSet || ttiType == TestCase)
|
||||||
parentItem()->revalidateCheckState();
|
parentItem()->revalidateCheckState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -135,6 +135,8 @@ private:
|
|||||||
unsigned m_column = 0;
|
unsigned m_column = 0;
|
||||||
QString m_proFile;
|
QString m_proFile;
|
||||||
Status m_status = NewlyAdded;
|
Status m_status = NewlyAdded;
|
||||||
|
|
||||||
|
friend class TestTreeModel; // grant access to (private) revalidateCheckState()
|
||||||
};
|
};
|
||||||
|
|
||||||
class TestCodeLocationAndType
|
class TestCodeLocationAndType
|
||||||
|
|||||||
@@ -110,6 +110,7 @@ bool TestTreeModel::setData(const QModelIndex &index, const QVariant &value, int
|
|||||||
emit dataChanged(index, index);
|
emit dataChanged(index, index);
|
||||||
if (role == Qt::CheckStateRole) {
|
if (role == Qt::CheckStateRole) {
|
||||||
switch (item->type()) {
|
switch (item->type()) {
|
||||||
|
case TestTreeItem::Root:
|
||||||
case TestTreeItem::TestCase:
|
case TestTreeItem::TestCase:
|
||||||
if (item->childCount() > 0)
|
if (item->childCount() > 0)
|
||||||
emit dataChanged(index.child(0, 0), index.child(item->childCount() - 1, 0));
|
emit dataChanged(index.child(0, 0), index.child(item->childCount() - 1, 0));
|
||||||
@@ -228,6 +229,7 @@ bool TestTreeModel::sweepChildren(TestTreeItem *item)
|
|||||||
|
|
||||||
if (child->type() != TestTreeItem::Root && child->markedForRemoval()) {
|
if (child->type() != TestTreeItem::Root && child->markedForRemoval()) {
|
||||||
destroyItem(child);
|
destroyItem(child);
|
||||||
|
item->revalidateCheckState();
|
||||||
hasChanged = true;
|
hasChanged = true;
|
||||||
} else if (child->hasChildren()) {
|
} else if (child->hasChildren()) {
|
||||||
hasChanged |= sweepChildren(child);
|
hasChanged |= sweepChildren(child);
|
||||||
@@ -266,6 +268,12 @@ void TestTreeModel::handleParseResult(const TestParseResult *result, TestTreeIte
|
|||||||
TestTreeItem *newItem = result->createTestTreeItem();
|
TestTreeItem *newItem = result->createTestTreeItem();
|
||||||
QTC_ASSERT(newItem, return);
|
QTC_ASSERT(newItem, return);
|
||||||
parentNode->appendChild(newItem);
|
parentNode->appendChild(newItem);
|
||||||
|
// new items are checked by default - revalidation of parents might be necessary
|
||||||
|
if (parentNode->checked() != Qt::Checked) {
|
||||||
|
parentNode->revalidateCheckState();
|
||||||
|
const QModelIndex &idx = indexForItem(parentNode);
|
||||||
|
emit dataChanged(idx, idx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestTreeModel::removeAllTestItems()
|
void TestTreeModel::removeAllTestItems()
|
||||||
|
|||||||
@@ -82,6 +82,10 @@ void TestTreeView::changeCheckStateAll(const Qt::CheckState checkState)
|
|||||||
item->setChecked(checkState);
|
item->setChecked(checkState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (count == 0) {
|
||||||
|
if (auto item = static_cast<TestTreeItem *>(currentRootIndex.internalPointer()))
|
||||||
|
item->setChecked(checkState);
|
||||||
|
}
|
||||||
emit dataChanged(currentRootIndex, last);
|
emit dataChanged(currentRootIndex, last);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user