ACF $AcfVersion:0$
CCumulatedProgressManagerBase.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ACF-Commercial
2#pragma once
3
4
5// STL includes
6#include <vector>
7#include <map>
8
9// Qt includes
10#include <QtCore/QMutex>
11
12// ACF includes
14
15
16namespace ibase
17{
18
19
25{
26public:
27 enum class TaskStatus
28 {
32 Created,
33
37 Running,
38
43 };
44
45 struct TaskInfo
46 {
47 QByteArray id;
48 QString description;
49 };
50
52 {
54 double progress = 0.0;
55 };
56
60 CCumulatedProgressManagerBase(const TaskInfo& defaultTaskInfo = {"", ""});
62
66 void SetDefaultTaskInfo(const TaskInfo& defaultTaskInfo);
67
71 double GetCumulatedProgress() const;
77 std::vector<TaskProgressInfo> GetProcessedTasks(bool preferSorted = false, int maxCount = -1) const;
78
79 bool IsCancelable() const;
80 virtual bool IsCanceled() const;
81 void SetCanceled(bool state = true);
82
83 // reimplemented (ibase::IProgressManager)
84 virtual void ResetProgressManager() override;
85 std::unique_ptr<IProgressManager> CreateSubtaskManager(
86 const QByteArray& taskId,
87 const QString& taskDescription,
88 double weight = 1.0) override;
89 virtual std::unique_ptr<IProgressLogger> StartProgressLogger(bool isCancelable = false, const QString& description = {}) override;
90
91protected:
92 // Methods designed to be overriden
93 virtual void OnProgressChanged(double cumulatedValue);
94 virtual void OnTasksChanged();
95
96 class TaskBase: virtual public istd::IPolymorphic
97 {
98 public:
99 TaskBase(CCumulatedProgressManagerBase* parentPtr, const TaskInfo& taskInfo, double weight, bool isCancelable);
100 virtual ~TaskBase();
101
103
104 protected:
106 };
107 friend class SubTaskManager;
108
109 // low level communication with logger and manager
110 virtual void OpenTask(TaskBase* taskPtr, const TaskInfo& taskInfo, double weight, bool isCancelable);
111 virtual void CloseTask(TaskBase* taskPtr);
112 virtual void ReportTaskProgress(TaskBase* taskPtr, double progress, TaskStatus taskStatus);
113
115
116private:
117 struct ProgressInfo
118 {
120 double progress = 0;
121 double weight = 1;
122 bool isCancelable = false;
123 TaskInfo taskInfo;
124 };
125
126 class Logger: public TaskBase, public ibase::IProgressLogger
127 {
128 public:
129 Logger(CCumulatedProgressManagerBase* parentPtr, const TaskInfo& taskInfo, bool isCancelable);
130
131 // reimplemented (ibase::IProgressLogger)
132 virtual void OnProgress(double currentProgress) override;
133 virtual bool IsCanceled() const override;
134 };
135
136 TaskInfo m_defaultTaskInfo;
137
138 std::map<TaskBase*, ProgressInfo> m_openTasks;
139
140 double m_currentProgress;
141
142 double m_closedTaskSum;
143 double m_maxProgressSum;
144 bool m_isProgressLoggerStarted;
145
146 int m_cancelableCounter;
147 bool m_isCanceled;
148
149 mutable QMutex m_tasksMutex;
150};
151
152
153} // namespace ibase
154
155
TaskBase(CCumulatedProgressManagerBase *parentPtr, const TaskInfo &taskInfo, double weight, bool isCancelable)
Progress manager delegating cumulated progress result to another manager.
virtual void OpenTask(TaskBase *taskPtr, const TaskInfo &taskInfo, double weight, bool isCancelable)
CCumulatedProgressManagerBase(const TaskInfo &defaultTaskInfo={"", ""})
Create cumulated progress manager.
void SetCanceled(bool state=true)
virtual void OnProgressChanged(double cumulatedValue)
double GetCumulatedProgress() const
Get final progress beeing result of all task progress.
std::unique_ptr< IProgressManager > CreateSubtaskManager(const QByteArray &taskId, const QString &taskDescription, double weight=1.0) override
Create progress manager for the subtask.
virtual std::unique_ptr< IProgressLogger > StartProgressLogger(bool isCancelable=false, const QString &description={}) override
Create progress logger.
virtual void ResetProgressManager() override
Reset progress manager and make it possible to reuse it.
void SetDefaultTaskInfo(const TaskInfo &defaultTaskInfo)
Set information of the default task.
@ Created
Task was created, but not started.
virtual void CloseTask(TaskBase *taskPtr)
std::vector< TaskProgressInfo > GetProcessedTasks(bool preferSorted=false, int maxCount=-1) const
Get list of current processed tasks.
virtual void ReportTaskProgress(TaskBase *taskPtr, double progress, TaskStatus taskStatus)
Consume information about progress of some process.
Consume information about progress of some process.
Base interface for all used interfaces and implementations.
This namespace contains basic implementations of standard primitives on the component level.