From f230998fffcffef712426635bdf920d32a2f147f Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 1 Dec 2025 13:09:11 +0100 Subject: [PATCH] #13256 Framework: Make sure labels and buttons are deleted Make sure standalone labels and buttons are deleted between multiple calls to defineUiOrdering. --- .../cafPdmUiFormLayoutObjectEditor.cpp | 44 ++++++++++++------- .../cafPdmUiFormLayoutObjectEditor.h | 2 + 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiFormLayoutObjectEditor.cpp b/Fwk/AppFwk/cafUserInterface/cafPdmUiFormLayoutObjectEditor.cpp index c24f9ee9f5..da9b390511 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiFormLayoutObjectEditor.cpp +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiFormLayoutObjectEditor.cpp @@ -624,33 +624,43 @@ void caf::PdmUiFormLayoutObjectEditor::cleanupBeforeSettingPdmObject() m_groupBoxes.clear(); - for ( auto& label : m_labels ) - { - if ( label ) - { - delete label; - } - } - m_labels.clear(); - - for ( auto& button : m_buttons ) - { - if ( button ) - { - delete button; - } - } - m_buttons.clear(); + deleteLabelsAndButtons(); // Note: Layouts are now managed by Qt's parent-child ownership system. // When added to parent layouts via addLayout(), Qt automatically handles cleanup. } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void caf::PdmUiFormLayoutObjectEditor::deleteLabelsAndButtons() +{ + for ( auto& label : m_labels ) + { + if ( label ) + { + label->deleteLater(); + } + } + m_labels.clear(); + + for ( auto& button : m_buttons ) + { + if ( button ) + { + button->deleteLater(); + } + } + m_buttons.clear(); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void caf::PdmUiFormLayoutObjectEditor::configureAndUpdateUi( const QString& uiConfigName ) { + deleteLabelsAndButtons(); + caf::PdmUiOrdering config; if ( pdmObject() ) { diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiFormLayoutObjectEditor.h b/Fwk/AppFwk/cafUserInterface/cafPdmUiFormLayoutObjectEditor.h index 8891867c5f..1530851f63 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiFormLayoutObjectEditor.h +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiFormLayoutObjectEditor.h @@ -111,6 +111,8 @@ private: QLabel* createLabel( QWidget* parent, const PdmUiLabel& label, const QString& uiConfigName ); QPushButton* createButton( QWidget* parent, const PdmUiButton& button, const QString& uiConfigName ); + void deleteLabelsAndButtons(); + private: std::map m_fieldViews; std::set m_usedFields; ///< used temporarily to store the new(complete) set of used fields