BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
GroupItem.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Models/GroupItem.cpp
6 //! @brief Implements class GroupItem
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
19 
20 const QString GroupItem::T_ITEMS = "Item tag";
21 
22 GroupItem::GroupItem() : SessionItem("GroupProperty")
23 {
26 
27  mapper()->setOnValueChange([this]() { onValueChange(); });
28 }
29 
30 GroupItem::~GroupItem() = default;
31 
32 void GroupItem::setGroupInfo(const GroupInfo& groupInfo)
33 {
34  if (m_controller)
35  throw GUIHelpers::Error("GroupItem::setGroup() -> Error. Attempt to set group twice.");
36 
37  m_controller = std::make_unique<GroupItemController>(this, groupInfo);
39 }
40 
42 {
43  return m_controller ? m_controller->currentItem() : nullptr;
44 }
45 
46 QString GroupItem::currentType() const
47 {
48  return m_controller->currentType();
49 }
50 
51 SessionItem* GroupItem::setCurrentType(const QString& modelType)
52 {
53  m_controller->setCurrentType(modelType);
55  return currentItem();
56 }
57 
58 QStringList GroupItem::translateList(const QStringList& list) const
59 {
60  // we do not add here the name of itself
61  return list;
62 }
63 
65 {
66  return m_controller->getItemOfType(type);
67 }
68 
70 {
71  if (!value().canConvert<ComboProperty>())
72  throw GUIHelpers::Error("GroupItem::onValueChange() -> Error. Wrong property type");
73 
74  ComboProperty property = value().value<ComboProperty>();
75  if (property.currentIndex() != m_controller->currentIndex()) {
76  m_controller->setCurrentIndex(property.currentIndex());
77  // because of the delay between ComboProperty change and the change in GroupItem here,
78  // we have to emit signals once again to inform other views (i.e. views other than the view
79  // were property was changed)
80  emitDataChanged(Qt::DisplayRole | Qt::EditRole);
81  }
82 }
83 
85 {
86  setValue(m_controller->createCombo());
87 }
Defines class ComboProperty.
Defines class GUIHelpers functions.
Defines class GroupItemController.
Defines class GroupItem.
Custom property to define list of string values with multiple selections.
Definition: ComboProperty.h:25
Defines info for GroupProperty, i.e.
Definition: GroupInfo.h:25
SessionItem * setCurrentType(const QString &modelType)
Definition: GroupItem.cpp:51
void setGroupInfo(const GroupInfo &groupInfo)
Definition: GroupItem.cpp:32
void updateComboValue()
Definition: GroupItem.cpp:84
QStringList translateList(const QStringList &list) const
Definition: GroupItem.cpp:58
SessionItem * currentItem() const
Definition: GroupItem.cpp:41
void onValueChange()
Definition: GroupItem.cpp:69
QString currentType() const
Definition: GroupItem.cpp:46
SessionItem * getItemOfType(const QString &type)
Definition: GroupItem.cpp:64
std::unique_ptr< GroupItemController > m_controller
Definition: GroupItem.h:45
static const QString T_ITEMS
Definition: GroupItem.h:27
void setOnValueChange(std::function< void(void)> f, const void *caller=0)
Definition: ModelMapper.cpp:30
bool registerTag(const QString &name, int min=0, int max=-1, QStringList modelTypes={})
Add new tag to this item with given name, min, max and types.
QVariant value() const
Get value.
bool setValue(QVariant value)
Set value, ensure that variant types match.
ModelMapper * mapper()
Returns the current model mapper of this item. Creates new one if necessary.
void setDefaultTag(const QString &tag)
Set default tag.
void emitDataChanged(int role=Qt::DisplayRole)
Notify model about data changes.
QString modelType() const
Get model type.