BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
pencontroller.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/view/mvvm/plotting/pencontroller.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 
18 #include "qcustomplot.h"
19 #include <stdexcept>
20 
21 using namespace ModelView;
22 
23 namespace {
24 //! Returns Qt pen style from current ComboProperty index.
25 Qt::PenStyle getQtPenFromComboIndex(const ComboProperty& combo)
26 {
27  // our ComboProperty for pens coincide with Qt definition
28  return static_cast<Qt::PenStyle>(combo.currentIndex());
29 }
30 } // namespace
31 
33  QCPGraph* m_graph{nullptr};
34  PenControllerImpl(QCPGraph* graph) : m_graph(graph)
35  {
36  if (!m_graph)
37  throw std::runtime_error("Error in PenController: uninitialised graph.");
38  }
39 
41  {
42  QColor color(QString::fromStdString(item->colorName()));
43  auto pencombo = item->property<ComboProperty>(PenItem::P_STYLE);
44  auto penwidth = item->property<int>(PenItem::P_WIDTH);
45 
46  QPen pen;
47  pen.setColor(color);
48  pen.setStyle(getQtPenFromComboIndex(pencombo));
49  pen.setWidth(penwidth);
50  m_graph->setPen(pen);
51 
52  m_graph->parentPlot()->replot();
53  }
54 };
55 
56 PenController::PenController(QCPGraph* graph) : p_impl(std::make_unique<PenControllerImpl>(graph))
57 {
58 }
59 
61 
63 {
64  auto on_property_change = [this](auto, auto) { p_impl->update_graph_from_item(currentItem()); };
65  setOnPropertyChange(on_property_change);
66 
67  p_impl->update_graph_from_item(currentItem());
68 }
Custom property to define list of string values with multiple selections.
Definition: comboproperty.h:27
void setOnPropertyChange(Callbacks::item_str_t f)
Sets callback to be notified on item's property change.
SessionItem * item() const
For necessary manipulations on unsubscription.
void subscribe() override
PenController(QCPGraph *graph)
std::unique_ptr< PenControllerImpl > p_impl
Definition: pencontroller.h:40
Represents basics settings of QPen.
static const std::string P_STYLE
static const std::string P_WIDTH
T property(const std::string &tag) const
Returns data stored in property item.
Definition: sessionitem.h:181
Defines class CLASS?
materialitems.h Collection of materials to populate MaterialModel.
Definition: filesystem.h:81
Defines class CLASS?
Defines class CLASS?