[4271] | 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 | #ifndef QWT_SCALE_ENGINE_H
|
---|
| 11 | #define QWT_SCALE_ENGINE_H
|
---|
| 12 |
|
---|
| 13 | #include "qwt_global.h"
|
---|
| 14 | #include "qwt_scale_div.h"
|
---|
| 15 | #include "qwt_interval.h"
|
---|
| 16 |
|
---|
| 17 | class QwtScaleTransformation;
|
---|
| 18 |
|
---|
| 19 | /*!
|
---|
| 20 | \brief Arithmetic including a tolerance
|
---|
| 21 | */
|
---|
| 22 | class QWT_EXPORT QwtScaleArithmetic
|
---|
| 23 | {
|
---|
| 24 | public:
|
---|
| 25 | static double ceilEps( double value, double intervalSize );
|
---|
| 26 | static double floorEps( double value, double intervalSize );
|
---|
| 27 |
|
---|
| 28 | static double divideEps( double interval, double steps );
|
---|
| 29 |
|
---|
| 30 | static double ceil125( double x );
|
---|
| 31 | static double floor125( double x );
|
---|
| 32 | };
|
---|
| 33 |
|
---|
| 34 | /*!
|
---|
| 35 | \brief Base class for scale engines.
|
---|
| 36 |
|
---|
| 37 | A scale engine tries to find "reasonable" ranges and step sizes
|
---|
| 38 | for scales.
|
---|
| 39 |
|
---|
| 40 | The layout of the scale can be varied with setAttribute().
|
---|
| 41 |
|
---|
| 42 | Qwt offers implementations for logarithmic (log10)
|
---|
| 43 | and linear scales. Contributions for other types of scale engines
|
---|
| 44 | (date/time, log2 ... ) are welcome.
|
---|
| 45 | */
|
---|
| 46 |
|
---|
| 47 | class QWT_EXPORT QwtScaleEngine
|
---|
| 48 | {
|
---|
| 49 | public:
|
---|
| 50 | /*!
|
---|
| 51 | Layout attributes
|
---|
| 52 | \sa setAttribute(), testAttribute(), reference(),
|
---|
| 53 | lowerMargin(), upperMargin()
|
---|
| 54 | */
|
---|
| 55 |
|
---|
| 56 | enum Attribute
|
---|
| 57 | {
|
---|
| 58 | //! No attributes
|
---|
| 59 | NoAttribute = 0x00,
|
---|
| 60 |
|
---|
| 61 | //! Build a scale which includes the reference() value.
|
---|
| 62 | IncludeReference = 0x01,
|
---|
| 63 |
|
---|
| 64 | //! Build a scale which is symmetric to the reference() value.
|
---|
| 65 | Symmetric = 0x02,
|
---|
| 66 |
|
---|
| 67 | /*!
|
---|
| 68 | The endpoints of the scale are supposed to be equal the
|
---|
| 69 | outmost included values plus the specified margins
|
---|
| 70 | (see setMargins()).
|
---|
| 71 | If this attribute is *not* set, the endpoints of the scale will
|
---|
| 72 | be integer multiples of the step size.
|
---|
| 73 | */
|
---|
| 74 | Floating = 0x04,
|
---|
| 75 |
|
---|
| 76 | //! Turn the scale upside down.
|
---|
| 77 | Inverted = 0x08
|
---|
| 78 | };
|
---|
| 79 |
|
---|
| 80 | //! Layout attributes
|
---|
| 81 | typedef QFlags<Attribute> Attributes;
|
---|
| 82 |
|
---|
| 83 | explicit QwtScaleEngine();
|
---|
| 84 | virtual ~QwtScaleEngine();
|
---|
| 85 |
|
---|
| 86 | void setAttribute( Attribute, bool on = true );
|
---|
| 87 | bool testAttribute( Attribute ) const;
|
---|
| 88 |
|
---|
| 89 | void setAttributes( Attributes );
|
---|
| 90 | Attributes attributes() const;
|
---|
| 91 |
|
---|
| 92 | void setReference( double reference );
|
---|
| 93 | double reference() const;
|
---|
| 94 |
|
---|
| 95 | void setMargins( double lower, double upper );
|
---|
| 96 | double lowerMargin() const;
|
---|
| 97 | double upperMargin() const;
|
---|
| 98 |
|
---|
| 99 | /*!
|
---|
| 100 | Align and divide an interval
|
---|
| 101 |
|
---|
| 102 | \param maxNumSteps Max. number of steps
|
---|
| 103 | \param x1 First limit of the interval (In/Out)
|
---|
| 104 | \param x2 Second limit of the interval (In/Out)
|
---|
| 105 | \param stepSize Step size (Return value)
|
---|
| 106 | */
|
---|
| 107 | virtual void autoScale( int maxNumSteps,
|
---|
| 108 | double &x1, double &x2, double &stepSize ) const = 0;
|
---|
| 109 |
|
---|
| 110 | /*!
|
---|
| 111 | \brief Calculate a scale division
|
---|
| 112 |
|
---|
| 113 | \param x1 First interval limit
|
---|
| 114 | \param x2 Second interval limit
|
---|
| 115 | \param maxMajSteps Maximum for the number of major steps
|
---|
| 116 | \param maxMinSteps Maximum number of minor steps
|
---|
| 117 | \param stepSize Step size. If stepSize == 0.0, the scaleEngine
|
---|
| 118 | calculates one.
|
---|
| 119 | */
|
---|
| 120 | virtual QwtScaleDiv divideScale( double x1, double x2,
|
---|
| 121 | int maxMajSteps, int maxMinSteps,
|
---|
| 122 | double stepSize = 0.0 ) const = 0;
|
---|
| 123 |
|
---|
| 124 | //! \return a transformation
|
---|
| 125 | virtual QwtScaleTransformation *transformation() const = 0;
|
---|
| 126 |
|
---|
| 127 | protected:
|
---|
| 128 | bool contains( const QwtInterval &, double val ) const;
|
---|
| 129 | QList<double> strip( const QList<double>&, const QwtInterval & ) const;
|
---|
| 130 | double divideInterval( double interval, int numSteps ) const;
|
---|
| 131 |
|
---|
| 132 | QwtInterval buildInterval( double v ) const;
|
---|
| 133 |
|
---|
| 134 | private:
|
---|
| 135 | class PrivateData;
|
---|
| 136 | PrivateData *d_data;
|
---|
| 137 | };
|
---|
| 138 |
|
---|
| 139 | /*!
|
---|
| 140 | \brief A scale engine for linear scales
|
---|
| 141 |
|
---|
| 142 | The step size will fit into the pattern
|
---|
| 143 | \f$\left\{ 1,2,5\right\} \cdot 10^{n}\f$, where n is an integer.
|
---|
| 144 | */
|
---|
| 145 |
|
---|
| 146 | class QWT_EXPORT QwtLinearScaleEngine: public QwtScaleEngine
|
---|
| 147 | {
|
---|
| 148 | public:
|
---|
| 149 | virtual void autoScale( int maxSteps,
|
---|
| 150 | double &x1, double &x2, double &stepSize ) const;
|
---|
| 151 |
|
---|
| 152 | virtual QwtScaleDiv divideScale( double x1, double x2,
|
---|
| 153 | int numMajorSteps, int numMinorSteps,
|
---|
| 154 | double stepSize = 0.0 ) const;
|
---|
| 155 |
|
---|
| 156 | virtual QwtScaleTransformation *transformation() const;
|
---|
| 157 |
|
---|
| 158 | protected:
|
---|
| 159 | QwtInterval align( const QwtInterval&, double stepSize ) const;
|
---|
| 160 |
|
---|
| 161 | void buildTicks(
|
---|
| 162 | const QwtInterval &, double stepSize, int maxMinSteps,
|
---|
| 163 | QList<double> ticks[QwtScaleDiv::NTickTypes] ) const;
|
---|
| 164 |
|
---|
| 165 | QList<double> buildMajorTicks(
|
---|
| 166 | const QwtInterval &interval, double stepSize ) const;
|
---|
| 167 |
|
---|
| 168 | void buildMinorTicks(
|
---|
| 169 | const QList<double>& majorTicks,
|
---|
| 170 | int maxMinMark, double step,
|
---|
| 171 | QList<double> &, QList<double> & ) const;
|
---|
| 172 | };
|
---|
| 173 |
|
---|
| 174 | /*!
|
---|
| 175 | \brief A scale engine for logarithmic (base 10) scales
|
---|
| 176 |
|
---|
| 177 | The step size is measured in *decades*
|
---|
| 178 | and the major step size will be adjusted to fit the pattern
|
---|
| 179 | \f$\left\{ 1,2,3,5\right\} \cdot 10^{n}\f$, where n is a natural number
|
---|
| 180 | including zero.
|
---|
| 181 |
|
---|
| 182 | \warning the step size as well as the margins are measured in *decades*.
|
---|
| 183 | */
|
---|
| 184 |
|
---|
| 185 | class QWT_EXPORT QwtLog10ScaleEngine: public QwtScaleEngine
|
---|
| 186 | {
|
---|
| 187 | public:
|
---|
| 188 | virtual void autoScale( int maxSteps,
|
---|
| 189 | double &x1, double &x2, double &stepSize ) const;
|
---|
| 190 |
|
---|
| 191 | virtual QwtScaleDiv divideScale( double x1, double x2,
|
---|
| 192 | int numMajorSteps, int numMinorSteps,
|
---|
| 193 | double stepSize = 0.0 ) const;
|
---|
| 194 |
|
---|
| 195 | virtual QwtScaleTransformation *transformation() const;
|
---|
| 196 |
|
---|
| 197 | protected:
|
---|
| 198 | QwtInterval log10( const QwtInterval& ) const;
|
---|
| 199 | QwtInterval pow10( const QwtInterval& ) const;
|
---|
| 200 |
|
---|
| 201 | QwtInterval align( const QwtInterval&, double stepSize ) const;
|
---|
| 202 |
|
---|
| 203 | void buildTicks(
|
---|
| 204 | const QwtInterval &, double stepSize, int maxMinSteps,
|
---|
| 205 | QList<double> ticks[QwtScaleDiv::NTickTypes] ) const;
|
---|
| 206 |
|
---|
| 207 | QList<double> buildMajorTicks(
|
---|
| 208 | const QwtInterval &interval, double stepSize ) const;
|
---|
| 209 |
|
---|
| 210 | QList<double> buildMinorTicks(
|
---|
| 211 | const QList<double>& majorTicks,
|
---|
| 212 | int maxMinMark, double step ) const;
|
---|
| 213 | };
|
---|
| 214 |
|
---|
| 215 | Q_DECLARE_OPERATORS_FOR_FLAGS( QwtScaleEngine::Attributes )
|
---|
| 216 |
|
---|
| 217 | #endif
|
---|