Classes | Public Member Functions | Protected Slots

QwtPlotPanner Class Reference

QwtPlotPanner provides panning of a plot canvas. More...

#include <qwt_plot_panner.h>

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

List of all members.

Classes

class  PrivateData

Public Member Functions

 QwtPlotPanner (QwtPlotCanvas *)
 Create a plot panner.
virtual ~QwtPlotPanner ()
 Destructor.
QwtPlotCanvascanvas ()
 Return observed plot canvas.
const QwtPlotCanvascanvas () const
 Return Observed plot canvas.
QwtPlotplot ()
 Return plot widget, containing the observed plot canvas.
const QwtPlotplot () const
 Return plot widget, containing the observed plot canvas.
void setAxisEnabled (int axis, bool on)
 En/Disable an axis.
bool isAxisEnabled (int axis) const

Protected Slots

virtual void moveCanvas (int dx, int dy)

Detailed Description

QwtPlotPanner provides panning of a plot canvas.

QwtPlotPanner is a panner for a QwtPlotCanvas, that adjusts the scales of the axes after dropping the canvas on its new position.

Together with QwtPlotZoomer and QwtPlotMagnifier powerful ways of navigating on a QwtPlot widget can be implemented easily.

Note:
The axes are not updated, while dragging the canvas
See also:
QwtPlotZoomer, QwtPlotMagnifier

Definition at line 32 of file qwt_plot_panner.h.


Constructor & Destructor Documentation

QwtPlotPanner::QwtPlotPanner ( QwtPlotCanvas canvas ) [explicit]

Create a plot panner.

The panner is enabled for all axes

Parameters:
canvasPlot canvas to pan, also the parent object
See also:
setAxisEnabled()

Definition at line 38 of file qwt_plot_panner.cpp.

References moveCanvas(), and QwtPanner::panned().

                                                 :
    QwtPanner(canvas)
{
    d_data = new PrivateData();

    connect(this, SIGNAL(panned(int, int)),
        SLOT(moveCanvas(int, int)));
}
QwtPlotPanner::~QwtPlotPanner (  ) [virtual]

Destructor.

Definition at line 48 of file qwt_plot_panner.cpp.

{
    delete d_data;
}

Member Function Documentation

QwtPlotCanvas * QwtPlotPanner::canvas (  )

Return observed plot canvas.

Definition at line 87 of file qwt_plot_panner.cpp.

Referenced by plot().

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

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

Return Observed plot canvas.

Definition at line 97 of file qwt_plot_panner.cpp.

{
    return ((QwtPlotPanner *)this)->canvas();
}
bool QwtPlotPanner::isAxisEnabled ( int  axis ) const

Test if an axis is enabled

Parameters:
axisAxis, see QwtPlot::Axis
Returns:
True, if the axis is enabled
See also:
setAxisEnabled(), moveCanvas()

Definition at line 78 of file qwt_plot_panner.cpp.

References QwtPlot::axisCnt, and QwtPlotPanner::PrivateData::isAxisEnabled.

{
    if ( axis >= 0 && axis < QwtPlot::axisCnt )
        return d_data->isAxisEnabled[axis];

    return true;
}
void QwtPlotPanner::moveCanvas ( int  dx,
int  dy 
) [protected, virtual, slot]

Adjust the enabled axes according to dx/dy

Parameters:
dxPixel offset in x direction
dyPixel offset in y direction
See also:
QwtPanner::panned()

Definition at line 130 of file qwt_plot_panner.cpp.

References QwtPlot::autoReplot(), QwtPlot::axisCnt, QwtPlot::axisScaleDiv(), QwtPlot::canvasMap(), QwtScaleMap::invTransform(), QwtPlotPanner::PrivateData::isAxisEnabled, QwtScaleDiv::lowerBound(), plot(), QwtPlot::replot(), QwtPlot::setAutoReplot(), QwtPlot::setAxisScale(), QwtScaleMap::transform(), QwtScaleDiv::upperBound(), QwtPlot::xBottom, and QwtPlot::xTop.

Referenced by QwtPlotPanner().

{
    if ( dx == 0 && dy == 0 )
        return;

    QwtPlot *plot = QwtPlotPanner::plot();
    if ( plot == NULL )
        return;
    
    const bool doAutoReplot = plot->autoReplot();
    plot->setAutoReplot(false);

    for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
    {
        if ( !d_data->isAxisEnabled[axis] )
            continue;

        const QwtScaleMap map = plot->canvasMap(axis);

        const int i1 = map.transform(plot->axisScaleDiv(axis)->lowerBound());
        const int i2 = map.transform(plot->axisScaleDiv(axis)->upperBound());

        double d1, d2;
        if ( axis == QwtPlot::xBottom || axis == QwtPlot::xTop )
        {
            d1 = map.invTransform(i1 - dx);
            d2 = map.invTransform(i2 - dx);
        }
        else
        {
            d1 = map.invTransform(i1 - dy);
            d2 = map.invTransform(i2 - dy);
        }

        plot->setAxisScale(axis, d1, d2);
    }

    plot->setAutoReplot(doAutoReplot);
    plot->replot();
}
const QwtPlot * QwtPlotPanner::plot (  ) const

Return plot widget, containing the observed plot canvas.

Definition at line 117 of file qwt_plot_panner.cpp.

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

Return plot widget, containing the observed plot canvas.

Definition at line 103 of file qwt_plot_panner.cpp.

References canvas().

Referenced by moveCanvas().

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

    return NULL;
}
void QwtPlotPanner::setAxisEnabled ( int  axis,
bool  on 
)

En/Disable an axis.

Axes that are enabled will be synchronized to the result of panning. All other axes will remain unchanged.

Parameters:
axisAxis, see QwtPlot::Axis
onOn/Off
See also:
isAxisEnabled(), moveCanvas()

Definition at line 64 of file qwt_plot_panner.cpp.

References QwtPlot::axisCnt, and QwtPlotPanner::PrivateData::isAxisEnabled.

{
    if ( axis >= 0 && axis < QwtPlot::axisCnt )
        d_data->isAxisEnabled[axis] = on;
}

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