BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
taginfo.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/model/mvvm/model/taginfo.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 
15 #include "mvvm/model/taginfo.h"
17 #include <algorithm>
18 #include <sstream>
19 #include <stdexcept>
20 
21 ModelView::TagInfo::TagInfo() : m_min(0), m_max(-1) {}
22 
23 ModelView::TagInfo::TagInfo(std::string name, int min, int max, std::vector<std::string> modelTypes)
24  : m_name(std::move(name)), m_min(min), m_max(max), m_modelTypes(std::move(modelTypes))
25 {
26  if (m_min < 0 || (m_min > m_max && m_max >= 0) || m_name.empty()) {
27  std::ostringstream ostr;
28  ostr << "Invalid constructor parameters"
29  << " " << m_name << " " << m_min << " " << m_max;
30  throw std::runtime_error(ostr.str());
31  }
32 }
33 
35  std::vector<std::string> modelTypes)
36 {
37  return TagInfo(std::move(name), 0, -1, std::move(modelTypes));
38 }
39 
41 {
42  return TagInfo(std::move(name), 1, 1, {std::move(model_type)});
43 }
44 
45 std::string ModelView::TagInfo::name() const
46 {
47  return m_name;
48 }
49 
51 {
52  return m_min;
53 }
54 
56 {
57  return m_max;
58 }
59 
60 std::vector<std::string> ModelView::TagInfo::modelTypes() const
61 {
62  return m_modelTypes;
63 }
64 
65 //! Returns true if given modelType matches the list of possible model types.
66 
67 bool ModelView::TagInfo::isValidChild(const std::string& modelType) const
68 {
69  return m_modelTypes.empty() ? true : Utils::Contains(m_modelTypes, modelType);
70 }
71 
72 //! Returns true if this tag is used to store single properties.
73 //! Properties are children that are created in SessionItem constructor using ::addProperty method.
74 
76 {
77  return m_min == 1 && m_max == 1;
78 }
79 
81 {
82  return m_name == other.m_name && m_min == other.m_min && m_max == other.m_max
83  && m_modelTypes == other.m_modelTypes;
84 }
85 
87 {
88  return !(*this == other);
89 }
Holds info about single tag for SessionItem.
Definition: taginfo.h:28
std::vector< std::string > m_modelTypes
Definition: taginfo.h:61
std::string name() const
Definition: taginfo.cpp:45
int max() const
Definition: taginfo.cpp:55
std::vector< std::string > modelTypes() const
Definition: taginfo.cpp:60
bool isValidChild(const std::string &modelType) const
Returns true if given modelType matches the list of possible model types.
Definition: taginfo.cpp:67
bool operator==(const TagInfo &other) const
Definition: taginfo.cpp:80
int min() const
Definition: taginfo.cpp:50
bool isSinglePropertyTag() const
Returns true if this tag is used to store single properties.
Definition: taginfo.cpp:75
static TagInfo universalTag(std::string name, std::vector< std::string > modelTypes={})
Constructs universal tag intended for unlimited amount of various items.
Definition: taginfo.cpp:34
bool operator!=(const TagInfo &other) const
Definition: taginfo.cpp:86
std::string m_name
Definition: taginfo.h:58
static TagInfo propertyTag(std::string name, std::string model_type)
Constructs tag intended for single property.
Definition: taginfo.cpp:40
Defines class CLASS?
bool Contains(const A &container, const B &element)
Returns true if container contains a given element.
std::string model_type
Definition: types.h:23
QString const & name(EShape k)
Definition: particles.cpp:21
Definition: filesystem.h:81
Defines class CLASS?