Make sure onChildrenUpdated is called in RicToggleItemsOnOthersOffFeature

This commit is contained in:
Magne Sjaastad 2024-05-03 09:50:04 +02:00
parent aea804b161
commit 24aa7fca3e
2 changed files with 15 additions and 2 deletions

View File

@ -52,10 +52,10 @@ public:
static QString findCollectionName( SelectionToggleType state );
static std::pair<caf::PdmObjectHandle*, caf::PdmChildArrayFieldHandle*> findOwnerAndChildArrayField( caf::PdmFieldHandle* fieldHandle );
private:
static caf::PdmUiTreeView* findTreeView( const caf::PdmUiItem* uiItem );
static caf::PdmUiTreeOrdering* findTreeItemFromSelectedUiItem( const caf::PdmUiItem* uiItem );
static std::vector<caf::PdmField<bool>*> findToggleFieldsFromSelection( SelectionToggleType state );
static std::pair<caf::PdmObjectHandle*, caf::PdmChildArrayFieldHandle*> findOwnerAndChildArrayField( caf::PdmFieldHandle* fieldHandle );
};

View File

@ -55,12 +55,16 @@ void RicToggleItemsOnOthersOffFeature::onActionTriggered( bool isChecked )
// First toggle off all siblings
caf::PdmFieldHandle* commonParent = commonParentForAllSelections( selectedObjects );
caf::PdmFieldHandle* firstField = nullptr;
for ( caf::PdmObjectHandle* child : childObjects( commonParent ) )
{
caf::PdmField<bool>* field = objectToggleField( child );
if ( field )
{
if ( !firstField ) firstField = field;
// Avoid calling setValueWithFieldChanged() here, as this potentially can trigger heavy computations. Assume
// that the update logic is sufficient when setting the selected objects.
field->setValue( false );
@ -74,6 +78,15 @@ void RicToggleItemsOnOthersOffFeature::onActionTriggered( bool isChecked )
field->setValueWithFieldChanged( true );
}
// If multiple fields are updated, we call onChildrenUpdated() on the owner of the first field
// Example: Trigger replot of curves when multiple curves are toggled
auto [ownerOfChildArrayField, childArrayFieldHandle] = RicToggleItemsFeatureImpl::findOwnerAndChildArrayField( firstField );
if ( ownerOfChildArrayField && childArrayFieldHandle )
{
std::vector<caf::PdmObjectHandle*> objs;
ownerOfChildArrayField->onChildrenUpdated( childArrayFieldHandle, objs );
}
}
//--------------------------------------------------------------------------------------------------