1 | // Copyright (C) 2024 Jarek Kobus |
2 | // Copyright (C) 2024 The Qt Company Ltd. |
3 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
4 | |
5 | #ifndef TASKING_TASKTREERUNNER_H |
6 | #define TASKING_TASKTREERUNNER_H |
7 | |
8 | // |
9 | // W A R N I N G |
10 | // ------------- |
11 | // |
12 | // This file is not part of the Qt API. It exists purely as an |
13 | // implementation detail. This header file may change from version to |
14 | // version without notice, or even be removed. |
15 | // |
16 | // We mean it. |
17 | // |
18 | |
19 | #include "tasking_global.h" |
20 | #include "tasktree.h" |
21 | |
22 | #include <QtCore/QObject> |
23 | |
24 | QT_BEGIN_NAMESPACE |
25 | |
26 | namespace Tasking { |
27 | |
28 | class TASKING_EXPORT TaskTreeRunner : public QObject |
29 | { |
30 | Q_OBJECT |
31 | |
32 | public: |
33 | using SetupHandler = std::function<void(TaskTree *)>; |
34 | using DoneHandler = std::function<void(DoneWith)>; |
35 | |
36 | ~TaskTreeRunner(); |
37 | |
38 | bool isRunning() const { return bool(m_taskTree); } |
39 | |
40 | // When task tree is running it resets the old task tree. |
41 | void start(const Group &recipe, |
42 | const SetupHandler &setupHandler = {}, |
43 | const DoneHandler &doneHandler = {}); |
44 | |
45 | // When task tree is running it emits done(DoneWith::Cancel) synchronously. |
46 | void cancel(); |
47 | |
48 | // No done() signal is emitted. |
49 | void reset(); |
50 | |
51 | Q_SIGNALS: |
52 | void aboutToStart(TaskTree *taskTree); |
53 | void done(DoneWith result); |
54 | |
55 | private: |
56 | std::unique_ptr<TaskTree> m_taskTree; |
57 | }; |
58 | |
59 | } // namespace Tasking |
60 | |
61 | QT_END_NAMESPACE |
62 | |
63 | #endif // TASKING_TASKTREERUNNER_H |
64 | |