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

    r4271 r8127  
    99
    1010#include "qwt_plot.h"
    11 #include "qwt_plot_canvas.h"
    1211#include "qwt_scale_div.h"
    1312#include "qwt_plot_magnifier.h"
     
    3029   \param canvas Plot canvas to be magnified
    3130*/
    32 QwtPlotMagnifier::QwtPlotMagnifier( QwtPlotCanvas *canvas ):
     31QwtPlotMagnifier::QwtPlotMagnifier( QWidget *canvas ):
    3332    QwtMagnifier( canvas )
    3433{
     
    7675
    7776//! Return observed plot canvas
    78 QwtPlotCanvas *QwtPlotMagnifier::canvas()
     77QWidget *QwtPlotMagnifier::canvas()
    7978{
    80     return qobject_cast<QwtPlotCanvas *>( parent() );
     79    return parentWidget();
    8180}
    8281
    8382//! Return Observed plot canvas
    84 const QwtPlotCanvas *QwtPlotMagnifier::canvas() const
     83const QWidget *QwtPlotMagnifier::canvas() const
    8584{
    86     return qobject_cast<const QwtPlotCanvas *>( parent() );
     85    return parentWidget();
    8786}
    8887
     
    9089QwtPlot *QwtPlotMagnifier::plot()
    9190{
    92     QwtPlotCanvas *w = canvas();
     91    QWidget *w = canvas();
    9392    if ( w )
    94         return w->plot();
     93        w = w->parentWidget();
    9594
    96     return NULL;
     95    return qobject_cast<QwtPlot *>( w );
    9796}
    9897
     
    10099const QwtPlot *QwtPlotMagnifier::plot() const
    101100{
    102     const QwtPlotCanvas *w = canvas();
     101    const QWidget *w = canvas();
    103102    if ( w )
    104         return w->plot();
     103        w = w->parentWidget();
    105104
    106     return NULL;
     105    return qobject_cast<const QwtPlot *>( w );
    107106}
    108107
     
    113112void QwtPlotMagnifier::rescale( double factor )
    114113{
     114    QwtPlot* plt = plot();
     115    if ( plt == NULL )
     116        return;
     117
    115118    factor = qAbs( factor );
    116119    if ( factor == 1.0 || factor == 0.0 )
     
    118121
    119122    bool doReplot = false;
    120     QwtPlot* plt = plot();
    121123
    122124    const bool autoReplot = plt->autoReplot();
     
    125127    for ( int axisId = 0; axisId < QwtPlot::axisCnt; axisId++ )
    126128    {
    127         const QwtScaleDiv *scaleDiv = plt->axisScaleDiv( axisId );
    128         if ( isAxisEnabled( axisId ) && scaleDiv->isValid() )
     129        if ( isAxisEnabled( axisId ) )
    129130        {
    130             const double center =
    131                 scaleDiv->lowerBound() + scaleDiv->range() / 2;
    132             const double width_2 = scaleDiv->range() / 2 * factor;
     131            const QwtScaleMap scaleMap = plt->canvasMap( axisId );
    133132
    134             plt->setAxisScale( axisId, center - width_2, center + width_2 );
     133            double v1 = scaleMap.s1();
     134            double v2 = scaleMap.s2();
     135
     136            if ( scaleMap.transformation() )
     137            {
     138                // the coordinate system of the paint device is always linear
     139
     140                v1 = scaleMap.transform( v1 ); // scaleMap.p1()
     141                v2 = scaleMap.transform( v2 ); // scaleMap.p2()
     142            }
     143
     144            const double center = 0.5 * ( v1 + v2 );
     145            const double width_2 = 0.5 * ( v2 - v1 ) * factor;
     146
     147            v1 = center - width_2;
     148            v2 = center + width_2;
     149
     150            if ( scaleMap.transformation() )
     151            {
     152                v1 = scaleMap.invTransform( v1 );
     153                v2 = scaleMap.invTransform( v2 );
     154            }
     155
     156            plt->setAxisScale( axisId, v1, v2 );
    135157            doReplot = true;
    136158        }
Note: See TracChangeset for help on using the changeset viewer.