BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
ScientificPlotEvent.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/PlotUtil/ScientificPlotEvent.cpp
6 //! @brief Implements class ScientificPlotEvent
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 
16 #include <QMouseEvent>
17 #include <qcustomplot.h>
18 
20  : QObject(scientific_plot)
21  , m_plot(scientific_plot)
22  , m_prevPos(scientific_plot->plotType())
23 {
24 }
25 
27 
28 //! Sets tracking of the mouse for parent DescriptedPlot
29 
31 {
32  m_plot->setMouseTracking(enable);
33  customPlot()->setMouseTracking(enable);
34 
35  if (enable)
36  connect(customPlot(), &QCustomPlot::mouseMove, this,
37  &ScientificPlotEvent::onCustomMouseMove, Qt::UniqueConnection);
38  else
39  disconnect(customPlot(), &QCustomPlot::mouseMove, this,
41 }
42 
43 //! Constructs status string on mouse move event coming from QCustomPlot. String is emitted
44 //! if mouse is in axes's viewport rectangle. Once mouse goes out of it, an
45 //! empty string is emitted once again.
46 
48 {
49  auto currentPos = currentPlotDescriptor(event);
50 
51  if (currentPos.inAxesRange()) {
52  scientificPlot()->statusString(currentPos.statusString());
53 
54  if (!m_prevPos.inAxesRange())
55  enteringPlot();
56 
57  positionChanged(currentPos.x(), currentPos.y());
58  } else if (m_prevPos.inAxesRange()) {
59  scientificPlot()->statusString(QString());
60  leavingPlot();
61  }
62 
63  m_prevPos = currentPos;
64 }
65 
67 {
68  return m_plot;
69 }
70 
72 {
73  return m_plot;
74 }
75 
77 {
78  return m_plot->customPlot();
79 }
80 
81 //! Constructs current position of the data.
82 
84 {
85  double x = scientificPlot()->pixelToXaxisCoord(event->pos().x());
86  double y = scientificPlot()->pixelToYaxisCoord(event->pos().y());
87  return scientificPlot()->eventInfo(x, y);
88 }
Defines class ScientificPlotEvent.
Contains parameters of mouse position in 1D or 2D plot.
Definition: PlotEventInfo.h:26
bool inAxesRange() const
Definition: PlotEventInfo.h:36
ScientificPlot * m_plot
~ScientificPlotEvent() override
ScientificPlot * scientificPlot()
void positionChanged(double x, double y)
PlotEventInfo currentPlotDescriptor(QMouseEvent *event) const
Constructs current position of the data.
void onCustomMouseMove(QMouseEvent *event)
Constructs status string on mouse move event coming from QCustomPlot. String is emitted if mouse is i...
ScientificPlotEvent(ScientificPlot *scientific_plot)
QCustomPlot * customPlot()
void setMouseTrackingEnabled(bool enable)
Sets tracking of the mouse for parent DescriptedPlot.
Common interface for plot-descriptor interaction.
virtual PlotEventInfo eventInfo(double xpos, double ypos) const =0
Returns plot descriptor corresponding to given axes coordinates.
void statusString(const QString &text)
virtual QCustomPlot * customPlot()=0
double pixelToYaxisCoord(double pixel) const
double pixelToXaxisCoord(double pixel) const
transform widget coordinates to axes coordinates