Select the first visible plot item in the Project Tree

When clicking on a plot, this change ensures that the first visible ancestor plot in the hierarchy is selected in the project tree.
This commit is contained in:
Magne Sjaastad committed 2025-07-25 08:42:13 +02:00
1 parent 213be04700
commit b9f13f742d
3 files changed
+31 -1

No files matched your search

@@ -74,6 +74,30 @@ void RiuPlotMainWindowTools::selectAsCurrentItem( const caf::PdmObject* object )
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
const caf::PdmObject* RiuPlotMainWindowTools::firstVisibleAncestorOrThis( const caf::PdmObject* object )
{
if ( RiaGuiApplication::isRunning() )
{
RiuPlotMainWindow* mpw = RiaGuiApplication::instance()->mainPlotWindow();
auto current = const_cast<caf::PdmObject*>( object );
while ( current )
{
if ( mpw->getTreeViewWithItem( current ) )
{
return current;
}
current = current->firstAncestorOfType<caf::PdmObject>();
}
}
return nullptr;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -36,6 +36,9 @@ public:
static void selectOrToggleObject( const caf::PdmObject* object, bool toggle );
static void refreshToolbars();
// Returns the first visible ancestor of the object, or the object itself if it is visible.
static const caf::PdmObject* firstVisibleAncestorOrThis( const caf::PdmObject* object );
// Use this function to select (and expand) an object in the project tree and update tool bars. Use the second
// parameter to expand a different object than the object to be selected.
static void onObjectAppended( const caf::PdmObject* objectToSelect, const caf::PdmObject* objectToExpand = nullptr );
@@ -574,7 +574,10 @@ bool RiuQwtPlotWidget::eventFilter( QObject* watched, QEvent* event )
( mouseEvent->button() == Qt::LeftButton || mouseEvent->button() == Qt::RightButton ) && m_plotDefinition )
{
// Select the plot clicked at in the Project Tree for both left and right mouse button clicks
RiuPlotMainWindowTools::selectAsCurrentItem( m_plotDefinition );
// If we have plots contained in other plots, select the first visible plot item in the hierarchy
auto firstVisibleItem = RiuPlotMainWindowTools::firstVisibleAncestorOrThis( m_plotDefinition );
RiuPlotMainWindowTools::selectAsCurrentItem( firstVisibleItem );
}
bool toggleItemInSelection = ( mouseEvent->modifiers() & Qt::ControlModifier ) != 0;