Changeset 8127 in ntrip for trunk/BNC/qwt/qwt_plot_zoomer.cpp
- Timestamp:
- May 10, 2017, 3:20:54 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_plot_zoomer.cpp
r4271 r8127 10 10 #include "qwt_plot_zoomer.h" 11 11 #include "qwt_plot.h" 12 #include "qwt_plot_canvas.h"13 12 #include "qwt_scale_div.h" 14 13 #include "qwt_picker_machine.h" 15 14 #include <qalgorithms.h> 15 16 static QwtInterval qwtExpandedZoomInterval( double v1, double v2, 17 double minRange, const QwtTransform* transform ) 18 { 19 double min = v1; 20 double max = v2; 21 22 if ( max - min < minRange ) 23 { 24 min = 0.5 * ( min + max - minRange ); 25 max = min + minRange; 26 27 if ( transform ) 28 { 29 // f.e the logarithmic scale doesn't allow values 30 // outside [QwtLogTransform::LogMin/QwtLogTransform::LogMax] 31 32 double minBounded = transform->bounded( min ); 33 double maxBounded = transform->bounded( max ); 34 35 if ( minBounded != min ) 36 { 37 maxBounded = transform->bounded( minBounded + minRange ); 38 } 39 else if ( maxBounded != max ) 40 { 41 minBounded = transform->bounded( maxBounded - minRange ); 42 } 43 44 min = minBounded; 45 max = maxBounded; 46 } 47 } 48 49 return QwtInterval( min, max ); 50 } 51 52 static QRectF qwtExpandedZoomRect( const QRectF &zoomRect, const QSizeF &minSize, 53 const QwtTransform* transformX, const QwtTransform* transformY ) 54 { 55 QRectF r = zoomRect; 56 57 if ( minSize.width() > r.width() ) 58 { 59 const QwtInterval intv = qwtExpandedZoomInterval( 60 r.left(), r.right(), minSize.width(), transformX ); 61 62 r.setLeft( intv.minValue() ); 63 r.setRight( intv.maxValue() ); 64 } 65 66 if ( minSize.height() > r.height() ) 67 { 68 const QwtInterval intv = qwtExpandedZoomInterval( 69 zoomRect.top(), zoomRect.bottom(), minSize.height(), transformY ); 70 71 r.setTop( intv.minValue() ); 72 r.setBottom( intv.maxValue() ); 73 } 74 75 return r; 76 } 16 77 17 78 class QwtPlotZoomer::PrivateData … … 33 94 34 95 The zoomer is initialized with a QwtPickerDragRectMachine, 35 the tracker mode is set to QwtPicker::ActiveOnly and the rubber band96 the tracker mode is set to QwtPicker::ActiveOnly and the rubber band 36 97 is set to QwtPicker::RectRubberBand 37 98 38 99 \param canvas Plot canvas to observe, also the parent object 39 \param doReplot Call replotfor the attached plot before initializing100 \param doReplot Call QwtPlot::replot() for the attached plot before initializing 40 101 the zoomer with its scales. This might be necessary, 41 102 when the plot is in a state with pending scale changes. … … 43 104 \sa QwtPlot::autoReplot(), QwtPlot::replot(), setZoomBase() 44 105 */ 45 QwtPlotZoomer::QwtPlotZoomer( Q wtPlotCanvas*canvas, bool doReplot ):106 QwtPlotZoomer::QwtPlotZoomer( QWidget *canvas, bool doReplot ): 46 107 QwtPlotPicker( canvas ) 47 108 { … … 54 115 55 116 The zoomer is initialized with a QwtPickerDragRectMachine, 56 the tracker mode is set to QwtPicker::ActiveOnly and the rubber band117 the tracker mode is set to QwtPicker::ActiveOnly and the rubber band 57 118 is set to QwtPicker;;RectRubberBand 58 119 … … 60 121 \param yAxis Y axis of the zoomer 61 122 \param canvas Plot canvas to observe, also the parent object 62 \param doReplot Call replotfor the attached plot before initializing123 \param doReplot Call QwtPlot::replot() for the attached plot before initializing 63 124 the zoomer with its scales. This might be necessary, 64 125 when the plot is in a state with pending scale changes. … … 68 129 69 130 QwtPlotZoomer::QwtPlotZoomer( int xAxis, int yAxis, 70 Q wtPlotCanvas*canvas, bool doReplot ):131 QWidget *canvas, bool doReplot ): 71 132 QwtPlotPicker( xAxis, yAxis, canvas ) 72 133 { … … 141 202 142 203 /*! 143 Return the zoom stack. zoomStack()[0] is the zoom base,144 zoomStack()[1] the first zoomed rectangle.204 \return The zoom stack. zoomStack()[0] is the zoom base, 205 zoomStack()[1] the first zoomed rectangle. 145 206 146 207 \sa setZoomStack(), zoomRectIndex() … … 163 224 Reinitialized the zoom stack with scaleRect() as base. 164 225 165 \param doReplot Call replotfor the attached plot before initializing226 \param doReplot Call QwtPlot::replot() for the attached plot before initializing 166 227 the zoomer with its scales. This might be necessary, 167 228 when the plot is in a state with pending scale changes. … … 189 250 190 251 base is united with the current scaleRect() and the zoom stack is 191 reinit alized with it as zoom base. plot is zoomed to scaleRect().252 reinitialized with it as zoom base. plot is zoomed to scaleRect(). 192 253 193 254 \param base Zoom base … … 218 279 219 280 /*! 220 Rectangle at the current position on the zoom stack. 221 281 \return Rectangle at the current position on the zoom stack. 222 282 \sa zoomRectIndex(), scaleRect(). 223 283 */ … … 239 299 240 300 Clears all rectangles above the current position of the 241 zoom stack and push s the normalized recton it.301 zoom stack and pushes the normalized rectangle on it. 242 302 243 303 \note If the maximal stack depth is reached, zoom is ignored. … … 275 335 276 336 Activate a rectangle on the zoom stack with an offset relative 277 to the current position. Negative values of off est will zoom out,337 to the current position. Negative values of offset will zoom out, 278 338 positive zoom in. A value of 0 zooms out to the zoom base. 279 339 … … 344 404 Adjust the observed plot to zoomRect() 345 405 346 \note Initiates QwtPlot::replot 406 \note Initiates QwtPlot::replot() 347 407 */ 348 408 … … 361 421 double x1 = rect.left(); 362 422 double x2 = rect.right(); 363 if ( plt->axisScaleDiv( xAxis() )->lowerBound() > 364 plt->axisScaleDiv( xAxis() )->upperBound() ) 365 { 423 if ( !plt->axisScaleDiv( xAxis() ).isIncreasing() ) 366 424 qSwap( x1, x2 ); 367 }368 425 369 426 plt->setAxisScale( xAxis(), x1, x2 ); … … 371 428 double y1 = rect.top(); 372 429 double y2 = rect.bottom(); 373 if ( plt->axisScaleDiv( yAxis() )->lowerBound() > 374 plt->axisScaleDiv( yAxis() )->upperBound() ) 375 { 430 if ( !plt->axisScaleDiv( yAxis() ).isIncreasing() ) 376 431 qSwap( y1, y2 ); 377 } 432 378 433 plt->setAxisScale( yAxis(), y1, y2 ); 379 434 … … 495 550 \brief Check and correct a selected rectangle 496 551 497 Reject rectangles with a h ight or width < 2, otherwise552 Reject rectangles with a height or width < 2, otherwise 498 553 expand the selected rectangle to a minimum size of 11x11 499 554 and accept it. 500 555 501 \return true If rectis accepted, or has been changed502 to a accepted rectangle.556 \return true If the rectangle is accepted, or has been changed 557 to an accepted one. 503 558 */ 504 559 … … 573 628 if accepted. 574 629 630 \param ok If true, complete the selection and emit selected signals 631 otherwise discard the selection. 632 575 633 \sa accept(), minZoomSize() 634 \return True if the selection has been accepted, false otherwise 576 635 */ 577 636 bool QwtPlotZoomer::end( bool ok ) … … 592 651 rect = rect.normalized(); 593 652 594 QRectF zoomRect = invTransform( rect ).normalized(); 595 596 const QSizeF minSize = minZoomSize(); 597 if ( minSize.isValid() ) 598 { 599 const QPointF center = zoomRect.center(); 600 zoomRect.setSize( zoomRect.size().expandedTo( minZoomSize() ) ); 601 zoomRect.moveCenter( center ); 602 } 653 const QwtScaleMap xMap = plot->canvasMap( xAxis() ); 654 const QwtScaleMap yMap = plot->canvasMap( yAxis() ); 655 656 QRectF zoomRect = QwtScaleMap::invTransform( xMap, yMap, rect ).normalized(); 657 658 zoomRect = qwtExpandedZoomRect( zoomRect, minZoomSize(), 659 xMap.transformation(), yMap.transformation() ); 603 660 604 661 zoom( zoomRect );
Note:
See TracChangeset
for help on using the changeset viewer.