Skip to content
Snippets Groups Projects
qwt_scale_engine.h 6.16 KiB
Newer Older
  • Learn to ignore specific revisions
  • pixhawk's avatar
    pixhawk committed
    /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     * Qwt Widget Library
     * Copyright (C) 1997   Josef Wilgen
     * Copyright (C) 2002   Uwe Rathmann
    
    pixhawk's avatar
    pixhawk committed
     * This library is free software; you can redistribute it and/or
     * modify it under the terms of the Qwt License, Version 1.0
     *****************************************************************************/
    
    #ifndef QWT_SCALE_ENGINE_H
    #define QWT_SCALE_ENGINE_H
    
    #include "qwt_global.h"
    #include "qwt_scale_div.h"
    
    Bryant's avatar
    Bryant committed
    #include "qwt_interval.h"
    
    pixhawk's avatar
    pixhawk committed
    
    
    Bryant's avatar
    Bryant committed
    class QwtTransform;
    
    pixhawk's avatar
    pixhawk committed
    
    /*!
      \brief Arithmetic including a tolerance
    */
    class QWT_EXPORT QwtScaleArithmetic
    {
    public:
    
    Bryant's avatar
    Bryant committed
        static double ceilEps( double value, double intervalSize );
        static double floorEps( double value, double intervalSize );
    
    pixhawk's avatar
    pixhawk committed
    
    
    Bryant's avatar
    Bryant committed
        static double divideEps( double interval, double steps );
    
    pixhawk's avatar
    pixhawk committed
    
    
    Bryant's avatar
    Bryant committed
        static double divideInterval( double interval, 
            int numSteps, uint base );
    
    pixhawk's avatar
    pixhawk committed
    };
    
    /*!
      \brief Base class for scale engines.
    
    
    Bryant's avatar
    Bryant committed
      A scale engine tries to find "reasonable" ranges and step sizes
    
      for scales.
    
    pixhawk's avatar
    pixhawk committed
    
      The layout of the scale can be varied with setAttribute().
    
    
    Bryant's avatar
    Bryant committed
      Qwt offers implementations for logarithmic and linear scales. 
    
    pixhawk's avatar
    pixhawk committed
    */
    
    class QWT_EXPORT QwtScaleEngine
    {
    public:
    
    Bryant's avatar
    Bryant committed
        /*! 
           Layout attributes
           \sa setAttribute(), testAttribute(), reference(),
               lowerMargin(), upperMargin()
         */
    
        enum Attribute
        {
            //! No attributes
            NoAttribute = 0x00,
    
            //! Build a scale which includes the reference() value.
            IncludeReference = 0x01,
    
            //! Build a scale which is symmetric to the reference() value.
            Symmetric = 0x02,
    
            /*!
               The endpoints of the scale are supposed to be equal the
               outmost included values plus the specified margins 
               (see setMargins()).
               If this attribute is *not* set, the endpoints of the scale will
               be integer multiples of the step size.
             */
            Floating = 0x04,
    
            //! Turn the scale upside down.
            Inverted = 0x08
    
    pixhawk's avatar
    pixhawk committed
        };
    
    
    Bryant's avatar
    Bryant committed
        //! Layout attributes
        typedef QFlags<Attribute> Attributes;
    
        explicit QwtScaleEngine( uint base = 10 );
    
    pixhawk's avatar
    pixhawk committed
        virtual ~QwtScaleEngine();
    
    
    Bryant's avatar
    Bryant committed
        void setBase( uint base );
        uint base() const;
    
        void setAttribute( Attribute, bool on = true );
        bool testAttribute( Attribute ) const;
    
    pixhawk's avatar
    pixhawk committed
    
    
    Bryant's avatar
    Bryant committed
        void setAttributes( Attributes );
        Attributes attributes() const;
    
    pixhawk's avatar
    pixhawk committed
    
    
    Bryant's avatar
    Bryant committed
        void setReference( double reference );
    
    pixhawk's avatar
    pixhawk committed
        double reference() const;
    
    
    Bryant's avatar
    Bryant committed
        void setMargins( double lower, double upper );
        double lowerMargin() const;
        double upperMargin() const;
    
    pixhawk's avatar
    pixhawk committed
    
        /*!
    
          Align and divide an interval
    
    pixhawk's avatar
    pixhawk committed
    
          \param maxNumSteps Max. number of steps
          \param x1 First limit of the interval (In/Out)
          \param x2 Second limit of the interval (In/Out)
          \param stepSize Step size (Return value)
    
    Bryant's avatar
    Bryant committed
        virtual void autoScale( int maxNumSteps,
            double &x1, double &x2, double &stepSize ) const = 0;
    
    pixhawk's avatar
    pixhawk committed
    
        /*!
          \brief Calculate a scale division
    
          \param x1 First interval limit
          \param x2 Second interval limit
    
    Bryant's avatar
    Bryant committed
          \param maxMajorSteps Maximum for the number of major steps
          \param maxMinorSteps Maximum number of minor steps
    
    pixhawk's avatar
    pixhawk committed
          \param stepSize Step size. If stepSize == 0.0, the scaleEngine
                       calculates one.
    
    Bryant's avatar
    Bryant committed
    
          \return Calculated scale division
    
    pixhawk's avatar
    pixhawk committed
        */
    
    Bryant's avatar
    Bryant committed
        virtual QwtScaleDiv divideScale( double x1, double x2,
            int maxMajorSteps, int maxMinorSteps,
            double stepSize = 0.0 ) const = 0;
    
    pixhawk's avatar
    pixhawk committed
    
    
    Bryant's avatar
    Bryant committed
        void setTransformation( QwtTransform * );
        QwtTransform *transformation() const;
    
    pixhawk's avatar
    pixhawk committed
    
    protected:
    
    Bryant's avatar
    Bryant committed
        bool contains( const QwtInterval &, double val ) const;
        QList<double> strip( const QList<double>&, const QwtInterval & ) const;
    
        double divideInterval( double interval, int numSteps ) const;
    
    pixhawk's avatar
    pixhawk committed
    
    
    Bryant's avatar
    Bryant committed
        QwtInterval buildInterval( double v ) const;
    
    pixhawk's avatar
    pixhawk committed
    
    private:
        class PrivateData;
        PrivateData *d_data;
    };
    
    /*!
      \brief A scale engine for linear scales
    
    
      The step size will fit into the pattern
    
    pixhawk's avatar
    pixhawk committed
      \f$\left\{ 1,2,5\right\} \cdot 10^{n}\f$, where n is an integer.
    */
    
    class QWT_EXPORT QwtLinearScaleEngine: public QwtScaleEngine
    {
    public:
    
    Bryant's avatar
    Bryant committed
        QwtLinearScaleEngine( uint base = 10 );
        virtual ~QwtLinearScaleEngine();
    
    pixhawk's avatar
    pixhawk committed
    
    
    Bryant's avatar
    Bryant committed
        virtual void autoScale( int maxSteps,
            double &x1, double &x2, double &stepSize ) const;
    
        virtual QwtScaleDiv divideScale( double x1, double x2,
            int numMajorSteps, int numMinorSteps,
                                         double stepSize = 0.0 ) const;
    
    pixhawk's avatar
    pixhawk committed
    
    
    protected:
    
    Bryant's avatar
    Bryant committed
        QwtInterval align( const QwtInterval&, double stepSize ) const;
    
    pixhawk's avatar
    pixhawk committed
    
        void buildTicks(
    
    Bryant's avatar
    Bryant committed
            const QwtInterval &, double stepSize, int maxMinSteps,
            QList<double> ticks[QwtScaleDiv::NTickTypes] ) const;
    
    pixhawk's avatar
    pixhawk committed
    
    
    Bryant's avatar
    Bryant committed
        QList<double> buildMajorTicks(
            const QwtInterval &interval, double stepSize ) const;
    
    pixhawk's avatar
    pixhawk committed
    
    
    Bryant's avatar
    Bryant committed
        void buildMinorTicks( const QList<double>& majorTicks,
            int maxMinorSteps, double stepSize,
            QList<double> &minorTicks, QList<double> &mediumTicks ) const;
    
    pixhawk's avatar
    pixhawk committed
    };
    
    /*!
    
    Bryant's avatar
    Bryant committed
      \brief A scale engine for logarithmic scales
    
    pixhawk's avatar
    pixhawk committed
    
      The step size is measured in *decades*
      and the major step size will be adjusted to fit the pattern
      \f$\left\{ 1,2,3,5\right\} \cdot 10^{n}\f$, where n is a natural number
      including zero.
    
      \warning the step size as well as the margins are measured in *decades*.
    */
    
    
    Bryant's avatar
    Bryant committed
    class QWT_EXPORT QwtLogScaleEngine: public QwtScaleEngine
    
    pixhawk's avatar
    pixhawk committed
    {
    public:
    
    Bryant's avatar
    Bryant committed
        QwtLogScaleEngine( uint base = 10 );
        virtual ~QwtLogScaleEngine();
    
    pixhawk's avatar
    pixhawk committed
    
    
    Bryant's avatar
    Bryant committed
        virtual void autoScale( int maxSteps,
            double &x1, double &x2, double &stepSize ) const;
    
    pixhawk's avatar
    pixhawk committed
    
    
    Bryant's avatar
    Bryant committed
        virtual QwtScaleDiv divideScale( double x1, double x2,
            int numMajorSteps, int numMinorSteps,
            double stepSize = 0.0 ) const;
    
    pixhawk's avatar
    pixhawk committed
    
    protected:
    
    Bryant's avatar
    Bryant committed
        QwtInterval align( const QwtInterval&, double stepSize ) const;
    
    pixhawk's avatar
    pixhawk committed
    
        void buildTicks(
    
    Bryant's avatar
    Bryant committed
            const QwtInterval &, double stepSize, int maxMinSteps,
            QList<double> ticks[QwtScaleDiv::NTickTypes] ) const;
    
    pixhawk's avatar
    pixhawk committed
    
    
    Bryant's avatar
    Bryant committed
        QList<double> buildMajorTicks(
            const QwtInterval &interval, double stepSize ) const;
    
    pixhawk's avatar
    pixhawk committed
    
    
    Bryant's avatar
    Bryant committed
        void buildMinorTicks( const QList<double>& majorTicks,
            int maxMinorSteps, double stepSize,
            QList<double> &minorTicks, QList<double> &mediumTicks ) const;
    
    pixhawk's avatar
    pixhawk committed
    };
    
    
    Bryant's avatar
    Bryant committed
    Q_DECLARE_OPERATORS_FOR_FLAGS( QwtScaleEngine::Attributes )
    
    
    pixhawk's avatar
    pixhawk committed
    #endif