Qwt User's Guide: qwt_abstract_scale.cpp Source File

Qwt User's Guide 6.3.0

Loading...
Searching...
No Matches
qwt_abstract_scale.cpp
1/******************************************************************************
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
17#include <qcoreevent.h>
18
19class QwtAbstractScale::PrivateData
20{
21 public:
22 PrivateData():
23 maxMajor( 5 ),
24 maxMinor( 3 ),
25 stepSize( 0.0 )
26 {
27 scaleEngine = new QwtLinearScaleEngine();
28 scaleDraw = new QwtScaleDraw();
29 }
30
31 ~PrivateData()
32 {
33 delete scaleEngine;
34 delete scaleDraw;
35 }
36
37 QwtScaleEngine* scaleEngine;
38 QwtAbstractScaleDraw* scaleDraw;
39
40 int maxMajor;
41 int maxMinor;
42 double stepSize;
43};
44
57QwtAbstractScale::QwtAbstractScale( QWidget* parent )
58 : QWidget( parent )
59{
60 m_data = new PrivateData;
61 rescale( 0.0, 100.0, m_data->stepSize );
62}
63
65QwtAbstractScale::~QwtAbstractScale()
66{
67 delete m_data;
68}
69
79 void QwtAbstractScale::setLowerBound( double value )
80{
81 setScale( value, upperBound() );
82}
83
88 double QwtAbstractScale::lowerBound() const
89{
90 return m_data->scaleDraw->scaleDiv().lowerBound();
91}
92
102 void QwtAbstractScale::setUpperBound( double value )
103{
104 setScale( lowerBound(), value );
105}
106
111 double QwtAbstractScale::upperBound() const
112{
113 return m_data->scaleDraw->scaleDiv().upperBound();
114}
115
130 void QwtAbstractScale::setScale( double lowerBound, double upperBound )
131{
132 rescale( lowerBound, upperBound, m_data->stepSize );
133}
134
145 void QwtAbstractScale::setScale( const QwtInterval& interval )
146{
147 setScale( interval.minValue(), interval.maxValue() );
148}
149
158 void QwtAbstractScale::setScale( const QwtScaleDiv& scaleDiv )
159{
160 if ( scaleDiv != m_data->scaleDraw->scaleDiv() )
161 {
162#if 1
163 if ( m_data->scaleEngine )
164 {
165 m_data->scaleDraw->setTransformation(
166 m_data->scaleEngine->transformation() );
167 }
168#endif
169
170 m_data->scaleDraw->setScaleDiv( scaleDiv );
171
172 scaleChange();
173 }
174}
175
189 void QwtAbstractScale::setScaleMaxMajor( int ticks )
190{
191 if ( ticks != m_data->maxMajor )
192 {
193 m_data->maxMajor = ticks;
194 updateScaleDraw();
195 }
196}
197
202 int QwtAbstractScale::scaleMaxMajor() const
203{
204 return m_data->maxMajor;
205}
206
219 void QwtAbstractScale::setScaleMaxMinor( int ticks )
220{
221 if ( ticks != m_data->maxMinor )
222 {
223 m_data->maxMinor = ticks;
224 updateScaleDraw();
225 }
226}
227
232 int QwtAbstractScale::scaleMaxMinor() const
233{
234 return m_data->maxMinor;
235}
236
251 void QwtAbstractScale::setScaleStepSize( double stepSize )
252{
253 if ( stepSize != m_data->stepSize )
254 {
255 m_data->stepSize = stepSize;
256 updateScaleDraw();
257 }
258}
259
264 double QwtAbstractScale::scaleStepSize() const
265{
266 return m_data->stepSize;
267}
268
277 void QwtAbstractScale::setAbstractScaleDraw( QwtAbstractScaleDraw* scaleDraw )
278{
279 if ( scaleDraw == NULL || scaleDraw == m_data->scaleDraw )
280 return;
281
282 if ( m_data->scaleDraw != NULL )
283 scaleDraw->setScaleDiv( m_data->scaleDraw->scaleDiv() );
284
285 delete m_data->scaleDraw;
286 m_data->scaleDraw = scaleDraw;
287}
288
293 QwtAbstractScaleDraw* QwtAbstractScale::abstractScaleDraw()
294{
295 return m_data->scaleDraw;
296}
297
302 const QwtAbstractScaleDraw* QwtAbstractScale::abstractScaleDraw() const
303{
304 return m_data->scaleDraw;
305}
306
316 void QwtAbstractScale::setScaleEngine( QwtScaleEngine* scaleEngine )
317{
318 if ( scaleEngine != NULL && scaleEngine != m_data->scaleEngine )
319 {
320 delete m_data->scaleEngine;
321 m_data->scaleEngine = scaleEngine;
322 }
323}
324
329 const QwtScaleEngine* QwtAbstractScale::scaleEngine() const
330{
331 return m_data->scaleEngine;
332}
333
338 QwtScaleEngine* QwtAbstractScale::scaleEngine()
339{
340 return m_data->scaleEngine;
341}
342
349 const QwtScaleDiv& QwtAbstractScale::scaleDiv() const
350{
351 return m_data->scaleDraw->scaleDiv();
352}
353
357 const QwtScaleMap& QwtAbstractScale::scaleMap() const
358{
359 return m_data->scaleDraw->scaleMap();
360}
361
369 int QwtAbstractScale::transform( double value ) const
370{
371 return qRound( m_data->scaleDraw->scaleMap().transform( value ) );
372}
373
381 double QwtAbstractScale::invTransform( int value ) const
382{
383 return m_data->scaleDraw->scaleMap().invTransform( value );
384}
385
390 bool QwtAbstractScale::isInverted() const
391{
392 return m_data->scaleDraw->scaleMap().isInverting();
393}
394
399 double QwtAbstractScale::minimum() const
400{
401 return qMin( m_data->scaleDraw->scaleDiv().lowerBound(),
402 m_data->scaleDraw->scaleDiv().upperBound() );
403}
404
409 double QwtAbstractScale::maximum() const
410{
411 return qMax( m_data->scaleDraw->scaleDiv().lowerBound(),
412 m_data->scaleDraw->scaleDiv().upperBound() );
413}
414
416 void QwtAbstractScale::scaleChange()
417{
418}
419
429 void QwtAbstractScale::rescale(
430 double lowerBound, double upperBound, double stepSize )
431{
432 const QwtScaleDiv scaleDiv = m_data->scaleEngine->divideScale(
433 lowerBound, upperBound, m_data->maxMajor, m_data->maxMinor, stepSize );
434
435 if ( scaleDiv != m_data->scaleDraw->scaleDiv() )
436 {
437#if 1
438 m_data->scaleDraw->setTransformation(
439 m_data->scaleEngine->transformation() );
440#endif
441
442 m_data->scaleDraw->setScaleDiv( scaleDiv );
443 scaleChange();
444 }
445}
446
453 void QwtAbstractScale::changeEvent( QEvent* event )
454{
455 if ( event->type() == QEvent::LocaleChange )
456 {
457 m_data->scaleDraw->invalidateCache();
458 }
459
460 QWidget::changeEvent( event );
461}
462
466 void QwtAbstractScale::updateScaleDraw()
467{
468 rescale( m_data->scaleDraw->scaleDiv().lowerBound(),
469 m_data->scaleDraw->scaleDiv().upperBound(), m_data->stepSize );
470}
471
472#include "moc_qwt_abstract_scale.cpp"
QwtAbstractScaleDraw
A abstract base class for drawing scales.
Definition qwt_abstract_scale_draw.h:32
QwtAbstractScaleDraw::setScaleDiv
void setScaleDiv(const QwtScaleDiv &)
Definition qwt_abstract_scale_draw.cpp:104
QwtAbstractScaleDraw::scaleMap
const QwtScaleMap & scaleMap() const
Definition qwt_abstract_scale_draw.cpp:121
QwtAbstractScaleDraw::invalidateCache
void invalidateCache()
Definition qwt_abstract_scale_draw.cpp:417
QwtAbstractScaleDraw::setTransformation
void setTransformation(QwtTransform *)
Definition qwt_abstract_scale_draw.cpp:115
QwtAbstractScaleDraw::scaleDiv
const QwtScaleDiv & scaleDiv() const
Definition qwt_abstract_scale_draw.cpp:133
QwtAbstractScale::scaleChange
virtual void scaleChange()
Notify changed scale.
Definition qwt_abstract_scale.cpp:416
QwtAbstractScale::scaleMap
const QwtScaleMap & scaleMap() const
Definition qwt_abstract_scale.cpp:357
QwtAbstractScale::setUpperBound
void setUpperBound(double value)
Definition qwt_abstract_scale.cpp:102
QwtAbstractScale::setScaleMaxMajor
void setScaleMaxMajor(int ticks)
Set the maximum number of major tick intervals.
Definition qwt_abstract_scale.cpp:189
QwtAbstractScale::lowerBound
double lowerBound() const
Definition qwt_abstract_scale.cpp:88
QwtAbstractScale::abstractScaleDraw
const QwtAbstractScaleDraw * abstractScaleDraw() const
Definition qwt_abstract_scale.cpp:302
QwtAbstractScale::invTransform
double invTransform(int) const
Definition qwt_abstract_scale.cpp:381
QwtAbstractScale::scaleEngine
const QwtScaleEngine * scaleEngine() const
Definition qwt_abstract_scale.cpp:329
QwtAbstractScale::rescale
void rescale(double lowerBound, double upperBound, double stepSize)
Definition qwt_abstract_scale.cpp:429
QwtAbstractScale::setScaleMaxMinor
void setScaleMaxMinor(int ticks)
Set the maximum number of minor tick intervals.
Definition qwt_abstract_scale.cpp:219
QwtAbstractScale::scaleDiv
const QwtScaleDiv & scaleDiv() const
Definition qwt_abstract_scale.cpp:349
QwtAbstractScale::scaleStepSize
double scaleStepSize() const
Definition qwt_abstract_scale.cpp:264
QwtAbstractScale::transform
int transform(double) const
Definition qwt_abstract_scale.cpp:369
QwtAbstractScale::~QwtAbstractScale
virtual ~QwtAbstractScale()
Destructor.
Definition qwt_abstract_scale.cpp:65
QwtAbstractScale::minimum
double minimum() const
Definition qwt_abstract_scale.cpp:399
QwtAbstractScale::isInverted
bool isInverted() const
Definition qwt_abstract_scale.cpp:390
QwtAbstractScale::setAbstractScaleDraw
void setAbstractScaleDraw(QwtAbstractScaleDraw *)
Set a scale draw.
Definition qwt_abstract_scale.cpp:277
QwtAbstractScale::scaleMaxMajor
int scaleMaxMajor() const
Definition qwt_abstract_scale.cpp:202
QwtAbstractScale::QwtAbstractScale
QwtAbstractScale(QWidget *parent=NULL)
Definition qwt_abstract_scale.cpp:57
QwtAbstractScale::setScaleEngine
void setScaleEngine(QwtScaleEngine *)
Set a scale engine.
Definition qwt_abstract_scale.cpp:316
QwtAbstractScale::setLowerBound
void setLowerBound(double value)
Definition qwt_abstract_scale.cpp:79
QwtAbstractScale::setScaleStepSize
void setScaleStepSize(double stepSize)
Set the step size used for calculating a scale division.
Definition qwt_abstract_scale.cpp:251
QwtAbstractScale::maximum
double maximum() const
Definition qwt_abstract_scale.cpp:409
QwtAbstractScale::updateScaleDraw
void updateScaleDraw()
Definition qwt_abstract_scale.cpp:466
QwtAbstractScale::upperBound
double upperBound() const
Definition qwt_abstract_scale.cpp:111
QwtAbstractScale::scaleMaxMinor
int scaleMaxMinor() const
Definition qwt_abstract_scale.cpp:232
QwtAbstractScale::setScale
void setScale(double lowerBound, double upperBound)
Specify a scale.
Definition qwt_abstract_scale.cpp:130
QwtAbstractScale::changeEvent
virtual void changeEvent(QEvent *) override
Definition qwt_abstract_scale.cpp:453
QwtInterval
A class representing an interval.
Definition qwt_interval.h:23
QwtInterval::minValue
double minValue() const
Definition qwt_interval.h:192
QwtInterval::maxValue
double maxValue() const
Definition qwt_interval.h:198
QwtLinearScaleEngine
A scale engine for linear scales.
Definition qwt_scale_engine.h:152
QwtScaleDiv
A class representing a scale division.
Definition qwt_scale_div.h:34
QwtScaleDiv::lowerBound
double lowerBound() const
Definition qwt_scale_div.cpp:131
QwtScaleDiv::upperBound
double upperBound() const
Definition qwt_scale_div.cpp:151
QwtScaleDraw
A class for drawing scales.
Definition qwt_scale_draw.h:36
QwtScaleEngine
Base class for scale engines.
Definition qwt_scale_engine.h:46
QwtScaleEngine::transformation
QwtTransform * transformation() const
Definition qwt_scale_engine.cpp:265
QwtScaleEngine::divideScale
virtual QwtScaleDiv divideScale(double x1, double x2, int maxMajorSteps, int maxMinorSteps, double stepSize=0.0) const =0
Calculate a scale division.
QwtScaleMap
A scale map.
Definition qwt_scale_map.h:27
QwtScaleMap::isInverting
bool isInverting() const
Definition qwt_scale_map.h:164
QwtScaleMap::transform
double transform(double s) const
Definition qwt_scale_map.h:137
QwtScaleMap::invTransform
double invTransform(double p) const
Definition qwt_scale_map.h:154