Signals | Public Member Functions | Protected Member Functions

QwtPlotPicker Class Reference

QwtPlotPicker provides selections on a plot canvas. More...

#include <qwt_plot_picker.h>

Inheritance diagram for QwtPlotPicker:
Inheritance graph
[legend]
Collaboration diagram for QwtPlotPicker:
Collaboration graph
[legend]

List of all members.

Signals

void selected (const QwtDoublePoint &pos)
void selected (const QwtDoubleRect &rect)
void selected (const QMemArray< QwtDoublePoint > &pa)
void appended (const QwtDoublePoint &pos)
void moved (const QwtDoublePoint &pos)

Public Member Functions

 QwtPlotPicker (QwtPlotCanvas *)
 Create a plot picker.
virtual ~QwtPlotPicker ()
 Destructor.
 QwtPlotPicker (int xAxis, int yAxis, QwtPlotCanvas *)
 QwtPlotPicker (int xAxis, int yAxis, int selectionFlags, RubberBand rubberBand, DisplayMode trackerMode, QwtPlotCanvas *)
virtual void setAxis (int xAxis, int yAxis)
int xAxis () const
 Return x axis.
int yAxis () const
 Return y axis.
QwtPlotplot ()
 Return plot widget, containing the observed plot canvas.
const QwtPlotplot () const
 Return plot widget, containing the observed plot canvas.
QwtPlotCanvascanvas ()
 Return observed plot canvas.
const QwtPlotCanvascanvas () const
 Return Observed plot canvas.

Protected Member Functions

QwtDoubleRect scaleRect () const
QwtDoubleRect invTransform (const QRect &) const
QRect transform (const QwtDoubleRect &) const
QwtDoublePoint invTransform (const QPoint &) const
QPoint transform (const QwtDoublePoint &) const
virtual QwtText trackerText (const QPoint &) const
virtual QwtText trackerText (const QwtDoublePoint &) const
 Translate a position into a position string.
virtual void move (const QPoint &)
virtual void append (const QPoint &)
virtual bool end (bool ok=true)

Detailed Description

QwtPlotPicker provides selections on a plot canvas.

QwtPlotPicker is a QwtPicker tailored for selections on a plot canvas. It is set to a x-Axis and y-Axis and translates all pixel coordinates into this coodinate system.

Definition at line 29 of file qwt_plot_picker.h.


Constructor & Destructor Documentation

QwtPlotPicker::QwtPlotPicker ( QwtPlotCanvas canvas ) [explicit]

Create a plot picker.

The picker is set to those x- and y-axis of the plot that are enabled. If both or no x-axis are enabled, the picker is set to QwtPlot::xBottom. If both or no y-axis are enabled, it is set to QwtPlot::yLeft.

Parameters:
canvasPlot canvas to observe, also the parent object
See also:
QwtPlot::autoReplot(), QwtPlot::replot(), QwtPlotPicker::scaleRect()

Definition at line 32 of file qwt_plot_picker.cpp.

References QwtPlot::axisEnabled(), plot(), setAxis(), xAxis(), QwtPlot::xBottom, QwtPlot::xTop, yAxis(), QwtPlot::yLeft, and QwtPlot::yRight.

                                                 :
    QwtPicker(canvas),
    d_xAxis(-1),
    d_yAxis(-1)
{
    if ( !canvas )
        return;

    // attach axes

    int xAxis = QwtPlot::xBottom;

    const QwtPlot *plot = QwtPlotPicker::plot();
    if ( !plot->axisEnabled(QwtPlot::xBottom) &&
        plot->axisEnabled(QwtPlot::xTop) )
    {
        xAxis = QwtPlot::xTop;
    }

    int yAxis = QwtPlot::yLeft;
    if ( !plot->axisEnabled(QwtPlot::yLeft) &&
        plot->axisEnabled(QwtPlot::yRight) )
    {
        yAxis = QwtPlot::yRight;
    }

    setAxis(xAxis, yAxis);
}
QwtPlotPicker::~QwtPlotPicker (  ) [virtual]

Destructor.

Definition at line 103 of file qwt_plot_picker.cpp.

{
}
QwtPlotPicker::QwtPlotPicker ( int  xAxis,
int  yAxis,
QwtPlotCanvas canvas 
) [explicit]

Create a plot picker

Parameters:
xAxisSet the x axis of the picker
yAxisSet the y axis of the picker
canvasPlot canvas to observe, also the parent object
See also:
QwtPlot::autoReplot(), QwtPlot::replot(), QwtPlotPicker::scaleRect()

Definition at line 70 of file qwt_plot_picker.cpp.

                                                                       :
    QwtPicker(canvas),
    d_xAxis(xAxis),
    d_yAxis(yAxis)
{
}
QwtPlotPicker::QwtPlotPicker ( int  xAxis,
int  yAxis,
int  selectionFlags,
RubberBand  rubberBand,
DisplayMode  trackerMode,
QwtPlotCanvas canvas 
) [explicit]

Create a plot picker

Parameters:
xAxisX axis of the picker
yAxisY axis of the picker
selectionFlagsOr'd value of SelectionType, RectSelectionType and SelectionMode
rubberBandRubberband style
trackerModeTracker mode
canvasPlot canvas to observe, also the parent object
See also:
QwtPicker, QwtPicker::setSelectionFlags(), QwtPicker::setRubberBand(), QwtPicker::setTrackerMode
QwtPlot::autoReplot(), QwtPlot::replot(), QwtPlotPicker::scaleRect()

Definition at line 93 of file qwt_plot_picker.cpp.

                              :
    QwtPicker(selectionFlags, rubberBand, trackerMode, canvas),
    d_xAxis(xAxis),
    d_yAxis(yAxis)
{
}

Member Function Documentation

void QwtPlotPicker::append ( const QPoint &  pos ) [protected, virtual]

Append a point to the selection and update rubberband and tracker.

Parameters:
posAdditional point
See also:
isActive, begin(), end(), move(), appended()
Note:
The appended(const QPoint &), appended(const QDoublePoint &) signals are emitted.

Reimplemented from QwtPicker.

Definition at line 249 of file qwt_plot_picker.cpp.

References appended(), and invTransform().

{
    QwtPicker::append(pos);
    emit appended(invTransform(pos));
}
void QwtPlotPicker::appended ( const QwtDoublePoint pos ) [signal]

A signal emitted when a point has been appended to the selection

Parameters:
posPosition of the appended point.
See also:
append(). moved()

Referenced by append().

QwtPlotCanvas * QwtPlotPicker::canvas (  )

Return observed plot canvas.

Definition at line 108 of file qwt_plot_picker.cpp.

References QwtPicker::parentWidget().

Referenced by plot().

{
    QWidget *w = parentWidget();
    if ( w && w->inherits("QwtPlotCanvas") )
        return (QwtPlotCanvas *)w;

    return NULL;
}
const QwtPlotCanvas * QwtPlotPicker::canvas (  ) const

Return Observed plot canvas.

Definition at line 118 of file qwt_plot_picker.cpp.

{
    return ((QwtPlotPicker *)this)->canvas();
}
bool QwtPlotPicker::end ( bool  ok = true ) [protected, virtual]

Close a selection setting the state to inactive.

Parameters:
okIf true, complete the selection and emit selected signals otherwise discard the selection.
Returns:
true if the selection is accepted, false otherwise

Reimplemented from QwtPicker.

Reimplemented in QwtPlotZoomer.

Definition at line 278 of file qwt_plot_picker.cpp.

References QwtPicker::CenterToCorner, QwtPicker::CenterToRadius, int(), invTransform(), plot(), QwtPicker::PointSelection, qwtAbs, qwtMax, QwtPicker::RectSelection, selected(), QwtPicker::selection(), and QwtPicker::selectionFlags().

{
    ok = QwtPicker::end(ok);
    if ( !ok )
        return false;

    QwtPlot *plot = QwtPlotPicker::plot();
    if ( !plot )
        return false;

    const QwtPolygon &pa = selection();
    if ( pa.count() == 0 )
        return false;

    if ( selectionFlags() & PointSelection )
    {
        const QwtDoublePoint pos = invTransform(pa[0]);
        emit selected(pos);
    }
    else if ( (selectionFlags() & RectSelection) && pa.count() >= 2 )
    {
        QPoint p1 = pa[0];
        QPoint p2 = pa[int(pa.count() - 1)];

        if ( selectionFlags() & CenterToCorner )
        {
            p1.setX(p1.x() - (p2.x() - p1.x()));
            p1.setY(p1.y() - (p2.y() - p1.y()));
        }
        else if ( selectionFlags() & CenterToRadius )
        {
            const int radius = qwtMax(qwtAbs(p2.x() - p1.x()),
                qwtAbs(p2.y() - p1.y()));
            p2.setX(p1.x() + radius);
            p2.setY(p1.y() + radius);
            p1.setX(p1.x() - radius);
            p1.setY(p1.y() - radius);
        }

        emit selected(invTransform(QRect(p1, p2)).normalized());
    }
    else 
    {
        QwtArray<QwtDoublePoint> dpa(pa.count());
        for ( int i = 0; i < int(pa.count()); i++ )
            dpa[i] = invTransform(pa[i]);

        emit selected(dpa);
    }

    return true;
}
QwtDoublePoint QwtPlotPicker::invTransform ( const QPoint &  pos ) const [protected]

Translate a point from pixel into plot coordinates

Returns:
Point in plot coordinates
See also:
QwtPlotPicker::transform()

Definition at line 374 of file qwt_plot_picker.cpp.

References QwtPlot::canvasMap(), QwtScaleMap::invTransform(), and plot().

{
    QwtScaleMap xMap = plot()->canvasMap(d_xAxis);
    QwtScaleMap yMap = plot()->canvasMap(d_yAxis);

    return QwtDoublePoint(
        xMap.invTransform(pos.x()),
        yMap.invTransform(pos.y())
    );
}
QwtDoubleRect QwtPlotPicker::invTransform ( const QRect &  rect ) const [protected]

Translate a rectangle from pixel into plot coordinates

Returns:
Rectangle in plot coordinates
See also:
QwtPlotPicker::transform()

Definition at line 337 of file qwt_plot_picker.cpp.

References QwtPlot::canvasMap(), QwtScaleMap::invTransform(), and plot().

Referenced by append(), QwtPlotZoomer::end(), end(), move(), and trackerText().

{
    QwtScaleMap xMap = plot()->canvasMap(d_xAxis);
    QwtScaleMap yMap = plot()->canvasMap(d_yAxis);

    const double left = xMap.invTransform(rect.left());
    const double right = xMap.invTransform(rect.right());
    const double top = yMap.invTransform(rect.top());
    const double bottom = yMap.invTransform(rect.bottom());

    return QwtDoubleRect(left, top,
        right - left, bottom - top);
}
void QwtPlotPicker::move ( const QPoint &  pos ) [protected, virtual]

Move the last point of the selection

Parameters:
posNew position
See also:
isActive, begin(), end(), append()
Note:
The moved(const QPoint &), moved(const QDoublePoint &) signals are emitted.

Reimplemented from QwtPicker.

Definition at line 264 of file qwt_plot_picker.cpp.

References invTransform(), and moved().

{
    QwtPicker::move(pos);
    emit moved(invTransform(pos));
}
void QwtPlotPicker::moved ( const QwtDoublePoint pos ) [signal]

A signal emitted whenever the last appended point of the selection has been moved.

Parameters:
posPosition of the moved last point of the selection.
See also:
move(), appended()

Referenced by move().

const QwtPlot * QwtPlotPicker::plot (  ) const

Return plot widget, containing the observed plot canvas.

Definition at line 138 of file qwt_plot_picker.cpp.

{
    return ((QwtPlotPicker *)this)->plot();
}
QwtPlot * QwtPlotPicker::plot (  )

Return plot widget, containing the observed plot canvas.

Definition at line 124 of file qwt_plot_picker.cpp.

References canvas().

Referenced by QwtPlotZoomer::end(), end(), invTransform(), QwtPlotPicker(), QwtPlotZoomer::rescale(), scaleRect(), setAxis(), QwtPlotZoomer::setZoomBase(), and transform().

{
    QObject *w = canvas();
    if ( w )
    {
        w = w->parent();
        if ( w && w->inherits("QwtPlot") )
            return (QwtPlot *)w;
    }

    return NULL;
}
QwtDoubleRect QwtPlotPicker::scaleRect (  ) const [protected]

Return normalized bounding rect of the axes

See also:
QwtPlot::autoReplot(), QwtPlot::replot().

Definition at line 148 of file qwt_plot_picker.cpp.

References QwtPlot::axisScaleDiv(), QwtScaleDiv::lowerBound(), QwtDoubleRect::normalized(), plot(), QwtScaleDiv::range(), xAxis(), and yAxis().

Referenced by QwtPlotZoomer::rescale(), QwtPlotZoomer::setAxis(), and QwtPlotZoomer::setZoomBase().

{
    QwtDoubleRect rect;

    if ( plot() )
    {
        const QwtScaleDiv *xs = plot()->axisScaleDiv(xAxis());
        const QwtScaleDiv *ys = plot()->axisScaleDiv(yAxis());

        if ( xs && ys )
        {
            rect = QwtDoubleRect( xs->lowerBound(), ys->lowerBound(), 
                xs->range(), ys->range() );
            rect = rect.normalized();
        }
    }

    return rect;
}
void QwtPlotPicker::selected ( const QwtDoublePoint pos ) [signal]

A signal emitted in case of selectionFlags() & PointSelection.

Parameters:
posSelected point

Referenced by end().

void QwtPlotPicker::selected ( const QwtDoubleRect rect ) [signal]

A signal emitted in case of selectionFlags() & RectSelection.

Parameters:
rectSelected rectangle
void QwtPlotPicker::selected ( const QMemArray< QwtDoublePoint > &  pa ) [signal]

A signal emitting the selected points, at the end of a selection.

Parameters:
paSelected points
void QwtPlotPicker::setAxis ( int  xAxis,
int  yAxis 
) [virtual]

Set the x and y axes of the picker

Parameters:
xAxisX axis
yAxisY axis

Reimplemented in QwtPlotZoomer.

Definition at line 174 of file qwt_plot_picker.cpp.

References plot(), xAxis(), and yAxis().

Referenced by QwtPlotPicker().

{
    const QwtPlot *plt = plot();
    if ( !plt )
        return;

    if ( xAxis != d_xAxis || yAxis != d_yAxis )
    {
        d_xAxis = xAxis;
        d_yAxis = yAxis;
    }
}
QwtText QwtPlotPicker::trackerText ( const QwtDoublePoint pos ) const [protected, virtual]

Translate a position into a position string.

In case of HLineRubberBand the label is the value of the y position, in case of VLineRubberBand the value of the x position. Otherwise the label contains x and y position separated by a ',' .

The format for the double to string conversion is "%.4f".

Parameters:
posPosition
Returns:
Position string

Definition at line 222 of file qwt_plot_picker.cpp.

References QwtPicker::HLineRubberBand, QwtPicker::rubberBand(), QwtPicker::VLineRubberBand, QwtDoublePoint::x(), and QwtDoublePoint::y().

{
    QString text;

    switch(rubberBand())
    {
        case HLineRubberBand:
            text.sprintf("%.4f", pos.y());
            break;
        case VLineRubberBand:
            text.sprintf("%.4f", pos.x());
            break;
        default:
            text.sprintf("%.4f, %.4f", pos.x(), pos.y());
    }
    return QwtText(text);
}
QwtText QwtPlotPicker::trackerText ( const QPoint &  pos ) const [protected, virtual]

Translate a pixel position into a position string

Parameters:
posPosition in pixel coordinates
Returns:
Position string

Reimplemented from QwtPicker.

Definition at line 205 of file qwt_plot_picker.cpp.

References invTransform().

{
    return trackerText(invTransform(pos));
}
QRect QwtPlotPicker::transform ( const QwtDoubleRect rect ) const [protected]

Translate a rectangle from plot into pixel coordinates

Returns:
Rectangle in pixel coordinates
See also:
QwtPlotPicker::invTransform()

Definition at line 356 of file qwt_plot_picker.cpp.

References QwtDoubleRect::bottom(), QwtPlot::canvasMap(), QwtDoubleRect::left(), plot(), QwtDoubleRect::right(), QwtDoubleRect::top(), and QwtScaleMap::transform().

{
    QwtScaleMap xMap = plot()->canvasMap(d_xAxis);
    QwtScaleMap yMap = plot()->canvasMap(d_yAxis);

    const int left = xMap.transform(rect.left());
    const int right = xMap.transform(rect.right());
    const int top = yMap.transform(rect.top());
    const int bottom = yMap.transform(rect.bottom());

    return QRect(left, top, right - left, bottom - top);
}
QPoint QwtPlotPicker::transform ( const QwtDoublePoint pos ) const [protected]

Translate a point from plot into pixel coordinates

Returns:
Point in pixel coordinates
See also:
QwtPlotPicker::invTransform()

Definition at line 390 of file qwt_plot_picker.cpp.

References QwtPlot::canvasMap(), plot(), QwtScaleMap::transform(), QwtDoublePoint::x(), and QwtDoublePoint::y().

{
    QwtScaleMap xMap = plot()->canvasMap(d_xAxis);
    QwtScaleMap yMap = plot()->canvasMap(d_yAxis);

    return QPoint(
        xMap.transform(pos.x()),
        yMap.transform(pos.y())
    );
}
int QwtPlotPicker::xAxis (  ) const

Return x axis.

Definition at line 188 of file qwt_plot_picker.cpp.

Referenced by QwtPlotPicker(), QwtPlotZoomer::rescale(), scaleRect(), QwtPlotZoomer::setAxis(), and setAxis().

{
    return d_xAxis;
}
int QwtPlotPicker::yAxis (  ) const

Return y axis.

Definition at line 194 of file qwt_plot_picker.cpp.

Referenced by QwtPlotPicker(), QwtPlotZoomer::rescale(), scaleRect(), QwtPlotZoomer::setAxis(), and setAxis().

{
    return d_yAxis;
}

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines