BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
editorbuilders.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // qt-mvvm: Model-view-view-model framework for large GUI applications
4 //
5 //! @file mvvm/viewmodel/mvvm/editors/editorbuilders.cpp
6 //! @brief Implements class CLASS?
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2020
11 //! @authors Gennady Pospelov et al, Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
27 #include "mvvm/model/sessionitem.h"
28 #include "mvvm/utils/reallimits.h"
29 #include <cmath>
30 
31 namespace {
32 double singleStep(int decimals)
33 {
34  // For item with decimals=3 (i.e. 0.001) single step will be 0.1
35  return 1. / std::pow(10., decimals - 1);
36 }
37 
38 double getStep(double val)
39 {
40  return val == 0.0 ? 1.0 : val / 100.;
41 }
42 
43 } // namespace
44 
45 namespace ModelView ::EditorBuilders {
46 
48 {
49  auto builder = [](const SessionItem*) -> editor_t { return std::make_unique<BoolEditor>(); };
50  return builder;
51 }
52 
54 {
55  auto builder = [](const SessionItem* item) -> editor_t {
56  auto editor = std::make_unique<IntegerEditor>();
57  if (item && item->hasData(ItemDataRole::LIMITS)) {
58  auto limits = item->data<RealLimits>(ItemDataRole::LIMITS);
59  editor->setRange(limits.lowerLimit(), limits.upperLimit());
60  }
61  return editor;
62  };
63  return builder;
64 }
65 
67 {
68  auto builder = [](const SessionItem* item) -> editor_t {
69  auto editor = std::make_unique<DoubleEditor>();
70  if (item && item->hasData(ItemDataRole::LIMITS)) {
71  auto limits = item->data<RealLimits>(ItemDataRole::LIMITS);
72  editor->setRange(limits.lowerLimit(), limits.upperLimit());
73  editor->setSingleStep(singleStep(Constants::default_double_decimals));
74  editor->setDecimals(Constants::default_double_decimals);
75  }
76  return editor;
77  };
78  return builder;
79 }
80 
82 {
83  auto builder = [](const SessionItem* item) -> editor_t {
84  auto editor = std::make_unique<ScientificDoubleEditor>();
85  if (item && item->hasData(ItemDataRole::LIMITS)) {
86  auto limits = item->data<RealLimits>(ItemDataRole::LIMITS);
87  editor->setRange(limits.lowerLimit(), limits.upperLimit());
88  }
89  return editor;
90  };
91  return builder;
92 }
93 
95 {
96  auto builder = [](const SessionItem* item) -> editor_t {
97  auto editor = std::make_unique<ScientificSpinBoxEditor>();
98  if (item) {
99  if (item->hasData(ItemDataRole::LIMITS)) {
100  auto limits = item->data<RealLimits>(ItemDataRole::LIMITS);
101  editor->setRange(limits.lowerLimit(), limits.upperLimit());
102  }
103  editor->setSingleStep(getStep(item->data<double>()));
104  }
105  editor->setDecimals(Constants::default_double_decimals);
106  return editor;
107  };
108  return builder;
109 }
110 
112 {
113  auto builder = [](const SessionItem*) -> editor_t { return std::make_unique<ColorEditor>(); };
114  return builder;
115 }
116 
118 {
119  auto builder = [](const SessionItem*) -> editor_t {
120  return std::make_unique<ComboPropertyEditor>();
121  };
122  return builder;
123 }
124 
126 {
127  auto builder = [](const SessionItem*) -> editor_t {
128  return std::make_unique<ExternalPropertyEditor>();
129  };
130  return builder;
131 }
132 
134 {
135  auto builder = [](const SessionItem*) -> editor_t {
136  return std::make_unique<SelectableComboBoxEditor>();
137  };
138  return builder;
139 }
140 
141 } // namespace ModelView::EditorBuilders
Defines class CLASS?
Limits for a real fit parameter.
Definition: RealLimits.h:24
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
builder_t ExternalPropertyEditorBuilder()
builder_t SelectableComboPropertyEditorBuilder()
builder_t ScientificDoubleEditorBuilder()
builder_t ScientificSpinBoxEditorBuilder()
const int default_double_decimals
std::function< editor_t(const SessionItem *)> builder_t
std::unique_ptr< CustomEditor > editor_t
const int LIMITS
possibly limits on item's data
Definition: mvvm_types.h:33
materialitems.h Collection of materials to populate MaterialModel.
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?