mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#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:
parent
c690c9fa53
commit
4cb59aa1d0
@ -45,7 +45,6 @@
|
||||
#include "cafSelectionManager.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <typeinfo>
|
||||
|
||||
namespace caf
|
||||
{
|
||||
@ -80,7 +79,7 @@ void PdmUiCommandSystemProxy::setCommandInterface( PdmUiCommandSystemInterface*
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiCommandSystemProxy::setUiValueToField( PdmUiFieldHandle* uiFieldHandle, const QVariant& newUiValue )
|
||||
{
|
||||
if ( uiFieldHandle )
|
||||
if ( uiFieldHandle && uiFieldHandle->fieldHandle() )
|
||||
{
|
||||
// Handle editing multiple objects when several objects are selected
|
||||
PdmFieldHandle* editorField = uiFieldHandle->fieldHandle();
|
||||
@ -89,41 +88,16 @@ void PdmUiCommandSystemProxy::setUiValueToField( PdmUiFieldHandle* uiFieldHandle
|
||||
std::vector<PdmFieldHandle*> fieldsToUpdate;
|
||||
fieldsToUpdate.push_back( editorField );
|
||||
|
||||
// For level 1 selection, find all fields with same 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
|
||||
// multi selection edit For now we only makes sure we have same owner object type
|
||||
{
|
||||
std::vector<PdmUiItem*> items;
|
||||
std::vector<PdmFieldHandle*> otherSelectedFields = fieldsFromSelection( fieldOwnerTypeId, editorField->keyword() );
|
||||
|
||||
int selectionLevel = 0;
|
||||
SelectionManager::instance()->selectedItems( items, selectionLevel );
|
||||
|
||||
for ( auto& item : items )
|
||||
// If current edited field is part of the selection, update all fields in selection
|
||||
if ( std::find( otherSelectedFields.begin(), otherSelectedFields.end(), editorField ) != otherSelectedFields.end() )
|
||||
{
|
||||
PdmObjectHandle* objectHandle = dynamic_cast<PdmObjectHandle*>( item );
|
||||
if ( objectHandle && typeid( *objectHandle ) == fieldOwnerTypeId )
|
||||
for ( auto otherField : otherSelectedFields )
|
||||
{
|
||||
// An object is selected, find field with same keyword as the current field being edited
|
||||
PdmFieldHandle* fieldHandle = objectHandle->findField( editorField->keyword() );
|
||||
if ( fieldHandle && fieldHandle != editorField )
|
||||
if ( otherField != 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 );
|
||||
}
|
||||
}
|
||||
fieldsToUpdate.push_back( otherField );
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
|
@ -36,6 +36,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <typeinfo>
|
||||
#include <vector>
|
||||
|
||||
class QVariant;
|
||||
class QMenu;
|
||||
class QString;
|
||||
@ -59,6 +62,10 @@ public:
|
||||
void setCurrentContextMenuTargetWidget( QWidget* targetWidget );
|
||||
void populateMenuWithDefaultCommands( const QString& uiConfigName, QMenu* menu );
|
||||
|
||||
private:
|
||||
static std::vector<PdmFieldHandle*> fieldsFromSelection( const std::type_info& fieldOwnerTypeId,
|
||||
const QString& fieldKeyword );
|
||||
|
||||
private:
|
||||
PdmUiCommandSystemInterface* m_commandInterface;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user