Fix active cell not resetting when clicking on cells (#9804)

- Refactor PlotShapeItems highlighting in QwtPlotWdiget - s.t. highlighting is not dependent on plotDefinition RimPlot object and its isCurveHighlightSupported flag.
- Remove plot definition assert and utilize guards to allow nullptr/undefined plotDefinition
This commit is contained in:
Jørgen Herje 2023-02-06 14:33:09 +01:00 committed by GitHub
parent b1e94adffd
commit 7a2aebe8b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 72 additions and 38 deletions

View File

@ -49,7 +49,6 @@ RiuPlotWidget::RiuPlotWidget( RimPlot* plotDefinition, QWidget* parent )
, m_plotTitle( "" ) , m_plotTitle( "" )
, m_plotTitleEnabled( true ) , m_plotTitleEnabled( true )
{ {
CAF_ASSERT( m_plotDefinition );
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------

View File

@ -79,8 +79,6 @@
RiuQwtPlotWidget::RiuQwtPlotWidget( RimPlot* plotDefinition, QWidget* parent ) RiuQwtPlotWidget::RiuQwtPlotWidget( RimPlot* plotDefinition, QWidget* parent )
: RiuPlotWidget( plotDefinition, parent ) : RiuPlotWidget( plotDefinition, parent )
{ {
CAF_ASSERT( m_plotDefinition );
auto* layout = new QVBoxLayout; auto* layout = new QVBoxLayout;
layout->setContentsMargins( 0, 0, 0, 0 ); layout->setContentsMargins( 0, 0, 0, 0 );
setLayout( layout ); setLayout( layout );
@ -595,11 +593,7 @@ bool RiuQwtPlotWidget::eventFilter( QObject* watched, QEvent* event )
auto* scaleWidget = qobject_cast<QwtScaleWidget*>( childClicked ); auto* scaleWidget = qobject_cast<QwtScaleWidget*>( childClicked );
if ( scaleWidget ) if ( scaleWidget )
{ {
if ( m_plotDefinition && m_plotDefinition->isCurveHighlightSupported() ) onAxisSelected( scaleWidget, toggleItemInSelection );
{
onAxisSelected( scaleWidget, toggleItemInSelection );
}
m_clickPosition = QPoint(); m_clickPosition = QPoint();
return true; return true;
} }
@ -620,10 +614,7 @@ bool RiuQwtPlotWidget::eventFilter( QObject* watched, QEvent* event )
{ {
endZoomOperations(); endZoomOperations();
if ( m_plotDefinition->isCurveHighlightSupported() ) selectClosestPlotItem( mouseEvent->pos(), toggleItemInSelection );
{
selectClosestPlotItem( mouseEvent->pos(), toggleItemInSelection );
}
m_clickPosition = QPoint(); m_clickPosition = QPoint();
return true; return true;
} }
@ -921,7 +912,6 @@ void RiuQwtPlotWidget::findClosestPlotItem( const QPoint& pos,
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
std::pair<RiuPlotCurve*, int> RiuQwtPlotWidget::findClosestCurve( const QPoint& pos, double& distanceFromClick ) const std::pair<RiuPlotCurve*, int> RiuQwtPlotWidget::findClosestCurve( const QPoint& pos, double& distanceFromClick ) const
{ {
QwtPlotItem* closestItem = nullptr; QwtPlotItem* closestItem = nullptr;
@ -987,6 +977,22 @@ void RiuQwtPlotWidget::replot()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiuQwtPlotWidget::highlightPlotItems( const std::set<const QwtPlotItem*>& closestItems ) void RiuQwtPlotWidget::highlightPlotItems( const std::set<const QwtPlotItem*>& closestItems )
{ {
highlightPlotCurves( closestItems );
highlightPlotShapeItems( closestItems );
updateCurveOrder();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuQwtPlotWidget::highlightPlotCurves( const std::set<const QwtPlotItem*>& closestItems )
{
if ( !m_plotDefinition || !m_plotDefinition->isCurveHighlightSupported() )
{
return;
}
auto plotItemList = m_plot->itemList(); auto plotItemList = m_plot->itemList();
for ( QwtPlotItem* plotItem : plotItemList ) for ( QwtPlotItem* plotItem : plotItemList )
{ {
@ -1033,7 +1039,17 @@ void RiuQwtPlotWidget::highlightPlotItems( const std::set<const QwtPlotItem*>& c
continue; continue;
} }
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuQwtPlotWidget::highlightPlotShapeItems( const std::set<const QwtPlotItem*>& closestItems )
{
auto plotItemList = m_plot->itemList();
for ( QwtPlotItem* plotItem : plotItemList )
{
auto* plotShapeItem = dynamic_cast<QwtPlotShapeItem*>( plotItem ); auto* plotShapeItem = dynamic_cast<QwtPlotShapeItem*>( plotItem );
if ( plotShapeItem && closestItems.count( plotItem ) > 0 ) if ( plotShapeItem && closestItems.count( plotItem ) > 0 )
{ {
@ -1044,8 +1060,6 @@ void RiuQwtPlotWidget::highlightPlotItems( const std::set<const QwtPlotItem*>& c
plotShapeItem->setZ( plotShapeItem->z() + 100.0 ); plotShapeItem->setZ( plotShapeItem->z() + 100.0 );
} }
} }
updateCurveOrder();
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -1053,28 +1067,49 @@ void RiuQwtPlotWidget::highlightPlotItems( const std::set<const QwtPlotItem*>& c
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiuQwtPlotWidget::resetPlotItemHighlighting( bool doUpdateCurveOrder ) void RiuQwtPlotWidget::resetPlotItemHighlighting( bool doUpdateCurveOrder )
{ {
if ( !m_originalZValues.empty() ) resetPlotCurveHighlighting();
{ resetPlotShapeItemHighlighting();
const auto& plotItemList = m_plot->itemList();
for ( QwtPlotItem* plotItem : plotItemList )
{
if ( auto* plotCurve = dynamic_cast<QwtPlotCurve*>( plotItem ) )
{
auto* riuPlotCurve = dynamic_cast<RiuPlotCurve*>( plotItem );
if ( auto rimPlotCurve = resetPlotAxisHighlighting();
dynamic_cast<RimPlotCurve*>( m_plotDefinition->findPdmObjectFromPlotCurve( riuPlotCurve ) ) )
{ if ( doUpdateCurveOrder ) updateCurveOrder();
rimPlotCurve->updateCurveAppearance(); }
double zValue = m_originalZValues[plotCurve];
riuPlotCurve->setZ( zValue ); //--------------------------------------------------------------------------------------------------
continue; ///
} //--------------------------------------------------------------------------------------------------
} void RiuQwtPlotWidget::resetPlotCurveHighlighting()
} {
m_originalZValues.clear(); if ( !m_plotDefinition || m_originalZValues.empty() )
{
return;
} }
const auto& plotItemList = m_plot->itemList();
for ( QwtPlotItem* plotItem : plotItemList )
{
if ( auto* plotCurve = dynamic_cast<QwtPlotCurve*>( plotItem ) )
{
auto* riuPlotCurve = dynamic_cast<RiuPlotCurve*>( plotItem );
if ( auto rimPlotCurve =
dynamic_cast<RimPlotCurve*>( m_plotDefinition->findPdmObjectFromPlotCurve( riuPlotCurve ) ) )
{
rimPlotCurve->updateCurveAppearance();
double zValue = m_originalZValues[plotCurve];
riuPlotCurve->setZ( zValue );
continue;
}
}
}
m_originalZValues.clear();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuQwtPlotWidget::resetPlotShapeItemHighlighting()
{
const auto& plotItemList = m_plot->itemList(); const auto& plotItemList = m_plot->itemList();
for ( QwtPlotItem* plotItem : plotItemList ) for ( QwtPlotItem* plotItem : plotItemList )
{ {
@ -1091,10 +1126,6 @@ void RiuQwtPlotWidget::resetPlotItemHighlighting( bool doUpdateCurveOrder )
plotShapeItem->setZ( plotShapeItem->z() - 100.0 ); plotShapeItem->setZ( plotShapeItem->z() - 100.0 );
} }
} }
resetPlotAxisHighlighting();
if ( doUpdateCurveOrder ) updateCurveOrder();
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------

View File

@ -217,7 +217,11 @@ 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 highlightPlotCurves( const std::set<const QwtPlotItem*>& closestItems );
void highlightPlotShapeItems( const std::set<const QwtPlotItem*>& closestItems );
void resetPlotItemHighlighting( bool doUpdateCurveOrder = true ); void resetPlotItemHighlighting( bool doUpdateCurveOrder = true );
void resetPlotCurveHighlighting();
void resetPlotShapeItemHighlighting();
void resetPlotAxisHighlighting(); void resetPlotAxisHighlighting();
void onAxisSelected( QwtScaleWidget* scale, bool toggleItemInSelection ); void onAxisSelected( QwtScaleWidget* scale, bool toggleItemInSelection );
void recalculateAxisExtents( RiuPlotAxis axis ); void recalculateAxisExtents( RiuPlotAxis axis );