From 66cec707187d68e16c91459af6bf9fd9178cd1ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Wed, 27 Jun 2018 13:13:24 +0200 Subject: [PATCH] AppFwk: Support field changed on multiple objects in general. Not only inside the command framework on CURRENT selection --- .../cafCommand/cafCmdUiCommandSystemImpl.cpp | 40 ++-------------- .../cafCommand/cafCmdUiCommandSystemImpl.h | 4 +- .../cafInternalPdmUiCommandSystemInterface.h | 4 +- .../cafPdmUiCommandSystemProxy.cpp | 48 ++++++++++++++++++- 4 files changed, 54 insertions(+), 42 deletions(-) diff --git a/Fwk/AppFwk/cafCommand/cafCmdUiCommandSystemImpl.cpp b/Fwk/AppFwk/cafCommand/cafCmdUiCommandSystemImpl.cpp index cfc18684fd..574c5a8954 100644 --- a/Fwk/AppFwk/cafCommand/cafCmdUiCommandSystemImpl.cpp +++ b/Fwk/AppFwk/cafCommand/cafCmdUiCommandSystemImpl.cpp @@ -66,43 +66,9 @@ CmdUiCommandSystemImpl::CmdUiCommandSystemImpl() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void CmdUiCommandSystemImpl::fieldChangedCommand(PdmFieldHandle* editorField, const QVariant& newUiValue) +void CmdUiCommandSystemImpl::fieldChangedCommand( const std::vector& fieldsToUpdate, const QVariant& newUiValue) { - std::vector fieldsToUpdate; - fieldsToUpdate.push_back(editorField); - - // For current selection, find all fields with same keyword - { - std::vector items; - SelectionManager::instance()->selectedItems(items, SelectionManager::CURRENT); - - for (size_t i = 0; i < items.size(); i++) - { - PdmObjectHandle* objectHandle = dynamic_cast(items[i]); - if (objectHandle) - { - // 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) - { - fieldsToUpdate.push_back(fieldHandle); - } - } - else - { - // A field is selected, check if keywords are identical - PdmUiFieldHandle* uiFieldHandle = dynamic_cast(items[i]); - if (uiFieldHandle) - { - PdmFieldHandle* field = uiFieldHandle->fieldHandle(); - if (field && field != editorField && field->keyword() == editorField->keyword()) - { - fieldsToUpdate.push_back(field); - } - } - } - } - } + if ( fieldsToUpdate.empty() ) return; std::vector commands; @@ -136,7 +102,7 @@ void CmdUiCommandSystemImpl::fieldChangedCommand(PdmFieldHandle* editorField, co } } - caf::PdmUiObjectHandle* uiOwnerObjectHandle = uiObj(editorField->ownerObject()); + caf::PdmUiObjectHandle* uiOwnerObjectHandle = uiObj(fieldsToUpdate[0]->ownerObject()); if (uiOwnerObjectHandle && !uiOwnerObjectHandle->useUndoRedoForFieldChanged()) { // Temporarily disable undo framework as requested by the PdmUiObjectHandle diff --git a/Fwk/AppFwk/cafCommand/cafCmdUiCommandSystemImpl.h b/Fwk/AppFwk/cafCommand/cafCmdUiCommandSystemImpl.h index 40fb1c787d..5c4948cedb 100644 --- a/Fwk/AppFwk/cafCommand/cafCmdUiCommandSystemImpl.h +++ b/Fwk/AppFwk/cafCommand/cafCmdUiCommandSystemImpl.h @@ -38,7 +38,7 @@ #pragma once #include "cafInternalPdmUiCommandSystemInterface.h" - +#include namespace caf { @@ -50,7 +50,7 @@ class CmdUiCommandSystemImpl : public PdmUiCommandSystemInterface public: CmdUiCommandSystemImpl(); - virtual void fieldChangedCommand(PdmFieldHandle* field, const QVariant& newUiValue); + virtual void fieldChangedCommand(const std::vector& fieldsToUpdate, const QVariant& newUiValue); virtual void populateMenuWithDefaultCommands(const QString& uiConfigName, QMenu* menu); bool isUndoEnabled(); diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafInternalPdmUiCommandSystemInterface.h b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafInternalPdmUiCommandSystemInterface.h index 07f247fef7..89ebc8b453 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafInternalPdmUiCommandSystemInterface.h +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafInternalPdmUiCommandSystemInterface.h @@ -36,6 +36,8 @@ #pragma once +#include + class QVariant; class QMenu; class QString; @@ -50,7 +52,7 @@ class PdmUiFieldHandle; class PdmUiCommandSystemInterface { public: - virtual void fieldChangedCommand(PdmFieldHandle* field, const QVariant& newUiValue) = 0; + virtual void fieldChangedCommand( const std::vector& fieldsToUpdate, const QVariant& newUiValue) = 0; virtual void populateMenuWithDefaultCommands(const QString& uiConfigName, QMenu* menu) = 0; }; diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiCommandSystemProxy.cpp b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiCommandSystemProxy.cpp index 810ad8a96d..a49d30bba0 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiCommandSystemProxy.cpp +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiCommandSystemProxy.cpp @@ -42,6 +42,7 @@ #include "cafPdmObjectHandle.h" #include "cafPdmUiFieldHandle.h" #include "cafPdmUiObjectHandle.h" +#include "cafSelectionManager.h" #include @@ -83,13 +84,56 @@ void PdmUiCommandSystemProxy::setUiValueToField(PdmUiFieldHandle* uiFieldHandle, { if (uiFieldHandle) { + // Handle editing multiple objects when several objects are selected + PdmFieldHandle* editorField = uiFieldHandle->fieldHandle(); + std::vector fieldsToUpdate; + fieldsToUpdate.push_back(editorField); + + // For current selection, find all fields with same keyword + { + std::vector items; + SelectionManager::instance()->selectedItems(items, SelectionManager::CURRENT); + SelectionManager::instance()->selectedItems(items, SelectionManager::APPLICATION_GLOBAL); + + for (size_t i = 0; i < items.size(); i++) + { + PdmObjectHandle* objectHandle = dynamic_cast(items[i]); + if (objectHandle) + { + // 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) + { + 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* uiFieldHandle = dynamic_cast(items[i]); + if (uiFieldHandle) + { + PdmFieldHandle* field = uiFieldHandle->fieldHandle(); + if (field && field != editorField && field->keyword() == editorField->keyword()) + { + fieldsToUpdate.push_back(field); + } + } + } + } + } + if (m_commandInterface) { - m_commandInterface->fieldChangedCommand(uiFieldHandle->fieldHandle(), newUiValue); + m_commandInterface->fieldChangedCommand(fieldsToUpdate, newUiValue); } else { - uiFieldHandle->setValueFromUiEditor(newUiValue); + for (auto fieldHandle : fieldsToUpdate) + { + fieldHandle->uiCapability()->setValueFromUiEditor(newUiValue); + } } } }