source: ntrip/trunk/BNC/qwt/qwt_plot_magnifier.cpp@ 8486

Last change on this file since 8486 was 8127, checked in by stoecker, 8 years ago

update qwt and qwtpolar, many QT5 fixes (unfinished)

File size: 3.7 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.h"
11#include "qwt_scale_div.h"
12#include "qwt_plot_magnifier.h"
13#include <qevent.h>
14
15class QwtPlotMagnifier::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 Constructor
29 \param canvas Plot canvas to be magnified
30*/
31QwtPlotMagnifier::QwtPlotMagnifier( QWidget *canvas ):
32 QwtMagnifier( canvas )
33{
34 d_data = new PrivateData();
35}
36
37//! Destructor
38QwtPlotMagnifier::~QwtPlotMagnifier()
39{
40 delete d_data;
41}
42
43/*!
44 \brief En/Disable an axis
45
46 Only Axes that are enabled will be zoomed.
47 All other axes will remain unchanged.
48
49 \param axis Axis, see QwtPlot::Axis
50 \param on On/Off
51
52 \sa isAxisEnabled()
53*/
54void QwtPlotMagnifier::setAxisEnabled( int axis, bool on )
55{
56 if ( axis >= 0 && axis < QwtPlot::axisCnt )
57 d_data->isAxisEnabled[axis] = on;
58}
59
60/*!
61 Test if an axis is enabled
62
63 \param axis Axis, see QwtPlot::Axis
64 \return True, if the axis is enabled
65
66 \sa setAxisEnabled()
67*/
68bool QwtPlotMagnifier::isAxisEnabled( int axis ) const
69{
70 if ( axis >= 0 && axis < QwtPlot::axisCnt )
71 return d_data->isAxisEnabled[axis];
72
73 return true;
74}
75
76//! Return observed plot canvas
77QWidget *QwtPlotMagnifier::canvas()
78{
79 return parentWidget();
80}
81
82//! Return Observed plot canvas
83const QWidget *QwtPlotMagnifier::canvas() const
84{
85 return parentWidget();
86}
87
88//! Return plot widget, containing the observed plot canvas
89QwtPlot *QwtPlotMagnifier::plot()
90{
91 QWidget *w = canvas();
92 if ( w )
93 w = w->parentWidget();
94
95 return qobject_cast<QwtPlot *>( w );
96}
97
98//! Return plot widget, containing the observed plot canvas
99const QwtPlot *QwtPlotMagnifier::plot() const
100{
101 const QWidget *w = canvas();
102 if ( w )
103 w = w->parentWidget();
104
105 return qobject_cast<const QwtPlot *>( w );
106}
107
108/*!
109 Zoom in/out the axes scales
110 \param factor A value < 1.0 zooms in, a value > 1.0 zooms out.
111*/
112void QwtPlotMagnifier::rescale( double factor )
113{
114 QwtPlot* plt = plot();
115 if ( plt == NULL )
116 return;
117
118 factor = qAbs( factor );
119 if ( factor == 1.0 || factor == 0.0 )
120 return;
121
122 bool doReplot = false;
123
124 const bool autoReplot = plt->autoReplot();
125 plt->setAutoReplot( false );
126
127 for ( int axisId = 0; axisId < QwtPlot::axisCnt; axisId++ )
128 {
129 if ( isAxisEnabled( axisId ) )
130 {
131 const QwtScaleMap scaleMap = plt->canvasMap( axisId );
132
133 double v1 = scaleMap.s1();
134 double v2 = scaleMap.s2();
135
136 if ( scaleMap.transformation() )
137 {
138 // the coordinate system of the paint device is always linear
139
140 v1 = scaleMap.transform( v1 ); // scaleMap.p1()
141 v2 = scaleMap.transform( v2 ); // scaleMap.p2()
142 }
143
144 const double center = 0.5 * ( v1 + v2 );
145 const double width_2 = 0.5 * ( v2 - v1 ) * factor;
146
147 v1 = center - width_2;
148 v2 = center + width_2;
149
150 if ( scaleMap.transformation() )
151 {
152 v1 = scaleMap.invTransform( v1 );
153 v2 = scaleMap.invTransform( v2 );
154 }
155
156 plt->setAxisScale( axisId, v1, v2 );
157 doReplot = true;
158 }
159 }
160
161 plt->setAutoReplot( autoReplot );
162
163 if ( doReplot )
164 plt->replot();
165}
Note: See TracBrowser for help on using the repository browser.