TaskProgress: Add setAutoStopOnCancel() property

By default it's true. When turned off task progress just
emits canceled() signal and leaves the further handling to the user.

Change-Id: Ice4456ac5ead5ca45712d1eb2c988302b273760c
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Jarek Kobus
2023-01-25 17:56:18 +01:00
parent 0d909c353c
commit ef065b8807
3 changed files with 16 additions and 2 deletions

View File

@@ -39,6 +39,7 @@ public:
QFutureWatcher<void> m_watcher;
QFutureInterface<void> m_futureInterface;
QPointer<FutureProgress> m_futureProgress;
bool m_isAutoStopOnCancel = true;
int m_halfLifeTimePerTask = 1000; // 1000 ms
QString m_displayName;
FutureProgress::KeepOnFinishType m_keep = FutureProgress::HideOnFinish;
@@ -99,7 +100,9 @@ TaskProgress::TaskProgress(TaskTree *taskTree)
, d(new TaskProgressPrivate(this, taskTree))
{
connect(&d->m_watcher, &QFutureWatcher<void>::canceled, this, [this] {
d->m_taskTree->stop(); // TODO: should we have different cancel policies?
emit canceled();
if (d->m_isAutoStopOnCancel)
d->m_taskTree->stop();
});
connect(d->m_taskTree, &TaskTree::started, this, [this] {
d->m_futureInterface = QFutureInterface<void>();
@@ -133,6 +136,11 @@ TaskProgress::TaskProgress(TaskTree *taskTree)
TaskProgress::~TaskProgress() = default;
void TaskProgress::setAutoStopOnCancel(bool enable)
{
d->m_isAutoStopOnCancel = enable;
}
void TaskProgress::setHalfLifeTimePerTask(int msecs)
{
d->m_halfLifeTimePerTask = msecs;