2019-10-24 02:51:40 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2019- Equinor ASA
|
|
|
|
//
|
|
|
|
// ResInsight is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
//
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#include "RiaPlotWindowRedrawScheduler.h"
|
|
|
|
|
2019-12-19 04:37:40 -06:00
|
|
|
#include "RiuMultiPlotPage.h"
|
2019-11-13 05:22:50 -06:00
|
|
|
#include "RiuMultiPlotWindow.h"
|
2019-10-24 02:51:40 -05:00
|
|
|
#include "RiuQwtPlotWidget.h"
|
|
|
|
|
|
|
|
#include <QCoreApplication>
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
#include <set>
|
|
|
|
|
|
|
|
#include "cafProgressState.h"
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RiaPlotWindowRedrawScheduler* RiaPlotWindowRedrawScheduler::instance()
|
|
|
|
{
|
|
|
|
static RiaPlotWindowRedrawScheduler theInstance;
|
|
|
|
|
|
|
|
return &theInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-12-19 04:37:40 -06:00
|
|
|
void RiaPlotWindowRedrawScheduler::scheduleMultiPlotWindowUpdate( RiuMultiPlotWindow* plotWindow )
|
2019-10-24 02:51:40 -05:00
|
|
|
{
|
|
|
|
m_plotWindowsToUpdate.push_back( plotWindow );
|
|
|
|
|
|
|
|
startTimer( 0 );
|
|
|
|
}
|
|
|
|
|
2019-12-19 04:37:40 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RiaPlotWindowRedrawScheduler::scheduleMultiPlotPageUpdate( RiuMultiPlotPage* plotPage )
|
|
|
|
{
|
|
|
|
m_plotPagesToUpdate.push_back( plotPage );
|
|
|
|
|
|
|
|
startTimer( 0 );
|
|
|
|
}
|
|
|
|
|
2019-10-24 02:51:40 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RiaPlotWindowRedrawScheduler::schedulePlotWidgetReplot( RiuQwtPlotWidget* plotWidget )
|
|
|
|
{
|
|
|
|
m_plotWidgetsToReplot.push_back( plotWidget );
|
|
|
|
|
|
|
|
startTimer( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RiaPlotWindowRedrawScheduler::clearAllScheduledUpdates()
|
|
|
|
{
|
|
|
|
if ( m_plotWindowUpdateTimer )
|
|
|
|
{
|
|
|
|
while ( m_plotWindowUpdateTimer->isActive() )
|
|
|
|
{
|
|
|
|
QCoreApplication::processEvents();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_plotWidgetsToReplot.clear();
|
2019-12-19 04:37:40 -06:00
|
|
|
m_plotPagesToUpdate.clear();
|
2019-10-24 02:51:40 -05:00
|
|
|
m_plotWindowsToUpdate.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RiaPlotWindowRedrawScheduler::performScheduledUpdatesAndReplots()
|
|
|
|
{
|
2019-11-13 05:22:50 -06:00
|
|
|
std::set<RiuQwtPlotWidget*> updatedPlots;
|
|
|
|
std::set<RiuMultiPlotWindow*> updatedPlotWindows;
|
2019-12-19 04:37:40 -06:00
|
|
|
std::set<RiuMultiPlotPage*> updatedPlotPages;
|
2019-10-24 02:51:40 -05:00
|
|
|
|
2019-11-13 05:22:50 -06:00
|
|
|
for ( RiuMultiPlotWindow* plotWindow : m_plotWindowsToUpdate )
|
2019-10-24 02:51:40 -05:00
|
|
|
{
|
|
|
|
if ( plotWindow && !updatedPlotWindows.count( plotWindow ) )
|
|
|
|
{
|
|
|
|
plotWindow->performUpdate();
|
|
|
|
updatedPlotWindows.insert( plotWindow );
|
2019-12-19 04:37:40 -06:00
|
|
|
for ( RiuMultiPlotPage* page : plotWindow->pages() )
|
|
|
|
{
|
|
|
|
updatedPlotPages.insert( page );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( RiuMultiPlotPage* plotPage : m_plotPagesToUpdate )
|
|
|
|
{
|
|
|
|
if ( plotPage && !updatedPlotPages.count( plotPage ) )
|
|
|
|
{
|
|
|
|
plotPage->performUpdate();
|
|
|
|
updatedPlotPages.insert( plotPage );
|
2019-10-24 02:51:40 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Perform update and replot. Make sure we handle legend update
|
|
|
|
for ( RiuQwtPlotWidget* plot : m_plotWidgetsToReplot )
|
|
|
|
{
|
|
|
|
if ( plot && !updatedPlots.count( plot ) )
|
|
|
|
{
|
|
|
|
plot->replot();
|
|
|
|
updatedPlots.insert( plot );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_plotWidgetsToReplot.clear();
|
2019-12-19 04:37:40 -06:00
|
|
|
m_plotPagesToUpdate.clear();
|
2019-10-24 02:51:40 -05:00
|
|
|
m_plotWindowsToUpdate.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RiaPlotWindowRedrawScheduler::slotUpdateAndReplotScheduledItemsWhenReady()
|
|
|
|
{
|
|
|
|
if ( caf::ProgressState::isActive() )
|
|
|
|
{
|
2019-11-25 03:46:17 -06:00
|
|
|
startTimer( 100 );
|
2019-10-24 02:51:40 -05:00
|
|
|
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 );
|
|
|
|
}
|
|
|
|
}
|