Skip to content
Snippets Groups Projects
qwt_scale_map.h 3.69 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_MAP_H
    #define QWT_SCALE_MAP_H
    
    #include "qwt_global.h"
    
    Bryant's avatar
    Bryant committed
    #include "qwt_transform.h"
    #include <qrect.h>
    
    pixhawk's avatar
    pixhawk committed
    
    
    Bryant's avatar
    Bryant committed
    #ifndef QT_NO_DEBUG_STREAM
    #include <qdebug.h>
    #endif
    
    pixhawk's avatar
    pixhawk committed
    
    
    Bryant's avatar
    Bryant committed
    class QRectF;
    
    pixhawk's avatar
    pixhawk committed
    
    /*!
       \brief A scale map
    
    
    Bryant's avatar
    Bryant committed
       QwtScaleMap offers transformations from the coordinate system
       of a scale into the linear coordinate system of a paint device 
       and vice versa.
    
    pixhawk's avatar
    pixhawk committed
    */
    class QWT_EXPORT QwtScaleMap
    {
    public:
        QwtScaleMap();
    
    Bryant's avatar
    Bryant committed
        QwtScaleMap( const QwtScaleMap& );
    
    pixhawk's avatar
    pixhawk committed
    
        ~QwtScaleMap();
    
    
    Bryant's avatar
    Bryant committed
        QwtScaleMap &operator=( const QwtScaleMap & );
    
        void setTransformation( QwtTransform * );
        const QwtTransform *transformation() const;
    
    pixhawk's avatar
    pixhawk committed
    
    
    Bryant's avatar
    Bryant committed
        void setPaintInterval( double p1, double p2 );
        void setScaleInterval( double s1, double s2 );
    
    pixhawk's avatar
    pixhawk committed
    
    
    Bryant's avatar
    Bryant committed
        double transform( double s ) const;
        double invTransform( double p ) const;
    
    pixhawk's avatar
    pixhawk committed
    
    
    Bryant's avatar
    Bryant committed
        double p1() const;
        double p2() const;
    
    pixhawk's avatar
    pixhawk committed
    
    
    Bryant's avatar
    Bryant committed
        double s1() const;
        double s2() const;
    
    pixhawk's avatar
    pixhawk committed
    
    
    Bryant's avatar
    Bryant committed
        double pDist() const;
        double sDist() const;
    
    pixhawk's avatar
    pixhawk committed
    
    
    Bryant's avatar
    Bryant committed
        static QRectF transform( const QwtScaleMap &,
            const QwtScaleMap &, const QRectF & );
        static QRectF invTransform( const QwtScaleMap &,
            const QwtScaleMap &, const QRectF & );
    
    pixhawk's avatar
    pixhawk committed
    
    
    Bryant's avatar
    Bryant committed
        static QPointF transform( const QwtScaleMap &,
            const QwtScaleMap &, const QPointF & );
        static QPointF invTransform( const QwtScaleMap &,
            const QwtScaleMap &, const QPointF & );
    
    pixhawk's avatar
    pixhawk committed
    
    
    Bryant's avatar
    Bryant committed
        bool isInverting() const;
    
    pixhawk's avatar
    pixhawk committed
    
    private:
    
    Bryant's avatar
    Bryant committed
        void updateFactor();
    
    pixhawk's avatar
    pixhawk committed
    
        double d_s1, d_s2;     // scale interval boundaries
        double d_p1, d_p2;     // paint device interval boundaries
    
        double d_cnv;       // conversion factor
    
    Bryant's avatar
    Bryant committed
        double d_ts1;
    
    pixhawk's avatar
    pixhawk committed
    
    
    Bryant's avatar
    Bryant committed
        QwtTransform *d_transform;
    
    pixhawk's avatar
    pixhawk committed
    };
    
    /*!
        \return First border of the scale interval
    */
    
    inline double QwtScaleMap::s1() const
    
    pixhawk's avatar
    pixhawk committed
    {
        return d_s1;
    }
    
    /*!
        \return Second border of the scale interval
    */
    
    inline double QwtScaleMap::s2() const
    
    pixhawk's avatar
    pixhawk committed
    {
        return d_s2;
    }
    
    /*!
        \return First border of the paint interval
    */
    
    inline double QwtScaleMap::p1() const
    
    pixhawk's avatar
    pixhawk committed
    {
        return d_p1;
    }
    
    /*!
        \return Second border of the paint interval
    */
    
    inline double QwtScaleMap::p2() const
    
    pixhawk's avatar
    pixhawk committed
    {
        return d_p2;
    }
    
    
    Bryant's avatar
    Bryant committed
    /*!
        \return qwtAbs(p2() - p1())
    */
    
    pixhawk's avatar
    pixhawk committed
    inline double QwtScaleMap::pDist() const
    {
    
    Bryant's avatar
    Bryant committed
        return qAbs( d_p2 - d_p1 );
    
    pixhawk's avatar
    pixhawk committed
    }
    
    
    Bryant's avatar
    Bryant committed
    /*!
        \return qwtAbs(s2() - s1())
    */
    
    pixhawk's avatar
    pixhawk committed
    inline double QwtScaleMap::sDist() const
    {
    
    Bryant's avatar
    Bryant committed
        return qAbs( d_s2 - d_s1 );
    
    pixhawk's avatar
    pixhawk committed
    }
    
    /*!
    
      Transform a point related to the scale interval into an point
    
    pixhawk's avatar
    pixhawk committed
      related to the interval of the paint device
    
    
    Bryant's avatar
    Bryant committed
      \param s Value relative to the coordinates of the scale
      \return Transformed value
    
    pixhawk's avatar
    pixhawk committed
    
    
    Bryant's avatar
    Bryant committed
      \sa invTransform()
    */
    inline double QwtScaleMap::transform( double s ) const
    {
        if ( d_transform )
            s = d_transform->transform( s );
    
    pixhawk's avatar
    pixhawk committed
    
    
    Bryant's avatar
    Bryant committed
        return d_p1 + ( s - d_ts1 ) * d_cnv;
    
    pixhawk's avatar
    pixhawk committed
    }
    
    /*!
    
    Bryant's avatar
    Bryant committed
      Transform an paint device value into a value in the
      interval of the scale.
    
      \param p Value relative to the coordinates of the paint device
      \return Transformed value
    
      \sa transform()
    
    pixhawk's avatar
    pixhawk committed
    */
    
    Bryant's avatar
    Bryant committed
    inline double QwtScaleMap::invTransform( double p ) const
    
    pixhawk's avatar
    pixhawk committed
    {
    
    Bryant's avatar
    Bryant committed
        double s = d_ts1 + ( p - d_p1 ) / d_cnv;
        if ( d_transform )
            s = d_transform->invTransform( s );
    
    pixhawk's avatar
    pixhawk committed
    
    
    Bryant's avatar
    Bryant committed
        return s;
    }
    
    pixhawk's avatar
    pixhawk committed
    
    
    Bryant's avatar
    Bryant committed
    //! \return True, when ( p1() < p2() ) != ( s1() < s2() )
    inline bool QwtScaleMap::isInverting() const
    
    pixhawk's avatar
    pixhawk committed
    {
    
    Bryant's avatar
    Bryant committed
        return ( ( d_p1 < d_p2 ) != ( d_s1 < d_s2 ) );
    
    pixhawk's avatar
    pixhawk committed
    }
    
    
    Bryant's avatar
    Bryant committed
    #ifndef QT_NO_DEBUG_STREAM
    QWT_EXPORT QDebug operator<<( QDebug, const QwtScaleMap & );
    #endif
    
    
    pixhawk's avatar
    pixhawk committed
    #endif