BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
plottableitems.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/plottableitems.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 
17 #include <QColor>
18 
19 using namespace ModelView;
20 
21 namespace {
22 //! Following Qt styles.
23 const ComboProperty penStyleCombo = ComboProperty::createFrom(
24  {"NoPen", "SolidLine", "DashLine", "DotLine", "DashDotLine", "DashDotDotLine"}, "SolidLine");
25 const int pen_default_width = 1;
26 const int pen_min_width = 0;
27 const int pen_max_width = 7;
28 const int penstyle_index_solid = 1;
29 const int penstyle_index_dashline = 2;
30 
31 // We do not want to depend from widgetutils.h to get App default font size. Let's stick to
32 // hardcoded value for the moment, even if on different systems it can be not-optimal.
33 const int default_title_size = 10;
34 const std::string default_title_family = "Noto Sans";
35 } // namespace
36 
38 {
39  addProperty(P_TEXT, "")->setDisplayName("Text");
40  addProperty(P_FONT, default_title_family)->setDisplayName("Font");
41  addProperty(P_SIZE, default_title_size)->setDisplayName("Size");
42 }
43 
45 {
46  addProperty(P_COLOR, QColor(Qt::black))->setDisplayName("Color")->setToolTip("Pen color");
47  addProperty(P_STYLE, penStyleCombo)->setDisplayName("Style")->setToolTip("Pen style");
48  addProperty(P_WIDTH, pen_default_width)
49  ->setDisplayName("Width")
50  ->setLimits(RealLimits::limited(pen_min_width, pen_max_width))
51  ->setToolTip("Pen width");
52 }
53 
54 //! Sets style of the pen to represent selected object (dash line).
55 
56 void PenItem::setSelected(bool is_selected)
57 {
58  auto combo = penStyleCombo;
59  combo.setCurrentIndex(is_selected ? penstyle_index_dashline : penstyle_index_solid);
60  setProperty(P_STYLE, combo);
61 }
62 
63 //! Returns color name in #RRGGBB format.
64 //! We do not want to expose QColor itself since it will be eventually removed.
65 
66 std::string PenItem::colorName() const
67 {
68  return property<QColor>(P_COLOR).name().toStdString();
69 }
70 
71 //! Sets named color following schema from https://www.w3.org/TR/css-color-3/#svg-color.
72 //! e.g. "mediumaquamarine"
73 //! We do not want to expose QColor itself since it will be eventually removed.
74 
75 void PenItem::setNamedColor(const std::string& named_color)
76 {
77  setProperty(P_COLOR, QColor(QString::fromStdString(named_color)));
78 }
Custom property to define list of string values with multiple selections.
Definition: comboproperty.h:27
static ComboProperty createFrom(const std::vector< std::string > &values, const std::string &current_value={})
void setCurrentIndex(int index)
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
static const std::string P_STYLE
static const std::string P_COLOR
static const std::string P_WIDTH
void setSelected(bool is_selected)
Sets style of the pen to represent selected object (dash line).
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.
static RealLimits limited(double left_bound_value, double right_bound_value)
Creates an object bounded from the left and right.
Definition: reallimits.cpp:61
void setProperty(const std::string &tag, const T &value)
Sets value to property item.
Definition: sessionitem.h:190
static const std::string P_SIZE
static const std::string P_FONT
static const std::string P_TEXT
Defines class CLASS?
const model_type TextItemType
Definition: mvvm_types.h:60
const model_type PenItemType
Definition: mvvm_types.h:57
materialitems.h Collection of materials to populate MaterialModel.
Defines class CLASS?