22 #include "qcustomplot.h"
31 QCP::MarginSides autoMarginPolicy(
int left,
int top,
int right,
int bottom)
33 QCP::MarginSides result{QCP::msAll};
35 result &= ~QCP::msLeft;
37 result &= ~QCP::msTop;
39 result &= ~QCP::msRight;
41 result &= ~QCP::msBottom;
51 std::unique_ptr<StatusStringReporter>
reporter;
58 auto on_mouse_move = [
this](
const std::string& str) {
86 auto layout =
new QVBoxLayout(
this);
88 layout->setSpacing(0);
89 layout->addWidget(
p_impl->custom_plot);
90 layout->addWidget(
p_impl->status_label);
93 setMouseTracking(
true);
94 p_impl->customPlot()->setMouseTracking(
true);
95 p_impl->customPlot()->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
96 p_impl->customPlot()->axisRect()->setupFullAxesBox(
true);
98 auto on_replot = [
this]() {
99 QMargins margins =
p_impl->customPlot()->axisRect()->margins();
102 connect(
p_impl->customPlot(), &QCustomPlot::afterReplot,
this, on_replot);
109 p_impl->viewport_controller->setItem(viewport_item);
114 return std::make_unique<CustomPlotSceneAdapter>(
p_impl->customPlot());
119 p_impl->setViewportToContent(left, top, right, bottom);
124 p_impl->setViewportToContent();
132 auto customPlot =
p_impl->customPlot();
133 customPlot->axisRect()->setAutoMargins(autoMarginPolicy(left, top, right, bottom));
135 QMargins orig = customPlot->axisRect()->margins();
136 int new_left = left >= 0 ? left : orig.left();
137 int new_top = top >= 0 ? top : orig.top();
138 int new_right = right >= 0 ? right : orig.right();
139 int new_bottom = bottom >= 0 ? bottom : orig.bottom();
140 customPlot->axisRect()->setMargins(QMargins(new_left, new_top, new_right, new_bottom));
142 customPlot->replot();
void setAxisMargins(int left, int top, int right, int bottom)
Set margins between axes rectangle and widget borders.
void setViewportToContent()
std::unique_ptr< GraphCanvasImpl > p_impl
void axisMarginsChanged(int left, int top, int right, int bottom)
void setItem(GraphViewportItem *viewport_item)
GraphCanvas(QWidget *parent=nullptr)
std::unique_ptr< SceneAdapterInterface > createSceneAdapter() const
2D viewport specialized for showing multiple GraphItem's.
Shows a single line of text on a white background.
void setText(const QString &text)
materialitems.h Collection of materials to populate MaterialModel.
std::unique_ptr< StatusStringReporter > CreateGraphReporter(QCustomPlot *custom_plot, std::function< void(const std::string &)> callback)
Creates reporter for status string in QCustomPlot containing graphs.
void setViewportToContent(double left, double top, double right, double bottom)
Updates viewport.
std::unique_ptr< StatusStringReporter > reporter
QCustomPlot * customPlot()
QCustomPlot * custom_plot
StatusLabel * status_label
std::unique_ptr< GraphViewportPlotController > viewport_controller
void setViewportToContent()
Updates viewport.