BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
colormapviewportitem.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // qt-mvvm: Model-view-view-model framework for large GUI applications
4 //
5 //! @file mvvm/model/mvvm/standarditems/colormapviewportitem.cpp
6 //! @brief Implements class CLASS?
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2020
11 //! @authors Gennady Pospelov et al, Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
19 #include <algorithm>
20 #include <vector>
21 
22 namespace {
23 const std::pair<double, double> default_axis_range{0.0, 1.0};
24 }
25 
26 using namespace ModelView;
27 
29 {
31  addProperty<ViewportAxisItem>(P_ZAXIS)->setDisplayName("color-axis");
32  // for the moment allow only one ColorMapItem
33  registerTag(TagInfo(T_ITEMS, 0, 1, {Constants::ColorMapItemType}), /*set_default*/ true);
34 }
35 
37 {
38  return item<ViewportAxisItem>(P_ZAXIS);
39 }
40 
42 {
45 }
46 
47 //! Returns range of x-axis as defined in underlying Data2DItem.
48 
49 std::pair<double, double> ColorMapViewportItem::data_xaxis_range() const
50 {
51  auto dataItem = data_item();
52  return dataItem && dataItem->xAxis() ? dataItem->xAxis()->range() : default_axis_range;
53 }
54 
55 //! Returns range of y-axis as defined in underlying Data2DItem.
56 
57 std::pair<double, double> ColorMapViewportItem::data_yaxis_range() const
58 {
59  auto dataItem = data_item();
60  return dataItem && dataItem->yAxis() ? dataItem->yAxis()->range() : default_axis_range;
61 }
62 
63 //! Returns Data2DItem if exists.
64 
66 {
67  auto colormap_item = item<ColorMapItem>(T_ITEMS);
68  return colormap_item ? colormap_item->dataItem() : nullptr;
69 }
70 
71 //! Updates zAxis to lower, upper values over all data points.
72 
74 {
75  if (auto dataItem = data_item(); dataItem) {
76  auto values = dataItem->content();
77  auto [lower, upper] = std::minmax_element(std::begin(values), std::end(values));
78  zAxis()->set_range(*lower, *upper);
79  }
80 }
Defines class CLASS?
void update_data_range()
Updates zAxis to lower, upper values over all data points.
virtual std::pair< double, double > data_yaxis_range() const override
Returns range of y-axis as defined in underlying Data2DItem.
Data2DItem * data_item() const
Returns Data2DItem if exists.
virtual std::pair< double, double > data_xaxis_range() const override
Returns range of x-axis as defined in underlying Data2DItem.
ViewportAxisItem * zAxis() const
void setViewportToContent() override
Sets range of x,y window to show all data.
static const std::string P_ZAXIS
Represents two-dimensional data (axes definition and 2d array of values).
Definition: data2ditem.h:29
void registerTag(const TagInfo &tagInfo, bool set_as_default=false)
Registers tag to hold items under given name.
Holds info about single tag for SessionItem.
Definition: taginfo.h:28
Item to represent viewport axis.
Definition: axisitems.h:43
void set_range(double lower, double upper)
Sets lower, upper range of axis to given values.
Definition: axisitems.cpp:51
Base class to represent 2D viewport.
Definition: viewportitem.h:27
virtual void setViewportToContent()
Sets range of x,y window to show all data.
static const std::string T_ITEMS
Definition: viewportitem.h:31
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
const model_type ColorMapItemType
Definition: mvvm_types.h:46
const model_type ColorMapViewportItemType
Definition: mvvm_types.h:47
materialitems.h Collection of materials to populate MaterialModel.