BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ModelView::GraphCanvas Class Reference

Widget to show scientific figure with multiple 1D graphs. More...

Inheritance diagram for ModelView::GraphCanvas:
[legend]
Collaboration diagram for ModelView::GraphCanvas:
[legend]

Classes

struct  GraphCanvasImpl
 

Signals

void axisMarginsChanged (int left, int top, int right, int bottom)
 

Public Member Functions

 GraphCanvas (QWidget *parent=nullptr)
 
 ~GraphCanvas () override
 
std::unique_ptr< SceneAdapterInterfacecreateSceneAdapter () const
 
void setAxisMargins (int left, int top, int right, int bottom)
 Set margins between axes rectangle and widget borders. More...
 
void setItem (GraphViewportItem *viewport_item)
 
void setViewportToContent ()
 
void setViewportToContent (double left, double top, double right, double bottom)
 

Private Attributes

std::unique_ptr< GraphCanvasImplp_impl
 

Detailed Description

Widget to show scientific figure with multiple 1D graphs.

Contains embedded QCustomPlot widget, shows content of GraphViewportItem.

Definition at line 30 of file graphcanvas.h.

Constructor & Destructor Documentation

◆ GraphCanvas()

GraphCanvas::GraphCanvas ( QWidget *  parent = nullptr)
explicit

Definition at line 83 of file graphcanvas.cpp.

84  : QWidget(parent), p_impl(std::make_unique<GraphCanvasImpl>())
85 {
86  auto layout = new QVBoxLayout(this);
87  layout->setMargin(0);
88  layout->setSpacing(0);
89  layout->addWidget(p_impl->custom_plot);
90  layout->addWidget(p_impl->status_label);
91  setLayout(layout);
92 
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);
97 
98  auto on_replot = [this]() {
99  QMargins margins = p_impl->customPlot()->axisRect()->margins();
100  axisMarginsChanged(margins.left(), margins.top(), margins.right(), margins.bottom());
101  };
102  connect(p_impl->customPlot(), &QCustomPlot::afterReplot, this, on_replot);
103 }
std::unique_ptr< GraphCanvasImpl > p_impl
Definition: graphcanvas.h:51
void axisMarginsChanged(int left, int top, int right, int bottom)

References axisMarginsChanged(), and p_impl.

◆ ~GraphCanvas()

GraphCanvas::~GraphCanvas ( )
overridedefault

Member Function Documentation

◆ axisMarginsChanged

void ModelView::GraphCanvas::axisMarginsChanged ( int  left,
int  top,
int  right,
int  bottom 
)
signal

◆ createSceneAdapter()

std::unique_ptr< SceneAdapterInterface > GraphCanvas::createSceneAdapter ( ) const

Definition at line 112 of file graphcanvas.cpp.

113 {
114  return std::make_unique<CustomPlotSceneAdapter>(p_impl->customPlot());
115 }

References p_impl.

Referenced by gui2::GraphicsScene::createPlotProxy().

◆ setAxisMargins()

void GraphCanvas::setAxisMargins ( int  left,
int  top,
int  right,
int  bottom 
)

Set margins between axes rectangle and widget borders.

If the value is negative, leave old margin intact and allow automatic margin adjustment.

Definition at line 130 of file graphcanvas.cpp.

131 {
132  auto customPlot = p_impl->customPlot();
133  customPlot->axisRect()->setAutoMargins(autoMarginPolicy(left, top, right, bottom));
134 
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));
141 
142  customPlot->replot();
143 }

References p_impl.

Referenced by gui2::SimPlotWidget::SimPlotWidget().

◆ setItem()

void GraphCanvas::setItem ( GraphViewportItem viewport_item)

Definition at line 107 of file graphcanvas.cpp.

108 {
109  p_impl->viewport_controller->setItem(viewport_item);
110 }

References p_impl.

Referenced by gui2::GraphCanvasWidget::setItem(), gui2::GraphicsScene::setItem(), and gui2::SimPlotWidget::setModels().

◆ setViewportToContent() [1/2]

void GraphCanvas::setViewportToContent ( )

Definition at line 122 of file graphcanvas.cpp.

123 {
124  p_impl->setViewportToContent();
125 }

References p_impl.

◆ setViewportToContent() [2/2]

void GraphCanvas::setViewportToContent ( double  left,
double  top,
double  right,
double  bottom 
)

Definition at line 117 of file graphcanvas.cpp.

118 {
119  p_impl->setViewportToContent(left, top, right, bottom);
120 }

References p_impl.

Referenced by gui2::SLDEditor::SLDEditor(), gui2::GraphCanvasWidget::updateViewport(), and gui2::SimPlotWidget::updateViewport().

Member Data Documentation

◆ p_impl

std::unique_ptr<GraphCanvasImpl> ModelView::GraphCanvas::p_impl
private

The documentation for this class was generated from the following files: