BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
SpecularDataCanvas.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/PlotSpecular/SpecularDataCanvas.cpp
6 //! @brief Implements class SpecularDataCanvas
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
21 #include <qcustomplot.h>
22 
24  : SessionItemWidget(parent)
25  , m_plot_canvas(new SpecularPlotCanvas)
26  , m_reset_view_action(nullptr)
27  , m_save_plot_action(nullptr)
28 
29 {
30  auto* vlayout = new QVBoxLayout(this);
31  vlayout->setSpacing(0);
32  vlayout->setContentsMargins(0, 0, 0, 0);
33  vlayout->addWidget(m_plot_canvas);
34  setLayout(vlayout);
35  setStyleSheet("background-color:white;");
36 
37  initActions();
38 
40 
41  enableDeprecatedOnMousePress(true); // true for legacy reasons
42 }
43 
45 {
46  SessionItemWidget::setItem(intensityItem);
47  m_plot_canvas->setItem(intensityItem);
48 }
49 
51 {
52  return QSize(500, 400);
53 }
54 
56 {
57  return QSize(128, 128);
58 }
59 
61 {
62  return QList<QAction*>() << m_reset_view_action << m_save_plot_action;
63 }
64 
66 {
67  return m_plot_canvas->customPlot();
68 }
69 
71 {
72  if (b)
73  connect(m_plot_canvas->customPlot(), &QCustomPlot::mousePress, this,
74  &SpecularDataCanvas::onMousePress, Qt::UniqueConnection);
75  else
76  disconnect(m_plot_canvas->customPlot(), &QCustomPlot::mousePress, this,
78 }
79 
81 {
83 }
84 
86 {
88 }
89 
91 {
92  QString dirname = gSessionData->projectDocument.value()->userExportDir();
93  GUI::Plot::savePlot(dirname, m_plot_canvas->customPlot(), specularDataItem()->getDatafield());
94 }
95 
96 void SpecularDataCanvas::onMousePress(QMouseEvent* event)
97 {
98  if (event->button() == Qt::RightButton)
99  emit customContextMenuRequested(event->globalPos());
100 }
101 
103 {
104  auto* result = dynamic_cast<SpecularDataItem*>(currentItem());
105  ASSERT(result);
106  return result;
107 }
108 
109 // TODO: try to reuse IntensityDataCanvas::initActions somehow
111 {
112  m_reset_view_action = new QAction(this);
113  m_reset_view_action->setText("Center view");
114  m_reset_view_action->setIcon(QIcon(":/images/camera-metering-center.svg"));
115  m_reset_view_action->setToolTip("Center view\n"
116  "x,y axes range will be set to default");
117  connect(m_reset_view_action, &QAction::triggered, this, &SpecularDataCanvas::onResetViewAction);
118 
119  m_save_plot_action = new QAction(this);
120  m_save_plot_action->setText("Save");
121  m_save_plot_action->setIcon(QIcon(":/images/content-save-outline.svg"));
122  m_save_plot_action->setToolTip("Save plot");
123  connect(m_save_plot_action, &QAction::triggered, this, &SpecularDataCanvas::onSavePlotAction);
124 }
Defines class ProjectDocument.
Defines class SavePlotAssistant.
SessionData * gSessionData
global pointer to the single instance
Definition: SessionData.cpp:17
Defines struct SessionData.
Defines class SpecularDataCanvas.
Defines class SpecularDataItem.
Defines class ColorMapCanvas.
The SessionItemWidget class is a base for all widgets representing the content of SessionItem....
SessionItem * currentItem()
virtual void setItem(SessionItem *item)
Base class for a GUI data item.
Definition: SessionItem.h:204
void setItem(SessionItem *intensityItem) override
QList< QAction * > actionList() override
SpecularPlotCanvas * m_plot_canvas
void onMousePress(QMouseEvent *event)
QSize minimumSizeHint() const override
SpecularDataCanvas(QWidget *parent=nullptr)
QCustomPlot * customPlot()
SpecularDataItem * specularDataItem()
void enableDeprecatedOnMousePress(bool b)
Enable or disable the onMousePress() handler. For legacy reasons the onMousePress handler is enabled....
QSize sizeHint() const override
void resetView()
Set axes viewport to original data.
The SpecularPlotCanvas class contains SpecularPlot for specular data presentation,...
void setItem(SessionItem *specularDataItem) override
QCustomPlot * customPlot()
void setStatusLabelEnabled(bool flag)
void savePlot(const QString &dirname, QCustomPlot *plot, Datafield *output_data)
std::optional< ProjectDocument * > projectDocument
Definition: SessionData.h:27