diff --git a/ApplicationCode/UserInterface/RiuPlotMainWindow.cpp b/ApplicationCode/UserInterface/RiuPlotMainWindow.cpp index 710cbb72ca..13878549eb 100644 --- a/ApplicationCode/UserInterface/RiuPlotMainWindow.cpp +++ b/ApplicationCode/UserInterface/RiuPlotMainWindow.cpp @@ -759,11 +759,14 @@ void RiuPlotMainWindow::slotSubWindowActivated( QMdiSubWindow* subWindow ) caf::PdmObject* pdmObject = dynamic_cast( uiItem ); if ( pdmObject ) { - RimViewWindow* owningView = nullptr; - pdmObject->firstAncestorOrThisOfType( owningView ); - if ( owningView && owningView == activatedView ) + std::vector ancestralViews; + pdmObject->allAncestorsOrThisOfType( ancestralViews ); + for ( auto ancestralView : ancestralViews ) { - childSelected = true; + if ( ancestralView == activatedView ) + { + childSelected = true; + } } } } diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmObjectHandle.h b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmObjectHandle.h index 131ffa0511..e8c94905e5 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmObjectHandle.h +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmObjectHandle.h @@ -50,6 +50,12 @@ public: template void firstAncestorOrThisOfTypeAsserted( T*& ancestor ) const; + template + void allAncestorsOfType( std::vector& ancestors ) const; + + template + void allAncestorsOrThisOfType( std::vector& ancestors ) const; + /// Traverses all children recursively to find objects of the requested type. This object is also /// included if it is of the requested type. template @@ -196,6 +202,36 @@ void PdmObjectHandle::firstAncestorOrThisOfTypeAsserted( T*& ancestor ) const CAF_ASSERT( ancestor ); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +template +void PdmObjectHandle::allAncestorsOfType( std::vector& ancestors ) const +{ + T* firstAncestor = nullptr; + this->firstAncestorOfType( firstAncestor ); + if ( firstAncestor ) + { + ancestors.push_back( firstAncestor ); + firstAncestor->allAncestorsOfType( ancestors ); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +template +void PdmObjectHandle::allAncestorsOrThisOfType( std::vector& ancestors ) const +{ + T* firstAncestorOrThis = nullptr; + this->firstAncestorOrThisOfType( firstAncestorOrThis ); + if ( firstAncestorOrThis ) + { + ancestors.push_back( firstAncestorOrThis ); + firstAncestorOrThis->allAncestorsOfType( ancestors ); + } +} + //-------------------------------------------------------------------------------------------------- /// //--------------------------------------------------------------------------------------------------