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

Description

Model for list of materials, used in MaterialEditorDialog.

This model is also used for changing values of a material, therefore the list can be updated accordingly.

Definition at line 27 of file MaterialEditorModel.h.

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

Public Member Functions

 MaterialEditorModel (MaterialItems *p)
 
MaterialItemaddRefractiveMaterial (const QString &name, double delta, double beta)
 
MaterialItemaddSLDMaterial (const QString &name, double sld, double abs_term)
 
MaterialItemcloneMaterial (const QModelIndex &index)
 
int columnCount (const QModelIndex &parent=QModelIndex()) const override
 
QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const override
 
QModelIndex first () const
 
QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
 
QModelIndex indexFromMaterial (const MaterialItem *m) const
 
QModelIndex indexFromMaterial (const QString &identifier) const
 
MaterialItemmaterialFromIndex (const QModelIndex &index) const
 
void removeMaterial (const QModelIndex &index)
 
int rowCount (const QModelIndex &parent=QModelIndex()) const override
 
void setBeta (const QModelIndex &index, double value)
 
void setColor (const QModelIndex &index, const QColor &color)
 
void setDelta (const QModelIndex &index, double value)
 
void setIm (const QModelIndex &index, double value)
 
void setMaterialItemName (const QModelIndex &index, const QString &name)
 
void setRe (const QModelIndex &index, double value)
 
void setX (const QModelIndex &index, double value)
 
void setY (const QModelIndex &index, double value)
 
void setZ (const QModelIndex &index, double value)
 

Private Types

enum  Column {
  NAME , TYPE , PARAMETERS , MAGNETIZATION ,
  NUM_COLUMNS
}
 The columns in the header. PARAMETERS contains delta/beta or Re/Im. More...
 

Private Attributes

MaterialItemsm_model
 

Member Enumeration Documentation

◆ Column

The columns in the header. PARAMETERS contains delta/beta or Re/Im.

Enumerator
NAME 
TYPE 
PARAMETERS 
MAGNETIZATION 
NUM_COLUMNS 

Definition at line 60 of file MaterialEditorModel.h.

Constructor & Destructor Documentation

◆ MaterialEditorModel()

MaterialEditorModel::MaterialEditorModel ( MaterialItems p)

Definition at line 23 of file MaterialEditorModel.cpp.

24  : m_model(p)
25 {
26 }
MaterialItems * m_model

Member Function Documentation

◆ addRefractiveMaterial()

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

Definition at line 201 of file MaterialEditorModel.cpp.

203 {
204  beginInsertRows(QModelIndex(), rowCount(), rowCount());
205  auto* m = m_model->addRefractiveMaterial(name, delta, beta);
206  endInsertRows();
207  return m;
208 }
int rowCount(const QModelIndex &parent=QModelIndex()) const override
MaterialItem * addRefractiveMaterial(const QString &name, double delta, double beta)
QString const & name(EShape k)
Definition: particles.cpp:20

References MaterialItems::addRefractiveMaterial(), m_model, GUI::RealSpace::Particles::name(), and rowCount().

Referenced by MaterialEditorDialog::addRefractiveMaterial().

Here is the call graph for this function:

◆ addSLDMaterial()

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

Definition at line 210 of file MaterialEditorModel.cpp.

211 {
212  beginInsertRows(QModelIndex(), rowCount(), rowCount());
213  auto* m = m_model->addSLDMaterial(name, sld, abs_term);
214  endInsertRows();
215  return m;
216 }
MaterialItem * addSLDMaterial(const QString &name, double sld, double abs_term)

References MaterialItems::addSLDMaterial(), m_model, GUI::RealSpace::Particles::name(), and rowCount().

Referenced by MaterialEditorDialog::addSldMaterial().

Here is the call graph for this function:

◆ cloneMaterial()

MaterialItem * MaterialEditorModel::cloneMaterial ( const QModelIndex &  index)

Definition at line 218 of file MaterialEditorModel.cpp.

219 {
220  beginInsertRows(QModelIndex(), rowCount(), rowCount());
221  auto* m = m_model->insertCopy(*materialFromIndex(index));
222  endInsertRows();
223  return m;
224 }
MaterialItem * materialFromIndex(const QModelIndex &index) const
MaterialItem * insertCopy(const MaterialItem &material)
Inserts a copy of the given material and returns the newly inserted item.

References MaterialItems::insertCopy(), m_model, materialFromIndex(), and rowCount().

Referenced by MaterialEditorDialog::cloneCurrentMaterial().

Here is the call graph for this function:

◆ columnCount()

int MaterialEditorModel::columnCount ( const QModelIndex &  parent = QModelIndex()) const
override

Definition at line 33 of file MaterialEditorModel.cpp.

34 {
35  return NUM_COLUMNS;
36 }

References NUM_COLUMNS.

◆ data()

QVariant MaterialEditorModel::data ( const QModelIndex &  index,
int  role = Qt::DisplayRole 
) const
override

Definition at line 58 of file MaterialEditorModel.cpp.

59 {
60  if (!index.isValid())
61  return {};
62 
63  MaterialItem* material = m_model->materialItems()[index.row()];
64 
65  if (role == Qt::DisplayRole) {
66  switch (index.column()) {
67  case NAME:
68  return material->matItemName();
69 
70  case TYPE:
71  return material->hasRefractiveIndex() ? "Refractive based" : "SLD based";
72 
73  case PARAMETERS:
74  if (material->hasRefractiveIndex())
75  return QString("delta: %1, beta: %2").arg(material->delta()).arg(material->beta());
76  else
77  return QString("re: %1, im: %2").arg(material->sldRe()).arg(material->sldIm());
78 
79  case MAGNETIZATION:
80  return QString("%1/%2/%3")
81  .arg(material->magnetization().x())
82  .arg(material->magnetization().y())
83  .arg(material->magnetization().z());
84  }
85  } else if (role == Qt::DecorationRole) {
86  switch (index.column()) {
87  case NAME: {
88  const int size = qApp->fontMetrics().height();
89  QPixmap pixmap(size, size);
90  pixmap.fill(materialFromIndex(index)->color());
91  return pixmap;
92  }
93  }
94  }
95 
96  return {};
97 }
bool hasRefractiveIndex() const
DoubleDescriptor sldIm()
DoubleDescriptor beta()
QString matItemName() const
R3 magnetization() const
DoubleDescriptor sldRe()
DoubleDescriptor delta()
const QVector< MaterialItem * > & materialItems() const

References MaterialItem::beta(), MaterialItem::delta(), MaterialItem::hasRefractiveIndex(), m_model, MaterialItem::magnetization(), MAGNETIZATION, materialFromIndex(), MaterialItems::materialItems(), MaterialItem::matItemName(), NAME, PARAMETERS, MaterialItem::sldIm(), MaterialItem::sldRe(), and TYPE.

Here is the call graph for this function:

◆ first()

QModelIndex MaterialEditorModel::first ( ) const

Definition at line 196 of file MaterialEditorModel.cpp.

197 {
198  return index(0, 0);
199 }

Referenced by MaterialEditorDialog::MaterialEditorDialog().

◆ headerData()

QVariant MaterialEditorModel::headerData ( int  section,
Qt::Orientation  orientation,
int  role = Qt::DisplayRole 
) const
override

Definition at line 38 of file MaterialEditorModel.cpp.

40 {
41  if (role != Qt::DisplayRole)
42  return {};
43 
44  switch (section) {
45  case NAME:
46  return "Name";
47  case TYPE:
48  return "Type";
49  case PARAMETERS:
50  return "Material parameters";
51  case MAGNETIZATION:
52  return "Magnetization [A/m]";
53  default:
54  return {};
55  }
56 }

References MAGNETIZATION, NAME, PARAMETERS, and TYPE.

◆ indexFromMaterial() [1/2]

QModelIndex MaterialEditorModel::indexFromMaterial ( const MaterialItem m) const

Definition at line 187 of file MaterialEditorModel.cpp.

188 {
189  const auto materials = m_model->materialItems();
190  for (int row = 0; row < materials.size(); row++)
191  if (materials[row] == m)
192  return index(row, 0);
193  return QModelIndex();
194 }

References m_model, and MaterialItems::materialItems().

Referenced by MaterialEditorDialog::setCurrentMaterial().

Here is the call graph for this function:

◆ indexFromMaterial() [2/2]

QModelIndex MaterialEditorModel::indexFromMaterial ( const QString &  identifier) const

Definition at line 178 of file MaterialEditorModel.cpp.

179 {
180  const auto materials = m_model->materialItems();
181  for (int row = 0; row < materials.size(); row++)
182  if (materials[row]->identifier() == identifier)
183  return index(row, 0);
184  return QModelIndex();
185 }

References m_model, and MaterialItems::materialItems().

Here is the call graph for this function:

◆ materialFromIndex()

MaterialItem * MaterialEditorModel::materialFromIndex ( const QModelIndex &  index) const

Definition at line 173 of file MaterialEditorModel.cpp.

174 {
175  return index.isValid() ? m_model->materialItems()[index.row()] : nullptr;
176 }

References m_model, and MaterialItems::materialItems().

Referenced by cloneMaterial(), MaterialEditorDialog::currentMaterial(), data(), removeMaterial(), setBeta(), setColor(), setDelta(), setIm(), setMaterialItemName(), setRe(), setX(), setY(), and setZ().

Here is the call graph for this function:

◆ removeMaterial()

void MaterialEditorModel::removeMaterial ( const QModelIndex &  index)

Definition at line 226 of file MaterialEditorModel.cpp.

227 {
228  beginRemoveRows(QModelIndex(), index.row(), index.row());
230  endRemoveRows();
231 }
void removeMaterial(const QString &identifier)

References m_model, materialFromIndex(), and MaterialItems::removeMaterial().

Referenced by MaterialEditorDialog::removeCurrentMaterial().

Here is the call graph for this function:

◆ rowCount()

int MaterialEditorModel::rowCount ( const QModelIndex &  parent = QModelIndex()) const
override

Definition at line 28 of file MaterialEditorModel.cpp.

29 {
30  return m_model->materialItems().size();
31 }

References m_model, and MaterialItems::materialItems().

Referenced by MaterialEditorDialog::MaterialEditorDialog(), addRefractiveMaterial(), addSLDMaterial(), and cloneMaterial().

Here is the call graph for this function:

◆ setBeta()

void MaterialEditorModel::setBeta ( const QModelIndex &  index,
double  value 
)

Definition at line 149 of file MaterialEditorModel.cpp.

150 {
151  auto* m = materialFromIndex(index);
152  m->setRefractiveIndex(m->delta(), value);
153  const auto paramIndex = this->index(index.row(), PARAMETERS);
154  emit dataChanged(paramIndex, paramIndex);
155 }

References materialFromIndex(), and PARAMETERS.

Here is the call graph for this function:

◆ setColor()

void MaterialEditorModel::setColor ( const QModelIndex &  index,
const QColor &  color 
)

Definition at line 105 of file MaterialEditorModel.cpp.

106 {
107  materialFromIndex(index)->setColor(color);
108  emit dataChanged(index, index);
109 }
void setColor(const QColor &color)

References materialFromIndex(), and MaterialItem::setColor().

Referenced by MaterialEditorDialog::onSelectColor().

Here is the call graph for this function:

◆ setDelta()

void MaterialEditorModel::setDelta ( const QModelIndex &  index,
double  value 
)

Definition at line 141 of file MaterialEditorModel.cpp.

142 {
143  auto* m = materialFromIndex(index);
144  m->setRefractiveIndex(value, m->beta());
145  const auto paramIndex = this->index(index.row(), PARAMETERS);
146  emit dataChanged(paramIndex, paramIndex);
147 }

References materialFromIndex(), and PARAMETERS.

Here is the call graph for this function:

◆ setIm()

void MaterialEditorModel::setIm ( const QModelIndex &  index,
double  value 
)

Definition at line 165 of file MaterialEditorModel.cpp.

166 {
167  auto* m = materialFromIndex(index);
168  m->setScatteringLengthDensity(complex_t(m->sldRe(), value));
169  auto paramIndex = this->index(index.row(), PARAMETERS);
170  emit dataChanged(paramIndex, paramIndex);
171 }

References materialFromIndex(), and PARAMETERS.

Here is the call graph for this function:

◆ setMaterialItemName()

void MaterialEditorModel::setMaterialItemName ( const QModelIndex &  index,
const QString &  name 
)

Definition at line 99 of file MaterialEditorModel.cpp.

100 {
102  emit dataChanged(index, index);
103 }
void setMatItemName(const QString &name)

References materialFromIndex(), GUI::RealSpace::Particles::name(), and MaterialItem::setMatItemName().

Here is the call graph for this function:

◆ setRe()

void MaterialEditorModel::setRe ( const QModelIndex &  index,
double  value 
)

Definition at line 157 of file MaterialEditorModel.cpp.

158 {
159  auto* m = materialFromIndex(index);
160  m->setScatteringLengthDensity(complex_t(value, m->sldIm()));
161  auto paramIndex = this->index(index.row(), PARAMETERS);
162  emit dataChanged(paramIndex, paramIndex);
163 }

References materialFromIndex(), and PARAMETERS.

Here is the call graph for this function:

◆ setX()

void MaterialEditorModel::setX ( const QModelIndex &  index,
double  value 
)

Definition at line 111 of file MaterialEditorModel.cpp.

112 {
113  auto* material = materialFromIndex(index);
114  R3 m = material->magnetization();
115  m.setX(value);
116  material->setMagnetization(m);
117  const auto magIndex = this->index(index.row(), MAGNETIZATION);
118  emit dataChanged(magIndex, magIndex);
119 }

References MAGNETIZATION, and materialFromIndex().

Here is the call graph for this function:

◆ setY()

void MaterialEditorModel::setY ( const QModelIndex &  index,
double  value 
)

Definition at line 121 of file MaterialEditorModel.cpp.

122 {
123  auto* material = materialFromIndex(index);
124  R3 m = material->magnetization();
125  m.setY(value);
126  material->setMagnetization(m);
127  const auto magIndex = this->index(index.row(), MAGNETIZATION);
128  emit dataChanged(magIndex, magIndex);
129 }

References MAGNETIZATION, and materialFromIndex().

Here is the call graph for this function:

◆ setZ()

void MaterialEditorModel::setZ ( const QModelIndex &  index,
double  value 
)

Definition at line 131 of file MaterialEditorModel.cpp.

132 {
133  auto* material = materialFromIndex(index);
134  R3 m = material->magnetization();
135  m.setZ(value);
136  material->setMagnetization(m);
137  const auto magIndex = this->index(index.row(), MAGNETIZATION);
138  emit dataChanged(magIndex, magIndex);
139 }

References MAGNETIZATION, and materialFromIndex().

Here is the call graph for this function:

Member Data Documentation

◆ m_model


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