diff --git a/Fwk/AppFwk/cafCommandFeatures/ToggleCommands/cafToggleItemsFeatureImpl.cpp b/Fwk/AppFwk/cafCommandFeatures/ToggleCommands/cafToggleItemsFeatureImpl.cpp index 7994eb173d..695fe977bb 100644 --- a/Fwk/AppFwk/cafCommandFeatures/ToggleCommands/cafToggleItemsFeatureImpl.cpp +++ b/Fwk/AppFwk/cafCommandFeatures/ToggleCommands/cafToggleItemsFeatureImpl.cpp @@ -38,6 +38,7 @@ #include "cafCmdFeatureManager.h" #include "cafPdmField.h" +#include "cafPdmSetFieldValue.h" #include "cafPdmUiFieldHandle.h" #include "cafPdmUiItem.h" #include "cafPdmUiObjectHandle.h" @@ -142,9 +143,9 @@ void ToggleItemsFeatureImpl::setObjectToggleStateForSelection( SelectionToggleTy { caf::PdmField* field = dynamic_cast*>( uiObjectHandleChild->objectToggleField() ); - if ( state == TOGGLE_ON ) field->setValueWithFieldChanged( true ); - if ( state == TOGGLE_OFF ) field->setValueWithFieldChanged( false ); - if ( state == TOGGLE_SUBITEMS ) field->setValueWithFieldChanged( !( field->v() ) ); + if ( state == TOGGLE_ON ) caf::setValueWithFieldChanged( field, true ); + if ( state == TOGGLE_OFF ) caf::setValueWithFieldChanged( field, false ); + if ( state == TOGGLE_SUBITEMS ) caf::setValueWithFieldChanged( field, !( field->v() ) ); } } } @@ -158,11 +159,11 @@ void ToggleItemsFeatureImpl::setObjectToggleStateForSelection( SelectionToggleTy { caf::PdmField* field = dynamic_cast*>( uiObjectHandle->objectToggleField() ); - if ( state == TOGGLE_ON ) field->setValueWithFieldChanged( true ); - if ( state == TOGGLE_OFF ) field->setValueWithFieldChanged( false ); + if ( state == TOGGLE_ON ) caf::setValueWithFieldChanged( field, true ); + if ( state == TOGGLE_OFF ) caf::setValueWithFieldChanged( field, false ); if ( state == TOGGLE_SUBITEMS || state == TOGGLE ) { - field->setValueWithFieldChanged( !( field->v() ) ); + caf::setValueWithFieldChanged( field, !( field->v() ) ); } } } diff --git a/Fwk/AppFwk/cafCommandFeatures/ToggleCommands/cafToggleItemsOnOthersOffFeature.cpp b/Fwk/AppFwk/cafCommandFeatures/ToggleCommands/cafToggleItemsOnOthersOffFeature.cpp index e9444595ac..59be2e9a58 100644 --- a/Fwk/AppFwk/cafCommandFeatures/ToggleCommands/cafToggleItemsOnOthersOffFeature.cpp +++ b/Fwk/AppFwk/cafCommandFeatures/ToggleCommands/cafToggleItemsOnOthersOffFeature.cpp @@ -42,6 +42,7 @@ #include "cafPdmObject.h" #include "cafPdmObjectHandle.h" +#include "cafPdmSetFieldValue.h" #include "cafPdmUiItem.h" #include @@ -82,7 +83,7 @@ void ToggleItemsOnOthersOffFeature::onActionTriggered( bool isChecked ) if ( field ) { - field->setValueWithFieldChanged( false ); + caf::setValueWithFieldChanged( field, false ); } } @@ -91,7 +92,7 @@ void ToggleItemsOnOthersOffFeature::onActionTriggered( bool isChecked ) { caf::PdmField* field = dynamic_cast*>( selectedObject->objectToggleField() ); - field->setValueWithFieldChanged( true ); + caf::setValueWithFieldChanged( field, true ); } } diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/CMakeLists.txt b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/CMakeLists.txt index b33de76ebe..6f1b6498ec 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/CMakeLists.txt +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/CMakeLists.txt @@ -38,6 +38,7 @@ set(PROJECT_FILES cafPdmFieldCapability.h cafPdmFieldHandle.cpp cafPdmFieldHandle.h + cafPdmSetFieldValue.h cafPdmObjectCapability.h cafPdmFieldReorderCapability.cpp cafPdmFieldReorderCapability.h diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmDataValueField.h b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmDataValueField.h index 490028b3cf..098682ef6c 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmDataValueField.h +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmDataValueField.h @@ -41,7 +41,6 @@ #include "cafAssert.h" #include "cafInternalPdmValueFieldSpecializations.h" -#include "cafPdmUiFieldHandleInterface.h" #include @@ -95,7 +94,6 @@ public: CAF_ASSERT( isInitializedByInitFieldMacro() ); m_fieldValue = fieldValue; } - void setValueWithFieldChanged( const DataType& fieldValue ); // Implementation of PdmValueField interface @@ -137,29 +135,4 @@ protected: DataType m_defaultFieldValue; }; -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -template -void caf::PdmDataValueField::setValueWithFieldChanged( const DataType& fieldValue ) -{ - CAF_ASSERT( isInitializedByInitFieldMacro() ); - - PdmUiFieldHandleInterface* uiFieldHandleInterface = capability(); - if ( uiFieldHandleInterface ) - { - QVariant oldValue = uiFieldHandleInterface->toUiBasedQVariant(); - - m_fieldValue = fieldValue; - - QVariant newUiBasedQVariant = uiFieldHandleInterface->toUiBasedQVariant(); - - uiFieldHandleInterface->notifyFieldChanged( oldValue, newUiBasedQVariant ); - } - else - { - m_fieldValue = fieldValue; - } -} - } // End of namespace caf diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmSetFieldValue.h b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmSetFieldValue.h new file mode 100644 index 0000000000..f47bdb0790 --- /dev/null +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmSetFieldValue.h @@ -0,0 +1,65 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2023 Ceetron Solutions AS +// +// This library may be used under the terms of either the GNU General Public License or +// the GNU Lesser General Public License as follows: +// +// GNU General Public License Usage +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +// GNU Lesser General Public License Usage +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU Lesser General Public License at <> +// for more details. +// +//################################################################################################## + +#pragma once + +#include "cafPdmFieldHandle.h" +#include "cafPdmUiFieldHandleInterface.h" + +namespace caf +{ + +// This is a template function, and auto is used to allow the compiler to deduce the type of the arguments +void setValueWithFieldChanged( auto fieldHandle, auto fieldValue ) +{ + PdmUiFieldHandleInterface* uiFieldHandleInterface = fieldHandle->capability(); + + if ( uiFieldHandleInterface ) + { + QVariant oldValue = uiFieldHandleInterface->toUiBasedQVariant(); + + fieldHandle->setValue( fieldValue ); + + QVariant newUiBasedQVariant = uiFieldHandleInterface->toUiBasedQVariant(); + + uiFieldHandleInterface->notifyFieldChanged( oldValue, newUiBasedQVariant ); + } + else + { + fieldHandle->setValue( fieldValue ); + } +} +} // end namespace caf