TaskTreeRunner: Add setup and done handlers

They might be more convenient than runner's signals.

Change-Id: Ie50afd12f8db6a7f125b1b728a59297d85a48f34
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Jarek Kobus
2024-01-18 10:12:00 +01:00
parent 491b24de70
commit 61a8128512
2 changed files with 14 additions and 3 deletions

View File

@@ -9,13 +9,19 @@ namespace Tasking {
TaskTreeRunner::~TaskTreeRunner() = default; 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)); 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(); m_taskTree.release()->deleteLater();
if (doneHandler)
doneHandler(result);
emit done(result); emit done(result);
}); });
if (setupHandler)
setupHandler(m_taskTree.get());
emit aboutToStart(m_taskTree.get()); emit aboutToStart(m_taskTree.get());
m_taskTree->start(); m_taskTree->start();
} }

View File

@@ -15,12 +15,17 @@ class TASKING_EXPORT TaskTreeRunner : public QObject
Q_OBJECT Q_OBJECT
public: public:
using SetupHandler = std::function<void(TaskTree *)>;
using DoneHandler = std::function<void(DoneWith)>;
~TaskTreeRunner(); ~TaskTreeRunner();
bool isRunning() const { return bool(m_taskTree); } bool isRunning() const { return bool(m_taskTree); }
// When task tree is running it resets the old task tree. // 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. // TODO: rename to cancel(), also in TaskTree API, adapt docs.
// When task tree is running it emits done(DoneWith::Cancel) synchronously. // When task tree is running it emits done(DoneWith::Cancel) synchronously.