// definition
#ifndef LINEMARKER_H
#define LINEMARKER_H
#include <QWidget>
/*! \brief Widget representing current cursor position on the curve.
\note
Marker <b>is not</b> and independent object.\n
It requires QwtPlotCurve and data vector to work efficiently.\n
When enabled it indicates current mouse position on the curve. It follows curve's Y values for mouse X position.\n
\note
Life span of the marker is controlled by client code but it is parented to the canvas so it will get deleted if canvas is destroyed.\n
Exapmle use:
\code
QVector< double > x_values;
QVector< double > y_values;
QwtPlotCurve* curve = new QwtPlotCurve();
curve->setSamples( x_values, y_values, qMin( x_values.size(), y_values.size() ) );
Marker* m = new Marker( *curve, x_values );
m->attach( plot->canvas() );
m->setEnabled( true );
\endcode
*/
{
Q_OBJECT
public:
/*! \brief Constructor.
*/
explicit LineMarker( const QwtPlotCurve& curve, const QVector< double >& v );
/*! \brief Overloaded Qt function.
It calls move( const QPoint& );
*/
void move( int x, int y );
/*! \brief Overloaded Qt function.
This version centres the widget horizontally.
*/
void move( const QPoint& );
public slots:
/*! \brief Snaps marker to point on the curve lying along current cursor X axis.
*/
void snapToCursor( void );
/*! \brief Reimplemented Qt function.
In this implementation whenever Marker is enabled it is also shown.\n
If it is disabled it gets hidden.\n
\param enabled Flag indicating if Marker should be enabled or disabled.
*/
void setEnabled( bool enabled );
protected:
/*! \brief Overloaded Qt function.
Draws marker's shape.
\param e Event.
*/
/*! \brief Overloaded Qt function.
Handles events incoming from QwtPlotCanvas:\n
- QEvent::MouseMove: marker is moved along curve according to current mouse x coordinate,\n
- QEvent::Resize: Changes fixed height of the marker to match height of the canvas,\n
\param o Object triggering the event.
\param e Event.
\return true if event is to be filtered out (i.e. stop it being handled further), false otherwise.
*/
public:
/*! \brief Property indicating if Marker is attached to a Canvas or not.
\return True if it's currently attached to a Canvas, false otherwise.
*/
bool isAttached( void );
/*! \brief Attaches Marker to a Canvas.
When Marker is attached to a Canvas it installs an EventFilter on in
to intercept mouse and key events.\n
\n
If Marker is already attached it will be detached from current canvas
and attached to a new one.\n
\n
If new cavans is the same as currently attached one this function does nothing.\n
\param canvas Canvas for Marker to attach to.
*/
/*! \brief Detaches Marker from current canvas.
By detaching Marker removes EventFilter from the Canvas and will no longer
receive any mouse or keyboard events.\n
\n
If tracker is not attached this function does nothing.\n
*/
void detach( void );
private:
/*! \brief Given X in canvas coordinates it snaps to curve Y at that X.
Finds curve X and Y value for canvas X value and moves tracker there.
\param canvasX X in canvas coordinates.
*/
void snapToCurveAt( int canvasX );
/*! \brief Returns current position of the cursor in canvas coordinates.
\return Cursor position translated to canvas coodrinates.
*/
QPoint cursorPos
( void ) const;
/*! \brief Finds closest point in curve data to the passed world coordinate.
World coordinate value has to be for the X axis as only that axis is searched.
\return Index of the point in the dataset.
*/
int findIndex( double worldX ) const;
const QwtPlotCurve& curve; //!< convenience cache
int elipsePosY; //!< position where small ellipse will be drawn on the line (Y only).
};
#endif // LINEMARKER_H
Bookmarks