From 193193d35fd1ceb8962cbe147f4bd3172d5f6c01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Mon, 31 Oct 2016 08:43:36 +0100 Subject: [PATCH] caf::ProgressInfo: Added some more descriptions and warnings on misuse. Added debug helper variables. --- .../cafUserInterface/cafProgressInfo.cpp | 45 ++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/Fwk/AppFwk/cafUserInterface/cafProgressInfo.cpp b/Fwk/AppFwk/cafUserInterface/cafProgressInfo.cpp index 1881a2d7ba..f349a44d4c 100644 --- a/Fwk/AppFwk/cafUserInterface/cafProgressInfo.cpp +++ b/Fwk/AppFwk/cafUserInterface/cafProgressInfo.cpp @@ -56,7 +56,7 @@ namespace caf { /// When the method returns, the ProgressInfo destructor will clean up and finish. /// The real beauty is that this class will magically interact with possible ProgressInfo instances /// in functions that your method calls, providing a complete, consistent and detailed progress bar - /// + /// /// caf::ProgressInfo progInfo(3, "Open File"); /// progInfo.setProgressDescription("Reading"); /// ...readFile() @@ -67,6 +67,26 @@ namespace caf { /// progInfo.setProgressDescription("Building geometry"); /// ... buildGeometry(); /// progInfo.incrementProgress(); // not needed really, because the destructor will send the progress to top. + /// + /// There are one particular limitation: The progress will not work correctly if the higher level + /// ProgressInfo object does not increment progress between the creation and operation of two (or more) + /// independent lower level ProgressInfo objects. If not, the progress will restart (within its limits) + /// for each progress object that is operating. + /// + /// caf::ProgressInfo progInfoHighLevel(3, "Open File"); + /// + /// { + /// caf::ProgressInfo progInfoLowLevel(10, ""); + /// } + /// // NEEDS progInfoHighLevel.incrementProgress() here !! + /// { + /// caf::ProgressInfo progInfoLowLevel(10, ""); + /// } + /// + /// It is not allowed to have several ProgressInfo objects in the same scope level + /// + /// caf::ProgressInfo progInfo1(10, ""); + /// caf::ProgressInfo progInfo2(10, ""); //<-- Will not work well //================================================================================================== //-------------------------------------------------------------------------------------------------- @@ -233,6 +253,8 @@ namespace caf { //-------------------------------------------------------------------------------------------------- static size_t currentTotalMaxProgressValue() { + std::vector& maxProgressStack_v = maxProgressStack(); + size_t levCount = 1; for (size_t levelDepth = 0; levelDepth < maxProgressStack().size(); ++levelDepth) { @@ -247,6 +269,11 @@ namespace caf { static size_t currentTotalProgress() { double progress = 0; + + std::vector& progressStack_v = progressStack(); + std::vector& progressSpanStack_v = progressSpanStack(); + std::vector& maxProgressStack_v = maxProgressStack(); + for (int i = static_cast(progressStack().size()) - 1; i >= 0; --i) { size_t span = (i < 1) ? 1 : progressSpanStack()[i - 1]; @@ -301,6 +328,10 @@ namespace caf { { if (!isUpdatePossible()) return; + std::vector& progressStack_v = progressStack(); + std::vector& progressSpanStack_v = progressSpanStack(); + std::vector& maxProgressStack_v = maxProgressStack(); + if (!maxProgressStack().size()) { //progressDialog()->setWindowModality(Qt::ApplicationModal); @@ -347,6 +378,10 @@ namespace caf { { if (!isUpdatePossible()) return; + std::vector& progressStack_v = progressStack(); + std::vector& progressSpanStack_v = progressSpanStack(); + std::vector& maxProgressStack_v = maxProgressStack(); + if (progressValue == progressStack().back()) return; // Do nothing if no progress. // Guard against the max value set for this level @@ -375,6 +410,10 @@ namespace caf { { if (!isUpdatePossible()) return; + std::vector& progressStack_v = progressStack(); + std::vector& progressSpanStack_v = progressSpanStack(); + std::vector& maxProgressStack_v = maxProgressStack(); + assert(progressStack().size()); ProgressInfoStatic::setProgress(progressStack().back() + progressSpanStack().back()); } @@ -400,6 +439,10 @@ namespace caf { { if (!isUpdatePossible()) return; + std::vector& progressStack_v = progressStack(); + std::vector& progressSpanStack_v = progressSpanStack(); + std::vector& maxProgressStack_v = maxProgressStack(); + assert(maxProgressStack().size() && progressStack().size() && progressSpanStack().size() && titleStack().size() && descriptionStack().size()); // Set progress to max value, and leave it there until somebody touches the progress again