diff options
author | Jarek Kobus <jaroslaw.kobus@qt.io> | 2022-11-16 09:06:32 +0100 |
---|---|---|
committer | Jarek Kobus <jaroslaw.kobus@qt.io> | 2022-11-18 15:31:03 +0000 |
commit | 4e4176a3d3003ca20a98c5d64ff486c6f8bf6f1a (patch) | |
tree | 6190cd7d34a74d9ac24ee777c6b021e7bbeadebf | |
parent | d21acbd413c486cbba11bdb906d1e1b0b0cce416 (diff) | |
download | qt-creator-4e4176a3d3003ca20a98c5d64ff486c6f8bf6f1a.tar.gz |
TaskTree: Add task tree adapter for task tree
Now it's possible to nest TaskTrees. A nested TaskTree
is seen as one, singular task inside parent tree.
Change-Id: Iad95de39c7b79580e0b589c222594de91d5b51a1
Reviewed-by: hjk <hjk@qt.io>
-rw-r--r-- | src/libs/utils/tasktree.cpp | 11 | ||||
-rw-r--r-- | src/libs/utils/tasktree.h | 8 | ||||
-rw-r--r-- | tests/auto/utils/tasktree/tst_tasktree.cpp | 17 |
3 files changed, 36 insertions, 0 deletions
diff --git a/src/libs/utils/tasktree.cpp b/src/libs/utils/tasktree.cpp index a11630926b..fcf47d5065 100644 --- a/src/libs/utils/tasktree.cpp +++ b/src/libs/utils/tasktree.cpp @@ -535,4 +535,15 @@ int TaskTree::progressValue() const return d->m_progressValue; } +TaskTreeAdapter::TaskTreeAdapter() +{ + connect(task(), &TaskTree::done, this, [this] { emit done(true); }); + connect(task(), &TaskTree::errorOccurred, this, [this] { emit done(false); }); +} + +void TaskTreeAdapter::start() +{ + task()->start(); +} + } // namespace Utils diff --git a/src/libs/utils/tasktree.h b/src/libs/utils/tasktree.h index be7074893e..16c81766ee 100644 --- a/src/libs/utils/tasktree.h +++ b/src/libs/utils/tasktree.h @@ -255,6 +255,13 @@ private: TaskTreePrivate *d; }; +class QTCREATOR_UTILS_EXPORT TaskTreeAdapter : public Tasking::TaskAdapter<TaskTree> +{ +public: + TaskTreeAdapter(); + void start() final; +}; + } // namespace Utils #define QTC_DECLARE_CUSTOM_TASK(CustomTaskName, TaskAdapterClass)\ @@ -266,3 +273,4 @@ template <typename ...Args>\ using CustomTaskName = CustomTask<TaskAdapterClass<Args...>>;\ } // namespace Utils::Tasking +QTC_DECLARE_CUSTOM_TASK(Tree, Utils::TaskTreeAdapter); diff --git a/tests/auto/utils/tasktree/tst_tasktree.cpp b/tests/auto/utils/tasktree/tst_tasktree.cpp index f25eb3c7ec..29202fa0b1 100644 --- a/tests/auto/utils/tasktree/tst_tasktree.cpp +++ b/tests/auto/utils/tasktree/tst_tasktree.cpp @@ -246,6 +246,20 @@ void tst_TaskTree::processTree_data() }, OnGroupDone(rootDone) }; + auto setupSubTree = [=](TaskTree &taskTree) { + const Group nestedRoot { + Process(std::bind(setupProcess, _1, 2), readResult), + Process(std::bind(setupProcess, _1, 3), readResult), + Process(std::bind(setupProcess, _1, 4), readResult), + }; + taskTree.setupRoot(nestedRoot); + }; + const Group sequentialSubTreeRoot { + Process(std::bind(setupProcess, _1, 1), readResult), + Tree(setupSubTree), + Process(std::bind(setupProcess, _1, 5), readResult), + OnGroupDone(rootDone) + }; const Log sequentialLog{{1, Handler::Setup}, {1, Handler::Done}, {2, Handler::Setup}, @@ -260,6 +274,8 @@ void tst_TaskTree::processTree_data() QTest::newRow("Sequential") << sequentialRoot << sequentialLog << true << true << 5; QTest::newRow("SequentialEncapsulated") << sequentialEncapsulatedRoot << sequentialLog << true << true << 5; + QTest::newRow("SequentialSubTree") << sequentialSubTreeRoot << sequentialLog + << true << true << 3; // We don't inspect subtrees const Group sequentialNestedRoot { Group { @@ -439,6 +455,7 @@ void tst_TaskTree::processTree_data() {-1, Handler::GroupDone}}; QTest::newRow("DynamicSetupSelected") << dynamicSetupSelRoot << dynamicSetupSelLog << true << true << 4; + } void tst_TaskTree::processTree() |