diff --git a/ztools/ztools/commands/datum_commands.py b/ztools/ztools/commands/datum_commands.py index 981d456..1e3c6fb 100644 --- a/ztools/ztools/commands/datum_commands.py +++ b/ztools/ztools/commands/datum_commands.py @@ -458,11 +458,24 @@ class DatumCreatorTaskPanel: self.update_params_ui(mode_id) return + def _clear_params_layout(self): + """Remove all rows from params_layout without deleting the widgets. + + QFormLayout.removeRow() destroys the widgets it owns. Instead we + detach every item from the layout (which relinquishes ownership) + and hide the widgets so they can be re-added later. + """ + while self.params_layout.count(): + item = self.params_layout.takeAt(0) + widget = item.widget() + if widget is not None: + widget.hide() + widget.setParent(None) + def update_params_ui(self, mode_id): """Update parameters UI based on mode.""" - # Clear existing params - while self.params_layout.rowCount() > 0: - self.params_layout.removeRow(0) + # Clear existing params without destroying widgets + self._clear_params_layout() if mode_id is None: self.params_group.setVisible(False) @@ -471,18 +484,26 @@ class DatumCreatorTaskPanel: self.params_group.setVisible(True) if mode_id in ("offset_face", "offset_plane"): + self.offset_spin.show() self.params_layout.addRow("Offset:", self.offset_spin) elif mode_id == "angled": + self.angle_spin.show() self.params_layout.addRow("Angle:", self.angle_spin) elif mode_id == "normal_edge": + self.param_spin.show() self.params_layout.addRow("Position (0-1):", self.param_spin) elif mode_id == "tangent_cyl": + self.angle_spin.show() self.params_layout.addRow("Angle:", self.angle_spin) elif mode_id == "point_xyz": + self.x_spin.show() + self.y_spin.show() + self.z_spin.show() self.params_layout.addRow("X:", self.x_spin) self.params_layout.addRow("Y:", self.y_spin) self.params_layout.addRow("Z:", self.z_spin) elif mode_id == "point_edge": + self.param_spin.show() self.params_layout.addRow("Position (0-1):", self.param_spin) else: # No parameters needed