Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_abstract_scale.cpp
- Timestamp:
- Nov 3, 2026, 10:53:35 AM (3 weeks ago)
- File:
-
- 1 edited
-
trunk/BNC/qwt/qwt_abstract_scale.cpp (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_abstract_scale.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 15 15 #include "qwt_interval.h" 16 16 17 #include <qcoreevent.h> 18 17 19 class QwtAbstractScale::PrivateData 18 20 { 19 public: 21 public: 20 22 PrivateData(): 21 23 maxMajor( 5 ), … … 33 35 } 34 36 35 QwtScaleEngine *scaleEngine;36 QwtAbstractScaleDraw *scaleDraw;37 QwtScaleEngine* scaleEngine; 38 QwtAbstractScaleDraw* scaleDraw; 37 39 38 40 int maxMajor; … … 42 44 43 45 /*! 44 Constructor 45 46 \param parent Parent widget 47 48 Creates a default QwtScaleDraw and a QwtLinearScaleEngine. 49 The initial scale boundaries are set to [ 0.0, 100.0 ] 50 51 The scaleStepSize() is initialized to 0.0, scaleMaxMajor() to 5 52 and scaleMaxMajor to 3. 53 */ 54 55 QwtAbstractScale::QwtAbstractScale( QWidget *parent ):56 QWidget( parent ) 57 { 58 d_data = new PrivateData;59 rescale( 0.0, 100.0, d_data->stepSize );46 Constructor 47 48 \param parent Parent widget 49 50 Creates a default QwtScaleDraw and a QwtLinearScaleEngine. 51 The initial scale boundaries are set to [ 0.0, 100.0 ] 52 53 The scaleStepSize() is initialized to 0.0, scaleMaxMajor() to 5 54 and scaleMaxMajor to 3. 55 */ 56 57 QwtAbstractScale::QwtAbstractScale( QWidget* parent ) 58 : QWidget( parent ) 59 { 60 m_data = new PrivateData; 61 rescale( 0.0, 100.0, m_data->stepSize ); 60 62 } 61 63 … … 63 65 QwtAbstractScale::~QwtAbstractScale() 64 66 { 65 delete d_data;66 } 67 68 /*! 69 Set the lower bound of the scale 70 71 \param value Lower bound 72 73 \sa lowerBound(), setScale(), setUpperBound() 74 \note For inverted scales the lower bound 67 delete m_data; 68 } 69 70 /*! 71 Set the lower bound of the scale 72 73 \param value Lower bound 74 75 \sa lowerBound(), setScale(), setUpperBound() 76 \note For inverted scales the lower bound 75 77 is greater than the upper bound 76 */ 78 */ 77 79 void QwtAbstractScale::setLowerBound( double value ) 78 80 { … … 81 83 82 84 /*! 83 \return Lower bound of the scale 84 \sa setLowerBound(), setScale(), upperBound() 85 */ 85 \return Lower bound of the scale 86 \sa setLowerBound(), setScale(), upperBound() 87 */ 86 88 double QwtAbstractScale::lowerBound() const 87 89 { 88 return d_data->scaleDraw->scaleDiv().lowerBound();89 } 90 91 /*! 92 Set the upper bound of the scale 93 94 \param value Upper bound 95 96 \sa upperBound(), setScale(), setLowerBound() 97 \note For inverted scales the lower bound 90 return m_data->scaleDraw->scaleDiv().lowerBound(); 91 } 92 93 /*! 94 Set the upper bound of the scale 95 96 \param value Upper bound 97 98 \sa upperBound(), setScale(), setLowerBound() 99 \note For inverted scales the lower bound 98 100 is greater than the upper bound 99 */ 101 */ 100 102 void QwtAbstractScale::setUpperBound( double value ) 101 103 { … … 104 106 105 107 /*! 106 \return Upper bound of the scale 107 \sa setUpperBound(), setScale(), lowerBound() 108 */ 108 \return Upper bound of the scale 109 \sa setUpperBound(), setScale(), lowerBound() 110 */ 109 111 double QwtAbstractScale::upperBound() const 110 112 { 111 return d_data->scaleDraw->scaleDiv().upperBound();112 } 113 114 /*! 115 \brief Specify a scale. 116 117 Define a scale by an interval 118 119 The ticks are calculated using scaleMaxMinor(), 120 scaleMaxMajor() and scaleStepSize(). 121 122 \param lowerBound lower limit of the scale interval 123 \param upperBound upper limit of the scale interval 124 125 \note For inverted scales the lower bound 113 return m_data->scaleDraw->scaleDiv().upperBound(); 114 } 115 116 /*! 117 \brief Specify a scale. 118 119 Define a scale by an interval 120 121 The ticks are calculated using scaleMaxMinor(), 122 scaleMaxMajor() and scaleStepSize(). 123 124 \param lowerBound lower limit of the scale interval 125 \param upperBound upper limit of the scale interval 126 127 \note For inverted scales the lower bound 126 128 is greater than the upper bound 127 */ 129 */ 128 130 void QwtAbstractScale::setScale( double lowerBound, double upperBound ) 129 131 { 130 rescale( lowerBound, upperBound, d_data->stepSize );131 } 132 133 /*! 134 \brief Specify a scale. 135 136 Define a scale by an interval 137 138 The ticks are calculated using scaleMaxMinor(), 139 scaleMaxMajor() and scaleStepSize(). 140 141 \param interval Interval 142 */ 143 void QwtAbstractScale::setScale( const QwtInterval &interval )132 rescale( lowerBound, upperBound, m_data->stepSize ); 133 } 134 135 /*! 136 \brief Specify a scale. 137 138 Define a scale by an interval 139 140 The ticks are calculated using scaleMaxMinor(), 141 scaleMaxMajor() and scaleStepSize(). 142 143 \param interval Interval 144 */ 145 void QwtAbstractScale::setScale( const QwtInterval& interval ) 144 146 { 145 147 setScale( interval.minValue(), interval.maxValue() ); … … 147 149 148 150 /*! 149 \brief Specify a scale. 150 151 scaleMaxMinor(), scaleMaxMajor() and scaleStepSize() and have no effect. 152 153 \param scaleDiv Scale division 154 \sa setAutoScale() 155 */ 156 void QwtAbstractScale::setScale( const QwtScaleDiv &scaleDiv )157 { 158 if ( scaleDiv != d_data->scaleDraw->scaleDiv() )151 \brief Specify a scale. 152 153 scaleMaxMinor(), scaleMaxMajor() and scaleStepSize() and have no effect. 154 155 \param scaleDiv Scale division 156 \sa setAutoScale() 157 */ 158 void QwtAbstractScale::setScale( const QwtScaleDiv& scaleDiv ) 159 { 160 if ( scaleDiv != m_data->scaleDraw->scaleDiv() ) 159 161 { 160 162 #if 1 161 if ( d_data->scaleEngine )163 if ( m_data->scaleEngine ) 162 164 { 163 d_data->scaleDraw->setTransformation(164 d_data->scaleEngine->transformation() );165 m_data->scaleDraw->setTransformation( 166 m_data->scaleEngine->transformation() ); 165 167 } 166 168 #endif 167 169 168 d_data->scaleDraw->setScaleDiv( scaleDiv );170 m_data->scaleDraw->setScaleDiv( scaleDiv ); 169 171 170 172 scaleChange(); … … 173 175 174 176 /*! 175 \brief Set the maximum number of major tick intervals. 176 177 The scale's major ticks are calculated automatically such that 178 the number of major intervals does not exceed ticks. 179 180 The default value is 5. 181 182 \param ticks Maximal number of major ticks. 183 184 \sa scaleMaxMajor(), setScaleMaxMinor(), 177 \brief Set the maximum number of major tick intervals. 178 179 The scale's major ticks are calculated automatically such that 180 the number of major intervals does not exceed ticks. 181 182 The default value is 5. 183 184 \param ticks Maximal number of major ticks. 185 186 \sa scaleMaxMajor(), setScaleMaxMinor(), 185 187 setScaleStepSize(), QwtScaleEngine::divideInterval() 186 */ 188 */ 187 189 void QwtAbstractScale::setScaleMaxMajor( int ticks ) 188 190 { 189 if ( ticks != d_data->maxMajor )190 { 191 d_data->maxMajor = ticks;191 if ( ticks != m_data->maxMajor ) 192 { 193 m_data->maxMajor = ticks; 192 194 updateScaleDraw(); 193 195 } … … 195 197 196 198 /*! 197 \return Maximal number of major tick intervals 198 \sa setScaleMaxMajor(), scaleMaxMinor() 199 */ 199 \return Maximal number of major tick intervals 200 \sa setScaleMaxMajor(), scaleMaxMinor() 201 */ 200 202 int QwtAbstractScale::scaleMaxMajor() const 201 203 { 202 return d_data->maxMajor;203 } 204 205 /*! 206 \brief Set the maximum number of minor tick intervals 207 208 The scale's minor ticks are calculated automatically such that 209 the number of minor intervals does not exceed ticks. 210 The default value is 3. 211 212 \param ticks Maximal number of minor ticks. 213 214 \sa scaleMaxMajor(), setScaleMaxMinor(), 204 return m_data->maxMajor; 205 } 206 207 /*! 208 \brief Set the maximum number of minor tick intervals 209 210 The scale's minor ticks are calculated automatically such that 211 the number of minor intervals does not exceed ticks. 212 The default value is 3. 213 214 \param ticks Maximal number of minor ticks. 215 216 \sa scaleMaxMajor(), setScaleMaxMinor(), 215 217 setScaleStepSize(), QwtScaleEngine::divideInterval() 216 */ 218 */ 217 219 void QwtAbstractScale::setScaleMaxMinor( int ticks ) 218 220 { 219 if ( ticks != d_data->maxMinor )220 { 221 d_data->maxMinor = ticks;221 if ( ticks != m_data->maxMinor ) 222 { 223 m_data->maxMinor = ticks; 222 224 updateScaleDraw(); 223 225 } … … 225 227 226 228 /*! 227 \return Maximal number of minor tick intervals 228 \sa setScaleMaxMinor(), scaleMaxMajor() 229 */ 229 \return Maximal number of minor tick intervals 230 \sa setScaleMaxMinor(), scaleMaxMajor() 231 */ 230 232 int QwtAbstractScale::scaleMaxMinor() const 231 233 { 232 return d_data->maxMinor;234 return m_data->maxMinor; 233 235 } 234 236 … … 246 248 \note Position and distance between the major ticks also 247 249 depends on scaleMaxMajor(). 248 */ 250 */ 249 251 void QwtAbstractScale::setScaleStepSize( double stepSize ) 250 252 { 251 if ( stepSize != d_data->stepSize )252 { 253 d_data->stepSize = stepSize;253 if ( stepSize != m_data->stepSize ) 254 { 255 m_data->stepSize = stepSize; 254 256 updateScaleDraw(); 255 257 } … … 257 259 258 260 /*! 259 \return Hint for the step size of the scale 260 \sa setScaleStepSize(), QwtScaleEngine::divideScale() 261 */ 261 \return Hint for the step size of the scale 262 \sa setScaleStepSize(), QwtScaleEngine::divideScale() 263 */ 262 264 double QwtAbstractScale::scaleStepSize() const 263 265 { 264 return d_data->stepSize;265 } 266 267 /*! 268 \brief Set a scale draw 269 270 scaleDraw has to be created with new and will be deleted in 271 the destructor or the next call of setAbstractScaleDraw(). 272 273 \sa abstractScaleDraw() 274 */ 275 void QwtAbstractScale::setAbstractScaleDraw( QwtAbstractScaleDraw *scaleDraw )276 { 277 if ( scaleDraw == NULL || scaleDraw == d_data->scaleDraw )266 return m_data->stepSize; 267 } 268 269 /*! 270 \brief Set a scale draw 271 272 scaleDraw has to be created with new and will be deleted in 273 the destructor or the next call of setAbstractScaleDraw(). 274 275 \sa abstractScaleDraw() 276 */ 277 void QwtAbstractScale::setAbstractScaleDraw( QwtAbstractScaleDraw* scaleDraw ) 278 { 279 if ( scaleDraw == NULL || scaleDraw == m_data->scaleDraw ) 278 280 return; 279 281 280 if ( d_data->scaleDraw != NULL )281 scaleDraw->setScaleDiv( d_data->scaleDraw->scaleDiv() );282 283 delete d_data->scaleDraw;284 d_data->scaleDraw = scaleDraw;282 if ( m_data->scaleDraw != NULL ) 283 scaleDraw->setScaleDiv( m_data->scaleDraw->scaleDiv() ); 284 285 delete m_data->scaleDraw; 286 m_data->scaleDraw = scaleDraw; 285 287 } 286 288 … … 288 290 \return Scale draw 289 291 \sa setAbstractScaleDraw() 290 */ 291 QwtAbstractScaleDraw *QwtAbstractScale::abstractScaleDraw()292 { 293 return d_data->scaleDraw;292 */ 293 QwtAbstractScaleDraw* QwtAbstractScale::abstractScaleDraw() 294 { 295 return m_data->scaleDraw; 294 296 } 295 297 … … 297 299 \return Scale draw 298 300 \sa setAbstractScaleDraw() 299 */ 300 const QwtAbstractScaleDraw *QwtAbstractScale::abstractScaleDraw() const301 { 302 return d_data->scaleDraw;303 } 304 305 /*! 306 \brief Set a scale engine 307 308 The scale engine is responsible for calculating the scale division 309 and provides a transformation between scale and widget coordinates. 310 311 scaleEngine has to be created with new and will be deleted in 312 the destructor or the next call of setScaleEngine. 313 */ 314 void QwtAbstractScale::setScaleEngine( QwtScaleEngine *scaleEngine )315 { 316 if ( scaleEngine != NULL && scaleEngine != d_data->scaleEngine )317 { 318 delete d_data->scaleEngine;319 d_data->scaleEngine = scaleEngine;320 } 321 } 322 323 /*! 324 \return Scale engine 325 \sa setScaleEngine() 326 */ 327 const QwtScaleEngine *QwtAbstractScale::scaleEngine() const328 { 329 return d_data->scaleEngine;330 } 331 332 /*! 333 \return Scale engine 334 \sa setScaleEngine() 335 */ 336 QwtScaleEngine *QwtAbstractScale::scaleEngine()337 { 338 return d_data->scaleEngine;339 } 340 341 /*! 342 \return Scale boundaries and positions of the ticks 343 344 The scale division might have been assigned explicitly 345 or calculated implicitly by rescale(). 346 */ 347 const QwtScaleDiv &QwtAbstractScale::scaleDiv() const348 { 349 return d_data->scaleDraw->scaleDiv();350 } 351 352 /*! 353 \return Map to translate between scale and widget coordinates 354 */ 355 const QwtScaleMap &QwtAbstractScale::scaleMap() const356 { 357 return d_data->scaleDraw->scaleMap();358 } 359 360 /*! 361 Translate a scale value into a widget coordinate 362 363 \param value Scale value 364 \return Corresponding widget coordinate for value 365 \sa scaleMap(), invTransform() 301 */ 302 const QwtAbstractScaleDraw* QwtAbstractScale::abstractScaleDraw() const 303 { 304 return m_data->scaleDraw; 305 } 306 307 /*! 308 \brief Set a scale engine 309 310 The scale engine is responsible for calculating the scale division 311 and provides a transformation between scale and widget coordinates. 312 313 scaleEngine has to be created with new and will be deleted in 314 the destructor or the next call of setScaleEngine. 315 */ 316 void QwtAbstractScale::setScaleEngine( QwtScaleEngine* scaleEngine ) 317 { 318 if ( scaleEngine != NULL && scaleEngine != m_data->scaleEngine ) 319 { 320 delete m_data->scaleEngine; 321 m_data->scaleEngine = scaleEngine; 322 } 323 } 324 325 /*! 326 \return Scale engine 327 \sa setScaleEngine() 328 */ 329 const QwtScaleEngine* QwtAbstractScale::scaleEngine() const 330 { 331 return m_data->scaleEngine; 332 } 333 334 /*! 335 \return Scale engine 336 \sa setScaleEngine() 337 */ 338 QwtScaleEngine* QwtAbstractScale::scaleEngine() 339 { 340 return m_data->scaleEngine; 341 } 342 343 /*! 344 \return Scale boundaries and positions of the ticks 345 346 The scale division might have been assigned explicitly 347 or calculated implicitly by rescale(). 348 */ 349 const QwtScaleDiv& QwtAbstractScale::scaleDiv() const 350 { 351 return m_data->scaleDraw->scaleDiv(); 352 } 353 354 /*! 355 \return Map to translate between scale and widget coordinates 356 */ 357 const QwtScaleMap& QwtAbstractScale::scaleMap() const 358 { 359 return m_data->scaleDraw->scaleMap(); 360 } 361 362 /*! 363 Translate a scale value into a widget coordinate 364 365 \param value Scale value 366 \return Corresponding widget coordinate for value 367 \sa scaleMap(), invTransform() 366 368 */ 367 369 int QwtAbstractScale::transform( double value ) const 368 370 { 369 return qRound( d_data->scaleDraw->scaleMap().transform( value ) );370 } 371 372 /*! 373 Translate a widget coordinate into a scale value 374 375 \param value Widget coordinate 376 \return Corresponding scale coordinate for value 377 \sa scaleMap(), transform() 371 return qRound( m_data->scaleDraw->scaleMap().transform( value ) ); 372 } 373 374 /*! 375 Translate a widget coordinate into a scale value 376 377 \param value Widget coordinate 378 \return Corresponding scale coordinate for value 379 \sa scaleMap(), transform() 378 380 */ 379 381 double QwtAbstractScale::invTransform( int value ) const 380 382 { 381 return d_data->scaleDraw->scaleMap().invTransform( value );382 } 383 384 /*! 385 \return True, when the scale is increasing in opposite direction 383 return m_data->scaleDraw->scaleMap().invTransform( value ); 384 } 385 386 /*! 387 \return True, when the scale is increasing in opposite direction 386 388 to the widget coordinates 387 389 */ 388 390 bool QwtAbstractScale::isInverted() const 389 391 { 390 return d_data->scaleDraw->scaleMap().isInverting();391 } 392 393 /*! 394 \return The boundary with the smaller value 395 \sa maximum(), lowerBound(), upperBound() 392 return m_data->scaleDraw->scaleMap().isInverting(); 393 } 394 395 /*! 396 \return The boundary with the smaller value 397 \sa maximum(), lowerBound(), upperBound() 396 398 */ 397 399 double QwtAbstractScale::minimum() const 398 400 { 399 return qMin( d_data->scaleDraw->scaleDiv().lowerBound(),400 d_data->scaleDraw->scaleDiv().upperBound() );401 } 402 403 /*! 404 \return The boundary with the larger value 405 \sa minimum(), lowerBound(), upperBound() 401 return qMin( m_data->scaleDraw->scaleDiv().lowerBound(), 402 m_data->scaleDraw->scaleDiv().upperBound() ); 403 } 404 405 /*! 406 \return The boundary with the larger value 407 \sa minimum(), lowerBound(), upperBound() 406 408 */ 407 409 double QwtAbstractScale::maximum() const 408 410 { 409 return qMax( d_data->scaleDraw->scaleDiv().lowerBound(),410 d_data->scaleDraw->scaleDiv().upperBound() );411 return qMax( m_data->scaleDraw->scaleDiv().lowerBound(), 412 m_data->scaleDraw->scaleDiv().upperBound() ); 411 413 } 412 414 … … 417 419 418 420 /*! 419 Recalculate the scale division and update the scale. 420 421 \param lowerBound Lower limit of the scale interval 422 \param upperBound Upper limit of the scale interval 423 \param stepSize Major step size 424 425 \sa scaleChange() 426 */ 421 Recalculate the scale division and update the scale. 422 423 \param lowerBound Lower limit of the scale interval 424 \param upperBound Upper limit of the scale interval 425 \param stepSize Major step size 426 427 \sa scaleChange() 428 */ 427 429 void QwtAbstractScale::rescale( 428 430 double lowerBound, double upperBound, double stepSize ) 429 431 { 430 const QwtScaleDiv scaleDiv = d_data->scaleEngine->divideScale(431 lowerBound, upperBound, d_data->maxMajor,d_data->maxMinor, stepSize );432 433 if ( scaleDiv != d_data->scaleDraw->scaleDiv() )432 const QwtScaleDiv scaleDiv = m_data->scaleEngine->divideScale( 433 lowerBound, upperBound, m_data->maxMajor, m_data->maxMinor, stepSize ); 434 435 if ( scaleDiv != m_data->scaleDraw->scaleDiv() ) 434 436 { 435 437 #if 1 436 d_data->scaleDraw->setTransformation(437 d_data->scaleEngine->transformation() );438 m_data->scaleDraw->setTransformation( 439 m_data->scaleEngine->transformation() ); 438 440 #endif 439 441 440 d_data->scaleDraw->setScaleDiv( scaleDiv );442 m_data->scaleDraw->setScaleDiv( scaleDiv ); 441 443 scaleChange(); 442 444 } 443 445 } 444 446 447 /*! 448 Change Event handler 449 \param event Change event 450 451 Invalidates internal caches if necessary 452 */ 453 void QwtAbstractScale::changeEvent( QEvent* event ) 454 { 455 if ( event->type() == QEvent::LocaleChange ) 456 { 457 m_data->scaleDraw->invalidateCache(); 458 } 459 460 QWidget::changeEvent( event ); 461 } 462 463 /*! 464 Recalculate ticks and scale boundaries. 465 */ 445 466 void QwtAbstractScale::updateScaleDraw() 446 467 { 447 rescale( d_data->scaleDraw->scaleDiv().lowerBound(), 448 d_data->scaleDraw->scaleDiv().upperBound(), d_data->stepSize ); 449 } 468 rescale( m_data->scaleDraw->scaleDiv().lowerBound(), 469 m_data->scaleDraw->scaleDiv().upperBound(), m_data->stepSize ); 470 } 471 472 #include "moc_qwt_abstract_scale.cpp"
Note:
See TracChangeset
for help on using the changeset viewer.
