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

Holds all tag info for SessionItem. More...

Classes

struct  TagInfo
 

Public Member Functions

void addChild (const QString &tagName)
 
int childCount (const QString &tagName)
 
int childMax (const QString &tagName)
 
int indexFromTagRow (const QString &tagName, int row) const
 Returns index in SessionItem's m_children corresponding to given row in tagName. More...
 
int insertIndexFromTagRow (const QString &tagName, int row)
 Returns index in SessionItem's m_children to insert new item. More...
 
bool isSingleItemTag (const QString &tagName)
 
bool isValid (const QString &tagName, const QString &modelType="") const
 Returns true if there is a registered tag with such name. More...
 
bool maximumReached (const QString &tagName) const
 
QStringList modelTypesForTag (const QString &tagName) const
 Returns list of modelTypes the given tagName is intended for. More...
 
bool registerTag (const QString &name, int min, int max, const QStringList &modelTypes)
 Register tag with given parameters. More...
 
void removeChild (const QString &tagName)
 
QString tagFromIndex (int index) const
 
int tagStartIndex (const QString &tagName) const
 Returns start index of given tagName corresponding to the index of SessionItem's m_children. More...
 

Private Member Functions

TagInfotagInfo (const QString &tagName)
 
const TagInfotagInfo (const QString &tagName) const
 

Private Attributes

QVector< TagInfom_tags
 

Detailed Description

Holds all tag info for SessionItem.

Definition at line 24 of file SessionItemTags.h.

Member Function Documentation

◆ addChild()

void SessionItemTags::addChild ( const QString &  tagName)

Definition at line 114 of file SessionItemTags.cpp.

115 {
116  if (maximumReached(tagName))
117  throw GUIHelpers::Error("SessionItemTags::addChild() -> Error. Can't exceed maximum"
118  "allowed number of children.");
119  tagInfo(tagName).childCount++;
120 }
TagInfo & tagInfo(const QString &tagName)
bool maximumReached(const QString &tagName) const

References SessionItemTags::TagInfo::childCount, maximumReached(), and tagInfo().

Here is the call graph for this function:

◆ childCount()

int SessionItemTags::childCount ( const QString &  tagName)

Definition at line 104 of file SessionItemTags.cpp.

105 {
106  return tagInfo(tagName).childCount;
107 }

References SessionItemTags::TagInfo::childCount, and tagInfo().

Referenced by indexFromTagRow().

Here is the call graph for this function:

◆ childMax()

int SessionItemTags::childMax ( const QString &  tagName)

Definition at line 109 of file SessionItemTags.cpp.

110 {
111  return tagInfo(tagName).max;
112 }

References SessionItemTags::TagInfo::max, and tagInfo().

Here is the call graph for this function:

◆ indexFromTagRow()

int SessionItemTags::indexFromTagRow ( const QString &  tagName,
int  row 
) const

Returns index in SessionItem's m_children corresponding to given row in tagName.

Definition at line 70 of file SessionItemTags.cpp.

71 {
72  if (row < 0 || row >= tagInfo(tagName).childCount)
73  throw GUIHelpers::Error("SessionItemTags::tagIndexFromRow() -> Error. Wrong row");
74  return tagStartIndex(tagName) + row;
75 }
int childCount(const QString &tagName)
int tagStartIndex(const QString &tagName) const
Returns start index of given tagName corresponding to the index of SessionItem's m_children.

References childCount(), tagInfo(), and tagStartIndex().

Here is the call graph for this function:

◆ insertIndexFromTagRow()

int SessionItemTags::insertIndexFromTagRow ( const QString &  tagName,
int  row 
)

Returns index in SessionItem's m_children to insert new item.

If number of items for given tagName exceeds maximum allowed, returns -1;

Definition at line 80 of file SessionItemTags.cpp.

81 {
82  if (maximumReached(tagName))
83  return -1;
84  auto& tag = tagInfo(tagName);
85  if (row > tag.childCount)
86  return -1;
87  if (row < 0)
88  row = tag.childCount;
89  return tagStartIndex(tagName) + row;
90 }

References maximumReached(), tagInfo(), and tagStartIndex().

Here is the call graph for this function:

◆ isSingleItemTag()

bool SessionItemTags::isSingleItemTag ( const QString &  tagName)

Definition at line 131 of file SessionItemTags.cpp.

132 {
133  if (!isValid(tagName))
134  return false;
135  const auto& tag = tagInfo(tagName);
136  return tag.min == 1 && tag.max == 1 && tag.childCount == 1;
137 }
bool isValid(const QString &tagName, const QString &modelType="") const
Returns true if there is a registered tag with such name.

References isValid(), and tagInfo().

Referenced by SessionItem::displayName().

Here is the call graph for this function:

◆ isValid()

bool SessionItemTags::isValid ( const QString &  tagName,
const QString &  modelType = "" 
) const

Returns true if there is a registered tag with such name.

If modelType is not empty, than an additional check is performed if tag is intended for the given modelType.

Definition at line 36 of file SessionItemTags.cpp.

37 {
38  for (const auto& tag : m_tags) {
39  if (tag.name == tagName) {
40  if (modelType.isEmpty())
41  return true;
42  return tag.modelTypes.isEmpty() ? true : tag.modelTypes.contains(modelType);
43  }
44  }
45  return false;
46 }
QVector< TagInfo > m_tags

References m_tags.

Referenced by SessionModel::insertNewItem(), isSingleItemTag(), modelTypesForTag(), SessionModel::moveItem(), and registerTag().

◆ maximumReached()

bool SessionItemTags::maximumReached ( const QString &  tagName) const

Definition at line 152 of file SessionItemTags.cpp.

153 {
154  const auto& tag = tagInfo(tagName);
155  if (tag.max != -1 && tag.max == tag.childCount)
156  return true;
157  return false;
158 }

References tagInfo().

Referenced by addChild(), insertIndexFromTagRow(), and SessionModel::moveItem().

Here is the call graph for this function:

◆ modelTypesForTag()

QStringList SessionItemTags::modelTypesForTag ( const QString &  tagName) const

Returns list of modelTypes the given tagName is intended for.

Definition at line 50 of file SessionItemTags.cpp.

51 {
52  return isValid(tagName) ? tagInfo(tagName).modelTypes : QStringList();
53 }

References isValid(), SessionItemTags::TagInfo::modelTypes, and tagInfo().

Here is the call graph for this function:

◆ registerTag()

bool SessionItemTags::registerTag ( const QString &  name,
int  min,
int  max,
const QStringList &  modelTypes 
)

Register tag with given parameters.

Returns true in case of success. Returns false if parameters are invalid or such tag was already registered.

Definition at line 21 of file SessionItemTags.cpp.

23 {
24  if (min < 0 || (min > max && max >= 0))
25  return false;
26  if (name.isEmpty() || isValid(name))
27  return false;
28  m_tags.push_back({name, min, max, 0, modelTypes});
29  return true;
30 }
QString const & name(EShape k)
Definition: particles.cpp:21

References isValid(), m_tags, and RealSpace::Particles::name().

Here is the call graph for this function:

◆ removeChild()

void SessionItemTags::removeChild ( const QString &  tagName)

Definition at line 122 of file SessionItemTags.cpp.

123 {
124  auto& tag = tagInfo(tagName);
125  if (tag.childCount == 0)
126  throw GUIHelpers::Error("SessionItemTags::removeChild() -> Error. Attempt to remove "
127  "unexisting child.");
128  tag.childCount--;
129 }

References tagInfo().

Here is the call graph for this function:

◆ tagFromIndex()

QString SessionItemTags::tagFromIndex ( int  index) const

Definition at line 92 of file SessionItemTags.cpp.

93 {
94  if (index < 0)
95  return "";
96  for (const auto& tag : m_tags) {
97  if (index < tag.childCount)
98  return tag.name;
99  index -= tag.childCount;
100  }
101  return "";
102 }

References m_tags.

◆ tagInfo() [1/2]

SessionItemTags::TagInfo & SessionItemTags::tagInfo ( const QString &  tagName)
private

Definition at line 139 of file SessionItemTags.cpp.

140 {
141  return const_cast<TagInfo&>(static_cast<const SessionItemTags*>(this)->tagInfo(tagName));
142 }
Holds all tag info for SessionItem.

Referenced by addChild(), childCount(), childMax(), indexFromTagRow(), insertIndexFromTagRow(), isSingleItemTag(), maximumReached(), modelTypesForTag(), and removeChild().

◆ tagInfo() [2/2]

const SessionItemTags::TagInfo & SessionItemTags::tagInfo ( const QString &  tagName) const
private

Definition at line 144 of file SessionItemTags.cpp.

145 {
146  for (const auto& tag : m_tags)
147  if (tag.name == tagName)
148  return tag;
149  throw GUIHelpers::Error("SessionItemTags::tagInfo() -> Error. No such tag '" + tagName + "'.");
150 }

References m_tags.

◆ tagStartIndex()

int SessionItemTags::tagStartIndex ( const QString &  tagName) const

Returns start index of given tagName corresponding to the index of SessionItem's m_children.

Definition at line 57 of file SessionItemTags.cpp.

58 {
59  int index(0);
60  for (const auto& tag : m_tags) {
61  if (tag.name == tagName)
62  return index;
63  index += tag.childCount;
64  }
65  throw GUIHelpers::Error("SessionItemTags::tagStartIndex() -> Error. Can';t find start index");
66 }

References m_tags.

Referenced by indexFromTagRow(), and insertIndexFromTagRow().

Member Data Documentation

◆ m_tags

QVector<TagInfo> SessionItemTags::m_tags
private

Definition at line 61 of file SessionItemTags.h.

Referenced by isValid(), registerTag(), tagFromIndex(), tagInfo(), and tagStartIndex().


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