mirror of
https://github.com/OPM/ResInsight.git
synced 2024-12-29 10:21:54 -06:00
Progress: optionally call QApplication::processEvents on progress updates
Add ProgressInfoEventProcessingBlocker Co-authored-by: Kristian Bendiksen kristian.bendiksen@gmail.com
This commit is contained in:
parent
a3a740b722
commit
9e41db33f5
@ -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;
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
@ -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 );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -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 );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -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 );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -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() )
|
||||
{
|
||||
@ -730,4 +728,20 @@ bool ProgressInfoStatic::isUpdatePossible()
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
ProgressInfoEventProcessingBlocker::ProgressInfoEventProcessingBlocker()
|
||||
{
|
||||
ProgressInfoStatic::s_shouldProcessEvents = false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
ProgressInfoEventProcessingBlocker::~ProgressInfoEventProcessingBlocker()
|
||||
{
|
||||
ProgressInfoStatic::s_shouldProcessEvents = true;
|
||||
}
|
||||
|
||||
} // namespace caf
|
||||
|
@ -75,6 +75,15 @@ private:
|
||||
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:
|
||||
@ -89,7 +98,7 @@ public:
|
||||
size_t maxProgressValue,
|
||||
const QString& title,
|
||||
bool delayShowingProgress,
|
||||
bool allowCance );
|
||||
bool allowCancel );
|
||||
|
||||
static void setProgressDescription( const QString& description );
|
||||
static void setProgress( size_t progressValue );
|
||||
@ -104,9 +113,11 @@ private:
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user