Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_plot_picker.cpp
- Timestamp:
- Nov 3, 2026, 10:53:35 AM (3 weeks ago)
- File:
-
- 1 edited
-
trunk/BNC/qwt/qwt_plot_picker.cpp (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_plot_picker.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 10 10 #include "qwt_plot_picker.h" 11 11 #include "qwt_plot.h" 12 #include "qwt_text.h" 12 13 #include "qwt_scale_div.h" 13 #include "qwt_painter.h"14 14 #include "qwt_scale_map.h" 15 15 #include "qwt_picker_machine.h" 16 16 17 /*! 18 \brief Create a plot picker 19 20 The picker is set to those x- and y-axis of the plot 21 that are enabled. If both or no x-axis are enabled, the picker 22 is set to QwtPlot::xBottom. If both or no y-axis are 23 enabled, it is set to QwtPlot::yLeft. 24 25 \param canvas Plot canvas to observe, also the parent object 26 27 \sa QwtPlot::autoReplot(), QwtPlot::replot(), scaleRect() 28 */ 29 30 QwtPlotPicker::QwtPlotPicker( QWidget *canvas ): 31 QwtPicker( canvas ), 32 d_xAxis( -1 ), 33 d_yAxis( -1 ) 34 { 17 class QwtPlotPicker::PrivateData 18 { 19 public: 20 PrivateData(): 21 xAxisId( -1 ), 22 yAxisId( -1 ) 23 { 24 } 25 26 QwtAxisId xAxisId; 27 QwtAxisId yAxisId; 28 }; 29 30 /*! 31 \brief Create a plot picker 32 33 The picker is set to those x- and y-axis of the plot 34 that are enabled. If both or no x-axis are enabled, the picker 35 is set to QwtAxis::XBottom. If both or no y-axis are 36 enabled, it is set to QwtAxis::YLeft. 37 38 \param canvas Plot canvas to observe, also the parent object 39 40 \sa QwtPlot::autoReplot(), QwtPlot::replot(), scaleRect() 41 */ 42 43 QwtPlotPicker::QwtPlotPicker( QWidget* canvas ) 44 : QwtPicker( canvas ) 45 { 46 m_data = new PrivateData; 47 35 48 if ( !canvas ) 36 49 return; 37 50 51 const QwtPlot* plot = QwtPlotPicker::plot(); 38 52 // attach axes 39 53 40 int xAxis = QwtPlot::xBottom; 41 42 const QwtPlot *plot = QwtPlotPicker::plot(); 43 if ( !plot->axisEnabled( QwtPlot::xBottom ) && 44 plot->axisEnabled( QwtPlot::xTop ) ) 45 { 46 xAxis = QwtPlot::xTop; 47 } 48 49 int yAxis = QwtPlot::yLeft; 50 if ( !plot->axisEnabled( QwtPlot::yLeft ) && 51 plot->axisEnabled( QwtPlot::yRight ) ) 52 { 53 yAxis = QwtPlot::yRight; 54 } 55 56 setAxis( xAxis, yAxis ); 57 } 58 59 /*! 60 Create a plot picker 61 62 \param xAxis Set the x axis of the picker 63 \param yAxis Set the y axis of the picker 64 \param canvas Plot canvas to observe, also the parent object 65 66 \sa QwtPlot::autoReplot(), QwtPlot::replot(), scaleRect() 67 */ 68 QwtPlotPicker::QwtPlotPicker( int xAxis, int yAxis, QWidget *canvas ): 69 QwtPicker( canvas ), 70 d_xAxis( xAxis ), 71 d_yAxis( yAxis ) 72 { 73 } 74 75 /*! 76 Create a plot picker 77 78 \param xAxis X axis of the picker 79 \param yAxis Y axis of the picker 80 \param rubberBand Rubber band style 81 \param trackerMode Tracker mode 82 \param canvas Plot canvas to observe, also the parent object 83 84 \sa QwtPicker, QwtPicker::setSelectionFlags(), QwtPicker::setRubberBand(), 54 using namespace QwtAxis; 55 56 int xAxis = XBottom; 57 if ( !plot->isAxisVisible( XBottom ) && plot->isAxisVisible( XTop ) ) 58 xAxis = XTop; 59 60 int yAxis = YLeft; 61 if ( !plot->isAxisVisible( YLeft ) && plot->isAxisVisible( YRight ) ) 62 yAxis = YRight; 63 64 setAxes( xAxis, yAxis ); 65 } 66 67 /*! 68 Create a plot picker 69 70 \param xAxisId X axis of the picker 71 \param yAxisId Y axis of the picker 72 \param canvas Plot canvas to observe, also the parent object 73 74 \sa QwtPlot::autoReplot(), QwtPlot::replot(), scaleRect() 75 */ 76 QwtPlotPicker::QwtPlotPicker( QwtAxisId xAxisId, QwtAxisId yAxisId, QWidget* canvas ) 77 : QwtPicker( canvas ) 78 { 79 m_data = new PrivateData; 80 m_data->xAxisId = xAxisId; 81 m_data->yAxisId = yAxisId; 82 } 83 84 /*! 85 Create a plot picker 86 87 \param xAxisId X axis of the picker 88 \param yAxisId Y axis of the picker 89 \param rubberBand Rubber band style 90 \param trackerMode Tracker mode 91 \param canvas Plot canvas to observe, also the parent object 92 93 \sa QwtPicker, QwtPicker::setSelectionFlags(), QwtPicker::setRubberBand(), 85 94 QwtPicker::setTrackerMode 86 95 87 \sa QwtPlot::autoReplot(), QwtPlot::replot(), scaleRect() 88 */ 89 QwtPlotPicker::QwtPlotPicker( int xAxis, int yAxis,90 RubberBand rubberBand, DisplayMode trackerMode, 91 QWidget *canvas ):92 QwtPicker( rubberBand, trackerMode, canvas ), 93 d_xAxis( xAxis ),94 d_yAxis( yAxis )95 { 96 \sa QwtPlot::autoReplot(), QwtPlot::replot(), scaleRect() 97 */ 98 QwtPlotPicker::QwtPlotPicker( QwtAxisId xAxisId, QwtAxisId yAxisId, 99 RubberBand rubberBand, DisplayMode trackerMode, QWidget* canvas ) 100 : QwtPicker( rubberBand, trackerMode, canvas ) 101 { 102 m_data = new PrivateData; 103 m_data->xAxisId = xAxisId; 104 m_data->yAxisId = yAxisId; 96 105 } 97 106 … … 99 108 QwtPlotPicker::~QwtPlotPicker() 100 109 { 110 delete m_data; 101 111 } 102 112 103 113 //! \return Observed plot canvas 104 QWidget *QwtPlotPicker::canvas()114 QWidget* QwtPlotPicker::canvas() 105 115 { 106 116 return parentWidget(); … … 108 118 109 119 //! \return Observed plot canvas 110 const QWidget *QwtPlotPicker::canvas() const120 const QWidget* QwtPlotPicker::canvas() const 111 121 { 112 122 return parentWidget(); … … 114 124 115 125 //! \return Plot widget, containing the observed plot canvas 116 QwtPlot *QwtPlotPicker::plot()117 { 118 QWidget *w = canvas();126 QwtPlot* QwtPlotPicker::plot() 127 { 128 QWidget* w = canvas(); 119 129 if ( w ) 120 130 w = w->parentWidget(); 121 131 122 return qobject_cast<QwtPlot *>( w );132 return qobject_cast< QwtPlot* >( w ); 123 133 } 124 134 125 135 //! \return Plot widget, containing the observed plot canvas 126 const QwtPlot *QwtPlotPicker::plot() const127 { 128 const QWidget *w = canvas();136 const QwtPlot* QwtPlotPicker::plot() const 137 { 138 const QWidget* w = canvas(); 129 139 if ( w ) 130 140 w = w->parentWidget(); 131 141 132 return qobject_cast<const QwtPlot *>( w );133 } 134 135 /*! 136 \return Normalized bounding rectangle of the axes 137 \sa QwtPlot::autoReplot(), QwtPlot::replot(). 138 */ 142 return qobject_cast< const QwtPlot* >( w ); 143 } 144 145 /*! 146 \return Normalized bounding rectangle of the axes 147 \sa QwtPlot::autoReplot(), QwtPlot::replot(). 148 */ 139 149 QRectF QwtPlotPicker::scaleRect() const 140 150 { … … 143 153 if ( plot() ) 144 154 { 145 const QwtScaleDiv &xs = plot()->axisScaleDiv( xAxis() );146 const QwtScaleDiv &ys = plot()->axisScaleDiv( yAxis() );155 const QwtScaleDiv& xs = plot()->axisScaleDiv( xAxis() ); 156 const QwtScaleDiv& ys = plot()->axisScaleDiv( yAxis() ); 147 157 148 158 rect = QRectF( xs.lowerBound(), ys.lowerBound(), … … 155 165 156 166 /*! 157 Set the x and y axes of the picker 158 159 \param xAxis X axis 160 \param yAxis Y axis 161 */ 162 void QwtPlotPicker::setAx is( int xAxis, int yAxis)163 { 164 const QwtPlot *plt = plot();167 Set the x and y axes of the picker 168 169 \param xAxisId X axis 170 \param yAxisId Y axis 171 */ 172 void QwtPlotPicker::setAxes( QwtAxisId xAxisId, QwtAxisId yAxisId ) 173 { 174 const QwtPlot* plt = plot(); 165 175 if ( !plt ) 166 176 return; 167 177 168 if ( xAxis != d_xAxis|| yAxis!= d_yAxis)169 { 170 d_xAxis= xAxis;171 d_yAxis= yAxis;178 if ( xAxisId != m_data->xAxisId || yAxisId != m_data->yAxisId ) 179 { 180 m_data->xAxisId = xAxisId; 181 m_data->yAxisId = yAxisId; 172 182 } 173 183 } 174 184 175 185 //! Return x axis 176 intQwtPlotPicker::xAxis() const177 { 178 return d_xAxis;186 QwtAxisId QwtPlotPicker::xAxis() const 187 { 188 return m_data->xAxisId; 179 189 } 180 190 181 191 //! Return y axis 182 intQwtPlotPicker::yAxis() const183 { 184 return d_yAxis;185 } 186 187 /*! 188 Translate a pixel position into a position string 189 190 \param pos Position in pixel coordinates 191 \return Position string 192 */ 193 QwtText QwtPlotPicker::trackerText( const QPoint &pos ) const192 QwtAxisId QwtPlotPicker::yAxis() const 193 { 194 return m_data->yAxisId; 195 } 196 197 /*! 198 Translate a pixel position into a position string 199 200 \param pos Position in pixel coordinates 201 \return Position string 202 */ 203 QwtText QwtPlotPicker::trackerText( const QPoint& pos ) const 194 204 { 195 205 if ( plot() == NULL ) … … 200 210 201 211 /*! 202 \brief Translate a position into a position string 203 204 In case of HLineRubberBand the label is the value of the 205 y position, in case of VLineRubberBand the value of the x position. 206 Otherwise the label contains x and y position separated by a ',' . 207 208 The format for the double to string conversion is "%.4f". 209 210 \param pos Position 211 \return Position string 212 */ 213 QwtText QwtPlotPicker::trackerTextF( const QPointF &pos ) const212 \brief Translate a position into a position string 213 214 In case of HLineRubberBand the label is the value of the 215 y position, in case of VLineRubberBand the value of the x position. 216 Otherwise the label contains x and y position separated by a ',' . 217 218 The format for the double to string conversion is "%.4f". 219 220 \param pos Position 221 \return Position string 222 */ 223 QwtText QwtPlotPicker::trackerTextF( const QPointF& pos ) const 214 224 { 215 225 QString text; … … 218 228 { 219 229 case HLineRubberBand: 220 text .sprintf( "%.4f",pos.y() );230 text = QString::number( pos.y(), 'f', 4 ); 221 231 break; 222 232 case VLineRubberBand: 223 text .sprintf( "%.4f",pos.x() );233 text = QString::number( pos.x(), 'f', 4 ); 224 234 break; 225 235 default: 226 text.sprintf( "%.4f, %.4f", pos.x(), pos.y() ); 236 text = QString::number( pos.x(), 'f', 4 ) 237 + ", " + QString::number( pos.y(), 'f', 4 ); 227 238 } 228 239 return QwtText( text ); … … 230 241 231 242 /*! 232 Append a point to the selection and update rubber band and tracker. 233 234 \param pos Additional point 235 \sa isActive, begin(), end(), move(), appended() 236 237 \note The appended(const QPoint &), appended(const QDoublePoint &) 243 Append a point to the selection and update rubber band and tracker. 244 245 \param pos Additional point 246 \sa isActive, begin(), end(), move(), appended() 247 248 \note The appended(const QPoint &), appended(const QDoublePoint &) 238 249 signals are emitted. 239 */ 240 void QwtPlotPicker::append( const QPoint &pos )250 */ 251 void QwtPlotPicker::append( const QPoint& pos ) 241 252 { 242 253 QwtPicker::append( pos ); … … 245 256 246 257 /*! 247 Move the last point of the selection 248 249 \param pos New position 250 \sa isActive, begin(), end(), append() 251 252 \note The moved(const QPoint &), moved(const QDoublePoint &) 258 Move the last point of the selection 259 260 \param pos New position 261 \sa isActive, begin(), end(), append() 262 263 \note The moved(const QPoint &), moved(const QDoublePoint &) 253 264 signals are emitted. 254 */ 255 void QwtPlotPicker::move( const QPoint &pos )265 */ 266 void QwtPlotPicker::move( const QPoint& pos ) 256 267 { 257 268 QwtPicker::move( pos ); … … 260 271 261 272 /*! 262 Close a selection setting the state to inactive. 263 264 \param ok If true, complete the selection and emit selected signals 273 Close a selection setting the state to inactive. 274 275 \param ok If true, complete the selection and emit selected signals 265 276 otherwise discard the selection. 266 \return True if the selection has been accepted, false otherwise 267 */ 277 \return True if the selection has been accepted, false otherwise 278 */ 268 279 269 280 bool QwtPlotPicker::end( bool ok ) … … 273 284 return false; 274 285 275 QwtPlot *plot = QwtPlotPicker::plot();286 QwtPlot* plot = QwtPlotPicker::plot(); 276 287 if ( !plot ) 277 288 return false; … … 309 320 case QwtPickerMachine::PolygonSelection: 310 321 { 311 QVector< QPointF> dpa( points.count() );322 QVector< QPointF > dpa( points.count() ); 312 323 for ( int i = 0; i < points.count(); i++ ) 313 324 dpa[i] = invTransform( points[i] ); … … 327 338 \return Rectangle in plot coordinates 328 339 \sa transform() 329 */ 330 QRectF QwtPlotPicker::invTransform( const QRect &rect ) const331 { 332 const QwtScaleMap xMap = plot()->canvasMap( d_xAxis);333 const QwtScaleMap yMap = plot()->canvasMap( d_yAxis);340 */ 341 QRectF QwtPlotPicker::invTransform( const QRect& rect ) const 342 { 343 const QwtScaleMap xMap = plot()->canvasMap( xAxis() ); 344 const QwtScaleMap yMap = plot()->canvasMap( yAxis() ); 334 345 335 346 return QwtScaleMap::invTransform( xMap, yMap, rect ); … … 340 351 \return Rectangle in pixel coordinates 341 352 \sa invTransform() 342 */ 343 QRect QwtPlotPicker::transform( const QRectF &rect ) const344 { 345 const QwtScaleMap xMap = plot()->canvasMap( d_xAxis);346 const QwtScaleMap yMap = plot()->canvasMap( d_yAxis);353 */ 354 QRect QwtPlotPicker::transform( const QRectF& rect ) const 355 { 356 const QwtScaleMap xMap = plot()->canvasMap( xAxis() ); 357 const QwtScaleMap yMap = plot()->canvasMap( yAxis() ); 347 358 348 359 return QwtScaleMap::transform( xMap, yMap, rect ).toRect(); … … 353 364 \return Point in plot coordinates 354 365 \sa transform() 355 */ 356 QPointF QwtPlotPicker::invTransform( const QPoint &pos ) const357 { 358 QwtScaleMap xMap = plot()->canvasMap( d_xAxis);359 QwtScaleMap yMap = plot()->canvasMap( d_yAxis);366 */ 367 QPointF QwtPlotPicker::invTransform( const QPoint& pos ) const 368 { 369 const QwtScaleMap xMap = plot()->canvasMap( xAxis() ); 370 const QwtScaleMap yMap = plot()->canvasMap( yAxis() ); 360 371 361 372 return QPointF( 362 373 xMap.invTransform( pos.x() ), 363 374 yMap.invTransform( pos.y() ) 364 ); 375 ); 365 376 } 366 377 … … 369 380 \return Point in pixel coordinates 370 381 \sa invTransform() 371 */ 372 QPoint QwtPlotPicker::transform( const QPointF &pos ) const 373 { 374 QwtScaleMap xMap = plot()->canvasMap( d_xAxis ); 375 QwtScaleMap yMap = plot()->canvasMap( d_yAxis ); 376 377 const QPointF p( xMap.transform( pos.x() ), 378 yMap.transform( pos.y() ) ); 382 */ 383 QPoint QwtPlotPicker::transform( const QPointF& pos ) const 384 { 385 const QwtScaleMap xMap = plot()->canvasMap( xAxis() ); 386 const QwtScaleMap yMap = plot()->canvasMap( yAxis() ); 387 388 const QPointF p( xMap.transform( pos.x() ), yMap.transform( pos.y() ) ); 379 389 380 390 return p.toPoint(); 381 391 } 392 393 #include "moc_qwt_plot_picker.cpp"
Note:
See TracChangeset
for help on using the changeset viewer.
