mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Add multi axis zoom class
Add class used to zoom all axis in a plot based on a screen rectangle.
This commit is contained in:
@@ -109,6 +109,7 @@ set(SOURCE_GROUP_HEADER_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuMatrixPlotWidget.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuMenuBarBuildTools.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuQwtPlotRectAnnotation.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuQwtPlotZoomerMultiAxes.h
|
||||
)
|
||||
|
||||
set(SOURCE_GROUP_SOURCE_FILES
|
||||
@@ -219,6 +220,7 @@ set(SOURCE_GROUP_SOURCE_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuMatrixPlotWidget.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuMenuBarBuildTools.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuQwtPlotRectAnnotation.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuQwtPlotZoomerMultiAxes.cpp
|
||||
)
|
||||
|
||||
if(RESINSIGHT_USE_QT_CHARTS)
|
||||
@@ -311,6 +313,7 @@ list(
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuTextContentFrame.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuQwtLegendOverlayContentFrame.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuMatrixPlotWidget.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuQwtPlotZoomerMultiAxes.h
|
||||
)
|
||||
|
||||
list(APPEND QT_UI_FILES)
|
||||
|
||||
@@ -65,15 +65,9 @@ RiuGridCrossQwtPlot::RiuGridCrossQwtPlot( RimGridCrossPlot* plot, QWidget* paren
|
||||
: RiuQwtPlotWidget( plot, parent )
|
||||
{
|
||||
// LeftButton for the zooming
|
||||
m_zoomerLeft = new RiuQwtPlotZoomer( qwtPlot()->canvas() );
|
||||
m_zoomerLeft->setTrackerMode( QwtPicker::AlwaysOff );
|
||||
m_zoomerLeft->initMousePattern( 1 );
|
||||
|
||||
// Attach a zoomer for the right axis
|
||||
m_zoomerRight = new RiuQwtPlotZoomer( qwtPlot()->canvas() );
|
||||
m_zoomerRight->setAxes( QwtAxis::XTop, QwtAxis::YRight );
|
||||
m_zoomerRight->setTrackerMode( QwtPicker::AlwaysOff );
|
||||
m_zoomerRight->initMousePattern( 1 );
|
||||
m_plotZoomer = new RiuQwtPlotZoomer( qwtPlot()->canvas() );
|
||||
m_plotZoomer->setTrackerMode( QwtPicker::AlwaysOff );
|
||||
m_plotZoomer->initMousePattern( 1 );
|
||||
|
||||
// MidButton for the panning
|
||||
QwtPlotPanner* panner = new QwtPlotPanner( qwtPlot()->canvas() );
|
||||
@@ -82,8 +76,7 @@ RiuGridCrossQwtPlot::RiuGridCrossQwtPlot( RimGridCrossPlot* plot, QWidget* paren
|
||||
auto wheelZoomer = new RiuQwtPlotWheelZoomer( qwtPlot() );
|
||||
|
||||
connect( wheelZoomer, SIGNAL( zoomUpdated() ), SLOT( onZoomedSlot() ) );
|
||||
connect( m_zoomerLeft, SIGNAL( zoomed( const QRectF& ) ), SLOT( onZoomedSlot() ) );
|
||||
connect( m_zoomerRight, SIGNAL( zoomed( const QRectF& ) ), SLOT( onZoomedSlot() ) );
|
||||
connect( m_plotZoomer, SIGNAL( zoomed() ), SLOT( onZoomedSlot() ) );
|
||||
connect( panner, SIGNAL( panned( int, int ) ), SLOT( onZoomedSlot() ) );
|
||||
connect( this,
|
||||
SIGNAL( plotItemSelected( std::shared_ptr<RiuPlotItem>, bool, int ) ),
|
||||
@@ -254,7 +247,7 @@ bool RiuGridCrossQwtPlot::curveText( const QwtPlotCurve* curve, QString* curveTi
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiuGridCrossQwtPlot::isZoomerActive() const
|
||||
{
|
||||
return m_zoomerLeft->isActiveAndValid() || m_zoomerRight->isActiveAndValid();
|
||||
return m_plotZoomer->isActiveAndValid();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -262,8 +255,7 @@ bool RiuGridCrossQwtPlot::isZoomerActive() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuGridCrossQwtPlot::endZoomOperations()
|
||||
{
|
||||
m_zoomerLeft->endZoomOperation();
|
||||
m_zoomerRight->endZoomOperation();
|
||||
m_plotZoomer->endZoomOperation();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -73,6 +73,5 @@ private:
|
||||
std::unique_ptr<RiuPlotAnnotationTool> m_annotationTool;
|
||||
QwtPlotMarker* m_selectedPointMarker;
|
||||
|
||||
QPointer<RiuQwtPlotZoomer> m_zoomerLeft;
|
||||
QPointer<RiuQwtPlotZoomer> m_zoomerRight;
|
||||
QPointer<RiuQwtPlotZoomer> m_plotZoomer;
|
||||
};
|
||||
|
||||
@@ -18,16 +18,17 @@
|
||||
#pragma once
|
||||
|
||||
#include "RiuGuiTheme.h"
|
||||
#include "RiuQwtPlotZoomerMultiAxes.h"
|
||||
|
||||
#include "qwt_plot_zoomer.h"
|
||||
|
||||
#include <QMouseEvent>
|
||||
|
||||
class RiuQwtPlotZoomer : public QwtPlotZoomer
|
||||
class RiuQwtPlotZoomer : public RiuQwtPlotZoomerMultiAxes
|
||||
{
|
||||
public:
|
||||
RiuQwtPlotZoomer( QWidget* canvas, bool doReplot = true )
|
||||
: QwtPlotZoomer( canvas, doReplot )
|
||||
: RiuQwtPlotZoomerMultiAxes( canvas, doReplot )
|
||||
{
|
||||
auto color = RiuGuiTheme::getColorByVariableName( "markerColor" );
|
||||
|
||||
@@ -46,8 +47,6 @@ public:
|
||||
void endZoomOperation() { reset(); }
|
||||
|
||||
protected:
|
||||
QSizeF minZoomSize() const override { return QwtPlotZoomer::minZoomSize() / 10.0e6; }
|
||||
|
||||
bool accept( QPolygon& pa ) const override
|
||||
{
|
||||
if ( pa.count() < 2 ) return false;
|
||||
@@ -59,6 +58,6 @@ protected:
|
||||
const int minSize = 10;
|
||||
if ( rect.width() < minSize && rect.height() < minSize ) return false;
|
||||
|
||||
return QwtPlotZoomer::accept( pa );
|
||||
return RiuQwtPlotZoomerMultiAxes::accept( pa );
|
||||
}
|
||||
};
|
||||
|
||||
110
ApplicationLibCode/UserInterface/RiuQwtPlotZoomerMultiAxes.cpp
Normal file
110
ApplicationLibCode/UserInterface/RiuQwtPlotZoomerMultiAxes.cpp
Normal file
@@ -0,0 +1,110 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2023- 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 "RiuQwtPlotZoomerMultiAxes.h"
|
||||
|
||||
#include "qwt_picker_machine.h"
|
||||
#include "qwt_plot.h"
|
||||
#include "qwt_scale_div.h"
|
||||
#include "qwt_scale_map.h"
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Create a zoomer for a plot canvas. All axes will be scaled based on the rectangle in screen coordinates.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiuQwtPlotZoomerMultiAxes::RiuQwtPlotZoomerMultiAxes( QWidget* canvas, bool doReplot )
|
||||
: QwtPlotPicker( canvas )
|
||||
{
|
||||
if ( canvas )
|
||||
{
|
||||
setTrackerMode( ActiveOnly );
|
||||
setRubberBand( RectRubberBand );
|
||||
setStateMachine( new QwtPickerDragRectMachine() );
|
||||
|
||||
if ( doReplot && plot() ) plot()->replot();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiuQwtPlotZoomerMultiAxes::end( bool ok )
|
||||
{
|
||||
ok = QwtPlotPicker::end( ok );
|
||||
if ( !ok ) return false;
|
||||
|
||||
QwtPlot* plot = RiuQwtPlotZoomerMultiAxes::plot();
|
||||
if ( !plot ) return false;
|
||||
|
||||
const QPolygon& pa = selection();
|
||||
if ( pa.count() < 2 ) return false;
|
||||
|
||||
QRect rect = QRect( pa.first(), pa.last() );
|
||||
rect = rect.normalized();
|
||||
|
||||
zoomFromScreenCoords( rect );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuQwtPlotZoomerMultiAxes::zoomFromScreenCoords( const QRectF& screenCoords )
|
||||
{
|
||||
QwtPlot* plot = RiuQwtPlotZoomerMultiAxes::plot();
|
||||
if ( !plot ) return;
|
||||
|
||||
const bool doReplot = plot->autoReplot();
|
||||
plot->setAutoReplot( false );
|
||||
|
||||
for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
|
||||
{
|
||||
const int axesCount = plot->axesCount( axisPos );
|
||||
for ( int i = 0; i < axesCount; i++ )
|
||||
{
|
||||
const QwtAxisId axisId( axisPos, i );
|
||||
|
||||
// Get the scale map for the axis used to convert between screen and domain coordinates
|
||||
const QwtScaleMap map = plot->canvasMap( axisId );
|
||||
|
||||
if ( axisId.isXAxis() )
|
||||
{
|
||||
const double screenX1 = screenCoords.left();
|
||||
const double screenX2 = screenCoords.right();
|
||||
const double domainX1 = map.invTransform( screenX1 );
|
||||
const double domainX2 = map.invTransform( screenX2 );
|
||||
|
||||
plot->setAxisScale( axisId, domainX1, domainX2 );
|
||||
}
|
||||
else
|
||||
{
|
||||
const double screenY1 = screenCoords.bottom();
|
||||
const double screenY2 = screenCoords.top();
|
||||
const double domainY1 = map.invTransform( screenY1 );
|
||||
const double domainY2 = map.invTransform( screenY2 );
|
||||
|
||||
plot->setAxisScale( axisId, domainY1, domainY2 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
plot->setAutoReplot( doReplot );
|
||||
plot->replot();
|
||||
|
||||
emit zoomed();
|
||||
}
|
||||
40
ApplicationLibCode/UserInterface/RiuQwtPlotZoomerMultiAxes.h
Normal file
40
ApplicationLibCode/UserInterface/RiuQwtPlotZoomerMultiAxes.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2023- 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.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "qwt_plot_picker.h"
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
class RiuQwtPlotZoomerMultiAxes : public QwtPlotPicker
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit RiuQwtPlotZoomerMultiAxes( QWidget*, bool doReplot = true );
|
||||
|
||||
Q_SIGNALS:
|
||||
void zoomed();
|
||||
|
||||
protected:
|
||||
bool end( bool ok = true ) override;
|
||||
|
||||
private:
|
||||
void zoomFromScreenCoords( const QRectF& screenCoords );
|
||||
};
|
||||
@@ -81,15 +81,9 @@ RiuSummaryQwtPlot::RiuSummaryQwtPlot( RimSummaryPlot* plot, QWidget* parent /*=
|
||||
connect( m_plotWidget, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( showContextMenu( QPoint ) ) );
|
||||
|
||||
// LeftButton for the zooming
|
||||
m_zoomerLeft = new RiuQwtPlotZoomer( m_plotWidget->qwtPlot()->canvas() );
|
||||
m_zoomerLeft->setTrackerMode( QwtPicker::AlwaysOff );
|
||||
m_zoomerLeft->initMousePattern( 1 );
|
||||
|
||||
// Attach a zoomer for the right axis
|
||||
m_zoomerRight = new RiuQwtPlotZoomer( m_plotWidget->qwtPlot()->canvas() );
|
||||
m_zoomerRight->setAxes( QwtAxis::XTop, QwtAxis::YRight );
|
||||
m_zoomerRight->setTrackerMode( QwtPicker::AlwaysOff );
|
||||
m_zoomerRight->initMousePattern( 1 );
|
||||
m_plotZoomer = new RiuQwtPlotZoomer( m_plotWidget->qwtPlot()->canvas() );
|
||||
m_plotZoomer->setTrackerMode( QwtPicker::AlwaysOff );
|
||||
m_plotZoomer->initMousePattern( 1 );
|
||||
|
||||
// MidButton for the panning
|
||||
QwtPlotPanner* panner = new QwtPlotPanner( m_plotWidget->qwtPlot()->canvas() );
|
||||
@@ -98,8 +92,7 @@ RiuSummaryQwtPlot::RiuSummaryQwtPlot( RimSummaryPlot* plot, QWidget* parent /*=
|
||||
m_wheelZoomer = new RiuQwtPlotWheelZoomer( m_plotWidget->qwtPlot() );
|
||||
|
||||
connect( m_wheelZoomer, SIGNAL( zoomUpdated() ), SLOT( onZoomedSlot() ) );
|
||||
connect( m_zoomerLeft, SIGNAL( zoomed( const QRectF& ) ), SLOT( onZoomedSlot() ) );
|
||||
connect( m_zoomerRight, SIGNAL( zoomed( const QRectF& ) ), SLOT( onZoomedSlot() ) );
|
||||
connect( m_plotZoomer, SIGNAL( zoomed() ), SLOT( onZoomedSlot() ) );
|
||||
connect( panner, SIGNAL( panned( int, int ) ), SLOT( onZoomedSlot() ) );
|
||||
|
||||
setDefaults();
|
||||
@@ -194,7 +187,7 @@ void RiuSummaryQwtPlot::setDefaults()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiuSummaryQwtPlot::isZoomerActive() const
|
||||
{
|
||||
return m_zoomerLeft->isActiveAndValid() || m_zoomerRight->isActiveAndValid();
|
||||
return m_plotZoomer->isActiveAndValid();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -202,8 +195,7 @@ bool RiuSummaryQwtPlot::isZoomerActive() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuSummaryQwtPlot::endZoomOperations()
|
||||
{
|
||||
m_zoomerLeft->endZoomOperation();
|
||||
m_zoomerRight->endZoomOperation();
|
||||
m_plotZoomer->endZoomOperation();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -71,7 +71,6 @@ private:
|
||||
std::unique_ptr<RiuPlotAnnotationTool> m_annotationTool;
|
||||
QPointer<RiuQwtPlotWidget> m_plotWidget;
|
||||
|
||||
QPointer<RiuQwtPlotZoomer> m_zoomerLeft;
|
||||
QPointer<RiuQwtPlotZoomer> m_zoomerRight;
|
||||
QPointer<RiuQwtPlotZoomer> m_plotZoomer;
|
||||
QPointer<RiuQwtPlotWheelZoomer> m_wheelZoomer;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user