Changeset 8127 in ntrip for trunk/BNC/qwt/qwt_plot_rescaler.cpp


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

    r4271 r8127  
    1010#include "qwt_plot_rescaler.h"
    1111#include "qwt_plot.h"
    12 #include "qwt_plot_canvas.h"
    1312#include "qwt_scale_div.h"
    1413#include "qwt_interval.h"
     14#include "qwt_plot_canvas.h"
    1515#include <qevent.h>
    1616#include <qalgorithms.h>
     
    5959   \sa setRescalePolicy(), setReferenceAxis()
    6060*/
    61 QwtPlotRescaler::QwtPlotRescaler( QwtPlotCanvas *canvas,
     61QwtPlotRescaler::QwtPlotRescaler( QWidget *canvas,
    6262        int referenceAxis, RescalePolicy policy ):
    6363    QObject( canvas )
     
    179179
    180180/*!
    181   Return direction in which an axis should be expanded
     181  \return Direction in which an axis should be expanded
    182182
    183183  \param axis Axis index ( see QwtPlot::AxisId )
     
    224224
    225225/*!
    226   Return aspect ratio between an axis and the reference axis.
     226  \return Aspect ratio between an axis and the reference axis.
    227227
    228228  \param axis Axis index ( see QwtPlot::AxisId )
     
    241241
    242242  In Fitting mode, the hint is used as minimal interval
    243   taht always needs to be displayed.
     243  that always needs to be displayed.
    244244
    245245  \param axis Axis, see QwtPlot::Axis
     
    268268
    269269//! \return plot canvas
    270 QwtPlotCanvas *QwtPlotRescaler::canvas()
    271 {
    272     return qobject_cast<QwtPlotCanvas *>( parent() );
     270QWidget *QwtPlotRescaler::canvas()
     271{
     272    return qobject_cast<QWidget *>( parent() );
    273273}
    274274
    275275//! \return plot canvas
    276 const QwtPlotCanvas *QwtPlotRescaler::canvas() const
    277 {
    278     return qobject_cast<const QwtPlotCanvas *>( parent() );
     276const QWidget *QwtPlotRescaler::canvas() const
     277{
     278    return qobject_cast<const QWidget *>( parent() );
    279279}
    280280
     
    282282QwtPlot *QwtPlotRescaler::plot()
    283283{
    284     QwtPlotCanvas *w = canvas();
     284    QWidget *w = canvas();
    285285    if ( w )
    286         return w->plot();
    287 
    288     return NULL;
     286        w = w->parentWidget();
     287
     288    return qobject_cast<QwtPlot *>( w );
    289289}
    290290
     
    292292const QwtPlot *QwtPlotRescaler::plot() const
    293293{
    294     const QwtPlotCanvas *w = canvas();
     294    const QWidget *w = canvas();
    295295    if ( w )
    296         return w->plot();
    297 
    298     return NULL;
     296        w = w->parentWidget();
     297
     298    return qobject_cast<const QwtPlot *>( w );
    299299}
    300300
    301301//!  Event filter for the plot canvas
    302 bool QwtPlotRescaler::eventFilter( QObject *o, QEvent *e )
    303 {
    304     if ( o && o == canvas() )
    305     {
    306         switch ( e->type() )
     302bool QwtPlotRescaler::eventFilter( QObject *object, QEvent *event )
     303{
     304    if ( object && object == canvas() )
     305    {
     306        switch ( event->type() )
    307307        {
    308308            case QEvent::Resize:
    309                 canvasResizeEvent( ( QResizeEvent * )e );
     309            {
     310                canvasResizeEvent( static_cast<QResizeEvent *>( event ) );
    310311                break;
     312            }
    311313            case QEvent::PolishRequest:
     314            {
    312315                rescale();
    313316                break;
     317            }
    314318            default:;
    315319        }
     
    327331void QwtPlotRescaler::canvasResizeEvent( QResizeEvent* event )
    328332{
    329     const int fw = 2 * canvas()->frameWidth();
    330     const QSize newSize = event->size() - QSize( fw, fw );
    331     const QSize oldSize = event->oldSize() - QSize( fw, fw );
     333    int left, top, right, bottom;
     334    canvas()->getContentsMargins( &left, &top, &right, &bottom );
     335
     336    const QSize marginSize( left + right, top + bottom );
     337
     338    const QSize newSize = event->size() - marginSize;
     339    const QSize oldSize = event->oldSize() - marginSize;
    332340
    333341    rescale( oldSize, newSize );
     
    433441
    434442/*!
    435    Synchronize an axis scale according to the scale of the reference axis
     443  Synchronize an axis scale according to the scale of the reference axis
    436444
    437445  \param axis Axis index ( see QwtPlot::AxisId )
    438446  \param reference Interval of the reference axis
    439447  \param size Size of the canvas
     448
     449  \return New interval for axis
    440450*/
    441451QwtInterval QwtPlotRescaler::syncScale( int axis,
     
    467477
    468478/*!
    469   Return orientation of an axis
     479  \return Orientation of an axis
    470480  \param axis Axis index ( see QwtPlot::AxisId )
    471481*/
     
    479489
    480490/*!
    481   Return interval of an axis
    482   \param axis Axis index ( see QwtPlot::AxisId )
     491  \param axis Axis index ( see QwtPlot::AxisId )
     492  \return Normalized interval of an axis
    483493*/
    484494QwtInterval QwtPlotRescaler::interval( int axis ) const
     
    487497        return QwtInterval();
    488498
    489     const QwtPlot *plt = plot();
    490 
    491     const double v1 = plt->axisScaleDiv( axis )->lowerBound();
    492     const double v2 = plt->axisScaleDiv( axis )->upperBound();
    493 
    494     return QwtInterval( v1, v2 ).normalized();
     499    return plot()->axisScaleDiv( axis ).interval().normalized();
    495500}
    496501
     
    584589            double v2 = intervals[axis].maxValue();
    585590
    586             if ( plt->axisScaleDiv( axis )->lowerBound() >
    587                 plt->axisScaleDiv( axis )->upperBound() )
    588             {
     591            if ( !plt->axisScaleDiv( axis ).isIncreasing() )
    589592                qSwap( v1, v2 );
    590             }
    591593
    592594            if ( d_data->inReplot >= 1 )
    593             {
    594                 d_data->axisData[axis].scaleDiv = *plt->axisScaleDiv( axis );
    595             }
     595                d_data->axisData[axis].scaleDiv = plt->axisScaleDiv( axis );
    596596
    597597            if ( d_data->inReplot >= 2 )
     
    610610    }
    611611
    612     const bool immediatePaint =
    613         plt->canvas()->testPaintAttribute( QwtPlotCanvas::ImmediatePaint );
    614     plt->canvas()->setPaintAttribute( QwtPlotCanvas::ImmediatePaint, false );
     612    QwtPlotCanvas *canvas = qobject_cast<QwtPlotCanvas *>( plt->canvas() );
     613
     614    bool immediatePaint = false;
     615    if ( canvas )
     616    {
     617        immediatePaint = canvas->testPaintAttribute( QwtPlotCanvas::ImmediatePaint );
     618        canvas->setPaintAttribute( QwtPlotCanvas::ImmediatePaint, false );
     619    }
    615620
    616621    plt->setAutoReplot( doReplot );
     
    620625    d_data->inReplot--;
    621626
    622     plt->canvas()->setPaintAttribute(
    623         QwtPlotCanvas::ImmediatePaint, immediatePaint );
    624 }
     627    if ( canvas && immediatePaint )
     628    {
     629        canvas->setPaintAttribute( QwtPlotCanvas::ImmediatePaint, true );
     630    }
     631}
Note: See TracChangeset for help on using the changeset viewer.