Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "qwt_abstract_scale.h"
00011 #include "qwt_scale_engine.h"
00012 #include "qwt_scale_draw.h"
00013 #include "qwt_scale_div.h"
00014 #include "qwt_scale_map.h"
00015 #include "qwt_interval.h"
00016 #include <qevent.h>
00017
00018 class QwtAbstractScale::PrivateData
00019 {
00020 public:
00021 PrivateData():
00022 maxMajor( 5 ),
00023 maxMinor( 3 ),
00024 stepSize( 0.0 )
00025 {
00026 scaleEngine = new QwtLinearScaleEngine();
00027 scaleDraw = new QwtScaleDraw();
00028 }
00029
00030 ~PrivateData()
00031 {
00032 delete scaleEngine;
00033 delete scaleDraw;
00034 }
00035
00036 QwtScaleEngine *scaleEngine;
00037 QwtAbstractScaleDraw *scaleDraw;
00038
00039 int maxMajor;
00040 int maxMinor;
00041 double stepSize;
00042 };
00043
00056 QwtAbstractScale::QwtAbstractScale( QWidget *parent ):
00057 QWidget( parent )
00058 {
00059 d_data = new PrivateData;
00060 rescale( 0.0, 100.0, d_data->stepSize );
00061 }
00062
00064 QwtAbstractScale::~QwtAbstractScale()
00065 {
00066 delete d_data;
00067 }
00068
00078 void QwtAbstractScale::setLowerBound( double value )
00079 {
00080 setScale( value, upperBound() );
00081 }
00082
00087 double QwtAbstractScale::lowerBound() const
00088 {
00089 return d_data->scaleDraw->scaleDiv().lowerBound();
00090 }
00091
00101 void QwtAbstractScale::setUpperBound( double value )
00102 {
00103 setScale( lowerBound(), value );
00104 }
00105
00110 double QwtAbstractScale::upperBound() const
00111 {
00112 return d_data->scaleDraw->scaleDiv().upperBound();
00113 }
00114
00129 void QwtAbstractScale::setScale( double lowerBound, double upperBound )
00130 {
00131 rescale( lowerBound, upperBound, d_data->stepSize );
00132 }
00133
00144 void QwtAbstractScale::setScale( const QwtInterval &interval )
00145 {
00146 setScale( interval.minValue(), interval.maxValue() );
00147 }
00148
00157 void QwtAbstractScale::setScale( const QwtScaleDiv &scaleDiv )
00158 {
00159 if ( scaleDiv != d_data->scaleDraw->scaleDiv() )
00160 {
00161 #if 1
00162 if ( d_data->scaleEngine )
00163 {
00164 d_data->scaleDraw->setTransformation(
00165 d_data->scaleEngine->transformation() );
00166 }
00167 #endif
00168
00169 d_data->scaleDraw->setScaleDiv( scaleDiv );
00170
00171 scaleChange();
00172 }
00173 }
00174
00188 void QwtAbstractScale::setScaleMaxMajor( int ticks )
00189 {
00190 if ( ticks != d_data->maxMajor )
00191 {
00192 d_data->maxMajor = ticks;
00193 updateScaleDraw();
00194 }
00195 }
00196
00201 int QwtAbstractScale::scaleMaxMajor() const
00202 {
00203 return d_data->maxMajor;
00204 }
00205
00218 void QwtAbstractScale::setScaleMaxMinor( int ticks )
00219 {
00220 if ( ticks != d_data->maxMinor )
00221 {
00222 d_data->maxMinor = ticks;
00223 updateScaleDraw();
00224 }
00225 }
00226
00231 int QwtAbstractScale::scaleMaxMinor() const
00232 {
00233 return d_data->maxMinor;
00234 }
00235
00250 void QwtAbstractScale::setScaleStepSize( double stepSize )
00251 {
00252 if ( stepSize != d_data->stepSize )
00253 {
00254 d_data->stepSize = stepSize;
00255 updateScaleDraw();
00256 }
00257 }
00258
00263 double QwtAbstractScale::scaleStepSize() const
00264 {
00265 return d_data->stepSize;
00266 }
00267
00276 void QwtAbstractScale::setAbstractScaleDraw( QwtAbstractScaleDraw *scaleDraw )
00277 {
00278 if ( scaleDraw == NULL || scaleDraw == d_data->scaleDraw )
00279 return;
00280
00281 if ( d_data->scaleDraw != NULL )
00282 scaleDraw->setScaleDiv( d_data->scaleDraw->scaleDiv() );
00283
00284 delete d_data->scaleDraw;
00285 d_data->scaleDraw = scaleDraw;
00286 }
00287
00292 QwtAbstractScaleDraw *QwtAbstractScale::abstractScaleDraw()
00293 {
00294 return d_data->scaleDraw;
00295 }
00296
00301 const QwtAbstractScaleDraw *QwtAbstractScale::abstractScaleDraw() const
00302 {
00303 return d_data->scaleDraw;
00304 }
00305
00315 void QwtAbstractScale::setScaleEngine( QwtScaleEngine *scaleEngine )
00316 {
00317 if ( scaleEngine != NULL && scaleEngine != d_data->scaleEngine )
00318 {
00319 delete d_data->scaleEngine;
00320 d_data->scaleEngine = scaleEngine;
00321 }
00322 }
00323
00328 const QwtScaleEngine *QwtAbstractScale::scaleEngine() const
00329 {
00330 return d_data->scaleEngine;
00331 }
00332
00337 QwtScaleEngine *QwtAbstractScale::scaleEngine()
00338 {
00339 return d_data->scaleEngine;
00340 }
00341
00348 const QwtScaleDiv &QwtAbstractScale::scaleDiv() const
00349 {
00350 return d_data->scaleDraw->scaleDiv();
00351 }
00352
00356 const QwtScaleMap &QwtAbstractScale::scaleMap() const
00357 {
00358 return d_data->scaleDraw->scaleMap();
00359 }
00360
00368 int QwtAbstractScale::transform( double value ) const
00369 {
00370 return qRound( d_data->scaleDraw->scaleMap().transform( value ) );
00371 }
00372
00380 double QwtAbstractScale::invTransform( int value ) const
00381 {
00382 return d_data->scaleDraw->scaleMap().invTransform( value );
00383 }
00384
00389 bool QwtAbstractScale::isInverted() const
00390 {
00391 return d_data->scaleDraw->scaleMap().isInverting();
00392 }
00393
00398 double QwtAbstractScale::minimum() const
00399 {
00400 return qMin( d_data->scaleDraw->scaleDiv().lowerBound(),
00401 d_data->scaleDraw->scaleDiv().upperBound() );
00402 }
00403
00408 double QwtAbstractScale::maximum() const
00409 {
00410 return qMax( d_data->scaleDraw->scaleDiv().lowerBound(),
00411 d_data->scaleDraw->scaleDiv().upperBound() );
00412 }
00413
00415 void QwtAbstractScale::scaleChange()
00416 {
00417 }
00418
00428 void QwtAbstractScale::rescale(
00429 double lowerBound, double upperBound, double stepSize )
00430 {
00431 const QwtScaleDiv scaleDiv = d_data->scaleEngine->divideScale(
00432 lowerBound, upperBound, d_data->maxMajor, d_data->maxMinor, stepSize );
00433
00434 if ( scaleDiv != d_data->scaleDraw->scaleDiv() )
00435 {
00436 #if 1
00437 d_data->scaleDraw->setTransformation(
00438 d_data->scaleEngine->transformation() );
00439 #endif
00440
00441 d_data->scaleDraw->setScaleDiv( scaleDiv );
00442 scaleChange();
00443 }
00444 }
00445
00452 void QwtAbstractScale::changeEvent( QEvent *event )
00453 {
00454 if ( event->type() == QEvent::LocaleChange )
00455 {
00456 d_data->scaleDraw->invalidateCache();
00457 }
00458
00459 QWidget::changeEvent( event );
00460 }
00461
00465 void QwtAbstractScale::updateScaleDraw()
00466 {
00467 rescale( d_data->scaleDraw->scaleDiv().lowerBound(),
00468 d_data->scaleDraw->scaleDiv().upperBound(), d_data->stepSize );
00469 }