Ignore:
Timestamp:
Nov 3, 2026, 10:53:35 AM (3 weeks ago)
Author:
stuerze
Message:

deprecated functions exchanged libs updated

File:
1 edited

Legend:

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

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1313#include "qwt_clipper.h"
    1414#include "qwt_painter.h"
    15 #include <string.h>
     15#include "qwt_graphic.h"
     16#include "qwt_text.h"
    1617
    1718#include <qpainter.h>
    18 
    19 static inline bool qwtIsHSampleInside( const QwtIntervalSample &sample,
     19#include <qmath.h>
     20#include <cstring>
     21
     22static inline bool qwtIsHSampleInside( const QwtIntervalSample& sample,
    2023    double xMin, double xMax, double yMin, double yMax )
    2124{
    … …  
    3033}
    3134
    32 static inline bool qwtIsVSampleInside( const QwtIntervalSample &sample,
     35static inline bool qwtIsVSampleInside( const QwtIntervalSample& sample,
    3336    double xMin, double xMax, double yMin, double yMax )
    3437{
    … …  
    4346}
    4447
    45 class QwtPlotIntervalCurve::PrivateData
    46 {
    47 public:
    48     PrivateData():
    49         style( QwtPlotIntervalCurve::Tube ),
    50         symbol( NULL ),
    51         pen( Qt::black ),
    52         brush( Qt::white )
    53     {
    54         paintAttributes = QwtPlotIntervalCurve::ClipPolygons;
    55         paintAttributes |= QwtPlotIntervalCurve::ClipSymbol;
    56 
    57         pen.setCapStyle( Qt::FlatCap );
    58     }
    59 
    60     ~PrivateData()
    61     {
    62         delete symbol;
    63     }
    64 
    65     QwtPlotIntervalCurve::CurveStyle style;
    66     const QwtIntervalSymbol *symbol;
    67 
    68     QPen pen;
    69     QBrush brush;
    70 
    71     QwtPlotIntervalCurve::PaintAttributes paintAttributes;
    72 };
    73 
    74 /*!
    75   Constructor
    76   \param title Title of the curve
    77 */
    78 QwtPlotIntervalCurve::QwtPlotIntervalCurve( const QwtText &title ):
    79     QwtPlotSeriesItem( title )
    80 {
    81     init();
    82 }
    83 
    84 /*!
    85   Constructor
    86   \param title Title of the curve
    87 */
    88 QwtPlotIntervalCurve::QwtPlotIntervalCurve( const QString &title ):
    89     QwtPlotSeriesItem( QwtText( title ) )
    90 {
    91     init();
    92 }
    93 
    94 //! Destructor
    95 QwtPlotIntervalCurve::~QwtPlotIntervalCurve()
    96 {
    97     delete d_data;
    98 }
    99 
    100 //! Initialize internal members
    101 void QwtPlotIntervalCurve::init()
    102 {
    103     setItemAttribute( QwtPlotItem::Legend, true );
    104     setItemAttribute( QwtPlotItem::AutoScale, true );
    105 
    106     d_data = new PrivateData;
    107     setData( new QwtIntervalSeriesData() );
    108 
    109     setZ( 19.0 );
    110 }
    111 
    112 //! \return QwtPlotItem::Rtti_PlotIntervalCurve
    113 int QwtPlotIntervalCurve::rtti() const
    114 {
    115     return QwtPlotIntervalCurve::Rtti_PlotIntervalCurve;
    116 }
    117 
    118 /*!
    119   Specify an attribute how to draw the curve
    120 
    121   \param attribute Paint attribute
    122   \param on On/Off
    123   \sa testPaintAttribute()
    124 */
    125 void QwtPlotIntervalCurve::setPaintAttribute(
    126     PaintAttribute attribute, bool on )
    127 {
    128     if ( on )
    129         d_data->paintAttributes |= attribute;
     48static inline int qwtInterpolated( int from, int to, double ratio )
     49{
     50    return qRound( from + ratio * ( to - from ) );
     51}
     52
     53static int qwtStartIndex( int from, double min, double max,
     54    const QwtSeriesData< QwtIntervalSample >* samples )
     55{
     56    /*
     57        As we know, that the value coordinates are montonically
     58        increasing/decreasing we can find the first sample before
     59        entering the interval using a binary search algo.
     60     */
     61
     62    struct lessThan
     63    {
     64        inline bool operator()( const double value,
     65            const QwtIntervalSample& sample ) const
     66        {
     67            return value < sample.value;
     68        }
     69    };
     70
     71    struct greaterThan
     72    {
     73        inline bool operator()( const double value,
     74            const QwtIntervalSample& sample ) const
     75        {
     76            return value > sample.value;
     77        }
     78    };
     79
     80    int idx;
     81
     82    if ( samples->firstSample().value < samples->lastSample().value )
     83    {
     84        idx = qwtUpperSampleIndex< QwtIntervalSample >(
     85            *samples, min, lessThan() );
     86    }
    13087    else
    131         d_data->paintAttributes &= ~attribute;
    132 }
    133 
    134 /*!
    135     \return True, when attribute is enabled
    136     \sa PaintAttribute, setPaintAttribute()
    137 */
    138 bool QwtPlotIntervalCurve::testPaintAttribute(
    139     PaintAttribute attribute ) const
    140 {
    141     return ( d_data->paintAttributes & attribute );
    142 }
    143 
    144 /*!
    145   Initialize data with an array of samples.
    146   \param samples Vector of samples
    147 */
    148 void QwtPlotIntervalCurve::setSamples(
    149     const QVector<QwtIntervalSample> &samples )
    150 {
    151     setData( new QwtIntervalSeriesData( samples ) );
    152 }
    153 
    154 /*!
    155   Assign a series of samples
    156 
    157   setSamples() is just a wrapper for setData() without any additional
    158   value - beside that it is easier to find for the developer.
    159 
    160   \param data Data
    161   \warning The item takes ownership of the data object, deleting
    162            it when its not used anymore.
    163 */
    164 void QwtPlotIntervalCurve::setSamples(
    165     QwtSeriesData<QwtIntervalSample> *data )
    166 {
    167     setData( data );
    168 }
    169 
    170 /*!
    171   Set the curve's drawing style
    172 
    173   \param style Curve style
    174   \sa CurveStyle, style()
    175 */
    176 void QwtPlotIntervalCurve::setStyle( CurveStyle style )
    177 {
    178     if ( style != d_data->style )
    179     {
    180         d_data->style = style;
    181 
    182         legendChanged();
    183         itemChanged();
    184     }
    185 }
    186 
    187 /*!
    188     \return Style of the curve
    189     \sa setStyle()
    190 */
    191 QwtPlotIntervalCurve::CurveStyle QwtPlotIntervalCurve::style() const
    192 {
    193     return d_data->style;
    194 }
    195 
    196 /*!
    197   Assign a symbol.
    198 
    199   \param symbol Symbol
    200   \sa symbol()
    201 */
    202 void QwtPlotIntervalCurve::setSymbol( const QwtIntervalSymbol *symbol )
    203 {
    204     if ( symbol != d_data->symbol )
    205     {
    206         delete d_data->symbol;
    207         d_data->symbol = symbol;
    208 
    209         legendChanged();
    210         itemChanged();
    211     }
    212 }
    213 
    214 /*!
    215   \return Current symbol or NULL, when no symbol has been assigned
    216   \sa setSymbol()
    217 */
    218 const QwtIntervalSymbol *QwtPlotIntervalCurve::symbol() const
    219 {
    220     return d_data->symbol;
    221 }
    222 
    223 /*!
    224   Build and assign a pen
    225 
    226   In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it
    227   non cosmetic ( see QPen::isCosmetic() ). This method has been introduced
    228   to hide this incompatibility.
    229 
    230   \param color Pen color
    231   \param width Pen width
    232   \param style Pen style
    233 
    234   \sa pen(), brush()
    235  */
    236 void QwtPlotIntervalCurve::setPen( const QColor &color, qreal width, Qt::PenStyle style )
    237 {
    238     setPen( QPen( color, width, style ) );
    239 }
    240 
    241 /*!
    242   \brief Assign a pen
    243   \param pen New pen
    244   \sa pen(), brush()
    245 */
    246 void QwtPlotIntervalCurve::setPen( const QPen &pen )
    247 {
    248     if ( pen != d_data->pen )
    249     {
    250         d_data->pen = pen;
    251 
    252         legendChanged();
    253         itemChanged();
    254     }
    255 }
    256 
    257 /*!
    258     \return Pen used to draw the lines
    259     \sa setPen(), brush()
    260 */
    261 const QPen& QwtPlotIntervalCurve::pen() const
    262 {
    263     return d_data->pen;
    264 }
    265 
    266 /*!
    267   Assign a brush.
    268 
    269   The brush is used to fill the area in Tube style().
    270 
    271   \param brush Brush
    272   \sa brush(), pen(), setStyle(), CurveStyle
    273 */
    274 void QwtPlotIntervalCurve::setBrush( const QBrush &brush )
    275 {
    276     if ( brush != d_data->brush )
    277     {
    278         d_data->brush = brush;
    279 
    280         legendChanged();
    281         itemChanged();
    282     }
    283 }
    284 
    285 /*!
    286   \return Brush used to fill the area in Tube style()
    287   \sa setBrush(), setStyle(), CurveStyle
    288 */
    289 const QBrush& QwtPlotIntervalCurve::brush() const
    290 {
    291     return d_data->brush;
    292 }
    293 
    294 /*!
    295   \return Bounding rectangle of all samples.
    296   For an empty series the rectangle is invalid.
    297 */
    298 QRectF QwtPlotIntervalCurve::boundingRect() const
    299 {
    300     QRectF rect = QwtPlotSeriesItem::boundingRect();
    301     if ( orientation() == Qt::Vertical )
    302         rect.setRect( rect.y(), rect.x(), rect.height(), rect.width() );
    303 
    304     return rect;
    305 }
    306 
    307 /*!
    308   Draw a subset of the samples
    309 
    310   \param painter Painter
    311   \param xMap Maps x-values into pixel coordinates.
    312   \param yMap Maps y-values into pixel coordinates.
    313   \param canvasRect Contents rectangle of the canvas
    314   \param from Index of the first sample to be painted
    315   \param to Index of the last sample to be painted. If to < 0 the
    316          series will be painted to its last sample.
    317 
    318   \sa drawTube(), drawSymbols()
    319 */
    320 void QwtPlotIntervalCurve::drawSeries( QPainter *painter,
    321     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    322     const QRectF &canvasRect, int from, int to ) const
    323 {
    324     if ( to < 0 )
    325         to = dataSize() - 1;
    326 
    327     if ( from < 0 )
    328         from = 0;
    329 
    330     if ( from > to )
    331         return;
    332 
    333     switch ( d_data->style )
    334     {
    335         case Tube:
    336             drawTube( painter, xMap, yMap, canvasRect, from, to );
    337             break;
    338 
    339         case NoCurve:
    340         default:
    341             break;
    342     }
    343 
    344     if ( d_data->symbol &&
    345         ( d_data->symbol->style() != QwtIntervalSymbol::NoSymbol ) )
    346     {
    347         drawSymbols( painter, *d_data->symbol,
    348             xMap, yMap, canvasRect, from, to );
    349     }
    350 }
    351 
    352 /*!
    353   Draw a tube
    354 
    355   Builds 2 curves from the upper and lower limits of the intervals
    356   and draws them with the pen(). The area between the curves is
    357   filled with the brush().
    358 
    359   \param painter Painter
    360   \param xMap Maps x-values into pixel coordinates.
    361   \param yMap Maps y-values into pixel coordinates.
    362   \param canvasRect Contents rectangle of the canvas
    363   \param from Index of the first sample to be painted
    364   \param to Index of the last sample to be painted. If to < 0 the
    365          series will be painted to its last sample.
    366 
    367   \sa drawSeries(), drawSymbols()
    368 */
    369 void QwtPlotIntervalCurve::drawTube( QPainter *painter,
    370     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    371     const QRectF &canvasRect, int from, int to ) const
     88    {
     89        idx = qwtUpperSampleIndex< QwtIntervalSample >(
     90            *samples, max, greaterThan() );
     91    }
     92
     93    if ( idx >= 0 )
     94    {
     95        idx = qMax( from, idx );
     96        if ( idx > 0 )
     97        {
     98            // we need to fill the area before the first sample
     99            idx--;
     100        }
     101    }
     102
     103    return idx;
     104}
     105
     106namespace
     107{
     108    class LinesRenderer
     109    {
     110      public:
     111        LinesRenderer( Qt::Orientation,
     112            const QwtScaleMap&, const QwtScaleMap&, const QRectF& );
     113
     114        void addSamples( const QwtSeriesData< QwtIntervalSample >*, int from, int to );
     115
     116        QVector< QLine > fillLines;
     117        QVector< QLine > borderLines;
     118
     119      private:
     120        bool addSample( const QwtIntervalSample& );
     121        void flush();
     122
     123        bool append( int value, int min, int max );
     124
     125        void addFillLineAt( int value, int min, int max );
     126        void addFillLines( int value, int min, int max );
     127
     128        void addBorderLineAt( int value, int min, int max );
     129        void addBorderLine( int, int, int, int );
     130
     131        const bool m_vertical;
     132
     133        const QwtScaleMap& m_valueMap;
     134        const QwtScaleMap& m_intervalMap;
     135
     136        const bool m_inverting;
     137        bool m_pending;
     138
     139        // all ints are in paint device coordinates
     140
     141        int m_intvMin, m_intvMax;   // interval boundaries of the canvas
     142        int m_valueMin, m_valueMax; // value boundaries of the canvas
     143
     144        int m_value; // value of the last sample being processed
     145
     146        struct
     147        {
     148            inline void reset( int value )
     149            {
     150                min = max = last = value;
     151            }
     152
     153            inline void extend( int value )
     154            {
     155                if ( value < min )
     156                    min = value;
     157                else if ( value > max )
     158                    max = value;
     159
     160                last = value;
     161            }
     162
     163            int min, max, last;
     164
     165        } m_lower, m_upper;
     166    };
     167
     168    LinesRenderer::LinesRenderer( Qt::Orientation orientation,
     169            const QwtScaleMap& xMap, const QwtScaleMap& yMap, const QRectF& rect )
     170        : m_vertical( orientation == Qt::Vertical )
     171        , m_valueMap( m_vertical ? xMap : yMap )
     172        , m_intervalMap( m_vertical ? yMap : xMap )
     173        , m_inverting( m_intervalMap.isInverting() )
     174        , m_pending( false )
     175        , m_value( 0 )
     176    {
     177        QRectF r = rect;
     178        if ( !m_vertical )
     179            r.setSize( QSizeF( r.height(), r.width() ) );
     180
     181        m_intvMin = qFloor( r.top() );
     182        m_intvMax = qCeil( r.bottom() );
     183
     184        m_valueMin = qFloor( r.left() );
     185        m_valueMax = qCeil( r.right() );
     186
     187        const int steps = m_valueMax - m_valueMin + 1;
     188
     189        // one line for each pixel
     190        fillLines.reserve( steps );
     191
     192        /*
     193            for both border lines:
     194                one line ( min/max ) of the samples lying on the same pixel
     195                one line connecting the pixels
     196         */
     197        borderLines.reserve( 4 * steps );
     198    }
     199
     200    void LinesRenderer::addSamples(
     201        const QwtSeriesData< QwtIntervalSample >* samples, int from, int to )
     202    {
     203        const double v1 = m_valueMap.invTransform( m_valueMin );
     204        const double v2 = m_valueMap.invTransform( m_valueMax );
     205
     206        from = qwtStartIndex( from, qMin( v1, v2 ), qMax( v1, v2 ), samples );
     207
     208        if ( from >= 0 )
     209        {
     210            for ( int i = from; i <= to; i++ )
     211            {
     212                if ( addSample( samples->sample( i ) ) )
     213                    break;
     214            }
     215        }
     216
     217        flush();
     218    }
     219
     220    inline bool LinesRenderer::addSample( const QwtIntervalSample& sample )
     221    {
     222        const double value = qRound( m_valueMap.transform( sample.value ) );
     223
     224        const int min = qRound( m_intervalMap.transform( sample.interval.minValue() ) );
     225        const int max = qRound( m_intervalMap.transform( sample.interval.maxValue() ) );
     226
     227        return m_inverting ? append( value, max, min ) : append( value, max, min );
     228    }
     229
     230    inline bool LinesRenderer::append(
     231        const int value, const int lower, const int upper )
     232    {
     233        if ( !m_pending )
     234        {
     235            m_value = value;
     236            m_lower.reset( lower );
     237            m_upper.reset( upper );
     238
     239            m_pending = true;
     240
     241            return false;
     242        }
     243
     244        if ( value != m_value )
     245        {
     246            addFillLines( value, lower, upper );
     247            addBorderLineAt( m_value, m_lower.min, m_lower.max );
     248            addBorderLineAt( m_value, m_upper.min, m_upper.max );
     249
     250            addBorderLine( m_value, m_lower.last, value, lower );
     251            addBorderLine( m_value, m_upper.last, value, upper );
     252
     253            if ( ( value > m_value ) ? ( value > m_valueMax ) : ( value < m_valueMin ) )
     254            {
     255                m_pending = false;
     256                return true;
     257            }
     258
     259            m_value = value;
     260
     261            m_lower.reset( lower );
     262            m_upper.reset( upper );
     263        }
     264        else
     265        {
     266            m_lower.extend( lower );
     267            m_upper.extend( upper );
     268        }
     269
     270        return false;
     271    }
     272
     273    inline void LinesRenderer::flush()
     274    {
     275        if ( m_pending )
     276        {
     277            addFillLineAt( m_value, m_lower.min, m_upper.max );
     278            addBorderLineAt( m_value, m_lower.min, m_lower.max );
     279            addBorderLineAt( m_value, m_upper.min, m_upper.max );
     280        }
     281    }
     282
     283    inline void LinesRenderer::addFillLines(
     284        const int value, const int lower, const int upper )
     285    {
     286        addFillLineAt( m_value, m_lower.min, m_upper.max );
     287
     288        const double delta = value - m_value;
     289
     290        if ( value > m_value )
     291        {
     292            for ( int v = m_value + 1; v < value; v++ )
     293            {
     294                const double ratio = ( v - m_value ) / delta;
     295
     296                addFillLineAt( v,
     297                    qwtInterpolated( m_lower.last, lower, ratio ),
     298                    qwtInterpolated( m_upper.last, upper, ratio ) );
     299            }
     300        }
     301        else
     302        {
     303            for ( int v = m_value - 1; v > value; v-- )
     304            {
     305                const double ratio = ( v - m_value ) / delta;
     306
     307                addFillLineAt( v,
     308                    qwtInterpolated( m_lower.last, lower, ratio ),
     309                    qwtInterpolated( m_upper.last, upper, ratio ) );
     310            }
     311        }
     312    }
     313
     314    inline void LinesRenderer::addFillLineAt( int value, int min, int max )
     315    {
     316        if ( ( min != max ) && ( max > m_intvMin ) && ( min < m_intvMax ) )
     317        {
     318            min = qMax( min, m_intvMin );
     319            max = qMin( max, m_intvMax );
     320
     321            if( m_vertical )
     322                fillLines += QLine( value, min, value, max );
     323            else
     324                fillLines += QLine( min, value, max, value );
     325        }
     326    }
     327
     328    inline void LinesRenderer::addBorderLineAt( int value, int min, int max )
     329    {
     330        if ( min != max )
     331            addBorderLine( value, min, value, max );
     332    }
     333
     334    inline void LinesRenderer::addBorderLine( int x1, int y1, int x2, int y2 )
     335    {
     336        if( m_vertical )
     337            borderLines += QLine( x1, y1, x2, y2 );
     338        else
     339            borderLines += QLine( y1, x1, y2, x2 );
     340    }
     341}
     342
     343static void qwtDrawTubeLines(
     344    const QwtPlotIntervalCurve* curve, QPainter* painter,
     345    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     346    const QRectF& canvasRect, int from, int to)
     347{
     348    LinesRenderer renderer( curve->orientation(), xMap, yMap, canvasRect );
     349    renderer.addSamples( curve->data(), from, to );
     350
     351    if ( curve->brush().style() != Qt::NoBrush )
     352    {
     353        painter->save();
     354
     355        painter->setPen( curve->brush().color() );
     356        painter->setRenderHint( QPainter::Antialiasing, false );
     357        painter->drawLines( renderer.fillLines );
     358
     359        painter->restore();
     360    }
     361
     362    if ( curve->pen().style() != Qt::NoPen )
     363    {
     364        painter->save();
     365
     366        painter->setPen( curve->pen() );
     367        painter->drawLines( renderer.borderLines );
     368
     369        painter->restore();
     370    }
     371}
     372
     373static void qwtDrawTube(
     374    const QwtPlotIntervalCurve* curve, QPainter* painter,
     375    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     376    const QRectF& canvasRect, int from, int to )
    372377{
    373378    const bool doAlign = QwtPainter::roundingAlignment( painter );
    … …  
    377382    const size_t size = to - from + 1;
    378383    QPolygonF polygon( 2 * size );
    379     QPointF *points = polygon.data();
     384    QPointF* points = polygon.data();
    380385
    381386    for ( uint i = 0; i < size; i++ )
    382387    {
    383         QPointF &minValue = points[i];
    384         QPointF &maxValue = points[2 * size - 1 - i];
    385 
    386         const QwtIntervalSample intervalSample = sample( from + i );
    387         if ( orientation() == Qt::Vertical )
     388        QPointF& minValue = points[i];
     389        QPointF& maxValue = points[2 * size - 1 - i];
     390
     391        const QwtIntervalSample intervalSample = curve->sample( from + i );
     392        if ( curve->orientation() == Qt::Vertical )
    388393        {
    389394            double x = xMap.transform( intervalSample.value );
    390395            double y1 = yMap.transform( intervalSample.interval.minValue() );
    391396            double y2 = yMap.transform( intervalSample.interval.maxValue() );
     397
    392398            if ( doAlign )
    393399            {
    … …  
    407413            double x1 = xMap.transform( intervalSample.interval.minValue() );
    408414            double x2 = xMap.transform( intervalSample.interval.maxValue() );
     415
    409416            if ( doAlign )
    410417            {
    … …  
    421428    }
    422429
    423     if ( d_data->brush.style() != Qt::NoBrush )
     430    const bool doClip = curve->testPaintAttribute( QwtPlotIntervalCurve::ClipPolygons );
     431
     432    if ( curve->brush().style() != Qt::NoBrush )
    424433    {
    425434        painter->setPen( QPen( Qt::NoPen ) );
    426         painter->setBrush( d_data->brush );
    427 
    428         if ( d_data->paintAttributes & ClipPolygons )
     435        painter->setBrush( curve->brush() );
     436
     437        if ( doClip )
    429438        {
    430439            const qreal m = 1.0;
    431             const QPolygonF p = QwtClipper::clipPolygonF(
    432                canvasRect.adjusted( -m, -m, m, m ), polygon, true );
     440            const QPolygonF p = QwtClipper::clippedPolygonF(
     441                canvasRect.adjusted( -m, -m, m, m ), polygon, true );
    433442
    434443            QwtPainter::drawPolygon( painter, p );
    … …  
    440449    }
    441450
    442     if ( d_data->pen.style() != Qt::NoPen )
    443     {
    444         painter->setPen( d_data->pen );
     451    if ( curve->pen().style() != Qt::NoPen )
     452    {
     453        painter->setPen( curve->pen() );
    445454        painter->setBrush( Qt::NoBrush );
    446455
    447         if ( d_data->paintAttributes & ClipPolygons )
    448         {
    449             qreal pw = qMax( qreal( 1.0 ), painter->pen().widthF() );
     456        if ( doClip )
     457        {
     458            qreal pw = QwtPainter::effectivePenWidth( painter->pen() );
    450459            const QRectF clipRect = canvasRect.adjusted( -pw, -pw, pw, pw );
    451460
    452             QPolygonF p;
    453 
    454             p.resize( size );
    455             ::memcpy( p.data(), points, size * sizeof( QPointF ) );
    456             p = QwtClipper::clipPolygonF( clipRect, p );
    457             QwtPainter::drawPolyline( painter, p );
    458 
    459             p.resize( size );
    460             ::memcpy( p.data(), points + size, size * sizeof( QPointF ) );
    461             p = QwtClipper::clipPolygonF( clipRect, p );
    462             QwtPainter::drawPolyline( painter, p );
     461            QPolygonF p( size );
     462
     463            std::memcpy( p.data(), points, size * sizeof( QPointF ) );
     464            QwtPainter::drawPolyline( painter,
     465                QwtClipper::clippedPolygonF( clipRect, p ) );
     466
     467            std::memcpy( p.data(), points + size, size * sizeof( QPointF ) );
     468            QwtPainter::drawPolyline( painter,
     469                QwtClipper::clippedPolygonF( clipRect, p ) );
    463470        }
    464471        else
    … …  
    472479}
    473480
    474 /*!
    475   Draw symbols for a subset of the samples
    476 
    477   \param painter Painter
    478   \param symbol Interval symbol
    479   \param xMap x map
    480   \param yMap y map
    481   \param canvasRect Contents rectangle of the canvas
    482   \param from Index of the first sample to be painted
    483   \param to Index of the last sample to be painted
    484 
    485   \sa setSymbol(), drawSeries(), drawTube()
    486 */
     481class QwtPlotIntervalCurve::PrivateData
     482{
     483  public:
     484    PrivateData():
     485        style( QwtPlotIntervalCurve::Tube ),
     486        symbol( NULL ),
     487        pen( Qt::black ),
     488        brush( Qt::white )
     489    {
     490        paintAttributes = QwtPlotIntervalCurve::ClipPolygons;
     491        paintAttributes |= QwtPlotIntervalCurve::ClipSymbol;
     492
     493        pen.setCapStyle( Qt::FlatCap );
     494    }
     495
     496    ~PrivateData()
     497    {
     498        delete symbol;
     499    }
     500
     501    QwtPlotIntervalCurve::CurveStyle style;
     502    const QwtIntervalSymbol* symbol;
     503
     504    QPen pen;
     505    QBrush brush;
     506
     507    QwtPlotIntervalCurve::PaintAttributes paintAttributes;
     508};
     509
     510/*!
     511   Constructor
     512   \param title Title of the curve
     513 */
     514QwtPlotIntervalCurve::QwtPlotIntervalCurve( const QwtText& title )
     515    : QwtPlotSeriesItem( title )
     516{
     517    init();
     518}
     519
     520/*!
     521   Constructor
     522   \param title Title of the curve
     523 */
     524QwtPlotIntervalCurve::QwtPlotIntervalCurve( const QString& title )
     525    : QwtPlotSeriesItem( QwtText( title ) )
     526{
     527    init();
     528}
     529
     530//! Destructor
     531QwtPlotIntervalCurve::~QwtPlotIntervalCurve()
     532{
     533    delete m_data;
     534}
     535
     536//! Initialize internal members
     537void QwtPlotIntervalCurve::init()
     538{
     539    setItemAttribute( QwtPlotItem::Legend, true );
     540    setItemAttribute( QwtPlotItem::AutoScale, true );
     541
     542    m_data = new PrivateData;
     543    setData( new QwtIntervalSeriesData() );
     544
     545    setZ( 19.0 );
     546}
     547
     548//! \return QwtPlotItem::Rtti_PlotIntervalCurve
     549int QwtPlotIntervalCurve::rtti() const
     550{
     551    return QwtPlotIntervalCurve::Rtti_PlotIntervalCurve;
     552}
     553
     554/*!
     555   Specify an attribute how to draw the curve
     556
     557   \param attribute Paint attribute
     558   \param on On/Off
     559   \sa testPaintAttribute()
     560 */
     561void QwtPlotIntervalCurve::setPaintAttribute(
     562    PaintAttribute attribute, bool on )
     563{
     564    if ( on )
     565        m_data->paintAttributes |= attribute;
     566    else
     567        m_data->paintAttributes &= ~attribute;
     568}
     569
     570/*!
     571    \return True, when attribute is enabled
     572    \sa PaintAttribute, setPaintAttribute()
     573 */
     574bool QwtPlotIntervalCurve::testPaintAttribute(
     575    PaintAttribute attribute ) const
     576{
     577    return ( m_data->paintAttributes & attribute );
     578}
     579
     580/*!
     581   Initialize data with an array of samples.
     582   \param samples Vector of samples
     583 */
     584void QwtPlotIntervalCurve::setSamples(
     585    const QVector< QwtIntervalSample >& samples )
     586{
     587    setData( new QwtIntervalSeriesData( samples ) );
     588}
     589
     590/*!
     591   Assign a series of samples
     592
     593   setSamples() is just a wrapper for setData() without any additional
     594   value - beside that it is easier to find for the developer.
     595
     596   \param data Data
     597   \warning The item takes ownership of the data object, deleting
     598           it when its not used anymore.
     599 */
     600void QwtPlotIntervalCurve::setSamples(
     601    QwtSeriesData< QwtIntervalSample >* data )
     602{
     603    setData( data );
     604}
     605
     606/*!
     607   Set the curve's drawing style
     608
     609   \param style Curve style
     610   \sa CurveStyle, style()
     611 */
     612void QwtPlotIntervalCurve::setStyle( CurveStyle style )
     613{
     614    if ( style != m_data->style )
     615    {
     616        m_data->style = style;
     617
     618        legendChanged();
     619        itemChanged();
     620    }
     621}
     622
     623/*!
     624    \return Style of the curve
     625    \sa setStyle()
     626 */
     627QwtPlotIntervalCurve::CurveStyle QwtPlotIntervalCurve::style() const
     628{
     629    return m_data->style;
     630}
     631
     632/*!
     633   Assign a symbol.
     634
     635   \param symbol Symbol
     636   \sa symbol()
     637 */
     638void QwtPlotIntervalCurve::setSymbol( const QwtIntervalSymbol* symbol )
     639{
     640    if ( symbol != m_data->symbol )
     641    {
     642        delete m_data->symbol;
     643        m_data->symbol = symbol;
     644
     645        legendChanged();
     646        itemChanged();
     647    }
     648}
     649
     650/*!
     651   \return Current symbol or NULL, when no symbol has been assigned
     652   \sa setSymbol()
     653 */
     654const QwtIntervalSymbol* QwtPlotIntervalCurve::symbol() const
     655{
     656    return m_data->symbol;
     657}
     658
     659/*!
     660   Build and assign a pen
     661
     662   In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it
     663   non cosmetic ( see QPen::isCosmetic() ). This method has been introduced
     664   to hide this incompatibility.
     665
     666   \param color Pen color
     667   \param width Pen width
     668   \param style Pen style
     669
     670   \sa pen(), brush()
     671 */
     672void QwtPlotIntervalCurve::setPen( const QColor& color, qreal width, Qt::PenStyle style )
     673{
     674    setPen( QPen( color, width, style ) );
     675}
     676
     677/*!
     678   \brief Assign a pen
     679   \param pen New pen
     680   \sa pen(), brush()
     681 */
     682void QwtPlotIntervalCurve::setPen( const QPen& pen )
     683{
     684    if ( pen != m_data->pen )
     685    {
     686        m_data->pen = pen;
     687
     688        legendChanged();
     689        itemChanged();
     690    }
     691}
     692
     693/*!
     694    \return Pen used to draw the lines
     695    \sa setPen(), brush()
     696 */
     697const QPen& QwtPlotIntervalCurve::pen() const
     698{
     699    return m_data->pen;
     700}
     701
     702/*!
     703   Assign a brush.
     704
     705   The brush is used to fill the area in Tube style().
     706
     707   \param brush Brush
     708   \sa brush(), pen(), setStyle(), CurveStyle
     709 */
     710void QwtPlotIntervalCurve::setBrush( const QBrush& brush )
     711{
     712    if ( brush != m_data->brush )
     713    {
     714        m_data->brush = brush;
     715
     716        legendChanged();
     717        itemChanged();
     718    }
     719}
     720
     721/*!
     722   \return Brush used to fill the area in Tube style()
     723   \sa setBrush(), setStyle(), CurveStyle
     724 */
     725const QBrush& QwtPlotIntervalCurve::brush() const
     726{
     727    return m_data->brush;
     728}
     729
     730/*!
     731   \return Bounding rectangle of all samples.
     732   For an empty series the rectangle is invalid.
     733 */
     734QRectF QwtPlotIntervalCurve::boundingRect() const
     735{
     736    QRectF rect = QwtPlotSeriesItem::boundingRect();
     737    if ( orientation() == Qt::Vertical )
     738        rect.setRect( rect.y(), rect.x(), rect.height(), rect.width() );
     739
     740    return rect;
     741}
     742
     743/*!
     744   Draw a subset of the samples
     745
     746   \param painter Painter
     747   \param xMap Maps x-values into pixel coordinates.
     748   \param yMap Maps y-values into pixel coordinates.
     749   \param canvasRect Contents rectangle of the canvas
     750   \param from Index of the first sample to be painted
     751   \param to Index of the last sample to be painted. If to < 0 the
     752         series will be painted to its last sample.
     753
     754   \sa drawTube(), drawSymbols()
     755 */
     756void QwtPlotIntervalCurve::drawSeries( QPainter* painter,
     757    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     758    const QRectF& canvasRect, int from, int to ) const
     759{
     760    if ( to < 0 )
     761        to = dataSize() - 1;
     762
     763    if ( from < 0 )
     764        from = 0;
     765
     766    if ( from > to )
     767        return;
     768
     769    if ( m_data->style == Tube )
     770        drawTube( painter, xMap, yMap, canvasRect, from, to );
     771
     772    if ( m_data->symbol &&
     773        ( m_data->symbol->style() != QwtIntervalSymbol::NoSymbol ) )
     774    {
     775        drawSymbols( painter, *m_data->symbol,
     776            xMap, yMap, canvasRect, from, to );
     777    }
     778}
     779
     780/*!
     781   Draw a tube
     782
     783   Builds 2 curves from the upper and lower limits of the intervals
     784   and draws them with the pen(). The area between the curves is
     785   filled with the brush().
     786
     787   \param painter Painter
     788   \param xMap Maps x-values into pixel coordinates.
     789   \param yMap Maps y-values into pixel coordinates.
     790   \param canvasRect Contents rectangle of the canvas
     791   \param from Index of the first sample to be painted
     792   \param to Index of the last sample to be painted. If to < 0 the
     793         series will be painted to its last sample.
     794
     795   \sa drawSeries(), drawSymbols()
     796 */
     797void QwtPlotIntervalCurve::drawTube(
     798    QPainter* painter, const QwtScaleMap& xMap,
     799    const QwtScaleMap& yMap, const QRectF& canvasRect, int from, int to) const
     800{
     801    if ( ( m_data->pen.style() == Qt::NoPen ) &&
     802        ( m_data->brush.style() == Qt::NoBrush ) )
     803    {
     804        return;
     805    }
     806
     807    const bool useLines = testPaintAttribute( TubeAsLines )
     808        && QwtPainter::roundingAlignment( painter );
     809
     810    if ( useLines )
     811        qwtDrawTubeLines( this, painter, xMap, yMap, canvasRect, from, to );
     812    else
     813        qwtDrawTube( this, painter, xMap, yMap, canvasRect, from, to );
     814}
     815
     816/*!
     817   Draw symbols for a subset of the samples
     818
     819   \param painter Painter
     820   \param symbol Interval symbol
     821   \param xMap x map
     822   \param yMap y map
     823   \param canvasRect Contents rectangle of the canvas
     824   \param from Index of the first sample to be painted
     825   \param to Index of the last sample to be painted
     826
     827   \sa setSymbol(), drawSeries(), drawTube()
     828 */
    487829void QwtPlotIntervalCurve::drawSymbols(
    488     QPainter *painter, const QwtIntervalSymbol &symbol,
    489     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    490     const QRectF &canvasRect, int from, int to ) const
     830    QPainter* painter, const QwtIntervalSymbol& symbol,
     831    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     832    const QRectF& canvasRect, int from, int to ) const
    491833{
    492834    painter->save();
    … …  
    505847    const double yMax = tr.bottom();
    506848
    507     const bool doClip = d_data->paintAttributes & ClipSymbol;
     849    const bool doClip = m_data->paintAttributes & ClipSymbol;
    508850
    509851    for ( int i = from; i <= to; i++ )
    … …  
    541883
    542884/*!
    543   \return Icon for the legend
    544 
    545   In case of Tube style() the icon is a plain rectangle filled with the brush().
    546   If a symbol is assigned it is scaled to size.
    547 
    548   \param index Index of the legend entry
     885   \return Icon for the legend
     886
     887   In case of Tube style() the icon is a plain rectangle filled with the brush().
     888   If a symbol is assigned it is scaled to size.
     889
     890   \param index Index of the legend entry
    549891               ( ignored as there is only one )
    550   \param size Icon size
    551 
    552   \sa QwtPlotItem::setLegendIconSize(), QwtPlotItem::legendData()
    553 */
     892   \param size Icon size
     893
     894   \sa QwtPlotItem::setLegendIconSize(), QwtPlotItem::legendData()
     895 */
    554896QwtGraphic QwtPlotIntervalCurve::legendIcon(
    555     int index, const QSizeF &size ) const
     897    int index, const QSizeF& size ) const
    556898{
    557899    Q_UNUSED( index );
    … …  
    568910        testRenderHint( QwtPlotItem::RenderAntialiased ) );
    569911
    570     if ( d_data->style == Tube )
     912    if ( m_data->style == Tube )
    571913    {
    572914        QRectF r( 0, 0, size.width(), size.height() );
    573         painter.fillRect( r, d_data->brush );
    574     }
    575 
    576     if ( d_data->symbol &&
    577         ( d_data->symbol->style() != QwtIntervalSymbol::NoSymbol ) )
    578     {
    579         QPen pen = d_data->symbol->pen();
     915        painter.fillRect( r, m_data->brush );
     916    }
     917
     918    if ( m_data->symbol &&
     919        ( m_data->symbol->style() != QwtIntervalSymbol::NoSymbol ) )
     920    {
     921        QPen pen = m_data->symbol->pen();
    580922        pen.setWidthF( pen.widthF() );
    581923        pen.setCapStyle( Qt::FlatCap );
    582924
    583925        painter.setPen( pen );
    584         painter.setBrush( d_data->symbol->brush() );
     926        painter.setBrush( m_data->symbol->brush() );
    585927
    586928        if ( orientation() == Qt::Vertical )
    … …  
    588930            const double x = 0.5 * size.width();
    589931
    590             d_data->symbol->draw( &painter, orientation(),
     932            m_data->symbol->draw( &painter, orientation(),
    591933                QPointF( x, 0 ), QPointF( x, size.height() - 1.0 ) );
    592934        }
    … …  
    595937            const double y = 0.5 * size.height();
    596938
    597             d_data->symbol->draw( &painter, orientation(),
     939            m_data->symbol->draw( &painter, orientation(),
    598940                QPointF( 0.0, y ), QPointF( size.width() - 1.0, y ) );
    599941        }
Note: See TracChangeset for help on using the changeset viewer.