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

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1010#include "qwt_plot_shapeitem.h"
    1111#include "qwt_scale_map.h"
     12#include "qwt_text.h"
     13#include "qwt_graphic.h"
    1214#include "qwt_painter.h"
    13 #include "qwt_curve_fitter.h"
     15#include "qwt_weeding_curve_fitter.h"
    1416#include "qwt_clipper.h"
    15 
    16 static QPainterPath qwtTransformPath( const QwtScaleMap &xMap,
    17         const QwtScaleMap &yMap, const QPainterPath &path, bool doAlign )
     17#include "qwt_math.h"
     18
     19#include <qpainter.h>
     20#include <qpainterpath.h>
     21
     22static QPainterPath qwtTransformPath( const QwtScaleMap& xMap,
     23    const QwtScaleMap& yMap, const QPainterPath& path, bool doAlign )
    1824{
    1925    QPainterPath shape;
    … …  
    2228    for ( int i = 0; i < path.elementCount(); i++ )
    2329    {
    24         const QPainterPath::Element &element = path.elementAt( i );
     30        const QPainterPath::Element element = path.elementAt( i );
    2531
    2632        double x = xMap.transform( element.x );
    … …  
    5359            case QPainterPath::CurveToElement:
    5460            {
    55                 const QPainterPath::Element& element1 = path.elementAt( ++i );
     61                const QPainterPath::Element element1 = path.elementAt( ++i );
    5662                const double x1 = xMap.transform( element1.x );
    5763                const double y1 = yMap.transform( element1.y );
    5864
    59                 const QPainterPath::Element& element2 = path.elementAt( ++i );
     65                const QPainterPath::Element element2 = path.elementAt( ++i );
    6066                const double x2 = xMap.transform( element2.x );
    6167                const double y2 = yMap.transform( element2.y );
    … …  
    7783class QwtPlotShapeItem::PrivateData
    7884{
    79 public:
    80     PrivateData():
    81         legendMode( QwtPlotShapeItem::LegendColor ),
    82         renderTolerance( 0.0 )
     85  public:
     86    PrivateData()
     87        : legendMode( QwtPlotShapeItem::LegendColor )
     88        , renderTolerance( 0.0 )
    8389    {
    8490    }
    … …  
    103109
    104110   \param title Title
    105 */
    106 QwtPlotShapeItem::QwtPlotShapeItem( const QString& title ):
    107     QwtPlotItem( QwtText( title ) )
     111 */
     112QwtPlotShapeItem::QwtPlotShapeItem( const QString& title )
     113    : QwtPlotItem( QwtText( title ) )
    108114{
    109115    init();
    … …  
    118124
    119125   \param title Title
    120 */
    121 QwtPlotShapeItem::QwtPlotShapeItem( const QwtText& title ):
    122     QwtPlotItem( title )
     126 */
     127QwtPlotShapeItem::QwtPlotShapeItem( const QwtText& title )
     128    : QwtPlotItem( title )
    123129{
    124130    init();
    … …  
    128134QwtPlotShapeItem::~QwtPlotShapeItem()
    129135{
    130     delete d_data;
     136    delete m_data;
    131137}
    132138
    133139void QwtPlotShapeItem::init()
    134140{
    135     d_data = new PrivateData();
    136     d_data->boundingRect = QwtPlotItem::boundingRect();
     141    m_data = new PrivateData();
     142    m_data->boundingRect = QwtPlotItem::boundingRect();
    137143
    138144    setItemAttribute( QwtPlotItem::AutoScale, true );
    … …  
    149155
    150156/*!
    151   Specify an attribute how to draw the shape
    152 
    153   \param attribute Paint attribute
    154   \param on On/Off
    155   \sa testPaintAttribute()
    156 */
     157   Specify an attribute how to draw the shape
     158
     159   \param attribute Paint attribute
     160   \param on On/Off
     161   \sa testPaintAttribute()
     162 */
    157163void QwtPlotShapeItem::setPaintAttribute( PaintAttribute attribute, bool on )
    158164{
    159165    if ( on )
    160         d_data->paintAttributes |= attribute;
     166        m_data->paintAttributes |= attribute;
    161167    else
    162         d_data->paintAttributes &= ~attribute;
    163 }
    164 
    165 /*!
    166   \return True, when attribute is enabled
    167   \sa setPaintAttribute()
    168 */
     168        m_data->paintAttributes &= ~attribute;
     169}
     170
     171/*!
     172   \return True, when attribute is enabled
     173   \sa setPaintAttribute()
     174 */
    169175bool QwtPlotShapeItem::testPaintAttribute( PaintAttribute attribute ) const
    170176{
    171     return ( d_data->paintAttributes & attribute );
    172 }
    173 
    174 /*!
    175   Set the mode how to represent the item on the legend
    176 
    177   \param mode Mode
    178   \sa legendMode()
     177    return ( m_data->paintAttributes & attribute );
     178}
     179
     180/*!
     181   Set the mode how to represent the item on the legend
     182
     183   \param mode Mode
     184   \sa legendMode()
    179185 */
    180186void QwtPlotShapeItem::setLegendMode( LegendMode mode )
    181187{
    182     if ( mode != d_data->legendMode )
    183     {
    184         d_data->legendMode = mode;
     188    if ( mode != m_data->legendMode )
     189    {
     190        m_data->legendMode = mode;
    185191        legendChanged();
    186192    }
    … …  
    188194
    189195/*!
    190   \return Mode how to represent the item on the legend
    191   \sa legendMode()
     196   \return Mode how to represent the item on the legend
     197   \sa legendMode()
    192198 */
    193199QwtPlotShapeItem::LegendMode QwtPlotShapeItem::legendMode() const
    194200{
    195     return d_data->legendMode;
     201    return m_data->legendMode;
    196202}
    197203
    … …  
    199205QRectF QwtPlotShapeItem::boundingRect() const
    200206{
    201     return d_data->boundingRect;
    202 }
    203 
    204 /*!
    205   \brief Set a path built from a rectangle
    206 
    207   \param rect Rectangle
    208   \sa setShape(), setPolygon(), shape()
    209  */
    210 void QwtPlotShapeItem::setRect( const QRectF &rect )
     207    return m_data->boundingRect;
     208}
     209
     210/*!
     211   \brief Set a path built from a rectangle
     212
     213   \param rect Rectangle
     214   \sa setShape(), setPolygon(), shape()
     215 */
     216void QwtPlotShapeItem::setRect( const QRectF& rect )
    211217{
    212218    QPainterPath path;
    … …  
    217223
    218224/*!
    219   \brief Set a path built from a polygon
    220 
    221   \param polygon Polygon
    222   \sa setShape(), setRect(), shape()
    223  */
    224 void QwtPlotShapeItem::setPolygon( const QPolygonF &polygon )
     225   \brief Set a path built from a polygon
     226
     227   \param polygon Polygon
     228   \sa setShape(), setRect(), shape()
     229 */
     230void QwtPlotShapeItem::setPolygon( const QPolygonF& polygon )
    225231{
    226232    QPainterPath shape;
    … …  
    231237
    232238/*!
    233   \brief Set the shape to be displayed
    234 
    235   \param shape Shape
    236   \sa setShape(), shape()
    237  */
    238 void QwtPlotShapeItem::setShape( const QPainterPath &shape )
    239 {
    240     if ( shape != d_data->shape )
    241     {
    242         d_data->shape = shape;
     239   \brief Set the shape to be displayed
     240
     241   \param shape Shape
     242   \sa setShape(), shape()
     243 */
     244void QwtPlotShapeItem::setShape( const QPainterPath& shape )
     245{
     246    if ( shape != m_data->shape )
     247    {
     248        m_data->shape = shape;
    243249        if ( shape.isEmpty() )
    244250        {
    245             d_data->boundingRect = QwtPlotItem::boundingRect();
     251            m_data->boundingRect = QwtPlotItem::boundingRect();
    246252        }
    247253        else
    248254        {
    249             d_data->boundingRect = shape.boundingRect();
     255            m_data->boundingRect = shape.boundingRect();
    250256        }
    251257
    … …  
    255261
    256262/*!
    257   \return Shape to be displayed
    258   \sa setShape()
     263   \return Shape to be displayed
     264   \sa setShape()
    259265 */
    260266QPainterPath QwtPlotShapeItem::shape() const
    261267{
    262     return d_data->shape;
    263 }
    264 
    265 /*!
    266   Build and assign a pen
    267 
    268   In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it
    269   non cosmetic ( see QPen::isCosmetic() ). This method has been introduced
    270   to hide this incompatibility.
    271 
    272   \param color Pen color
    273   \param width Pen width
    274   \param style Pen style
    275 
    276   \sa pen(), brush()
    277  */
    278 void QwtPlotShapeItem::setPen( const QColor &color, qreal width, Qt::PenStyle style )
     268    return m_data->shape;
     269}
     270
     271/*!
     272   Build and assign a pen
     273
     274   In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it
     275   non cosmetic ( see QPen::isCosmetic() ). This method has been introduced
     276   to hide this incompatibility.
     277
     278   \param color Pen color
     279   \param width Pen width
     280   \param style Pen style
     281
     282   \sa pen(), brush()
     283 */
     284void QwtPlotShapeItem::setPen( const QColor& color, qreal width, Qt::PenStyle style )
    279285{
    280286    setPen( QPen( color, width, style ) );
    … …  
    282288
    283289/*!
    284   \brief Assign a pen
    285 
    286   The pen is used to draw the outline of the shape
    287 
    288   \param pen Pen
    289   \sa pen(), brush()
    290 */
    291 void QwtPlotShapeItem::setPen( const QPen &pen )
    292 {
    293     if ( pen != d_data->pen )
    294     {
    295         d_data->pen = pen;
     290   \brief Assign a pen
     291
     292   The pen is used to draw the outline of the shape
     293
     294   \param pen Pen
     295   \sa pen(), brush()
     296 */
     297void QwtPlotShapeItem::setPen( const QPen& pen )
     298{
     299    if ( pen != m_data->pen )
     300    {
     301        m_data->pen = pen;
    296302        itemChanged();
    297303    }
    … …  
    301307    \return Pen used to draw the outline of the shape
    302308    \sa setPen(), brush()
    303 */
     309 */
    304310QPen QwtPlotShapeItem::pen() const
    305311{
    306     return d_data->pen;
    307 }
    308 
    309 /*!
    310   Assign a brush.
    311 
    312   The brush is used to fill the path
    313 
    314   \param brush Brush
    315   \sa brush(), pen()
    316 */
    317 void QwtPlotShapeItem::setBrush( const QBrush &brush )
    318 {
    319     if ( brush != d_data->brush )
    320     {
    321         d_data->brush = brush;
     312    return m_data->pen;
     313}
     314
     315/*!
     316   Assign a brush.
     317
     318   The brush is used to fill the path
     319
     320   \param brush Brush
     321   \sa brush(), pen()
     322 */
     323void QwtPlotShapeItem::setBrush( const QBrush& brush )
     324{
     325    if ( brush != m_data->brush )
     326    {
     327        m_data->brush = brush;
    322328        itemChanged();
    323329    }
    … …  
    325331
    326332/*!
    327   \return Brush used to fill the shape
    328   \sa setBrush(), pen()
    329 */
     333   \return Brush used to fill the shape
     334   \sa setBrush(), pen()
     335 */
    330336QBrush QwtPlotShapeItem::brush() const
    331337{
    332     return d_data->brush;
    333 }
    334 
    335 /*!
    336   \brief Set the tolerance for the weeding optimization
    337 
    338   After translating the shape into target device coordinate
    339   ( usually widget geometries ) the painter path can be simplified
    340   by a point weeding algorithm ( Douglas-Peucker ).
    341 
    342   For shapes built from curves and ellipses weeding might
    343   have the opposite effect because they have to be expanded
    344   to polygons.
    345 
    346   \param tolerance Accepted error when reducing the number of points
     338    return m_data->brush;
     339}
     340
     341/*!
     342   \brief Set the tolerance for the weeding optimization
     343
     344   After translating the shape into target device coordinate
     345   ( usually widget geometries ) the painter path can be simplified
     346   by a point weeding algorithm ( Douglas-Peucker ).
     347
     348   For shapes built from curves and ellipses weeding might
     349   have the opposite effect because they have to be expanded
     350   to polygons.
     351
     352   \param tolerance Accepted error when reducing the number of points
    347353                   A value <= 0.0 disables weeding.
    348354
    349   \sa renderTolerance(), QwtWeedingCurveFitter
     355   \sa renderTolerance(), QwtWeedingCurveFitter
    350356 */
    351357void QwtPlotShapeItem::setRenderTolerance( double tolerance )
    352358{
    353     tolerance = qMax( tolerance, 0.0 );
    354 
    355     if ( tolerance != d_data->renderTolerance )
    356     {
    357         d_data->renderTolerance = tolerance;
     359    tolerance = qwtMaxF( tolerance, 0.0 );
     360
     361    if ( tolerance != m_data->renderTolerance )
     362    {
     363        m_data->renderTolerance = tolerance;
    358364        itemChanged();
    359365    }
    … …  
    361367
    362368/*!
    363   \return Tolerance for the weeding optimization
    364   \sa setRenderTolerance()
     369   \return Tolerance for the weeding optimization
     370   \sa setRenderTolerance()
    365371 */
    366372double QwtPlotShapeItem::renderTolerance() const
    367373{
    368     return d_data->renderTolerance;
    369 }
    370 
    371 /*!
    372   Draw the shape item
    373 
    374   \param painter Painter
    375   \param xMap X-Scale Map
    376   \param yMap Y-Scale Map
    377   \param canvasRect Contents rect of the plot canvas
    378 */
    379 void QwtPlotShapeItem::draw( QPainter *painter,
    380     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    381     const QRectF &canvasRect ) const
    382 {
    383     if ( d_data->shape.isEmpty() )
     374    return m_data->renderTolerance;
     375}
     376
     377/*!
     378   Draw the shape item
     379
     380   \param painter Painter
     381   \param xMap X-Scale Map
     382   \param yMap Y-Scale Map
     383   \param canvasRect Contents rect of the plot canvas
     384 */
     385void QwtPlotShapeItem::draw( QPainter* painter,
     386    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     387    const QRectF& canvasRect ) const
     388{
     389    if ( m_data->shape.isEmpty() )
    384390        return;
    385391
    386     if ( d_data->pen.style() == Qt::NoPen
    387         && d_data->brush.style() == Qt::NoBrush )
     392    if ( m_data->pen.style() == Qt::NoPen
     393        && m_data->brush.style() == Qt::NoBrush )
    388394    {
    389395        return;
    … …  
    393399        xMap, yMap, canvasRect.toRect() );
    394400
    395     const QRectF &br = d_data->boundingRect;
     401    const QRectF& br = m_data->boundingRect;
    396402
    397403    if ( ( br.left() > cr.right() ) || ( br.right() < cr.left() )
    398404        || ( br.top() > cr.bottom() ) || ( br.bottom() < cr.top() ) )
    399405    {
    400         // outside the visisble area
     406        // outside the visible area
    401407        return;
    402408    }
    … …  
    405411
    406412    QPainterPath path = qwtTransformPath( xMap, yMap,
    407         d_data->shape, doAlign );
     413        m_data->shape, doAlign );
    408414
    409415    if ( testPaintAttribute( QwtPlotShapeItem::ClipPolygons ) )
    410416    {
    411         qreal pw = qMax( qreal( 1.0 ), painter->pen().widthF());
    412         QRectF clipRect = canvasRect.adjusted( -pw, -pw, pw, pw );
     417        const qreal pw = QwtPainter::effectivePenWidth( painter->pen() );
     418        const QRectF clipRect = canvasRect.adjusted( -pw, -pw, pw, pw );
    413419
    414420        QPainterPath clippedPath;
    415421        clippedPath.setFillRule( path.fillRule() );
    416422
    417         const QList<QPolygonF> polygons = path.toSubpathPolygons();
     423        QList< QPolygonF > polygons = path.toSubpathPolygons();
    418424        for ( int i = 0; i < polygons.size(); i++ )
    419425        {
    420             const QPolygonF p = QwtClipper::clipPolygonF(
    421                 clipRect, polygons[i], true );
    422 
    423             clippedPath.addPolygon( p );
     426            QwtClipper::clipPolygonF( clipRect, polygons[i], true );
     427            clippedPath.addPolygon( polygons[i] );
    424428
    425429        }
    … …  
    428432    }
    429433
    430     if ( d_data->renderTolerance > 0.0 )
    431     {
    432         QwtWeedingCurveFitter fitter( d_data->renderTolerance );
     434    if ( m_data->renderTolerance > 0.0 )
     435    {
     436        QwtWeedingCurveFitter fitter( m_data->renderTolerance );
    433437
    434438        QPainterPath fittedPath;
    435439        fittedPath.setFillRule( path.fillRule() );
    436440
    437         const QList<QPolygonF> polygons = path.toSubpathPolygons();
     441        const QList< QPolygonF > polygons = path.toSubpathPolygons();
    438442        for ( int i = 0; i < polygons.size(); i++ )
    439443            fittedPath.addPolygon( fitter.fitCurve( polygons[ i ] ) );
    … …  
    442446    }
    443447
    444     painter->setPen( d_data->pen );
    445     painter->setBrush( d_data->brush );
     448    painter->setPen( m_data->pen );
     449    painter->setBrush( m_data->brush );
    446450
    447451    painter->drawPath( path );
    … …  
    449453
    450454/*!
    451   \return A rectangle filled with the color of the brush ( or the pen )
    452 
    453   \param index Index of the legend entry
     455   \return A rectangle filled with the color of the brush ( or the pen )
     456
     457   \param index Index of the legend entry
    454458                ( usually there is only one )
    455   \param size Icon size
    456 
    457   \sa setLegendIconSize(), legendData()
    458 */
     459   \param size Icon size
     460
     461   \sa setLegendIconSize(), legendData()
     462 */
    459463QwtGraphic QwtPlotShapeItem::legendIcon( int index,
    460     const QSizeF &size ) const
     464    const QSizeF& size ) const
    461465{
    462466    Q_UNUSED( index );
    … …  
    468472        return icon;
    469473
    470     if ( d_data->legendMode == QwtPlotShapeItem::LegendShape )
    471     {
    472         const QRectF &br = d_data->boundingRect;
     474    if ( m_data->legendMode == QwtPlotShapeItem::LegendShape )
     475    {
     476        const QRectF& br = m_data->boundingRect;
    473477
    474478        QPainter painter( &icon );
    … …  
    478482        painter.translate( -br.topLeft() );
    479483
    480         painter.setPen( d_data->pen );
    481         painter.setBrush( d_data->brush );
    482         painter.drawPath( d_data->shape );
     484        painter.setPen( m_data->pen );
     485        painter.setBrush( m_data->brush );
     486        painter.drawPath( m_data->shape );
    483487    }
    484488    else
    485489    {
    486490        QColor iconColor;
    487         if ( d_data->brush.style() != Qt::NoBrush )
    488             iconColor = d_data->brush.color();
     491        if ( m_data->brush.style() != Qt::NoBrush )
     492            iconColor = m_data->brush.color();
    489493        else
    490             iconColor = d_data->pen.color();
     494            iconColor = m_data->pen.color();
    491495
    492496        icon = defaultIcon( iconColor, size );
Note: See TracChangeset for help on using the changeset viewer.