#7347 Property Editor : Check if current field is part of selection

When using toggle buttons in tree view, the current field changed might be outside of the current selection. Only apply multiple field changed if current field is part of the current selection.
This commit is contained in:
Magne Sjaastad 2021-02-15 10:58:51 +01:00
parent c690c9fa53
commit 4cb59aa1d0
2 changed files with 58 additions and 34 deletions

View File

@ -45,7 +45,6 @@
#include "cafSelectionManager.h" #include "cafSelectionManager.h"
#include <cstddef> #include <cstddef>
#include <typeinfo>
namespace caf namespace caf
{ {
@ -80,7 +79,7 @@ void PdmUiCommandSystemProxy::setCommandInterface( PdmUiCommandSystemInterface*
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void PdmUiCommandSystemProxy::setUiValueToField( PdmUiFieldHandle* uiFieldHandle, const QVariant& newUiValue ) void PdmUiCommandSystemProxy::setUiValueToField( PdmUiFieldHandle* uiFieldHandle, const QVariant& newUiValue )
{ {
if ( uiFieldHandle ) if ( uiFieldHandle && uiFieldHandle->fieldHandle() )
{ {
// Handle editing multiple objects when several objects are selected // Handle editing multiple objects when several objects are selected
PdmFieldHandle* editorField = uiFieldHandle->fieldHandle(); PdmFieldHandle* editorField = uiFieldHandle->fieldHandle();
@ -89,41 +88,16 @@ void PdmUiCommandSystemProxy::setUiValueToField( PdmUiFieldHandle* uiFieldHandle
std::vector<PdmFieldHandle*> fieldsToUpdate; std::vector<PdmFieldHandle*> fieldsToUpdate;
fieldsToUpdate.push_back( editorField ); fieldsToUpdate.push_back( editorField );
// For level 1 selection, find all fields with same keyword std::vector<PdmFieldHandle*> otherSelectedFields = fieldsFromSelection( fieldOwnerTypeId, editorField->keyword() );
// Todo: Should traverse the ui ordering and find all fields with same keyword and same owner object type.
// Until we do, fields embedded into the property panel from a different object will not work with // If current edited field is part of the selection, update all fields in selection
// multi selection edit For now we only makes sure we have same owner object type if ( std::find( otherSelectedFields.begin(), otherSelectedFields.end(), editorField ) != otherSelectedFields.end() )
{ {
std::vector<PdmUiItem*> items; for ( auto otherField : otherSelectedFields )
int selectionLevel = 0;
SelectionManager::instance()->selectedItems( items, selectionLevel );
for ( auto& item : items )
{ {
PdmObjectHandle* objectHandle = dynamic_cast<PdmObjectHandle*>( item ); if ( otherField != editorField )
if ( objectHandle && typeid( *objectHandle ) == fieldOwnerTypeId )
{ {
// An object is selected, find field with same keyword as the current field being edited fieldsToUpdate.push_back( otherField );
PdmFieldHandle* fieldHandle = objectHandle->findField( editorField->keyword() );
if ( fieldHandle && fieldHandle != editorField )
{
fieldsToUpdate.push_back( fieldHandle );
}
}
else
{
// Todo Remove when dust has settled. Selection manager is not supposed to select single fields
// A field is selected, check if keywords are identical
PdmUiFieldHandle* itemFieldHandle = dynamic_cast<PdmUiFieldHandle*>( item );
if ( itemFieldHandle )
{
PdmFieldHandle* field = itemFieldHandle->fieldHandle();
if ( field && field != editorField && field->keyword() == editorField->keyword() )
{
fieldsToUpdate.push_back( field );
}
}
} }
} }
} }
@ -164,4 +138,47 @@ void PdmUiCommandSystemProxy::populateMenuWithDefaultCommands( const QString& ui
} }
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<PdmFieldHandle*> PdmUiCommandSystemProxy::fieldsFromSelection( const std::type_info& fieldOwnerTypeId,
const QString& fieldKeyword )
{
std::vector<PdmUiItem*> items;
std::vector<PdmFieldHandle*> additionalFieldsToUpdate;
int selectionLevel = 0;
SelectionManager::instance()->selectedItems( items, selectionLevel );
for ( auto& item : items )
{
PdmObjectHandle* objectHandle = dynamic_cast<PdmObjectHandle*>( item );
if ( objectHandle && typeid( *objectHandle ) == fieldOwnerTypeId )
{
// An object is selected, find field with same keyword as the current field being edited
PdmFieldHandle* fieldHandle = objectHandle->findField( fieldKeyword );
if ( fieldHandle )
{
additionalFieldsToUpdate.push_back( fieldHandle );
}
}
else
{
// Todo Remove when dust has settled. Selection manager is not supposed to select single fields
// A field is selected, check if keywords are identical
PdmUiFieldHandle* itemFieldHandle = dynamic_cast<PdmUiFieldHandle*>( item );
if ( itemFieldHandle )
{
PdmFieldHandle* field = itemFieldHandle->fieldHandle();
if ( field && field->keyword() == fieldKeyword )
{
additionalFieldsToUpdate.push_back( field );
}
}
}
}
return additionalFieldsToUpdate;
}
} // end namespace caf } // end namespace caf

View File

@ -36,6 +36,9 @@
#pragma once #pragma once
#include <typeinfo>
#include <vector>
class QVariant; class QVariant;
class QMenu; class QMenu;
class QString; class QString;
@ -59,6 +62,10 @@ public:
void setCurrentContextMenuTargetWidget( QWidget* targetWidget ); void setCurrentContextMenuTargetWidget( QWidget* targetWidget );
void populateMenuWithDefaultCommands( const QString& uiConfigName, QMenu* menu ); void populateMenuWithDefaultCommands( const QString& uiConfigName, QMenu* menu );
private:
static std::vector<PdmFieldHandle*> fieldsFromSelection( const std::type_info& fieldOwnerTypeId,
const QString& fieldKeyword );
private: private:
PdmUiCommandSystemInterface* m_commandInterface; PdmUiCommandSystemInterface* m_commandInterface;
}; };