BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
colormapinfoformatter.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/colormapinfoformatter.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/utils/stringutils.h"
17 #include "qcustomplot.h"
18 #include <sstream>
19 
20 using namespace ModelView;
21 
22 namespace {
23 QCPColorMap* find_colormap(QCustomPlot* custom_plot)
24 {
25  for (int i = 0; i < custom_plot->plottableCount(); ++i) {
26  if (auto plottable = dynamic_cast<QCPColorMap*>(custom_plot->plottable()); plottable)
27  return plottable;
28  }
29 
30  return nullptr;
31 }
32 
33 struct Context {
34  double xpos{0.0};
35  double ypos{0.0};
36  int nx{0};
37  int ny{0};
38  double value{0.0};
39 };
40 
41 std::string compose_string(const Context& context)
42 {
43  std::ostringstream ostr;
44  ostr << "[x: " << Utils::DoubleToString(context.xpos, 3) << ", ";
45  ostr << "y: " << Utils::DoubleToString(context.ypos, 3) << "] ";
46  ostr << "[binx: " << context.nx << ", ";
47  ostr << "biny: " << context.ny << "] ";
48  ostr << "[value: " << Utils::ScientificDoubleToString(context.value) << "]";
49  return ostr.str();
50 }
51 
52 } // namespace
53 
54 std::string ColorMapInfoFormatter::status_string(QCustomPlot* custom_plot, double x, double y) const
55 {
56  // shall we provide caching here?
57  auto color_map = find_colormap(custom_plot);
58  Context context{x, y};
59 
60  color_map->data()->coordToCell(x, y, &context.nx, &context.ny);
61  context.value = color_map->data()->cell(context.nx, context.ny);
62 
63  return compose_string(context);
64 }
std::string status_string(QCustomPlot *custom_plot, double x, double y) const override
Returns status string representing data in color map.
Defines class CLASS?
MVVM_MODEL_EXPORT std::string ScientificDoubleToString(double input, int precision=6)
Returns string representation of scientific double.
MVVM_MODEL_EXPORT std::string DoubleToString(double input, int precision=12)
Returns string representation of double with given precision.
materialitems.h Collection of materials to populate MaterialModel.
Defines class CLASS?