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

Provides logic for manipulating items belonging to GroupItem parent. More...

Collaboration diagram for GroupItemController:
[legend]

Public Member Functions

 GroupItemController (SessionItem *groupItem, GroupInfo groupInfo)
 
QVariant createCombo () const
 
int currentIndex () const
 
SessionItemcurrentItem ()
 
QString currentType () const
 
SessionItemgetItemOfType (const QString &type)
 Returns item of give type. More...
 
void setCurrentIndex (int index)
 
void setCurrentType (const QString &type)
 

Private Member Functions

SessionItemaddItem (const QString &item_type)
 
SessionItemcreateCorrespondingItem ()
 
QStringList itemLabels () const
 
QStringList itemTypes () const
 
int toIndex (const QString &type) const
 
QString toString (int currentIndex) const
 

Private Attributes

QString m_current_type
 
GroupInfo m_groupInfo
 
SessionItemm_groupItem
 

Detailed Description

Provides logic for manipulating items belonging to GroupItem parent.

Definition at line 26 of file GroupItemController.h.

Constructor & Destructor Documentation

◆ GroupItemController()

GroupItemController::GroupItemController ( SessionItem groupItem,
GroupInfo  groupInfo 
)

Definition at line 20 of file GroupItemController.cpp.

21  : m_groupItem(groupItem), m_groupInfo(groupInfo)
22 {
25 }
QString defaultType() const
Definition: GroupInfo.cpp:40
SessionItem * createCorrespondingItem()
bool insertItem(int row, SessionItem *item, const QString &tag="")
Insert item into given tag into given row.

References createCorrespondingItem(), GroupInfo::defaultType(), SessionItem::insertItem(), m_current_type, m_groupInfo, and m_groupItem.

Here is the call graph for this function:

Member Function Documentation

◆ addItem()

SessionItem * GroupItemController::addItem ( const QString &  item_type)
private

Definition at line 108 of file GroupItemController.cpp.

109 {
110  return ItemFactory::CreateItem(item_type);
111 }
SessionItem * CreateItem(const QString &model_name, SessionItem *parent=nullptr)
create SessionItem of specific type and parent
Definition: ItemFactory.cpp:30

References ItemFactory::CreateItem().

Referenced by createCorrespondingItem(), and getItemOfType().

Here is the call graph for this function:

◆ createCombo()

QVariant GroupItemController::createCombo ( ) const

Definition at line 90 of file GroupItemController.cpp.

91 {
92  ComboProperty result;
93  result.setValues(itemLabels());
94  result.setCurrentIndex(currentIndex());
95  return result.variant();
96 }
Custom property to define list of string values with multiple selections.
Definition: ComboProperty.h:25
QVariant variant() const
Constructs variant enclosing given ComboProperty.
void setCurrentIndex(int index)
void setValues(const QStringList &values)
Sets new list of values. Current value will be preserved, if exists in a new list.
QStringList itemLabels() const

References currentIndex(), itemLabels(), ComboProperty::setCurrentIndex(), ComboProperty::setValues(), and ComboProperty::variant().

Here is the call graph for this function:

◆ createCorrespondingItem()

SessionItem * GroupItemController::createCorrespondingItem ( )
private

Definition at line 113 of file GroupItemController.cpp.

114 {
115  return addItem(currentType());
116 }
QString currentType() const
SessionItem * addItem(const QString &item_type)

References addItem(), and currentType().

Referenced by GroupItemController(), and setCurrentType().

Here is the call graph for this function:

◆ currentIndex()

int GroupItemController::currentIndex ( ) const

Definition at line 80 of file GroupItemController.cpp.

81 {
82  return toIndex(m_current_type);
83 }
int toIndex(const QString &type) const

References m_current_type, and toIndex().

Referenced by createCombo().

Here is the call graph for this function:

◆ currentItem()

SessionItem * GroupItemController::currentItem ( )

Definition at line 27 of file GroupItemController.cpp.

28 {
29  return m_groupItem ? m_groupItem->getChildOfType(currentType()) : nullptr;
30 }
SessionItem * getChildOfType(const QString &type) const
Returns the first child of the given type.

References currentType(), SessionItem::getChildOfType(), and m_groupItem.

Referenced by setCurrentType().

Here is the call graph for this function:

◆ currentType()

QString GroupItemController::currentType ( ) const

Definition at line 32 of file GroupItemController.cpp.

33 {
34  return m_current_type;
35 }

References m_current_type.

Referenced by createCorrespondingItem(), currentItem(), getItemOfType(), and setCurrentType().

◆ getItemOfType()

SessionItem * GroupItemController::getItemOfType ( const QString &  type)

Returns item of give type.

If it doesn't exist, it will be created. Method do not change current item.

Definition at line 62 of file GroupItemController.cpp.

63 {
64  if (m_groupItem) {
65  if (auto item = m_groupItem->getChildOfType(type)) {
66  return item;
67  } else {
68  SessionItem* new_item = addItem(type);
69  if (type != currentType()) {
70  new_item->setVisible(false);
71  new_item->setEnabled(false);
72  }
73  m_groupItem->insertItem(-1, new_item);
74  return new_item;
75  }
76  }
77  return nullptr;
78 }
void setVisible(bool enabled)
Flags accessors.
void setEnabled(bool enabled)

References addItem(), currentType(), SessionItem::getChildOfType(), SessionItem::insertItem(), m_groupItem, SessionItem::setEnabled(), and SessionItem::setVisible().

Here is the call graph for this function:

◆ itemLabels()

QStringList GroupItemController::itemLabels ( ) const
private

Definition at line 103 of file GroupItemController.cpp.

104 {
105  return m_groupInfo.itemLabels();
106 }
QStringList itemLabels() const
Definition: GroupInfo.cpp:69

References GroupInfo::itemLabels(), and m_groupInfo.

Referenced by createCombo().

Here is the call graph for this function:

◆ itemTypes()

QStringList GroupItemController::itemTypes ( ) const
private

Definition at line 98 of file GroupItemController.cpp.

99 {
100  return m_groupInfo.itemTypes();
101 }
QStringList itemTypes() const
Definition: GroupInfo.cpp:60

References GroupInfo::itemTypes(), and m_groupInfo.

Referenced by toIndex(), and toString().

Here is the call graph for this function:

◆ setCurrentIndex()

void GroupItemController::setCurrentIndex ( int  index)

Definition at line 85 of file GroupItemController.cpp.

86 {
87  setCurrentType(toString(index));
88 }
void setCurrentType(const QString &type)
QString toString(int currentIndex) const

References setCurrentType(), and toString().

Here is the call graph for this function:

◆ setCurrentType()

void GroupItemController::setCurrentType ( const QString &  type)

Definition at line 37 of file GroupItemController.cpp.

38 {
39  if (type == currentType())
40  return;
41 
42  auto prevItem = currentItem();
43  m_current_type = type;
44 
45  if (m_groupItem) {
46  if (auto item = m_groupItem->getChildOfType(m_current_type)) {
47  item->setVisible(true);
48  item->setEnabled(true);
49  } else {
51  }
52  if (prevItem) {
53  prevItem->setVisible(false);
54  prevItem->setEnabled(false);
55  }
56  }
57 }
SessionItem * currentItem()

References createCorrespondingItem(), currentItem(), currentType(), SessionItem::getChildOfType(), SessionItem::insertItem(), m_current_type, and m_groupItem.

Referenced by setCurrentIndex().

Here is the call graph for this function:

◆ toIndex()

int GroupItemController::toIndex ( const QString &  type) const
private

Definition at line 118 of file GroupItemController.cpp.

119 {
120  return itemTypes().indexOf(type);
121 }
QStringList itemTypes() const

References itemTypes().

Referenced by currentIndex().

Here is the call graph for this function:

◆ toString()

QString GroupItemController::toString ( int  currentIndex) const
private

Definition at line 123 of file GroupItemController.cpp.

124 {
125  return itemTypes().at(index);
126 }

References itemTypes().

Referenced by setCurrentIndex().

Here is the call graph for this function:

Member Data Documentation

◆ m_current_type

QString GroupItemController::m_current_type
private

◆ m_groupInfo

GroupInfo GroupItemController::m_groupInfo
private

Definition at line 52 of file GroupItemController.h.

Referenced by GroupItemController(), itemLabels(), and itemTypes().

◆ m_groupItem

SessionItem* GroupItemController::m_groupItem
private

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