Changeset 8127 in ntrip for trunk/BNC/qwt/qwt_plot_axis.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_axis.cpp

    r4271 r8127  
    2727    int maxMinor;
    2828
     29    bool isValid;
     30
    2931    QwtScaleDiv scaleDiv;
    3032    QwtScaleEngine *scaleEngine;
     
    5456    d_axisData[xBottom]->scaleWidget->setObjectName( "QwtPlotAxisXBottom" );
    5557
     58#if 1
     59    // better find the font sizes from the application font
    5660    QFont fscl( fontInfo().family(), 10 );
    5761    QFont fttl( fontInfo().family(), 12, QFont::Bold );
     62#endif
    5863
    5964    for ( axisId = 0; axisId < axisCnt; axisId++ )
    6065    {
    6166        AxisData &d = *d_axisData[axisId];
     67
     68        d.scaleEngine = new QwtLinearScaleEngine;
     69
     70        d.scaleWidget->setTransformation(
     71            d.scaleEngine->transformation() );
    6272
    6373        d.scaleWidget->setFont( fscl );
     
    7787        d.maxMajor = 8;
    7888
    79         d.scaleEngine = new QwtLinearScaleEngine;
    80 
    81         d.scaleDiv.invalidate();
     89
     90        d.isValid = false;
    8291    }
    8392
     
    99108
    100109/*!
    101   \return specified axis, or NULL if axisId is invalid.
    102   \param axisId axis index
     110  \return Scale widget of the specified axis, or NULL if axisId is invalid.
     111  \param axisId Axis index
    103112*/
    104113const QwtScaleWidget *QwtPlot::axisWidget( int axisId ) const
     
    111120
    112121/*!
    113   \return specified axis, or NULL if axisId is invalid.
    114   \param axisId axis index
     122  \return Scale widget of the specified axis, or NULL if axisId is invalid.
     123  \param axisId Axis index
    115124*/
    116125QwtScaleWidget *QwtPlot::axisWidget( int axisId )
     
    123132
    124133/*!
    125    Change the scale engine for an axis
    126 
    127   \param axisId axis index
     134  Change the scale engine for an axis
     135
     136  \param axisId Axis index
    128137  \param scaleEngine Scale engine
    129138
     
    139148        d.scaleEngine = scaleEngine;
    140149
    141         d.scaleDiv.invalidate();
     150        d_axisData[axisId]->scaleWidget->setTransformation(
     151            scaleEngine->transformation() );
     152
     153        d.isValid = false;
    142154
    143155        autoRefresh();
     
    146158
    147159/*!
    148   \param axisId axis index
     160  \param axisId Axis index
    149161  \return Scale engine for a specific axis
    150162*/
     
    158170
    159171/*!
    160   \param axisId axis index
     172  \param axisId Axis index
    161173  \return Scale engine for a specific axis
    162174*/
     
    169181}
    170182/*!
    171   \return \c true if autoscaling is enabled
    172   \param axisId axis index
     183  \return \c True, if autoscaling is enabled
     184  \param axisId Axis index
    173185*/
    174186bool QwtPlot::axisAutoScale( int axisId ) const
     
    182194
    183195/*!
    184   \return \c true if a specified axis is enabled
    185   \param axisId axis index
     196  \return \c True, if a specified axis is enabled
     197  \param axisId Axis index
    186198*/
    187199bool QwtPlot::axisEnabled( int axisId ) const
     
    194206
    195207/*!
    196   \return the font of the scale labels for a specified axis
    197   \param axisId axis index
     208  \return The font of the scale labels for a specified axis
     209  \param axisId Axis index
    198210*/
    199211QFont QwtPlot::axisFont( int axisId ) const
     
    207219
    208220/*!
    209   \return the maximum number of major ticks for a specified axis
    210   \param axisId axis index
    211   \sa setAxisMaxMajor()
     221  \return The maximum number of major ticks for a specified axis
     222  \param axisId Axis index
     223  \sa setAxisMaxMajor(), QwtScaleEngine::divideScale()
    212224*/
    213225int QwtPlot::axisMaxMajor( int axisId ) const
     
    221233/*!
    222234  \return the maximum number of minor ticks for a specified axis
    223   \param axisId axis index
    224   \sa setAxisMaxMinor()
     235  \param axisId Axis index
     236  \sa setAxisMaxMinor(), QwtScaleEngine::divideScale()
    225237*/
    226238int QwtPlot::axisMaxMinor( int axisId ) const
     
    235247  \brief Return the scale division of a specified axis
    236248
    237   axisScaleDiv(axisId)->lowerBound(), axisScaleDiv(axisId)->upperBound()
     249  axisScaleDiv(axisId).lowerBound(), axisScaleDiv(axisId).upperBound()
    238250  are the current limits of the axis scale.
    239251
    240   \param axisId axis index
     252  \param axisId Axis index
    241253  \return Scale division
    242254
    243   \sa QwtScaleDiv, setAxisScaleDiv()
    244 */
    245 const QwtScaleDiv *QwtPlot::axisScaleDiv( int axisId ) const
     255  \sa QwtScaleDiv, setAxisScaleDiv(), QwtScaleEngine::divideScale()
     256*/
     257const QwtScaleDiv &QwtPlot::axisScaleDiv( int axisId ) const
     258{
     259    return d_axisData[axisId]->scaleDiv;
     260}
     261
     262/*!
     263  \brief Return the scale draw of a specified axis
     264
     265  \param axisId Axis index
     266  \return Specified scaleDraw for axis, or NULL if axis is invalid.
     267*/
     268const QwtScaleDraw *QwtPlot::axisScaleDraw( int axisId ) const
    246269{
    247270    if ( !axisValid( axisId ) )
    248271        return NULL;
    249272
    250     return &d_axisData[axisId]->scaleDiv;
    251 }
    252 
    253 /*!
    254   \brief Return the scale division of a specified axis
    255 
    256   axisScaleDiv(axisId)->lowerBound(), axisScaleDiv(axisId)->upperBound()
    257   are the current limits of the axis scale.
    258 
    259   \param axisId axis index
    260   \return Scale division
    261 
    262   \sa QwtScaleDiv, setAxisScaleDiv()
    263 */
    264 QwtScaleDiv *QwtPlot::axisScaleDiv( int axisId )
     273    return axisWidget( axisId )->scaleDraw();
     274}
     275
     276/*!
     277  \brief Return the scale draw of a specified axis
     278
     279  \param axisId Axis index
     280  \return Specified scaleDraw for axis, or NULL if axis is invalid.
     281*/
     282QwtScaleDraw *QwtPlot::axisScaleDraw( int axisId )
    265283{
    266284    if ( !axisValid( axisId ) )
    267285        return NULL;
    268286
    269     return &d_axisData[axisId]->scaleDiv;
    270 }
    271 
    272 /*!
    273   \returns the scale draw of a specified axis
    274   \param axisId axis index
    275   \return specified scaleDraw for axis, or NULL if axis is invalid.
    276   \sa QwtScaleDraw
    277 */
    278 const QwtScaleDraw *QwtPlot::axisScaleDraw( int axisId ) const
    279 {
    280     if ( !axisValid( axisId ) )
    281         return NULL;
    282 
    283287    return axisWidget( axisId )->scaleDraw();
    284288}
    285289
    286290/*!
    287   \returns the scale draw of a specified axis
    288   \param axisId axis index
    289   \return specified scaleDraw for axis, or NULL if axis is invalid.
    290   \sa QwtScaleDraw
    291 */
    292 QwtScaleDraw *QwtPlot::axisScaleDraw( int axisId )
    293 {
    294     if ( !axisValid( axisId ) )
    295         return NULL;
    296 
    297     return axisWidget( axisId )->scaleDraw();
    298 }
    299 
    300 /*!
    301    Return the step size parameter, that has been set
    302    in setAxisScale. This doesn't need to be the step size
    303    of the current scale.
    304 
    305   \param axisId axis index
     291  \brief Return the step size parameter that has been set in setAxisScale.
     292
     293  This doesn't need to be the step size of the current scale.
     294
     295  \param axisId Axis index
    306296  \return step size parameter value
    307297
    308    \sa setAxisScale()
     298   \sa setAxisScale(), QwtScaleEngine::divideScale()
    309299*/
    310300double QwtPlot::axisStepSize( int axisId ) const
     
    321311  This is only a convenience function for axisScaleDiv( axisId )->interval();
    322312 
    323   \param axisId axis index
     313  \param axisId Axis index
    324314  \return Scale interval
    325315
     
    335325
    336326/*!
    337   \return the title of a specified axis
    338   \param axisId axis index
     327  \return Title of a specified axis
     328  \param axisId Axis index
    339329*/
    340330QwtText QwtPlot::axisTitle( int axisId ) const
     
    355345
    356346  Only xBottom and yLeft are enabled by default.
    357   \param axisId axis index
     347
     348  \param axisId Axis index
    358349  \param tf \c true (enabled) or \c false (disabled)
    359350*/
     
    370361  Transform the x or y coordinate of a position in the
    371362  drawing region into a value.
    372   \param axisId axis index
     363
     364  \param axisId Axis index
    373365  \param pos position
     366
     367  \return Position as axis coordinate
     368
    374369  \warning The position can be an x or a y coordinate,
    375370           depending on the specified axis.
     
    386381/*!
    387382  \brief Transform a value into a coordinate in the plotting region
    388   \param axisId axis index
     383
     384  \param axisId Axis index
    389385  \param value value
    390   \return X or y coordinate in the plotting region corresponding
     386  \return X or Y coordinate in the plotting region corresponding
    391387          to the value.
    392388*/
     
    401397/*!
    402398  \brief Change the font of an axis
    403   \param axisId axis index
    404   \param f font
     399
     400  \param axisId Axis index
     401  \param font Font
    405402  \warning This function changes the font of the tick labels,
    406403           not of the axis title.
    407404*/
    408 void QwtPlot::setAxisFont( int axisId, const QFont &f )
    409 {
    410     if ( axisValid( axisId ) )
    411         axisWidget( axisId )->setFont( f );
     405void QwtPlot::setAxisFont( int axisId, const QFont &font )
     406{
     407    if ( axisValid( axisId ) )
     408        axisWidget( axisId )->setFont( font );
    412409}
    413410
     
    418415  after a fixed scale has been set. Autoscaling is enabled by default.
    419416
    420   \param axisId axis index
     417  \param axisId Axis index
    421418  \param on On/Off
    422419  \sa setAxisScale(), setAxisScaleDiv(), updateAxes()
     
    436433/*!
    437434  \brief Disable autoscaling and specify a fixed scale for a selected axis.
    438   \param axisId axis index
    439   \param min
    440   \param max minimum and maximum of the scale
     435
     436  In updateAxes() the scale engine calculates a scale division from the
     437  specified parameters, that will be assigned to the scale widget. So
     438  updates of the scale widget usually happen delayed with the next replot.
     439
     440  \param axisId Axis index
     441  \param min Minimum of the scale
     442  \param max Maximum of the scale
    441443  \param stepSize Major step size. If <code>step == 0</code>, the step size is
    442             calculated automatically using the maxMajor setting.
    443   \sa setAxisMaxMajor(), setAxisAutoScale(), axisStepSize()
     444                  calculated automatically using the maxMajor setting.
     445
     446  \sa setAxisMaxMajor(), setAxisAutoScale(), axisStepSize(), QwtScaleEngine::divideScale()
    444447*/
    445448void QwtPlot::setAxisScale( int axisId, double min, double max, double stepSize )
     
    450453
    451454        d.doAutoScale = false;
    452         d.scaleDiv.invalidate();
     455        d.isValid = false;
    453456
    454457        d.minValue = min;
     
    462465/*!
    463466  \brief Disable autoscaling and specify a fixed scale for a selected axis.
    464   \param axisId axis index
     467
     468  The scale division will be stored locally only until the next call
     469  of updateAxes(). So updates of the scale widget usually happen delayed with
     470  the next replot.
     471
     472  \param axisId Axis index
    465473  \param scaleDiv Scale division
     474
    466475  \sa setAxisScale(), setAxisAutoScale()
    467476*/
     
    474483        d.doAutoScale = false;
    475484        d.scaleDiv = scaleDiv;
     485        d.isValid = true;
    476486
    477487        autoRefresh();
     
    481491/*!
    482492  \brief Set a scale draw
    483   \param axisId axis index
    484   \param scaleDraw object responsible for drawing scales.
     493
     494  \param axisId Axis index
     495  \param scaleDraw Object responsible for drawing scales.
    485496
    486497  By passing scaleDraw it is possible to extend QwtScaleDraw
     
    505516/*!
    506517  Change the alignment of the tick labels
    507   \param axisId axis index
     518
     519  \param axisId Axis index
    508520  \param alignment Or'd Qt::AlignmentFlags see <qnamespace.h>
     521
    509522  \sa QwtScaleDraw::setLabelAlignment()
    510523*/
     
    517530/*!
    518531  Rotate all tick labels
    519   \param axisId axis index
     532
     533  \param axisId Axis index
    520534  \param rotation Angle in degrees. When changing the label rotation,
    521535                  the label alignment might be adjusted too.
     536
    522537  \sa QwtScaleDraw::setLabelRotation(), setAxisLabelAlignment()
    523538*/
     
    531546  Set the maximum number of minor scale intervals for a specified axis
    532547
    533   \param axisId axis index
    534   \param maxMinor maximum number of minor steps
     548  \param axisId Axis index
     549  \param maxMinor Maximum number of minor steps
     550
    535551  \sa axisMaxMinor()
    536552*/
     
    545561        {
    546562            d.maxMinor = maxMinor;
    547             d.scaleDiv.invalidate();
     563            d.isValid = false;
    548564            autoRefresh();
    549565        }
     
    554570  Set the maximum number of major scale intervals for a specified axis
    555571
    556   \param axisId axis index
    557   \param maxMajor maximum number of major steps
     572  \param axisId Axis index
     573  \param maxMajor Maximum number of major steps
     574
    558575  \sa axisMaxMajor()
    559576*/
     
    568585        {
    569586            d.maxMajor = maxMajor;
    570             d.scaleDiv.invalidate();
     587            d.isValid = false;
    571588            autoRefresh();
    572589        }
     
    576593/*!
    577594  \brief Change the title of a specified axis
    578   \param axisId axis index
     595
     596  \param axisId Axis index
    579597  \param title axis title
    580598*/
     
    587605/*!
    588606  \brief Change the title of a specified axis
    589   \param axisId axis index
    590   \param title axis title
     607
     608  \param axisId Axis index
     609  \param title Axis title
    591610*/
    592611void QwtPlot::setAxisTitle( int axisId, const QwtText &title )
     
    596615}
    597616
    598 //! Rebuild the scales
     617/*!
     618  \brief Rebuild the axes scales
     619
     620  In case of autoscaling the boundaries of a scale are calculated
     621  from the bounding rectangles of all plot items, having the
     622  QwtPlotItem::AutoScale flag enabled ( QwtScaleEngine::autoScale() ).
     623  Then a scale division is calculated ( QwtScaleEngine::didvideScale() )
     624  and assigned to scale widget.
     625
     626  When the scale boundaries have been assigned with setAxisScale() a
     627  scale division is calculated ( QwtScaleEngine::didvideScale() )
     628  for this interval and assigned to the scale widget.
     629
     630  When the scale has been set explicitly by setAxisScaleDiv() the
     631  locally stored scale division gets assigned to the scale widget.
     632
     633  The scale widget indicates modifications by emitting a
     634  QwtScaleWidget::scaleDivChanged() signal.
     635
     636  updateAxes() is usually called by replot().
     637
     638  \sa setAxisAutoScale(), setAxisScale(), setAxisScaleDiv(), replot()
     639      QwtPlotItem::boundingRect()
     640 */
    599641void QwtPlot::updateAxes()
    600642{
     
    620662        {
    621663            const QRectF rect = item->boundingRect();
    622             intv[item->xAxis()] |= QwtInterval( rect.left(), rect.right() );
    623             intv[item->yAxis()] |= QwtInterval( rect.top(), rect.bottom() );
     664
     665            if ( rect.width() >= 0.0 )
     666                intv[item->xAxis()] |= QwtInterval( rect.left(), rect.right() );
     667
     668            if ( rect.height() >= 0.0 )
     669                intv[item->yAxis()] |= QwtInterval( rect.top(), rect.bottom() );
    624670        }
    625671    }
     
    637683        if ( d.doAutoScale && intv[axisId].isValid() )
    638684        {
    639             d.scaleDiv.invalidate();
     685            d.isValid = false;
    640686
    641687            minValue = intv[axisId].minValue();
     
    645691                minValue, maxValue, stepSize );
    646692        }
    647         if ( !d.scaleDiv.isValid() )
     693        if ( !d.isValid )
    648694        {
    649695            d.scaleDiv = d.scaleEngine->divideScale(
    650696                minValue, maxValue,
    651697                d.maxMajor, d.maxMinor, stepSize );
     698            d.isValid = true;
    652699        }
    653700
    654701        QwtScaleWidget *scaleWidget = axisWidget( axisId );
    655         scaleWidget->setScaleDiv(
    656             d.scaleEngine->transformation(), d.scaleDiv );
     702        scaleWidget->setScaleDiv( d.scaleDiv );
    657703
    658704        int startDist, endDist;
     
    664710    {
    665711        QwtPlotItem *item = *it;
    666         item->updateScaleDiv( *axisScaleDiv( item->xAxis() ),
    667             *axisScaleDiv( item->yAxis() ) );
    668     }
    669 }
    670 
     712        if ( item->testItemInterest( QwtPlotItem::ScaleInterest ) )
     713        {
     714            item->updateScaleDiv( axisScaleDiv( item->xAxis() ),
     715                axisScaleDiv( item->yAxis() ) );
     716        }
     717    }
     718}
     719
Note: See TracChangeset for help on using the changeset viewer.