From 7621086367e4fa8b4205789cb7406a355770e01f Mon Sep 17 00:00:00 2001 From: Matthias Puchner <github@mpuchner.de> Date: Thu, 21 Oct 2021 12:25:44 +0200 Subject: [PATCH] enhance ParticleCoreShellItem to allow un-setting core & shell --- GUI/Models/ParticleCoreShellItem.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/GUI/Models/ParticleCoreShellItem.cpp b/GUI/Models/ParticleCoreShellItem.cpp index 036d22182f8..d69c70a60e7 100644 --- a/GUI/Models/ParticleCoreShellItem.cpp +++ b/GUI/Models/ParticleCoreShellItem.cpp @@ -66,9 +66,15 @@ ParticleItem* ParticleCoreShellItem::core() const return dynamic_cast<ParticleItem*>(getItem(T_CORE)); } -void ParticleCoreShellItem::setCore(ParticleItem* core) +void ParticleCoreShellItem::setCore(ParticleItem* newCore) { - model()->moveItem(core, this, -1, T_CORE); + if (newCore == nullptr) { + if (core() != nullptr) + model()->removeItem(core()); + return; + } + + model()->moveItem(newCore, this, -1, T_CORE); } ParticleItem* ParticleCoreShellItem::createCore() @@ -86,9 +92,15 @@ ParticleItem* ParticleCoreShellItem::shell() const return dynamic_cast<ParticleItem*>(getItem(T_SHELL)); } -void ParticleCoreShellItem::setShell(ParticleItem* shell) +void ParticleCoreShellItem::setShell(ParticleItem* newShell) { - model()->moveItem(shell, this, -1, T_SHELL); + if (newShell == nullptr) { + if (shell() != nullptr) + model()->removeItem(shell()); + return; + } + + model()->moveItem(newShell, this, -1, T_SHELL); } ParticleItem* ParticleCoreShellItem::createShell() -- GitLab