diff options
author | Jarek Kobus <jaroslaw.kobus@qt.io> | 2022-11-10 16:57:17 +0100 |
---|---|---|
committer | Jarek Kobus <jaroslaw.kobus@qt.io> | 2022-11-18 15:52:10 +0000 |
commit | 5d4667e682a1d90da41a371e1ffb4a52c6bb890f (patch) | |
tree | 85e1113e0fcc31f0df6a0d423ce8c1e8e54f6d76 | |
parent | 4e4176a3d3003ca20a98c5d64ff486c6f8bf6f1a (diff) | |
download | qt-creator-5d4667e682a1d90da41a371e1ffb4a52c6bb890f.tar.gz |
Introduce TaskProgress
It's responsible for showing progress of the running task tree.
It's able to cancel the running task tree automatically after
pressing a small 'x' indicator on progress panel.
In this case TaskTree::stop() method is being called.
Change-Id: Ia1b3d88de74571e3e56f431b1a31755492ad4aa2
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
-rw-r--r-- | src/plugins/coreplugin/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/plugins/coreplugin/coreplugin.qbs | 1 | ||||
-rw-r--r-- | src/plugins/coreplugin/progressmanager/processprogress.cpp | 4 | ||||
-rw-r--r-- | src/plugins/coreplugin/progressmanager/taskprogress.cpp | 87 | ||||
-rw-r--r-- | src/plugins/coreplugin/progressmanager/taskprogress.h | 27 |
5 files changed, 118 insertions, 2 deletions
diff --git a/src/plugins/coreplugin/CMakeLists.txt b/src/plugins/coreplugin/CMakeLists.txt index 29542994ce..27ad0bfefd 100644 --- a/src/plugins/coreplugin/CMakeLists.txt +++ b/src/plugins/coreplugin/CMakeLists.txt @@ -144,6 +144,7 @@ add_qtc_plugin(Core progressmanager/progressbar.cpp progressmanager/progressbar.h progressmanager/progressmanager.cpp progressmanager/progressmanager.h progressmanager/progressmanager_p.h progressmanager/progressview.cpp progressmanager/progressview.h + progressmanager/taskprogress.cpp progressmanager/taskprogress.h rightpane.cpp rightpane.h settingsdatabase.cpp settingsdatabase.h sidebar.cpp sidebar.h diff --git a/src/plugins/coreplugin/coreplugin.qbs b/src/plugins/coreplugin/coreplugin.qbs index 7bd810e1c4..be30292174 100644 --- a/src/plugins/coreplugin/coreplugin.qbs +++ b/src/plugins/coreplugin/coreplugin.qbs @@ -243,6 +243,7 @@ Project { "progressbar.cpp", "progressbar.h", "progressmanager.cpp", "progressmanager.h", "progressmanager_p.h", "progressview.cpp", "progressview.h", + "taskprogress.cpp", "taskprogress.h", ] } diff --git a/src/plugins/coreplugin/progressmanager/processprogress.cpp b/src/plugins/coreplugin/progressmanager/processprogress.cpp index ae7d0be58c..4b5aa0322b 100644 --- a/src/plugins/coreplugin/progressmanager/processprogress.cpp +++ b/src/plugins/coreplugin/progressmanager/processprogress.cpp @@ -71,8 +71,8 @@ void ProcessProgressPrivate::parseProgress(const QString &inputText) \brief The ProcessProgress class is responsible for showing progress of the running process. - It's able to cancel the running process automatically after pressing a small 'x' indicator on - progress panel. In this case the QtcProcess::stop() method is being called. + It's possible to cancel the running process automatically after pressing a small 'x' + indicator on progress panel. In this case QtcProcess::stop() method is being called. */ ProcessProgress::ProcessProgress(QtcProcess *process) diff --git a/src/plugins/coreplugin/progressmanager/taskprogress.cpp b/src/plugins/coreplugin/progressmanager/taskprogress.cpp new file mode 100644 index 0000000000..28312055ab --- /dev/null +++ b/src/plugins/coreplugin/progressmanager/taskprogress.cpp @@ -0,0 +1,87 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0 + +#include "taskprogress.h" + +#include "progressmanager.h" + +#include <utils/qtcassert.h> +#include <utils/tasktree.h> + +#include <QFutureWatcher> + +using namespace Utils; + +namespace Core { + +class TaskProgressPrivate : public QObject +{ +public: + explicit TaskProgressPrivate(TaskProgress *progress, TaskTree *taskTree); + ~TaskProgressPrivate(); + + TaskTree *m_taskTree = nullptr; + QFutureWatcher<void> m_watcher; + QFutureInterface<void> m_futureInterface; + QString m_displayName; +}; + +TaskProgressPrivate::TaskProgressPrivate(TaskProgress *progress, TaskTree *taskTree) + : QObject(progress) + , m_taskTree(taskTree) +{ +} + +TaskProgressPrivate::~TaskProgressPrivate() +{ + if (m_futureInterface.isRunning()) { + m_futureInterface.reportCanceled(); + m_futureInterface.reportFinished(); + // TODO: should we stop the process? Or just mark the process canceled? + // What happens to task in progress manager? + } +} + +/*! + \class Core::TaskProgress + + \brief The TaskProgress class is responsible for showing progress of the running task tree. + + It's possible to cancel the running task tree automatically after pressing a small 'x' + indicator on progress panel. In this case TaskTree::stop() method is being called. +*/ + +TaskProgress::TaskProgress(TaskTree *taskTree) + : QObject(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? + }); + connect(d->m_taskTree, &TaskTree::started, this, [this] { + d->m_futureInterface = QFutureInterface<void>(); + d->m_futureInterface.setProgressRange(0, d->m_taskTree->progressMaximum()); + d->m_watcher.setFuture(d->m_futureInterface.future()); + d->m_futureInterface.reportStarted(); + + const auto id = Id::fromString(d->m_displayName + ".action"); + ProgressManager::addTask(d->m_futureInterface.future(), d->m_displayName, id); + }); + connect(d->m_taskTree, &TaskTree::progressValueChanged, this, [this](int value) { + d->m_futureInterface.setProgressValue(value); + }); + connect(d->m_taskTree, &TaskTree::done, this, [this] { + d->m_futureInterface.reportFinished(); + }); + connect(d->m_taskTree, &TaskTree::errorOccurred, this, [this] { + d->m_futureInterface.reportCanceled(); + d->m_futureInterface.reportFinished(); + }); +} + +void TaskProgress::setDisplayName(const QString &name) +{ + d->m_displayName = name; +} + +} // namespace Core diff --git a/src/plugins/coreplugin/progressmanager/taskprogress.h b/src/plugins/coreplugin/progressmanager/taskprogress.h new file mode 100644 index 0000000000..056ebf5014 --- /dev/null +++ b/src/plugins/coreplugin/progressmanager/taskprogress.h @@ -0,0 +1,27 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0 + +#pragma once + +#include <coreplugin/core_global.h> + +#include <QObject> + +namespace Utils { class TaskTree; } + +namespace Core { + +class TaskProgressPrivate; + +class CORE_EXPORT TaskProgress : public QObject +{ +public: + TaskProgress(Utils::TaskTree *taskTree); // Makes TaskProgress a child of task tree + + void setDisplayName(const QString &name); + +private: + TaskProgressPrivate *d; +}; + +} // namespace Core |