1
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
3
* Copyright (C) 1997 Josef Wilgen
4
* Copyright (C) 2002 Uwe Rathmann
6
* This library is free software; you can redistribute it and/or
7
* modify it under the terms of the Qwt License, Version 1.0
8
*****************************************************************************/
12
#include "qwt_scale_div.h"
14
#include "qwt_plot_canvas.h"
15
#include "qwt_plot_panner.h"
17
class QwtPlotPanner::PrivateData
22
for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
23
isAxisEnabled[axis] = true;
26
bool isAxisEnabled[QwtPlot::axisCnt];
30
\brief Create a plot panner
32
The panner is enabled for all axes
34
\param canvas Plot canvas to pan, also the parent object
38
QwtPlotPanner::QwtPlotPanner(QwtPlotCanvas *canvas):
41
d_data = new PrivateData();
43
connect(this, SIGNAL(panned(int, int)),
44
SLOT(moveCanvas(int, int)));
48
QwtPlotPanner::~QwtPlotPanner()
54
\brief En/Disable an axis
56
Axes that are enabled will be synchronized to the
57
result of panning. All other axes will remain unchanged.
59
\param axis Axis, see QwtPlot::Axis
62
\sa isAxisEnabled, moveCanvas
64
void QwtPlotPanner::setAxisEnabled(int axis, bool on)
66
if ( axis >= 0 && axis < QwtPlot::axisCnt )
67
d_data->isAxisEnabled[axis] = on;
71
Test if an axis is enabled
73
\param axis Axis, see QwtPlot::Axis
74
\return True, if the axis is enabled
76
\sa setAxisEnabled, moveCanvas
78
bool QwtPlotPanner::isAxisEnabled(int axis) const
80
if ( axis >= 0 && axis < QwtPlot::axisCnt )
81
return d_data->isAxisEnabled[axis];
86
//! Return observed plot canvas
87
QwtPlotCanvas *QwtPlotPanner::canvas()
89
QWidget *w = parentWidget();
90
if ( w && w->inherits("QwtPlotCanvas") )
91
return (QwtPlotCanvas *)w;
96
//! Return Observed plot canvas
97
const QwtPlotCanvas *QwtPlotPanner::canvas() const
99
return ((QwtPlotPanner *)this)->canvas();
102
//! Return plot widget, containing the observed plot canvas
103
QwtPlot *QwtPlotPanner::plot()
105
QObject *w = canvas();
109
if ( w && w->inherits("QwtPlot") )
116
//! Return plot widget, containing the observed plot canvas
117
const QwtPlot *QwtPlotPanner::plot() const
119
return ((QwtPlotPanner *)this)->plot();
123
Adjust the enabled axes according to dx/dy
125
\param dx Pixel offset in x direction
126
\param dy Pixel offset in y direction
128
\sa QwtPanner::panned()
130
void QwtPlotPanner::moveCanvas(int dx, int dy)
132
if ( dx == 0 && dy == 0 )
135
QwtPlot *plot = QwtPlotPanner::plot();
139
const bool doAutoReplot = plot->autoReplot();
140
plot->setAutoReplot(false);
142
for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
144
if ( !d_data->isAxisEnabled[axis] )
147
const QwtScaleMap map = plot->canvasMap(axis);
149
const int i1 = map.transform(plot->axisScaleDiv(axis)->lBound());
150
const int i2 = map.transform(plot->axisScaleDiv(axis)->hBound());
153
if ( axis == QwtPlot::xBottom || axis == QwtPlot::xTop )
155
d1 = map.invTransform(i1 - dx);
156
d2 = map.invTransform(i2 - dx);
160
d1 = map.invTransform(i1 - dy);
161
d2 = map.invTransform(i2 - dy);
164
plot->setAxisScale(axis, d1, d2);
167
plot->setAutoReplot(doAutoReplot);