BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
colormapcanvas.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/colormapcanvas.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 
22 #include "qcustomplot.h"
23 
24 using namespace ModelView;
25 
27  QCustomPlot* custom_plot{nullptr};
28  std::unique_ptr<ColorMapViewportPlotController> viewport_controller;
29  std::unique_ptr<StatusStringReporter> reporter;
30  StatusLabel* status_label{nullptr};
31 
32  ColorMapCanvasImpl() : custom_plot(new QCustomPlot), status_label(new StatusLabel)
33  {
34  viewport_controller = std::make_unique<ColorMapViewportPlotController>(custom_plot);
35 
36  auto on_mouse_move = [this](const std::string& str) {
37  status_label->setText(QString::fromStdString(str));
38  };
39  reporter = CreateColorMapReporter(custom_plot, on_mouse_move);
40  }
41 
42  QCustomPlot* customPlot() { return custom_plot; }
43 };
44 
46  : QWidget(parent), p_impl(std::make_unique<ColorMapCanvasImpl>())
47 {
48  auto layout = new QVBoxLayout(this);
49  layout->setMargin(0);
50  layout->setSpacing(0);
51  layout->addWidget(p_impl->custom_plot);
52  layout->addWidget(p_impl->status_label);
53  setLayout(layout);
54 
55  p_impl->customPlot()->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
56  p_impl->customPlot()->axisRect()->setupFullAxesBox(true);
57 }
58 
60 
62 {
63  p_impl->viewport_controller->setItem(viewport_item);
64 }
65 
66 //! Creates adapter to convert widget coordinates, to QCustomPlot internal coordinate system
67 //! (defined by its axes).
68 
69 std::unique_ptr<SceneAdapterInterface> ColorMapCanvas::createSceneAdapter() const
70 {
71  return std::make_unique<CustomPlotSceneAdapter>(p_impl->customPlot());
72 }
ColorMapCanvas(QWidget *parent=nullptr)
void setItem(ColorMapViewportItem *viewport_item)
std::unique_ptr< SceneAdapterInterface > createSceneAdapter() const
Creates adapter to convert widget coordinates, to QCustomPlot internal coordinate system (defined by ...
std::unique_ptr< ColorMapCanvasImpl > p_impl
Container with viewport and collection of ColorMapItem's to plot.
Shows a single line of text on a white background.
Definition: statuslabel.h:29
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
materialitems.h Collection of materials to populate MaterialModel.
std::unique_ptr< StatusStringReporter > CreateColorMapReporter(QCustomPlot *custom_plot, std::function< void(const std::string &)> callback)
Creates reporter for status string in QCustomPlot containing QCPColorMap.
Definition: filesystem.h:81
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
std::unique_ptr< ColorMapViewportPlotController > viewport_controller
std::unique_ptr< StatusStringReporter > reporter