Qwt User's Guide: qwt_abstract_scale.cpp Source File

- Main Page
- Classes
- Files
- Related Pages

- File List
- File Members

# qwt_abstract_scale.cpp

    00001 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
    00002  * Qwt Widget Library
    00003  * Copyright (C) 1997   Josef Wilgen
    00004  * Copyright (C) 2002   Uwe Rathmann
    00005  *
    00006  * This library is free software; you can redistribute it and/or
    00007  * modify it under the terms of the Qwt License, Version 1.0
    00008  *****************************************************************************/
    00009
    00010 #include "qwt_scale_engine.h"
    00011 #include "qwt_scale_draw.h"
    00012 #include "qwt_scale_div.h"
    00013 #include "qwt_scale_map.h"
    00014 #include "qwt_double_interval.h"
    00015 #include "qwt_abstract_scale.h"
    00016
    00017 class QwtAbstractScale::PrivateData
    00018 {
    00019 public:
    00020     PrivateData():
    00021         maxMajor(5),
    00022         maxMinor(3),
    00023         stepSize(0.0),
    00024         autoScale(true)
    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     bool autoScale;
    00044 };
    00045
    00053 QwtAbstractScale::QwtAbstractScale()
    00054 {
    00055     d_data = new PrivateData;
    00056     rescale(0.0, 100.0);
    00057 }
    00058
    00060 QwtAbstractScale::~QwtAbstractScale()
    00061 {
    00062     delete d_data;
    00063 }
    00064
    00075 void QwtAbstractScale::setScale(double vmin, double vmax, double stepSize)
    00076 {
    00077     d_data->autoScale = false;
    00078     d_data->stepSize = stepSize;
    00079
    00080     rescale(vmin, vmax, stepSize);
    00081 }
    00082
    00092 void QwtAbstractScale::setScale(const QwtDoubleInterval &interval,
    00093     double stepSize)
    00094 {
    00095     setScale(interval.minValue(), interval.maxValue(), stepSize);
    00096 }
    00097
    00098
    00107 void QwtAbstractScale::setScale(const QwtScaleDiv &scaleDiv)
    00108 {
    00109     d_data->autoScale = false;
    00110
    00111     if (scaleDiv != d_data->scaleDraw->scaleDiv())
    00112     {
    00113         d_data->scaleDraw->setScaleDiv(scaleDiv);
    00114         scaleChange();
    00115     }
    00116 }
    00117
    00127 void QwtAbstractScale::rescale(double vmin, double vmax, double stepSize)
    00128 {
    00129     const QwtScaleDiv scaleDiv = d_data->scaleEngine->divideScale(
    00130         vmin, vmax, d_data->maxMajor, d_data->maxMinor, stepSize);
    00131
    00132     if ( scaleDiv != d_data->scaleDraw->scaleDiv() )
    00133     {
    00134         d_data->scaleDraw->setTransformation(
    00135             d_data->scaleEngine->transformation());
    00136         d_data->scaleDraw->setScaleDiv(scaleDiv);
    00137         scaleChange();
    00138     }
    00139 }
    00140
    00147 void QwtAbstractScale::setAutoScale()
    00148 {
    00149     if (!d_data->autoScale)
    00150     {
    00151         d_data->autoScale = true;
    00152         scaleChange();
    00153     }
    00154 }
    00155
    00159 bool QwtAbstractScale::autoScale() const
    00160 {
    00161     return d_data->autoScale;
    00162 }
    00163
    00173 void QwtAbstractScale::setScaleMaxMajor(int ticks)
    00174 {
    00175     if (ticks != d_data->maxMajor)
    00176     {
    00177         d_data->maxMajor = ticks;
    00178         updateScaleDraw();
    00179     }
    00180 }
    00181
    00191 void QwtAbstractScale::setScaleMaxMinor(int ticks)
    00192 {
    00193     if ( ticks != d_data->maxMinor)
    00194     {
    00195         d_data->maxMinor = ticks;
    00196         updateScaleDraw();
    00197     }
    00198 }
    00199
    00204 int QwtAbstractScale::scaleMaxMinor() const
    00205 {
    00206     return d_data->maxMinor;
    00207 }
    00208
    00213 int QwtAbstractScale::scaleMaxMajor() const
    00214 {
    00215     return d_data->maxMajor;
    00216 }
    00217
    00224 void QwtAbstractScale::setAbstractScaleDraw(QwtAbstractScaleDraw *scaleDraw)
    00225 {
    00226     if ( scaleDraw == NULL || scaleDraw == d_data->scaleDraw )
    00227         return;
    00228
    00229     if ( d_data->scaleDraw != NULL )
    00230         scaleDraw->setScaleDiv(d_data->scaleDraw->scaleDiv());
    00231
    00232     delete d_data->scaleDraw;
    00233     d_data->scaleDraw = scaleDraw;
    00234 }
    00235
    00240 QwtAbstractScaleDraw *QwtAbstractScale::abstractScaleDraw()
    00241 {
    00242     return d_data->scaleDraw;
    00243 }
    00244
    00249 const QwtAbstractScaleDraw *QwtAbstractScale::abstractScaleDraw() const
    00250 {
    00251     return d_data->scaleDraw;
    00252 }
    00253
    00254 void QwtAbstractScale::updateScaleDraw()
    00255 {
    00256     rescale( d_data->scaleDraw->scaleDiv().lBound(),
    00257         d_data->scaleDraw->scaleDiv().hBound(), d_data->stepSize);
    00258 }
    00259
    00269 void QwtAbstractScale::setScaleEngine(QwtScaleEngine *scaleEngine)
    00270 {
    00271     if ( scaleEngine != NULL && scaleEngine != d_data->scaleEngine )
    00272     {
    00273         delete d_data->scaleEngine;
    00274         d_data->scaleEngine = scaleEngine;
    00275     }
    00276 }
    00277
    00282 const QwtScaleEngine *QwtAbstractScale::scaleEngine() const
    00283 {
    00284     return d_data->scaleEngine;
    00285 }
    00286
    00291 QwtScaleEngine *QwtAbstractScale::scaleEngine()
    00292 {
    00293     return d_data->scaleEngine;
    00294 }
    00295
    00301 void QwtAbstractScale::scaleChange()
    00302 {
    00303 }
    00304
    00308 const QwtScaleMap &QwtAbstractScale::scaleMap() const
    00309 {
    00310     return d_data->scaleDraw->scaleMap();
    00311 }