From 61a812851257387f6b0cc3a61d31dfb132bfb186 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Thu, 18 Jan 2024 10:12:00 +0100 Subject: [PATCH] TaskTreeRunner: Add setup and done handlers They might be more convenient than runner's signals. Change-Id: Ie50afd12f8db6a7f125b1b728a59297d85a48f34 Reviewed-by: Eike Ziller --- src/libs/solutions/tasking/tasktreerunner.cpp | 10 ++++++++-- src/libs/solutions/tasking/tasktreerunner.h | 7 ++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/libs/solutions/tasking/tasktreerunner.cpp b/src/libs/solutions/tasking/tasktreerunner.cpp index abaa0777191..d4accf217dd 100644 --- a/src/libs/solutions/tasking/tasktreerunner.cpp +++ b/src/libs/solutions/tasking/tasktreerunner.cpp @@ -9,13 +9,19 @@ namespace Tasking { TaskTreeRunner::~TaskTreeRunner() = default; -void TaskTreeRunner::start(const Group &recipe) +void TaskTreeRunner::start(const Group &recipe, + const SetupHandler &setupHandler, + const DoneHandler &doneHandler) { m_taskTree.reset(new TaskTree(recipe)); - connect(m_taskTree.get(), &TaskTree::done, this, [this](DoneWith result) { + connect(m_taskTree.get(), &TaskTree::done, this, [this, doneHandler](DoneWith result) { m_taskTree.release()->deleteLater(); + if (doneHandler) + doneHandler(result); emit done(result); }); + if (setupHandler) + setupHandler(m_taskTree.get()); emit aboutToStart(m_taskTree.get()); m_taskTree->start(); } diff --git a/src/libs/solutions/tasking/tasktreerunner.h b/src/libs/solutions/tasking/tasktreerunner.h index 95f6ddde14e..a0c0bad7b37 100644 --- a/src/libs/solutions/tasking/tasktreerunner.h +++ b/src/libs/solutions/tasking/tasktreerunner.h @@ -15,12 +15,17 @@ class TASKING_EXPORT TaskTreeRunner : public QObject Q_OBJECT public: + using SetupHandler = std::function; + using DoneHandler = std::function; + ~TaskTreeRunner(); bool isRunning() const { return bool(m_taskTree); } // When task tree is running it resets the old task tree. - void start(const Group &recipe); + void start(const Group &recipe, + const SetupHandler &setupHandler = {}, + const DoneHandler &doneHandler = {}); // TODO: rename to cancel(), also in TaskTree API, adapt docs. // When task tree is running it emits done(DoneWith::Cancel) synchronously.