RiuQwtPlotWidget: fix actions on selection of axis.

This commit is contained in:
Kristian Bendiksen 2022-04-01 15:57:11 +02:00
parent 7cb72688ea
commit 11060078d8
14 changed files with 47 additions and 53 deletions

View File

@ -905,12 +905,12 @@ void RimAnalysisPlot::updateAxes()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimAnalysisPlot::onAxisSelected( int axis, bool toggle )
void RimAnalysisPlot::onAxisSelected( RiuPlotAxis axis, bool toggle )
{
RiuPlotMainWindowTools::showPlotMainWindow();
caf::PdmObject* itemToSelect = nullptr;
if ( axis == QwtAxis::YLeft )
if ( axis.axis() == RiaDefines::PlotAxis::PLOT_AXIS_LEFT )
{
if ( m_barOrientation == BARS_VERTICAL )
{
@ -921,7 +921,7 @@ void RimAnalysisPlot::onAxisSelected( int axis, bool toggle )
itemToSelect = this;
}
}
else if ( axis == QwtAxis::XBottom )
else if ( axis.axis() == RiaDefines::PlotAxis::PLOT_AXIS_BOTTOM )
{
if ( m_barOrientation == BARS_HORIZONTAL )
{

View File

@ -135,7 +135,7 @@ private:
void reattachAllCurves() override {}
void updateAxes() override;
void onAxisSelected( int axis, bool toggle ) override;
void onAxisSelected( RiuPlotAxis axis, bool toggle ) override;
void setAutoScaleXEnabled( bool enabled ) override {}
void setAutoScaleYEnabled( bool enabled ) override {}
void updateLegend() override{};

View File

@ -231,7 +231,7 @@ caf::PdmObject* RimWellDistributionPlot::findPdmObjectFromPlotCurve( const RiuPl
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellDistributionPlot::onAxisSelected( int /*axis*/, bool /*toggle*/ )
void RimWellDistributionPlot::onAxisSelected( RiuPlotAxis /*axis*/, bool /*toggle*/ )
{
// cvf::Trace::show("RimWellDistributionPlot::onAxisSelected()");
}

View File

@ -60,7 +60,7 @@ public:
void reattachAllCurves() override;
void detachAllCurves() override;
caf::PdmObject* findPdmObjectFromPlotCurve( const RiuPlotCurve* curve ) const override;
void onAxisSelected( int axis, bool toggle ) override;
void onAxisSelected( RiuPlotAxis axis, bool toggle ) override;
// RimPlotWindow implementations
QString description() const override;

View File

@ -372,15 +372,15 @@ caf::PdmObject* RimGridCrossPlot::findPdmObjectFromPlotCurve( const RiuPlotCurve
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimGridCrossPlot::onAxisSelected( int axis, bool toggle )
void RimGridCrossPlot::onAxisSelected( RiuPlotAxis axis, bool toggle )
{
RiuPlotMainWindowTools::showPlotMainWindow();
RimPlotAxisProperties* properties = nullptr;
if ( axis == QwtAxis::YLeft )
if ( axis.axis() == RiaDefines::PlotAxis::PLOT_AXIS_LEFT )
{
properties = m_yAxisProperties;
}
else if ( axis == QwtAxis::XBottom )
else if ( axis.axis() == RiaDefines::PlotAxis::PLOT_AXIS_BOTTOM )
{
properties = m_xAxisProperties;
}

View File

@ -105,7 +105,7 @@ public:
void setAutoScaleXEnabled( bool enabled ) override;
void setAutoScaleYEnabled( bool enabled ) override;
caf::PdmObject* findPdmObjectFromPlotCurve( const RiuPlotCurve* curve ) const override;
void onAxisSelected( int axis, bool toggle ) override;
void onAxisSelected( RiuPlotAxis axis, bool toggle ) override;
bool isDeletable() const override;

View File

@ -320,6 +320,6 @@ void RimPlot::onPlotItemSelected( std::shared_ptr<RiuPlotItem>, bool, int )
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlot::onAxisSelected( int axis, bool toggle )
void RimPlot::onAxisSelected( RiuPlotAxis axis, bool toggle )
{
}

View File

@ -22,6 +22,8 @@
#include "RimPlotWindow.h"
#include "RiuPlotAxis.h"
#include "cafAppEnum.h"
#include "cafPdmChildArrayField.h"
#include "cafPdmField.h"
@ -119,7 +121,7 @@ protected:
virtual void handleWheelEvent( QWheelEvent* event );
private slots:
virtual void onAxisSelected( int axis, bool toggle );
virtual void onAxisSelected( RiuPlotAxis axis, bool toggle );
virtual void onPlotItemSelected( std::shared_ptr<RiuPlotItem> selectedItem, bool toggleItem, int sampleIndex );
void onPlotSelected( bool toggle );
void onViewerDestroyed();

View File

@ -377,30 +377,11 @@ caf::PdmObject* RimSummaryPlot::findPdmObjectFromPlotCurve( const RiuPlotCurve*
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSummaryPlot::onAxisSelected( int axis, bool toggle )
void RimSummaryPlot::onAxisSelected( RiuPlotAxis axis, bool toggle )
{
RiuPlotMainWindowTools::showPlotMainWindow();
caf::PdmObject* itemToSelect = nullptr;
if ( axis == QwtAxis::YLeft )
{
itemToSelect = m_leftYAxisProperties_OBSOLETE;
}
else if ( axis == QwtAxis::YRight )
{
itemToSelect = m_rightYAxisProperties_OBSOLETE;
}
else if ( axis == QwtAxis::XBottom )
{
if ( m_isCrossPlot )
{
itemToSelect = m_bottomAxisProperties_OBSOLETE;
}
else
{
itemToSelect = m_timeAxisProperties_OBSOLETE;
}
}
caf::PdmObject* itemToSelect = axisPropertiesForPlotAxis( axis );
if ( toggle )
{

View File

@ -178,7 +178,7 @@ public:
caf::PdmObject* findPdmObjectFromPlotCurve( const RiuPlotCurve* curve ) const override;
void onAxisSelected( int axis, bool toggle ) override;
void onAxisSelected( RiuPlotAxis axis, bool toggle ) override;
static constexpr int precision()
{

View File

@ -1043,7 +1043,7 @@ void RimWellLogTrack::updateZoomFromParentPlot()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellLogTrack::onAxisSelected( int axis, bool toggle )
void RimWellLogTrack::onAxisSelected( RiuPlotAxis axis, bool toggle )
{
if ( toggle )
{

View File

@ -210,7 +210,7 @@ public:
QString asciiDataForPlotExport() const override;
void onAxisSelected( int axis, bool toggle ) override;
void onAxisSelected( RiuPlotAxis axis, bool toggle ) override;
void onChildDeleted( caf::PdmChildArrayFieldHandle* childArray,
std::vector<caf::PdmObjectHandle*>& referringObjects ) override;

View File

@ -95,7 +95,7 @@ RiuQwtPlotWidget::RiuQwtPlotWidget( RimPlot* plotDefinition, QWidget* parent )
setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
connect( this, SIGNAL( plotSelected( bool ) ), plotDefinition, SLOT( onPlotSelected( bool ) ) );
connect( this, SIGNAL( axisSelected( int, bool ) ), plotDefinition, SLOT( onAxisSelected( int, bool ) ) );
connect( this, SIGNAL( axisSelected( RiuPlotAxis, bool ) ), plotDefinition, SLOT( onAxisSelected( RiuPlotAxis, bool ) ) );
connect( this,
SIGNAL( plotItemSelected( std::shared_ptr<RiuPlotItem>, bool, int ) ),
plotDefinition,
@ -562,9 +562,9 @@ bool RiuQwtPlotWidget::eventFilter( QObject* watched, QEvent* event )
m_clickPosition = mouseEvent->pos();
}
if ( watched == this && !m_plot->canvas()->geometry().contains( mouseEvent->pos() ) )
if ( watched == m_plot && !m_plot->canvas()->geometry().contains( mouseEvent->pos() ) )
{
if ( mouseEvent->type() == QMouseEvent::MouseButtonRelease && ( mouseEvent->button() == Qt::LeftButton ) &&
if ( mouseEvent->type() == QMouseEvent::MouseButtonPress && ( mouseEvent->button() == Qt::LeftButton ) &&
!m_clickPosition.isNull() )
{
QWidget* childClicked = m_plot->childAt( m_clickPosition );
@ -784,15 +784,20 @@ RimViewWindow* RiuQwtPlotWidget::ownerViewWindow() const
//--------------------------------------------------------------------------------------------------
void RiuQwtPlotWidget::onAxisSelected( QwtScaleWidget* scale, bool toggleItemInSelection )
{
int axisId = -1;
for ( int i = 0; i < QwtAxis::AxisPositions; ++i )
{
if ( scale == m_plot->axisWidget( i ) )
QwtAxis::Position pos = static_cast<QwtAxis::Position>( i );
int count = m_plot->axesCount( pos );
for ( int id = 0; id < count; id++ )
{
axisId = i;
QwtAxisId axisId( pos, id );
if ( scale == m_plot->axisWidget( axisId ) )
{
emit axisSelected( findPlotAxisForQwtAxis( axisId ), toggleItemInSelection );
return;
}
}
}
emit axisSelected( axisId, toggleItemInSelection );
}
//--------------------------------------------------------------------------------------------------
@ -1247,6 +1252,18 @@ void RiuQwtPlotWidget::pruneAxes( const std::set<RiuPlotAxis>& usedAxes )
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuPlotAxis RiuQwtPlotWidget::findPlotAxisForQwtAxis( const QwtAxisId& qwtAxisId ) const
{
for ( auto [plotAxis, qwtMapping] : m_axisMapping )
if ( qwtMapping == qwtAxisId ) return plotAxis;
CAF_ASSERT( false );
return RiuPlotAxis::defaultLeft();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -1261,20 +1278,12 @@ void RiuQwtPlotWidget::moveAxis( RiuPlotAxis oldAxis, RiuPlotAxis newAxis )
return count;
};
auto findPlotAxisForQwtAxis = [this]( const QwtAxisId& qwtAxisId ) {
for ( auto [plotAxis, qwtMapping] : m_axisMapping )
if ( qwtMapping == qwtAxisId ) return plotAxis;
CAF_ASSERT( false );
return RiuPlotAxis::defaultLeft();
};
auto isLastItem = [this]( RiuPlotAxis plotAxis, int count ) {
auto qwtAxis = toQwtPlotAxis( plotAxis );
return qwtAxis.id == ( count - 1 );
};
auto removeAxis = [this, countAxis, isLastItem, findPlotAxisForQwtAxis]( RiuPlotAxis plotAxis ) {
auto removeAxis = [this, countAxis, isLastItem]( RiuPlotAxis plotAxis ) {
auto qwtAxisPos = RiuQwtPlotTools::toQwtPlotAxisEnum( plotAxis.axis() );
int count = countAxis( plotAxis.axis() );

View File

@ -175,7 +175,7 @@ public:
signals:
void plotSelected( bool toggleSelection );
void axisSelected( int axisId, bool toggleSelection );
void axisSelected( RiuPlotAxis axisId, bool toggleSelection );
void plotItemSelected( std::shared_ptr<RiuPlotItem> plotItem, bool toggleSelection, int sampleIndex );
void onKeyPressEvent( QKeyEvent* event );
void onWheelEvent( QWheelEvent* event );
@ -200,6 +200,8 @@ protected:
void setAxisScaleType( QwtAxisId axis, RiuQwtPlotWidget::AxisScaleType axisScaleType );
void setAxisScale( QwtAxisId axis, double min, double max );
RiuPlotAxis findPlotAxisForQwtAxis( const QwtAxisId& qwtAxisId ) const;
private:
void selectClosestPlotItem( const QPoint& pos, bool toggleItemInSelection = false );
static int defaultMinimumWidth();