BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
ColorMap.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/PlotUtil/ColorMap.h
6 //! @brief Defines class ColorMap
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_PLOTUTIL_COLORMAP_H
16 #define BORNAGAIN_GUI_VIEW_PLOTUTIL_COLORMAP_H
17 
19 #include <QMap>
20 #include <QPoint>
21 #include <memory>
22 #include <qcustomplot.h>
23 
24 class IntensityDataItem;
25 class QCustomPlot;
26 class QCPColorMap;
27 class QCPColorScale;
28 class UpdateTimer;
30 
31 //! The ColorMap class presents 2D intensity data from IntensityDataItem as color map.
32 
33 //! Provides a minimal functionality for data plotting and axes interaction. Should be a component
34 //! for more complicated plotting widgets. This is a replacement for ColorMapPlot.
35 
36 class ColorMap : public ScientificPlot {
37  Q_OBJECT
38 
39 public:
40  explicit ColorMap(QWidget* parent = nullptr);
41 
42  QSize sizeHint() const override { return QSize(500, 400); }
43  QSize minimumSizeHint() const override { return QSize(128, 128); }
44 
45  QCustomPlot* customPlot() override { return m_customPlot; }
46  const QCustomPlot* customPlot() const override { return m_customPlot; }
47  QCPColorScale* colorScale() { return m_colorScale; }
48 
49  //! Returns rectangle representing current axes zoom state in widget coordinates
51 
52  //! Returns PlotEventInfo corresponding to given axes coordinates.
53  PlotEventInfo eventInfo(double xpos, double ypos) const override;
54 
55 signals:
56  void marginsChanged(double left, double right);
57 
58 public slots:
59  void setLogz(bool logz);
60  void resetView();
61 
62 private slots:
63  void onIntensityModified();
64  void onPropertyChanged(const QString& property_name);
65  void onAxisPropertyChanged(const QString& axisName, const QString& propertyName);
66  void onDataRangeChanged(QCPRange newRange);
67  void onXaxisRangeChanged(QCPRange newRange);
68  void onYaxisRangeChanged(QCPRange newRange);
69  void replot();
70  void onTimeToReplot();
71  void marginsChangedNotify();
72 
73 protected:
74  void subscribeToItem() override;
75  void unsubscribeFromItem() override;
76 
77 private:
78  void initColorMap();
79 
80  void setConnected(bool isConnected);
81  void setAxesRangeConnected(bool isConnected);
82  void setDataRangeConnected(bool isConnected);
83  void setUpdateTimerConnected(bool isConnected);
84 
86 
94 
95  void setColorScaleVisible(bool visibility_flag);
96 
98  const IntensityDataItem* intensityItem() const;
99 
100  QCustomPlot* m_customPlot;
101  QCPColorMap* m_colorMap;
102  QCPColorScale* m_colorScale;
104  QCPLayoutGrid* m_colorBarLayout;
105 
107 };
108 
109 #endif // BORNAGAIN_GUI_VIEW_PLOTUTIL_COLORMAP_H
Declares class ScientificPlot.
The ColorMap class presents 2D intensity data from IntensityDataItem as color map.
Definition: ColorMap.h:36
QCPColorMap * m_colorMap
Definition: ColorMap.h:101
UpdateTimer * m_updateTimer
Definition: ColorMap.h:103
QRectF viewportRectangleInWidgetCoordinates()
Returns rectangle representing current axes zoom state in widget coordinates.
Definition: ColorMap.cpp:53
void setAxesRangeFromItem(IntensityDataItem *item)
Sets (xmin,xmax,nbins) and (ymin,ymax,nbins) of ColorMap from intensity item.
Definition: ColorMap.cpp:336
const QCustomPlot * customPlot() const override
Definition: ColorMap.h:46
QCPLayoutGrid * m_colorBarLayout
Definition: ColorMap.h:104
bool m_block_update
Definition: ColorMap.h:106
ColorMap(QWidget *parent=nullptr)
Definition: ColorMap.cpp:31
void setUpdateTimerConnected(bool isConnected)
Definition: ColorMap.cpp:299
PlotEventInfo eventInfo(double xpos, double ypos) const override
Returns PlotEventInfo corresponding to given axes coordinates.
Definition: ColorMap.cpp:67
void setConnected(bool isConnected)
Definition: ColorMap.cpp:258
void setFixedColorMapMargins()
to make fixed margins for whole colormap (change in axes labels wont affect axes rectangle)
Definition: ColorMap.cpp:309
void replot()
Schedule replot for later execution by onTimeReplot() slot.
Definition: ColorMap.cpp:195
void unsubscribeFromItem() override
Definition: ColorMap.cpp:227
QCPColorScale * colorScale()
Definition: ColorMap.h:47
void onYaxisRangeChanged(QCPRange newRange)
Propagate ymin, ymax back to IntensityDataItem.
Definition: ColorMap.cpp:185
void initColorMap()
creates and initializes the color map
Definition: ColorMap.cpp:233
QSize minimumSizeHint() const override
Definition: ColorMap.h:43
void marginsChanged(double left, double right)
void setAxesRangeConnected(bool isConnected)
Connects/disconnects signals related to ColorMap's X,Y axes rectangle change.
Definition: ColorMap.cpp:267
QCustomPlot * customPlot() override
Definition: ColorMap.h:45
void setAxesLabelsFromItem(IntensityDataItem *item)
Sets X,Y axes labels from item.
Definition: ColorMap.cpp:357
void setDataRangeFromItem(IntensityDataItem *item)
Definition: ColorMap.cpp:405
void setColorMapFromItem(IntensityDataItem *intensityItem)
Sets initial state of ColorMap to match given intensity item.
Definition: ColorMap.cpp:316
void setDataRangeConnected(bool isConnected)
Connects/disconnects signals related to ColorMap's Z-axis (min,max) change.
Definition: ColorMap.cpp:290
void onPropertyChanged(const QString &property_name)
updates color map depending on IntensityDataItem properties
Definition: ColorMap.cpp:109
void onAxisPropertyChanged(const QString &axisName, const QString &propertyName)
Definition: ColorMap.cpp:126
void onTimeToReplot()
Replots ColorMap.
Definition: ColorMap.cpp:202
void subscribeToItem() override
Definition: ColorMap.cpp:207
QCPColorScale * m_colorScale
Definition: ColorMap.h:102
void onDataRangeChanged(QCPRange newRange)
Propagate zmin, zmax back to IntensityDataItem.
Definition: ColorMap.cpp:168
void setColorScaleAppearanceFromItem(IntensityDataItem *item)
Sets the appearance of color scale (visibility, gradient type) from intensity item.
Definition: ColorMap.cpp:393
IntensityDataItem * intensityItem()
Definition: ColorMap.cpp:443
void setDataFromItem(IntensityDataItem *item)
Sets the intensity values to ColorMap.
Definition: ColorMap.cpp:376
void resetView()
reset all axes min,max to initial value
Definition: ColorMap.cpp:96
void setLogz(bool logz)
sets logarithmic scale
Definition: ColorMap.cpp:89
void onIntensityModified()
Definition: ColorMap.cpp:101
void onXaxisRangeChanged(QCPRange newRange)
Propagate xmin, xmax back to IntensityDataItem.
Definition: ColorMap.cpp:176
QCustomPlot * m_customPlot
Definition: ColorMap.h:100
void setColorScaleVisible(bool visibility_flag)
Definition: ColorMap.cpp:413
QSize sizeHint() const override
Definition: ColorMap.h:42
void marginsChangedNotify()
Calculates left, right margins around color map to report to projection plot.
Definition: ColorMap.cpp:428
void setAxesZoomFromItem(IntensityDataItem *item)
Sets zoom range of X,Y axes as in intensity item.
Definition: ColorMap.cpp:347
Contains parameters of mouse position in 1D or 2D plot.
Definition: PlotEventInfo.h:26
Helps ScientificPlot to handle mouse events. Particularly, it constructs a valid status string....
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