BornAgain  1.19.79
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/Model/BaseItem/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 
16 #include "GUI/Util/ComboProperty.h"
17 #include "GUI/Util/Error.h"
18 
20  : SessionItem(M_TYPE)
21 {
24 
25  mapper()->setOnValueChange([this]() { onValueChange(); });
26 }
27 
28 GroupItem::~GroupItem() = default;
29 
30 void GroupItem::setGroupInfo(const GroupInfo& groupInfo)
31 {
32  if (m_controller)
33  throw Error("GroupItem::setGroup() -> Error. Attempt to set group twice.");
34 
35  m_controller = std::make_unique<GroupItemController>(this, groupInfo);
37 }
38 
40 {
41  return m_controller ? m_controller->currentItem() : nullptr;
42 }
43 
44 QString GroupItem::currentType() const
45 {
46  return m_controller->currentType();
47 }
48 
49 SessionItem* GroupItem::setCurrentType(const QString& modelType)
50 {
51  m_controller->setCurrentType(modelType);
53  return currentItem();
54 }
55 
56 SessionItem* GroupItem::getItemOfType(const QString& type) const
57 {
58  return m_controller->getItemOfType(type);
59 }
60 
61 QVector<SessionItem*> GroupItem::groupItems() const
62 {
63  return getItems(T_ITEMS);
64 }
65 
66 bool GroupItem::isItemsTagName(const QString& name)
67 {
68  return name == T_ITEMS;
69 }
70 
72 {
73  if (!value().canConvert<ComboProperty>())
74  throw Error("GroupItem::onValueChange() -> Error. Wrong property type");
75 
76  auto property = value().value<ComboProperty>();
77  if (property.currentIndex() != m_controller->currentIndex()) {
78  m_controller->setCurrentIndex(property.currentIndex());
79  // because of the delay between ComboProperty change and the change in GroupItem here,
80  // we have to emit signals once again to inform other views (i.e. views other than the view
81  // were property was changed)
82  emitDataChanged(Qt::DisplayRole | Qt::EditRole);
83  }
84 }
85 
87 {
88  setValue(m_controller->createCombo());
89 }
Defines class ComboProperty.
Defines error class.
Defines class GroupItem.
Custom property to define list of string values with multiple selections. Intended for QVariant.
Definition: ComboProperty.h:25
Defines info for GroupProperty, i.e. collection of model types, their labels and the name of default ...
Definition: GroupInfo.h:25
SessionItem * setCurrentType(const QString &modelType)
Definition: GroupItem.cpp:49
void setGroupInfo(const GroupInfo &groupInfo)
Definition: GroupItem.cpp:30
void updateComboValue()
Definition: GroupItem.cpp:86
static bool isItemsTagName(const QString &name)
Definition: GroupItem.cpp:66
static constexpr auto T_ITEMS
Definition: GroupItem.h:27
SessionItem * getItemOfType(const QString &type) const
Definition: GroupItem.cpp:56
QVector< SessionItem * > groupItems() const
Definition: GroupItem.cpp:61
SessionItem * currentItem() const
Definition: GroupItem.cpp:39
~GroupItem() override
void onValueChange()
Definition: GroupItem.cpp:71
QString currentType() const
Definition: GroupItem.cpp:44
std::unique_ptr< GroupItemController > m_controller
Definition: GroupItem.h:53
void setOnValueChange(std::function< void(void)> f, const void *caller=nullptr)
Definition: ModelMapper.cpp:34
Base class for a GUI data item.
Definition: SessionItem.h:204
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. max = -1 -> unlimited,...
QVector< SessionItem * > getItems(const QString &tag="") const
Returns vector of all items of given tag.
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.
QString const & name(EShape k)
Definition: particles.cpp:20