From 27bc3300d670d65b9c5332308605ef8263c3939c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20Vr=C3=A1til?= Date: Fri, 3 Apr 2015 18:17:12 +0200 Subject: Async: implement progress reporting through future This is a simplified progress reporting, since it does not report progress of ther overcall Job chain, but only of individual tasks, which makes it only really useful on one-task Jobs. TODO: propagate subjob progress to the Future user gets copy of TODO: compound progress reporting (be able to report a progress of the overall Job chain) --- async/src/future.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'async/src/future.cpp') diff --git a/async/src/future.cpp b/async/src/future.cpp index 970060b..4f3cd80 100644 --- a/async/src/future.cpp +++ b/async/src/future.cpp @@ -102,6 +102,21 @@ QString FutureBase::errorMessage() const return d->errorMessage; } +void FutureBase::setProgress(int processed, int total) +{ + setProgress((qreal) processed / total); +} + +void FutureBase::setProgress(qreal progress) +{ + for (auto watcher : d->watchers) { + if (watcher) { + watcher->futureProgressCallback(progress); + } + } +} + + void FutureBase::addWatcher(FutureWatcherBase* watcher) { @@ -128,6 +143,11 @@ void FutureWatcherBase::futureReadyCallback() Q_EMIT futureReady(); } +void FutureWatcherBase::futureProgressCallback(qreal progress) +{ + Q_EMIT futureProgress(progress); +} + void FutureWatcherBase::setFutureImpl(const FutureBase &future) { d->future = future; -- cgit v1.2.3