BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
DataItemUtils.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Models/DataItemUtils.cpp
6 //! @brief Implements namespace DataItemUtils
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 
21 
22 namespace {
23 template <class DataItemType> DataItemType* dataItem(SessionItem* parent)
24 {
25  ASSERT(parent && "Assertion failed in DataItemUtils::dataItem: nullptr passed.");
26 
27  if (parent->modelType() == "JobItem")
28  return dynamic_cast<DataItemType*>(parent->getItem(JobItem::T_OUTPUT));
29  else if (auto real_data = dynamic_cast<RealDataItem*>(parent))
30  return dynamic_cast<DataItemType*>(real_data->dataItem());
31  else if (auto self = dynamic_cast<DataItemType*>(parent))
32  return self;
33 
34  throw GUIHelpers::Error("Error in DataItemUtils::dataItem: unexpected item passed.");
35 }
36 } // namespace
37 
39 {
40  return dataItem<IntensityDataItem>(parent);
41 }
42 
44 {
45  return dataItem<SpecularDataItem>(parent);
46 }
#define ASSERT(condition)
Definition: Assert.h:31
Defines namespace DataItemUtils.
Defines class GUIHelpers functions.
Defines class IntensityDataItem.
Defines class JobItem.
Defines class RealDataItem.
Defines class SpecularDataItem.
static const QString T_OUTPUT
Definition: JobItem.h:50
The RealDataItem class represents intensity data imported from file and intended for fitting.
Definition: RealDataItem.h:35
QString modelType() const
Get model type.
SessionItem * getItem(const QString &tag="", int row=0) const
Returns item in given row of given tag.
SpecularDataItem * specularDataItem(SessionItem *parent)
Returns SpecularDataItem contained as a child in givent parent.
IntensityDataItem * intensityDataItem(SessionItem *parent)
Returns IntensityDataItem contained as a child in givent parent.