13#include <QMutexLocker>
29 , parentProgressProxy(proxy)
30 , parentUpdater(parentUpdater)
45 int currentProgress = 0;
46 bool isUndefinedState =
false;
50 int updateInterval = 250;
51 bool autoNestNames =
false;
54 bool isStarted =
false;
62 return parentUpdater ? parentUpdater : parentProgressProxy;
71 : d (new
Private(this, progressProxy, 0, mode))
80 : d (new
Private(this, 0, updater, Unthreaded))
90 if (
d->progressProxy()) {
91 d->progressProxy()->setRange(0,
d->taskMax);
92 d->progressProxy()->setValue(
d->progressProxy()->maximum());
97 d->updateCompressor->stop();
99 qDeleteAll(
d->subtasks);
108 QMutexLocker l(&
d->mutex);
111 d->taskMax = range - 1;
113 d->currentProgress = 0;
131 QMutexLocker l(&
d->mutex);
132 d->subtasks.append(
p);
146 QMutexLocker l(&
d->mutex);
148 for (
auto it =
d->subtasks.begin(); it !=
d->subtasks.end();) {
149 if ((*it)->connectedUpdater() != updater) {
153 (*it)->deleteLater();
154 it =
d->subtasks.erase(it);
170 QMutexLocker l(&
d->mutex);
175 if (!updater)
continue;
177 updater->setProgress(100);
178 updater->setInterrupted(
true);
190 qApp->processEvents();
193 d->updateCompressor->start();
208 QMutexLocker l(&
d->mutex);
210 if (!
d->subtasks.isEmpty()) {
211 int totalProgress = 0;
213 d->isUndefinedState =
false;
216 if (updater->interrupted()) {
217 d->currentProgress = -1;
221 if (!updater->hasValidRange()) {
224 d->isUndefinedState =
true;
228 if (updater->isPersistent() && updater->isCompleted()) {
232 const int progress = qBound(0, updater->progress(), 100);
233 totalProgress += progress * updater->weight();
234 totalWeight += updater->weight();
237 const int progressPercent = totalWeight > 0 ? totalProgress / totalWeight : -1;
242 qRound(qreal(progressPercent) *
d->taskMax / 99.0);
247 if (
d->progressProxy()) {
248 if (!
d->isUndefinedState) {
249 d->progressProxy()->setRange(0,
d->taskMax);
251 if (
d->currentProgress == -1) {
252 d->currentProgress =
d->progressProxy()->maximum();
255 if (
d->currentProgress >=
d->progressProxy()->maximum()) {
257 QMutexLocker l(&
d->mutex);
260 d->progressProxy()->setRange(0,
d->taskMax);
261 d->progressProxy()->setValue(
d->progressProxy()->maximum());
263 d->progressProxy()->setValue(
d->currentProgress);
266 d->progressProxy()->setRange(0,0);
267 d->progressProxy()->setValue(0);
270 d->updateParentText();
274void KoProgressUpdater::Private::updateParentText()
276 if (!progressProxy())
return;
278 QString actionName = taskName;
283 if (updater->isPersistent() && updater->isCompleted()) {
287 if (updater->progress() < 100) {
288 const QString subTaskName = updater->mergedSubTaskName();
290 if (!subTaskName.isEmpty()) {
291 if (actionName.isEmpty()) {
292 actionName = subTaskName;
294 actionName = QString(
"%1: %2").arg(actionName).arg(subTaskName);
300 progressProxy()->setAutoNestedName(actionName);
302 progressProxy()->setFormat(actionName);
307void KoProgressUpdater::Private::clearState()
309 for (
auto it = subtasks.begin(); it != subtasks.end();) {
310 if (!(*it)->isPersistent()) {
311 (*it)->deleteLater();
312 it = subtasks.erase(it);
314 if ((*it)->interrupted()) {
315 (*it)->setInterrupted(
false);
331 d->updateCompressor->setDelay(ms);
336 return d->updateCompressor->delay();
346 return d->autoNestNames;
float value(const T *src, size_t ch)
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void setAutoNestNames(bool value)
~KoProgressUpdater() override
destructor
KoProgressProxy * progressProxy()
void triggerUpdateAsynchronously()
KoProgressProxy * parentProgressProxy
KisSignalCompressor * updateCompressor
QPointer< KoUpdater > parentUpdater
void removePersistentSubtask(QPointer< KoUpdater > updater)
void start(int range=100, const QString &text="")
void setUpdateInterval(int ms)
QList< QPointer< KoUpdaterPrivate > > subtasks
QPointer< KoUpdater > startSubtask(int weight=1, const QString &name=QString(), bool isPersistent=false)
Private(KoProgressUpdater *_q, KoProgressProxy *proxy, QPointer< KoUpdater > parentUpdater, Mode _mode)
KoProgressUpdater(KoProgressProxy *progressProxy, Mode mode=Threaded)
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
#define KIS_ASSERT_RECOVER_RETURN(cond)
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)