Skip to content

Commit

Permalink
Progress: optionally call QApplication::processEvents on progress upd…
Browse files Browse the repository at this point in the history
…ates

Add ProgressInfoEventProcessingBlocker

Co-authored-by: Kristian Bendiksen [email protected]
  • Loading branch information
magnesj committed Sep 11, 2024
1 parent a3a740b commit 9e41db3
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ void RicWellPathsImportOsduFeature::onActionTriggered( bool isChecked )
{
std::vector<RiuWellImportWizard::WellInfo> importedWells = wellImportwizard.importedWells();

caf::ProgressInfo progress( importedWells.size(), "Importing wells from OSDU", false, true );
int colorIndex = 0;
std::vector<RimOsduWellPath*> newWells;
caf::ProgressInfoEventProcessingBlocker blocker;
caf::ProgressInfo progress( importedWells.size(), "Importing wells from OSDU", false, true );
int colorIndex = 0;
std::vector<RimOsduWellPath*> newWells;
for ( const auto& w : importedWells )
{
auto wellPath = new RimOsduWellPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ bool RimWellPathCollection::loadDataAndUpdate()
return count;
};

caf::ProgressInfoEventProcessingBlocker blocker;
caf::ProgressInfo progress( allWellPaths().size() + countWellLogs( allWellPaths() ) + 2, "Reading well paths from file", false, true );

readWellPathFormationFiles();
Expand Down
36 changes: 25 additions & 11 deletions Fwk/AppFwk/cafUserInterface/cafProgressInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,9 +476,10 @@ ProgressInfoBlocker::~ProgressInfoBlocker()
///
//==================================================================================================

bool ProgressInfoStatic::s_disabled = false;
bool ProgressInfoStatic::s_running = false;
bool ProgressInfoStatic::s_isButtonConnected = false;
bool ProgressInfoStatic::s_disabled = false;
bool ProgressInfoStatic::s_running = false;
bool ProgressInfoStatic::s_isButtonConnected = false;
bool ProgressInfoStatic::s_shouldProcessEvents = true;

//--------------------------------------------------------------------------------------------------
///
Expand Down Expand Up @@ -541,8 +542,8 @@ void ProgressInfoStatic::start( ProgressInfo& progressInfo,
dialog->setValue( static_cast<int>( currentTotalProgress() ) );
dialog->setLabelText( currentComposedLabel() );
}
// QCoreApplication::processEvents( QEventLoop::ExcludeUserInputEvents );
// if (progressDialog()) progressDialog()->repaint();

if ( s_shouldProcessEvents ) QCoreApplication::processEvents( QEventLoop::ExcludeUserInputEvents );
}

//--------------------------------------------------------------------------------------------------
Expand All @@ -559,8 +560,8 @@ void ProgressInfoStatic::setProgressDescription( const QString& description )
{
dialog->setLabelText( currentComposedLabel() );
}
// QCoreApplication::processEvents( QEventLoop::ExcludeUserInputEvents );
// if (progressDialog()) progressDialog()->repaint();

if ( s_shouldProcessEvents ) QCoreApplication::processEvents( QEventLoop::ExcludeUserInputEvents );
}

//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -605,8 +606,7 @@ void ProgressInfoStatic::setProgress( size_t progressValue )
dialog->setValue( totalProgress );
}

// QCoreApplication::processEvents( QEventLoop::ExcludeUserInputEvents );
// if (progressDialog()) progressDialog()->repaint();
if ( s_shouldProcessEvents ) QCoreApplication::processEvents( QEventLoop::ExcludeUserInputEvents );
}

//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -687,8 +687,6 @@ void ProgressInfoStatic::finished()
dialog->setLabelText( currentComposedLabel() );
}

// QCoreApplication::processEvents( QEventLoop::ExcludeUserInputEvents );

// If we are finishing the last level, clean up
if ( maxProgressStack_v.empty() )
{
Expand Down Expand Up @@ -730,4 +728,20 @@ bool ProgressInfoStatic::isUpdatePossible()
return false;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
ProgressInfoEventProcessingBlocker::ProgressInfoEventProcessingBlocker()
{
ProgressInfoStatic::s_shouldProcessEvents = false;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
ProgressInfoEventProcessingBlocker::~ProgressInfoEventProcessingBlocker()
{
ProgressInfoStatic::s_shouldProcessEvents = true;
}

} // namespace caf
13 changes: 12 additions & 1 deletion Fwk/AppFwk/cafUserInterface/cafProgressInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ class ProgressInfo
std::atomic<bool> m_isCancelled;
};

// This class is used to block the processing of events while a progress info dialog is shown. This is required when the
// progress info dialog is shown from a non-GUI thread.
class ProgressInfoEventProcessingBlocker
{
public:
ProgressInfoEventProcessingBlocker();
~ProgressInfoEventProcessingBlocker();
};

class ProgressInfoBlocker
{
public:
Expand All @@ -89,7 +98,7 @@ class ProgressInfoStatic
size_t maxProgressValue,
const QString& title,
bool delayShowingProgress,
bool allowCance );
bool allowCancel );

static void setProgressDescription( const QString& description );
static void setProgress( size_t progressValue );
Expand All @@ -104,9 +113,11 @@ class ProgressInfoStatic

private:
friend class ProgressInfoBlocker;
friend class ProgressInfoEventProcessingBlocker;
static bool s_running;
static bool s_disabled;
static bool s_isButtonConnected;
static bool s_shouldProcessEvents;
};

} // namespace caf

0 comments on commit 9e41db3

Please sign in to comment.