Merge pull request #8654 from OPM/filter_wheelevents

Summary Multiplot: page scroll and zoom fixes
This commit is contained in:
jonjenssen
2022-03-10 13:13:44 +01:00
committed by GitHub
parent 0d45b88d09
commit c9b762fb16
13 changed files with 244 additions and 11 deletions

View File

@@ -1687,11 +1687,16 @@ bool RiaGuiApplication::notify( QObject* receiver, QEvent* event )
{
if ( event->type() == QEvent::KeyPress )
{
QKeyEvent* keyEvent = static_cast<QKeyEvent*>( event );
RimPlotWindow* plot = dynamic_cast<RimPlotWindow*>( activePlotWindow() );
QKeyEvent* keyEvent = static_cast<QKeyEvent*>( event );
RimPlotWindow* plot = dynamic_cast<RimPlotWindow*>( activePlotWindow() );
if ( plot ) done = plot->handleGlobalKeyEvent( keyEvent );
}
else if ( event->type() == QEvent::Wheel )
{
QWheelEvent* wheelEvent = static_cast<QWheelEvent*>( event );
RimPlotWindow* plot = dynamic_cast<RimPlotWindow*>( activePlotWindow() );
if ( plot ) done = plot->handleGlobalWheelEvent( wheelEvent );
}
if ( !done )
{
done = QApplication::notify( receiver, event );

View File

@@ -906,3 +906,14 @@ void RimMultiPlot::cleanupBeforeClose()
m_viewer = nullptr;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimMultiPlot::isMouseCursorInsidePlot()
{
if ( !m_viewer ) return false;
QPoint curpos = m_viewer->mapFromGlobal( QCursor::pos() );
return ( m_viewer->rect().contains( curpos ) );
}

View File

@@ -141,6 +141,8 @@ protected:
virtual void updatePlotWindowTitle();
bool isMouseCursorInsidePlot();
private:
void cleanupBeforeClose();
void doUpdateLayout() override;

View File

@@ -344,3 +344,11 @@ bool RimPlotWindow::handleGlobalKeyEvent( QKeyEvent* keyEvent )
{
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimPlotWindow::handleGlobalWheelEvent( QWheelEvent* wheelEvent )
{
return false;
}

View File

@@ -32,6 +32,7 @@ class RiuQwtPlotWidget;
class QwtPlotCurve;
class QKeyEvent;
class QWheelEvent;
class QPaintDevice;
//==================================================================================================
@@ -76,6 +77,7 @@ public:
QPageLayout pageLayout() const;
virtual bool handleGlobalKeyEvent( QKeyEvent* keyEvent );
virtual bool handleGlobalWheelEvent( QWheelEvent* wheelEvent );
protected:
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;

View File

@@ -16,7 +16,7 @@
//
/////////////////////////////////////////////////////////////////////////////////
#include "RimMultiPlot.h"
#include "RimSummaryMultiPlot.h"
#include "RiaSummaryAddressAnalyzer.h"
#include "RiaSummaryStringTools.h"
@@ -31,7 +31,7 @@
#include "RimSummaryCurve.h"
#include "RimSummaryPlotControls.h"
#include "RimSummaryMultiPlot.h"
#include "RimMultiPlot.h"
#include "RimSummaryPlot.h"
#include "RimSummaryPlotNameHelper.h"
#include "RimSummaryPlotSourceStepping.h"
@@ -43,6 +43,8 @@
#include "cafPdmUiTreeOrdering.h"
#include "cafPdmUiTreeSelectionEditor.h"
#include <QKeyEvent>
CAF_PDM_SOURCE_INIT( RimSummaryMultiPlot, "MultiSummaryPlot" );
//--------------------------------------------------------------------------------------------------
///
@@ -60,6 +62,11 @@ RimSummaryMultiPlot::RimSummaryMultiPlot()
m_syncAxisRanges.uiCapability()->setUiEditorTypeName( caf::PdmUiPushButtonEditor::uiEditorTypeName() );
m_syncAxisRanges.uiCapability()->setUiIconFromResourceString( ":/AxesSync16x16.png" );
CAF_PDM_InitField( &m_disableWheelZoom, "DisableWheelZoom", true, "", "", "Disable Mouse Wheel Zooming in Multi Summary Plot" );
m_disableWheelZoom.xmlCapability()->disableIO();
m_disableWheelZoom.uiCapability()->setUiEditorTypeName( caf::PdmUiPushButtonEditor::uiEditorTypeName() );
m_disableWheelZoom.uiCapability()->setUiIconFromResourceString( ":/DisableZoom.png" );
CAF_PDM_InitFieldNoDefault( &m_sourceStepping, "SourceStepping", "" );
m_sourceStepping = new RimSummaryPlotSourceStepping;
m_sourceStepping->setSourceSteppingType( RimSummaryDataSourceStepping::Axis::Y_AXIS );
@@ -388,6 +395,7 @@ std::vector<caf::PdmFieldHandle*> RimSummaryMultiPlot::fieldsToShowInToolbar()
{
std::vector<caf::PdmFieldHandle*> toolBarFields;
toolBarFields.push_back( &m_disableWheelZoom );
toolBarFields.push_back( &m_syncAxisRanges );
auto& sourceObject = m_sourceStepping();
@@ -405,7 +413,48 @@ std::vector<caf::PdmFieldHandle*> RimSummaryMultiPlot::fieldsToShowInToolbar()
//--------------------------------------------------------------------------------------------------
bool RimSummaryMultiPlot::handleGlobalKeyEvent( QKeyEvent* keyEvent )
{
return RimSummaryPlotControls::handleKeyEvents( m_sourceStepping(), keyEvent );
if ( !RimSummaryPlotControls::handleKeyEvents( m_sourceStepping(), keyEvent ) )
{
if ( isMouseCursorInsidePlot() )
{
if ( keyEvent->key() == Qt::Key_PageUp )
{
m_viewer->goToPrevPage();
return true;
}
else if ( keyEvent->key() == Qt::Key_PageDown )
{
m_viewer->goToNextPage();
return true;
}
}
return false;
}
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimSummaryMultiPlot::handleGlobalWheelEvent( QWheelEvent* wheelEvent )
{
if ( m_disableWheelZoom )
{
if ( isMouseCursorInsidePlot() )
{
if ( wheelEvent->angleDelta().y() > 0 )
{
m_viewer->goToPrevPage();
}
else if ( wheelEvent->angleDelta().y() < 0 )
{
m_viewer->goToNextPage();
}
return true;
}
}
return false;
}
//--------------------------------------------------------------------------------------------------

View File

@@ -63,6 +63,7 @@ public:
protected:
bool handleGlobalKeyEvent( QKeyEvent* keyEvent ) override;
bool handleGlobalWheelEvent( QWheelEvent* wheelEvent ) override;
private:
void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override;
@@ -82,6 +83,7 @@ private:
caf::PdmField<bool> m_autoPlotTitles;
caf::PdmField<bool> m_autoPlotTitlesOnSubPlots;
caf::PdmField<bool> m_syncAxisRanges;
caf::PdmField<bool> m_disableWheelZoom;
caf::PdmChildField<RimSummaryPlotSourceStepping*> m_sourceStepping;

View File

@@ -99,6 +99,7 @@ RiuMultiPlotBook::RiuMultiPlotBook( RimMultiPlot* plotDefinition, QWidget* paren
, m_titleVisible( true )
, m_subTitlesVisible( true )
, m_previewMode( true )
, m_currentPageIndex( 0 )
{
const int spacing = 8;
@@ -585,3 +586,30 @@ void RiuMultiPlotBook::applyLook()
m_book->setPalette( newPalette );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuMultiPlotBook::changeCurrentPage( int pageDiff )
{
m_currentPageIndex += pageDiff;
if ( m_currentPageIndex >= (int)m_pages.size() ) m_currentPageIndex = (int)m_pages.size() - 1;
if ( m_currentPageIndex < 0 ) m_currentPageIndex = 0;
if ( !m_pages.isEmpty() ) m_scrollArea->ensureWidgetVisible( m_pages[m_currentPageIndex] );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuMultiPlotBook::goToNextPage()
{
changeCurrentPage( 1 );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuMultiPlotBook::goToPrevPage()
{
changeCurrentPage( -1 );
}

View File

@@ -86,6 +86,9 @@ public:
void renderTo( QPaintDevice* painter );
void goToNextPage();
void goToPrevPage();
protected:
void contextMenuEvent( QContextMenuEvent* ) override;
@@ -107,6 +110,9 @@ private:
const QList<QPointer<RiuMultiPlotPage>>& pages() const;
RiuMultiPlotPage* createPage();
void applyLook();
void changeCurrentPage( int pageDiff );
private slots:
virtual void performUpdate();
@@ -125,4 +131,5 @@ protected:
bool m_titleVisible;
bool m_subTitlesVisible;
bool m_previewMode;
int m_currentPageIndex;
};