BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
axistitlecontroller.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/axistitlecontroller.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 "qcustomplot.h"
18 #include <stdexcept>
19 
20 using namespace ModelView;
21 
23  QCPAxis* m_axis{nullptr};
24 
25  AxisTitleControllerImpl(QCPAxis* axis) : m_axis(axis)
26  {
27  if (!axis)
28  throw std::runtime_error("AxisTitleController: axis is not initialized.");
29  }
30 
32  {
33  auto font = m_axis->labelFont();
34  font.setPointSize(item->property<int>(TextItem::P_SIZE));
35  font.setFamily(QString::fromStdString(item->property<std::string>(TextItem::P_FONT)));
36  m_axis->setLabel(QString::fromStdString(item->property<std::string>(TextItem::P_TEXT)));
37  m_axis->setLabelFont(font);
38 
39  m_axis->parentPlot()->replot();
40  }
41 };
42 
44  : p_impl(std::make_unique<AxisTitleControllerImpl>(axis))
45 
46 {
47 }
48 
50 
52 {
53  auto on_property_change = [this](auto, auto) { p_impl->updateAxisFromItem(currentItem()); };
54  setOnPropertyChange(on_property_change);
55 
56  p_impl->updateAxisFromItem(currentItem());
57 }
Defines class CLASS?
std::unique_ptr< AxisTitleControllerImpl > p_impl
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.
T property(const std::string &tag) const
Returns data stored in property item.
Definition: sessionitem.h:181
Represent text item on plot.
static const std::string P_SIZE
static const std::string P_FONT
static const std::string P_TEXT
materialitems.h Collection of materials to populate MaterialModel.
Definition: filesystem.h:81
Defines class CLASS?