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_round_scale_draw.cpp

    r4271 r8127  
    1212#include "qwt_scale_div.h"
    1313#include "qwt_scale_map.h"
     14#include "qwt_math.h"
    1415#include <qpen.h>
    1516#include <qpainter.h>
     
    2122public:
    2223    PrivateData():
    23         center( 50, 50 ),
    24         radius( 50 ),
    25         startAngle( -135 * 16 ),
    26         endAngle( 135 * 16 )
     24        center( 50.0, 50.0 ),
     25        radius( 50.0 ),
     26        startAngle( -135.0 ),
     27        endAngle( 135.0 )
    2728    {
    2829    }
     
    6465  \sa moveCenter()
    6566*/
    66 void QwtRoundScaleDraw::setRadius( int radius )
     67void QwtRoundScaleDraw::setRadius( double radius )
    6768{
    6869    d_data->radius = radius;
     
    7475  Radius is the radius of the backbone without ticks and labels.
    7576
     77  \return Radius of the scale
    7678  \sa setRadius(), extent()
    7779*/
    78 int QwtRoundScaleDraw::radius() const
     80double QwtRoundScaleDraw::radius() const
    7981{
    8082    return d_data->radius;
     
    110112  <li>The angle range is limited to [-360, 360] degrees. Angles exceeding
    111113      this range will be clipped.
    112   <li>For angles more than 359 degrees above or below min(angle1, angle2),
     114  <li>For angles more or equal than 360 degrees above or below min(angle1, angle2),
    113115      scale marks will not be drawn.
    114   <li>If you need a counterclockwise scale, use QwtScaleDiv::setRange
     116  <li>If you need a counterclockwise scale, use QwtScaleDiv::setInterval()
    115117  </ul>
    116118*/
    117119void QwtRoundScaleDraw::setAngleRange( double angle1, double angle2 )
    118120{
     121#if 0
    119122    angle1 = qBound( -360.0, angle1, 360.0 );
    120123    angle2 = qBound( -360.0, angle2, 360.0 );
    121 
    122     d_data->startAngle = angle1 * 16.0;
    123     d_data->endAngle = angle2 * 16.0;
     124#endif
     125
     126    d_data->startAngle = angle1;
     127    d_data->endAngle = angle2;
    124128
    125129    if ( d_data->startAngle == d_data->endAngle )
     
    142146void QwtRoundScaleDraw::drawLabel( QPainter *painter, double value ) const
    143147{
     148    const double tval = scaleMap().transform( value );
     149    if ( ( tval >= d_data->startAngle + 360.0 )
     150        || ( tval <= d_data->startAngle - 360.0 ) )
     151    {
     152        return;
     153    }
     154
    144155    const QwtText label = tickLabel( painter->font(), value );
    145156    if ( label.isEmpty() )
    146157        return;
    147158
    148     const double tval = scaleMap().transform( value );
    149     if ( ( tval > d_data->startAngle + 359 * 16 )
    150         || ( tval < d_data->startAngle - 359 * 16 ) )
    151     {
    152         return;
    153     }
    154 
    155159    double radius = d_data->radius;
    156160    if ( hasComponent( QwtAbstractScaleDraw::Ticks ) ||
     
    164168
    165169    const QSizeF sz = label.textSize( painter->font() );
    166     const double arc = tval / 16.0 / 360.0 * 2 * M_PI;
     170    const double arc = qwtRadians( tval );
    167171
    168172    const double x = d_data->center.x() +
    169173        ( radius + sz.width() / 2.0 ) * qSin( arc );
    170174    const double y = d_data->center.y() -
    171         ( radius + sz.height() / 2.0 ) * cos( arc );
     175        ( radius + sz.height() / 2.0 ) * qCos( arc );
    172176
    173177    const QRectF r( x - sz.width() / 2, y - sz.height() / 2,
     
    196200    const double radius = d_data->radius;
    197201
    198     if ( ( tval <= d_data->startAngle + 359 * 16 )
    199         || ( tval >= d_data->startAngle - 359 * 16 ) )
    200     {
    201         const double arc = double( tval ) / 16.0 * M_PI / 180.0;
     202    if ( ( tval < d_data->startAngle + 360.0 )
     203        && ( tval > d_data->startAngle - 360.0 ) )
     204    {
     205        const double arc = qwtRadians( tval );
    202206
    203207        const double sinArc = qSin( arc );
     
    221225void QwtRoundScaleDraw::drawBackbone( QPainter *painter ) const
    222226{
    223     const double a1 = qMin( scaleMap().p1(), scaleMap().p2() ) - 90 * 16;
    224     const double a2 = qMax( scaleMap().p1(), scaleMap().p2() ) - 90 * 16;
     227    const double deg1 = scaleMap().p1();
     228    const double deg2 = scaleMap().p2();
     229
     230    const int a1 = qRound( qMin( deg1, deg2 ) - 90 );
     231    const int a2 = qRound( qMax( deg1, deg2 ) - 90 );
    225232
    226233    const double radius = d_data->radius;
     
    228235    const double y = d_data->center.y() - radius;
    229236
    230     painter->drawArc( x, y, 2 * radius, 2 * radius,
    231         -a2, a2 - a1 + 1 );          // counterclockwise
     237    painter->drawArc( QRectF( x, y, 2 * radius, 2 * radius ),
     238        -a2 * 16, ( a2 - a1 + 1 ) * 16 );          // counterclockwise
    232239}
    233240
     
    240247
    241248   \param font Font used for painting the labels
     249   \return Calculated extent
    242250
    243251   \sa setMinimumExtent(), minimumExtent()
    244    \warning The implemented algo is not too smart and
     252   \warning The implemented algorithm is not too smart and
    245253            calculates only an upper limit, that might be a
    246254            few pixels too large
     
    260268                continue;
    261269
    262             const QwtText label = tickLabel( font, value );
    263             if ( label.isEmpty() )
    264                 continue;
    265 
    266270            const double tval = scaleMap().transform( value );
    267             if ( ( tval < d_data->startAngle + 360 * 16 )
    268                 && ( tval > d_data->startAngle - 360 * 16 ) )
     271            if ( ( tval < d_data->startAngle + 360 )
     272                && ( tval > d_data->startAngle - 360 ) )
    269273            {
    270                 const double arc = tval / 16.0 / 360.0 * 2 * M_PI;
     274                const QwtText label = tickLabel( font, value );
     275                if ( label.isEmpty() )
     276                    continue;
     277
     278                const double arc = qwtRadians( tval );
    271279
    272280                const QSizeF sz = label.textSize( font );
     
    290298    if ( hasComponent( QwtAbstractScaleDraw::Backbone ) )
    291299    {
    292         const double pw = qMax( 1, penWidth() );  // penwidth can be zero
     300        const double pw = qMax( 1, penWidth() );  // pen width can be zero
    293301        d += pw;
    294302    }
Note: See TracChangeset for help on using the changeset viewer.