Progress: optionally call QApplication::processEvents on progress updates.

Fixes the missing updates of UI when running long tasks in main thread.
This commit is contained in:
Kristian Bendiksen
2024-09-09 10:16:49 +02:00
parent 9b5c5ae0d3
commit eb762fd122
3 changed files with 28 additions and 17 deletions

View File

@@ -174,7 +174,7 @@ bool RimWellPathCollection::loadDataAndUpdate()
return count;
};
caf::ProgressInfo progress( allWellPaths().size() + countWellLogs( allWellPaths() ) + 2, "Reading well paths from file", false, true );
caf::ProgressInfo progress( allWellPaths().size() + countWellLogs( allWellPaths() ) + 2, "Reading well paths from file", false, true, false );
readWellPathFormationFiles();

View File

@@ -127,11 +127,15 @@ ProgressTask::~ProgressTask()
/// If you do not need a title for a particular level, simply pass "" and it will be ignored.
/// \sa setProgressDescription
//--------------------------------------------------------------------------------------------------
ProgressInfo::ProgressInfo( size_t maxProgressValue, const QString& title, bool delayShowingProgress, bool allowCancel )
ProgressInfo::ProgressInfo( size_t maxProgressValue,
const QString& title,
bool delayShowingProgress,
bool allowCancel,
bool shouldProcessEvents )
{
m_isCancelled.store( false );
ProgressInfoStatic::start( *this, maxProgressValue, title, delayShowingProgress, allowCancel );
ProgressInfoStatic::start( *this, maxProgressValue, title, delayShowingProgress, allowCancel, shouldProcessEvents );
if ( dynamic_cast<QApplication*>( QCoreApplication::instance() ) )
{
@@ -476,9 +480,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;
//--------------------------------------------------------------------------------------------------
///
@@ -487,8 +492,11 @@ void ProgressInfoStatic::start( ProgressInfo& progressInfo,
size_t maxProgressValue,
const QString& title,
bool delayShowingProgress,
bool allowCancel )
bool allowCancel,
bool shouldProcessEvents )
{
s_shouldProcessEvents = shouldProcessEvents;
if ( !isUpdatePossible() ) return;
std::vector<size_t>& progressStack_v = progressStack();
@@ -541,8 +549,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 );
}
//--------------------------------------------------------------------------------------------------
@@ -559,8 +567,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 );
}
//--------------------------------------------------------------------------------------------------
@@ -605,8 +613,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 );
}
//--------------------------------------------------------------------------------------------------
@@ -687,8 +694,6 @@ void ProgressInfoStatic::finished()
dialog->setLabelText( currentComposedLabel() );
}
// QCoreApplication::processEvents( QEventLoop::ExcludeUserInputEvents );
// If we are finishing the last level, clean up
if ( maxProgressStack_v.empty() )
{

View File

@@ -59,7 +59,11 @@ private:
class ProgressInfo
{
public:
ProgressInfo( size_t maxProgressValue, const QString& title, bool delayShowingProgress = true, bool allowCancel = false );
ProgressInfo( size_t maxProgressValue,
const QString& title,
bool delayShowingProgress = true,
bool allowCancel = false,
bool shouldProcessEvents = true );
~ProgressInfo();
void setProgressDescription( const QString& description );
@@ -89,7 +93,8 @@ public:
size_t maxProgressValue,
const QString& title,
bool delayShowingProgress,
bool allowCance );
bool allowCancel,
bool shouldProcessEvents );
static void setProgressDescription( const QString& description );
static void setProgress( size_t progressValue );
@@ -107,6 +112,7 @@ private:
static bool s_running;
static bool s_disabled;
static bool s_isButtonConnected;
static bool s_shouldProcessEvents;
};
} // namespace caf