Changeset 8127 in ntrip for trunk/BNC/qwt/qwt_scale_map.cpp


Ignore:
Timestamp:
May 10, 2017, 3:20:54 PM (7 years ago)
Author:
stoecker
Message:

update qwt and qwtpolar, many QT5 fixes (unfinished)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/qwt/qwt_scale_map.cpp

    r4271 r8127  
    99
    1010#include "qwt_scale_map.h"
     11#include "qwt_math.h"
    1112#include <qrect.h>
    12 #include <qalgorithms.h>
    13 #include <qmath.h>
    1413#include <qdebug.h>
    15 
    16 #if QT_VERSION < 0x040601
    17 #define qExp(x) ::exp(x)
    18 #endif
    19 
    20 //! Smallest allowed value for logarithmic scales: 1.0e-150
    21 QT_STATIC_CONST_IMPL double QwtScaleMap::LogMin = 1.0e-150;
    22 
    23 //! Largest allowed value for logarithmic scales: 1.0e150
    24 QT_STATIC_CONST_IMPL double QwtScaleMap::LogMax = 1.0e150;
    25 
    26 //! Constructor for a linear transformation
    27 QwtScaleTransformation::QwtScaleTransformation( Type type ):
    28     d_type( type )
    29 {
    30 }
    31 
    32 //! Destructor
    33 QwtScaleTransformation::~QwtScaleTransformation()
    34 {
    35 }
    36 
    37 //! Create a clone of the transformation
    38 QwtScaleTransformation *QwtScaleTransformation::copy() const
    39 {
    40     return new QwtScaleTransformation( d_type );
    41 }
    42 
    43 /*!
    44   \brief Transform a value from the coordinate system of a scale
    45          into the coordinate system of the paint device
    46 
    47   \param s  Value related to the coordinate system of the scale
    48   \param s1 First border of the coordinate system of the scale
    49   \param s2 Second border of the coordinate system of the scale
    50   \param p1 First border of the coordinate system of the paint device
    51   \param p2 Second border of the coordinate system of the paint device
    52   \return
    53   <dl>
    54   <dt>linear mapping:<dd>p1 + (p2 - p1) / (s2 - s1) * (s - s1);</dd>
    55   </dl>
    56   <dl>
    57   <dt>log10 mapping: <dd>p1 + (p2 - p1) / log(s2 / s1) * log(s / s1);</dd>
    58   </dl>
    59 */
    60 
    61 double QwtScaleTransformation::xForm(
    62     double s, double s1, double s2, double p1, double p2 ) const
    63 {
    64     if ( d_type == Log10 )
    65         return p1 + ( p2 - p1 ) / log( s2 / s1 ) * log( s / s1 );
    66     else
    67         return p1 + ( p2 - p1 ) / ( s2 - s1 ) * ( s - s1 );
    68 }
    69 
    70 /*!
    71   \brief Transform a value from the coordinate system of the paint device
    72          into the coordinate system of a scale.
    73 
    74   \param p Value related to the coordinate system of the paint device
    75   \param p1 First border of the coordinate system of the paint device
    76   \param p2 Second border of the coordinate system of the paint device
    77   \param s1 First border of the coordinate system of the scale
    78   \param s2 Second border of the coordinate system of the scale
    79   \return
    80   <dl>
    81   <dt>linear mapping:<dd>s1 + ( s2 - s1 ) / ( p2 - p1 ) * ( p - p1 );</dd>
    82   </dl>
    83   <dl>
    84   <dt>log10 mapping:<dd>exp((p - p1) / (p2 - p1) * log(s2 / s1)) * s1;</dd>
    85   </dl>
    86 */
    87 
    88 double QwtScaleTransformation::invXForm( double p, double p1, double p2,
    89     double s1, double s2 ) const
    90 {
    91     if ( d_type == Log10 )
    92         return qExp( ( p - p1 ) / ( p2 - p1 ) * log( s2 / s1 ) ) * s1;
    93     else
    94         return s1 + ( s2 - s1 ) / ( p2 - p1 ) * ( p - p1 );
    95 }
    9614
    9715/*!
     
    10523    d_p1( 0.0 ),
    10624    d_p2( 1.0 ),
    107     d_cnv( 1.0 )
    108 {
    109     d_transformation = new QwtScaleTransformation(
    110         QwtScaleTransformation::Linear );
     25    d_cnv( 1.0 ),
     26    d_ts1( 0.0 ),
     27    d_transform( NULL )
     28{
    11129}
    11230
     
    11735    d_p1( other.d_p1 ),
    11836    d_p2( other.d_p2 ),
    119     d_cnv( other.d_cnv )
    120 {
    121     d_transformation = other.d_transformation->copy();
     37    d_cnv( other.d_cnv ),
     38    d_ts1( other.d_ts1 ),
     39    d_transform( NULL )
     40{
     41    if ( other.d_transform )
     42        d_transform = other.d_transform->copy();
    12243}
    12344
     
    12748QwtScaleMap::~QwtScaleMap()
    12849{
    129     delete d_transformation;
     50    delete d_transform;
    13051}
    13152
     
    13859    d_p2 = other.d_p2;
    13960    d_cnv = other.d_cnv;
    140 
    141     delete d_transformation;
    142     d_transformation = other.d_transformation->copy();
     61    d_ts1 = other.d_ts1;
     62
     63    delete d_transform;
     64    d_transform = NULL;
     65
     66    if ( other.d_transform )
     67        d_transform = other.d_transform->copy();
    14368
    14469    return *this;
     
    14873   Initialize the map with a transformation
    14974*/
    150 void QwtScaleMap::setTransformation(
    151     QwtScaleTransformation *transformation )
    152 {
    153     if ( transformation == NULL )
    154         return;
    155 
    156     if ( transformation != d_transformation )
     75void QwtScaleMap::setTransformation( QwtTransform *transform )
     76{
     77    if ( transform != d_transform )
    15778    {
    158         delete d_transformation;
    159         d_transformation = transformation;
     79        delete d_transform;
     80        d_transform = transform;
    16081    }
    16182
     
    16485
    16586//! Get the transformation
    166 const QwtScaleTransformation *QwtScaleMap::transformation() const
    167 {
    168     return d_transformation;
     87const QwtTransform *QwtScaleMap::transformation() const
     88{
     89    return d_transform;
    16990}
    17091
     
    17394  \param s1 first border
    17495  \param s2 second border
    175   \warning logarithmic scales might be aligned to [LogMin, LogMax]
     96  \warning scales might be aligned to
     97           transformation depending boundaries
    17698*/
    17799void QwtScaleMap::setScaleInterval( double s1, double s2 )
    178100{
    179     if ( d_transformation->type() == QwtScaleTransformation::Log10 )
    180     {
    181         if ( s1 < LogMin )
    182             s1 = LogMin;
    183         else if ( s1 > LogMax )
    184             s1 = LogMax;
    185 
    186         if ( s2 < LogMin )
    187             s2 = LogMin;
    188         else if ( s2 > LogMax )
    189             s2 = LogMax;
    190     }
    191 
    192101    d_s1 = s1;
    193102    d_s2 = s2;
    194103
    195     if ( d_transformation->type() != QwtScaleTransformation::Other )
    196         newFactor();
     104    if ( d_transform )
     105    {
     106        d_s1 = d_transform->bounded( d_s1 );
     107        d_s2 = d_transform->bounded( d_s2 );
     108    }
     109
     110    updateFactor();
    197111}
    198112
     
    207121    d_p2 = p2;
    208122
    209     if ( d_transformation->type() != QwtScaleTransformation::Other )
    210         newFactor();
    211 }
    212 
    213 /*!
    214   \brief Re-calculate the conversion factor.
    215 */
    216 void QwtScaleMap::newFactor()
    217 {
    218     d_cnv = 0.0;
    219 
    220     switch ( d_transformation->type() )
     123    updateFactor();
     124}
     125
     126void QwtScaleMap::updateFactor()
     127{
     128    d_ts1 = d_s1;
     129    double ts2 = d_s2;
     130
     131    if ( d_transform )
    221132    {
    222         case QwtScaleTransformation::Linear:
    223         {
    224             if ( d_s2 != d_s1 )
    225                 d_cnv = ( d_p2 - d_p1 ) / ( d_s2 - d_s1 );
    226             break;
    227         }
    228         case QwtScaleTransformation::Log10:
    229         {
    230             if ( d_s1 != 0 )
    231                 d_cnv = ( d_p2 - d_p1 ) / log( d_s2 / d_s1 );
    232             break;
    233         }
    234         default:;
     133        d_ts1 = d_transform->transform( d_ts1 );
     134        ts2 = d_transform->transform( ts2 );
    235135    }
     136
     137    d_cnv = 1.0;
     138    if ( d_ts1 != ts2 )
     139        d_cnv = ( d_p2 - d_p1 ) / ( ts2 - d_ts1 );
    236140}
    237141
     
    334238{
    335239    debug.nospace() << "QwtScaleMap("
    336         << static_cast<int>( map.transformation()->type() )
     240        << map.transformation()
    337241        << ", s:" << map.s1() << "->" << map.s2()
    338242        << ", p:" << map.p1() << "->" << map.p2()
Note: See TracChangeset for help on using the changeset viewer.