source: ntrip/trunk/GnssCenter/qwt/qwt_plot_panner.cpp@ 9313

Last change on this file since 9313 was 4839, checked in by mervart, 12 years ago
File size: 3.9 KB
Line 
1/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
2 * Qwt Widget Library
3 * Copyright (C) 1997 Josef Wilgen
4 * Copyright (C) 2002 Uwe Rathmann
5 *
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 *****************************************************************************/
9
10#include "qwt_plot_panner.h"
11#include "qwt_scale_div.h"
12#include "qwt_plot.h"
13#include "qwt_plot_canvas.h"
14
15class QwtPlotPanner::PrivateData
16{
17public:
18 PrivateData()
19 {
20 for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
21 isAxisEnabled[axis] = true;
22 }
23
24 bool isAxisEnabled[QwtPlot::axisCnt];
25};
26
27/*!
28 \brief Create a plot panner
29
30 The panner is enabled for all axes
31
32 \param canvas Plot canvas to pan, also the parent object
33
34 \sa setAxisEnabled()
35*/
36QwtPlotPanner::QwtPlotPanner( QwtPlotCanvas *canvas ):
37 QwtPanner( canvas )
38{
39 d_data = new PrivateData();
40
41 connect( this, SIGNAL( panned( int, int ) ),
42 SLOT( moveCanvas( int, int ) ) );
43}
44
45//! Destructor
46QwtPlotPanner::~QwtPlotPanner()
47{
48 delete d_data;
49}
50
51/*!
52 \brief En/Disable an axis
53
54 Axes that are enabled will be synchronized to the
55 result of panning. All other axes will remain unchanged.
56
57 \param axis Axis, see QwtPlot::Axis
58 \param on On/Off
59
60 \sa isAxisEnabled(), moveCanvas()
61*/
62void QwtPlotPanner::setAxisEnabled( int axis, bool on )
63{
64 if ( axis >= 0 && axis < QwtPlot::axisCnt )
65 d_data->isAxisEnabled[axis] = on;
66}
67
68/*!
69 Test if an axis is enabled
70
71 \param axis Axis, see QwtPlot::Axis
72 \return True, if the axis is enabled
73
74 \sa setAxisEnabled(), moveCanvas()
75*/
76bool QwtPlotPanner::isAxisEnabled( int axis ) const
77{
78 if ( axis >= 0 && axis < QwtPlot::axisCnt )
79 return d_data->isAxisEnabled[axis];
80
81 return true;
82}
83
84//! Return observed plot canvas
85QwtPlotCanvas *QwtPlotPanner::canvas()
86{
87 return qobject_cast<QwtPlotCanvas *>( parentWidget() );
88}
89
90//! Return Observed plot canvas
91const QwtPlotCanvas *QwtPlotPanner::canvas() const
92{
93 return qobject_cast<const QwtPlotCanvas *>( parentWidget() );
94}
95
96//! Return plot widget, containing the observed plot canvas
97QwtPlot *QwtPlotPanner::plot()
98{
99 QwtPlotCanvas *w = canvas();
100 if ( w )
101 return w->plot();
102
103 return NULL;
104}
105
106//! Return plot widget, containing the observed plot canvas
107const QwtPlot *QwtPlotPanner::plot() const
108{
109 const QwtPlotCanvas *w = canvas();
110 if ( w )
111 return w->plot();
112
113 return NULL;
114}
115
116/*!
117 Adjust the enabled axes according to dx/dy
118
119 \param dx Pixel offset in x direction
120 \param dy Pixel offset in y direction
121
122 \sa QwtPanner::panned()
123*/
124void QwtPlotPanner::moveCanvas( int dx, int dy )
125{
126 if ( dx == 0 && dy == 0 )
127 return;
128
129 QwtPlot *plot = this->plot();
130 if ( plot == NULL )
131 return;
132
133 const bool doAutoReplot = plot->autoReplot();
134 plot->setAutoReplot( false );
135
136 for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
137 {
138 if ( !d_data->isAxisEnabled[axis] )
139 continue;
140
141 const QwtScaleMap map = plot->canvasMap( axis );
142
143 const double p1 = map.transform( plot->axisScaleDiv( axis )->lowerBound() );
144 const double p2 = map.transform( plot->axisScaleDiv( axis )->upperBound() );
145
146 double d1, d2;
147 if ( axis == QwtPlot::xBottom || axis == QwtPlot::xTop )
148 {
149 d1 = map.invTransform( p1 - dx );
150 d2 = map.invTransform( p2 - dx );
151 }
152 else
153 {
154 d1 = map.invTransform( p1 - dy );
155 d2 = map.invTransform( p2 - dy );
156 }
157
158 plot->setAxisScale( axis, d1, d2 );
159 }
160
161 plot->setAutoReplot( doAutoReplot );
162 plot->replot();
163}
164
165/*!
166 Calculate a mask from the border mask of the canvas
167 \sa QwtPlotCanvas::borderMask()
168*/
169QBitmap QwtPlotPanner::contentsMask() const
170{
171 if ( canvas() )
172 return canvas()->borderMask( size() );
173
174 return QwtPanner::contentsMask();
175}
Note: See TracBrowser for help on using the repository browser.