diff --git a/GUI/Models/ItemCatalog.cpp b/GUI/Models/ItemCatalog.cpp index cfd686e553f1f77bfba959cd19c956883f8d9c1f..abf2c9d12b0b95153b5bf7d02df3516e2f079e9e 100644 --- a/GUI/Models/ItemCatalog.cpp +++ b/GUI/Models/ItemCatalog.cpp @@ -63,7 +63,7 @@ ItemCatalog::ItemCatalog() { - add("MultiLayer", create_new<MultiLayerItem>); + addItem<MultiLayerItem>(); addItem<LayerItem>(); add("ParticleLayout", create_new<ParticleLayoutItem>); add("Particle", create_new<ParticleItem>); @@ -251,7 +251,7 @@ std::unique_ptr<SessionItem> ItemCatalog::createItemPtr(const QString& modelType QStringList ItemCatalog::validTopItemTypes() { - return {"MultiLayer", + return {MultiLayerItem::M_TYPE, LayerItem::M_TYPE, "ParticleLayout", "Particle", diff --git a/GUI/Models/JobItem.cpp b/GUI/Models/JobItem.cpp index 4d705c6aaceff3dfc116acffa041212b2bad3e35..ad38ba6db20f74c4943e82bca94f253f6fd37602 100644 --- a/GUI/Models/JobItem.cpp +++ b/GUI/Models/JobItem.cpp @@ -71,7 +71,7 @@ JobItem::JobItem() : SessionItem(M_TYPE) addProperty(P_PROGRESS, 0)->setVisible(false); addProperty(P_PRESENTATION_TYPE, QVariant::Type::Invalid)->setVisible(false); - registerTag(T_SAMPLE, 1, 1, QStringList() << "MultiLayer"); + registerTag(T_SAMPLE, 1, 1, {MultiLayerItem::M_TYPE}); registerTag(T_MATERIAL_CONTAINER, 1, 1, {MaterialItemContainer::M_TYPE}); registerTag(T_INSTRUMENT, 1, 1, {GISASInstrumentItem::M_TYPE, OffSpecularInstrumentItem::M_TYPE, diff --git a/GUI/Models/JobModelFunctions.cpp b/GUI/Models/JobModelFunctions.cpp index 6a22ba7efc299a6d12f2f87ec12b0a710ecc491d..13dcf8c93a1f286abb81f7d80843fbde1f88f888 100644 --- a/GUI/Models/JobModelFunctions.cpp +++ b/GUI/Models/JobModelFunctions.cpp @@ -78,7 +78,7 @@ void GUI::Model::JobFunctions::setupJobItemSampleData(JobItem* jobItem, const MultiLayerItem* sampleItem) { MultiLayerItem* multilayer = jobItem->copySampleIntoJob(sampleItem); - multilayer->setItemName("MultiLayer"); + multilayer->setItemName(MultiLayerItem::M_TYPE); // copying materials MaterialItemContainer* container = jobItem->createMaterialContainer(); diff --git a/GUI/Models/LayerItem.cpp b/GUI/Models/LayerItem.cpp index aebbca8180f347d0daae7515440aaab2cf6135d6..0f0119ec57113a5c4d6d4d14a2e73ad1786374fc 100644 --- a/GUI/Models/LayerItem.cpp +++ b/GUI/Models/LayerItem.cpp @@ -14,6 +14,7 @@ #include "GUI/Models/LayerItem.h" #include "GUI/Models/MaterialItemUtils.h" +#include "GUI/Models/MultiLayerItem.h" #include "GUI/Models/ParticleLayoutItem.h" namespace { @@ -107,7 +108,7 @@ QVector<ParticleLayoutItem*> LayerItem::layouts() const void LayerItem::updateAppearance(SessionItem* new_parent) { if (!new_parent) { - if (parent() && parent()->modelType() == "MultiLayer") { + if (parent() && parent()->hasModelType<MultiLayerItem>()) { // we are about to be removed from MultiLayer getItem(LayerItem::P_ROUGHNESS)->setEnabled(true); getItem(LayerItem::P_THICKNESS)->setEnabled(true); diff --git a/GUI/Models/MultiLayerItem.cpp b/GUI/Models/MultiLayerItem.cpp index ec1a83cea0cb8375acfebb2720dbcf9a2196aa19..edc098ac656e57aa61e1415a9435c996aa63f80c 100644 --- a/GUI/Models/MultiLayerItem.cpp +++ b/GUI/Models/MultiLayerItem.cpp @@ -25,10 +25,12 @@ const QString MultiLayerItem::P_CROSS_CORR_LENGTH = const QString MultiLayerItem::P_EXTERNAL_FIELD = "ExternalField"; const QString MultiLayerItem::T_LAYERS = "Layer tag"; -MultiLayerItem::MultiLayerItem() : SessionGraphicsItem("MultiLayer") +const QString MultiLayerItem::M_TYPE = "MultiLayer"; + +MultiLayerItem::MultiLayerItem() : SessionGraphicsItem(M_TYPE) { setToolTip("A multilayer to hold stack of layers"); - setItemName("MultiLayer"); + setItemName(M_TYPE); addProperty(P_CROSS_CORR_LENGTH, 0.0) ->setDecimals(5) diff --git a/GUI/Models/MultiLayerItem.h b/GUI/Models/MultiLayerItem.h index d937ff0e1891383d01f173d9445545f557144499..6a8d3ccd606febb3f85f60fa84ec58e3fa59fef4 100644 --- a/GUI/Models/MultiLayerItem.h +++ b/GUI/Models/MultiLayerItem.h @@ -22,6 +22,9 @@ public: static const QString P_CROSS_CORR_LENGTH; static const QString P_EXTERNAL_FIELD; static const QString T_LAYERS; + + static const QString M_TYPE; + MultiLayerItem(); QVector<SessionItem*> materialPropertyItems(); diff --git a/GUI/Models/SampleValidator.cpp b/GUI/Models/SampleValidator.cpp index e5f74d01944522c4a805ddaa8f63d9cb1608110d..4064624ea1c42fd473c42c21b1145ba42bdcfab8 100644 --- a/GUI/Models/SampleValidator.cpp +++ b/GUI/Models/SampleValidator.cpp @@ -42,7 +42,7 @@ void SampleValidator::validateItem(const SessionItem* item) QString diagnosis; - if (item->modelType() == "MultiLayer") { + if (item->hasModelType<MultiLayerItem>()) { diagnosis = validateMultiLayerItem(item); } else if (item->modelType() == "ParticleLayout") { diagnosis = validateParticleLayoutItem(item); diff --git a/GUI/Views/RealSpaceWidgets/RealSpaceBuilder.cpp b/GUI/Views/RealSpaceWidgets/RealSpaceBuilder.cpp index 43cbefe6b487719cf65bcd94ec689e5e7a98e469..1bd158a9e2e7db9b5ee6070255d6687678f27338 100644 --- a/GUI/Views/RealSpaceWidgets/RealSpaceBuilder.cpp +++ b/GUI/Views/RealSpaceWidgets/RealSpaceBuilder.cpp @@ -48,7 +48,7 @@ void RealSpaceBuilder::populate(RealSpaceModel* model, const SessionItem& item, model->defCamPos = cameraPosition; - if (item.modelType() == "MultiLayer") + if (item.hasModelType<MultiLayerItem>()) populateMultiLayer(model, item, sceneGeometry); else if (item.hasModelType<LayerItem>()) diff --git a/GUI/Views/SampleDesigner/SampleViewAligner.cpp b/GUI/Views/SampleDesigner/SampleViewAligner.cpp index 7a926072ffd2a7ad775cc3184bc120d0567c1e0b..135da05320e857e66a4565efb5fb62855427d909 100644 --- a/GUI/Views/SampleDesigner/SampleViewAligner.cpp +++ b/GUI/Views/SampleDesigner/SampleViewAligner.cpp @@ -14,6 +14,7 @@ #include "GUI/Views/SampleDesigner/SampleViewAligner.h" #include "GUI/Models/LayerItem.h" +#include "GUI/Models/MultiLayerItem.h" #include "GUI/Models/SampleModel.h" #include "GUI/Views/CommonWidgets/StyleUtils.h" #include "GUI/Views/SampleDesigner/DesignerScene.h" @@ -130,7 +131,7 @@ QList<IView*> SampleViewAligner::getConnectedViews(IView* view) } else { connected_items.append(itemOfView->parent()); } - if (itemOfView->modelType() == "MultiLayer") { + if (itemOfView->hasModelType<MultiLayerItem>()) { // MultiLayer will not interact with its Layers, but with they children, e.g. with // ParticleLayouts for (auto child : itemOfView->children()) { diff --git a/GUI/Views/SampleDesigner/SampleViewFactory.cpp b/GUI/Views/SampleDesigner/SampleViewFactory.cpp index 9355ac54236ea07abca6db2bbc8ebff4c7f5fb88..0218f3c828a9f9c6591f6ee4cdb6708cb7c2acd9 100644 --- a/GUI/Views/SampleDesigner/SampleViewFactory.cpp +++ b/GUI/Views/SampleDesigner/SampleViewFactory.cpp @@ -15,6 +15,7 @@ #include "GUI/Views/SampleDesigner/SampleViewFactory.h" #include "GUI/Models/InterferenceFunctionItems.h" #include "GUI/Models/LayerItem.h" +#include "GUI/Models/MultiLayerItem.h" #include "GUI/Views/SampleDesigner/InterferenceFunctionViews.h" #include "GUI/Views/SampleDesigner/LayerView.h" #include "GUI/Views/SampleDesigner/MesoCrystalView.h" @@ -26,7 +27,7 @@ #include "GUI/Views/SampleDesigner/TransformationView.h" QStringList SampleViewFactory::m_valid_item_types = - {"MultiLayer", + {MultiLayerItem::M_TYPE, LayerItem::M_TYPE, "ParticleLayout", "Particle", @@ -52,7 +53,7 @@ bool SampleViewFactory::isValidType(const QString& model_type) IView* SampleViewFactory::createSampleView(const QString& model_type) { - if (model_type == "MultiLayer") { + if (model_type == MultiLayerItem::M_TYPE) { return new MultiLayerView(); } else if (model_type == LayerItem::M_TYPE) { return new LayerView(); diff --git a/GUI/Views/SimulationWidgets/SimulationDataSelectorWidget.cpp b/GUI/Views/SimulationWidgets/SimulationDataSelectorWidget.cpp index 1f0a625704c9ef8138980340e3b317b07d5611d9..2244eee8e3dc6b4a11dee993c758d30ff1a7d16e 100644 --- a/GUI/Views/SimulationWidgets/SimulationDataSelectorWidget.cpp +++ b/GUI/Views/SimulationWidgets/SimulationDataSelectorWidget.cpp @@ -123,7 +123,7 @@ void SimulationDataSelectorWidget::updateViewElements() updateSelection(m_instrumentCombo, GUI::Model::ItemUtils::topItemNames(m_applicationModels->instrumentModel())); updateSelection(m_sampleCombo, GUI::Model::ItemUtils::topItemNames( - m_applicationModels->sampleModel(), "MultiLayer")); + m_applicationModels->sampleModel(), MultiLayerItem::M_TYPE)); updateSelection(m_realDataCombo, GUI::Model::ItemUtils::topItemNames(m_applicationModels->realDataModel()), true); diff --git a/Tests/UnitTests/GUI/TestModelUtils.cpp b/Tests/UnitTests/GUI/TestModelUtils.cpp index 181d4316c134d2774ba1f6663416a5df99081abc..4a056eb4730872026e85bcdee436c45461acdb3b 100644 --- a/Tests/UnitTests/GUI/TestModelUtils.cpp +++ b/Tests/UnitTests/GUI/TestModelUtils.cpp @@ -40,9 +40,9 @@ TEST_F(TestModelUtils, test_topItemNames) item->setItemName("name2"); // checking names of items of certain type - ASSERT_EQ(GUI::Model::ItemUtils::topItemNames(&model, "MultiLayer").size(), 2); - EXPECT_EQ(GUI::Model::ItemUtils::topItemNames(&model, "MultiLayer").at(0), "name1"); - EXPECT_EQ(GUI::Model::ItemUtils::topItemNames(&model, "MultiLayer").at(1), "name2"); + ASSERT_EQ(GUI::Model::ItemUtils::topItemNames(&model, MultiLayerItem::M_TYPE).size(), 2); + EXPECT_EQ(GUI::Model::ItemUtils::topItemNames(&model, MultiLayerItem::M_TYPE).at(0), "name1"); + EXPECT_EQ(GUI::Model::ItemUtils::topItemNames(&model, MultiLayerItem::M_TYPE).at(1), "name2"); // checking names of all top items QStringList expected = {"name1", "Layer", "name2"};