BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
graphitem.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/graphitem.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 
20 #include <QColor>
21 
22 using namespace ModelView;
23 
25 {
26  addProperty<LinkedItem>(P_LINK)->setDisplayName("Link");
27  addProperty<TextItem>(P_GRAPH_TITLE)->setDisplayName("Graph title");
28  addProperty<PenItem>(P_PEN)->setDisplayName("Pen");
29  addProperty(P_DISPLAYED, true)->setDisplayName("Displayed");
30 }
31 
32 //! Sets link to the data item.
33 
34 void GraphItem::setDataItem(const Data1DItem* data_item)
35 {
36  item<LinkedItem>(P_LINK)->setLink(data_item);
37 }
38 
39 //! Update item from the content of given graph. Link to the data will be set
40 //! as in given item, other properties copied.
41 
42 void GraphItem::setFromGraphItem(const GraphItem* graph_item)
43 {
44  setDataItem(graph_item->dataItem());
45  auto pen = item<PenItem>(P_PEN);
46  auto source_pen = graph_item->item<PenItem>(P_PEN);
47  pen->setProperty(PenItem::P_COLOR, source_pen->property<QColor>(PenItem::P_COLOR));
48  pen->setProperty(PenItem::P_STYLE, source_pen->property<ComboProperty>(PenItem::P_STYLE));
49  pen->setProperty(PenItem::P_WIDTH, source_pen->property<int>(PenItem::P_WIDTH));
50 }
51 
52 //! Returns data item linked to the given GraphItem.
53 
55 {
56  return item<LinkedItem>(P_LINK)->get<Data1DItem>();
57 }
58 
59 std::vector<double> GraphItem::binCenters() const
60 {
61  return dataItem() ? dataItem()->binCenters() : std::vector<double>();
62 }
63 
64 std::vector<double> GraphItem::binValues() const
65 {
66  return dataItem() ? dataItem()->binValues() : std::vector<double>();
67 }
68 
69 std::vector<double> GraphItem::binErrors() const
70 {
71  return dataItem() ? dataItem()->binErrors() : std::vector<double>();
72 }
73 
74 //! Returns color name in #RRGGBB format.
75 
76 std::string GraphItem::colorName() const
77 {
78  return penItem()->colorName();
79 }
80 
81 //! Sets named color following schema from https://www.w3.org/TR/css-color-3/#svg-color.
82 //! e.g. "mediumaquamarine"
83 
84 void GraphItem::setNamedColor(const std::string& named_color)
85 {
86  penItem()->setNamedColor(named_color);
87 }
88 
90 {
91  return item<PenItem>(P_PEN);
92 }
Custom property to define list of string values with multiple selections.
Definition: comboproperty.h:27
Complex item holding mixed SessionItem types (single properties and other CompountItems).
Definition: compounditem.h:28
T * addProperty(const std::string &name)
Adds property item of given type.
Definition: compounditem.h:43
Represents one-dimensional data (axis and values).
Definition: data1ditem.h:30
std::vector< double > binValues() const
Returns values stored in bins.
Definition: data1ditem.cpp:76
std::vector< double > binCenters() const
Sets axis. Bin content will be set to zero.
Definition: data1ditem.cpp:57
std::vector< double > binErrors() const
Returns value errors stored in bins.
Definition: data1ditem.cpp:93
One-dimensional graph representation of Data1DItem.
Definition: graphitem.h:29
std::string colorName() const
Returns color name in #RRGGBB format.
Definition: graphitem.cpp:76
static const std::string P_DISPLAYED
Definition: graphitem.h:34
static const std::string P_GRAPH_TITLE
Definition: graphitem.h:32
std::vector< double > binValues() const
Definition: graphitem.cpp:64
Data1DItem * dataItem() const
Returns data item linked to the given GraphItem.
Definition: graphitem.cpp:54
static const std::string P_PEN
Definition: graphitem.h:33
void setDataItem(const Data1DItem *item)
Sets link to the data item.
Definition: graphitem.cpp:34
PenItem * penItem() const
Definition: graphitem.cpp:89
std::vector< double > binCenters() const
Definition: graphitem.cpp:59
void setFromGraphItem(const GraphItem *graph_item)
Update item from the content of given graph.
Definition: graphitem.cpp:42
void setNamedColor(const std::string &named_color)
Sets named color following schema from https://www.w3.org/TR/css-color-3/#svg-color.
Definition: graphitem.cpp:84
static const std::string P_LINK
Definition: graphitem.h:31
std::vector< double > binErrors() const
Definition: graphitem.cpp:69
GraphItem(const std::string &model_type=Constants::GraphItemType)
Definition: graphitem.cpp:24
Represents basics settings of QPen.
static const std::string P_STYLE
static const std::string P_COLOR
static const std::string P_WIDTH
std::string colorName() const
Returns color name in #RRGGBB format.
void setNamedColor(const std::string &named_color)
Sets named color following schema from https://www.w3.org/TR/css-color-3/#svg-color.
T * item(const std::string &tag) const
Returns first item under given tag casted to a specified type.
Definition: sessionitem.h:156
virtual SessionItem * setDisplayName(const std::string &name)
Sets display name (fluent interface).
void setProperty(const std::string &tag, const T &value)
Sets value to property item.
Definition: sessionitem.h:190
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
materialitems.h Collection of materials to populate MaterialModel.
std::string model_type
Definition: types.h:23
Defines class CLASS?