Skip to content

Commit

Permalink
Progress emit only when changed
Browse files Browse the repository at this point in the history
  • Loading branch information
vpicaver committed Mar 22, 2020
1 parent 6489ad7 commit a7a36be
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions asyncfuture.h
Original file line number Diff line number Diff line change
Expand Up @@ -739,11 +739,6 @@ class DeferredFuture : public QObject, public QFutureInterface<T>{
mutex.unlock();
}

void setParent(QFuture<void> future) {
setParentProgressValue(future.progressValue());
setParentProgressRange(future.progressMinimum(), future.progressMaximum());
}

protected:
DeferredFuture(QObject* parent = nullptr): QObject(parent),
QFutureInterface<T>(QFutureInterface<T>::Running),
Expand Down Expand Up @@ -790,11 +785,17 @@ class DeferredFuture : public QObject, public QFutureInterface<T>{
}

void updateProgressRanges() {
QFutureInterface<T>::setProgressRange(0, parentProgress.range() + watchProgress.range());
int newMax = parentProgress.range() + watchProgress.range();
if(QFutureInterface<T>::progressMaximum() != newMax) {
QFutureInterface<T>::setProgressRange(0, newMax);
}
}

void updateProgressValue() {
QFutureInterface<T>::setProgressValue(parentProgress.value + watchProgress.value);
int newProgress = parentProgress.value + watchProgress.value;
if(QFutureInterface<T>::progressValue() != newProgress) {
QFutureInterface<T>::setProgressValue(newProgress);
}
}

/// The future is already finished. It will take effect immediately
Expand Down Expand Up @@ -853,17 +854,21 @@ class CombinedFuture: public DeferredFuture<void> {
progressFunc = [=](int progress) {
mutex.lock();
int diff = progress - *currentProgress;
*currentProgress = progress;
QFutureInterface<void>::setProgressValue(progressValue() + diff);
if(diff != 0) {
*currentProgress = progress;
QFutureInterface<void>::setProgressValue(progressValue() + diff);
}
mutex.unlock();
};

progressRangeFunc = [=](int min, int max) {
Q_UNUSED(min);
mutex.lock();
int diff = max - *progressIncrement;
*progressIncrement = max;
QFutureInterface<void>::setProgressRange(0, progressMaximum() + diff);
if(diff != 0) {
*progressIncrement = max;
QFutureInterface<void>::setProgressRange(0, progressMaximum() + diff);
}
mutex.unlock();
};
}
Expand Down

0 comments on commit a7a36be

Please sign in to comment.