TaskTree: Introduce List element

The List element of GroupItem type is a helper for
constructing Group content with an initializer lists.
Since there is no easy way of mixing items and lists of items
inside the initializer list, the List element encloses
the list of children in a single GroupItem element making it
possible to mix the lists of GroupItems with individual
GroupItem elements on a single initializer list.

This addresses the 25th point in the master task below.

Task-number: QTCREATORBUG-28741
Change-Id: I5fa4b76677f5aa7dcf875b9e9a16d86a26d380a7
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2023-11-03 23:07:26 +01:00
parent af63dcaf96
commit 1da7f18fb7
3 changed files with 32 additions and 22 deletions

View File

@@ -902,10 +902,17 @@ void TreeStorageBase::activateStorage(int id) const
void GroupItem::addChildren(const QList<GroupItem> &children)
{
QTC_ASSERT(m_type == Type::Group, qWarning("Only Group may have children, skipping...");
return);
QTC_ASSERT(m_type == Type::Group || m_type == Type::List,
qWarning("Only Group or List may have children, skipping..."); return);
if (m_type == Type::List) {
m_children.append(children);
return;
}
for (const GroupItem &child : children) {
switch (child.m_type) {
case Type::List:
addChildren(child.m_children);
break;
case Type::Group:
m_children.append(child);
break;

View File

@@ -188,6 +188,7 @@ public:
protected:
enum class Type {
List,
Group,
GroupData,
Storage,
@@ -195,6 +196,7 @@ protected:
};
GroupItem() = default;
GroupItem(Type type) : m_type(type) { }
GroupItem(const GroupData &data)
: m_type(Type::GroupData)
, m_groupData(data) {}
@@ -220,6 +222,14 @@ private:
TaskHandler m_taskHandler;
};
// TODO: Add tests.
class TASKING_EXPORT List final : public GroupItem
{
public:
List(const QList<GroupItem> &children) : GroupItem(Type::List) { addChildren(children); }
List(std::initializer_list<GroupItem> children) : GroupItem(Type::List) { addChildren(children); }
};
class TASKING_EXPORT Group final : public GroupItem
{
public:

View File

@@ -183,6 +183,15 @@ int main(int argc, char *argv[])
std::unique_ptr<TaskTree> taskTree;
const auto createGroup = [](GroupWidget *widget) {
return List {
widget->executeMode(),
widget->workflowPolicy(),
onGroupSetup([widget] { widget->setState(State::Running); }),
onGroupDone([widget](DoneWith result) { widget->setState(resultToState(result)); }),
};
};
const auto createTask = [](TaskWidget *widget) {
const milliseconds timeout{widget->busyTime() * 1000};
const auto setupTask = [widget, timeout](milliseconds &taskObject) {
@@ -199,17 +208,9 @@ int main(int argc, char *argv[])
const auto recipe = [&] {
const Group root {
rootGroup->executeMode(),
rootGroup->workflowPolicy(),
onGroupSetup([rootGroup] { rootGroup->setState(State::Running); }),
onGroupDone([rootGroup](DoneWith result) { rootGroup->setState(resultToState(result)); }),
createGroup(rootGroup),
Group {
groupTask_1->executeMode(),
groupTask_1->workflowPolicy(),
onGroupSetup([groupTask_1] { groupTask_1->setState(State::Running); }),
onGroupDone([groupTask_1](DoneWith result) { groupTask_1->setState(resultToState(result)); }),
createGroup(groupTask_1),
createTask(task_1_1),
createTask(task_1_2),
createTask(task_1_3)
@@ -217,19 +218,11 @@ int main(int argc, char *argv[])
createTask(task_2),
createTask(task_3),
Group {
groupTask_4->executeMode(),
groupTask_4->workflowPolicy(),
onGroupSetup([groupTask_4] { groupTask_4->setState(State::Running); }),
onGroupDone([groupTask_4](DoneWith result) { groupTask_4->setState(resultToState(result)); }),
createGroup(groupTask_4),
createTask(task_4_1),
createTask(task_4_2),
Group {
groupTask_4_3->executeMode(),
groupTask_4_3->workflowPolicy(),
onGroupSetup([groupTask_4_3] { groupTask_4_3->setState(State::Running); }),
onGroupDone([groupTask_4_3](DoneWith result) { groupTask_4_3->setState(resultToState(result)); }),
createGroup(groupTask_4_3),
createTask(task_4_3_1),
createTask(task_4_3_2),
createTask(task_4_3_3),