BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
GroupInfo Class Reference

Defines info for GroupProperty, i.e. More...

Classes

struct  TypeAndLabel
 

Public Member Functions

 GroupInfo (const QString &groupType="", bool is_sorted=true)
 
void add (const QString &itemType, const QString &itemLabel)
 
QString defaultType () const
 
QString groupType () const
 
bool isValid ()
 
QStringList itemLabels () const
 
QStringList itemTypes () const
 
void setDefaultType (const QString &modelType)
 

Private Member Functions

bool containsType (const QString &itemType) const
 Default model type for given group (i.e. FFCylinder for formfactor group) More...
 

Private Attributes

bool is_sorted
 
QString m_defaultItemType
 Unique group name for GroupInfoCatalog. More...
 
QString m_groupType
 Info will be sorted if true, otherwise order of insertion will be preserved. More...
 
QVector< TypeAndLabelm_info
 

Detailed Description

Defines info for GroupProperty, i.e.

collection of model types, their labels and the name of default item's modelType.

Definition at line 25 of file GroupInfo.h.

Constructor & Destructor Documentation

◆ GroupInfo()

GroupInfo::GroupInfo ( const QString &  groupType = "",
bool  is_sorted = true 
)
explicit

Definition at line 18 of file GroupInfo.cpp.

20 {
21 }
QString m_groupType
Info will be sorted if true, otherwise order of insertion will be preserved.
Definition: GroupInfo.h:53
bool is_sorted
Definition: GroupInfo.h:55
QString groupType() const
Definition: GroupInfo.cpp:55

Member Function Documentation

◆ add()

void GroupInfo::add ( const QString &  itemType,
const QString &  itemLabel 
)

Definition at line 23 of file GroupInfo.cpp.

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 }
QVector< TypeAndLabel > m_info
Definition: GroupInfo.h:56
bool containsType(const QString &itemType) const
Default model type for given group (i.e. FFCylinder for formfactor group)
Definition: GroupInfo.cpp:83

References containsType(), groupType(), is_sorted, and m_info.

Referenced by GroupInfoCatalog::GroupInfoCatalog().

Here is the call graph for this function:

◆ containsType()

bool GroupInfo::containsType ( const QString &  itemType) const
private

Default model type for given group (i.e. FFCylinder for formfactor group)

Definition at line 83 of file GroupInfo.cpp.

84 {
85  for (auto& pair : m_info)
86  if (itemType == pair.m_itemType)
87  return true;
88 
89  return false;
90 }

References m_info.

Referenced by add(), and setDefaultType().

◆ defaultType()

QString GroupInfo::defaultType ( ) const

Definition at line 40 of file GroupInfo.cpp.

41 {
42  if (m_defaultItemType == "" && m_info.size() != 0)
43  return m_info[0].m_itemType;
44  return m_defaultItemType;
45 }
QString m_defaultItemType
Unique group name for GroupInfoCatalog.
Definition: GroupInfo.h:51

References m_defaultItemType, and m_info.

Referenced by GroupItemController::GroupItemController().

◆ groupType()

QString GroupInfo::groupType ( ) const

Definition at line 55 of file GroupInfo.cpp.

56 {
57  return m_groupType;
58 }

References m_groupType.

Referenced by add(), and GroupInfoCatalog::addInfo().

◆ isValid()

bool GroupInfo::isValid ( )

Definition at line 78 of file GroupInfo.cpp.

79 {
80  return !m_groupType.isEmpty();
81 }

References m_groupType.

◆ itemLabels()

QStringList GroupInfo::itemLabels ( ) const

Definition at line 69 of file GroupInfo.cpp.

70 {
71  QStringList result;
72  for (auto& pair : m_info)
73  result.append(pair.m_itemLabel);
74 
75  return result;
76 }

References m_info.

Referenced by GroupItemController::itemLabels().

◆ itemTypes()

QStringList GroupInfo::itemTypes ( ) const

Definition at line 60 of file GroupInfo.cpp.

61 {
62  QStringList result;
63  for (auto& pair : m_info)
64  result.append(pair.m_itemType);
65 
66  return result;
67 }

References m_info.

Referenced by GroupItemController::itemTypes().

◆ setDefaultType()

void GroupInfo::setDefaultType ( const QString &  modelType)

Definition at line 47 of file GroupInfo.cpp.

48 {
49  if (!containsType(modelType))
50  throw GUIHelpers::Error("GroupInfo::add() -> Error. No such type '" + modelType + "'");
51 
52  m_defaultItemType = modelType;
53 }

References containsType(), and m_defaultItemType.

Referenced by GroupInfoCatalog::GroupInfoCatalog().

Here is the call graph for this function:

Member Data Documentation

◆ is_sorted

bool GroupInfo::is_sorted
private

Definition at line 55 of file GroupInfo.h.

Referenced by add().

◆ m_defaultItemType

QString GroupInfo::m_defaultItemType
private

Unique group name for GroupInfoCatalog.

Definition at line 51 of file GroupInfo.h.

Referenced by defaultType(), and setDefaultType().

◆ m_groupType

QString GroupInfo::m_groupType
private

Info will be sorted if true, otherwise order of insertion will be preserved.

Definition at line 53 of file GroupInfo.h.

Referenced by groupType(), and isValid().

◆ m_info

QVector<TypeAndLabel> GroupInfo::m_info
private

Definition at line 56 of file GroupInfo.h.

Referenced by add(), containsType(), defaultType(), itemLabels(), and itemTypes().


The documentation for this class was generated from the following files: