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

    r4271 r8127  
    1313#include "qwt_clipper.h"
    1414#include "qwt_painter.h"
     15#include <string.h>
    1516
    1617#include <qpainter.h>
     
    2425
    2526    const bool isOffScreen = ( y < yMin ) || ( y > yMax )
    26         || ( x1 < xMin && x2 < xMin ) || ( x1 > yMax && x2 > xMax );
     27        || ( x1 < xMin && x2 < xMin ) || ( x1 > xMax && x2 > xMax );
    2728
    2829    return !isOffScreen;
     
    4647public:
    4748    PrivateData():
    48         style( Tube ),
     49        style( QwtPlotIntervalCurve::Tube ),
    4950        symbol( NULL ),
    5051        pen( Qt::black ),
     
    5354        paintAttributes = QwtPlotIntervalCurve::ClipPolygons;
    5455        paintAttributes |= QwtPlotIntervalCurve::ClipSymbol;
    55    
     56
    5657        pen.setCapStyle( Qt::FlatCap );
    5758    }
     
    6263    }
    6364
    64     CurveStyle style;
     65    QwtPlotIntervalCurve::CurveStyle style;
    6566    const QwtIntervalSymbol *symbol;
    6667
     
    7677*/
    7778QwtPlotIntervalCurve::QwtPlotIntervalCurve( const QwtText &title ):
    78     QwtPlotSeriesItem<QwtIntervalSample>( title )
     79    QwtPlotSeriesItem( title )
    7980{
    8081    init();
     
    8687*/
    8788QwtPlotIntervalCurve::QwtPlotIntervalCurve( const QString &title ):
    88     QwtPlotSeriesItem<QwtIntervalSample>( QwtText( title ) )
     89    QwtPlotSeriesItem( QwtText( title ) )
    8990{
    9091    init();
     
    104105
    105106    d_data = new PrivateData;
    106     d_series = new QwtIntervalSeriesData();
     107    setData( new QwtIntervalSeriesData() );
    107108
    108109    setZ( 19.0 );
     
    122123  \sa testPaintAttribute()
    123124*/
    124 void QwtPlotIntervalCurve::setPaintAttribute( 
     125void QwtPlotIntervalCurve::setPaintAttribute(
    125126    PaintAttribute attribute, bool on )
    126127{
     
    132133
    133134/*!
    134     \brief Return the current paint attributes
     135    \return True, when attribute is enabled
    135136    \sa PaintAttribute, setPaintAttribute()
    136137*/
    137 bool QwtPlotIntervalCurve::testPaintAttribute( 
     138bool QwtPlotIntervalCurve::testPaintAttribute(
    138139    PaintAttribute attribute ) const
    139140{
     
    148149    const QVector<QwtIntervalSample> &samples )
    149150{
    150     delete d_series;
    151     d_series = new QwtIntervalSeriesData( samples );
    152     itemChanged();
     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*/
     164void QwtPlotIntervalCurve::setSamples(
     165    QwtSeriesData<QwtIntervalSample> *data )
     166{
     167    setData( data );
    153168}
    154169
     
    164179    {
    165180        d_data->style = style;
     181
     182        legendChanged();
    166183        itemChanged();
    167184    }
     
    169186
    170187/*!
    171     \brief Return the current style
     188    \return Style of the curve
    172189    \sa setStyle()
    173190*/
     
    189206        delete d_data->symbol;
    190207        d_data->symbol = symbol;
     208
     209        legendChanged();
    191210        itemChanged();
    192211    }
     
    201220    return d_data->symbol;
    202221}
     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 */
     236void QwtPlotIntervalCurve::setPen( const QColor &color, qreal width, Qt::PenStyle style )
     237{   
     238    setPen( QPen( color, width, style ) );
     239}   
    203240
    204241/*!
     
    212249    {
    213250        d_data->pen = pen;
     251
     252        legendChanged();
    214253        itemChanged();
    215254    }
     
    217256
    218257/*!
    219     \brief Return the pen used to draw the lines
     258    \return Pen used to draw the lines
    220259    \sa setPen(), brush()
    221260*/
     
    238277    {
    239278        d_data->brush = brush;
     279
     280        legendChanged();
    240281        itemChanged();
    241282    }
     
    257298QRectF QwtPlotIntervalCurve::boundingRect() const
    258299{
    259     QRectF rect = QwtPlotSeriesItem<QwtIntervalSample>::boundingRect();
     300    QRectF rect = QwtPlotSeriesItem::boundingRect();
    260301    if ( rect.isValid() && orientation() == Qt::Vertical )
    261302        rect.setRect( rect.y(), rect.x(), rect.height(), rect.width() );
     
    270311  \param xMap Maps x-values into pixel coordinates.
    271312  \param yMap Maps y-values into pixel coordinates.
    272   \param canvasRect Contents rect of the canvas
     313  \param canvasRect Contents rectangle of the canvas
    273314  \param from Index of the first sample to be painted
    274315  \param to Index of the last sample to be painted. If to < 0 the
     
    304345        ( d_data->symbol->style() != QwtIntervalSymbol::NoSymbol ) )
    305346    {
    306         drawSymbols( painter, *d_data->symbol, 
     347        drawSymbols( painter, *d_data->symbol,
    307348            xMap, yMap, canvasRect, from, to );
    308349    }
     
    319360  \param xMap Maps x-values into pixel coordinates.
    320361  \param yMap Maps y-values into pixel coordinates.
    321   \param canvasRect Contents rect of the canvas
     362  \param canvasRect Contents rectangle of the canvas
    322363  \param from Index of the first sample to be painted
    323364  \param to Index of the last sample to be painted. If to < 0 the
     
    388429        {
    389430            const qreal m = 1.0;
    390             const QPolygonF p = QwtClipper::clipPolygonF( 
    391                 canvasRect.adjusted(-m, -m, m, m), polygon, true );
     431            const QPolygonF p = QwtClipper::clipPolygonF(
     432               canvasRect.adjusted( -m, -m, m, m ), polygon, true );
    392433
    393434            QwtPainter::drawPolygon( painter, p );
     
    406447        if ( d_data->paintAttributes & ClipPolygons )
    407448        {
    408             qreal pw = qMax( qreal( 1.0 ), painter->pen().widthF());
    409             const QRectF clipRect = canvasRect.adjusted(-pw, -pw, pw, pw);
     449            qreal pw = qMax( qreal( 1.0 ), painter->pen().widthF() );
     450            const QRectF clipRect = canvasRect.adjusted( -pw, -pw, pw, pw );
    410451
    411452            QPolygonF p;
    412453
    413454            p.resize( size );
    414             qMemCopy( p.data(), points, size * sizeof( QPointF ) );
    415             p = QwtClipper::clipPolygonF( canvasRect, p );
     455            ::memcpy( p.data(), points, size * sizeof( QPointF ) );
     456            p = QwtClipper::clipPolygonF( clipRect, p );
    416457            QwtPainter::drawPolyline( painter, p );
    417458
    418459            p.resize( size );
    419             qMemCopy( p.data(), points + size, size * sizeof( QPointF ) );
    420             p = QwtClipper::clipPolygonF( canvasRect, p );
     460            ::memcpy( p.data(), points + size, size * sizeof( QPointF ) );
     461            p = QwtClipper::clipPolygonF( clipRect, p );
    421462            QwtPainter::drawPolyline( painter, p );
    422463        }
     
    438479  \param xMap x map
    439480  \param yMap y map
    440   \param canvasRect Contents rect of the canvas
     481  \param canvasRect Contents rectangle of the canvas
    441482  \param from Index of the first sample to be painted
    442483  \param to Index of the last sample to be painted
     
    457498    painter->setBrush( symbol.brush() );
    458499
    459     const QRectF &tr = QwtScaleMap::invTransform( xMap, yMap, canvasRect);
     500    const QRectF tr = QwtScaleMap::invTransform( xMap, yMap, canvasRect );
    460501
    461502    const double xMin = tr.left();
     
    464505    const double yMax = tr.bottom();
    465506
    466     const bool doClip = d_data->paintAttributes & ClipPolygons;
     507    const bool doClip = d_data->paintAttributes & ClipSymbol;
    467508
    468509    for ( int i = from; i <= to; i++ )
     
    500541
    501542/*!
    502   In case of Tibe stale() a plain rectangle is painted without a pen filled
    503   the brush(). If a symbol is assigned it is painted cebtered into rect.
    504 
    505   \param painter Painter
    506   \param rect Bounding rectangle for the identifier
    507 */
    508 
    509 void QwtPlotIntervalCurve::drawLegendIdentifier(
    510     QPainter *painter, const QRectF &rect ) const
    511 {
    512     const double dim = qMin( rect.width(), rect.height() );
    513 
    514     QSizeF size( dim, dim );
    515 
    516     QRectF r( 0, 0, size.width(), size.height() );
    517     r.moveCenter( rect.center() );
     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
     549               ( ignored as there is only one )
     550  \param size Icon size
     551   
     552  \sa QwtPlotItem::setLegendIconSize(), QwtPlotItem::legendData()
     553*/
     554QwtGraphic QwtPlotIntervalCurve::legendIcon(
     555    int index, const QSizeF &size ) const
     556{
     557    Q_UNUSED( index );
     558
     559    if ( size.isEmpty() )
     560        return QwtGraphic();
     561
     562    QwtGraphic icon;
     563    icon.setDefaultSize( size );
     564    icon.setRenderHint( QwtGraphic::RenderPensUnscaled, true );
     565
     566    QPainter painter( &icon );
     567    painter.setRenderHint( QPainter::Antialiasing,
     568        testRenderHint( QwtPlotItem::RenderAntialiased ) );
    518569
    519570    if ( d_data->style == Tube )
    520571    {
    521         painter->fillRect( r, d_data->brush );
     572        QRectF r( 0, 0, size.width(), size.height() );
     573        painter.fillRect( r, d_data->brush );
    522574    }
    523575
     
    529581        pen.setCapStyle( Qt::FlatCap );
    530582
    531         painter->setPen( pen );
    532         painter->setBrush( d_data->symbol->brush() );
     583        painter.setPen( pen );
     584        painter.setBrush( d_data->symbol->brush() );
    533585
    534586        if ( orientation() == Qt::Vertical )
    535587        {
    536             d_data->symbol->draw( painter, orientation(),
    537                 QPointF( r.center().x(), r.top() ),
    538                 QPointF( r.center().x(), r.bottom() - 1 ) );
     588            const double x = 0.5 * size.width();
     589
     590            d_data->symbol->draw( &painter, orientation(),
     591                QPointF( x, 0 ), QPointF( x, size.height() - 1.0 ) );
    539592        }
    540593        else
    541594        {
    542             d_data->symbol->draw( painter, orientation(),
    543                 QPointF( r.left(), r.center().y() ),
    544                 QPointF( r.right() - 1, r.center().y() ) );
    545         }
    546     }
    547 }
     595            const double y = 0.5 * size.height();
     596
     597            d_data->symbol->draw( &painter, orientation(),
     598                QPointF( 0.0, y ), QPointF( size.width() - 1.0, y ) );
     599        }
     600    }
     601
     602    return icon;
     603}
Note: See TracChangeset for help on using the changeset viewer.