From 0efd9c7f7dc59c11d4bcb47ecc3ac03592b75b86 Mon Sep 17 00:00:00 2001
From: Matthias Puchner <github@mpuchner.de>
Date: Sat, 18 Dec 2021 10:29:04 +0100
Subject: [PATCH] free ParticleCoreShellForm from SessionItem

---
 .../SampleDesigner/ParticleCoreShellForm.cpp  | 32 +++++++------------
 1 file changed, 12 insertions(+), 20 deletions(-)

diff --git a/GUI/View/SampleDesigner/ParticleCoreShellForm.cpp b/GUI/View/SampleDesigner/ParticleCoreShellForm.cpp
index dbf1012010f..37c5fee8bd4 100644
--- a/GUI/View/SampleDesigner/ParticleCoreShellForm.cpp
+++ b/GUI/View/SampleDesigner/ParticleCoreShellForm.cpp
@@ -13,6 +13,7 @@
 //  ************************************************************************************************
 
 #include "GUI/View/SampleDesigner/ParticleCoreShellForm.h"
+#include "GUI/Model/Sample/FormFactorItemCatalog.h"
 #include "GUI/Model/Sample/FormFactorItems.h"
 #include "GUI/Model/Sample/ParticleCoreShellItem.h"
 #include "GUI/Model/Sample/ParticleItem.h"
@@ -22,7 +23,6 @@
 #include "GUI/View/SampleDesigner/SampleEditorController.h"
 #include "GUI/View/SampleDesigner/SelectionContainerForm.h"
 #include "GUI/View/Tool/GroupBoxCollapser.h"
-
 #include <QAction>
 #include <QComboBox>
 #include <memory>
@@ -31,21 +31,17 @@ namespace {
 
 QComboBox* createFormFactorCombo(QWidget* parent, FormFactorItem* current)
 {
+    ASSERT(current);
     auto* combo = new QComboBox(parent);
     WheelEventEater::install(combo);
     combo->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
 
-    combo->addItem(QIcon(), "None", "");
-    for (const auto& modelType : ItemCatalog::formfactorTypes()) {
-        const auto ui = ItemCatalog::instance().uiInfo(modelType);
-        combo->addItem(QIcon(ui.iconPath), ui.menuEntry, modelType);
+    for (const auto type : FormFactorItemCatalog::types()) {
+        const auto ui = FormFactorItemCatalog::uiInfo(type);
+        combo->addItem(QIcon(ui.iconPath), ui.menuEntry, (uint8_t)type);
     }
     combo->setMaxVisibleItems(combo->count());
-
-    if (current == nullptr)
-        combo->setCurrentIndex(0);
-    else
-        combo->setCurrentIndex(combo->findData(current->modelType()));
+    combo->setCurrentIndex(combo->findData((uint8_t)FormFactorItemCatalog::type(current)));
 
     return combo;
 }
@@ -131,8 +127,8 @@ void ParticleCoreShellForm::onCoreComboChanged()
     while (core.layouter->layout()->rowCount() > 1)
         core.layouter->layout()->removeRow(1);
 
-    const QString newClassName = core.formfactorCombo->currentData().toString();
-    m_ec->setCoreFormFactor(this, newClassName);
+    const auto type = (FormFactorItemCatalog::Type)core.formfactorCombo->currentData().toUInt();
+    m_ec->setCoreFormFactor(this, type);
 }
 
 void ParticleCoreShellForm::onShellComboChanged()
@@ -140,8 +136,8 @@ void ParticleCoreShellForm::onShellComboChanged()
     while (shell.layouter->layout()->rowCount() > 1)
         shell.layouter->layout()->removeRow(1);
 
-    const QString newClassName = shell.formfactorCombo->currentData().toString();
-    m_ec->setShellFormFactor(this, newClassName);
+    const auto type = (FormFactorItemCatalog::Type)shell.formfactorCombo->currentData().toUInt();
+    m_ec->setShellFormFactor(this, type);
 }
 
 void ParticleCoreShellForm::showCoreInRealSpace()
@@ -161,9 +157,7 @@ void ParticleCoreShellForm::createCoreWidgets()
     QString groupTitle = "Core";
 
     if (ParticleItem* particle = m_item->core()) {
-        const QString formfactor =
-            particle->formfactorItem()->value().value<ComboProperty>().getValue();
-
+        const QString formfactor = FormFactorItemCatalog::menuEntry(particle->formfactor());
         groupTitle += " (" + formfactor + ")";
 
         core.layouter->addGroupOfValues("Geometry", particle->formfactor()->geometryValues());
@@ -180,9 +174,7 @@ void ParticleCoreShellForm::createShellWidgets()
     QString groupTitle = "Shell";
 
     if (ParticleItem* particle = m_item->shell()) {
-        const QString formfactor =
-            particle->formfactorItem()->value().value<ComboProperty>().getValue();
-
+        const QString formfactor = FormFactorItemCatalog::menuEntry(particle->formfactor());
         groupTitle += " (" + formfactor + ")";
 
         shell.layouter->addGroupOfValues("Geometry", particle->formfactor()->geometryValues());
-- 
GitLab