BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
ScientificPlotEvent Class Reference

Description

Helps ScientificPlot to handle mouse events. Particularly, it constructs a valid status string. Can be extended to play a role of event filter.

Definition at line 29 of file ScientificPlotEvent.h.

Inheritance diagram for ScientificPlotEvent:
[legend]
Collaboration diagram for ScientificPlotEvent:
[legend]

Public Slots

void onCustomMouseMove (QMouseEvent *event)
 Constructs status string on mouse move event coming from QCustomPlot. String is emitted if mouse is in axes's viewport rectangle. Once mouse goes out of it, an empty string is emitted once again. More...
 

Signals

void enteringPlot ()
 
void leavingPlot ()
 
void positionChanged (double x, double y)
 

Public Member Functions

 ScientificPlotEvent (ScientificPlot *scientific_plot)
 
 ~ScientificPlotEvent () override
 
void setMouseTrackingEnabled (bool enable)
 Sets tracking of the mouse for parent DescriptedPlot. More...
 

Private Member Functions

PlotEventInfo currentPlotDescriptor (QMouseEvent *event) const
 Constructs current position of the data. More...
 
QCustomPlot * customPlot ()
 
ScientificPlotscientificPlot ()
 
const ScientificPlotscientificPlot () const
 

Private Attributes

ScientificPlotm_plot
 
PlotEventInfo m_prevPos
 

Constructor & Destructor Documentation

◆ ScientificPlotEvent()

ScientificPlotEvent::ScientificPlotEvent ( ScientificPlot scientific_plot)
explicit

Definition at line 19 of file ScientificPlotEvent.cpp.

20  : QObject(scientific_plot)
21  , m_plot(scientific_plot)
22  , m_prevPos(scientific_plot->plotType())
23 {
24 }
ScientificPlot * m_plot
PLOT_TYPE plotType() const
Returns the type of current plot.

◆ ~ScientificPlotEvent()

ScientificPlotEvent::~ScientificPlotEvent ( )
overridedefault

Member Function Documentation

◆ currentPlotDescriptor()

PlotEventInfo ScientificPlotEvent::currentPlotDescriptor ( QMouseEvent *  event) const
private

Constructs current position of the data.

Definition at line 83 of file ScientificPlotEvent.cpp.

84 {
85  double x = scientificPlot()->pixelToXaxisCoord(event->pos().x());
86  double y = scientificPlot()->pixelToYaxisCoord(event->pos().y());
87  return scientificPlot()->eventInfo(x, y);
88 }
ScientificPlot * scientificPlot()
virtual PlotEventInfo eventInfo(double xpos, double ypos) const =0
Returns plot descriptor corresponding to given axes coordinates.
double pixelToYaxisCoord(double pixel) const
double pixelToXaxisCoord(double pixel) const
transform widget coordinates to axes coordinates

References ScientificPlot::eventInfo(), ScientificPlot::pixelToXaxisCoord(), ScientificPlot::pixelToYaxisCoord(), and scientificPlot().

Referenced by onCustomMouseMove().

Here is the call graph for this function:

◆ customPlot()

QCustomPlot * ScientificPlotEvent::customPlot ( )
private

Definition at line 76 of file ScientificPlotEvent.cpp.

77 {
78  return m_plot->customPlot();
79 }
virtual QCustomPlot * customPlot()=0

References ScientificPlot::customPlot(), and m_plot.

Referenced by setMouseTrackingEnabled().

Here is the call graph for this function:

◆ enteringPlot

void ScientificPlotEvent::enteringPlot ( )
signal

◆ leavingPlot

void ScientificPlotEvent::leavingPlot ( )
signal

◆ onCustomMouseMove

void ScientificPlotEvent::onCustomMouseMove ( QMouseEvent *  event)
slot

Constructs status string on mouse move event coming from QCustomPlot. String is emitted if mouse is in axes's viewport rectangle. Once mouse goes out of it, an empty string is emitted once again.

Definition at line 47 of file ScientificPlotEvent.cpp.

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 }
bool inAxesRange() const
Definition: PlotEventInfo.h:36
void positionChanged(double x, double y)
PlotEventInfo currentPlotDescriptor(QMouseEvent *event) const
Constructs current position of the data.
void statusString(const QString &text)

References currentPlotDescriptor(), enteringPlot(), PlotEventInfo::inAxesRange(), leavingPlot(), m_prevPos, positionChanged(), scientificPlot(), and ScientificPlot::statusString().

Referenced by setMouseTrackingEnabled().

Here is the call graph for this function:

◆ positionChanged

void ScientificPlotEvent::positionChanged ( double  x,
double  y 
)
signal

◆ scientificPlot() [1/2]

ScientificPlot * ScientificPlotEvent::scientificPlot ( )
private

Definition at line 66 of file ScientificPlotEvent.cpp.

67 {
68  return m_plot;
69 }

References m_plot.

Referenced by currentPlotDescriptor(), and onCustomMouseMove().

◆ scientificPlot() [2/2]

const ScientificPlot * ScientificPlotEvent::scientificPlot ( ) const
private

Definition at line 71 of file ScientificPlotEvent.cpp.

72 {
73  return m_plot;
74 }

References m_plot.

◆ setMouseTrackingEnabled()

void ScientificPlotEvent::setMouseTrackingEnabled ( bool  enable)

Sets tracking of the mouse for parent DescriptedPlot.

Definition at line 30 of file ScientificPlotEvent.cpp.

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 }
void onCustomMouseMove(QMouseEvent *event)
Constructs status string on mouse move event coming from QCustomPlot. String is emitted if mouse is i...
QCustomPlot * customPlot()

References customPlot(), m_plot, and onCustomMouseMove().

Referenced by ScientificPlot::setMouseTrackingEnabled().

Here is the call graph for this function:

Member Data Documentation

◆ m_plot

ScientificPlot* ScientificPlotEvent::m_plot
private

Definition at line 52 of file ScientificPlotEvent.h.

Referenced by customPlot(), scientificPlot(), and setMouseTrackingEnabled().

◆ m_prevPos

PlotEventInfo ScientificPlotEvent::m_prevPos
private

Definition at line 53 of file ScientificPlotEvent.h.

Referenced by onCustomMouseMove().


The documentation for this class was generated from the following files: