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

@@ -82,7 +82,7 @@ ProcessProgress::ProcessProgress(QtcProcess *process)
, d(new ProcessProgressPrivate(this, process))
{
connect(&d->m_watcher, &QFutureWatcher<void>::canceled, this, [this] {
d->m_process->stop(); // TODO: should we have different cancel policies?
d->m_process->stop(); // TODO: See TaskProgress::setAutoStopOnCancel
});
connect(d->m_process, &QtcProcess::starting, this, [this] {
d->m_futureInterface = QFutureInterface<void>();

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;

View File

@@ -17,16 +17,22 @@ class TaskProgressPrivate;
class CORE_EXPORT TaskProgress : public QObject
{
Q_OBJECT
public:
TaskProgress(Utils::TaskTree *taskTree); // Makes TaskProgress a child of task tree
~TaskProgress() override;
void setAutoStopOnCancel(bool enable); // Default is true
void setHalfLifeTimePerTask(int msecs); // Default is 1000 ms
void setDisplayName(const QString &name);
void setKeepOnFinish(FutureProgress::KeepOnFinishType keepType);
void setSubtitleVisibleInStatusBar(bool visible);
void setSubtitle(const QString &subtitle);
signals:
void canceled();
private:
std::unique_ptr<TaskProgressPrivate> d;
};