Janitor: Skip undo/redo if field is marked as non-writable

This commit is contained in:
Magne Sjaastad 2023-02-17 08:26:35 +01:00
parent ac9b9b2699
commit 320ece44dd
4 changed files with 30 additions and 7 deletions

View File

@ -44,6 +44,7 @@
#include "cafPdmFieldHandle.h"
#include "cafPdmObjectHandle.h"
#include "cafPdmUiObjectHandle.h"
#include "cafPdmXmlFieldHandle.h"
#include "cafSelectionManager.h"
#include <QMenu>
@ -61,6 +62,21 @@ CmdUiCommandSystemImpl::CmdUiCommandSystemImpl()
m_disableUndoForFieldChange = false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool CmdUiCommandSystemImpl::isFieldWritable( PdmFieldHandle* fieldToUpdate ) const
{
if ( !fieldToUpdate ) return false;
auto xmlCapability = fieldToUpdate->xmlCapability();
if ( !xmlCapability ) return false;
if ( !xmlCapability->isIOWritable() ) return false;
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -48,6 +48,7 @@ class CmdUiCommandSystemImpl : public PdmUiCommandSystemInterface
public:
CmdUiCommandSystemImpl();
bool isFieldWritable( PdmFieldHandle* fieldToUpdate ) const override;
void fieldChangedCommand( const std::vector<PdmFieldHandle*>& fieldsToUpdate, const QVariant& newUiValue ) override;
void setCurrentContextMenuTargetWidget( QWidget* targetWidget ) override;
void populateMenuWithDefaultCommands( const QString& uiConfigName, QMenu* menu ) override;

View File

@ -51,6 +51,7 @@ class PdmUiFieldHandle;
class PdmUiCommandSystemInterface
{
public:
virtual bool isFieldWritable( PdmFieldHandle* fieldToUpdate ) const = 0;
virtual void fieldChangedCommand( const std::vector<PdmFieldHandle*>& fieldsToUpdate, const QVariant& newUiValue ) = 0;
virtual void setCurrentContextMenuTargetWidget( QWidget* targetWidget ) = 0;

View File

@ -102,16 +102,21 @@ void PdmUiCommandSystemProxy::setUiValueToField( PdmUiFieldHandle* uiFieldHandle
}
}
if ( m_commandInterface )
if ( m_commandInterface && !fieldsToUpdate.empty() )
{
caf::PdmUiObjectHandle* uiOwnerObjectHandle = uiObj( editorField->ownerObject() );
if ( uiOwnerObjectHandle && uiOwnerObjectHandle->useUndoRedoForFieldChanged() )
auto firstField = fieldsToUpdate.front();
if ( m_commandInterface->isFieldWritable( firstField ) )
{
m_commandInterface->fieldChangedCommand( fieldsToUpdate, newUiValue );
return;
caf::PdmUiObjectHandle* uiOwnerObjectHandle = uiObj( editorField->ownerObject() );
if ( uiOwnerObjectHandle && uiOwnerObjectHandle->useUndoRedoForFieldChanged() )
{
m_commandInterface->fieldChangedCommand( fieldsToUpdate, newUiValue );
return;
}
}
}
// Fallback to update field values without undo/redo support
for ( auto fieldHandle : fieldsToUpdate )
{
fieldHandle->uiCapability()->setValueFromUiEditor( newUiValue, true );
@ -186,8 +191,8 @@ std::vector<PdmFieldHandle*> PdmUiCommandSystemProxy::fieldsFromSelection( PdmFi
else
{
// Search one level in the project tree for fields in child objects
// Searching in deeper levels is currently not supported, and is considered difficult to match correctly
// and robust
// Searching in deeper levels is currently not supported, and is considered difficult to match
// correctly and robust
//
// Check for identical owner class to guard for matching field names in multiple child objects of a
// different type