Changeset 8127 in ntrip for trunk/BNC/qwt/qwt_plot_rescaler.cpp
- Timestamp:
- May 10, 2017, 3:20:54 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_plot_rescaler.cpp
r4271 r8127 10 10 #include "qwt_plot_rescaler.h" 11 11 #include "qwt_plot.h" 12 #include "qwt_plot_canvas.h"13 12 #include "qwt_scale_div.h" 14 13 #include "qwt_interval.h" 14 #include "qwt_plot_canvas.h" 15 15 #include <qevent.h> 16 16 #include <qalgorithms.h> … … 59 59 \sa setRescalePolicy(), setReferenceAxis() 60 60 */ 61 QwtPlotRescaler::QwtPlotRescaler( Q wtPlotCanvas*canvas,61 QwtPlotRescaler::QwtPlotRescaler( QWidget *canvas, 62 62 int referenceAxis, RescalePolicy policy ): 63 63 QObject( canvas ) … … 179 179 180 180 /*! 181 Return direction in which an axis should be expanded181 \return Direction in which an axis should be expanded 182 182 183 183 \param axis Axis index ( see QwtPlot::AxisId ) … … 224 224 225 225 /*! 226 Return aspect ratio between an axis and the reference axis.226 \return Aspect ratio between an axis and the reference axis. 227 227 228 228 \param axis Axis index ( see QwtPlot::AxisId ) … … 241 241 242 242 In Fitting mode, the hint is used as minimal interval 243 t aht always needs to be displayed.243 that always needs to be displayed. 244 244 245 245 \param axis Axis, see QwtPlot::Axis … … 268 268 269 269 //! \return plot canvas 270 Q wtPlotCanvas*QwtPlotRescaler::canvas()271 { 272 return qobject_cast<Q wtPlotCanvas*>( parent() );270 QWidget *QwtPlotRescaler::canvas() 271 { 272 return qobject_cast<QWidget *>( parent() ); 273 273 } 274 274 275 275 //! \return plot canvas 276 const Q wtPlotCanvas*QwtPlotRescaler::canvas() const277 { 278 return qobject_cast<const Q wtPlotCanvas*>( parent() );276 const QWidget *QwtPlotRescaler::canvas() const 277 { 278 return qobject_cast<const QWidget *>( parent() ); 279 279 } 280 280 … … 282 282 QwtPlot *QwtPlotRescaler::plot() 283 283 { 284 Q wtPlotCanvas*w = canvas();284 QWidget *w = canvas(); 285 285 if ( w ) 286 return w->plot();287 288 return NULL;286 w = w->parentWidget(); 287 288 return qobject_cast<QwtPlot *>( w ); 289 289 } 290 290 … … 292 292 const QwtPlot *QwtPlotRescaler::plot() const 293 293 { 294 const Q wtPlotCanvas*w = canvas();294 const QWidget *w = canvas(); 295 295 if ( w ) 296 return w->plot();297 298 return NULL;296 w = w->parentWidget(); 297 298 return qobject_cast<const QwtPlot *>( w ); 299 299 } 300 300 301 301 //! 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() )302 bool QwtPlotRescaler::eventFilter( QObject *object, QEvent *event ) 303 { 304 if ( object && object == canvas() ) 305 { 306 switch ( event->type() ) 307 307 { 308 308 case QEvent::Resize: 309 canvasResizeEvent( ( QResizeEvent * )e ); 309 { 310 canvasResizeEvent( static_cast<QResizeEvent *>( event ) ); 310 311 break; 312 } 311 313 case QEvent::PolishRequest: 314 { 312 315 rescale(); 313 316 break; 317 } 314 318 default:; 315 319 } … … 327 331 void QwtPlotRescaler::canvasResizeEvent( QResizeEvent* event ) 328 332 { 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; 332 340 333 341 rescale( oldSize, newSize ); … … 433 441 434 442 /*! 435 443 Synchronize an axis scale according to the scale of the reference axis 436 444 437 445 \param axis Axis index ( see QwtPlot::AxisId ) 438 446 \param reference Interval of the reference axis 439 447 \param size Size of the canvas 448 449 \return New interval for axis 440 450 */ 441 451 QwtInterval QwtPlotRescaler::syncScale( int axis, … … 467 477 468 478 /*! 469 Return orientation of an axis479 \return Orientation of an axis 470 480 \param axis Axis index ( see QwtPlot::AxisId ) 471 481 */ … … 479 489 480 490 /*! 481 Return interval of an axis482 \ param axis Axis index ( see QwtPlot::AxisId )491 \param axis Axis index ( see QwtPlot::AxisId ) 492 \return Normalized interval of an axis 483 493 */ 484 494 QwtInterval QwtPlotRescaler::interval( int axis ) const … … 487 497 return QwtInterval(); 488 498 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(); 495 500 } 496 501 … … 584 589 double v2 = intervals[axis].maxValue(); 585 590 586 if ( plt->axisScaleDiv( axis )->lowerBound() > 587 plt->axisScaleDiv( axis )->upperBound() ) 588 { 591 if ( !plt->axisScaleDiv( axis ).isIncreasing() ) 589 592 qSwap( v1, v2 ); 590 }591 593 592 594 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 ); 596 596 597 597 if ( d_data->inReplot >= 2 ) … … 610 610 } 611 611 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 } 615 620 616 621 plt->setAutoReplot( doReplot ); … … 620 625 d_data->inReplot--; 621 626 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.