Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_plot_picker.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_picker.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_picker.h"
    1111#include "qwt_plot.h"
     12#include "qwt_text.h"
    1213#include "qwt_scale_div.h"
    13 #include "qwt_painter.h"
    1414#include "qwt_scale_map.h"
    1515#include "qwt_picker_machine.h"
    1616
    17 /*!
    18   \brief Create a plot picker
    19 
    20   The picker is set to those x- and y-axis of the plot
    21   that are enabled. If both or no x-axis are enabled, the picker
    22   is set to QwtPlot::xBottom. If both or no y-axis are
    23   enabled, it is set to QwtPlot::yLeft.
    24 
    25   \param canvas Plot canvas to observe, also the parent object
    26 
    27   \sa QwtPlot::autoReplot(), QwtPlot::replot(), scaleRect()
    28 */
    29 
    30 QwtPlotPicker::QwtPlotPicker( QWidget *canvas ):
    31     QwtPicker( canvas ),
    32     d_xAxis( -1 ),
    33     d_yAxis( -1 )
    34 {
     17class QwtPlotPicker::PrivateData
     18{
     19  public:
     20    PrivateData():
     21        xAxisId( -1 ),
     22        yAxisId( -1 )
     23    {
     24    }
     25
     26    QwtAxisId xAxisId;
     27    QwtAxisId yAxisId;
     28};
     29
     30/*!
     31   \brief Create a plot picker
     32
     33   The picker is set to those x- and y-axis of the plot
     34   that are enabled. If both or no x-axis are enabled, the picker
     35   is set to QwtAxis::XBottom. If both or no y-axis are
     36   enabled, it is set to QwtAxis::YLeft.
     37
     38   \param canvas Plot canvas to observe, also the parent object
     39
     40   \sa QwtPlot::autoReplot(), QwtPlot::replot(), scaleRect()
     41 */
     42
     43QwtPlotPicker::QwtPlotPicker( QWidget* canvas )
     44    : QwtPicker( canvas )
     45{
     46    m_data = new PrivateData;
     47
    3548    if ( !canvas )
    3649        return;
    3750
     51    const QwtPlot* plot = QwtPlotPicker::plot();
    3852    // attach axes
    3953
    40     int xAxis = QwtPlot::xBottom;
    41 
    42     const QwtPlot *plot = QwtPlotPicker::plot();
    43     if ( !plot->axisEnabled( QwtPlot::xBottom ) &&
    44         plot->axisEnabled( QwtPlot::xTop ) )
    45     {
    46         xAxis = QwtPlot::xTop;
    47     }
    48 
    49     int yAxis = QwtPlot::yLeft;
    50     if ( !plot->axisEnabled( QwtPlot::yLeft ) &&
    51         plot->axisEnabled( QwtPlot::yRight ) )
    52     {
    53         yAxis = QwtPlot::yRight;
    54     }
    55 
    56     setAxis( xAxis, yAxis );
    57 }
    58 
    59 /*!
    60   Create a plot picker
    61 
    62   \param xAxis Set the x axis of the picker
    63   \param yAxis Set the y axis of the picker
    64   \param canvas Plot canvas to observe, also the parent object
    65 
    66   \sa QwtPlot::autoReplot(), QwtPlot::replot(), scaleRect()
    67 */
    68 QwtPlotPicker::QwtPlotPicker( int xAxis, int yAxis, QWidget *canvas ):
    69     QwtPicker( canvas ),
    70     d_xAxis( xAxis ),
    71     d_yAxis( yAxis )
    72 {
    73 }
    74 
    75 /*!
    76   Create a plot picker
    77 
    78   \param xAxis X axis of the picker
    79   \param yAxis Y axis of the picker
    80   \param rubberBand Rubber band style
    81   \param trackerMode Tracker mode
    82   \param canvas Plot canvas to observe, also the parent object
    83 
    84   \sa QwtPicker, QwtPicker::setSelectionFlags(), QwtPicker::setRubberBand(),
     54    using namespace QwtAxis;
     55
     56    int xAxis = XBottom;
     57    if ( !plot->isAxisVisible( XBottom ) && plot->isAxisVisible( XTop ) )
     58        xAxis = XTop;
     59
     60    int yAxis = YLeft;
     61    if ( !plot->isAxisVisible( YLeft ) && plot->isAxisVisible( YRight ) )
     62        yAxis = YRight;
     63
     64    setAxes( xAxis, yAxis );
     65}
     66
     67/*!
     68   Create a plot picker
     69
     70   \param xAxisId X axis of the picker
     71   \param yAxisId Y axis of the picker
     72   \param canvas Plot canvas to observe, also the parent object
     73
     74   \sa QwtPlot::autoReplot(), QwtPlot::replot(), scaleRect()
     75 */
     76QwtPlotPicker::QwtPlotPicker( QwtAxisId xAxisId, QwtAxisId yAxisId, QWidget* canvas )
     77    : QwtPicker( canvas )
     78{
     79    m_data = new PrivateData;
     80    m_data->xAxisId = xAxisId;
     81    m_data->yAxisId = yAxisId;
     82}
     83
     84/*!
     85   Create a plot picker
     86
     87   \param xAxisId X axis of the picker
     88   \param yAxisId Y axis of the picker
     89   \param rubberBand Rubber band style
     90   \param trackerMode Tracker mode
     91   \param canvas Plot canvas to observe, also the parent object
     92
     93   \sa QwtPicker, QwtPicker::setSelectionFlags(), QwtPicker::setRubberBand(),
    8594      QwtPicker::setTrackerMode
    8695
    87   \sa QwtPlot::autoReplot(), QwtPlot::replot(), scaleRect()
    88 */
    89 QwtPlotPicker::QwtPlotPicker( int xAxis, int yAxis,
    90         RubberBand rubberBand, DisplayMode trackerMode,
    91         QWidget *canvas ):
    92     QwtPicker( rubberBand, trackerMode, canvas ),
    93     d_xAxis( xAxis ),
    94     d_yAxis( yAxis )
    95 {
     96   \sa QwtPlot::autoReplot(), QwtPlot::replot(), scaleRect()
     97 */
     98QwtPlotPicker::QwtPlotPicker( QwtAxisId xAxisId, QwtAxisId yAxisId,
     99        RubberBand rubberBand, DisplayMode trackerMode, QWidget* canvas )
     100    : QwtPicker( rubberBand, trackerMode, canvas )
     101{
     102    m_data = new PrivateData;
     103    m_data->xAxisId = xAxisId;
     104    m_data->yAxisId = yAxisId;
    96105}
    97106
    … …  
    99108QwtPlotPicker::~QwtPlotPicker()
    100109{
     110    delete m_data;
    101111}
    102112
    103113//! \return Observed plot canvas
    104 QWidget *QwtPlotPicker::canvas()
     114QWidget* QwtPlotPicker::canvas()
    105115{
    106116    return parentWidget();
    … …  
    108118
    109119//! \return Observed plot canvas
    110 const QWidget *QwtPlotPicker::canvas() const
     120const QWidget* QwtPlotPicker::canvas() const
    111121{
    112122    return parentWidget();
    … …  
    114124
    115125//! \return Plot widget, containing the observed plot canvas
    116 QwtPlot *QwtPlotPicker::plot()
    117 {
    118     QWidget *w = canvas();
     126QwtPlot* QwtPlotPicker::plot()
     127{
     128    QWidget* w = canvas();
    119129    if ( w )
    120130        w = w->parentWidget();
    121131
    122     return qobject_cast<QwtPlot *>( w );
     132    return qobject_cast< QwtPlot* >( w );
    123133}
    124134
    125135//! \return Plot widget, containing the observed plot canvas
    126 const QwtPlot *QwtPlotPicker::plot() const
    127 {
    128     const QWidget *w = canvas();
     136const QwtPlot* QwtPlotPicker::plot() const
     137{
     138    const QWidget* w = canvas();
    129139    if ( w )
    130140        w = w->parentWidget();
    131141
    132     return qobject_cast<const QwtPlot *>( w );
    133 }
    134 
    135 /*!
    136   \return Normalized bounding rectangle of the axes
    137   \sa QwtPlot::autoReplot(), QwtPlot::replot().
    138 */
     142    return qobject_cast< const QwtPlot* >( w );
     143}
     144
     145/*!
     146   \return Normalized bounding rectangle of the axes
     147   \sa QwtPlot::autoReplot(), QwtPlot::replot().
     148 */
    139149QRectF QwtPlotPicker::scaleRect() const
    140150{
    … …  
    143153    if ( plot() )
    144154    {
    145         const QwtScaleDiv &xs = plot()->axisScaleDiv( xAxis() );
    146         const QwtScaleDiv &ys = plot()->axisScaleDiv( yAxis() );
     155        const QwtScaleDiv& xs = plot()->axisScaleDiv( xAxis() );
     156        const QwtScaleDiv& ys = plot()->axisScaleDiv( yAxis() );
    147157
    148158        rect = QRectF( xs.lowerBound(), ys.lowerBound(),
    … …  
    155165
    156166/*!
    157   Set the x and y axes of the picker
    158 
    159   \param xAxis X axis
    160   \param yAxis Y axis
    161 */
    162 void QwtPlotPicker::setAxis( int xAxis, int yAxis )
    163 {
    164     const QwtPlot *plt = plot();
     167   Set the x and y axes of the picker
     168
     169   \param xAxisId X axis
     170   \param yAxisId Y axis
     171 */
     172void QwtPlotPicker::setAxes( QwtAxisId xAxisId, QwtAxisId yAxisId )
     173{
     174    const QwtPlot* plt = plot();
    165175    if ( !plt )
    166176        return;
    167177
    168     if ( xAxis != d_xAxis || yAxis != d_yAxis )
    169     {
    170         d_xAxis = xAxis;
    171         d_yAxis = yAxis;
     178    if ( xAxisId != m_data->xAxisId || yAxisId != m_data->yAxisId )
     179    {
     180        m_data->xAxisId = xAxisId;
     181        m_data->yAxisId = yAxisId;
    172182    }
    173183}
    174184
    175185//! Return x axis
    176 int QwtPlotPicker::xAxis() const
    177 {
    178     return d_xAxis;
     186QwtAxisId QwtPlotPicker::xAxis() const
     187{
     188    return m_data->xAxisId;
    179189}
    180190
    181191//! Return y axis
    182 int QwtPlotPicker::yAxis() const
    183 {
    184     return d_yAxis;
    185 }
    186 
    187 /*!
    188   Translate a pixel position into a position string
    189 
    190   \param pos Position in pixel coordinates
    191   \return Position string
    192 */
    193 QwtText QwtPlotPicker::trackerText( const QPoint &pos ) const
     192QwtAxisId QwtPlotPicker::yAxis() const
     193{
     194    return m_data->yAxisId;
     195}
     196
     197/*!
     198   Translate a pixel position into a position string
     199
     200   \param pos Position in pixel coordinates
     201   \return Position string
     202 */
     203QwtText QwtPlotPicker::trackerText( const QPoint& pos ) const
    194204{
    195205    if ( plot() == NULL )
    … …  
    200210
    201211/*!
    202   \brief Translate a position into a position string
    203 
    204   In case of HLineRubberBand the label is the value of the
    205   y position, in case of VLineRubberBand the value of the x position.
    206   Otherwise the label contains x and y position separated by a ',' .
    207 
    208   The format for the double to string conversion is "%.4f".
    209 
    210   \param pos Position
    211   \return Position string
    212 */
    213 QwtText QwtPlotPicker::trackerTextF( const QPointF &pos ) const
     212   \brief Translate a position into a position string
     213
     214   In case of HLineRubberBand the label is the value of the
     215   y position, in case of VLineRubberBand the value of the x position.
     216   Otherwise the label contains x and y position separated by a ',' .
     217
     218   The format for the double to string conversion is "%.4f".
     219
     220   \param pos Position
     221   \return Position string
     222 */
     223QwtText QwtPlotPicker::trackerTextF( const QPointF& pos ) const
    214224{
    215225    QString text;
    … …  
    218228    {
    219229        case HLineRubberBand:
    220             text.sprintf( "%.4f", pos.y() );
     230            text = QString::number( pos.y(), 'f', 4 );
    221231            break;
    222232        case VLineRubberBand:
    223             text.sprintf( "%.4f", pos.x() );
     233            text = QString::number( pos.x(), 'f', 4 );
    224234            break;
    225235        default:
    226             text.sprintf( "%.4f, %.4f", pos.x(), pos.y() );
     236            text = QString::number( pos.x(), 'f', 4 )
     237                + ", " + QString::number( pos.y(), 'f', 4 );
    227238    }
    228239    return QwtText( text );
    … …  
    230241
    231242/*!
    232   Append a point to the selection and update rubber band and tracker.
    233 
    234   \param pos Additional point
    235   \sa isActive, begin(), end(), move(), appended()
    236 
    237   \note The appended(const QPoint &), appended(const QDoublePoint &)
     243   Append a point to the selection and update rubber band and tracker.
     244
     245   \param pos Additional point
     246   \sa isActive, begin(), end(), move(), appended()
     247
     248   \note The appended(const QPoint &), appended(const QDoublePoint &)
    238249        signals are emitted.
    239 */
    240 void QwtPlotPicker::append( const QPoint &pos )
     250 */
     251void QwtPlotPicker::append( const QPoint& pos )
    241252{
    242253    QwtPicker::append( pos );
    … …  
    245256
    246257/*!
    247   Move the last point of the selection
    248 
    249   \param pos New position
    250   \sa isActive, begin(), end(), append()
    251 
    252   \note The moved(const QPoint &), moved(const QDoublePoint &)
     258   Move the last point of the selection
     259
     260   \param pos New position
     261   \sa isActive, begin(), end(), append()
     262
     263   \note The moved(const QPoint &), moved(const QDoublePoint &)
    253264        signals are emitted.
    254 */
    255 void QwtPlotPicker::move( const QPoint &pos )
     265 */
     266void QwtPlotPicker::move( const QPoint& pos )
    256267{
    257268    QwtPicker::move( pos );
    … …  
    260271
    261272/*!
    262   Close a selection setting the state to inactive.
    263 
    264   \param ok If true, complete the selection and emit selected signals
     273   Close a selection setting the state to inactive.
     274
     275   \param ok If true, complete the selection and emit selected signals
    265276            otherwise discard the selection.
    266   \return True if the selection has been accepted, false otherwise
    267 */
     277   \return True if the selection has been accepted, false otherwise
     278 */
    268279
    269280bool QwtPlotPicker::end( bool ok )
    … …  
    273284        return false;
    274285
    275     QwtPlot *plot = QwtPlotPicker::plot();
     286    QwtPlot* plot = QwtPlotPicker::plot();
    276287    if ( !plot )
    277288        return false;
    … …  
    309320        case QwtPickerMachine::PolygonSelection:
    310321        {
    311             QVector<QPointF> dpa( points.count() );
     322            QVector< QPointF > dpa( points.count() );
    312323            for ( int i = 0; i < points.count(); i++ )
    313324                dpa[i] = invTransform( points[i] );
    … …  
    327338    \return Rectangle in plot coordinates
    328339    \sa transform()
    329 */
    330 QRectF QwtPlotPicker::invTransform( const QRect &rect ) const
    331 {
    332     const QwtScaleMap xMap = plot()->canvasMap( d_xAxis );
    333     const QwtScaleMap yMap = plot()->canvasMap( d_yAxis );
     340 */
     341QRectF QwtPlotPicker::invTransform( const QRect& rect ) const
     342{
     343    const QwtScaleMap xMap = plot()->canvasMap( xAxis() );
     344    const QwtScaleMap yMap = plot()->canvasMap( yAxis() );
    334345
    335346    return QwtScaleMap::invTransform( xMap, yMap, rect );
    … …  
    340351    \return Rectangle in pixel coordinates
    341352    \sa invTransform()
    342 */
    343 QRect QwtPlotPicker::transform( const QRectF &rect ) const
    344 {
    345     const QwtScaleMap xMap = plot()->canvasMap( d_xAxis );
    346     const QwtScaleMap yMap = plot()->canvasMap( d_yAxis );
     353 */
     354QRect QwtPlotPicker::transform( const QRectF& rect ) const
     355{
     356    const QwtScaleMap xMap = plot()->canvasMap( xAxis() );
     357    const QwtScaleMap yMap = plot()->canvasMap( yAxis() );
    347358
    348359    return QwtScaleMap::transform( xMap, yMap, rect ).toRect();
    … …  
    353364    \return Point in plot coordinates
    354365    \sa transform()
    355 */
    356 QPointF QwtPlotPicker::invTransform( const QPoint &pos ) const
    357 {
    358     QwtScaleMap xMap = plot()->canvasMap( d_xAxis );
    359     QwtScaleMap yMap = plot()->canvasMap( d_yAxis );
     366 */
     367QPointF QwtPlotPicker::invTransform( const QPoint& pos ) const
     368{
     369    const QwtScaleMap xMap = plot()->canvasMap( xAxis() );
     370    const QwtScaleMap yMap = plot()->canvasMap( yAxis() );
    360371
    361372    return QPointF(
    362373        xMap.invTransform( pos.x() ),
    363374        yMap.invTransform( pos.y() )
    364     );
     375        );
    365376}
    366377
    … …  
    369380    \return Point in pixel coordinates
    370381    \sa invTransform()
    371 */
    372 QPoint QwtPlotPicker::transform( const QPointF &pos ) const
    373 {
    374     QwtScaleMap xMap = plot()->canvasMap( d_xAxis );
    375     QwtScaleMap yMap = plot()->canvasMap( d_yAxis );
    376 
    377     const QPointF p( xMap.transform( pos.x() ),
    378         yMap.transform( pos.y() ) );
     382 */
     383QPoint QwtPlotPicker::transform( const QPointF& pos ) const
     384{
     385    const QwtScaleMap xMap = plot()->canvasMap( xAxis() );
     386    const QwtScaleMap yMap = plot()->canvasMap( yAxis() );
     387
     388    const QPointF p( xMap.transform( pos.x() ), yMap.transform( pos.y() ) );
    379389
    380390    return p.toPoint();
    381391}
     392
     393#include "moc_qwt_plot_picker.cpp"
Note: See TracChangeset for help on using the changeset viewer.