BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
GroupInfo.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Models/GroupInfo.cpp
6 //! @brief Defines class GroupInfo
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 
17 
18 GroupInfo::GroupInfo(const QString& groupType, bool is_sorted)
19  : m_groupType(groupType), is_sorted(is_sorted)
20 {
21 }
22 
23 void GroupInfo::add(const QString& itemType, const QString& itemLabel)
24 {
25  if (groupType().isEmpty())
26  throw GUIHelpers::Error("GroupInfo::add() -> Error. Empty group name");
27 
28  if (containsType(itemType))
29  throw GUIHelpers::Error("GroupInfo::add() -> Error. "
30  "Model type '"
31  + itemType + "' already exists.");
32 
33  m_info.push_back({itemType, itemLabel});
34 
35  if (is_sorted)
36  std::sort(m_info.begin(), m_info.end(),
37  [](TypeAndLabel a, TypeAndLabel b) { return a.m_itemType < b.m_itemType; });
38 }
39 
40 QString GroupInfo::defaultType() const
41 {
42  if (m_defaultItemType == "" && m_info.size() != 0)
43  return m_info[0].m_itemType;
44  return m_defaultItemType;
45 }
46 
47 void GroupInfo::setDefaultType(const QString& modelType)
48 {
49  if (!containsType(modelType))
50  throw GUIHelpers::Error("GroupInfo::add() -> Error. No such type '" + modelType + "'");
51 
52  m_defaultItemType = modelType;
53 }
54 
55 QString GroupInfo::groupType() const
56 {
57  return m_groupType;
58 }
59 
60 QStringList GroupInfo::itemTypes() const
61 {
62  QStringList result;
63  for (auto& pair : m_info)
64  result.append(pair.m_itemType);
65 
66  return result;
67 }
68 
69 QStringList GroupInfo::itemLabels() const
70 {
71  QStringList result;
72  for (auto& pair : m_info)
73  result.append(pair.m_itemLabel);
74 
75  return result;
76 }
77 
79 {
80  return !m_groupType.isEmpty();
81 }
82 
83 bool GroupInfo::containsType(const QString& itemType) const
84 {
85  for (auto& pair : m_info)
86  if (itemType == pair.m_itemType)
87  return true;
88 
89  return false;
90 }
Defines class GUIHelpers functions.
Defines class GroupInfo.
GroupInfo(const QString &groupType="", bool is_sorted=true)
Definition: GroupInfo.cpp:18
bool isValid()
Definition: GroupInfo.cpp:78
QVector< TypeAndLabel > m_info
Definition: GroupInfo.h:56
QStringList itemLabels() const
Definition: GroupInfo.cpp:69
void add(const QString &itemType, const QString &itemLabel)
Definition: GroupInfo.cpp:23
QString m_groupType
Info will be sorted if true, otherwise order of insertion will be preserved.
Definition: GroupInfo.h:53
QString defaultType() const
Definition: GroupInfo.cpp:40
QStringList itemTypes() const
Definition: GroupInfo.cpp:60
bool is_sorted
Definition: GroupInfo.h:55
QString groupType() const
Definition: GroupInfo.cpp:55
QString m_defaultItemType
Unique group name for GroupInfoCatalog.
Definition: GroupInfo.h:51
bool containsType(const QString &itemType) const
Default model type for given group (i.e. FFCylinder for formfactor group)
Definition: GroupInfo.cpp:83
void setDefaultType(const QString &modelType)
Definition: GroupInfo.cpp:47