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

Description

Holds all tag info for SessionItem.

Definition at line 24 of file SessionItemTags.h.

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. If number of items for given tagName exceeds maximum allowed, returns -1;. More...
 
bool isSingleItemTag (const QString &tagName) const
 
bool 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. 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. Returns true in case of success. Returns false if parameters are invalid or such tag was already registered. 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
 

Member Function Documentation

◆ addChild()

void SessionItemTags::addChild ( const QString &  tagName)

Definition at line 113 of file SessionItemTags.cpp.

114 {
115  ASSERT(!maximumReached(tagName));
116  tagInfo(tagName).childCount++;
117 }
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 103 of file SessionItemTags.cpp.

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

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 108 of file SessionItemTags.cpp.

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

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  ASSERT(row >= 0 && row < tagInfo(tagName).childCount);
73  return tagStartIndex(tagName) + row;
74 }
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 79 of file SessionItemTags.cpp.

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

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

Here is the call graph for this function:

◆ isSingleItemTag()

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

Definition at line 126 of file SessionItemTags.cpp.

127 {
128  if (!isValid(tagName))
129  return false;
130  const auto& tag = tagInfo(tagName);
131  return tag.min == 1 && tag.max == 1 && tag.childCount == 1;
132 }
bool isValid(const QString &tagName, const QString &modelType="") const
Returns true if there is a registered tag with such name. If modelType is not empty,...

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 147 of file SessionItemTags.cpp.

148 {
149  const auto& tag = tagInfo(tagName);
150  return tag.max != -1 && tag.max == tag.childCount;
151 }

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:20

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

Here is the call graph for this function:

◆ removeChild()

void SessionItemTags::removeChild ( const QString &  tagName)

Definition at line 119 of file SessionItemTags.cpp.

120 {
121  auto& tag = tagInfo(tagName);
122  ASSERT(tag.childCount > 0);
123  tag.childCount--;
124 }

References tagInfo().

Here is the call graph for this function:

◆ tagFromIndex()

QString SessionItemTags::tagFromIndex ( int  index) const

Definition at line 91 of file SessionItemTags.cpp.

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

References m_tags.

◆ tagInfo() [1/2]

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

Definition at line 134 of file SessionItemTags.cpp.

135 {
136  return const_cast<TagInfo&>(static_cast<const SessionItemTags*>(this)->tagInfo(tagName));
137 }
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 139 of file SessionItemTags.cpp.

140 {
141  for (const auto& tag : m_tags)
142  if (tag.name == tagName)
143  return tag;
144  ASSERT(0);
145 }

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  ASSERT(0);
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: