Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_plot_grid.cpp


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

    r8127 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1313#include "qwt_scale_map.h"
    1414#include "qwt_scale_div.h"
    15 #include "qwt_math.h"
     15
    1616#include <qpainter.h>
    1717#include <qpen.h>
    1818
     19static inline bool qwtFuzzyGreaterOrEqual( double d1, double d2 )
     20{
     21    return ( d1 >= d2 ) || qFuzzyCompare( d1, d2 );
     22}
     23
    1924class QwtPlotGrid::PrivateData
    2025{
    21 public:
    22     PrivateData():
    23         xEnabled( true ),
    24         yEnabled( true ),
    25         xMinEnabled( false ),
    26         yMinEnabled( false )
     26  public:
     27    PrivateData()
     28        : xEnabled( true )
     29        , yEnabled( true )
     30        , xMinEnabled( false )
     31        , yMinEnabled( false )
    2732    {
    2833    }
    … …  
    4146
    4247//! Enables major grid, disables minor grid
    43 QwtPlotGrid::QwtPlotGrid():
    44     QwtPlotItem( QwtText( "Grid" ) )
    45 {
    46     d_data = new PrivateData;
     48QwtPlotGrid::QwtPlotGrid()
     49    : QwtPlotItem( QwtText( "Grid" ) )
     50{
     51    m_data = new PrivateData;
    4752
    4853    setItemInterest( QwtPlotItem::ScaleInterest, true );
    … …  
    5358QwtPlotGrid::~QwtPlotGrid()
    5459{
    55     delete d_data;
     60    delete m_data;
    5661}
    5762
    … …  
    6368
    6469/*!
    65   \brief Enable or disable vertical grid lines
    66   \param on Enable (true) or disable
    67 
    68   \sa Minor grid lines can be enabled or disabled with
     70   \brief Enable or disable vertical grid lines
     71   \param on Enable (true) or disable
     72
     73   \sa Minor grid lines can be enabled or disabled with
    6974      enableXMin()
    70 */
     75 */
    7176void QwtPlotGrid::enableX( bool on )
    7277{
    73     if ( d_data->xEnabled != on )
    74     {
    75         d_data->xEnabled = on;
    76 
    77         legendChanged();
    78         itemChanged();
    79     }
    80 }
    81 
    82 /*!
    83   \brief Enable or disable horizontal grid lines
    84   \param on Enable (true) or disable
    85   \sa Minor grid lines can be enabled or disabled with enableYMin()
    86 */
     78    if ( m_data->xEnabled != on )
     79    {
     80        m_data->xEnabled = on;
     81
     82        legendChanged();
     83        itemChanged();
     84    }
     85}
     86
     87/*!
     88   \brief Enable or disable horizontal grid lines
     89   \param on Enable (true) or disable
     90   \sa Minor grid lines can be enabled or disabled with enableYMin()
     91 */
    8792void QwtPlotGrid::enableY( bool on )
    8893{
    89     if ( d_data->yEnabled != on )
    90     {
    91         d_data->yEnabled = on;
    92 
    93         legendChanged();
    94         itemChanged();
    95     }
    96 }
    97 
    98 /*!
    99   \brief Enable or disable  minor vertical grid lines.
    100   \param on Enable (true) or disable
    101   \sa enableX()
    102 */
     94    if ( m_data->yEnabled != on )
     95    {
     96        m_data->yEnabled = on;
     97
     98        legendChanged();
     99        itemChanged();
     100    }
     101}
     102
     103/*!
     104   \brief Enable or disable  minor vertical grid lines.
     105   \param on Enable (true) or disable
     106   \sa enableX()
     107 */
    103108void QwtPlotGrid::enableXMin( bool on )
    104109{
    105     if ( d_data->xMinEnabled != on )
    106     {
    107         d_data->xMinEnabled = on;
    108 
    109         legendChanged();
    110         itemChanged();
    111     }
    112 }
    113 
    114 /*!
    115   \brief Enable or disable minor horizontal grid lines
    116   \param on Enable (true) or disable
    117   \sa enableY()
    118 */
     110    if ( m_data->xMinEnabled != on )
     111    {
     112        m_data->xMinEnabled = on;
     113
     114        legendChanged();
     115        itemChanged();
     116    }
     117}
     118
     119/*!
     120   \brief Enable or disable minor horizontal grid lines
     121   \param on Enable (true) or disable
     122   \sa enableY()
     123 */
    119124void QwtPlotGrid::enableYMin( bool on )
    120125{
    121     if ( d_data->yMinEnabled != on )
    122     {
    123         d_data->yMinEnabled = on;
    124 
    125         legendChanged();
    126         itemChanged();
    127     }
    128 }
    129 
    130 /*!
    131   Assign an x axis scale division
    132 
    133   \param scaleDiv Scale division
    134 */
    135 void QwtPlotGrid::setXDiv( const QwtScaleDiv &scaleDiv )
    136 {
    137     if ( d_data->xScaleDiv != scaleDiv )
    138     {
    139         d_data->xScaleDiv = scaleDiv;
    140         itemChanged();
    141     }
    142 }
    143 
    144 /*!
    145   Assign a y axis division
    146 
    147   \param scaleDiv Scale division
    148 */
    149 void QwtPlotGrid::setYDiv( const QwtScaleDiv &scaleDiv )
    150 {
    151     if ( d_data->yScaleDiv != scaleDiv )
    152     {
    153         d_data->yScaleDiv = scaleDiv;
    154         itemChanged();
    155     }
    156 }
    157 
    158 /*!
    159   Build and assign a pen for both major and minor grid lines
    160 
    161   In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it
    162   non cosmetic ( see QPen::isCosmetic() ). This method has been introduced
    163   to hide this incompatibility.
    164 
    165   \param color Pen color
    166   \param width Pen width
    167   \param style Pen style
    168 
    169   \sa pen(), brush()
    170  */
    171 void QwtPlotGrid::setPen( const QColor &color, qreal width, Qt::PenStyle style )
     126    if ( m_data->yMinEnabled != on )
     127    {
     128        m_data->yMinEnabled = on;
     129
     130        legendChanged();
     131        itemChanged();
     132    }
     133}
     134
     135/*!
     136   Assign an x axis scale division
     137
     138   \param scaleDiv Scale division
     139 */
     140void QwtPlotGrid::setXDiv( const QwtScaleDiv& scaleDiv )
     141{
     142    if ( m_data->xScaleDiv != scaleDiv )
     143    {
     144        m_data->xScaleDiv = scaleDiv;
     145        itemChanged();
     146    }
     147}
     148
     149/*!
     150   Assign a y axis division
     151
     152   \param scaleDiv Scale division
     153 */
     154void QwtPlotGrid::setYDiv( const QwtScaleDiv& scaleDiv )
     155{
     156    if ( m_data->yScaleDiv != scaleDiv )
     157    {
     158        m_data->yScaleDiv = scaleDiv;
     159        itemChanged();
     160    }
     161}
     162
     163/*!
     164   Build and assign a pen for both major and minor grid lines
     165
     166   In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it
     167   non cosmetic ( see QPen::isCosmetic() ). This method has been introduced
     168   to hide this incompatibility.
     169
     170   \param color Pen color
     171   \param width Pen width
     172   \param style Pen style
     173
     174   \sa pen(), brush()
     175 */
     176void QwtPlotGrid::setPen( const QColor& color, qreal width, Qt::PenStyle style )
    172177{
    173178    setPen( QPen( color, width, style ) );
    … …  
    175180
    176181/*!
    177   Assign a pen for both major and minor grid lines
    178 
    179   \param pen Pen
    180   \sa setMajorPen(), setMinorPen()
    181 */
    182 void QwtPlotGrid::setPen( const QPen &pen )
    183 {
    184     if ( d_data->majorPen != pen || d_data->minorPen != pen )
    185     {
    186         d_data->majorPen = pen;
    187         d_data->minorPen = pen;
    188 
    189         legendChanged();
    190         itemChanged();
    191     }
    192 }
    193 
    194 /*!
    195   Build and assign a pen for both major grid lines
    196 
    197   In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it
    198   non cosmetic ( see QPen::isCosmetic() ). This method has been introduced
    199   to hide this incompatibility.
    200 
    201   \param color Pen color
    202   \param width Pen width
    203   \param style Pen style
    204 
    205   \sa pen(), brush()
    206  */
    207 void QwtPlotGrid::setMajorPen( const QColor &color, qreal width, Qt::PenStyle style )
     182   Assign a pen for both major and minor grid lines
     183
     184   \param pen Pen
     185   \sa setMajorPen(), setMinorPen()
     186 */
     187void QwtPlotGrid::setPen( const QPen& pen )
     188{
     189    if ( m_data->majorPen != pen || m_data->minorPen != pen )
     190    {
     191        m_data->majorPen = pen;
     192        m_data->minorPen = pen;
     193
     194        legendChanged();
     195        itemChanged();
     196    }
     197}
     198
     199/*!
     200   Build and assign a pen for both major grid lines
     201
     202   In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it
     203   non cosmetic ( see QPen::isCosmetic() ). This method has been introduced
     204   to hide this incompatibility.
     205
     206   \param color Pen color
     207   \param width Pen width
     208   \param style Pen style
     209
     210   \sa pen(), brush()
     211 */
     212void QwtPlotGrid::setMajorPen( const QColor& color, qreal width, Qt::PenStyle style )
    208213{
    209214    setMajorPen( QPen( color, width, style ) );
    … …  
    211216
    212217/*!
    213   Assign a pen for the major grid lines
    214 
    215   \param pen Pen
    216   \sa majorPen(), setMinorPen(), setPen()
    217 */
    218 void QwtPlotGrid::setMajorPen( const QPen &pen )
    219 {
    220     if ( d_data->majorPen != pen )
    221     {
    222         d_data->majorPen = pen;
    223 
    224         legendChanged();
    225         itemChanged();
    226     }
    227 }
    228 
    229 /*!
    230   Build and assign a pen for the minor grid lines
    231 
    232   In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it
    233   non cosmetic ( see QPen::isCosmetic() ). This method has been introduced
    234   to hide this incompatibility.
    235 
    236   \param color Pen color
    237   \param width Pen width
    238   \param style Pen style
    239 
    240   \sa pen(), brush()
    241  */
    242 void QwtPlotGrid::setMinorPen( const QColor &color, qreal width, Qt::PenStyle style )
     218   Assign a pen for the major grid lines
     219
     220   \param pen Pen
     221   \sa majorPen(), setMinorPen(), setPen()
     222 */
     223void QwtPlotGrid::setMajorPen( const QPen& pen )
     224{
     225    if ( m_data->majorPen != pen )
     226    {
     227        m_data->majorPen = pen;
     228
     229        legendChanged();
     230        itemChanged();
     231    }
     232}
     233
     234/*!
     235   Build and assign a pen for the minor grid lines
     236
     237   In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it
     238   non cosmetic ( see QPen::isCosmetic() ). This method has been introduced
     239   to hide this incompatibility.
     240
     241   \param color Pen color
     242   \param width Pen width
     243   \param style Pen style
     244
     245   \sa pen(), brush()
     246 */
     247void QwtPlotGrid::setMinorPen( const QColor& color, qreal width, Qt::PenStyle style )
    243248{
    244249    setMinorPen( QPen( color, width, style ) );
    … …  
    246251
    247252/*!
    248   Assign a pen for the minor grid lines
    249 
    250   \param pen Pen
    251   \sa minorPen(), setMajorPen(), setPen()
    252 */
    253 void QwtPlotGrid::setMinorPen( const QPen &pen )
    254 {
    255     if ( d_data->minorPen != pen )
    256     {
    257         d_data->minorPen = pen;
    258 
    259         legendChanged();
    260         itemChanged();
    261     }
    262 }
    263 
    264 /*!
    265   \brief Draw the grid
    266 
    267   The grid is drawn into the bounding rectangle such that
    268   grid lines begin and end at the rectangle's borders. The X and Y
    269   maps are used to map the scale divisions into the drawing region
    270   screen.
    271 
    272   \param painter  Painter
    273   \param xMap X axis map
    274   \param yMap Y axis
    275   \param canvasRect Contents rectangle of the plot canvas
    276 */
    277 void QwtPlotGrid::draw( QPainter *painter,
    278     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    279     const QRectF &canvasRect ) const
     253   Assign a pen for the minor grid lines
     254
     255   \param pen Pen
     256   \sa minorPen(), setMajorPen(), setPen()
     257 */
     258void QwtPlotGrid::setMinorPen( const QPen& pen )
     259{
     260    if ( m_data->minorPen != pen )
     261    {
     262        m_data->minorPen = pen;
     263
     264        legendChanged();
     265        itemChanged();
     266    }
     267}
     268
     269/*!
     270   \brief Draw the grid
     271
     272   The grid is drawn into the bounding rectangle such that
     273   grid lines begin and end at the rectangle's borders. The X and Y
     274   maps are used to map the scale divisions into the drawing region
     275   screen.
     276
     277   \param painter  Painter
     278   \param xMap X axis map
     279   \param yMap Y axis
     280   \param canvasRect Contents rectangle of the plot canvas
     281 */
     282void QwtPlotGrid::draw( QPainter* painter,
     283    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     284    const QRectF& canvasRect ) const
    280285{
    281286    //  draw minor grid lines
    282     QPen minorPen = d_data->minorPen;
     287    QPen minorPen = m_data->minorPen;
    283288    minorPen.setCapStyle( Qt::FlatCap );
    284289
    285290    painter->setPen( minorPen );
    286291
    287     if ( d_data->xEnabled && d_data->xMinEnabled )
     292    if ( m_data->xEnabled && m_data->xMinEnabled )
    288293    {
    289294        drawLines( painter, canvasRect, Qt::Vertical, xMap,
    290             d_data->xScaleDiv.ticks( QwtScaleDiv::MinorTick ) );
     295            m_data->xScaleDiv.ticks( QwtScaleDiv::MinorTick ) );
    291296        drawLines( painter, canvasRect, Qt::Vertical, xMap,
    292             d_data->xScaleDiv.ticks( QwtScaleDiv::MediumTick ) );
    293     }
    294 
    295     if ( d_data->yEnabled && d_data->yMinEnabled )
     297            m_data->xScaleDiv.ticks( QwtScaleDiv::MediumTick ) );
     298    }
     299
     300    if ( m_data->yEnabled && m_data->yMinEnabled )
    296301    {
    297302        drawLines( painter, canvasRect, Qt::Horizontal, yMap,
    298             d_data->yScaleDiv.ticks( QwtScaleDiv::MinorTick ) );
     303            m_data->yScaleDiv.ticks( QwtScaleDiv::MinorTick ) );
    299304        drawLines( painter, canvasRect, Qt::Horizontal, yMap,
    300             d_data->yScaleDiv.ticks( QwtScaleDiv::MediumTick ) );
     305            m_data->yScaleDiv.ticks( QwtScaleDiv::MediumTick ) );
    301306    }
    302307
    303308    //  draw major grid lines
    304     QPen majorPen = d_data->majorPen;
     309    QPen majorPen = m_data->majorPen;
    305310    majorPen.setCapStyle( Qt::FlatCap );
    306311
    307312    painter->setPen( majorPen );
    308313
    309     if ( d_data->xEnabled )
     314    if ( m_data->xEnabled )
    310315    {
    311316        drawLines( painter, canvasRect, Qt::Vertical, xMap,
    312             d_data->xScaleDiv.ticks( QwtScaleDiv::MajorTick ) );
    313     }
    314 
    315     if ( d_data->yEnabled )
     317            m_data->xScaleDiv.ticks( QwtScaleDiv::MajorTick ) );
     318    }
     319
     320    if ( m_data->yEnabled )
    316321    {
    317322        drawLines( painter, canvasRect, Qt::Horizontal, yMap,
    318             d_data->yScaleDiv.ticks( QwtScaleDiv::MajorTick ) );
    319     }
    320 }
    321 
    322 void QwtPlotGrid::drawLines( QPainter *painter, const QRectF &canvasRect,
    323     Qt::Orientation orientation, const QwtScaleMap &scaleMap,
    324     const QList<double> &values ) const
     323            m_data->yScaleDiv.ticks( QwtScaleDiv::MajorTick ) );
     324    }
     325}
     326
     327void QwtPlotGrid::drawLines( QPainter* painter, const QRectF& canvasRect,
     328    Qt::Orientation orientation, const QwtScaleMap& scaleMap,
     329    const QList< double >& values ) const
    325330{
    326331    const double x1 = canvasRect.left();
    … …  
    340345        {
    341346            if ( qwtFuzzyGreaterOrEqual( value, y1 ) &&
    342                 qwtFuzzyLessOrEqual( value, y2 ) )
     347                qwtFuzzyGreaterOrEqual( y2, value ) )
    343348            {
    344349                QwtPainter::drawLine( painter, x1, value, x2, value );
    … …  
    348353        {
    349354            if ( qwtFuzzyGreaterOrEqual( value, x1 ) &&
    350                 qwtFuzzyLessOrEqual( value, x2 ) )
     355                qwtFuzzyGreaterOrEqual( x2, value ) )
    351356            {
    352357                QwtPainter::drawLine( painter, value, y1, value, y2 );
    … …  
    357362
    358363/*!
    359   \return the pen for the major grid lines
    360   \sa setMajorPen(), setMinorPen(), setPen()
    361 */
    362 const QPen &QwtPlotGrid::majorPen() const
    363 {
    364     return d_data->majorPen;
    365 }
    366 
    367 /*!
    368   \return the pen for the minor grid lines
    369   \sa setMinorPen(), setMajorPen(), setPen()
    370 */
    371 const QPen &QwtPlotGrid::minorPen() const
    372 {
    373     return d_data->minorPen;
    374 }
    375 
    376 /*!
    377   \return true if vertical grid lines are enabled
    378   \sa enableX()
    379 */
     364   \return the pen for the major grid lines
     365   \sa setMajorPen(), setMinorPen(), setPen()
     366 */
     367const QPen& QwtPlotGrid::majorPen() const
     368{
     369    return m_data->majorPen;
     370}
     371
     372/*!
     373   \return the pen for the minor grid lines
     374   \sa setMinorPen(), setMajorPen(), setPen()
     375 */
     376const QPen& QwtPlotGrid::minorPen() const
     377{
     378    return m_data->minorPen;
     379}
     380
     381/*!
     382   \return true if vertical grid lines are enabled
     383   \sa enableX()
     384 */
    380385bool QwtPlotGrid::xEnabled() const
    381386{
    382     return d_data->xEnabled;
    383 }
    384 
    385 /*!
    386   \return true if minor vertical grid lines are enabled
    387   \sa enableXMin()
    388 */
     387    return m_data->xEnabled;
     388}
     389
     390/*!
     391   \return true if minor vertical grid lines are enabled
     392   \sa enableXMin()
     393 */
    389394bool QwtPlotGrid::xMinEnabled() const
    390395{
    391     return d_data->xMinEnabled;
    392 }
    393 
    394 /*!
    395   \return true if horizontal grid lines are enabled
    396   \sa enableY()
    397 */
     396    return m_data->xMinEnabled;
     397}
     398
     399/*!
     400   \return true if horizontal grid lines are enabled
     401   \sa enableY()
     402 */
    398403bool QwtPlotGrid::yEnabled() const
    399404{
    400     return d_data->yEnabled;
    401 }
    402 
    403 /*!
    404   \return true if minor horizontal grid lines are enabled
    405   \sa enableYMin()
    406 */
     405    return m_data->yEnabled;
     406}
     407
     408/*!
     409   \return true if minor horizontal grid lines are enabled
     410   \sa enableYMin()
     411 */
    407412bool QwtPlotGrid::yMinEnabled() const
    408413{
    409     return d_data->yMinEnabled;
     414    return m_data->yMinEnabled;
    410415}
    411416
    412417
    413418/*! \return the scale division of the x axis */
    414 const QwtScaleDiv &QwtPlotGrid::xScaleDiv() const
    415 {
    416     return d_data->xScaleDiv;
     419const QwtScaleDiv& QwtPlotGrid::xScaleDiv() const
     420{
     421    return m_data->xScaleDiv;
    417422}
    418423
    419424/*! \return the scale division of the y axis */
    420 const QwtScaleDiv &QwtPlotGrid::yScaleDiv() const
    421 {
    422     return d_data->yScaleDiv;
     425const QwtScaleDiv& QwtPlotGrid::yScaleDiv() const
     426{
     427    return m_data->yScaleDiv;
    423428}
    424429
    … …  
    430435
    431436   \sa QwtPlot::updateAxes()
    432 */
     437 */
    433438void QwtPlotGrid::updateScaleDiv( const QwtScaleDiv& xScaleDiv,
    434439    const QwtScaleDiv& yScaleDiv )
Note: See TracChangeset for help on using the changeset viewer.