17 #include <qcustomplot.h>
24 QCPGraph* find_graph_nearby(QCustomPlot* custom_plot,
double x,
double y)
26 double widget_px = custom_plot->xAxis->coordToPixel(x);
27 double widget_py = custom_plot->yAxis->coordToPixel(y);
28 return dynamic_cast<QCPGraph*
>(custom_plot->plottableAt(QPointF(widget_px, widget_py)));
31 int getBin(
const QCPGraph* graph,
double x)
33 const int key_start = graph->findBegin(x);
34 const int key_end = graph->findBegin(x,
false);
35 if (key_end == key_start || key_end == graph->dataCount())
37 return (x - graph->dataSortKey(key_start)) <= (graph->dataSortKey(key_end) - x) ? key_start
44 bool close_to_graph{
false};
49 std::string compose_string(
const Context& context)
51 std::ostringstream ostr;
54 if (context.close_to_graph) {
55 ostr <<
"[binx: " << context.nx <<
"] ";
65 Context context{x, y};
67 if (
auto qcp_graph = find_graph_nearby(custom_plot, x, y); qcp_graph) {
68 context.close_to_graph =
true;
69 context.nx = getBin(qcp_graph, x);
70 context.value = qcp_graph->dataMainValue(context.nx);
73 return compose_string(context);
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.