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
58 : QWidget( parent )
59{
60 m_data = new PrivateData;
61 rescale( 0.0, 100.0, m_data->stepSize );
62}
63
66{
67 delete m_data;
68}
69
80{
81 setScale( value, upperBound() );
82}
83
89{
90 return m_data->scaleDraw->scaleDiv().lowerBound();
91}
92
103{
104 setScale( lowerBound(), value );
105}
106
112{
113 return m_data->scaleDraw->scaleDiv().upperBound();
114}
115
130void QwtAbstractScale::setScale( double lowerBound, double upperBound )
131{
132 rescale( lowerBound, upperBound, m_data->stepSize );
133}
134
146{
147 setScale( interval.minValue(), interval.maxValue() );
148}
149
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
190{
191 if ( ticks != m_data->maxMajor )
192 {
193 m_data->maxMajor = ticks;
195 }
196}
197
203{
204 return m_data->maxMajor;
205}
206
220{
221 if ( ticks != m_data->maxMinor )
222 {
223 m_data->maxMinor = ticks;
225 }
226}
227
233{
234 return m_data->maxMinor;
235}
236
252{
253 if ( stepSize != m_data->stepSize )
254 {
255 m_data->stepSize = stepSize;
257 }
258}
259
265{
266 return m_data->stepSize;
267}
268
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
294{
295 return m_data->scaleDraw;
296}
297
303{
304 return m_data->scaleDraw;
305}
306
317{
318 if ( scaleEngine != NULL && scaleEngine != m_data->scaleEngine )
319 {
320 delete m_data->scaleEngine;
321 m_data->scaleEngine = scaleEngine;
322 }
323}
324
330{
331 return m_data->scaleEngine;
332}
333
339{
340 return m_data->scaleEngine;
341}
342
350{
351 return m_data->scaleDraw->scaleDiv();
352}
353
358{
359 return m_data->scaleDraw->scaleMap();
360}
361
369int QwtAbstractScale::transform( double value ) const
370{
371 return qRound( m_data->scaleDraw->scaleMap().transform( value ) );
372}
373
381double QwtAbstractScale::invTransform( int value ) const
382{
383 return m_data->scaleDraw->scaleMap().invTransform( value );
384}
385
391{
392 return m_data->scaleDraw->scaleMap().isInverting();
393}
394
400{
401 return qMin( m_data->scaleDraw->scaleDiv().lowerBound(),
402 m_data->scaleDraw->scaleDiv().upperBound() );
403}
404
410{
411 return qMax( m_data->scaleDraw->scaleDiv().lowerBound(),
412 m_data->scaleDraw->scaleDiv().upperBound() );
413}
414
419
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
453void 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
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"
A abstract base class for drawing scales.
void setScaleDiv(const QwtScaleDiv &)
const QwtScaleMap & scaleMap() const
void setTransformation(QwtTransform *)
const QwtScaleDiv & scaleDiv() const
virtual void scaleChange()
Notify changed scale.
const QwtScaleMap & scaleMap() const
void setUpperBound(double value)
void setScaleMaxMajor(int ticks)
Set the maximum number of major tick intervals.
double lowerBound() const
const QwtAbstractScaleDraw * abstractScaleDraw() const
double invTransform(int) const
const QwtScaleEngine * scaleEngine() const
void rescale(double lowerBound, double upperBound, double stepSize)
void setScaleMaxMinor(int ticks)
Set the maximum number of minor tick intervals.
const QwtScaleDiv & scaleDiv() const
double scaleStepSize() const
int transform(double) const
virtual ~QwtAbstractScale()
Destructor.
void setAbstractScaleDraw(QwtAbstractScaleDraw *)
Set a scale draw.
QwtAbstractScale(QWidget *parent=NULL)
void setScaleEngine(QwtScaleEngine *)
Set a scale engine.
void setLowerBound(double value)
void setScaleStepSize(double stepSize)
Set the step size used for calculating a scale division.
double upperBound() const
void setScale(double lowerBound, double upperBound)
Specify a scale.
virtual void changeEvent(QEvent *) override
A class representing an interval.
double minValue() const
double maxValue() const
A scale engine for linear scales.
A class representing a scale division.
double lowerBound() const
double upperBound() const
A class for drawing scales.
Base class for scale engines.
QwtTransform * transformation() const
virtual QwtScaleDiv divideScale(double x1, double x2, int maxMajorSteps, int maxMinorSteps, double stepSize=0.0) const =0
Calculate a scale division.
A scale map.
bool isInverting() const
double transform(double s) const
double invTransform(double p) const