source: ntrip/branches/BNC_2.13.beta/qwt/qwt_abstract_scale.cpp@ 10132

Last change on this file since 10132 was 9383, checked in by stoecker, 4 years ago

update to qwt verion 6.1.1 to fix build with newer Qt5

File size: 10.2 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_abstract_scale.h"
11#include "qwt_scale_engine.h"
12#include "qwt_scale_draw.h"
13#include "qwt_scale_div.h"
14#include "qwt_scale_map.h"
15#include "qwt_interval.h"
16
17class QwtAbstractScale::PrivateData
18{
19public:
20 PrivateData():
21 maxMajor( 5 ),
22 maxMinor( 3 ),
23 stepSize( 0.0 )
24 {
25 scaleEngine = new QwtLinearScaleEngine();
26 scaleDraw = new QwtScaleDraw();
27 }
28
29 ~PrivateData()
30 {
31 delete scaleEngine;
32 delete scaleDraw;
33 }
34
35 QwtScaleEngine *scaleEngine;
36 QwtAbstractScaleDraw *scaleDraw;
37
38 int maxMajor;
39 int maxMinor;
40 double stepSize;
41};
42
43/*!
44 Constructor
45
46 \param parent Parent widget
47
48 Creates a default QwtScaleDraw and a QwtLinearScaleEngine.
49 The initial scale boundaries are set to [ 0.0, 100.0 ]
50
51 The scaleStepSize() is initialized to 0.0, scaleMaxMajor() to 5
52 and scaleMaxMajor to 3.
53*/
54
55QwtAbstractScale::QwtAbstractScale( QWidget *parent ):
56 QWidget( parent )
57{
58 d_data = new PrivateData;
59 rescale( 0.0, 100.0, d_data->stepSize );
60}
61
62//! Destructor
63QwtAbstractScale::~QwtAbstractScale()
64{
65 delete d_data;
66}
67
68/*!
69 Set the lower bound of the scale
70
71 \param value Lower bound
72
73 \sa lowerBound(), setScale(), setUpperBound()
74 \note For inverted scales the lower bound
75 is greater than the upper bound
76*/
77void QwtAbstractScale::setLowerBound( double value )
78{
79 setScale( value, upperBound() );
80}
81
82/*!
83 \return Lower bound of the scale
84 \sa setLowerBound(), setScale(), upperBound()
85*/
86double QwtAbstractScale::lowerBound() const
87{
88 return d_data->scaleDraw->scaleDiv().lowerBound();
89}
90
91/*!
92 Set the upper bound of the scale
93
94 \param value Upper bound
95
96 \sa upperBound(), setScale(), setLowerBound()
97 \note For inverted scales the lower bound
98 is greater than the upper bound
99*/
100void QwtAbstractScale::setUpperBound( double value )
101{
102 setScale( lowerBound(), value );
103}
104
105/*!
106 \return Upper bound of the scale
107 \sa setUpperBound(), setScale(), lowerBound()
108*/
109double QwtAbstractScale::upperBound() const
110{
111 return d_data->scaleDraw->scaleDiv().upperBound();
112}
113
114/*!
115 \brief Specify a scale.
116
117 Define a scale by an interval
118
119 The ticks are calculated using scaleMaxMinor(),
120 scaleMaxMajor() and scaleStepSize().
121
122 \param lowerBound lower limit of the scale interval
123 \param upperBound upper limit of the scale interval
124
125 \note For inverted scales the lower bound
126 is greater than the upper bound
127*/
128void QwtAbstractScale::setScale( double lowerBound, double upperBound )
129{
130 rescale( lowerBound, upperBound, d_data->stepSize );
131}
132
133/*!
134 \brief Specify a scale.
135
136 Define a scale by an interval
137
138 The ticks are calculated using scaleMaxMinor(),
139 scaleMaxMajor() and scaleStepSize().
140
141 \param interval Interval
142*/
143void QwtAbstractScale::setScale( const QwtInterval &interval )
144{
145 setScale( interval.minValue(), interval.maxValue() );
146}
147
148/*!
149 \brief Specify a scale.
150
151 scaleMaxMinor(), scaleMaxMajor() and scaleStepSize() and have no effect.
152
153 \param scaleDiv Scale division
154 \sa setAutoScale()
155*/
156void QwtAbstractScale::setScale( const QwtScaleDiv &scaleDiv )
157{
158 if ( scaleDiv != d_data->scaleDraw->scaleDiv() )
159 {
160#if 1
161 if ( d_data->scaleEngine )
162 {
163 d_data->scaleDraw->setTransformation(
164 d_data->scaleEngine->transformation() );
165 }
166#endif
167
168 d_data->scaleDraw->setScaleDiv( scaleDiv );
169
170 scaleChange();
171 }
172}
173
174/*!
175 \brief Set the maximum number of major tick intervals.
176
177 The scale's major ticks are calculated automatically such that
178 the number of major intervals does not exceed ticks.
179
180 The default value is 5.
181
182 \param ticks Maximal number of major ticks.
183
184 \sa scaleMaxMajor(), setScaleMaxMinor(),
185 setScaleStepSize(), QwtScaleEngine::divideInterval()
186*/
187void QwtAbstractScale::setScaleMaxMajor( int ticks )
188{
189 if ( ticks != d_data->maxMajor )
190 {
191 d_data->maxMajor = ticks;
192 updateScaleDraw();
193 }
194}
195
196/*!
197 \return Maximal number of major tick intervals
198 \sa setScaleMaxMajor(), scaleMaxMinor()
199*/
200int QwtAbstractScale::scaleMaxMajor() const
201{
202 return d_data->maxMajor;
203}
204
205/*!
206 \brief Set the maximum number of minor tick intervals
207
208 The scale's minor ticks are calculated automatically such that
209 the number of minor intervals does not exceed ticks.
210 The default value is 3.
211
212 \param ticks Maximal number of minor ticks.
213
214 \sa scaleMaxMajor(), setScaleMaxMinor(),
215 setScaleStepSize(), QwtScaleEngine::divideInterval()
216*/
217void QwtAbstractScale::setScaleMaxMinor( int ticks )
218{
219 if ( ticks != d_data->maxMinor )
220 {
221 d_data->maxMinor = ticks;
222 updateScaleDraw();
223 }
224}
225
226/*!
227 \return Maximal number of minor tick intervals
228 \sa setScaleMaxMinor(), scaleMaxMajor()
229*/
230int QwtAbstractScale::scaleMaxMinor() const
231{
232 return d_data->maxMinor;
233}
234
235/*!
236 \brief Set the step size used for calculating a scale division
237
238 The step size is hint for calculating the intervals for
239 the major ticks of the scale. A value of 0.0 is interpreted
240 as no hint.
241
242 \param stepSize Hint for the step size of the scale
243
244 \sa scaleStepSize(), QwtScaleEngine::divideScale()
245
246 \note Position and distance between the major ticks also
247 depends on scaleMaxMajor().
248*/
249void QwtAbstractScale::setScaleStepSize( double stepSize )
250{
251 if ( stepSize != d_data->stepSize )
252 {
253 d_data->stepSize = stepSize;
254 updateScaleDraw();
255 }
256}
257
258/*!
259 \return Hint for the step size of the scale
260 \sa setScaleStepSize(), QwtScaleEngine::divideScale()
261*/
262double QwtAbstractScale::scaleStepSize() const
263{
264 return d_data->stepSize;
265}
266
267/*!
268 \brief Set a scale draw
269
270 scaleDraw has to be created with new and will be deleted in
271 the destructor or the next call of setAbstractScaleDraw().
272
273 \sa abstractScaleDraw()
274*/
275void QwtAbstractScale::setAbstractScaleDraw( QwtAbstractScaleDraw *scaleDraw )
276{
277 if ( scaleDraw == NULL || scaleDraw == d_data->scaleDraw )
278 return;
279
280 if ( d_data->scaleDraw != NULL )
281 scaleDraw->setScaleDiv( d_data->scaleDraw->scaleDiv() );
282
283 delete d_data->scaleDraw;
284 d_data->scaleDraw = scaleDraw;
285}
286
287/*!
288 \return Scale draw
289 \sa setAbstractScaleDraw()
290*/
291QwtAbstractScaleDraw *QwtAbstractScale::abstractScaleDraw()
292{
293 return d_data->scaleDraw;
294}
295
296/*!
297 \return Scale draw
298 \sa setAbstractScaleDraw()
299*/
300const QwtAbstractScaleDraw *QwtAbstractScale::abstractScaleDraw() const
301{
302 return d_data->scaleDraw;
303}
304
305/*!
306 \brief Set a scale engine
307
308 The scale engine is responsible for calculating the scale division
309 and provides a transformation between scale and widget coordinates.
310
311 scaleEngine has to be created with new and will be deleted in
312 the destructor or the next call of setScaleEngine.
313*/
314void QwtAbstractScale::setScaleEngine( QwtScaleEngine *scaleEngine )
315{
316 if ( scaleEngine != NULL && scaleEngine != d_data->scaleEngine )
317 {
318 delete d_data->scaleEngine;
319 d_data->scaleEngine = scaleEngine;
320 }
321}
322
323/*!
324 \return Scale engine
325 \sa setScaleEngine()
326*/
327const QwtScaleEngine *QwtAbstractScale::scaleEngine() const
328{
329 return d_data->scaleEngine;
330}
331
332/*!
333 \return Scale engine
334 \sa setScaleEngine()
335*/
336QwtScaleEngine *QwtAbstractScale::scaleEngine()
337{
338 return d_data->scaleEngine;
339}
340
341/*!
342 \return Scale boundaries and positions of the ticks
343
344 The scale division might have been assigned explicitly
345 or calculated implicitly by rescale().
346 */
347const QwtScaleDiv &QwtAbstractScale::scaleDiv() const
348{
349 return d_data->scaleDraw->scaleDiv();
350}
351
352/*!
353 \return Map to translate between scale and widget coordinates
354 */
355const QwtScaleMap &QwtAbstractScale::scaleMap() const
356{
357 return d_data->scaleDraw->scaleMap();
358}
359
360/*!
361 Translate a scale value into a widget coordinate
362
363 \param value Scale value
364 \return Corresponding widget coordinate for value
365 \sa scaleMap(), invTransform()
366 */
367int QwtAbstractScale::transform( double value ) const
368{
369 return qRound( d_data->scaleDraw->scaleMap().transform( value ) );
370}
371
372/*!
373 Translate a widget coordinate into a scale value
374
375 \param value Widget coordinate
376 \return Corresponding scale coordinate for value
377 \sa scaleMap(), transform()
378 */
379double QwtAbstractScale::invTransform( int value ) const
380{
381 return d_data->scaleDraw->scaleMap().invTransform( value );
382}
383
384/*!
385 \return True, when the scale is increasing in opposite direction
386 to the widget coordinates
387 */
388bool QwtAbstractScale::isInverted() const
389{
390 return d_data->scaleDraw->scaleMap().isInverting();
391}
392
393/*!
394 \return The boundary with the smaller value
395 \sa maximum(), lowerBound(), upperBound()
396 */
397double QwtAbstractScale::minimum() const
398{
399 return qMin( d_data->scaleDraw->scaleDiv().lowerBound(),
400 d_data->scaleDraw->scaleDiv().upperBound() );
401}
402
403/*!
404 \return The boundary with the larger value
405 \sa minimum(), lowerBound(), upperBound()
406 */
407double QwtAbstractScale::maximum() const
408{
409 return qMax( d_data->scaleDraw->scaleDiv().lowerBound(),
410 d_data->scaleDraw->scaleDiv().upperBound() );
411}
412
413//! Notify changed scale
414void QwtAbstractScale::scaleChange()
415{
416}
417
418/*!
419 Recalculate the scale division and update the scale.
420
421 \param lowerBound Lower limit of the scale interval
422 \param upperBound Upper limit of the scale interval
423 \param stepSize Major step size
424
425 \sa scaleChange()
426*/
427void QwtAbstractScale::rescale(
428 double lowerBound, double upperBound, double stepSize )
429{
430 const QwtScaleDiv scaleDiv = d_data->scaleEngine->divideScale(
431 lowerBound, upperBound, d_data->maxMajor, d_data->maxMinor, stepSize );
432
433 if ( scaleDiv != d_data->scaleDraw->scaleDiv() )
434 {
435#if 1
436 d_data->scaleDraw->setTransformation(
437 d_data->scaleEngine->transformation() );
438#endif
439
440 d_data->scaleDraw->setScaleDiv( scaleDiv );
441 scaleChange();
442 }
443}
444
445void QwtAbstractScale::updateScaleDraw()
446{
447 rescale( d_data->scaleDraw->scaleDiv().lowerBound(),
448 d_data->scaleDraw->scaleDiv().upperBound(), d_data->stepSize );
449}
Note: See TracBrowser for help on using the repository browser.