BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
Plot1D.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Views/IntensityDataWidgets/Plot1D.h
6 //! @brief Defines class Plot1D
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_COREGUI_VIEWS_INTENSITYDATAWIDGETS_PLOT1D_H
16 #define BORNAGAIN_GUI_COREGUI_VIEWS_INTENSITYDATAWIDGETS_PLOT1D_H
17 
19 #include <qcustomplot.h>
20 
21 class BasicAxisItem;
22 class DataItem;
23 class Data1DViewItem;
24 class Data1DProperties;
25 class SpecularPlotEvent;
26 class UpdateTimer;
27 
28 //! The Plot1D class presents data of several 1D DataItems contained in a
29 //! Data1DViewItem. Provides minimal functionality for data plotting and axes interaction. Should be
30 //! a component for more complicated plotting widgets.
31 
32 class Plot1D : public ScientificPlot {
33  Q_OBJECT
34 
35 public:
36  explicit Plot1D(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 private slots:
54  //! updates plot depending on IntensityDataItem properties
55  void onPropertyChanged(const QString& property_name);
56 
57  //! Propagate xmin, xmax back to IntensityDataItem
58  void onXaxisRangeChanged(QCPRange newRange);
59 
60  //! Propagate ymin, ymax back to IntensityDataItem
61  void onYaxisRangeChanged(QCPRange newRange);
62 
63  //! Replots SpecularPlot.
64  void onTimeToReplot();
65 
66 protected:
67  void subscribeToItem() override;
68  void unsubscribeFromItem() override;
69 
70 private:
71  //! creates and initializes the color map
72  void initPlots();
73 
74  void setConnected(bool isConnected);
75 
76  //! Connects/disconnects signals related to SpecularPlot's X,Y axes rectangle change.
77  void setAxesRangeConnected(bool isConnected);
78 
79  void setUpdateTimerConnected(bool isConnected);
80 
81  //! Refresh axes' labels, range and graph data.
82  void refreshPlotData();
83 
84  //! Sets (xmin,xmax) and (ymin,ymax) of SpecularPlot from specular item.
85  //! Also sets logarithmic scale on y-axis if necessary.
87 
88  //! Sets X,Y axes labels from item
90 
91  //! Sets label to axis
92  void setLabel(const BasicAxisItem* item, QCPAxis* axis, QString label);
93 
94  //! Sets data to graphs.
95  void updateAllGraphs();
96 
97  //! Sets data to the graph corresponding to the passed Data1DProperties.
98  void updateGraph(Data1DProperties* item);
99 
101  const Data1DViewItem* viewItem() 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  std::map<Data1DProperties*, QCPGraph*> m_graph_map;
111 
113 };
114 
115 #endif // BORNAGAIN_GUI_COREGUI_VIEWS_INTENSITYDATAWIDGETS_PLOT1D_H
Declares class ScientificPlot.
Holds data required for 1D DataItem representation.
View model for 1D DataItem.
Provides common functionality for IntensityDataItem and SpecularDataItem.
Definition: DataItem.h:29
The Plot1D class presents data of several 1D DataItems contained in a Data1DViewItem.
Definition: Plot1D.h:32
void onTimeToReplot()
Replots SpecularPlot.
Definition: Plot1D.cpp:107
QCustomPlot * customPlot() override
Definition: Plot1D.h:44
void updateAllGraphs()
Sets data to graphs.
Definition: Plot1D.cpp:240
void initPlots()
creates and initializes the color map
Definition: Plot1D.cpp:146
void setAxesRangeConnected(bool isConnected)
Connects/disconnects signals related to SpecularPlot's X,Y axes rectangle change.
Definition: Plot1D.cpp:163
void resetView()
reset all axes min,max to initial value
Definition: Plot1D.cpp:74
QSize minimumSizeHint() const override
Definition: Plot1D.h:39
Plot1D(QWidget *parent=nullptr)
Definition: Plot1D.cpp:33
void setAxesLabelsFromItem(Data1DViewItem *item)
Sets X,Y axes labels from item.
Definition: Plot1D.cpp:225
void setAxesRangeFromItem(Data1DViewItem *item)
Sets (xmin,xmax) and (ymin,ymax) of SpecularPlot from specular item.
Definition: Plot1D.cpp:213
void setConnected(bool isConnected)
Definition: Plot1D.cpp:157
void refreshPlotData()
Refresh axes' labels, range and graph data.
Definition: Plot1D.cpp:194
const QCustomPlot * customPlot() const override
Definition: Plot1D.h:45
void setUpdateTimerConnected(bool isConnected)
Definition: Plot1D.cpp:185
QSize sizeHint() const override
Definition: Plot1D.h:38
void replot()
Schedule replot for later execution by onTimeReplot() slot.
Definition: Plot1D.cpp:298
QCustomPlot * m_custom_plot
Definition: Plot1D.h:108
UpdateTimer * m_update_timer
Definition: Plot1D.h:109
PlotEventInfo eventInfo(double xpos, double ypos) const override
Returns PlotEventInfo corresponding to given axes coordinates.
Definition: Plot1D.cpp:53
void updateGraph(Data1DProperties *item)
Sets data to the graph corresponding to the passed Data1DProperties.
Definition: Plot1D.cpp:247
void onPropertyChanged(const QString &property_name)
updates plot depending on IntensityDataItem properties
Definition: Plot1D.cpp:79
void onYaxisRangeChanged(QCPRange newRange)
Propagate ymin, ymax back to IntensityDataItem.
Definition: Plot1D.cpp:99
void setLog(bool log)
sets logarithmic scale
Definition: Plot1D.cpp:68
Data1DViewItem * viewItem()
Definition: Plot1D.cpp:255
bool m_block_update
Definition: Plot1D.h:112
void unsubscribeFromItem() override
Definition: Plot1D.cpp:136
std::map< Data1DProperties *, QCPGraph * > m_graph_map
Definition: Plot1D.h:110
void setLabel(const BasicAxisItem *item, QCPAxis *axis, QString label)
Sets label to axis.
Definition: Plot1D.cpp:231
void onXaxisRangeChanged(QCPRange newRange)
Propagate xmin, xmax back to IntensityDataItem.
Definition: Plot1D.cpp:91
void modifyAxesProperties(const QString &axisName, const QString &propertyName)
Definition: Plot1D.cpp:267
void subscribeToItem() override
Definition: Plot1D.cpp:112
Contains parameters of mouse position in 1D or 2D plot.
Definition: PlotEventInfo.h:26
Common interface for plot-descriptor interaction.
The UpdateTimer class accumulates update requests during certain period of time, and at the end of th...
Definition: UpdateTimer.h:27