BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
MaterialEditorDialog Class Reference

Dialog to hold MaterialEditor. More...

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

Public Slots

void onCancelButton ()
 
void onOKButton ()
 replaces original material model with the model modified by MaterialEditor More...
 

Public Member Functions

 MaterialEditorDialog (MaterialModel *materialModel, QWidget *parent=nullptr)
 
ExternalProperty selectedMaterialProperty ()
 
void setMaterialProperty (const ExternalProperty &matProperty)
 

Private Member Functions

QBoxLayout * createButtonLayout ()
 
void init_material_editor ()
 
void readSettings ()
 
void writeSettings ()
 

Private Attributes

MaterialEditorm_materialEditor
 
MaterialModelm_origMaterialModel
 
std::unique_ptr< MaterialModelm_tmpMaterialModel
 

Detailed Description

Dialog to hold MaterialEditor.

It's main function is to return MaterialModel to original state, if user decided to cancel changes.

Definition at line 30 of file MaterialEditorDialog.h.

Constructor & Destructor Documentation

◆ MaterialEditorDialog()

MaterialEditorDialog::MaterialEditorDialog ( MaterialModel materialModel,
QWidget *  parent = nullptr 
)

Definition at line 30 of file MaterialEditorDialog.cpp.

31  : QDialog(parent), m_origMaterialModel(materialModel), m_materialEditor(nullptr)
32 {
33  setWindowTitle("Material Editor");
34  setMinimumSize(128, 128);
35  setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
36 
38 
39  auto layout = new QVBoxLayout;
40  layout->setContentsMargins(0, 0, 0, 0);
41  layout->addWidget(m_materialEditor);
42  layout->addLayout(createButtonLayout());
43 
44  setLayout(layout);
45 
47 }
QBoxLayout * createButtonLayout()
MaterialEditor * m_materialEditor
MaterialModel * m_origMaterialModel
void setResizable(QDialog *dialog)
Make modal dialog resizable.
Definition: StyleUtils.cpp:87

References createButtonLayout(), init_material_editor(), m_materialEditor, and StyleUtils::setResizable().

Here is the call graph for this function:

Member Function Documentation

◆ createButtonLayout()

QBoxLayout * MaterialEditorDialog::createButtonLayout ( )
private

Definition at line 66 of file MaterialEditorDialog.cpp.

67 {
68  auto result = new QHBoxLayout;
69 
70  auto okButton = new QPushButton("OK");
71  connect(okButton, &QPushButton::clicked, this, &MaterialEditorDialog::onOKButton);
72  auto cancelButton = new QPushButton("Cancel");
73  connect(cancelButton, &QPushButton::clicked, this, &MaterialEditorDialog::onCancelButton);
74 
75  result->setMargin(10);
76  result->setSpacing(5);
77  result->addStretch(1);
78  result->addWidget(okButton);
79  result->addWidget(cancelButton);
80 
81  return result;
82 }
void onOKButton()
replaces original material model with the model modified by MaterialEditor

References onCancelButton(), and onOKButton().

Referenced by MaterialEditorDialog().

Here is the call graph for this function:

◆ init_material_editor()

void MaterialEditorDialog::init_material_editor ( )
private

Definition at line 84 of file MaterialEditorDialog.cpp.

85 {
89  readSettings();
90 }
#define ASSERT(condition)
Definition: Assert.h:31
std::unique_ptr< MaterialModel > m_tmpMaterialModel
Main widget of MaterialEditor.
MaterialModel * createCopy(SessionItem *parent=nullptr)

References ASSERT, MaterialModel::createCopy(), m_materialEditor, m_origMaterialModel, m_tmpMaterialModel, and readSettings().

Referenced by MaterialEditorDialog().

Here is the call graph for this function:

◆ onCancelButton

void MaterialEditorDialog::onCancelButton ( )
slot

Definition at line 60 of file MaterialEditorDialog.cpp.

61 {
62  writeSettings();
63  reject();
64 }

References writeSettings().

Referenced by createButtonLayout().

Here is the call graph for this function:

◆ onOKButton

void MaterialEditorDialog::onOKButton ( )
slot

replaces original material model with the model modified by MaterialEditor

Definition at line 50 of file MaterialEditorDialog.cpp.

51 {
55  }
56  writeSettings();
57  accept();
58 }
bool modelWasChanged() const
virtual void clear()
virtual void initFrom(SessionModel *model, SessionItem *parent)

References SessionModel::clear(), SessionModel::initFrom(), m_materialEditor, m_origMaterialModel, m_tmpMaterialModel, MaterialEditor::modelWasChanged(), and writeSettings().

Referenced by createButtonLayout().

Here is the call graph for this function:

◆ readSettings()

void MaterialEditorDialog::readSettings ( )
private

Definition at line 92 of file MaterialEditorDialog.cpp.

93 {
94  QSettings settings;
95  if (settings.childGroups().contains(Constants::S_MATERIALEDITOR)) {
96  settings.beginGroup(Constants::S_MATERIALEDITOR);
97  resize(settings.value(Constants::S_WINDOWSIZE, default_dialog_size).toSize());
98  if (settings.contains(Constants::S_WINDOWPOSITION)) {
99  move(settings.value(Constants::S_WINDOWPOSITION).toPoint());
100  }
101  } else {
102  resize(default_dialog_size);
103  }
104 }
const char S_MATERIALEDITOR[]
const char S_WINDOWPOSITION[]
const char S_WINDOWSIZE[]

References Constants::S_MATERIALEDITOR, Constants::S_WINDOWPOSITION, and Constants::S_WINDOWSIZE.

Referenced by init_material_editor().

◆ selectedMaterialProperty()

ExternalProperty MaterialEditorDialog::selectedMaterialProperty ( )

Definition at line 115 of file MaterialEditorDialog.cpp.

116 {
118  return MaterialItemUtils::materialProperty(*material);
119 
120  return ExternalProperty();
121 }
The ExternalProperty class defines custom QVariant property to carry the text, color and an identifie...
MaterialItem * selectedMaterial()
ExternalProperty materialProperty(const SessionItem &materialItem)
Constructs material property corresponding to given material.

References m_materialEditor, MaterialItemUtils::materialProperty(), and MaterialEditor::selectedMaterial().

Referenced by MaterialItemUtils::selectMaterialProperty().

Here is the call graph for this function:

◆ setMaterialProperty()

void MaterialEditorDialog::setMaterialProperty ( const ExternalProperty matProperty)

Definition at line 124 of file MaterialEditorDialog.cpp.

125 {
127 
129 }
void setInitialMaterialProperty(const ExternalProperty &matProperty)
Sets selection corresponding to initial material property.

References ASSERT, m_materialEditor, and MaterialEditor::setInitialMaterialProperty().

Referenced by MaterialItemUtils::selectMaterialProperty().

Here is the call graph for this function:

◆ writeSettings()

void MaterialEditorDialog::writeSettings ( )
private

Definition at line 106 of file MaterialEditorDialog.cpp.

107 {
108  QSettings settings;
109  settings.beginGroup(Constants::S_MATERIALEDITOR);
110  settings.setValue(Constants::S_WINDOWSIZE, this->size());
111  settings.setValue(Constants::S_WINDOWPOSITION, this->pos());
112  settings.endGroup();
113 }

References Constants::S_MATERIALEDITOR, Constants::S_WINDOWPOSITION, and Constants::S_WINDOWSIZE.

Referenced by onCancelButton(), and onOKButton().

Member Data Documentation

◆ m_materialEditor

MaterialEditor* MaterialEditorDialog::m_materialEditor
private

◆ m_origMaterialModel

MaterialModel* MaterialEditorDialog::m_origMaterialModel
private

Definition at line 51 of file MaterialEditorDialog.h.

Referenced by init_material_editor(), and onOKButton().

◆ m_tmpMaterialModel

std::unique_ptr<MaterialModel> MaterialEditorDialog::m_tmpMaterialModel
private

Definition at line 52 of file MaterialEditorDialog.h.

Referenced by init_material_editor(), and onOKButton().


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