BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
gui2::MaterialEditorActions Class Reference

Handles user actions applied to material table. More...

Inheritance diagram for gui2::MaterialEditorActions:
[legend]
Collaboration diagram for gui2::MaterialEditorActions:
[legend]

Classes

struct  MaterialEditorActionsImpl
 

Public Member Functions

 MaterialEditorActions (QObject *parent=nullptr)
 
 ~MaterialEditorActions ()
 
void onAddMaterial ()
 
void onCloneMaterial ()
 Processes request to clone selected materials. More...
 
void onExport ()
 
void onImport ()
 
void onMoveDown ()
 
void onMoveUp ()
 
void onRemoveMaterial ()
 
void setMaterialSelectionModel (MaterialSelectionModel *selection_model)
 
void setModel (MaterialModel *model)
 

Private Attributes

std::unique_ptr< MaterialEditorActionsImplp_impl
 

Detailed Description

Handles user actions applied to material table.

Belongs to MaterialEditor.

Definition at line 30 of file materialeditoractions.h.

Constructor & Destructor Documentation

◆ MaterialEditorActions()

gui2::MaterialEditorActions::MaterialEditorActions ( QObject *  parent = nullptr)

Definition at line 53 of file materialeditoractions.cpp.

54  : QObject(parent), p_impl(std::make_unique<MaterialEditorActionsImpl>())
55 {
56 }
std::unique_ptr< MaterialEditorActionsImpl > p_impl

◆ ~MaterialEditorActions()

gui2::MaterialEditorActions::~MaterialEditorActions ( )
default

Member Function Documentation

◆ onAddMaterial()

void gui2::MaterialEditorActions::onAddMaterial ( )

Definition at line 68 of file materialeditoractions.cpp.

69 {
70  if (!p_impl->material_model)
71  return;
72 
73  auto [parent, tagrow] = p_impl->locateInsertPlace();
74  auto material = p_impl->material_model->addDefaultMaterial(tagrow);
75  p_impl->selection_model->selectItem(material);
76 }

References p_impl.

Referenced by gui2::MaterialEditorToolBar::MaterialEditorToolBar().

◆ onCloneMaterial()

void gui2::MaterialEditorActions::onCloneMaterial ( )

Processes request to clone selected materials.

Definition at line 80 of file materialeditoractions.cpp.

81 {
82  if (!p_impl->material_model)
83  return;
84 
85  std::vector<ModelView::SessionItem*> new_selection;
86  for (const auto item : p_impl->selection_model->selectedMaterials())
87  new_selection.push_back(p_impl->material_model->cloneMaterial(item));
88  p_impl->selection_model->selectItems(new_selection);
89 }

References p_impl.

Referenced by gui2::MaterialEditorToolBar::MaterialEditorToolBar().

◆ onExport()

void gui2::MaterialEditorActions::onExport ( )

Definition at line 120 of file materialeditoractions.cpp.

121 {
122  auto item = p_impl->root_item();
123  const auto containers = item->children();
124 
125  bool title = true; // print title only once in ascii file
126  QString tableData;
127  QString titleData;
128 
129  for (auto container : containers) {
130  auto data = container->modelType();
131  for (auto fields : dynamic_cast<MaterialBaseItem*>(container)->children()) {
132  if (title) {
133  titleData += (fields->displayName()).c_str();
134  titleData += " ";
135  }
136  auto val = fields->data<QVariant>(1); // role 1 has the values.
137  if (strcmp(val.typeName(), "std::string") == 0) {
138  tableData += val.value<std::string>().c_str();
139  tableData += " ";
140  } else if (strcmp(val.typeName(), "int") == 0) {
141  auto int_val = val.value<int>();
142  tableData += QString::number(int_val);
143  tableData += " ";
144  } else if (strcmp(val.typeName(), "double") == 0) {
145  auto double_val = val.value<double>();
146  tableData += QString::number(double_val);
147  tableData += " ";
148  } else if (strcmp(val.typeName(), "float") == 0) {
149  auto float_val = val.value<float>();
150  tableData += QString::number(float_val);
151  tableData += " ";
152  } else {
153  auto color_str = val.toString();
154  tableData += color_str;
155  tableData += " ";
156  }
157  }
158  if (title) {
159  titleData += "\n";
160  tableData = titleData + tableData;
161  }
162  title = false;
163  tableData += "\n";
164  }
165  /*for text file*/
166  QFile txtFile("materialdata");
167  if (txtFile.open(QIODevice::WriteOnly)) {
168 
169  QTextStream out(&txtFile);
170  out << tableData;
171 
172  txtFile.close();
173  }
174 }

References p_impl.

Referenced by gui2::MaterialEditorToolBar::MaterialEditorToolBar().

◆ onImport()

void gui2::MaterialEditorActions::onImport ( )

Definition at line 176 of file materialeditoractions.cpp.

176 {}

Referenced by gui2::MaterialEditorToolBar::MaterialEditorToolBar().

◆ onMoveDown()

void gui2::MaterialEditorActions::onMoveDown ( )

Definition at line 109 of file materialeditoractions.cpp.

110 {
111  if (!p_impl->selection_model)
112  return;
113 
114  auto items = p_impl->selection_model->selectedMaterials();
115  std::reverse(items.begin(), items.end()); // to correctly move multiple selections
116  for (auto item : p_impl->selection_model->selectedMaterials())
118 }
MVVM_MODEL_EXPORT void MoveDown(SessionItem *item)
Moves item down (increments row of the item). Works on children belonging to single tag.
Definition: modelutils.cpp:71

References ModelView::Utils::MoveDown(), and p_impl.

Referenced by gui2::MaterialEditorToolBar::MaterialEditorToolBar().

Here is the call graph for this function:

◆ onMoveUp()

void gui2::MaterialEditorActions::onMoveUp ( )

Definition at line 100 of file materialeditoractions.cpp.

101 {
102  if (!p_impl->selection_model)
103  return;
104 
105  for (auto item : p_impl->selection_model->selectedMaterials())
107 }
MVVM_MODEL_EXPORT void MoveUp(SessionItem *item)
Moves item up (decrements row of the item). Works on children belonging to single tag.
Definition: modelutils.cpp:63

References ModelView::Utils::MoveUp(), and p_impl.

Referenced by gui2::MaterialEditorToolBar::MaterialEditorToolBar().

Here is the call graph for this function:

◆ onRemoveMaterial()

void gui2::MaterialEditorActions::onRemoveMaterial ( )

Definition at line 91 of file materialeditoractions.cpp.

92 {
93  if (!p_impl->selection_model)
94  return;
95 
96  for (auto item : p_impl->selection_model->selectedMaterials())
98 }
MVVM_MODEL_EXPORT void DeleteItemFromModel(SessionItem *item)
Removes and deletes item from its model.
Definition: modelutils.cpp:54

References ModelView::Utils::DeleteItemFromModel(), and p_impl.

Referenced by gui2::MaterialEditorToolBar::MaterialEditorToolBar().

Here is the call graph for this function:

◆ setMaterialSelectionModel()

void gui2::MaterialEditorActions::setMaterialSelectionModel ( MaterialSelectionModel selection_model)

Definition at line 63 of file materialeditoractions.cpp.

64 {
65  p_impl->selection_model = selection_model;
66 }

References p_impl.

Referenced by gui2::MaterialEditor::setModels().

◆ setModel()

void gui2::MaterialEditorActions::setModel ( MaterialModel model)

Definition at line 58 of file materialeditoractions.cpp.

59 {
60  p_impl->material_model = model;
61 }

References p_impl.

Referenced by gui2::MaterialEditor::setModels().

Member Data Documentation

◆ p_impl

std::unique_ptr<MaterialEditorActionsImpl> gui2::MaterialEditorActions::p_impl
private

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