Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_plot_grid.cpp
- Timestamp:
- Nov 3, 2026, 10:53:35 AM (3 weeks ago)
- File:
-
- 1 edited
-
trunk/BNC/qwt/qwt_plot_grid.cpp (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_plot_grid.cpp
r8127 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 13 13 #include "qwt_scale_map.h" 14 14 #include "qwt_scale_div.h" 15 #include "qwt_math.h" 15 16 16 #include <qpainter.h> 17 17 #include <qpen.h> 18 18 19 static inline bool qwtFuzzyGreaterOrEqual( double d1, double d2 ) 20 { 21 return ( d1 >= d2 ) || qFuzzyCompare( d1, d2 ); 22 } 23 19 24 class QwtPlotGrid::PrivateData 20 25 { 21 public: 22 PrivateData() :23 xEnabled( true ) ,24 yEnabled( true ) ,25 xMinEnabled( false ) ,26 yMinEnabled( false ) 26 public: 27 PrivateData() 28 : xEnabled( true ) 29 , yEnabled( true ) 30 , xMinEnabled( false ) 31 , yMinEnabled( false ) 27 32 { 28 33 } … … 41 46 42 47 //! Enables major grid, disables minor grid 43 QwtPlotGrid::QwtPlotGrid() :44 QwtPlotItem( QwtText( "Grid" ) ) 45 { 46 d_data = new PrivateData;48 QwtPlotGrid::QwtPlotGrid() 49 : QwtPlotItem( QwtText( "Grid" ) ) 50 { 51 m_data = new PrivateData; 47 52 48 53 setItemInterest( QwtPlotItem::ScaleInterest, true ); … … 53 58 QwtPlotGrid::~QwtPlotGrid() 54 59 { 55 delete d_data;60 delete m_data; 56 61 } 57 62 … … 63 68 64 69 /*! 65 \brief Enable or disable vertical grid lines 66 \param on Enable (true) or disable 67 68 \sa Minor grid lines can be enabled or disabled with 70 \brief Enable or disable vertical grid lines 71 \param on Enable (true) or disable 72 73 \sa Minor grid lines can be enabled or disabled with 69 74 enableXMin() 70 */ 75 */ 71 76 void QwtPlotGrid::enableX( bool on ) 72 77 { 73 if ( d_data->xEnabled != on )74 { 75 d_data->xEnabled = on;76 77 legendChanged(); 78 itemChanged(); 79 } 80 } 81 82 /*! 83 \brief Enable or disable horizontal grid lines 84 \param on Enable (true) or disable 85 \sa Minor grid lines can be enabled or disabled with enableYMin() 86 */ 78 if ( m_data->xEnabled != on ) 79 { 80 m_data->xEnabled = on; 81 82 legendChanged(); 83 itemChanged(); 84 } 85 } 86 87 /*! 88 \brief Enable or disable horizontal grid lines 89 \param on Enable (true) or disable 90 \sa Minor grid lines can be enabled or disabled with enableYMin() 91 */ 87 92 void QwtPlotGrid::enableY( bool on ) 88 93 { 89 if ( d_data->yEnabled != on )90 { 91 d_data->yEnabled = on;92 93 legendChanged(); 94 itemChanged(); 95 } 96 } 97 98 /*! 99 \brief Enable or disable minor vertical grid lines. 100 \param on Enable (true) or disable 101 \sa enableX() 102 */ 94 if ( m_data->yEnabled != on ) 95 { 96 m_data->yEnabled = on; 97 98 legendChanged(); 99 itemChanged(); 100 } 101 } 102 103 /*! 104 \brief Enable or disable minor vertical grid lines. 105 \param on Enable (true) or disable 106 \sa enableX() 107 */ 103 108 void QwtPlotGrid::enableXMin( bool on ) 104 109 { 105 if ( d_data->xMinEnabled != on )106 { 107 d_data->xMinEnabled = on;108 109 legendChanged(); 110 itemChanged(); 111 } 112 } 113 114 /*! 115 \brief Enable or disable minor horizontal grid lines 116 \param on Enable (true) or disable 117 \sa enableY() 118 */ 110 if ( m_data->xMinEnabled != on ) 111 { 112 m_data->xMinEnabled = on; 113 114 legendChanged(); 115 itemChanged(); 116 } 117 } 118 119 /*! 120 \brief Enable or disable minor horizontal grid lines 121 \param on Enable (true) or disable 122 \sa enableY() 123 */ 119 124 void QwtPlotGrid::enableYMin( bool on ) 120 125 { 121 if ( d_data->yMinEnabled != on )122 { 123 d_data->yMinEnabled = on;124 125 legendChanged(); 126 itemChanged(); 127 } 128 } 129 130 /*! 131 Assign an x axis scale division 132 133 \param scaleDiv Scale division 134 */ 135 void QwtPlotGrid::setXDiv( const QwtScaleDiv &scaleDiv )136 { 137 if ( d_data->xScaleDiv != scaleDiv )138 { 139 d_data->xScaleDiv = scaleDiv;140 itemChanged(); 141 } 142 } 143 144 /*! 145 Assign a y axis division 146 147 \param scaleDiv Scale division 148 */ 149 void QwtPlotGrid::setYDiv( const QwtScaleDiv &scaleDiv )150 { 151 if ( d_data->yScaleDiv != scaleDiv )152 { 153 d_data->yScaleDiv = scaleDiv;154 itemChanged(); 155 } 156 } 157 158 /*! 159 Build and assign a pen for both major and minor grid lines 160 161 In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it 162 non cosmetic ( see QPen::isCosmetic() ). This method has been introduced 163 to hide this incompatibility. 164 165 \param color Pen color 166 \param width Pen width 167 \param style Pen style 168 169 \sa pen(), brush() 170 */ 171 void QwtPlotGrid::setPen( const QColor &color, qreal width, Qt::PenStyle style )126 if ( m_data->yMinEnabled != on ) 127 { 128 m_data->yMinEnabled = on; 129 130 legendChanged(); 131 itemChanged(); 132 } 133 } 134 135 /*! 136 Assign an x axis scale division 137 138 \param scaleDiv Scale division 139 */ 140 void QwtPlotGrid::setXDiv( const QwtScaleDiv& scaleDiv ) 141 { 142 if ( m_data->xScaleDiv != scaleDiv ) 143 { 144 m_data->xScaleDiv = scaleDiv; 145 itemChanged(); 146 } 147 } 148 149 /*! 150 Assign a y axis division 151 152 \param scaleDiv Scale division 153 */ 154 void QwtPlotGrid::setYDiv( const QwtScaleDiv& scaleDiv ) 155 { 156 if ( m_data->yScaleDiv != scaleDiv ) 157 { 158 m_data->yScaleDiv = scaleDiv; 159 itemChanged(); 160 } 161 } 162 163 /*! 164 Build and assign a pen for both major and minor grid lines 165 166 In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it 167 non cosmetic ( see QPen::isCosmetic() ). This method has been introduced 168 to hide this incompatibility. 169 170 \param color Pen color 171 \param width Pen width 172 \param style Pen style 173 174 \sa pen(), brush() 175 */ 176 void QwtPlotGrid::setPen( const QColor& color, qreal width, Qt::PenStyle style ) 172 177 { 173 178 setPen( QPen( color, width, style ) ); … … 175 180 176 181 /*! 177 Assign a pen for both major and minor grid lines 178 179 \param pen Pen 180 \sa setMajorPen(), setMinorPen() 181 */ 182 void QwtPlotGrid::setPen( const QPen &pen )183 { 184 if ( d_data->majorPen != pen ||d_data->minorPen != pen )185 { 186 d_data->majorPen = pen;187 d_data->minorPen = pen;188 189 legendChanged(); 190 itemChanged(); 191 } 192 } 193 194 /*! 195 Build and assign a pen for both major grid lines 196 197 In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it 198 non cosmetic ( see QPen::isCosmetic() ). This method has been introduced 199 to hide this incompatibility. 200 201 \param color Pen color 202 \param width Pen width 203 \param style Pen style 204 205 \sa pen(), brush() 206 */ 207 void QwtPlotGrid::setMajorPen( const QColor &color, qreal width, Qt::PenStyle style )182 Assign a pen for both major and minor grid lines 183 184 \param pen Pen 185 \sa setMajorPen(), setMinorPen() 186 */ 187 void QwtPlotGrid::setPen( const QPen& pen ) 188 { 189 if ( m_data->majorPen != pen || m_data->minorPen != pen ) 190 { 191 m_data->majorPen = pen; 192 m_data->minorPen = pen; 193 194 legendChanged(); 195 itemChanged(); 196 } 197 } 198 199 /*! 200 Build and assign a pen for both major grid lines 201 202 In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it 203 non cosmetic ( see QPen::isCosmetic() ). This method has been introduced 204 to hide this incompatibility. 205 206 \param color Pen color 207 \param width Pen width 208 \param style Pen style 209 210 \sa pen(), brush() 211 */ 212 void QwtPlotGrid::setMajorPen( const QColor& color, qreal width, Qt::PenStyle style ) 208 213 { 209 214 setMajorPen( QPen( color, width, style ) ); … … 211 216 212 217 /*! 213 Assign a pen for the major grid lines 214 215 \param pen Pen 216 \sa majorPen(), setMinorPen(), setPen() 217 */ 218 void QwtPlotGrid::setMajorPen( const QPen &pen )219 { 220 if ( d_data->majorPen != pen )221 { 222 d_data->majorPen = pen;223 224 legendChanged(); 225 itemChanged(); 226 } 227 } 228 229 /*! 230 Build and assign a pen for the minor grid lines 231 232 In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it 233 non cosmetic ( see QPen::isCosmetic() ). This method has been introduced 234 to hide this incompatibility. 235 236 \param color Pen color 237 \param width Pen width 238 \param style Pen style 239 240 \sa pen(), brush() 241 */ 242 void QwtPlotGrid::setMinorPen( const QColor &color, qreal width, Qt::PenStyle style )218 Assign a pen for the major grid lines 219 220 \param pen Pen 221 \sa majorPen(), setMinorPen(), setPen() 222 */ 223 void QwtPlotGrid::setMajorPen( const QPen& pen ) 224 { 225 if ( m_data->majorPen != pen ) 226 { 227 m_data->majorPen = pen; 228 229 legendChanged(); 230 itemChanged(); 231 } 232 } 233 234 /*! 235 Build and assign a pen for the minor grid lines 236 237 In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it 238 non cosmetic ( see QPen::isCosmetic() ). This method has been introduced 239 to hide this incompatibility. 240 241 \param color Pen color 242 \param width Pen width 243 \param style Pen style 244 245 \sa pen(), brush() 246 */ 247 void QwtPlotGrid::setMinorPen( const QColor& color, qreal width, Qt::PenStyle style ) 243 248 { 244 249 setMinorPen( QPen( color, width, style ) ); … … 246 251 247 252 /*! 248 Assign a pen for the minor grid lines 249 250 \param pen Pen 251 \sa minorPen(), setMajorPen(), setPen() 252 */ 253 void QwtPlotGrid::setMinorPen( const QPen &pen )254 { 255 if ( d_data->minorPen != pen )256 { 257 d_data->minorPen = pen;258 259 legendChanged(); 260 itemChanged(); 261 } 262 } 263 264 /*! 265 \brief Draw the grid 266 267 The grid is drawn into the bounding rectangle such that 268 grid lines begin and end at the rectangle's borders. The X and Y 269 maps are used to map the scale divisions into the drawing region 270 screen. 271 272 \param painter Painter 273 \param xMap X axis map 274 \param yMap Y axis 275 \param canvasRect Contents rectangle of the plot canvas 276 */ 277 void QwtPlotGrid::draw( QPainter *painter,278 const QwtScaleMap &xMap, const QwtScaleMap&yMap,279 const QRectF &canvasRect ) const253 Assign a pen for the minor grid lines 254 255 \param pen Pen 256 \sa minorPen(), setMajorPen(), setPen() 257 */ 258 void QwtPlotGrid::setMinorPen( const QPen& pen ) 259 { 260 if ( m_data->minorPen != pen ) 261 { 262 m_data->minorPen = pen; 263 264 legendChanged(); 265 itemChanged(); 266 } 267 } 268 269 /*! 270 \brief Draw the grid 271 272 The grid is drawn into the bounding rectangle such that 273 grid lines begin and end at the rectangle's borders. The X and Y 274 maps are used to map the scale divisions into the drawing region 275 screen. 276 277 \param painter Painter 278 \param xMap X axis map 279 \param yMap Y axis 280 \param canvasRect Contents rectangle of the plot canvas 281 */ 282 void QwtPlotGrid::draw( QPainter* painter, 283 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 284 const QRectF& canvasRect ) const 280 285 { 281 286 // draw minor grid lines 282 QPen minorPen = d_data->minorPen;287 QPen minorPen = m_data->minorPen; 283 288 minorPen.setCapStyle( Qt::FlatCap ); 284 289 285 290 painter->setPen( minorPen ); 286 291 287 if ( d_data->xEnabled &&d_data->xMinEnabled )292 if ( m_data->xEnabled && m_data->xMinEnabled ) 288 293 { 289 294 drawLines( painter, canvasRect, Qt::Vertical, xMap, 290 d_data->xScaleDiv.ticks( QwtScaleDiv::MinorTick ) );295 m_data->xScaleDiv.ticks( QwtScaleDiv::MinorTick ) ); 291 296 drawLines( painter, canvasRect, Qt::Vertical, xMap, 292 d_data->xScaleDiv.ticks( QwtScaleDiv::MediumTick ) );293 } 294 295 if ( d_data->yEnabled &&d_data->yMinEnabled )297 m_data->xScaleDiv.ticks( QwtScaleDiv::MediumTick ) ); 298 } 299 300 if ( m_data->yEnabled && m_data->yMinEnabled ) 296 301 { 297 302 drawLines( painter, canvasRect, Qt::Horizontal, yMap, 298 d_data->yScaleDiv.ticks( QwtScaleDiv::MinorTick ) );303 m_data->yScaleDiv.ticks( QwtScaleDiv::MinorTick ) ); 299 304 drawLines( painter, canvasRect, Qt::Horizontal, yMap, 300 d_data->yScaleDiv.ticks( QwtScaleDiv::MediumTick ) );305 m_data->yScaleDiv.ticks( QwtScaleDiv::MediumTick ) ); 301 306 } 302 307 303 308 // draw major grid lines 304 QPen majorPen = d_data->majorPen;309 QPen majorPen = m_data->majorPen; 305 310 majorPen.setCapStyle( Qt::FlatCap ); 306 311 307 312 painter->setPen( majorPen ); 308 313 309 if ( d_data->xEnabled )314 if ( m_data->xEnabled ) 310 315 { 311 316 drawLines( painter, canvasRect, Qt::Vertical, xMap, 312 d_data->xScaleDiv.ticks( QwtScaleDiv::MajorTick ) );313 } 314 315 if ( d_data->yEnabled )317 m_data->xScaleDiv.ticks( QwtScaleDiv::MajorTick ) ); 318 } 319 320 if ( m_data->yEnabled ) 316 321 { 317 322 drawLines( painter, canvasRect, Qt::Horizontal, yMap, 318 d_data->yScaleDiv.ticks( QwtScaleDiv::MajorTick ) );319 } 320 } 321 322 void QwtPlotGrid::drawLines( QPainter *painter, const QRectF&canvasRect,323 Qt::Orientation orientation, const QwtScaleMap &scaleMap,324 const QList< double> &values ) const323 m_data->yScaleDiv.ticks( QwtScaleDiv::MajorTick ) ); 324 } 325 } 326 327 void QwtPlotGrid::drawLines( QPainter* painter, const QRectF& canvasRect, 328 Qt::Orientation orientation, const QwtScaleMap& scaleMap, 329 const QList< double >& values ) const 325 330 { 326 331 const double x1 = canvasRect.left(); … … 340 345 { 341 346 if ( qwtFuzzyGreaterOrEqual( value, y1 ) && 342 qwtFuzzy LessOrEqual(value, y2) )347 qwtFuzzyGreaterOrEqual( y2, value ) ) 343 348 { 344 349 QwtPainter::drawLine( painter, x1, value, x2, value ); … … 348 353 { 349 354 if ( qwtFuzzyGreaterOrEqual( value, x1 ) && 350 qwtFuzzy LessOrEqual(value, x2) )355 qwtFuzzyGreaterOrEqual( x2, value ) ) 351 356 { 352 357 QwtPainter::drawLine( painter, value, y1, value, y2 ); … … 357 362 358 363 /*! 359 \return the pen for the major grid lines 360 \sa setMajorPen(), setMinorPen(), setPen() 361 */ 362 const QPen &QwtPlotGrid::majorPen() const363 { 364 return d_data->majorPen;365 } 366 367 /*! 368 \return the pen for the minor grid lines 369 \sa setMinorPen(), setMajorPen(), setPen() 370 */ 371 const QPen &QwtPlotGrid::minorPen() const372 { 373 return d_data->minorPen;374 } 375 376 /*! 377 \return true if vertical grid lines are enabled 378 \sa enableX() 379 */ 364 \return the pen for the major grid lines 365 \sa setMajorPen(), setMinorPen(), setPen() 366 */ 367 const QPen& QwtPlotGrid::majorPen() const 368 { 369 return m_data->majorPen; 370 } 371 372 /*! 373 \return the pen for the minor grid lines 374 \sa setMinorPen(), setMajorPen(), setPen() 375 */ 376 const QPen& QwtPlotGrid::minorPen() const 377 { 378 return m_data->minorPen; 379 } 380 381 /*! 382 \return true if vertical grid lines are enabled 383 \sa enableX() 384 */ 380 385 bool QwtPlotGrid::xEnabled() const 381 386 { 382 return d_data->xEnabled;383 } 384 385 /*! 386 \return true if minor vertical grid lines are enabled 387 \sa enableXMin() 388 */ 387 return m_data->xEnabled; 388 } 389 390 /*! 391 \return true if minor vertical grid lines are enabled 392 \sa enableXMin() 393 */ 389 394 bool QwtPlotGrid::xMinEnabled() const 390 395 { 391 return d_data->xMinEnabled;392 } 393 394 /*! 395 \return true if horizontal grid lines are enabled 396 \sa enableY() 397 */ 396 return m_data->xMinEnabled; 397 } 398 399 /*! 400 \return true if horizontal grid lines are enabled 401 \sa enableY() 402 */ 398 403 bool QwtPlotGrid::yEnabled() const 399 404 { 400 return d_data->yEnabled;401 } 402 403 /*! 404 \return true if minor horizontal grid lines are enabled 405 \sa enableYMin() 406 */ 405 return m_data->yEnabled; 406 } 407 408 /*! 409 \return true if minor horizontal grid lines are enabled 410 \sa enableYMin() 411 */ 407 412 bool QwtPlotGrid::yMinEnabled() const 408 413 { 409 return d_data->yMinEnabled;414 return m_data->yMinEnabled; 410 415 } 411 416 412 417 413 418 /*! \return the scale division of the x axis */ 414 const QwtScaleDiv &QwtPlotGrid::xScaleDiv() const415 { 416 return d_data->xScaleDiv;419 const QwtScaleDiv& QwtPlotGrid::xScaleDiv() const 420 { 421 return m_data->xScaleDiv; 417 422 } 418 423 419 424 /*! \return the scale division of the y axis */ 420 const QwtScaleDiv &QwtPlotGrid::yScaleDiv() const421 { 422 return d_data->yScaleDiv;425 const QwtScaleDiv& QwtPlotGrid::yScaleDiv() const 426 { 427 return m_data->yScaleDiv; 423 428 } 424 429 … … 430 435 431 436 \sa QwtPlot::updateAxes() 432 */ 437 */ 433 438 void QwtPlotGrid::updateScaleDiv( const QwtScaleDiv& xScaleDiv, 434 439 const QwtScaleDiv& yScaleDiv )
Note:
See TracChangeset
for help on using the changeset viewer.
