From c00aea75fb89586dc0d0a69dc77f3a8854bbf144 Mon Sep 17 00:00:00 2001 From: Kristian Bendiksen Date: Fri, 11 Mar 2022 16:02:30 +0100 Subject: [PATCH] #8662 QtCharts: Implement tooltip when hovering over curves --- .../Summary/CMakeLists_files.cmake | 2 + .../RimEnsembleCurveInfoTextProvider.cpp | 39 ++++++ .../RimEnsembleCurveInfoTextProvider.h | 32 +++++ .../UserInterface/CMakeLists_files.cmake | 2 + .../RiuPlotCurveInfoTextProvider.h | 33 ++++++ .../UserInterface/RiuQtChartsPlotWidget.cpp | 61 +++++++++- .../UserInterface/RiuQtChartsPlotWidget.h | 14 ++- .../UserInterface/RiuQtChartsToolTip.cpp | 112 ++++++++++++++++++ .../UserInterface/RiuQtChartsToolTip.h | 48 ++++++++ .../UserInterface/RiuQwtCurvePointTracker.cpp | 15 +-- .../UserInterface/RiuQwtCurvePointTracker.h | 25 ++-- .../UserInterface/RiuSummaryQtChartsPlot.cpp | 4 +- .../UserInterface/RiuSummaryQwtPlot.cpp | 24 +--- .../UserInterface/RiuWellLogTrack.cpp | 10 +- 14 files changed, 365 insertions(+), 56 deletions(-) create mode 100644 ApplicationLibCode/ProjectDataModel/Summary/RimEnsembleCurveInfoTextProvider.cpp create mode 100644 ApplicationLibCode/ProjectDataModel/Summary/RimEnsembleCurveInfoTextProvider.h create mode 100644 ApplicationLibCode/UserInterface/RiuPlotCurveInfoTextProvider.h create mode 100644 ApplicationLibCode/UserInterface/RiuQtChartsToolTip.cpp create mode 100644 ApplicationLibCode/UserInterface/RiuQtChartsToolTip.h diff --git a/ApplicationLibCode/ProjectDataModel/Summary/CMakeLists_files.cmake b/ApplicationLibCode/ProjectDataModel/Summary/CMakeLists_files.cmake index e96af9970f..c5b777c780 100644 --- a/ApplicationLibCode/ProjectDataModel/Summary/CMakeLists_files.cmake +++ b/ApplicationLibCode/ProjectDataModel/Summary/CMakeLists_files.cmake @@ -45,6 +45,7 @@ set(SOURCE_GROUP_HEADER_FILES ${CMAKE_CURRENT_LIST_DIR}/RimSummaryAddressCollection.h ${CMAKE_CURRENT_LIST_DIR}/RimSummaryMultiPlotCollection.h ${CMAKE_CURRENT_LIST_DIR}/RimSummaryPlotControls.h + ${CMAKE_CURRENT_LIST_DIR}/RimEnsembleCurveInfoTextProvider.h ) set(SOURCE_GROUP_SOURCE_FILES @@ -94,6 +95,7 @@ set(SOURCE_GROUP_SOURCE_FILES ${CMAKE_CURRENT_LIST_DIR}/RimSummaryAddressCollection.cpp ${CMAKE_CURRENT_LIST_DIR}/RimSummaryMultiPlotCollection.cpp ${CMAKE_CURRENT_LIST_DIR}/RimSummaryPlotControls.cpp + ${CMAKE_CURRENT_LIST_DIR}/RimEnsembleCurveInfoTextProvider.cpp ) list(APPEND CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES}) diff --git a/ApplicationLibCode/ProjectDataModel/Summary/RimEnsembleCurveInfoTextProvider.cpp b/ApplicationLibCode/ProjectDataModel/Summary/RimEnsembleCurveInfoTextProvider.cpp new file mode 100644 index 0000000000..f023f4835b --- /dev/null +++ b/ApplicationLibCode/ProjectDataModel/Summary/RimEnsembleCurveInfoTextProvider.cpp @@ -0,0 +1,39 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2022 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RimEnsembleCurveInfoTextProvider.h" + +#include "RimSummaryCase.h" +#include "RimSummaryCurve.h" + +#include "RiuPlotCurve.h" + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RimEnsembleCurveInfoTextProvider::curveInfoText( RiuPlotCurve* riuCurve ) const +{ + // RiuPlotCurve* riuCurve = dynamic_cast( curve ); + RimSummaryCurve* sumCurve = nullptr; + if ( riuCurve ) + { + sumCurve = dynamic_cast( riuCurve->ownerRimCurve() ); + } + + return sumCurve && sumCurve->summaryCaseY() ? sumCurve->summaryCaseY()->displayCaseName() : ""; +} diff --git a/ApplicationLibCode/ProjectDataModel/Summary/RimEnsembleCurveInfoTextProvider.h b/ApplicationLibCode/ProjectDataModel/Summary/RimEnsembleCurveInfoTextProvider.h new file mode 100644 index 0000000000..12ce1ab84d --- /dev/null +++ b/ApplicationLibCode/ProjectDataModel/Summary/RimEnsembleCurveInfoTextProvider.h @@ -0,0 +1,32 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2022 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "RiuPlotCurveInfoTextProvider.h" + +#include + +//================================================================================================== +// +//================================================================================================== +class RimEnsembleCurveInfoTextProvider : public RiuPlotCurveInfoTextProvider +{ +public: + QString curveInfoText( RiuPlotCurve* ) const override; +}; diff --git a/ApplicationLibCode/UserInterface/CMakeLists_files.cmake b/ApplicationLibCode/UserInterface/CMakeLists_files.cmake index fb2833eeda..891d30170a 100644 --- a/ApplicationLibCode/UserInterface/CMakeLists_files.cmake +++ b/ApplicationLibCode/UserInterface/CMakeLists_files.cmake @@ -214,6 +214,7 @@ if(RESINSIGHT_USE_QT_CHARTS) ${CMAKE_CURRENT_LIST_DIR}/RiuQtChartsPlotWidget.h ${CMAKE_CURRENT_LIST_DIR}/RiuQtChartsPlotTools.h ${CMAKE_CURRENT_LIST_DIR}/RiuQtChartsPlotCurveSymbol.h + ${CMAKE_CURRENT_LIST_DIR}/RiuQtChartsToolTip.h ${CMAKE_CURRENT_LIST_DIR}/RiuSummaryQtChartsPlot.h ) @@ -225,6 +226,7 @@ if(RESINSIGHT_USE_QT_CHARTS) ${CMAKE_CURRENT_LIST_DIR}/RiuQtChartsPlotWidget.cpp ${CMAKE_CURRENT_LIST_DIR}/RiuQtChartsPlotTools.cpp ${CMAKE_CURRENT_LIST_DIR}/RiuQtChartsPlotCurveSymbol.cpp + ${CMAKE_CURRENT_LIST_DIR}/RiuQtChartsToolTip.cpp ${CMAKE_CURRENT_LIST_DIR}/RiuSummaryQtChartsPlot.cpp ) diff --git a/ApplicationLibCode/UserInterface/RiuPlotCurveInfoTextProvider.h b/ApplicationLibCode/UserInterface/RiuPlotCurveInfoTextProvider.h new file mode 100644 index 0000000000..70fe084dc9 --- /dev/null +++ b/ApplicationLibCode/UserInterface/RiuPlotCurveInfoTextProvider.h @@ -0,0 +1,33 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2015- Equinor ASA +// Copyright (C) 2015- Ceetron Solutions AS +// +// 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include + +class RiuPlotCurve; + +//-------------------------------------------------------------------------------------------------- +/// Interface for retrieving curve info text +//-------------------------------------------------------------------------------------------------- +class RiuPlotCurveInfoTextProvider +{ +public: + virtual QString curveInfoText( RiuPlotCurve* curve ) const = 0; +}; diff --git a/ApplicationLibCode/UserInterface/RiuQtChartsPlotWidget.cpp b/ApplicationLibCode/UserInterface/RiuQtChartsPlotWidget.cpp index bcc535f08f..9ed59149bb 100644 --- a/ApplicationLibCode/UserInterface/RiuQtChartsPlotWidget.cpp +++ b/ApplicationLibCode/UserInterface/RiuQtChartsPlotWidget.cpp @@ -27,10 +27,12 @@ #include "RiuDraggableOverlayFrame.h" #include "RiuGuiTheme.h" +#include "RiuPlotCurveInfoTextProvider.h" #include "RiuPlotMainWindowTools.h" #include "RiuPlotWidget.h" #include "RiuQtChartView.h" #include "RiuQtChartsPlotCurve.h" +#include "RiuQtChartsToolTip.h" #include "RiuQwtDateScaleWrapper.h" #include "caf.h" @@ -52,9 +54,13 @@ using namespace QtCharts; //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -RiuQtChartsPlotWidget::RiuQtChartsPlotWidget( RimPlot* plotDefinition, QWidget* parent ) +RiuQtChartsPlotWidget::RiuQtChartsPlotWidget( RimPlot* plotDefinition, + QWidget* parent, + RiuPlotCurveInfoTextProvider* plotCurveNameProvider ) : RiuPlotWidget( plotDefinition, parent ) + , m_plotCurveNameProvider( plotCurveNameProvider ) , m_dateScaleWrapper( new RiuQwtDateScaleWrapper() ) + , m_toolTip( nullptr ) { CAF_ASSERT( m_plotDefinition ); @@ -853,6 +859,8 @@ void RiuQtChartsPlotWidget::attach( RiuPlotCurve* plotCurve, addToChart( m_lineSeriesMap, plotCurve, lineSeries, xAxis, yAxis, qtChartsPlotCurve ); addToChart( m_areaSeriesMap, plotCurve, areaSeries, xAxis, yAxis, qtChartsPlotCurve ); addToChart( m_scatterSeriesMap, plotCurve, scatterSeries, xAxis, yAxis, qtChartsPlotCurve ); + + connect( dynamic_cast( lineSeries ), &QLineSeries::hovered, this, &RiuQtChartsPlotWidget::tooltip ); } //-------------------------------------------------------------------------------------------------- @@ -1234,3 +1242,54 @@ void RiuQtChartsPlotWidget::pruneAxes( const std::set& usedAxes ) } } } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuQtChartsPlotWidget::tooltip( const QPointF& point, bool state ) +{ + QAbstractSeries* series = qobject_cast( sender() ); + if ( !m_toolTip ) m_toolTip = new RiuQtChartsToolTip( qtChart(), series ); + + if ( state ) + { + QString nameFromSeries = createNameFromSeries( series ); + + QDateTime date = QDateTime::fromMSecsSinceEpoch( point.x() ); + QString dateString = RiaQDateTimeTools::toStringUsingApplicationLocale( date, "hh:mm dd.MMMM.yyyy" ); + + QString text = QString( "%1 (%2)" ).arg( point.y() ).arg( dateString ); + + if ( !nameFromSeries.isEmpty() ) text.prepend( nameFromSeries + ": " ); + + m_toolTip->setText( text ); + + m_toolTip->setAnchor( point ); + m_toolTip->setSeries( series ); + m_toolTip->setZValue( 200 ); + m_toolTip->updateGeometry(); + m_toolTip->show(); + } + else + { + m_toolTip->hide(); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RiuQtChartsPlotWidget::createNameFromSeries( QAbstractSeries* series ) const +{ + if ( !m_plotCurveNameProvider ) return ""; + + for ( auto [plotCurve, plotSeries] : m_lineSeriesMap ) + { + if ( plotSeries == series ) + { + return m_plotCurveNameProvider->curveInfoText( plotCurve ); + } + } + + return ""; +} diff --git a/ApplicationLibCode/UserInterface/RiuQtChartsPlotWidget.h b/ApplicationLibCode/UserInterface/RiuQtChartsPlotWidget.h index c67ee6f70d..bb593885bd 100644 --- a/ApplicationLibCode/UserInterface/RiuQtChartsPlotWidget.h +++ b/ApplicationLibCode/UserInterface/RiuQtChartsPlotWidget.h @@ -36,6 +36,9 @@ class RiaPlotWindowRedrawScheduler; class RimPlot; class RiuPlotCurve; class RiuQtChartsPlotCurve; +class RiuQtChartsToolTip; +class RiuPlotCurveSymbol; +class RiuPlotCurveInfoTextProvider; class QEvent; class QLabel; @@ -64,7 +67,9 @@ class RiuQtChartsPlotWidget : public RiuPlotWidget Q_OBJECT public: - RiuQtChartsPlotWidget( RimPlot* plotDefinition, QWidget* parent = nullptr ); + RiuQtChartsPlotWidget( RimPlot* plotDefinition, + QWidget* parent = nullptr, + RiuPlotCurveInfoTextProvider* plotCurveNameProvider = nullptr ); ~RiuQtChartsPlotWidget() override; int axisTitleFontSize( RiuPlotAxis axis ) const override; @@ -217,6 +222,7 @@ signals: private slots: void axisRangeChanged(); + void tooltip( const QPointF& point, bool state ); private: void addAxis( RiuPlotAxis plotAxis, bool isEnabled, bool isAutoScale ); @@ -229,6 +235,8 @@ private: QtCharts::QCategoryAxis* categoryAxis(); + QString createNameFromSeries( QtCharts::QAbstractSeries* series ) const; + private: QPointer m_viewer; @@ -240,5 +248,7 @@ private: std::map m_areaSeriesMap; std::map m_scatterSeriesMap; - RiuQwtDateScaleWrapper* m_dateScaleWrapper; + RiuQwtDateScaleWrapper* m_dateScaleWrapper; + RiuQtChartsToolTip* m_toolTip; + RiuPlotCurveInfoTextProvider* m_plotCurveNameProvider; }; diff --git a/ApplicationLibCode/UserInterface/RiuQtChartsToolTip.cpp b/ApplicationLibCode/UserInterface/RiuQtChartsToolTip.cpp new file mode 100644 index 0000000000..151f9a8f31 --- /dev/null +++ b/ApplicationLibCode/UserInterface/RiuQtChartsToolTip.cpp @@ -0,0 +1,112 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2022- 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RiuQtChartsToolTip.h" + +#include +#include +#include +#include +#include + +using namespace QtCharts; + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RiuQtChartsToolTip::RiuQtChartsToolTip( QChart* chart, QtCharts::QAbstractSeries* series ) + : QGraphicsItem( chart ) + , m_chart( chart ) + , m_series( series ) + , m_radius( 10 ) +{ +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QRectF RiuQtChartsToolTip::boundingRect() const +{ + QPointF anchor = mapFromParent( m_chart->mapToPosition( m_anchor, m_series ) ); + QRectF rect = m_rect.united( m_textRect ); + rect.setLeft( std::min( rect.left(), anchor.x() ) ); + rect.setRight( std::max( rect.right(), anchor.x() ) ); + rect.setTop( std::min( rect.top(), anchor.y() ) ); + rect.setBottom( std::max( rect.bottom(), anchor.y() ) ); + return rect; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuQtChartsToolTip::paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget ) +{ + Q_UNUSED( option ) + Q_UNUSED( widget ) + QPainterPath path; + + QPointF anchor = mapFromParent( m_chart->mapToPosition( m_anchor, m_series ) ); + + path.addEllipse( anchor, m_radius, m_radius ); + path = path.simplified(); + + painter->setPen( QPen( Qt::black ) ); + + painter->drawPath( path ); + painter->drawText( m_textRect, m_text ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuQtChartsToolTip::setSeries( QAbstractSeries* series ) +{ + m_series = series; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuQtChartsToolTip::setText( const QString& text ) +{ + m_text = text; + QFontMetrics metrics( m_font ); + m_textRect = metrics.boundingRect( QRect( 0, 0, 150, 150 ), Qt::AlignLeft, m_text ); + m_textRect.translate( m_radius, 0 ); + prepareGeometryChange(); + + m_rect.setRect( -m_radius, -m_radius, m_radius, m_radius ); + m_rect.moveCenter( QPoint( m_radius, m_radius ) ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuQtChartsToolTip::setAnchor( QPointF point ) +{ + m_anchor = point; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuQtChartsToolTip::updateGeometry() +{ + prepareGeometryChange(); + setPos( m_chart->mapToPosition( m_anchor, m_series ) ); +} diff --git a/ApplicationLibCode/UserInterface/RiuQtChartsToolTip.h b/ApplicationLibCode/UserInterface/RiuQtChartsToolTip.h new file mode 100644 index 0000000000..d741bb83f9 --- /dev/null +++ b/ApplicationLibCode/UserInterface/RiuQtChartsToolTip.h @@ -0,0 +1,48 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2022- 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include +#include +#include +#include + +class RiuQtChartsToolTip : public QGraphicsItem +{ +public: + RiuQtChartsToolTip( QtCharts::QChart* parent, QtCharts::QAbstractSeries* series ); + + void setSeries( QtCharts::QAbstractSeries* series ); + void setText( const QString& text ); + void setAnchor( QPointF point ); + void updateGeometry(); + + QRectF boundingRect() const override; + void paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget ) override; + +private: + QString m_text; + QRectF m_textRect; + QRectF m_rect; + QPointF m_anchor; + QFont m_font; + int m_radius; + QtCharts::QChart* m_chart; + QtCharts::QAbstractSeries* m_series; +}; diff --git a/ApplicationLibCode/UserInterface/RiuQwtCurvePointTracker.cpp b/ApplicationLibCode/UserInterface/RiuQwtCurvePointTracker.cpp index c425cd187d..8d23423eda 100644 --- a/ApplicationLibCode/UserInterface/RiuQwtCurvePointTracker.cpp +++ b/ApplicationLibCode/UserInterface/RiuQwtCurvePointTracker.cpp @@ -20,12 +20,13 @@ #include "RiaQDateTimeTools.h" #include "RiuGuiTheme.h" - -#include "qwt_plot_marker.h" -#include "qwt_symbol.h" +#include "RiuPlotCurve.h" +#include "RiuPlotCurveInfoTextProvider.h" #include "qwt_date_scale_draw.h" #include "qwt_plot_curve.h" +#include "qwt_plot_marker.h" +#include "qwt_symbol.h" #include "qwt_text.h" #include // For DBL_MAX @@ -35,9 +36,9 @@ //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -RiuQwtCurvePointTracker::RiuQwtCurvePointTracker( QwtPlot* plot, - bool isMainAxisHorizontal, - IPlotCurveInfoTextProvider* curveInfoTextProvider ) +RiuQwtCurvePointTracker::RiuQwtCurvePointTracker( QwtPlot* plot, + bool isMainAxisHorizontal, + RiuPlotCurveInfoTextProvider* curveInfoTextProvider ) : QwtPlotPicker( plot->canvas() ) , m_plot( plot ) , m_isMainAxisHorizontal( isMainAxisHorizontal ) @@ -187,7 +188,7 @@ QPointF RiuQwtCurvePointTracker::closestCurvePoint( const QPoint& cursorPositio if ( curveInfoText && closestCurve && m_curveInfoTextProvider ) { - *curveInfoText = m_curveInfoTextProvider->curveInfoText( closestCurve ); + *curveInfoText = m_curveInfoTextProvider->curveInfoText( dynamic_cast( closestCurve ) ); } if ( dateScaleDraw ) diff --git a/ApplicationLibCode/UserInterface/RiuQwtCurvePointTracker.h b/ApplicationLibCode/UserInterface/RiuQwtCurvePointTracker.h index 0f4ff14d9c..6aba3e04ce 100644 --- a/ApplicationLibCode/UserInterface/RiuQwtCurvePointTracker.h +++ b/ApplicationLibCode/UserInterface/RiuQwtCurvePointTracker.h @@ -24,7 +24,7 @@ class QwtPlotMarker; class QwtPlotCurve; -class IPlotCurveInfoTextProvider; +class RiuPlotCurveInfoTextProvider; //-------------------------------------------------------------------------------------------------- /// Class to add mouse over-tracking of curve points with text marker @@ -32,9 +32,9 @@ class IPlotCurveInfoTextProvider; class RiuQwtCurvePointTracker : public QwtPlotPicker { public: - explicit RiuQwtCurvePointTracker( QwtPlot* plot, - bool isMainAxisHorizontal, - IPlotCurveInfoTextProvider* curveInfoTextProvider = nullptr ); + explicit RiuQwtCurvePointTracker( QwtPlot* plot, + bool isMainAxisHorizontal, + RiuPlotCurveInfoTextProvider* curveInfoTextProvider = nullptr ); ~RiuQwtCurvePointTracker() override; protected: @@ -52,17 +52,8 @@ protected: QwtPlot::Axis relatedXAxis, QwtPlot::Axis relatedYAxis ) const; - QPointer m_plot; - QwtPlotMarker* m_plotMarker; - bool m_isMainAxisHorizontal; - IPlotCurveInfoTextProvider* m_curveInfoTextProvider; -}; - -//-------------------------------------------------------------------------------------------------- -/// Interface for retrieving curve info text -//-------------------------------------------------------------------------------------------------- -class IPlotCurveInfoTextProvider -{ -public: - virtual QString curveInfoText( QwtPlotCurve* curve ) = 0; + QPointer m_plot; + QwtPlotMarker* m_plotMarker; + bool m_isMainAxisHorizontal; + RiuPlotCurveInfoTextProvider* m_curveInfoTextProvider; }; diff --git a/ApplicationLibCode/UserInterface/RiuSummaryQtChartsPlot.cpp b/ApplicationLibCode/UserInterface/RiuSummaryQtChartsPlot.cpp index 9fc1356f97..91c8b0b134 100644 --- a/ApplicationLibCode/UserInterface/RiuSummaryQtChartsPlot.cpp +++ b/ApplicationLibCode/UserInterface/RiuSummaryQtChartsPlot.cpp @@ -20,6 +20,7 @@ #include "RiaPreferences.h" +#include "RimEnsembleCurveInfoTextProvider.h" #include "RimSummaryPlot.h" #include "RiuPlotCurve.h" @@ -32,7 +33,7 @@ RiuSummaryQtChartsPlot::RiuSummaryQtChartsPlot( RimSummaryPlot* plot ) : RiuSummaryPlot( plot ) { - m_plotWidget = new RiuQtChartsPlotWidget( plot ); + m_plotWidget = new RiuQtChartsPlotWidget( plot, nullptr, new RimEnsembleCurveInfoTextProvider ); m_plotWidget->setContextMenuPolicy( Qt::CustomContextMenu ); connect( m_plotWidget, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( showContextMenu( QPoint ) ) ); @@ -43,7 +44,6 @@ RiuSummaryQtChartsPlot::RiuSummaryQtChartsPlot( RimSummaryPlot* plot ) m_plotWidget->setInternalLegendVisible( true ); } - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/UserInterface/RiuSummaryQwtPlot.cpp b/ApplicationLibCode/UserInterface/RiuSummaryQwtPlot.cpp index d26df7d761..e903f22da5 100644 --- a/ApplicationLibCode/UserInterface/RiuSummaryQwtPlot.cpp +++ b/ApplicationLibCode/UserInterface/RiuSummaryQwtPlot.cpp @@ -23,6 +23,7 @@ #include "Commands/CorrelationPlotCommands/RicNewCorrelationPlotFeature.h" +#include "RimEnsembleCurveInfoTextProvider.h" #include "RimPlotAxisAnnotation.h" #include "RimPlotAxisProperties.h" #include "RimPlotAxisPropertiesInterface.h" @@ -67,28 +68,7 @@ #include -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -class EnsembleCurveInfoTextProvider : public IPlotCurveInfoTextProvider -{ -public: - //-------------------------------------------------------------------------------------------------- - /// - //-------------------------------------------------------------------------------------------------- - QString curveInfoText( QwtPlotCurve* curve ) override - { - RiuPlotCurve* riuCurve = dynamic_cast( curve ); - RimSummaryCurve* sumCurve = nullptr; - if ( riuCurve ) - { - sumCurve = dynamic_cast( riuCurve->ownerRimCurve() ); - } - - return sumCurve && sumCurve->summaryCaseY() ? sumCurve->summaryCaseY()->displayCaseName() : ""; - } -}; -static EnsembleCurveInfoTextProvider ensembleCurveInfoTextProvider; +static RimEnsembleCurveInfoTextProvider ensembleCurveInfoTextProvider; //-------------------------------------------------------------------------------------------------- /// diff --git a/ApplicationLibCode/UserInterface/RiuWellLogTrack.cpp b/ApplicationLibCode/UserInterface/RiuWellLogTrack.cpp index 3a3766b95f..1ebdbd35f5 100644 --- a/ApplicationLibCode/UserInterface/RiuWellLogTrack.cpp +++ b/ApplicationLibCode/UserInterface/RiuWellLogTrack.cpp @@ -27,6 +27,7 @@ #include "RiuGuiTheme.h" #include "RiuPlotCurve.h" +#include "RiuPlotCurveInfoTextProvider.h" #include "RiuQwtCurvePointTracker.h" #include "RiuQwtPlotTools.h" @@ -41,7 +42,7 @@ class RiuWellLogCurvePointTracker : public RiuQwtCurvePointTracker { public: - RiuWellLogCurvePointTracker( QwtPlot* plot, IPlotCurveInfoTextProvider* curveInfoTextProvider, RimWellLogTrack* track ) + RiuWellLogCurvePointTracker( QwtPlot* plot, RiuPlotCurveInfoTextProvider* curveInfoTextProvider, RimWellLogTrack* track ) : RiuQwtCurvePointTracker( plot, false, curveInfoTextProvider ) , m_wellLogTrack( track ) { @@ -105,16 +106,15 @@ private: //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -class WellLogCurveInfoTextProvider : public IPlotCurveInfoTextProvider +class WellLogCurveInfoTextProvider : public RiuPlotCurveInfoTextProvider { public: //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- - QString curveInfoText( QwtPlotCurve* curve ) override + QString curveInfoText( RiuPlotCurve* riuCurve ) const override { - RiuPlotCurve* riuCurve = dynamic_cast( curve ); - RimWellLogCurve* wlCurve = nullptr; + RimWellLogCurve* wlCurve = nullptr; if ( riuCurve ) { wlCurve = dynamic_cast( riuCurve->ownerRimCurve() );