BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
SpecularPlot.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/PlotSpecular/SpecularPlot.h
6 //! @brief Defines class SpecularPlot
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 
15 #ifndef BORNAGAIN_GUI_VIEW_PLOTSPECULAR_SPECULARPLOT_H
16 #define BORNAGAIN_GUI_VIEW_PLOTSPECULAR_SPECULARPLOT_H
17 
19 #include <memory>
20 #include <qcustomplot.h>
21 
22 class BasicAxisItem;
23 class SpecularDataItem;
24 class SpecularPlotEvent;
25 class UpdateTimer;
26 
27 //! The SpecularPlot class presents 1D intensity data from SpecularDataItem.
28 
29 //! Provides minimal functionality for data plotting and axes interaction. Should be a component
30 //! for more complicated plotting widgets. Corresponds to ColorMap for 2D intensity data.
31 
32 class SpecularPlot : public ScientificPlot {
33  Q_OBJECT
34 
35 public:
36  explicit SpecularPlot(QWidget* parent = nullptr);
37 
38  QSize sizeHint() const override { return QSize(500, 400); }
39  QSize minimumSizeHint() const override { return QSize(128, 128); }
40 
41  //! Returns PlotEventInfo corresponding to given axes coordinates.
42  PlotEventInfo eventInfo(double xpos, double ypos) const override;
43 
44  QCustomPlot* customPlot() override { return m_custom_plot; }
45  const QCustomPlot* customPlot() const override { return m_custom_plot; }
46 
47  //! sets logarithmic scale
48  void setLog(bool log);
49 
50  //! reset all axes min,max to initial value
51  void resetView();
52 
53  //! Adds scatter ro real data plot
54  void initScatter();
55 
56 private slots:
57  //! updates plot depending on IntensityDataItem properties
58  void onPropertyChanged(const QString& property_name);
59 
60  //! Propagate xmin, xmax back to IntensityDataItem
61  void onXaxisRangeChanged(QCPRange newRange);
62 
63  //! Propagate ymin, ymax back to IntensityDataItem
64  void onYaxisRangeChanged(QCPRange newRange);
65 
66  //! Replots SpecularPlot.
67  void onTimeToReplot();
68 
69 protected:
70  void subscribeToItem() override;
71  void unsubscribeFromItem() override;
72 
73 private:
74  //! creates and initializes the color map
75  void initPlot();
76 
77  void setConnected(bool isConnected);
78 
79  //! Connects/disconnects signals related to SpecularPlot's X,Y axes rectangle change.
80  void setAxesRangeConnected(bool isConnected);
81 
82  void setUpdateTimerConnected(bool isConnected);
83 
84  //! Sets initial state of SpecularPlot to match given intensity item.
86 
87  //! Sets (xmin,xmax) and (ymin,ymax) of SpecularPlot from specular item.
88  //! Also sets logarithmic scale on y-axis if necessary.
90 
91  //! Sets X,Y axes labels from item
93 
94  //! Sets label to axis
95  void setLabel(const BasicAxisItem* item, QCPAxis* axis, QString label);
96 
97  //! Sets the intensity values to SpecularPlot.
99 
101  const SpecularDataItem* specularItem() const;
102 
103  void modifyAxesProperties(const QString& axisName, const QString& propertyName);
104 
105  //! Schedule replot for later execution by onTimeReplot() slot.
106  void replot();
107 
108  QCustomPlot* m_custom_plot;
110 
112 };
113 
114 #endif // BORNAGAIN_GUI_VIEW_PLOTSPECULAR_SPECULARPLOT_H
Declares class ScientificPlot.
Contains parameters of mouse position in 1D or 2D plot.
Definition: PlotEventInfo.h:26
Common interface for plot-descriptor interaction.
The SpecularPlot class presents 1D intensity data from SpecularDataItem.
Definition: SpecularPlot.h:32
QCustomPlot * customPlot() override
Definition: SpecularPlot.h:44
bool m_block_update
Definition: SpecularPlot.h:111
void initPlot()
creates and initializes the color map
void setAxesRangeConnected(bool isConnected)
Connects/disconnects signals related to SpecularPlot's X,Y axes rectangle change.
void setConnected(bool isConnected)
void setAxesLabelsFromItem(SpecularDataItem *item)
Sets X,Y axes labels from item.
SpecularPlot(QWidget *parent=nullptr)
void setLog(bool log)
sets logarithmic scale
PlotEventInfo eventInfo(double xpos, double ypos) const override
Returns PlotEventInfo corresponding to given axes coordinates.
UpdateTimer * m_update_timer
Definition: SpecularPlot.h:109
QSize sizeHint() const override
Definition: SpecularPlot.h:38
void setUpdateTimerConnected(bool isConnected)
void onXaxisRangeChanged(QCPRange newRange)
Propagate xmin, xmax back to IntensityDataItem.
void setPlotFromItem(SpecularDataItem *specularItem)
Sets initial state of SpecularPlot to match given intensity item.
void initScatter()
Adds scatter ro real data plot.
void setAxesRangeFromItem(SpecularDataItem *item)
Sets (xmin,xmax) and (ymin,ymax) of SpecularPlot from specular item. Also sets logarithmic scale on y...
void modifyAxesProperties(const QString &axisName, const QString &propertyName)
const QCustomPlot * customPlot() const override
Definition: SpecularPlot.h:45
void onTimeToReplot()
Replots SpecularPlot.
void setLabel(const BasicAxisItem *item, QCPAxis *axis, QString label)
Sets label to axis.
void onPropertyChanged(const QString &property_name)
updates plot depending on IntensityDataItem properties
QCustomPlot * m_custom_plot
Definition: SpecularPlot.h:108
void setDataFromItem(SpecularDataItem *item)
Sets the intensity values to SpecularPlot.
void subscribeToItem() override
SpecularDataItem * specularItem()
QSize minimumSizeHint() const override
Definition: SpecularPlot.h:39
void replot()
Schedule replot for later execution by onTimeReplot() slot.
void unsubscribeFromItem() override
void onYaxisRangeChanged(QCPRange newRange)
Propagate ymin, ymax back to IntensityDataItem.
void resetView()
reset all axes min,max to initial value
The UpdateTimer class accumulates update requests during certain period of time, and at the end of th...
Definition: UpdateTimer.h:27