From 7b6934a1ffa31ccc7b1c5c243fb93dbf7561ea85 Mon Sep 17 00:00:00 2001 From: jonjenssen Date: Fri, 21 Nov 2025 02:52:49 +0100 Subject: [PATCH] Make sure property editor(s) and tree view selections are in sync after loading a project --- .../UserInterface/RiuMainWindow.cpp | 30 +++++++++---------- .../UserInterface/RiuPlotMainWindow.cpp | 26 ++++++++-------- 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/ApplicationLibCode/UserInterface/RiuMainWindow.cpp b/ApplicationLibCode/UserInterface/RiuMainWindow.cpp index 1090ff7270..fb7e39ec99 100644 --- a/ApplicationLibCode/UserInterface/RiuMainWindow.cpp +++ b/ApplicationLibCode/UserInterface/RiuMainWindow.cpp @@ -263,22 +263,22 @@ void RiuMainWindow::initializeGuiNewProjectLoaded() } } - // Find the project tree and reselect items to trigger the selectionChanged signal. This will make sure that the property view is - // updated based on the selection in the main project tree. - if ( auto dockWidget = RiuDockWidgetTools::findDockWidget( dockManager(), RiuDockWidgetTools::mainWindowProjectTreeName() ) ) + // Sync selections with property editor. + // Go backwards as the most "important" tree view is first in the list + // and we want that to use the property editor in case multiple tree views are visible + for ( auto it = m_projectTreeViews.rbegin(); it != m_projectTreeViews.rend(); it++ ) { - if ( auto tree = dynamic_cast( dockWidget->widget() ) ) + auto projectTree = *it; + if ( !projectTree->isVisible() ) continue; + std::vector uiItems; + projectTree->selectedUiItems( uiItems ); + + if ( !uiItems.empty() ) { - std::vector uiItems; - tree->selectedUiItems( uiItems ); - - std::vector constSelectedItems; - for ( auto item : uiItems ) - { - constSelectedItems.push_back( item ); - } - - tree->selectItems( constSelectedItems ); + auto firstSelectedObject = dynamic_cast( uiItems.front() ); + updateUiFieldsFromActiveResult( firstSelectedObject ); + m_pdmUiPropertyView->showProperties( firstSelectedObject ); + m_seismicHistogramPanel->showHistogram( firstSelectedObject ); } } } @@ -1517,9 +1517,7 @@ void RiuMainWindow::selectedObjectsChanged() } updateUiFieldsFromActiveResult( firstSelectedObject ); - m_pdmUiPropertyView->showProperties( firstSelectedObject ); - m_seismicHistogramPanel->showHistogram( firstSelectedObject ); if ( uiItems.size() == 1 && m_allowActiveViewChangeFromSelection ) diff --git a/ApplicationLibCode/UserInterface/RiuPlotMainWindow.cpp b/ApplicationLibCode/UserInterface/RiuPlotMainWindow.cpp index 9c9a63c103..f5b26a49fe 100644 --- a/ApplicationLibCode/UserInterface/RiuPlotMainWindow.cpp +++ b/ApplicationLibCode/UserInterface/RiuPlotMainWindow.cpp @@ -236,22 +236,20 @@ void RiuPlotMainWindow::initializeGuiNewProjectLoaded() refreshToolbars(); - // Find the project tree and reselect items to trigger the selectionChanged signal. This will make sure that the property view is - // updated based on the selection in the main project tree. - if ( auto dockWidget = RiuDockWidgetTools::findDockWidget( dockManager(), RiuDockWidgetTools::plotMainWindowPlotsTreeName() ) ) + // Sync selections with property views. + // Go backwards as the most "important" tree view is first in the list + // and we want that to use the property editor in case multiple tree views are visible + for ( int i = (int)m_projectTreeViews.size() - 1; i >= 0; i-- ) { - if ( auto tree = dynamic_cast( dockWidget->widget() ) ) + auto projectTree = projectTreeView( i ); + if ( !projectTree->isVisible() ) continue; + + std::vector uiItems; + projectTree->selectedUiItems( uiItems ); + if ( !uiItems.empty() ) { - std::vector uiItems; - tree->selectedUiItems( uiItems ); - - std::vector constSelectedItems; - for ( auto item : uiItems ) - { - constSelectedItems.push_back( item ); - } - - tree->selectItems( constSelectedItems ); + auto firstSelectedObject = dynamic_cast( uiItems.front() ); + if ( i < (int)m_propertyViews.size() ) m_propertyViews[i]->showProperties( firstSelectedObject ); } } }