#6266 Fix unwanted selection change when changing window focus

This commit is contained in:
Gaute Lindkvist 2020-08-05 13:03:52 +02:00
parent 105deba056
commit 31246b59f3
2 changed files with 43 additions and 4 deletions

View File

@ -759,14 +759,17 @@ void RiuPlotMainWindow::slotSubWindowActivated( QMdiSubWindow* subWindow )
caf::PdmObject* pdmObject = dynamic_cast<caf::PdmObject*>( uiItem );
if ( pdmObject )
{
RimViewWindow* owningView = nullptr;
pdmObject->firstAncestorOrThisOfType( owningView );
if ( owningView && owningView == activatedView )
std::vector<RimViewWindow*> ancestralViews;
pdmObject->allAncestorsOrThisOfType( ancestralViews );
for ( auto ancestralView : ancestralViews )
{
if ( ancestralView == activatedView )
{
childSelected = true;
}
}
}
}
if ( !childSelected )
{
selectAsCurrentItem( activatedView );

View File

@ -50,6 +50,12 @@ public:
template <typename T>
void firstAncestorOrThisOfTypeAsserted( T*& ancestor ) const;
template <typename T>
void allAncestorsOfType( std::vector<T*>& ancestors ) const;
template <typename T>
void allAncestorsOrThisOfType( std::vector<T*>& 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 <typename T>
@ -196,6 +202,36 @@ void PdmObjectHandle::firstAncestorOrThisOfTypeAsserted( T*& ancestor ) const
CAF_ASSERT( ancestor );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template <typename T>
void PdmObjectHandle::allAncestorsOfType( std::vector<T*>& ancestors ) const
{
T* firstAncestor = nullptr;
this->firstAncestorOfType( firstAncestor );
if ( firstAncestor )
{
ancestors.push_back( firstAncestor );
firstAncestor->allAncestorsOfType( ancestors );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template <typename T>
void PdmObjectHandle::allAncestorsOrThisOfType( std::vector<T*>& ancestors ) const
{
T* firstAncestorOrThis = nullptr;
this->firstAncestorOrThisOfType( firstAncestorOrThis );
if ( firstAncestorOrThis )
{
ancestors.push_back( firstAncestorOrThis );
firstAncestorOrThis->allAncestorsOfType( ancestors );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------