mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Remove duplicated code in RiaPlotWindowRedrawScheduler
This commit is contained in:
parent
59df1a655e
commit
71b0ae1a16
@ -15,19 +15,13 @@
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RiaPlotWindowRedrawScheduler.h"
|
||||
|
||||
#include "RiuMultiPlotBook.h"
|
||||
#include "RiuMultiPlotPage.h"
|
||||
#include "RiuPlotWidget.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDebug>
|
||||
|
||||
#include <set>
|
||||
|
||||
#include "cafProgressState.h"
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -87,13 +81,8 @@ void RiaPlotWindowRedrawScheduler::schedulePlotWidgetReplot( RiuPlotWidget* plot
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaPlotWindowRedrawScheduler::clearAllScheduledUpdates()
|
||||
{
|
||||
if ( m_plotWindowUpdateTimer )
|
||||
{
|
||||
while ( m_plotWindowUpdateTimer->isActive() )
|
||||
{
|
||||
QCoreApplication::processEvents();
|
||||
}
|
||||
}
|
||||
waitUntilWorkIsDone();
|
||||
|
||||
m_plotWidgetsToReplot.clear();
|
||||
m_plotPagesToUpdate.clear();
|
||||
m_plotBooksToUpdate.clear();
|
||||
@ -102,7 +91,7 @@ void RiaPlotWindowRedrawScheduler::clearAllScheduledUpdates()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaPlotWindowRedrawScheduler::performScheduledUpdatesAndReplots()
|
||||
void RiaPlotWindowRedrawScheduler::performScheduledUpdates()
|
||||
{
|
||||
std::map<QPointer<RiuMultiPlotBook>, RiaDefines::MultiPlotPageUpdateType> plotBooksToUpdate;
|
||||
std::map<QPointer<RiuMultiPlotPage>, RiaDefines::MultiPlotPageUpdateType> pagesToUpdate;
|
||||
@ -145,57 +134,3 @@ void RiaPlotWindowRedrawScheduler::performScheduledUpdatesAndReplots()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaPlotWindowRedrawScheduler::blockScheduledUpdatesAndReplots()
|
||||
{
|
||||
m_blockScheduledUpdatesAndReplots = true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaPlotWindowRedrawScheduler::unblockScheduledUpdatesAndReplots()
|
||||
{
|
||||
m_blockScheduledUpdatesAndReplots = false;
|
||||
startTimer( 0 );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaPlotWindowRedrawScheduler::slotUpdateAndReplotScheduledItemsWhenReady()
|
||||
{
|
||||
if ( m_blockScheduledUpdatesAndReplots )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ( caf::ProgressState::isActive() )
|
||||
{
|
||||
startTimer( 100 );
|
||||
return;
|
||||
}
|
||||
|
||||
performScheduledUpdatesAndReplots();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaPlotWindowRedrawScheduler::startTimer( int msecs )
|
||||
{
|
||||
if ( !m_plotWindowUpdateTimer )
|
||||
{
|
||||
m_plotWindowUpdateTimer.reset( new QTimer( this ) );
|
||||
connect( m_plotWindowUpdateTimer.data(), SIGNAL( timeout() ), this, SLOT( slotUpdateAndReplotScheduledItemsWhenReady() ) );
|
||||
}
|
||||
|
||||
if ( !m_plotWindowUpdateTimer->isActive() )
|
||||
{
|
||||
m_plotWindowUpdateTimer->setSingleShot( true );
|
||||
m_plotWindowUpdateTimer->start( msecs );
|
||||
}
|
||||
}
|
||||
|
@ -17,23 +17,19 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
#pragma once
|
||||
|
||||
#include "cafPdmPointer.h"
|
||||
|
||||
#include "RiaDefines.h"
|
||||
#include "RiaScheduler.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QPointer>
|
||||
#include <QScopedPointer>
|
||||
#include <QTimer>
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
|
||||
class RiuMultiPlotPage;
|
||||
class RiuMultiPlotBook;
|
||||
class RiuPlotWidget;
|
||||
|
||||
class RiaPlotWindowRedrawScheduler : public QObject
|
||||
class RiaPlotWindowRedrawScheduler : public RiaScheduler
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -46,26 +42,12 @@ public:
|
||||
RiaDefines::MultiPlotPageUpdateType updateType = RiaDefines::MultiPlotPageUpdateType::ALL );
|
||||
void schedulePlotWidgetReplot( RiuPlotWidget* plotWidget );
|
||||
void clearAllScheduledUpdates();
|
||||
void performScheduledUpdatesAndReplots();
|
||||
|
||||
void blockScheduledUpdatesAndReplots();
|
||||
void unblockScheduledUpdatesAndReplots();
|
||||
|
||||
private slots:
|
||||
void slotUpdateAndReplotScheduledItemsWhenReady();
|
||||
|
||||
private:
|
||||
RiaPlotWindowRedrawScheduler() = default;
|
||||
~RiaPlotWindowRedrawScheduler() override = default;
|
||||
|
||||
void startTimer( int msecs );
|
||||
void performScheduledUpdates() override;
|
||||
|
||||
private:
|
||||
std::map<QPointer<RiuMultiPlotPage>, RiaDefines::MultiPlotPageUpdateType> m_plotPagesToUpdate;
|
||||
std::map<QPointer<RiuMultiPlotBook>, RiaDefines::MultiPlotPageUpdateType> m_plotBooksToUpdate;
|
||||
|
||||
std::set<QPointer<RiuPlotWidget>> m_plotWidgetsToReplot;
|
||||
|
||||
QScopedPointer<QTimer> m_plotWindowUpdateTimer;
|
||||
bool m_blockScheduledUpdatesAndReplots = false;
|
||||
};
|
||||
|
@ -26,6 +26,7 @@
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaScheduler::RiaScheduler()
|
||||
: m_blockUpdate( false )
|
||||
{
|
||||
}
|
||||
|
||||
@ -36,6 +37,18 @@ RiaScheduler::~RiaScheduler()
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaScheduler::blockUpdate( bool blockUpdate )
|
||||
{
|
||||
m_blockUpdate = blockUpdate;
|
||||
if ( !m_blockUpdate )
|
||||
{
|
||||
startTimer( 0 );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -47,7 +60,7 @@ void RiaScheduler::slotUpdateScheduledItemsWhenReady()
|
||||
return;
|
||||
}
|
||||
|
||||
performScheduledUpdates();
|
||||
if ( !m_blockUpdate ) performScheduledUpdates();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -35,6 +35,8 @@ public:
|
||||
|
||||
virtual void performScheduledUpdates() = 0;
|
||||
|
||||
void blockUpdate( bool blockUpdate );
|
||||
|
||||
protected:
|
||||
void startTimer( int msecs );
|
||||
void waitUntilWorkIsDone();
|
||||
@ -44,4 +46,5 @@ private slots:
|
||||
|
||||
private:
|
||||
QScopedPointer<QTimer> m_updateTimer;
|
||||
bool m_blockUpdate;
|
||||
};
|
||||
|
@ -89,7 +89,7 @@ void RicSnapshotViewToFileFeature::savePlotPdfReportAs( const QString& fileName,
|
||||
|
||||
auto viewWidget = plot->viewWidget();
|
||||
|
||||
RiaPlotWindowRedrawScheduler::instance()->performScheduledUpdatesAndReplots();
|
||||
RiaPlotWindowRedrawScheduler::instance()->performScheduledUpdates();
|
||||
QCoreApplication::processEvents();
|
||||
QFile pdfFile( fileName );
|
||||
if ( pdfFile.open( QIODevice::WriteOnly ) )
|
||||
|
@ -70,7 +70,7 @@ void RicAppendSummaryPlotsForObjectsFeature::appendPlots( RimSummaryMultiPlot*
|
||||
caf::ProgressInfo info( sumAddressCollections.size(), "Appending plots..." );
|
||||
|
||||
summaryMultiPlot->startBatchAddOperation();
|
||||
RiaPlotWindowRedrawScheduler::instance()->blockScheduledUpdatesAndReplots();
|
||||
RiaPlotWindowRedrawScheduler::instance()->blockUpdate( true );
|
||||
|
||||
for ( auto summaryAdrCollection : sumAddressCollections )
|
||||
{
|
||||
@ -119,7 +119,7 @@ void RicAppendSummaryPlotsForObjectsFeature::appendPlots( RimSummaryMultiPlot*
|
||||
summaryMultiPlot->endBatchAddOperation();
|
||||
|
||||
RiaPlotWindowRedrawScheduler::instance()->clearAllScheduledUpdates();
|
||||
RiaPlotWindowRedrawScheduler::instance()->unblockScheduledUpdatesAndReplots();
|
||||
RiaPlotWindowRedrawScheduler::instance()->blockUpdate( false );
|
||||
|
||||
summaryMultiPlot->loadDataAndUpdate();
|
||||
|
||||
|
@ -95,7 +95,7 @@ void RicNewMultiPhaseRftSegmentPlotFeature::onActionTriggered( bool isChecked )
|
||||
plot->loadDataAndUpdate();
|
||||
plot->updateTrackVisibility();
|
||||
|
||||
RiaPlotWindowRedrawScheduler::instance()->performScheduledUpdatesAndReplots();
|
||||
RiaPlotWindowRedrawScheduler::instance()->performScheduledUpdates();
|
||||
plot->updateLayout();
|
||||
|
||||
RiuPlotMainWindowTools::onObjectAppended( plot );
|
||||
|
@ -104,7 +104,7 @@ void RicNewRftSegmentWellLogPlotFeature::onActionTriggered( bool isChecked )
|
||||
plot->loadDataAndUpdate();
|
||||
plot->updateTrackVisibility();
|
||||
|
||||
RiaPlotWindowRedrawScheduler::instance()->performScheduledUpdatesAndReplots();
|
||||
RiaPlotWindowRedrawScheduler::instance()->performScheduledUpdates();
|
||||
plot->updateLayout();
|
||||
|
||||
RiuPlotMainWindowTools::onObjectAppended( plot );
|
||||
|
@ -950,7 +950,7 @@ void RimDepthTrackPlot::onPlotsReordered( const SignalEmitter* emitter )
|
||||
recreatePlotWidgets();
|
||||
loadDataAndUpdate();
|
||||
|
||||
RiaPlotWindowRedrawScheduler::instance()->performScheduledUpdatesAndReplots();
|
||||
RiaPlotWindowRedrawScheduler::instance()->performScheduledUpdates();
|
||||
updateLayout();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user