diff --git a/GUI/Models/ItemWithMaterial.cpp b/GUI/Models/ItemWithMaterial.cpp index 6ce5f0a8b420ce9654058c2a4b62d5be466a229c..3564c5829b978258cd44deccdc73d27b063aa1eb 100644 --- a/GUI/Models/ItemWithMaterial.cpp +++ b/GUI/Models/ItemWithMaterial.cpp @@ -23,6 +23,11 @@ void ItemWithMaterial::setMaterial(const MaterialItem* materialItem) setItemValue(P_MATERIAL, materialItem->identifier()); } +void ItemWithMaterial::setMaterial(const QString& materialIdentifier) +{ + setItemValue(P_MATERIAL, materialIdentifier); +} + bool ItemWithMaterial::isMaterialPropertyName(const QString& name) { return name == P_MATERIAL; diff --git a/GUI/Models/ItemWithMaterial.h b/GUI/Models/ItemWithMaterial.h index 5860cc4cc34216bfff8ed74d9b5554757fc81660..fac18285505ab3962f5dc002ebaae93e51f2539e 100644 --- a/GUI/Models/ItemWithMaterial.h +++ b/GUI/Models/ItemWithMaterial.h @@ -26,9 +26,14 @@ private: public: static bool isMaterialPropertyName(const QString& name); - //! Set the material this item shall use. Stores the identifier, not the pointer! + //! Set the material this item shall use. + //! Stores the identifier, not the pointer! void setMaterial(const MaterialItem* materialItem); + //! Set the material this item shall use. + //! Stores the given identifier, not a pointer to the material! + void setMaterial(const QString& materialIdentifier); + //! Set "no material defined" void setMaterialUndefined(); diff --git a/GUI/Models/LayerItem.cpp b/GUI/Models/LayerItem.cpp index 74f5aed35ce5a8ea995fae8bc76adad3fc72b639..16dc9bcea1c53aa3672e45271293a070fd99d518 100644 --- a/GUI/Models/LayerItem.cpp +++ b/GUI/Models/LayerItem.cpp @@ -108,6 +108,11 @@ QVector<ParticleLayoutItem*> LayerItem::layouts() const return items<ParticleLayoutItem>(T_LAYOUTS); } +void LayerItem::removeLayout(ParticleLayoutItem* layout) +{ + model()->removeItem(layout); +} + void LayerItem::updateAppearance(SessionItem* new_parent) { if (!new_parent) { diff --git a/GUI/Models/LayerItem.h b/GUI/Models/LayerItem.h index fea1cabf5eec215b827fa16cb68e7cd0508b9a18..8a03fe293b7dd5d8ecb940476919bd006462cfc2 100644 --- a/GUI/Models/LayerItem.h +++ b/GUI/Models/LayerItem.h @@ -49,6 +49,7 @@ public: SessionItem* numSlicesItem() const; QVector<ParticleLayoutItem*> layouts() const; + void removeLayout(ParticleLayoutItem* layout); private: void updateAppearance(SessionItem* new_parent); diff --git a/GUI/Models/MultiLayerItem.cpp b/GUI/Models/MultiLayerItem.cpp index 69d8f6502a9b8a048c9b3bf902d019d8cf94d3ca..156e2ef557517126a7fd5b9db893c4e9a4993b1d 100644 --- a/GUI/Models/MultiLayerItem.cpp +++ b/GUI/Models/MultiLayerItem.cpp @@ -107,6 +107,17 @@ void MultiLayerItem::removeLayer(LayerItem* item) model()->removeItem(item); } + +void MultiLayerItem::moveLayer(LayerItem* item, LayerItem* beforeThisLayer) +{ + int index = -1; // move to end + if (beforeThisLayer != nullptr) { + index = layers().indexOf(beforeThisLayer); + } + + model()->moveItem(item, this, index); +} + void MultiLayerItem::updateLayers() { QVector<LayerItem*> list = childrenOfType<LayerItem>(); diff --git a/GUI/Models/MultiLayerItem.h b/GUI/Models/MultiLayerItem.h index ee079fb7938f0c7b7c6c59b5e4016e9837290371..65a2f2a491e20dfc6719d5b30c6732ad8b9ab914 100644 --- a/GUI/Models/MultiLayerItem.h +++ b/GUI/Models/MultiLayerItem.h @@ -55,6 +55,7 @@ public: LayerItem* addLayer(int index); void removeLayer(LayerItem* item); + void moveLayer(LayerItem* item, LayerItem* beforeThisLayer); private: void updateLayers(); diff --git a/GUI/Models/ParticleCompositionItem.cpp b/GUI/Models/ParticleCompositionItem.cpp index 995e622d7a4e0c680ffc7bffa9abeac90b9f05b2..7445774b4ac90753a902bbddf23700ba964951f6 100644 --- a/GUI/Models/ParticleCompositionItem.cpp +++ b/GUI/Models/ParticleCompositionItem.cpp @@ -89,3 +89,8 @@ void ParticleCompositionItem::addParticle(ItemWithParticles* particle) { model()->moveItem(particle, this, -1, T_PARTICLES); } + +void ParticleCompositionItem::removeParticle(ItemWithParticles* particle) +{ + model()->removeItem(particle); +} diff --git a/GUI/Models/ParticleCompositionItem.h b/GUI/Models/ParticleCompositionItem.h index bca44f32065b832004eebd88c67735f42899fa58..35ca50042cf4b222fe3843f9f3602976885ce784 100644 --- a/GUI/Models/ParticleCompositionItem.h +++ b/GUI/Models/ParticleCompositionItem.h @@ -33,6 +33,7 @@ public: QVector<ItemWithParticles*> particles() const; void addParticle(ItemWithParticles* particle); + void removeParticle(ItemWithParticles* particle); }; #endif // BORNAGAIN_GUI_MODELS_PARTICLECOMPOSITIONITEM_H diff --git a/GUI/Models/ParticleLayoutItem.cpp b/GUI/Models/ParticleLayoutItem.cpp index f4f63dfa2b96ae3ee5f03a796d8149f16311660b..cd83ea3f4fe890946553b36b8b29ad8162b321ba 100644 --- a/GUI/Models/ParticleLayoutItem.cpp +++ b/GUI/Models/ParticleLayoutItem.cpp @@ -108,6 +108,11 @@ void ParticleLayoutItem::addParticle(ItemWithParticles* particle) model()->moveItem(particle, this, -1, T_PARTICLES); } +void ParticleLayoutItem::removeParticle(ItemWithParticles* particle) +{ + model()->removeItem(particle); +} + InterferenceItem* ParticleLayoutItem::interference() const { return dynamic_cast<InterferenceItem*>(getItem(T_INTERFERENCE)); diff --git a/GUI/Models/ParticleLayoutItem.h b/GUI/Models/ParticleLayoutItem.h index 275decfc4d9a1239f637abdb8a58c2cf24467f2e..0b05e37dd3901954cd716020a63a0f1af1f2a16e 100644 --- a/GUI/Models/ParticleLayoutItem.h +++ b/GUI/Models/ParticleLayoutItem.h @@ -41,6 +41,7 @@ public: QVector<ItemWithParticles*> particles() const; void addParticle(ItemWithParticles* particle); + void removeParticle(ItemWithParticles* particle); InterferenceItem* interference() const; template <typename T> T* createInterference(); diff --git a/GUI/Models/SamplesTreeModel.cpp b/GUI/Models/SamplesTreeModel.cpp index 960ed832a9abedcbaa2dce92f1725b18a811c541..0fa9329ccb214debb00f53f98ac1db55e1757ae0 100644 --- a/GUI/Models/SamplesTreeModel.cpp +++ b/GUI/Models/SamplesTreeModel.cpp @@ -14,9 +14,11 @@ #include "GUI/Models/SamplesTreeModel.h" #include "GUI/Application/Application.h" +#include "GUI/Models/GUIExamplesFactory.h" #include "GUI/Models/ModelUtils.h" #include "GUI/Models/MultiLayerItem.h" #include "GUI/Models/SampleModel.h" +#include "GUI/mainwindow/projectmanager.h" #include <QApplication> #include <QFontMetrics> #include <QIcon> @@ -213,3 +215,19 @@ QModelIndex SamplesTreeModel::createSample() endInsertRows(); return indexForItem(multilayer_item); } + +QModelIndex SamplesTreeModel::createSampleFromExamples(const QString& className, + const QString& title, + const QString& description) +{ + const int row = m_sampleModel->multiLayerItems().size(); + beginInsertRows(index(0, 0), row, row); + + auto* sample = dynamic_cast<MultiLayerItem*>(GUIExamplesFactory::createSampleItems( + className, m_sampleModel, ProjectManager::instance()->document()->materialModel())); + sample->setItemName(title); + sample->setDescription(description); + + endInsertRows(); + return indexForItem(sample); +} diff --git a/GUI/Models/SamplesTreeModel.h b/GUI/Models/SamplesTreeModel.h index 071e26133bcaedb41e8f91b343382171c890875f..af65fb27aa6514cabc36ed495337af738acf1cee 100644 --- a/GUI/Models/SamplesTreeModel.h +++ b/GUI/Models/SamplesTreeModel.h @@ -48,6 +48,9 @@ public: //! Create a new sample (multilayer) and return the index of it. QModelIndex createSample(); + QModelIndex createSampleFromExamples(const QString& className, const QString& title, + const QString& description); + private: void clear();