BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
MaterialItems Class Reference

Description

Definition at line 24 of file MaterialItems.h.

Inheritance diagram for MaterialItems:
[legend]
Collaboration diagram for MaterialItems:
[legend]

Signals

void materialAddedOrRemoved ()
 
void materialChanged (MaterialItem *materialItem)
 

Public Member Functions

 MaterialItems (QObject *parent=nullptr)
 
 ~MaterialItems ()
 
void addMaterial (MaterialItem *material)
 Add the material and take ownership of it. More...
 
MaterialItemaddRefractiveMaterial (const QString &name, double delta, double beta)
 
MaterialItemaddSLDMaterial (const QString &name, double sld, double abs_term)
 
void clear ()
 
MaterialItemscreateCopy () const
 
MaterialItemdefaultMaterial () const
 
void initFrom (const MaterialItems &from)
 Copies the complete content, emitting signals for existing and changed materials. More...
 
MaterialIteminsertCopy (const MaterialItem &material)
 Inserts a copy of the given material and returns the newly inserted item. More...
 
MaterialItemmaterialFromIdentifier (const QString &identifier) const
 
MaterialItemmaterialFromName (const QString &name) const
 
const QVector< MaterialItem * > & materialItems () const
 
bool operator!= (const MaterialItems &other) const
 
bool operator== (const MaterialItems &other) const
 Compares for complete equality (same material identifiers, same order of materials,...) More...
 
void removeMaterial (const QString &identifier)
 
void removeMaterial (MaterialItem *materialItem)
 
void serialize (Streamer &s)
 

Private Member Functions

void addMaterial (MaterialItem *material, bool signalAdding)
 Add the material and take ownership of it. More...
 

Private Attributes

QVector< MaterialItem * > m_materialItems
 all materials (owned by this class) More...
 

Constructor & Destructor Documentation

◆ MaterialItems()

MaterialItems::MaterialItems ( QObject *  parent = nullptr)
explicit

Definition at line 47 of file MaterialItems.cpp.

48  : QObject(parent)
49 {
50 }

Referenced by createCopy().

◆ ~MaterialItems()

MaterialItems::~MaterialItems ( )

Definition at line 52 of file MaterialItems.cpp.

53 {
54  clear();
55 }

References clear().

Here is the call graph for this function:

Member Function Documentation

◆ addMaterial() [1/2]

void MaterialItems::addMaterial ( MaterialItem material)

Add the material and take ownership of it.

Definition at line 63 of file MaterialItems.cpp.

64 {
65  addMaterial(material, true);
66 }
void addMaterial(MaterialItem *material)
Add the material and take ownership of it.

Referenced by addRefractiveMaterial(), addSLDMaterial(), initFrom(), and insertCopy().

◆ addMaterial() [2/2]

void MaterialItems::addMaterial ( MaterialItem material,
bool  signalAdding 
)
private

Add the material and take ownership of it.

In the given flag the signal "materialAddedOrRemoved" can be suppressed.

Definition at line 68 of file MaterialItems.cpp.

69 {
70  ASSERT(material);
71  material->disconnect(this);
72  m_materialItems << material;
73  connect(material, &MaterialItem::dataChanged, this, [=] { emit materialChanged(material); });
74 
75  if (signalAdding)
77 }
void dataChanged() const
void materialAddedOrRemoved()
QVector< MaterialItem * > m_materialItems
all materials (owned by this class)
Definition: MaterialItems.h:76
void materialChanged(MaterialItem *materialItem)

References MaterialItem::dataChanged(), m_materialItems, materialAddedOrRemoved(), and materialChanged().

◆ addRefractiveMaterial()

MaterialItem * MaterialItems::addRefractiveMaterial ( const QString &  name,
double  delta,
double  beta 
)

Definition at line 89 of file MaterialItems.cpp.

90 {
91  auto* materialItem = new MaterialItem();
92  materialItem->setMatItemName(name);
93  materialItem->setColor(suggestMaterialColor(name));
94  materialItem->setRefractiveIndex(delta, beta);
95  addMaterial(materialItem);
96 
97  return materialItem;
98 }
QString const & name(EShape k)
Definition: particles.cpp:20

References addMaterial(), and GUI::RealSpace::Particles::name().

Referenced by MaterialEditorModel::addRefractiveMaterial(), and MultiLayerItem::addStandardMaterials().

Here is the call graph for this function:

◆ addSLDMaterial()

MaterialItem * MaterialItems::addSLDMaterial ( const QString &  name,
double  sld,
double  abs_term 
)

Definition at line 100 of file MaterialItems.cpp.

101 {
102  auto* materialItem = new MaterialItem();
103  materialItem->setMatItemName(name);
104  materialItem->setColor(suggestMaterialColor(name));
105  materialItem->setScatteringLengthDensity(complex_t(sld, abs_term));
106  addMaterial(materialItem);
107 
108  return materialItem;
109 }

References addMaterial(), and GUI::RealSpace::Particles::name().

Referenced by MaterialEditorModel::addSLDMaterial().

Here is the call graph for this function:

◆ clear()

void MaterialItems::clear ( )

Definition at line 57 of file MaterialItems.cpp.

58 {
59  qDeleteAll(m_materialItems);
60  m_materialItems.clear();
61 }

References m_materialItems.

Referenced by ~MaterialItems(), and serialize().

◆ createCopy()

MaterialItems * MaterialItems::createCopy ( ) const

Definition at line 79 of file MaterialItems.cpp.

80 {
81  auto* result = new MaterialItems();
82 
83  for (const auto* m : m_materialItems)
84  result->addMaterial(new MaterialItem(*m));
85 
86  return result;
87 }
MaterialItems(QObject *parent=nullptr)

References MaterialItems(), and m_materialItems.

Here is the call graph for this function:

◆ defaultMaterial()

MaterialItem * MaterialItems::defaultMaterial ( ) const

Definition at line 144 of file MaterialItems.cpp.

145 {
146  ASSERT(!materialItems().isEmpty());
147  return materialItems().front();
148 }
const QVector< MaterialItem * > & materialItems() const

References materialItems().

Referenced by ParticleCoreShellItem::createCore(), and ParticleCoreShellItem::createShell().

Here is the call graph for this function:

◆ initFrom()

void MaterialItems::initFrom ( const MaterialItems from)

Copies the complete content, emitting signals for existing and changed materials.

Definition at line 170 of file MaterialItems.cpp.

171 {
172  // update existing to new contents (do not delete and recreate to keep references valid)
173  for (auto* destItem : m_materialItems)
174  if (auto* fromItem = from.materialFromIdentifier(destItem->identifier()))
175  destItem->updateFrom(*fromItem);
176 
177  bool anyAddedOrRemoved = false;
178 
179  // remove non-existing
180  auto* iter = m_materialItems.begin();
181  while (iter != m_materialItems.end())
182  if (!from.materialFromIdentifier((*iter)->identifier())) {
183  delete *iter;
184  iter = m_materialItems.erase(iter);
185  anyAddedOrRemoved = true;
186  } else
187  iter++;
188 
189  // copy new ones
190  for (const auto* m : from.materialItems())
191  if (!materialFromIdentifier(m->identifier())) {
192  addMaterial(new MaterialItem(*m), false);
193  anyAddedOrRemoved = true;
194  }
195 
196  // copy order
197  QVector<MaterialItem*> tmp;
198  for (const auto* m : from.materialItems())
199  tmp << materialFromIdentifier(m->identifier());
200  m_materialItems = tmp;
201 
202  if (anyAddedOrRemoved)
203  emit materialAddedOrRemoved();
204 }
MaterialItem * materialFromIdentifier(const QString &identifier) const

References addMaterial(), m_materialItems, materialAddedOrRemoved(), materialFromIdentifier(), and materialItems().

Referenced by MaterialEditorDialog::MaterialEditorDialog(), and MaterialEditorDialog::accept().

Here is the call graph for this function:

◆ insertCopy()

MaterialItem * MaterialItems::insertCopy ( const MaterialItem material)

Inserts a copy of the given material and returns the newly inserted item.

The copy will have a different material identifier and a different name.

Definition at line 129 of file MaterialItems.cpp.

130 {
131  auto* newMaterial = new MaterialItem(material);
132  newMaterial->createNewIdentifier();
133  newMaterial->setMatItemName(material.matItemName() + " (copy)");
134  addMaterial(newMaterial);
135 
136  return newMaterial;
137 }
QString matItemName() const

References addMaterial(), and MaterialItem::matItemName().

Referenced by MaterialEditorModel::cloneMaterial().

Here is the call graph for this function:

◆ materialAddedOrRemoved

void MaterialItems::materialAddedOrRemoved ( )
signal

◆ materialChanged

void MaterialItems::materialChanged ( MaterialItem materialItem)
signal

◆ materialFromIdentifier()

MaterialItem * MaterialItems::materialFromIdentifier ( const QString &  identifier) const

Definition at line 120 of file MaterialItems.cpp.

121 {
122  for (auto* materialItem : m_materialItems)
123  if (materialItem->identifier() == identifier)
124  return materialItem;
125 
126  return nullptr;
127 }

References m_materialItems.

Referenced by initFrom(), ItemWithMaterial::materialItem(), and removeMaterial().

◆ materialFromName()

MaterialItem * MaterialItems::materialFromName ( const QString &  name) const

Definition at line 111 of file MaterialItems.cpp.

112 {
113  for (auto* materialItem : m_materialItems)
114  if (materialItem->matItemName() == name)
115  return materialItem;
116 
117  return nullptr;
118 }

References m_materialItems, and GUI::RealSpace::Particles::name().

Referenced by RealSpaceCanvas::updateScene().

Here is the call graph for this function:

◆ materialItems()

◆ operator!=()

bool MaterialItems::operator!= ( const MaterialItems other) const

Definition at line 218 of file MaterialItems.cpp.

219 {
220  return !operator==(other);
221 }
@ other
The unit has no enum value defined in here (e.g. when defined as an explicit string)
bool operator==(const MaterialItems &other) const
Compares for complete equality (same material identifiers, same order of materials,...

References operator==(), and other.

Here is the call graph for this function:

◆ operator==()

bool MaterialItems::operator== ( const MaterialItems other) const

Compares for complete equality (same material identifiers, same order of materials,...)

Definition at line 206 of file MaterialItems.cpp.

207 {
208  if (m_materialItems.size() != other.m_materialItems.size())
209  return false;
210 
211  for (int i = 0; i < m_materialItems.size(); i++)
212  if (*m_materialItems[i] != *other.m_materialItems[i])
213  return false;
214 
215  return true;
216 }

References m_materialItems, and other.

Referenced by operator!=().

◆ removeMaterial() [1/2]

void MaterialItems::removeMaterial ( const QString &  identifier)

Definition at line 150 of file MaterialItems.cpp.

151 {
153 }
void removeMaterial(const QString &identifier)

References materialFromIdentifier().

Referenced by MaterialEditorModel::removeMaterial().

Here is the call graph for this function:

◆ removeMaterial() [2/2]

void MaterialItems::removeMaterial ( MaterialItem materialItem)

Definition at line 155 of file MaterialItems.cpp.

156 {
157  m_materialItems.removeAll(materialItem);
158  delete materialItem;
159  emit materialAddedOrRemoved();
160 }

References m_materialItems, and materialAddedOrRemoved().

◆ serialize()

void MaterialItems::serialize ( Streamer s)

Definition at line 162 of file MaterialItems.cpp.

163 {
164  if (s.xmlReader())
165  clear();
166  s.assertVersion(0);
167  Serialize::rwVector(s, "MaterialItems", m_materialItems);
168 }
QXmlStreamReader * xmlReader()
Returns stream reader or nullptr.
Definition: Streamer.h:48
void assertVersion(unsigned expectedVersion) const
As reader, throws DeserializationException unless the expected version is read. As writer,...
Definition: Streamer.cpp:26
void rwVector(Streamer &s, const QString &tag, QVector< T > &vec, Args... argsForConstructor)
Serializes a list of items of known and fixed type. Passes optional arguments to the constructor.
Definition: Serialize.h:93

References Streamer::assertVersion(), clear(), m_materialItems, Serialize::rwVector(), and Streamer::xmlReader().

Here is the call graph for this function:

Member Data Documentation

◆ m_materialItems

QVector<MaterialItem*> MaterialItems::m_materialItems
private

all materials (owned by this class)

Definition at line 76 of file MaterialItems.h.

Referenced by addMaterial(), clear(), createCopy(), initFrom(), materialFromIdentifier(), materialFromName(), materialItems(), operator==(), removeMaterial(), and serialize().


The documentation for this class was generated from the following files: