BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
MaterialEditorDialog.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Views/MaterialEditor/MaterialEditorDialog.cpp
6 //! @brief Implements class MaterialEditorDialog
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
21 #include <QAction>
22 #include <QPushButton>
23 #include <QSettings>
24 #include <QVBoxLayout>
25 
26 namespace {
27 const QSize default_dialog_size(512, 400);
28 }
29 
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 }
48 
49 //! replaces original material model with the model modified by MaterialEditor
51 {
55  }
56  writeSettings();
57  accept();
58 }
59 
61 {
62  writeSettings();
63  reject();
64 }
65 
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 }
83 
85 {
89  readSettings();
90 }
91 
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 }
105 
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 }
114 
116 {
118  return MaterialItemUtils::materialProperty(*material);
119 
120  return ExternalProperty();
121 }
122 
123 //!
125 {
127 
129 }
#define ASSERT(condition)
Definition: Assert.h:31
Defines class MaterialEditorDialog.
Defines class MaterialEditor.
Defines class MaterialItemUtils.
Defines class MaterialModel.
DefinesStyleUtils namespace.
The ExternalProperty class defines custom QVariant property to carry the text, color and an identifie...
void setMaterialProperty(const ExternalProperty &matProperty)
std::unique_ptr< MaterialModel > m_tmpMaterialModel
QBoxLayout * createButtonLayout()
MaterialEditor * m_materialEditor
MaterialEditorDialog(MaterialModel *materialModel, QWidget *parent=nullptr)
void onOKButton()
replaces original material model with the model modified by MaterialEditor
ExternalProperty selectedMaterialProperty()
MaterialModel * m_origMaterialModel
Main widget of MaterialEditor.
bool modelWasChanged() const
MaterialItem * selectedMaterial()
void setInitialMaterialProperty(const ExternalProperty &matProperty)
Sets selection corresponding to initial material property.
MaterialModel * createCopy(SessionItem *parent=nullptr)
virtual void clear()
virtual void initFrom(SessionModel *model, SessionItem *parent)
Defines namespace Constants.
const char S_MATERIALEDITOR[]
const char S_WINDOWPOSITION[]
const char S_WINDOWSIZE[]
ExternalProperty materialProperty(const SessionItem &materialItem)
Constructs material property corresponding to given material.
void setResizable(QDialog *dialog)
Make modal dialog resizable.
Definition: StyleUtils.cpp:87