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

Description

Provides logic for manipulating items belonging to GroupItem parent.

Definition at line 26 of file GroupItemController.h.

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. If it doesn't exist, it will be created. Method do not change current item. 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
 

Constructor & Destructor Documentation

◆ GroupItemController()

GroupItemController::GroupItemController ( SessionItem groupItem,
GroupInfo  groupInfo 
)

Definition at line 22 of file GroupItemController.cpp.

23  : m_groupItem(groupItem)
24  , m_groupInfo(std::move(groupInfo))
25 {
28 }
QString defaultType() const
Definition: GroupInfo.cpp:33
SessionItem * createCorrespondingItem()
void insertChild(int row, SessionItem *item, const QString &tag="")
Insert item into given tag into given row.

References createCorrespondingItem(), GroupInfo::defaultType(), SessionItem::insertChild(), 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 104 of file GroupItemController.cpp.

105 {
106  return GUI::Model::ItemFactory::CreateItem(item_type);
107 }
SessionItem * CreateItem(const QString &model_name, SessionItem *parent=nullptr)
create SessionItem of specific type and parent
Definition: ItemFactory.cpp:19

References GUI::Model::ItemFactory::CreateItem().

Referenced by createCorrespondingItem(), and getItemOfType().

Here is the call graph for this function:

◆ createCombo()

QVariant GroupItemController::createCombo ( ) const

Definition at line 86 of file GroupItemController.cpp.

87 {
88  ComboProperty result;
89  result.setValues(itemLabels());
90  result.setCurrentIndex(currentIndex());
91  return result.variant();
92 }
Custom property to define list of string values with multiple selections. Intended for QVariant.
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 109 of file GroupItemController.cpp.

110 {
111  return addItem(currentType());
112 }
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 76 of file GroupItemController.cpp.

77 {
78  return toIndex(m_current_type);
79 }
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 30 of file GroupItemController.cpp.

31 {
32  return m_groupItem ? m_groupItem->getChildOfType(currentType()) : nullptr;
33 }
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 35 of file GroupItemController.cpp.

36 {
37  return m_current_type;
38 }

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  return nullptr;
66  if (auto* item = m_groupItem->getChildOfType(type))
67  return item;
68  SessionItem* new_item = addItem(type);
69  if (type != currentType())
70  new_item->setEnabled(false);
71 
72  m_groupItem->insertChild(-1, new_item);
73  return new_item;
74 }
Base class for a GUI data item.
Definition: SessionItem.h:204
void setEnabled(bool enabled)
Flags accessors.

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

Here is the call graph for this function:

◆ itemLabels()

QStringList GroupItemController::itemLabels ( ) const
private

Definition at line 99 of file GroupItemController.cpp.

100 {
101  return m_groupInfo.itemLabels();
102 }
QStringList itemLabels() const
Definition: GroupInfo.cpp:54

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 94 of file GroupItemController.cpp.

95 {
96  return m_groupInfo.itemTypes();
97 }
QStringList itemTypes() const
Definition: GroupInfo.cpp:46

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 81 of file GroupItemController.cpp.

82 {
83  setCurrentType(toString(index));
84 }
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 40 of file GroupItemController.cpp.

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

References createCorrespondingItem(), currentItem(), currentType(), SessionItem::getChildOfType(), SessionItem::insertChild(), 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 114 of file GroupItemController.cpp.

115 {
116  return itemTypes().indexOf(type);
117 }
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 119 of file GroupItemController.cpp.

120 {
121  return itemTypes().at(index);
122 }

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: