Skip to content
Snippets Groups Projects
Commit 8b71196d authored by Mikhail Svechnikov's avatar Mikhail Svechnikov
Browse files

use PolyPtrExra for LayerComponentItems and ParticleItems

parent 72ddb672
No related branches found
No related tags found
1 merge request!2757Use extra data in PolyPtr to create particles and layer containers (#1031)
Pipeline #170995 passed
......@@ -64,7 +64,7 @@ public:
}
};
//! Holds a polymorphous item which can only be created with extra parameter.
//! Holds a polymorphous item which can only be created with an extra parameter.
template <typename BaseItem, typename Catalog, typename ExtraData>
class PolyPtrExra : public PolyPtrBase<BaseItem, Catalog> {
public:
......
......@@ -103,7 +103,8 @@ ItemWithLayers* LayerStackItem::addNewItemAt(ItemWithLayers* item, int index)
if (index < 0)
index = m_components.size();
auto new_item = new PolyPtr<ItemWithLayers, LayeredComponentCatalog>;
auto new_item =
new PolyPtrExra<ItemWithLayers, LayeredComponentCatalog, MaterialsSet>(m_materials);
new_item->setCertainItem(item); // gets ownership
m_components.insert_at(index, new_item);
return m_components[index]->certainItem();
......@@ -172,7 +173,9 @@ void LayerStackItem::readFrom(QXmlStreamReader* r)
else if (tag == Tag::NumPeriods)
m_n_periods = XML::readTaggedUInt(r, tag);
else if (tag == Tag::Component) {
m_components.push_back(new PolyPtr<ItemWithLayers, LayeredComponentCatalog>);
m_components.push_back(
new PolyPtrExra<ItemWithLayers, LayeredComponentCatalog, MaterialsSet>(
m_materials));
m_components.back()->readFrom(r, m_materials);
XML::gotoEndElementOfTag(r, tag);
} else
......
......@@ -48,7 +48,7 @@ public:
private:
uint m_n_periods;
OwningVector<PolyPtr<ItemWithLayers, LayeredComponentCatalog>> m_components;
OwningVector<PolyPtrExra<ItemWithLayers, LayeredComponentCatalog, MaterialsSet>> m_components;
const MaterialsSet* m_materials;
};
......
......@@ -19,6 +19,8 @@
ItemWithLayers* LayeredComponentCatalog::create(Type type, const MaterialsSet* materials)
{
ASSERT(materials);
switch (type) {
case Type::Layer:
return new LayerItem(materials);
......
......@@ -27,7 +27,7 @@ public:
enum class Type : uint8_t { Layer = 0, LayerStack = 1 };
//! Creates the item of the given type.
static ItemWithLayers* create(Type type, const MaterialsSet* materials = nullptr);
static ItemWithLayers* create(Type type, const MaterialsSet* materials);
//! List of available types, sorted as expected in the UI.
static QVector<Type> types();
......
......@@ -49,6 +49,7 @@ const QString position_tooltip = "Relative position of the mesocrystal's referen
MesocrystalItem::MesocrystalItem(const MaterialsSet* materials)
: ItemWithParticles(abundance_tooltip, position_tooltip)
, m_basis_particle(materials)
, m_materials(materials)
{
m_vectorA.init("First lattice vector (nm)", "Coordinates of the first lattice vector",
......
......@@ -71,7 +71,7 @@ private:
VectorProperty m_vectorB;
VectorProperty m_vectorC;
PolyPtr<FormfactorItem, FormfactorCatalog> m_outer_shape;
PolyPtr<ItemWithParticles, ParticleCatalog> m_basis_particle;
PolyPtrExra<ItemWithParticles, ParticleCatalog, MaterialsSet> m_basis_particle;
const MaterialsSet* m_materials;
};
......
......@@ -21,6 +21,8 @@
ItemWithParticles* ParticleCatalog::create(Type type, const MaterialsSet* materials)
{
ASSERT(materials);
switch (type) {
case Type::Particle:
return new ParticleItem(materials);
......
......@@ -27,7 +27,7 @@ public:
enum class Type : uint8_t { Particle = 1, Composition = 2, CoreShell = 3, Mesocrystal = 4 };
//! Creates the item of the given type.
static ItemWithParticles* create(Type type, const MaterialsSet* materials = nullptr);
static ItemWithParticles* create(Type type, const MaterialsSet* materials);
//! List of available types, sorted as expected in the UI.
static QVector<Type> types();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment