From e199182e2f3faf652d11873cf660cc917b762305 Mon Sep 17 00:00:00 2001 From: Gaute Lindkvist Date: Wed, 4 Dec 2019 13:26:00 +0100 Subject: [PATCH] #5178 Fix axis rounding on plots other than Well Log Plots --- .../UserInterface/RiuQwtPlotWidget.cpp | 39 +------------------ .../UserInterface/RiuQwtPlotWidget.h | 3 -- .../UserInterface/RiuWellLogTrack.cpp | 31 +++++++++++++++ .../UserInterface/RiuWellLogTrack.h | 3 ++ 4 files changed, 35 insertions(+), 41 deletions(-) diff --git a/ApplicationCode/UserInterface/RiuQwtPlotWidget.cpp b/ApplicationCode/UserInterface/RiuQwtPlotWidget.cpp index 248d4c7386..d78f9b77aa 100644 --- a/ApplicationCode/UserInterface/RiuQwtPlotWidget.cpp +++ b/ApplicationCode/UserInterface/RiuQwtPlotWidget.cpp @@ -65,7 +65,7 @@ RiuQwtPlotWidget::RiuQwtPlotWidget( RimPlot* plot, QWidget* parent ) , m_plotDefinition( plot ) , m_draggable( true ) { - setDefaults(); + RiuQwtPlotTools::setCommonPlotBehaviour( this ); this->installEventFilter( this ); this->canvas()->installEventFilter( this ); @@ -161,34 +161,6 @@ RimPlot* RiuQwtPlotWidget::plotDefinition() const return m_plotDefinition; } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RiuQwtPlotWidget::setEnabledAxes( const std::set enabledAxes ) -{ - for ( int axisId = 0; axisId < QwtPlot::axisCnt; ++axisId ) - { - QwtPlot::Axis axis = static_cast( axisId ); - if ( enabledAxes.count( axis ) ) - { - enableAxis( axis, true ); - // Align the canvas with the actual min and max values of the curves - axisScaleEngine( axis )->setAttribute( QwtScaleEngine::Floating, true ); - setAxisScale( axis, 0.0, 100.0 ); - axisScaleDraw( axis )->setMinimumExtent( axisExtent( axis ) ); - setMinimumWidth( defaultMinimumWidth() ); - - axisWidget( axis )->setMargin( 0 ); - m_axisTitlesEnabled[axis] = true; - } - else - { - enableAxis( axis, false ); - m_axisTitlesEnabled[axis] = false; - } - } -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -704,15 +676,6 @@ void RiuQwtPlotWidget::updateOverlayFrameLayout() } } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RiuQwtPlotWidget::setDefaults() -{ - setEnabledAxes( {QwtPlot::xTop, QwtPlot::yLeft} ); - RiuQwtPlotTools::setCommonPlotBehaviour( this ); -} - void RiuQwtPlotWidget::selectPlotOwner( bool toggleItemInSelection ) { if ( toggleItemInSelection ) diff --git a/ApplicationCode/UserInterface/RiuQwtPlotWidget.h b/ApplicationCode/UserInterface/RiuQwtPlotWidget.h index b6e14ec6e3..55b246a549 100644 --- a/ApplicationCode/UserInterface/RiuQwtPlotWidget.h +++ b/ApplicationCode/UserInterface/RiuQwtPlotWidget.h @@ -70,8 +70,6 @@ public: bool titleBold = false, Qt::AlignmentFlag alignment = Qt::AlignRight ); - void setEnabledAxes( const std::set enabledAxes ); - void setAxisTitleText( QwtPlot::Axis axis, const QString& title ); void setAxisTitleEnabled( QwtPlot::Axis axis, bool enable ); @@ -119,7 +117,6 @@ protected: virtual void endZoomOperations(); private: - void setDefaults(); void selectPlotOwner( bool toggleItemInSelection = false ); void selectClosestCurve( const QPoint& pos, bool toggleItemInSelection = false ); static int defaultMinimumWidth(); diff --git a/ApplicationCode/UserInterface/RiuWellLogTrack.cpp b/ApplicationCode/UserInterface/RiuWellLogTrack.cpp index fc7e074b42..e3a051d3b6 100644 --- a/ApplicationCode/UserInterface/RiuWellLogTrack.cpp +++ b/ApplicationCode/UserInterface/RiuWellLogTrack.cpp @@ -21,6 +21,10 @@ #include "RimWellLogTrack.h" +#include "qwt_scale_draw.h" +#include "qwt_scale_engine.h" +#include "qwt_scale_widget.h" + #include #define RIU_SCROLLWHEEL_ZOOMFACTOR 1.1 @@ -32,6 +36,10 @@ RiuWellLogTrack::RiuWellLogTrack( RimWellLogTrack* plotTrackDefinition, QWidget* parent /*= nullptr */ ) : RiuQwtPlotWidget( plotTrackDefinition, parent ) { + setAxisEnabled( QwtPlot::yLeft, true ); + setAxisEnabled( QwtPlot::yRight, false ); + setAxisEnabled( QwtPlot::xTop, true ); + setAxisEnabled( QwtPlot::xBottom, false ); } //-------------------------------------------------------------------------------------------------- @@ -81,3 +89,26 @@ bool RiuWellLogTrack::eventFilter( QObject* watched, QEvent* event ) } return RiuQwtPlotWidget::eventFilter( watched, event ); } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuWellLogTrack::setAxisEnabled( QwtPlot::Axis axis, bool enabled ) +{ + if ( enabled ) + { + enableAxis( axis, true ); + + // Align the canvas with the actual min and max values of the curves + axisScaleEngine( axis )->setAttribute( QwtScaleEngine::Floating, true ); + setAxisScale( axis, 0.0, 100.0 ); + axisScaleDraw( axis )->setMinimumExtent( axisExtent( axis ) ); + + axisWidget( axis )->setMargin( 0 ); + setAxisTitleEnabled( axis, true ); + } + else + { + enableAxis( axis, false ); + } +} diff --git a/ApplicationCode/UserInterface/RiuWellLogTrack.h b/ApplicationCode/UserInterface/RiuWellLogTrack.h index 7915ae2632..03bc7a975a 100644 --- a/ApplicationCode/UserInterface/RiuWellLogTrack.h +++ b/ApplicationCode/UserInterface/RiuWellLogTrack.h @@ -37,4 +37,7 @@ public: protected: bool eventFilter( QObject* watched, QEvent* event ) override; + +private: + void setAxisEnabled( QwtPlot::Axis axis, bool enabled ); };