mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Highlight the curve belonging to the legend you click on. (#9259)
* Highlight the curve belonging to the legend you click on. * Make sure legend curve order remains the same when changing hilited curve
This commit is contained in:
parent
49e298c0b8
commit
2aedf38f79
@ -502,9 +502,7 @@ void RimSummaryCurveCollection::defineEditorAttribute( const caf::PdmFieldHandle
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RimSummaryCurveCollection::onCurvesReordered( const SignalEmitter* emitter )
|
void RimSummaryCurveCollection::onCurvesReordered( const SignalEmitter* emitter )
|
||||||
{
|
{
|
||||||
// detach and reattach to make sure curve legends are shown in correct order
|
refreshCurveOrdering();
|
||||||
detachPlotCurves();
|
|
||||||
reattachPlotCurves();
|
|
||||||
curvesChanged.send();
|
curvesChanged.send();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -543,3 +541,12 @@ void RimSummaryCurveCollection::defineObjectEditorAttribute( QString uiConfigNam
|
|||||||
myAttr->currentObject = m_currentSummaryCurve.p();
|
myAttr->currentObject = m_currentSummaryCurve.p();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RimSummaryCurveCollection::refreshCurveOrdering()
|
||||||
|
{
|
||||||
|
detachPlotCurves();
|
||||||
|
reattachPlotCurves();
|
||||||
|
}
|
||||||
|
@ -61,6 +61,8 @@ public:
|
|||||||
|
|
||||||
void loadDataAndUpdate( bool updateParentPlot );
|
void loadDataAndUpdate( bool updateParentPlot );
|
||||||
|
|
||||||
|
void refreshCurveOrdering();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setParentPlotAndReplot( RiuPlotWidget* plot );
|
void setParentPlotAndReplot( RiuPlotWidget* plot );
|
||||||
void setParentPlotNoReplot( RiuPlotWidget* plot );
|
void setParentPlotNoReplot( RiuPlotWidget* plot );
|
||||||
|
@ -2456,6 +2456,8 @@ RiuPlotWidget* RimSummaryPlot::doCreatePlotViewWidget( QWidget* mainWindowParent
|
|||||||
m_summaryPlot = std::make_unique<RiuSummaryQwtPlot>( this, mainWindowParent );
|
m_summaryPlot = std::make_unique<RiuSummaryQwtPlot>( this, mainWindowParent );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
QObject::connect( plotWidget(), SIGNAL( curveOrderNeedsUpdate() ), this, SLOT( updateCurveOrder() ) );
|
||||||
|
|
||||||
for ( const auto& axisProperties : m_axisProperties )
|
for ( const auto& axisProperties : m_axisProperties )
|
||||||
{
|
{
|
||||||
plotWidget()->ensureAxisIsCreated( axisProperties->plotAxisType() );
|
plotWidget()->ensureAxisIsCreated( axisProperties->plotAxisType() );
|
||||||
@ -3015,3 +3017,11 @@ RimSummaryPlotSourceStepping* RimSummaryPlot::sourceStepper()
|
|||||||
{
|
{
|
||||||
return m_sourceStepping();
|
return m_sourceStepping();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RimSummaryPlot::updateCurveOrder()
|
||||||
|
{
|
||||||
|
m_summaryCurveCollection->refreshCurveOrdering();
|
||||||
|
}
|
||||||
|
@ -252,6 +252,7 @@ protected:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onPlotZoomed();
|
void onPlotZoomed();
|
||||||
|
void updateCurveOrder();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<RimSummaryCurve*> visibleSummaryCurvesForAxis( RiuPlotAxis plotAxis ) const;
|
std::vector<RimSummaryCurve*> visibleSummaryCurvesForAxis( RiuPlotAxis plotAxis ) const;
|
||||||
|
@ -189,11 +189,15 @@ void RiuMultiPlotPage::insertPlot( RiuPlotWidget* plotWidget, size_t index )
|
|||||||
legend->setMaxColumns( legendColumns );
|
legend->setMaxColumns( legendColumns );
|
||||||
legend->horizontalScrollBar()->setVisible( false );
|
legend->horizontalScrollBar()->setVisible( false );
|
||||||
legend->verticalScrollBar()->setVisible( false );
|
legend->verticalScrollBar()->setVisible( false );
|
||||||
|
legend->setDefaultItemMode( QwtLegendData::Clickable );
|
||||||
if ( qwtPlotWidget )
|
if ( qwtPlotWidget )
|
||||||
{
|
{
|
||||||
legend->connect( qwtPlotWidget->qwtPlot(),
|
legend->connect( qwtPlotWidget->qwtPlot(),
|
||||||
SIGNAL( legendDataChanged( const QVariant&, const QList<QwtLegendData>& ) ),
|
SIGNAL( legendDataChanged( const QVariant&, const QList<QwtLegendData>& ) ),
|
||||||
SLOT( updateLegend( const QVariant&, const QList<QwtLegendData>& ) ) );
|
SLOT( updateLegend( const QVariant&, const QList<QwtLegendData>& ) ) );
|
||||||
|
qwtPlotWidget->connect( legend,
|
||||||
|
SIGNAL( clicked( const QVariant&, int ) ),
|
||||||
|
SLOT( onLegendClicked( const QVariant&, int ) ) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -188,6 +188,9 @@ public:
|
|||||||
|
|
||||||
virtual void updateZoomDependentCurveProperties();
|
virtual void updateZoomDependentCurveProperties();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void curveOrderNeedsUpdate();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void updateOverlayFrameLayout();
|
void updateOverlayFrameLayout();
|
||||||
|
|
||||||
|
@ -17,11 +17,16 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
#include "RiuQwtPlotLegend.h"
|
#include "RiuQwtPlotLegend.h"
|
||||||
|
|
||||||
|
#include "RiuQwtPlotWidget.h"
|
||||||
|
|
||||||
#include "qwt_dyngrid_layout.h"
|
#include "qwt_dyngrid_layout.h"
|
||||||
#include "qwt_legend_label.h"
|
#include "qwt_legend_label.h"
|
||||||
|
#include "qwt_plot.h"
|
||||||
|
#include "qwt_plot_item.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QResizeEvent>
|
#include <QResizeEvent>
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
@ -616,17 +616,6 @@ bool RiuQwtPlotWidget::eventFilter( QObject* watched, QEvent* event )
|
|||||||
void RiuQwtPlotWidget::hideEvent( QHideEvent* event )
|
void RiuQwtPlotWidget::hideEvent( QHideEvent* event )
|
||||||
{
|
{
|
||||||
resetPlotItemHighlighting();
|
resetPlotItemHighlighting();
|
||||||
// TODO: remove?
|
|
||||||
// m_plot->hideEvent( event );
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
void RiuQwtPlotWidget::showEvent( QShowEvent* event )
|
|
||||||
{
|
|
||||||
// TODO: remove?
|
|
||||||
// m_plot->showEvent( event );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -634,8 +623,6 @@ void RiuQwtPlotWidget::showEvent( QShowEvent* event )
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RiuQwtPlotWidget::resizeEvent( QResizeEvent* event )
|
void RiuQwtPlotWidget::resizeEvent( QResizeEvent* event )
|
||||||
{
|
{
|
||||||
// TODO: remove???
|
|
||||||
// QwtPlot::resizeEvent( event );
|
|
||||||
updateOverlayFrameLayout();
|
updateOverlayFrameLayout();
|
||||||
event->accept();
|
event->accept();
|
||||||
}
|
}
|
||||||
@ -936,10 +923,10 @@ void RiuQwtPlotWidget::selectClosestPlotItem( const QPoint& pos, bool toggleItem
|
|||||||
findClosestPlotItem( pos, &closestItem, &closestCurvePoint, &distanceFromClick );
|
findClosestPlotItem( pos, &closestItem, &closestCurvePoint, &distanceFromClick );
|
||||||
|
|
||||||
RiuPlotMainWindowTools::showPlotMainWindow();
|
RiuPlotMainWindowTools::showPlotMainWindow();
|
||||||
resetPlotItemHighlighting();
|
|
||||||
if ( closestItem && distanceFromClick < 20 )
|
if ( closestItem && distanceFromClick < 20 )
|
||||||
{
|
{
|
||||||
// TODO: highlight all selected curves
|
bool refreshCurveOrder = false;
|
||||||
|
resetPlotItemHighlighting( refreshCurveOrder );
|
||||||
std::set<const QwtPlotItem*> plotItems = { closestItem };
|
std::set<const QwtPlotItem*> plotItems = { closestItem };
|
||||||
highlightPlotItems( plotItems );
|
highlightPlotItems( plotItems );
|
||||||
auto plotItem = std::make_shared<RiuQwtPlotItem>( closestItem );
|
auto plotItem = std::make_shared<RiuQwtPlotItem>( closestItem );
|
||||||
@ -947,6 +934,7 @@ void RiuQwtPlotWidget::selectClosestPlotItem( const QPoint& pos, bool toggleItem
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
resetPlotItemHighlighting();
|
||||||
emit plotSelected( toggleItemInSelection );
|
emit plotSelected( toggleItemInSelection );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1015,13 +1003,13 @@ void RiuQwtPlotWidget::highlightPlotItems( const std::set<const QwtPlotItem*>& c
|
|||||||
m_originalCurveProperties.insert( std::make_pair( plotCurve, properties ) );
|
m_originalCurveProperties.insert( std::make_pair( plotCurve, properties ) );
|
||||||
m_originalZValues.insert( std::make_pair( plotCurve, zValue ) );
|
m_originalZValues.insert( std::make_pair( plotCurve, zValue ) );
|
||||||
|
|
||||||
|
restoreCurveOrder();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NB! Create a copy of the item list before the loop to avoid invalidated iterators when iterating the list
|
|
||||||
// plotCurve->setZ() causes the ordering of items in the list to change
|
|
||||||
auto plotItemList = m_plot->itemList();
|
auto plotItemList = m_plot->itemList();
|
||||||
for ( QwtPlotItem* plotItem : plotItemList )
|
for ( QwtPlotItem* plotItem : plotItemList )
|
||||||
{
|
{
|
||||||
@ -1081,15 +1069,15 @@ void RiuQwtPlotWidget::highlightPlotItems( const std::set<const QwtPlotItem*>& c
|
|||||||
plotShapeItem->setZ( plotShapeItem->z() + 100.0 );
|
plotShapeItem->setZ( plotShapeItem->z() + 100.0 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
restoreCurveOrder();
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RiuQwtPlotWidget::resetPlotItemHighlighting()
|
void RiuQwtPlotWidget::resetPlotItemHighlighting( bool refreshCurveOrder )
|
||||||
{
|
{
|
||||||
// NB! Create a copy of the item list before the loop to avoid invalidated iterators when iterating the list
|
|
||||||
// plotCurve->setZ() causes the ordering of items in the list to change
|
|
||||||
auto plotItemList = m_plot->itemList();
|
auto plotItemList = m_plot->itemList();
|
||||||
for ( QwtPlotItem* plotItem : plotItemList )
|
for ( QwtPlotItem* plotItem : plotItemList )
|
||||||
{
|
{
|
||||||
@ -1129,6 +1117,8 @@ void RiuQwtPlotWidget::resetPlotItemHighlighting()
|
|||||||
m_originalZValues.clear();
|
m_originalZValues.clear();
|
||||||
|
|
||||||
resetPlotAxisHighlighting();
|
resetPlotAxisHighlighting();
|
||||||
|
|
||||||
|
if ( refreshCurveOrder ) restoreCurveOrder();
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -1519,3 +1509,37 @@ QwtAxisId RiuQwtPlotWidget::toQwtPlotAxis( RiuPlotAxis plotAxis ) const
|
|||||||
|
|
||||||
return { -1, -1 };
|
return { -1, -1 };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RiuQwtPlotWidget::highlightPlotItem( const QwtPlotItem* plotItem )
|
||||||
|
{
|
||||||
|
bool refreshCurveOrder = false;
|
||||||
|
resetPlotItemHighlighting( refreshCurveOrder );
|
||||||
|
|
||||||
|
std::set<const QwtPlotItem*> items;
|
||||||
|
items.insert( plotItem );
|
||||||
|
highlightPlotItems( items );
|
||||||
|
|
||||||
|
replot();
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RiuQwtPlotWidget::onLegendClicked( const QVariant& itemInfo, int index )
|
||||||
|
{
|
||||||
|
if ( !itemInfo.canConvert<QwtPlotItem*>() ) return;
|
||||||
|
|
||||||
|
QwtPlotItem* plotItem = qvariant_cast<QwtPlotItem*>( itemInfo );
|
||||||
|
if ( plotItem ) highlightPlotItem( plotItem );
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RiuQwtPlotWidget::restoreCurveOrder()
|
||||||
|
{
|
||||||
|
emit curveOrderNeedsUpdate();
|
||||||
|
}
|
||||||
|
@ -174,6 +174,11 @@ public:
|
|||||||
|
|
||||||
QwtAxisId toQwtPlotAxis( RiuPlotAxis axis ) const;
|
QwtAxisId toQwtPlotAxis( RiuPlotAxis axis ) const;
|
||||||
|
|
||||||
|
void highlightPlotItem( const QwtPlotItem* plotItem );
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void onLegendClicked( const QVariant& itemInfo, int index );
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void plotSelected( bool toggleSelection );
|
void plotSelected( bool toggleSelection );
|
||||||
void axisSelected( RiuPlotAxis axisId, bool toggleSelection );
|
void axisSelected( RiuPlotAxis axisId, bool toggleSelection );
|
||||||
@ -185,7 +190,6 @@ signals:
|
|||||||
protected:
|
protected:
|
||||||
bool eventFilter( QObject* watched, QEvent* event ) override;
|
bool eventFilter( QObject* watched, QEvent* event ) override;
|
||||||
void hideEvent( QHideEvent* event ) override;
|
void hideEvent( QHideEvent* event ) override;
|
||||||
void showEvent( QShowEvent* event ) override;
|
|
||||||
void resizeEvent( QResizeEvent* event ) override;
|
void resizeEvent( QResizeEvent* event ) override;
|
||||||
void keyPressEvent( QKeyEvent* event ) override;
|
void keyPressEvent( QKeyEvent* event ) override;
|
||||||
|
|
||||||
@ -211,13 +215,15 @@ private:
|
|||||||
void highlightPlotAxes( QwtAxisId axisIdX, QwtAxisId axisIdY );
|
void highlightPlotAxes( QwtAxisId axisIdX, QwtAxisId axisIdY );
|
||||||
void highlightPlotItemsForQwtAxis( QwtAxisId axisId );
|
void highlightPlotItemsForQwtAxis( QwtAxisId axisId );
|
||||||
void highlightPlotItems( const std::set<const QwtPlotItem*>& closestItems );
|
void highlightPlotItems( const std::set<const QwtPlotItem*>& closestItems );
|
||||||
void resetPlotItemHighlighting();
|
void resetPlotItemHighlighting( bool refreshCurveOrder = true );
|
||||||
void resetPlotAxisHighlighting();
|
void resetPlotAxisHighlighting();
|
||||||
void onAxisSelected( QwtScaleWidget* scale, bool toggleItemInSelection );
|
void onAxisSelected( QwtScaleWidget* scale, bool toggleItemInSelection );
|
||||||
void recalculateAxisExtents( RiuPlotAxis axis );
|
void recalculateAxisExtents( RiuPlotAxis axis );
|
||||||
|
|
||||||
static int highlightItemWidthAdjustment();
|
static int highlightItemWidthAdjustment();
|
||||||
|
|
||||||
|
void restoreCurveOrder();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct CurveProperties
|
struct CurveProperties
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user