BornAgain  1.19.79
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/Support/Type/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 
16 #include "Base/Util/Assert.h"
17 
18 GroupInfo::GroupInfo(bool is_sorted)
19  : is_sorted(is_sorted)
20 {
21 }
22 
23 void GroupInfo::add(const QString& itemType, const QString& itemLabel)
24 {
25  ASSERT(!containsType(itemType));
26  m_info.push_back({itemType, itemLabel});
27 
28  if (is_sorted)
29  std::sort(m_info.begin(), m_info.end(),
30  [](TypeAndLabel a, TypeAndLabel b) { return a.m_itemType < b.m_itemType; });
31 }
32 
33 QString GroupInfo::defaultType() const
34 {
35  if (m_defaultItemType.isEmpty() && !m_info.empty())
36  return m_info[0].m_itemType;
37  return m_defaultItemType;
38 }
39 
40 void GroupInfo::setDefaultType(const QString& modelType)
41 {
42  ASSERT(containsType(modelType));
43  m_defaultItemType = modelType;
44 }
45 
46 QStringList GroupInfo::itemTypes() const
47 {
48  QStringList result;
49  for (const auto& pair : m_info)
50  result.append(pair.m_itemType);
51  return result;
52 }
53 
54 QStringList GroupInfo::itemLabels() const
55 {
56  QStringList result;
57  for (const auto& pair : m_info)
58  result.append(pair.m_itemLabel);
59  return result;
60 }
61 
62 bool GroupInfo::containsType(const QString& itemType) const
63 {
64  for (const auto& pair : m_info)
65  if (itemType == pair.m_itemType)
66  return true;
67  return false;
68 }
Defines class GroupInfo.
QVector< TypeAndLabel > m_info
Definition: GroupInfo.h:56
QStringList itemLabels() const
Definition: GroupInfo.cpp:54
void add(const QString &itemType, const QString &itemLabel)
Definition: GroupInfo.cpp:23
void setDefaultType()
Definition: GroupInfo.h:35
QString defaultType() const
Definition: GroupInfo.cpp:33
QStringList itemTypes() const
Definition: GroupInfo.cpp:46
bool is_sorted
Definition: GroupInfo.h:55
GroupInfo(bool is_sorted=true)
Definition: GroupInfo.cpp:18
QString m_defaultItemType
Info will be sorted if true, otherwise order of insertion will be preserved.
Definition: GroupInfo.h:53
bool containsType(const QString &itemType) const
Default model type for given group (i.e. FFCylinder for formfactor group)
Definition: GroupInfo.cpp:62