BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
statusstringreporter.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/statusstringreporter.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 
19 #include <stdexcept>
20 
21 using namespace ModelView;
22 
25  QCustomPlot* custom_plot{nullptr};
27  std::unique_ptr<StatusStringFormatterInterface> fmt;
28  std::unique_ptr<MouseMoveReporter> mouse_reporter;
30 
33  std::unique_ptr<StatusStringFormatterInterface> formatter)
34  : parent(parent)
36  , callback(std::move(callback))
37  , fmt(std::move(formatter))
38  {
39  if (!custom_plot)
40  throw std::runtime_error("StatusStringReporter: not initialized custom plot.");
41 
42  auto on_mouse_move = [this](const MousePosInfo& pos) {
43  if (pos.in_axes_range) {
44  notify_client(pos);
47  } else {
50  }
51 
52  prevPos = pos;
53  };
54  mouse_reporter = std::make_unique<MouseMoveReporter>(custom_plot, on_mouse_move);
55  }
56 
57  //! Notify client about mouse move with formatted status string.
58 
59  void notify_client(const MousePosInfo& pos)
60  {
61  callback(fmt->status_string(this->custom_plot, pos.xpos, pos.ypos));
62  }
63 
64  //! Notify client on leaving axes area.
65 
67  {
68  // notifying client with empty string as a sign that we have left the area
69  callback({});
70  }
71 
72  //! Notify client on entering axes area.
73 
75  {
76  // for future improvements
77  }
78 };
79 
81  QCustomPlot* custom_plot, callback_t callback,
82  std::unique_ptr<StatusStringFormatterInterface> formatter)
83  : p_impl(std::make_unique<StatusStringReporterImpl>(this, custom_plot, callback,
84  std::move(formatter)))
85 {
86 }
87 
Reports back status string composed for current mouse position in QCustomPlot.
StatusStringReporter(QCustomPlot *custom_plot, callback_t callback, std::unique_ptr< StatusStringFormatterInterface > formatter)
std::function< void(const std::string &)> callback_t
Defines class CLASS?
Defines class CLASS?
materialitems.h Collection of materials to populate MaterialModel.
Definition: filesystem.h:81
Defines class CLASS?
Aggregate to hold mouse position info in QCustomPlot context.
Definition: mouseposinfo.h:27
std::unique_ptr< StatusStringFormatterInterface > fmt
void entering_the_area()
Notify client on entering axes area.
void notify_client(const MousePosInfo &pos)
Notify client about mouse move with formatted status string.
void leaving_the_area()
Notify client on leaving axes area.
StatusStringReporterImpl(StatusStringReporter *parent, QCustomPlot *custom_plot, callback_t callback, std::unique_ptr< StatusStringFormatterInterface > formatter)