From a7a36bebe17119fbce1cebd304a546823d252563 Mon Sep 17 00:00:00 2001 From: Philip Schuchardt Date: Sat, 21 Mar 2020 23:55:47 -0400 Subject: [PATCH] Progress emit only when changed --- asyncfuture.h | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/asyncfuture.h b/asyncfuture.h index 19f1fe8..0127731 100644 --- a/asyncfuture.h +++ b/asyncfuture.h @@ -739,11 +739,6 @@ class DeferredFuture : public QObject, public QFutureInterface{ mutex.unlock(); } - void setParent(QFuture future) { - setParentProgressValue(future.progressValue()); - setParentProgressRange(future.progressMinimum(), future.progressMaximum()); - } - protected: DeferredFuture(QObject* parent = nullptr): QObject(parent), QFutureInterface(QFutureInterface::Running), @@ -790,11 +785,17 @@ class DeferredFuture : public QObject, public QFutureInterface{ } void updateProgressRanges() { - QFutureInterface::setProgressRange(0, parentProgress.range() + watchProgress.range()); + int newMax = parentProgress.range() + watchProgress.range(); + if(QFutureInterface::progressMaximum() != newMax) { + QFutureInterface::setProgressRange(0, newMax); + } } void updateProgressValue() { - QFutureInterface::setProgressValue(parentProgress.value + watchProgress.value); + int newProgress = parentProgress.value + watchProgress.value; + if(QFutureInterface::progressValue() != newProgress) { + QFutureInterface::setProgressValue(newProgress); + } } /// The future is already finished. It will take effect immediately @@ -853,8 +854,10 @@ class CombinedFuture: public DeferredFuture { progressFunc = [=](int progress) { mutex.lock(); int diff = progress - *currentProgress; - *currentProgress = progress; - QFutureInterface::setProgressValue(progressValue() + diff); + if(diff != 0) { + *currentProgress = progress; + QFutureInterface::setProgressValue(progressValue() + diff); + } mutex.unlock(); }; @@ -862,8 +865,10 @@ class CombinedFuture: public DeferredFuture { Q_UNUSED(min); mutex.lock(); int diff = max - *progressIncrement; - *progressIncrement = max; - QFutureInterface::setProgressRange(0, progressMaximum() + diff); + if(diff != 0) { + *progressIncrement = max; + QFutureInterface::setProgressRange(0, progressMaximum() + diff); + } mutex.unlock(); }; }