Changeset 8127 in ntrip for trunk/BNC/qwt/qwt_scale_draw.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_draw.cpp

    r4271 r8127  
    1717#include <qmath.h>
    1818
     19#if QT_VERSION < 0x040601
     20#define qFastSin(x) qSin(x)
     21#define qFastCos(x) qCos(x)
     22#endif
     23
    1924class QwtScaleDraw::PrivateData
    2025{
     
    5964   Return alignment of the scale
    6065   \sa setAlignment()
     66   \return Alignment of the scale
    6167*/
    6268QwtScaleDraw::Alignment QwtScaleDraw::alignment() const
     
    6773/*!
    6874   Set the alignment of the scale
     75
     76   \param align Alignment of the scale
    6977
    7078   The default alignment is QwtScaleDraw::BottomScale
     
    8189  TopScale, BottomScale are horizontal (Qt::Horizontal) scales,
    8290  LeftScale, RightScale are vertical (Qt::Vertical) scales.
     91
     92  \return Orientation of the scale
    8393
    8494  \sa alignment()
     
    108118  \param end End border distance
    109119*/
    110 void QwtScaleDraw::getBorderDistHint( const QFont &font,
    111                                       int &start, int &end ) const
     120void QwtScaleDraw::getBorderDistHint(
     121    const QFont &font, int &start, int &end ) const
    112122{
    113123    start = 0;
    114     end = 0;
     124    end = 1.0;
    115125
    116126    if ( !hasComponent( QwtAbstractScaleDraw::Labels ) )
     
    189199
    190200    const QList<double> &ticks = scaleDiv().ticks( QwtScaleDiv::MajorTick );
    191     if ( ticks.count() == 0 )
     201    if ( ticks.isEmpty() )
    192202        return 0;
    193203
     
    200210    if ( vertical )
    201211    {
    202         bRect2.setRect( -bRect2.bottom(), 0, bRect2.height(), bRect2.width() );
    203     }
    204     int maxDist = 0;
     212        bRect2.setRect( -bRect2.bottom(), 0.0, bRect2.height(), bRect2.width() );
     213    }
     214
     215    double maxDist = 0.0;
    205216
    206217    for ( int i = 1; i < ticks.count(); i++ )
     
    210221        if ( vertical )
    211222        {
    212             bRect2.setRect( -bRect2.bottom(), 0,
     223            bRect2.setRect( -bRect2.bottom(), 0.0,
    213224                bRect2.height(), bRect2.width() );
    214225        }
    215226
    216         int dist = fm.leading(); // space between the labels
     227        double dist = fm.leading(); // space between the labels
    217228        if ( bRect1.right() > 0 )
    218229            dist += bRect1.right();
     
    224235    }
    225236
    226     double angle = labelRotation() / 180.0 * M_PI;
     237    double angle = qwtRadians( labelRotation() );
    227238    if ( vertical )
    228239        angle += M_PI / 2;
    229240
    230     if ( qSin( angle ) == 0.0 )
    231         return maxDist;
     241    const double sinA = qFastSin( angle ); // qreal -> double
     242    if ( qFuzzyCompare( sinA + 1.0, 1.0 ) )
     243        return qCeil( maxDist );
    232244
    233245    const int fmHeight = fm.ascent() - 2;
     
    235247    // The distance we need until there is
    236248    // the height of the label font. This height is needed
    237     // for the neighbour labal.
    238 
    239     int labelDist = qFloor( fmHeight / qSin( angle ) * qCos( angle ) );
     249    // for the neighbored label.
     250
     251    double labelDist = fmHeight / qFastSin( angle ) * qFastCos( angle );
    240252    if ( labelDist < 0 )
    241253        labelDist = -labelDist;
    242254
    243     // The cast above floored labelDist. We want to ceil.
    244     labelDist++;
    245 
    246255    // For text orientations close to the scale orientation
    247256
     
    255264        labelDist = fmHeight;
    256265
    257     return labelDist;
     266    return qCeil( labelDist );
    258267}
    259268
     
    267276
    268277   \param font Font used for painting the labels
     278   \return Extent
    269279
    270280   \sa minLength()
     
    292302    if ( hasComponent( QwtAbstractScaleDraw::Backbone ) )
    293303    {
    294         const double pw = qMax( 1, penWidth() );  // penwidth can be zero
     304        const double pw = qMax( 1, penWidth() );  // pen width can be zero
    295305        d += pw;
    296306    }
     
    304314
    305315   \param font Font used for painting the labels
     316   \return Minimum length that is needed to draw the scale
    306317
    307318   \sa extent()
     
    337348   Find the position, where to paint a label
    338349
    339    The position has a distance of majTickLength() + spacing() + 1
    340    from the backbone. The direction depends on the alignment()
     350   The position has a distance that depends on the length of the ticks
     351   in direction of the alignment().
    341352
    342353   \param value Value
     354   \return Position, where to paint a label
    343355*/
    344356QPointF QwtScaleDraw::labelPosition( double value ) const
     
    391403   \param painter Painter
    392404   \param value Value of the tick
    393    \param len Lenght of the tick
     405   \param len Length of the tick
    394406
    395407   \sa drawBackbone(), drawLabel()
     
    597609  overlapping labels.
    598610
     611  \param length Length of the backbone
     612
    599613  \sa move(), minLabelDist()
    600614*/
    601615void QwtScaleDraw::setLength( double length )
    602616{
     617#if 1
    603618    if ( length >= 0 && length < 10 )
    604619        length = 10;
     620
     621    // why should we accept negative lengths ???
    605622    if ( length < 0 && length > -10 )
    606623        length = -10;
     624#else
     625    length = qMax( length, 10 );
     626#endif
    607627
    608628    d_data->len = length;
     
    648668
    649669/*!
    650   Find the bounding rect for the label. The coordinates of
    651   the rect are absolute coordinates ( calculated from pos() ).
     670  \brief Find the bounding rectangle for the label.
     671
     672  The coordinates of the rectangle are absolute ( calculated from pos() ).
    652673  in direction of the tick.
    653674
     
    655676  \param value Value
    656677
     678  \return Bounding rectangle
    657679  \sa labelRect()
    658680*/
     
    677699   \param size Size of the label
    678700
     701   \return Transformation matrix
    679702   \sa setLabelAlignment(), setLabelRotation()
    680703*/
     
    740763
    741764/*!
    742   Find the bounding rect for the label. The coordinates of
    743   the rect are relative to spacing + ticklength from the backbone
     765  Find the bounding rectangle for the label. The coordinates of
     766  the rectangle are relative to spacing + tick length from the backbone
    744767  in direction of the tick.
    745768
    746769  \param font Font used for painting
    747770  \param value Value
     771
     772   \return Bounding rectangle that is needed to draw a label
    748773*/
    749774QRectF QwtScaleDraw::labelRect( const QFont &font, double value ) const
     
    769794   \param font Label font
    770795   \param value Value
     796
     797   \return Size that is needed to draw a label
    771798*/
    772799QSizeF QwtScaleDraw::labelSize( const QFont &font, double value ) const
     
    805832  \brief Change the label flags
    806833
    807   Labels are aligned to the point ticklength + spacing away from the backbone.
     834  Labels are aligned to the point tick length + spacing away from the backbone.
    808835
    809836  The alignment is relative to the orientation of the label text.
     
    824851           The alignment of the label is not the alignment
    825852           of the scale and is not the alignment of the flags
    826            (QwtText::flags()) returned from QwtAbstractScaleDraw::label().
     853           ( QwtText::flags() ) returned from QwtAbstractScaleDraw::label().
    827854*/
    828855
     
    847874int QwtScaleDraw::maxLabelWidth( const QFont &font ) const
    848875{
    849     int maxWidth = 0;
     876    double maxWidth = 0.0;
    850877
    851878    const QList<double> &ticks = scaleDiv().ticks( QwtScaleDiv::MajorTick );
     
    855882        if ( scaleDiv().contains( v ) )
    856883        {
    857             const int w = labelSize( font, ticks[i] ).width();
     884            const double w = labelSize( font, ticks[i] ).width();
    858885            if ( w > maxWidth )
    859886                maxWidth = w;
     
    861888    }
    862889
    863     return maxWidth;
     890    return qCeil( maxWidth );
    864891}
    865892
     
    870897int QwtScaleDraw::maxLabelHeight( const QFont &font ) const
    871898{
    872     int maxHeight = 0;
     899    double maxHeight = 0.0;
    873900
    874901    const QList<double> &ticks = scaleDiv().ticks( QwtScaleDiv::MajorTick );
     
    878905        if ( scaleDiv().contains( v ) )
    879906        {
    880             const int h = labelSize( font, ticks[i] ).height();
     907            const double h = labelSize( font, ticks[i] ).height();
    881908            if ( h > maxHeight )
    882909                maxHeight = h;
     
    884911    }
    885912
    886     return maxHeight;
     913    return qCeil( maxHeight );
    887914}
    888915
Note: See TracChangeset for help on using the changeset viewer.