BornAgain  1.19.79
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/Model/Data/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 #include "GUI/Util/Error.h"
20 
22  : SessionItem(M_TYPE)
23 {
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 Error("Error in DataPropertyContainer::addItem: hosting models are different");
59 
60  Data1DProperties* previous_item = nullptr;
61  if (!propertyItems().empty())
62  previous_item = dynamic_cast<Data1DProperties*>(propertyItems().back());
63 
64  auto* property_item = new Data1DProperties();
65  insertChild(-1, property_item);
66  property_item->setDataItem(data_item);
67  property_item->setColorProperty(Data1DProperties::nextColorName(previous_item));
68 
69  if (dynamic_cast<RealDataItem*>(data_item->parentItem())) {
70  property_item->setScatterProperty("Disc");
71  property_item->setLineProperty("None");
72  } else {
73  property_item->setScatterProperty("None");
74  property_item->setLineProperty("Line");
75  }
76 }
77 
78 std::vector<DataItem*> DataPropertyContainer::dataItems()
79 {
80  std::vector<DataItem*> result;
81  auto items = propertyItems();
82  std::transform(items.begin(), items.end(), std::back_inserter(result),
83  [](Data1DProperties* item) {
84  auto* data_item = item->dataItem();
85  ASSERT(data_item);
86  return data_item;
87  });
88  return result;
89 }
90 
92 {
93  return propertyItem(i)->dataItem();
94 }
Declares class DataItem.
Defines class DataProperties and its descendants.
Defines class DataPropertyContainer.
Defines error class.
Defines class RealDataItem.
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....
static constexpr auto M_TYPE
Abstract base class for IntensityDataItem and SpecularDataItem. Owns one simulated data set of type D...
Definition: DataItem.h:34
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 constexpr auto T_CHILDREN
DataItem * basicDataItem() const
Provides access to experimental data, for display and fitting. Owns an AbstractDataLoader.
Definition: RealDataItem.h:33
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.
void insertChild(int row, SessionItem *item, const QString &tag="")
Insert item into given tag into given row.
void setDefaultTag(const QString &tag)
Set default tag.
SessionModel * model() const
Returns model of this item.
Definition: SessionItem.cpp:60
T * item(const QString &tag) const
Definition: SessionItem.h:353
SessionItem * parentItem() const
Returns parent of this item.
Definition: SessionItem.cpp:67
QVector< T * > items(const QString &tag="") const
Definition: SessionItem.h:361
QVector< SessionItem * > children() const
Returns vector of all children.
Definition: SessionItem.cpp:95