From 749e19a8799c6fd60cfa37e29ddb03c3c1fecf54 Mon Sep 17 00:00:00 2001 From: Gaute Lindkvist Date: Tue, 12 Mar 2019 11:01:49 +0100 Subject: [PATCH] Create a simpler task system for handling sub tasks in progress dialog. * Remove incrementProgressAndUpdateNextStep() method --- .../RicNewWellBoreStabilityPlotFeature.cpp | 53 ++++++++++++------- .../cafUserInterface/cafProgressInfo.cpp | 41 +++++++------- Fwk/AppFwk/cafUserInterface/cafProgressInfo.h | 14 ++++- 3 files changed, 68 insertions(+), 40 deletions(-) diff --git a/ApplicationCode/Commands/WellLogCommands/RicNewWellBoreStabilityPlotFeature.cpp b/ApplicationCode/Commands/WellLogCommands/RicNewWellBoreStabilityPlotFeature.cpp index f9f78f7856..682cede2d7 100644 --- a/ApplicationCode/Commands/WellLogCommands/RicNewWellBoreStabilityPlotFeature.cpp +++ b/ApplicationCode/Commands/WellLogCommands/RicNewWellBoreStabilityPlotFeature.cpp @@ -102,29 +102,42 @@ void RicNewWellBoreStabilityPlotFeature::onActionTriggered(bool isChecked) if (!geoMechView) return; caf::ProgressInfo progInfo(100, "Creating Well Bore Stability Plot"); - progInfo.setProgressDescription("Creating plot and formation track"); - progInfo.setNextProgressIncrement(2); + RimGeoMechCase* geoMechCase = geoMechView->geoMechCase(); + RimWellLogPlot* plot = RicNewWellLogPlotFeatureImpl::createWellLogPlot(false, "Well Bore Stability"); - QString plotName("Well Bore Stability"); - RimWellLogPlot* plot = RicNewWellLogPlotFeatureImpl::createWellLogPlot(false, plotName); - createFormationTrack(plot, wellPath, geoMechCase); - progInfo.incrementProgressAndUpdateNextStep(3, "Creating well design track"); - createCasingShoeTrack(plot, wellPath, geoMechCase); - progInfo.incrementProgressAndUpdateNextStep(75, "Creating stability curves track"); - createStabilityCurvesTrack(plot, wellPath, geoMechView); - progInfo.incrementProgressAndUpdateNextStep(15, "Creating angles track"); - createAnglesTrack(plot, wellPath, geoMechView); - progInfo.incrementProgressAndUpdateNextStep(5, "Updating all tracks"); - plot->enableAllAutoNameTags(true); - plot->setPlotTitleVisible(true); - plot->setTrackLegendsVisible(true); - plot->setTrackLegendsHorizontal(true); - plot->setDepthType(RimWellLogPlot::TRUE_VERTICAL_DEPTH); - plot->setDepthAutoZoom(true); + { + auto task = progInfo.task("Creating formation track", 2); + createFormationTrack(plot, wellPath, geoMechCase); + } + + { + auto task = progInfo.task("Creating well design track", 3); + createCasingShoeTrack(plot, wellPath, geoMechCase); + } - RicNewWellLogPlotFeatureImpl::updateAfterCreation(plot); - progInfo.incrementProgress(); + { + auto task = progInfo.task("Creating stability curves track", 75); + createStabilityCurvesTrack(plot, wellPath, geoMechView); + } + + { + auto task = progInfo.task("Creating angles track", 15); + createAnglesTrack(plot, wellPath, geoMechView); + } + + { + auto task = progInfo.task("Updating all tracks", 5); + + plot->enableAllAutoNameTags(true); + plot->setPlotTitleVisible(true); + plot->setTrackLegendsVisible(true); + plot->setTrackLegendsHorizontal(true); + plot->setDepthType(RimWellLogPlot::TRUE_VERTICAL_DEPTH); + plot->setDepthAutoZoom(true); + + RicNewWellLogPlotFeatureImpl::updateAfterCreation(plot); + } RiuPlotMainWindowTools::selectAsCurrentItem(plot); diff --git a/Fwk/AppFwk/cafUserInterface/cafProgressInfo.cpp b/Fwk/AppFwk/cafUserInterface/cafProgressInfo.cpp index f65691167c..37b84df39f 100644 --- a/Fwk/AppFwk/cafUserInterface/cafProgressInfo.cpp +++ b/Fwk/AppFwk/cafUserInterface/cafProgressInfo.cpp @@ -50,6 +50,18 @@ namespace caf { + //-------------------------------------------------------------------------------------------------- + /// + //-------------------------------------------------------------------------------------------------- + ProgressTask::ProgressTask(ProgressInfo& parentTask) + : m_parentTask(parentTask) + { + } + ProgressTask::~ProgressTask() + { + m_parentTask.incrementProgress(); + } + //================================================================================================== /// /// \class caf::ProgressInfo @@ -152,16 +164,6 @@ namespace caf { ProgressInfoStatic::incrementProgress(); } - //-------------------------------------------------------------------------------------------------- - /// Convenience method for incrementing progress and setting step size and description for next step - //-------------------------------------------------------------------------------------------------- - void ProgressInfo::incrementProgressAndUpdateNextStep(size_t nextStepSize, const QString& nextDescription) - { - incrementProgress(); - setNextProgressIncrement(nextStepSize); - setProgressDescription(nextDescription); - } - //-------------------------------------------------------------------------------------------------- /// To make a certain operation span more of the progress bar than one tick, /// set the number of progress ticks that you want it to use before calling it. @@ -176,15 +178,18 @@ namespace caf { //-------------------------------------------------------------------------------------------------- void ProgressInfo::setNextProgressIncrement(size_t nextStepSize) { - ProgressInfoStatic::setNextProgressIncrement(nextStepSize); + ProgressInfoStatic::setNextProgressIncrement(nextStepSize); } - - - - - - + //-------------------------------------------------------------------------------------------------- + /// + //-------------------------------------------------------------------------------------------------- + caf::ProgressTask ProgressInfo::task(const QString& description, int stepSize) + { + setProgressDescription(description); + setNextProgressIncrement(stepSize); + return caf::ProgressTask(*this); + } //================================================================================================== /// @@ -631,6 +636,4 @@ namespace caf { //if (progressDialog()) progressDialog()->repaint(); } } - - } // namespace caf diff --git a/Fwk/AppFwk/cafUserInterface/cafProgressInfo.h b/Fwk/AppFwk/cafUserInterface/cafProgressInfo.h index 9cdfcfc494..16fefc39e2 100644 --- a/Fwk/AppFwk/cafUserInterface/cafProgressInfo.h +++ b/Fwk/AppFwk/cafUserInterface/cafProgressInfo.h @@ -43,6 +43,17 @@ class QString; namespace caf { +class ProgressInfo; + +class ProgressTask +{ +public: + ProgressTask(ProgressInfo& parentTask); + ~ProgressTask(); +private: + ProgressInfo& m_parentTask; +}; + class ProgressInfo { public: @@ -52,9 +63,10 @@ public: void setProgressDescription(const QString& description); void setProgress(size_t progressValue); void incrementProgress(); - void incrementProgressAndUpdateNextStep(size_t nextStepSize, const QString& nextDescription); void setNextProgressIncrement(size_t nextStepSize); + ProgressTask task(const QString& description, int stepSize); + };