mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-26 07:00:17 -05:00
Refactors tracker text implementation
Simplifies the implementation of the tracker text provider by using a `std::function` instead of a dedicated interface. This change improves code maintainability and reduces complexity.
This commit is contained in:
1 parent
9923f0ed1b
commit
b0b2c56267
2 files changed
+8
-22
No files matched your search
@@ -43,6 +43,8 @@
|
||||
|
||||
#include <QHBoxLayout>
|
||||
|
||||
#include <functional>
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
@@ -67,22 +69,22 @@ public:
|
||||
class RiuPvtQwtPicker : public QwtPicker
|
||||
{
|
||||
public:
|
||||
RiuPvtQwtPicker( QwtPlot* plot, RiuPvtTrackerTextProvider* trackerTextProvider )
|
||||
RiuPvtQwtPicker( QwtPlot* plot, std::function<QString()> textProvider )
|
||||
: QwtPicker( QwtPicker::NoRubberBand, QwtPicker::AlwaysOn, plot->canvas() )
|
||||
, m_trackerTextProvider( trackerTextProvider )
|
||||
, m_textProvider( textProvider )
|
||||
{
|
||||
setStateMachine( new QwtPickerTrackerMachine );
|
||||
}
|
||||
|
||||
QwtText trackerText( const QPoint& ) const override
|
||||
{
|
||||
QwtText text( m_trackerTextProvider->trackerText() );
|
||||
QwtText text( m_textProvider() );
|
||||
text.setRenderFlags( Qt::AlignLeft );
|
||||
return text;
|
||||
}
|
||||
|
||||
private:
|
||||
const RiuPvtTrackerTextProvider* m_trackerTextProvider;
|
||||
std::function<QString()> m_textProvider;
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
@@ -112,7 +114,7 @@ RiuPvtPlotWidget::RiuPvtPlotWidget( RiuPvtPlotPanel* parent )
|
||||
|
||||
setLayout( layout );
|
||||
|
||||
m_qwtPicker = new RiuPvtQwtPicker( m_qwtPlot, this );
|
||||
m_qwtPicker = new RiuPvtQwtPicker( m_qwtPlot, [this]() { return m_trackerLabel; } );
|
||||
RiuGuiTheme::styleQwtItem( m_qwtPicker );
|
||||
connect( m_qwtPicker, SIGNAL( activated( bool ) ), this, SLOT( slotPickerActivated( bool ) ) );
|
||||
connect( m_qwtPicker, SIGNAL( moved( const QPoint& ) ), this, SLOT( slotPickerPointChanged( const QPoint& ) ) );
|
||||
@@ -472,14 +474,6 @@ size_t RiuPvtPlotWidget::indexOfQwtCurve( const QwtPlotCurve* qwtCurve ) const
|
||||
return cvf::UNDEFINED_SIZE_T;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Implements the RiuPvtTrackerTextProvider interface
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiuPvtPlotWidget::trackerText() const
|
||||
{
|
||||
return m_trackerLabel;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -39,19 +39,12 @@ class QwtPlot;
|
||||
class QwtPlotMarker;
|
||||
class QwtPlotCurve;
|
||||
|
||||
// Interface for providing our custom picker with a tracker text
|
||||
class RiuPvtTrackerTextProvider
|
||||
{
|
||||
public:
|
||||
virtual QString trackerText() const = 0;
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class RiuPvtPlotWidget : public QWidget, public RiuPvtTrackerTextProvider
|
||||
class RiuPvtPlotWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -72,7 +65,6 @@ private:
|
||||
const QwtPlotCurve* closestCurveSample( const QPoint& cursorPosition, int* closestSampleIndex ) const;
|
||||
size_t indexOfQwtCurve( const QwtPlotCurve* qwtCurve ) const;
|
||||
void updateTrackerPlotMarkerAndLabelFromPicker();
|
||||
QString trackerText() const override;
|
||||
|
||||
private slots:
|
||||
void slotPickerActivated( bool );
|
||||
|
||||
Reference in new issue
Block a user