BornAgain  1.19.0
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/coregui/Views/IntensityDataWidgets/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), m_plot(scientific_plot), m_prevPos(scientific_plot->plotType())
21 {
22 }
23 
25 
26 //! Sets tracking of the mouse for parent DescriptedPlot
27 
29 {
30  m_plot->setMouseTracking(enable);
31  customPlot()->setMouseTracking(enable);
32 
33  if (enable)
34  connect(customPlot(), &QCustomPlot::mouseMove, this,
35  &ScientificPlotEvent::onCustomMouseMove, Qt::UniqueConnection);
36  else
37  disconnect(customPlot(), &QCustomPlot::mouseMove, this,
39 }
40 
41 //! Constructs status string on mouse move event coming from QCustomPlot. String is emitted
42 //! if mouse is in axes's viewport rectangle. Once mouse goes out of it, an
43 //! empty string is emitted once again.
44 
46 {
47  auto currentPos = currentPlotDescriptor(event);
48 
49  if (currentPos.inAxesRange()) {
50  scientificPlot()->statusString(currentPos.statusString());
51 
52  if (!m_prevPos.inAxesRange())
53  enteringPlot();
54 
55  positionChanged(currentPos.x(), currentPos.y());
56  } else if (m_prevPos.inAxesRange()) {
57  scientificPlot()->statusString(QString());
58  leavingPlot();
59  }
60 
61  m_prevPos = std::move(currentPos);
62 }
63 
65 {
66  return m_plot;
67 }
68 
70 {
71  return m_plot;
72 }
73 
75 {
76  return m_plot->customPlot();
77 }
78 
79 //! Constructs current position of the data.
80 
82 {
83  double x = scientificPlot()->pixelToXaxisCoord(event->pos().x());
84  double y = scientificPlot()->pixelToYaxisCoord(event->pos().y());
85  return scientificPlot()->eventInfo(x, y);
86 }
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.
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