BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
viewportitem.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/viewportitem.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 
16 #include "mvvm/model/modelutils.h"
18 
19 using namespace ModelView;
20 
22 
24 {
25  return item<ViewportAxisItem>(P_XAXIS);
26 }
27 
29 {
30  return item<ViewportAxisItem>(P_YAXIS);
31 }
32 
33 //! Sets range of x,y window to show all data.
34 //! Allows adding an additional margin to automatically calculated axis range. Margins are
35 //! given in relative units wrt calculated axis range.
36 //! Example: setViewportToContent(0.0, 0.1, 0.0, 0.1) will set axes to show all graphs with 10% gap
37 //! above and below graph's max and min.
38 
39 void ViewportItem::setViewportToContent(double left, double top, double right, double bottom)
40 {
41  Utils::BeginMacros(this, "setViewportToContent");
42  auto [xmin, xmax] = data_xaxis_range();
43  xAxis()->set_range(xmin - (xmax - xmin) * left, xmax + (xmax - xmin) * right);
44 
45  auto [ymin, ymax] = data_yaxis_range();
46  yAxis()->set_range(ymin - (ymax - ymin) * bottom, ymax + (ymax - ymin) * top);
47  Utils::EndMacros(this);
48 }
49 
50 //! Sets range of x,y window to show all data.
51 
53 {
54  Utils::BeginMacros(this, "setViewportToContent");
55  auto [xmin, xmax] = data_xaxis_range();
56  xAxis()->set_range(xmin, xmax);
57 
58  auto [ymin, ymax] = data_yaxis_range();
59  yAxis()->set_range(ymin, ymax);
60  Utils::EndMacros(this);
61 }
62 
64 {
65  addProperty<ViewportAxisItem>(P_XAXIS)->setDisplayName("X axis");
66  addProperty<ViewportAxisItem>(P_YAXIS)->setDisplayName("Y axis");
67 }
Defines class CLASS?
Complex item holding mixed SessionItem types (single properties and other CompountItems).
Definition: compounditem.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
ViewportAxisItem * xAxis() const
virtual void setViewportToContent()
Sets range of x,y window to show all data.
static const std::string P_XAXIS
Definition: viewportitem.h:29
static const std::string P_YAXIS
Definition: viewportitem.h:30
virtual std::pair< double, double > data_xaxis_range() const =0
ViewportItem(const model_type &model)
ViewportAxisItem * yAxis() const
virtual std::pair< double, double > data_yaxis_range() const =0
Defines class CLASS?
MVVM_MODEL_EXPORT void EndMacros(const SessionItem *item)
Finishes undo/redo macros.
Definition: modelutils.cpp:100
MVVM_MODEL_EXPORT void BeginMacros(const SessionItem *item, const std::string &macro_name)
Begin undo/redo macros with given name.
Definition: modelutils.cpp:91
materialitems.h Collection of materials to populate MaterialModel.
std::string model_type
Definition: types.h:23
Defines class CLASS?