BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
DataPropertyContainer.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Models/DataPropertyContainer.cpp
6 //! @brief Implements class DataPropertyContainer
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 DataPropertyContainer::T_CHILDREN = "data links";
21 
23 {
24  registerTag(T_CHILDREN, 0, -1, QStringList() << "DataItem1DProperties");
26 }
27 
28 QVector<Data1DProperties*> DataPropertyContainer::propertyItems()
29 {
30  QVector<Data1DProperties*> result;
31  auto source = getItems();
32  std::transform(source.begin(), source.end(), std::back_inserter(result),
33  [](SessionItem* item) { return dynamic_cast<Data1DProperties*>(item); });
34  return result;
35 }
36 
38 {
39  auto children = getItems();
40  if (children.empty())
41  return nullptr;
42  auto property_item = dynamic_cast<Data1DProperties*>(children[static_cast<int>(i)]);
43  ASSERT(property_item);
44  return property_item;
45 }
46 
48 {
49  auto basic_property_item = propertyItem(0);
50  if (!basic_property_item)
51  return nullptr;
52  return basic_property_item->dataItem();
53 }
54 
56 {
57  if (this->model() != data_item->model())
58  throw GUIHelpers::Error(
59  "Error in DataPropertyContainer::addItem: hosting models are different");
60 
61  auto property_items = propertyItems();
62  Data1DProperties* previous_item = nullptr;
63  if (!propertyItems().empty())
64  previous_item = dynamic_cast<Data1DProperties*>(propertyItems().back());
65 
66  auto property_item = new Data1DProperties();
67  insertItem(-1, property_item);
68  property_item->setDataItem(data_item);
69  property_item->setColorProperty(Data1DProperties::nextColorName(previous_item));
70 }
71 
72 std::vector<DataItem*> DataPropertyContainer::dataItems()
73 {
74  std::vector<DataItem*> result;
75  auto items = propertyItems();
76  std::transform(items.begin(), items.end(), std::back_inserter(result),
77  [](Data1DProperties* item) {
78  auto data_item = item->dataItem();
79  ASSERT(data_item);
80  return data_item;
81  });
82  return result;
83 }
84 
86 {
87  return propertyItem(i)->dataItem();
88 }
#define ASSERT(condition)
Definition: Assert.h:31
Declares class DataItem.
Defines class DataProperties and its descendants.
Defines class DataPropertyContainer.
Defines class GUIHelpers functions.
Holds data required for 1D DataItem representation.
static const QString & nextColorName(Data1DProperties *properties)
Returns the name of the color, which follows the color of passes property container.
Provides common functionality for IntensityDataItem and SpecularDataItem.
Definition: DataItem.h:29
DataItem * dataItem()
Data1DProperties * propertyItem(size_t i) const
void addItem(DataItem *data_item)
QVector< Data1DProperties * > propertyItems()
std::vector< DataItem * > dataItems()
DataItem * dataItem(size_t i) const
static const QString T_CHILDREN
bool insertItem(int row, SessionItem *item, const QString &tag="")
Insert item into given tag into given row.
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.
QVector< SessionItem * > getItems(const QString &tag="") const
Returns vector of all items of given tag.
void setDefaultTag(const QString &tag)
Set default tag.
SessionModel * model() const
Returns model of this item.
Definition: SessionItem.cpp:66
T * item(const QString &tag) const
Definition: SessionItem.h:151
QVector< SessionItem * > children() const
Returns vector of all children.