Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_thermo.cpp
- Timestamp:
- Nov 3, 2026, 10:53:35 AM (3 weeks ago)
- File:
-
- 1 edited
-
trunk/BNC/qwt/qwt_thermo.cpp (modified) (56 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_thermo.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #include "qwt_thermo.h" 11 #include "qwt_scale_engine.h"12 11 #include "qwt_scale_draw.h" 13 12 #include "qwt_scale_map.h" 14 13 #include "qwt_color_map.h" 14 #include "qwt_math.h" 15 15 16 #include <qpainter.h> 16 17 #include <qevent.h> … … 18 19 #include <qstyle.h> 19 20 #include <qstyleoption.h> 20 #include <qmath.h> 21 22 static inline void qwtDrawLine( QPainter *painter, int pos, 23 const QColor &color, const QRect &pipeRect, const QRect &liquidRect, 21 #include <qmargins.h> 22 23 #include <algorithm> 24 #include <functional> 25 26 static inline void qwtDrawLine( QPainter* painter, int pos, 27 const QColor& color, const QRect& pipeRect, const QRect& liquidRect, 24 28 Qt::Orientation orientation ) 25 29 { … … 37 41 } 38 42 39 QVector< double> qwtTickList( const QwtScaleDiv&scaleDiv )40 { 41 QVector< double> values;43 static QVector< double > qwtTickList( const QwtScaleDiv& scaleDiv ) 44 { 45 QVector< double > values; 42 46 43 47 double lowerLimit = scaleDiv.interval().minValue(); … … 52 56 tickType < QwtScaleDiv::NTickTypes; tickType++ ) 53 57 { 54 const QList< double> ticks = scaleDiv.ticks( tickType );58 const QList< double > ticks = scaleDiv.ticks( tickType ); 55 59 56 60 for ( int i = 0; i < ticks.count(); i++ ) … … 69 73 class QwtThermo::PrivateData 70 74 { 71 public: 72 PrivateData() :73 orientation( Qt::Vertical ) ,74 scalePosition( QwtThermo::TrailingScale ) ,75 spacing( 3 ) ,76 borderWidth( 2 ) ,77 pipeWidth( 10 ) ,78 alarmLevel( 0.0 ) ,79 alarmEnabled( false ) ,80 autoFillPipe( true ) ,81 originMode( QwtThermo::OriginMinimum ) ,82 origin( 0.0 ) ,83 colorMap( NULL ) ,84 value( 0.0 ) 75 public: 76 PrivateData() 77 : orientation( Qt::Vertical ) 78 , scalePosition( QwtThermo::TrailingScale ) 79 , spacing( 3 ) 80 , borderWidth( 2 ) 81 , pipeWidth( 10 ) 82 , alarmLevel( 0.0 ) 83 , alarmEnabled( false ) 84 , autoFillPipe( true ) 85 , originMode( QwtThermo::OriginMinimum ) 86 , origin( 0.0 ) 87 , colorMap( NULL ) 88 , value( 0.0 ) 85 89 { 86 90 rangeFlags = QwtInterval::IncludeBorders; … … 106 110 double origin; 107 111 108 QwtColorMap *colorMap;112 QwtColorMap* colorMap; 109 113 110 114 double value; … … 112 116 113 117 /*! 114 Constructor 115 \param parent Parent widget 116 */ 117 QwtThermo::QwtThermo( QWidget *parent ):118 QwtAbstractScale( parent ) 119 { 120 d_data = new PrivateData;118 Constructor 119 \param parent Parent widget 120 */ 121 QwtThermo::QwtThermo( QWidget* parent ) 122 : QwtAbstractScale( parent ) 123 { 124 m_data = new PrivateData; 121 125 122 126 QSizePolicy policy( QSizePolicy::MinimumExpanding, QSizePolicy::Fixed ); 123 if ( d_data->orientation == Qt::Vertical )127 if ( m_data->orientation == Qt::Vertical ) 124 128 policy.transpose(); 125 129 … … 133 137 QwtThermo::~QwtThermo() 134 138 { 135 delete d_data;136 } 137 138 /*! 139 \brief Exclude/Include min/max values 140 141 According to the flags minValue() and maxValue() 142 are included/excluded from the pipe. In case of an 143 excluded value the corresponding tick is painted 144 1 pixel off of the pipeRect(). 145 146 F.e. when a minimum 147 of 0.0 has to be displayed as an empty pipe the minValue() 148 needs to be excluded. 149 150 \param flags Range flags 151 \sa rangeFlags() 152 */ 139 delete m_data; 140 } 141 142 /*! 143 \brief Exclude/Include min/max values 144 145 According to the flags minValue() and maxValue() 146 are included/excluded from the pipe. In case of an 147 excluded value the corresponding tick is painted 148 1 pixel off of the pipeRect(). 149 150 F.e. when a minimum 151 of 0.0 has to be displayed as an empty pipe the minValue() 152 needs to be excluded. 153 154 \param flags Range flags 155 \sa rangeFlags() 156 */ 153 157 void QwtThermo::setRangeFlags( QwtInterval::BorderFlags flags ) 154 158 { 155 if ( d_data->rangeFlags != flags )156 { 157 d_data->rangeFlags = flags;159 if ( m_data->rangeFlags != flags ) 160 { 161 m_data->rangeFlags = flags; 158 162 update(); 159 163 } … … 161 165 162 166 /*! 163 \return Range flags 164 \sa setRangeFlags() 165 */ 167 \return Range flags 168 \sa setRangeFlags() 169 */ 166 170 QwtInterval::BorderFlags QwtThermo::rangeFlags() const 167 171 { 168 return d_data->rangeFlags;169 } 170 171 /*! 172 Set the current value. 173 174 \param value New Value 175 \sa value() 176 */ 172 return m_data->rangeFlags; 173 } 174 175 /*! 176 Set the current value. 177 178 \param value New Value 179 \sa value() 180 */ 177 181 void QwtThermo::setValue( double value ) 178 182 { 179 if ( d_data->value != value )180 { 181 d_data->value = value;183 if ( m_data->value != value ) 184 { 185 m_data->value = value; 182 186 update(); 183 187 } … … 187 191 double QwtThermo::value() const 188 192 { 189 return d_data->value;190 } 191 192 /*! 193 \brief Set a scale draw 194 195 For changing the labels of the scales, it 196 is necessary to derive from QwtScaleDraw and 197 overload QwtScaleDraw::label(). 198 199 \param scaleDraw ScaleDraw object, that has to be created with 193 return m_data->value; 194 } 195 196 /*! 197 \brief Set a scale draw 198 199 For changing the labels of the scales, it 200 is necessary to derive from QwtScaleDraw and 201 overload QwtScaleDraw::label(). 202 203 \param scaleDraw ScaleDraw object, that has to be created with 200 204 new and will be deleted in ~QwtThermo() or the next 201 205 call of setScaleDraw(). 202 */ 203 void QwtThermo::setScaleDraw( QwtScaleDraw *scaleDraw )206 */ 207 void QwtThermo::setScaleDraw( QwtScaleDraw* scaleDraw ) 204 208 { 205 209 setAbstractScaleDraw( scaleDraw ); … … 210 214 \return the scale draw of the thermo 211 215 \sa setScaleDraw() 212 */ 213 const QwtScaleDraw *QwtThermo::scaleDraw() const214 { 215 return static_cast<const QwtScaleDraw *>( abstractScaleDraw() );216 */ 217 const QwtScaleDraw* QwtThermo::scaleDraw() const 218 { 219 return static_cast< const QwtScaleDraw* >( abstractScaleDraw() ); 216 220 } 217 221 … … 219 223 \return the scale draw of the thermo 220 224 \sa setScaleDraw() 221 */ 222 QwtScaleDraw *QwtThermo::scaleDraw()223 { 224 return static_cast<QwtScaleDraw *>( abstractScaleDraw() );225 } 226 227 /*! 228 Paint event handler 229 \param event Paint event 230 */ 231 void QwtThermo::paintEvent( QPaintEvent *event )225 */ 226 QwtScaleDraw* QwtThermo::scaleDraw() 227 { 228 return static_cast< QwtScaleDraw* >( abstractScaleDraw() ); 229 } 230 231 /*! 232 Paint event handler 233 \param event Paint event 234 */ 235 void QwtThermo::paintEvent( QPaintEvent* event ) 232 236 { 233 237 QPainter painter( this ); … … 235 239 236 240 QStyleOption opt; 237 opt.init(this); 241 opt.initFrom(this); 238 242 style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this); 239 243 … … 242 246 if ( !tRect.contains( event->rect() ) ) 243 247 { 244 if ( d_data->scalePosition != QwtThermo::NoScale )248 if ( m_data->scalePosition != QwtThermo::NoScale ) 245 249 scaleDraw()->draw( &painter, palette() ); 246 250 } 247 251 248 const int bw = d_data->borderWidth;252 const int bw = m_data->borderWidth; 249 253 250 254 const QBrush brush = palette().brush( QPalette::Base ); … … 252 256 tRect.adjusted( -bw, -bw, bw, bw ), 253 257 palette(), true, bw, 254 d_data->autoFillPipe ? &brush : NULL );258 m_data->autoFillPipe ? &brush : NULL ); 255 259 256 260 drawLiquid( &painter, tRect ); … … 258 262 259 263 /*! 260 Resize event handler 261 \param event Resize event 262 */ 263 void QwtThermo::resizeEvent( QResizeEvent *event )264 Resize event handler 265 \param event Resize event 266 */ 267 void QwtThermo::resizeEvent( QResizeEvent* event ) 264 268 { 265 269 Q_UNUSED( event ); … … 268 272 269 273 /*! 270 Qt change event handler 271 \param event Event 272 */ 273 void QwtThermo::changeEvent( QEvent *event )274 Qt change event handler 275 \param event Event 276 */ 277 void QwtThermo::changeEvent( QEvent* event ) 274 278 { 275 279 switch( event->type() ) … … 287 291 288 292 /*! 289 Recalculate the QwtThermo geometry and layout based on 290 pipeRect() and the fonts. 291 292 \param update_geometry notify the layout system and call update 293 Recalculate the QwtThermo geometry and layout based on 294 pipeRect() and the fonts. 295 296 \param update_geometry notify the layout system and call update 293 297 to redraw the scale 294 */ 298 */ 295 299 void QwtThermo::layoutThermo( bool update_geometry ) 296 300 { 297 301 const QRect tRect = pipeRect(); 298 const int bw = d_data->borderWidth +d_data->spacing;302 const int bw = m_data->borderWidth + m_data->spacing; 299 303 const bool inverted = ( upperBound() < lowerBound() ); 300 304 301 305 int from, to; 302 306 303 if ( d_data->orientation == Qt::Horizontal )307 if ( m_data->orientation == Qt::Horizontal ) 304 308 { 305 309 from = tRect.left(); 306 310 to = tRect.right(); 307 311 308 if ( d_data->rangeFlags & QwtInterval::ExcludeMinimum )312 if ( m_data->rangeFlags & QwtInterval::ExcludeMinimum ) 309 313 { 310 314 if ( inverted ) … … 313 317 from--; 314 318 } 315 if ( d_data->rangeFlags & QwtInterval::ExcludeMaximum )319 if ( m_data->rangeFlags & QwtInterval::ExcludeMaximum ) 316 320 { 317 321 if ( inverted ) … … 321 325 } 322 326 323 if ( d_data->scalePosition == QwtThermo::TrailingScale )327 if ( m_data->scalePosition == QwtThermo::TrailingScale ) 324 328 { 325 329 scaleDraw()->setAlignment( QwtScaleDraw::TopScale ); … … 339 343 to = tRect.bottom(); 340 344 341 if ( d_data->rangeFlags & QwtInterval::ExcludeMinimum )345 if ( m_data->rangeFlags & QwtInterval::ExcludeMinimum ) 342 346 { 343 347 if ( inverted ) … … 346 350 to++; 347 351 } 348 if ( d_data->rangeFlags & QwtInterval::ExcludeMaximum )352 if ( m_data->rangeFlags & QwtInterval::ExcludeMaximum ) 349 353 { 350 354 if ( inverted ) … … 354 358 } 355 359 356 if ( d_data->scalePosition == QwtThermo::LeadingScale )360 if ( m_data->scalePosition == QwtThermo::LeadingScale ) 357 361 { 358 362 scaleDraw()->setAlignment( QwtScaleDraw::RightScale ); … … 376 380 377 381 /*! 378 \return Bounding rectangle of the pipe ( without borders ) 382 \return Bounding rectangle of the pipe ( without borders ) 379 383 in widget coordinates 380 */ 384 */ 381 385 QRect QwtThermo::pipeRect() const 382 386 { 383 387 int mbd = 0; 384 if ( d_data->scalePosition != QwtThermo::NoScale )388 if ( m_data->scalePosition != QwtThermo::NoScale ) 385 389 { 386 390 int d1, d2; … … 388 392 mbd = qMax( d1, d2 ); 389 393 } 390 const int bw = d_data->borderWidth;394 const int bw = m_data->borderWidth; 391 395 const int scaleOff = bw + mbd; 392 396 … … 394 398 395 399 QRect pipeRect = cr; 396 if ( d_data->orientation == Qt::Horizontal )400 if ( m_data->orientation == Qt::Horizontal ) 397 401 { 398 402 pipeRect.adjust( scaleOff, 0, -scaleOff, 0 ); 399 403 400 if ( d_data->scalePosition == QwtThermo::TrailingScale )401 pipeRect.setTop( cr.top() + cr.height() - bw - d_data->pipeWidth );404 if ( m_data->scalePosition == QwtThermo::TrailingScale ) 405 pipeRect.setTop( cr.top() + cr.height() - bw - m_data->pipeWidth ); 402 406 else 403 407 pipeRect.setTop( bw ); 404 408 405 pipeRect.setHeight( d_data->pipeWidth );409 pipeRect.setHeight( m_data->pipeWidth ); 406 410 } 407 411 else // Qt::Vertical … … 409 413 pipeRect.adjust( 0, scaleOff, 0, -scaleOff ); 410 414 411 if ( d_data->scalePosition == QwtThermo::LeadingScale )415 if ( m_data->scalePosition == QwtThermo::LeadingScale ) 412 416 pipeRect.setLeft( bw ); 413 417 else 414 pipeRect.setLeft( cr.left() + cr.width() - bw - d_data->pipeWidth );415 416 pipeRect.setWidth( d_data->pipeWidth );418 pipeRect.setLeft( cr.left() + cr.width() - bw - m_data->pipeWidth ); 419 420 pipeRect.setWidth( m_data->pipeWidth ); 417 421 } 418 422 … … 421 425 422 426 /*! 423 \brief Set the orientation. 424 \param orientation Allowed values are Qt::Horizontal and Qt::Vertical. 425 426 \sa orientation(), scalePosition() 427 */ 427 \brief Set the orientation. 428 \param orientation Allowed values are Qt::Horizontal and Qt::Vertical. 429 430 \sa orientation(), scalePosition() 431 */ 428 432 void QwtThermo::setOrientation( Qt::Orientation orientation ) 429 433 { 430 if ( orientation == d_data->orientation )434 if ( orientation == m_data->orientation ) 431 435 return; 432 436 433 d_data->orientation = orientation;437 m_data->orientation = orientation; 434 438 435 439 if ( !testAttribute( Qt::WA_WState_OwnSizePolicy ) ) … … 446 450 447 451 /*! 448 \return Orientation 449 \sa setOrientation() 450 */ 452 \return Orientation 453 \sa setOrientation() 454 */ 451 455 Qt::Orientation QwtThermo::orientation() const 452 456 { 453 return d_data->orientation;454 } 455 456 /*! 457 \brief Change how the origin is determined. 458 \sa originMode(), serOrigin(), origin() 457 return m_data->orientation; 458 } 459 460 /*! 461 \brief Change how the origin is determined. 462 \sa originMode(), serOrigin(), origin() 459 463 */ 460 464 void QwtThermo::setOriginMode( OriginMode m ) 461 465 { 462 if ( m == d_data->originMode )466 if ( m == m_data->originMode ) 463 467 return; 464 468 465 d_data->originMode = m;469 m_data->originMode = m; 466 470 update(); 467 471 } 468 472 469 473 /*! 470 \return Mode, how the origin is determined. 471 \sa setOriginMode(), serOrigin(), origin() 474 \return Mode, how the origin is determined. 475 \sa setOriginMode(), serOrigin(), origin() 472 476 */ 473 477 QwtThermo::OriginMode QwtThermo::originMode() const 474 478 { 475 return d_data->originMode;476 } 477 478 /*! 479 \brief Specifies the custom origin. 480 481 If originMode is set to OriginCustom this property controls where the 482 liquid starts. 483 484 \param origin New origin level 485 \sa setOriginMode(), originMode(), origin() 479 return m_data->originMode; 480 } 481 482 /*! 483 \brief Specifies the custom origin. 484 485 If originMode is set to OriginCustom this property controls where the 486 liquid starts. 487 488 \param origin New origin level 489 \sa setOriginMode(), originMode(), origin() 486 490 */ 487 491 void QwtThermo::setOrigin( double origin ) 488 492 { 489 if ( origin == d_data->origin )493 if ( origin == m_data->origin ) 490 494 return; 491 495 492 d_data->origin = origin;496 m_data->origin = origin; 493 497 update(); 494 498 } 495 499 496 500 /*! 497 \return Origin of the thermo, when OriginCustom is enabled 498 \sa setOrigin(), setOriginMode(), originMode() 501 \return Origin of the thermo, when OriginCustom is enabled 502 \sa setOrigin(), setOriginMode(), originMode() 499 503 */ 500 504 double QwtThermo::origin() const 501 505 { 502 return d_data->origin;503 } 504 505 /*! 506 \brief Change the position of the scale 507 \param scalePosition Position of the scale. 508 509 \sa ScalePosition, scalePosition() 510 */ 506 return m_data->origin; 507 } 508 509 /*! 510 \brief Change the position of the scale 511 \param scalePosition Position of the scale. 512 513 \sa ScalePosition, scalePosition() 514 */ 511 515 void QwtThermo::setScalePosition( ScalePosition scalePosition ) 512 516 { 513 if ( d_data->scalePosition == scalePosition )517 if ( m_data->scalePosition == scalePosition ) 514 518 return; 515 519 516 d_data->scalePosition = scalePosition;520 m_data->scalePosition = scalePosition; 517 521 518 522 if ( testAttribute( Qt::WA_WState_Polished ) ) … … 523 527 \return Scale position. 524 528 \sa setScalePosition() 525 */ 529 */ 526 530 QwtThermo::ScalePosition QwtThermo::scalePosition() const 527 531 { 528 return d_data->scalePosition;532 return m_data->scalePosition; 529 533 } 530 534 … … 539 543 \param painter Painter 540 544 \param pipeRect Bounding rectangle of the pipe without borders 541 */ 545 */ 542 546 void QwtThermo::drawLiquid( 543 QPainter *painter, const QRect&pipeRect ) const547 QPainter* painter, const QRect& pipeRect ) const 544 548 { 545 549 painter->save(); … … 551 555 QRect liquidRect = fillRect( pipeRect ); 552 556 553 if ( d_data->colorMap != NULL )557 if ( m_data->colorMap != NULL ) 554 558 { 555 559 const QwtInterval interval = scaleDiv().interval().normalized(); … … 558 562 // we calculate the colors for the rounded tick values 559 563 560 QVector< double> values = qwtTickList( scaleDraw()->scaleDiv() );564 QVector< double > values = qwtTickList( scaleDraw()->scaleDiv() ); 561 565 562 566 if ( scaleMap.isInverting() ) 563 qSort( values.begin(), values.end(),qGreater<double>() );567 std::sort( values.begin(), values.end(), std::greater< double >() ); 564 568 else 565 qSort( values.begin(), values.end(),qLess<double>() );569 std::sort( values.begin(), values.end(), std::less< double >() ); 566 570 567 571 int from; … … 570 574 from = qRound( scaleMap.transform( values[0] ) ); 571 575 qwtDrawLine( painter, from, 572 d_data->colorMap->color( interval, values[0] ),573 pipeRect, liquidRect, d_data->orientation );576 m_data->colorMap->color( interval, values[0] ), 577 pipeRect, liquidRect, m_data->orientation ); 574 578 } 575 579 … … 583 587 584 588 qwtDrawLine( painter, pos, 585 d_data->colorMap->color( interval, v ),586 pipeRect, liquidRect, d_data->orientation );589 m_data->colorMap->color( interval, v ), 590 pipeRect, liquidRect, m_data->orientation ); 587 591 } 588 592 589 593 qwtDrawLine( painter, to, 590 d_data->colorMap->color( interval, values[i] ),591 pipeRect, liquidRect, d_data->orientation );594 m_data->colorMap->color( interval, values[i] ), 595 pipeRect, liquidRect, m_data->orientation ); 592 596 593 597 from = to; … … 596 600 else 597 601 { 598 if ( !liquidRect.isEmpty() && d_data->alarmEnabled )602 if ( !liquidRect.isEmpty() && m_data->alarmEnabled ) 599 603 { 600 604 const QRect r = alarmRect( liquidRect ); … … 613 617 614 618 /*! 615 \brief Change the spacing between pipe and scale 616 617 A spacing of 0 means, that the backbone of the scale is below 618 the pipe. 619 620 The default setting is 3 pixels. 621 622 \param spacing Number of pixels 623 \sa spacing(); 624 */ 619 \brief Change the spacing between pipe and scale 620 621 A spacing of 0 means, that the backbone of the scale is below 622 the pipe. 623 624 The default setting is 3 pixels. 625 626 \param spacing Number of pixels 627 \sa spacing(); 628 */ 625 629 void QwtThermo::setSpacing( int spacing ) 626 630 { … … 628 632 spacing = 0; 629 633 630 if ( spacing != d_data->spacing )631 { 632 d_data->spacing = spacing;634 if ( spacing != m_data->spacing ) 635 { 636 m_data->spacing = spacing; 633 637 layoutThermo( true ); 634 638 } … … 636 640 637 641 /*! 638 \return Number of pixels between pipe and scale 639 \sa setSpacing() 640 */ 642 \return Number of pixels between pipe and scale 643 \sa setSpacing() 644 */ 641 645 int QwtThermo::spacing() const 642 646 { 643 return d_data->spacing;647 return m_data->spacing; 644 648 } 645 649 … … 648 652 \param width Border width 649 653 \sa borderWidth() 650 */ 654 */ 651 655 void QwtThermo::setBorderWidth( int width ) 652 656 { … … 654 658 width = 0; 655 659 656 if ( width != d_data->borderWidth )657 { 658 d_data->borderWidth = width;660 if ( width != m_data->borderWidth ) 661 { 662 m_data->borderWidth = width; 659 663 layoutThermo( true ); 660 664 } … … 664 668 \return Border width of the thermometer pipe. 665 669 \sa setBorderWidth() 666 */ 670 */ 667 671 int QwtThermo::borderWidth() const 668 672 { 669 return d_data->borderWidth;670 } 671 672 /*! 673 \brief Assign a color map for the fill color 674 675 \param colorMap Color map 676 \warning The alarm threshold has no effect, when 673 return m_data->borderWidth; 674 } 675 676 /*! 677 \brief Assign a color map for the fill color 678 679 \param colorMap Color map 680 \warning The alarm threshold has no effect, when 677 681 a color map has been assigned 678 */ 679 void QwtThermo::setColorMap( QwtColorMap *colorMap )680 { 681 if ( colorMap != d_data->colorMap )682 { 683 delete d_data->colorMap;684 d_data->colorMap = colorMap;685 } 686 } 687 688 /*! 689 \return Color map for the fill color 690 \warning The alarm threshold has no effect, when 682 */ 683 void QwtThermo::setColorMap( QwtColorMap* colorMap ) 684 { 685 if ( colorMap != m_data->colorMap ) 686 { 687 delete m_data->colorMap; 688 m_data->colorMap = colorMap; 689 } 690 } 691 692 /*! 693 \return Color map for the fill color 694 \warning The alarm threshold has no effect, when 691 695 a color map has been assigned 692 */ 693 QwtColorMap *QwtThermo::colorMap()694 { 695 return d_data->colorMap;696 } 697 698 /*! 699 \return Color map for the fill color 700 \warning The alarm threshold has no effect, when 696 */ 697 QwtColorMap* QwtThermo::colorMap() 698 { 699 return m_data->colorMap; 700 } 701 702 /*! 703 \return Color map for the fill color 704 \warning The alarm threshold has no effect, when 701 705 a color map has been assigned 702 */ 703 const QwtColorMap *QwtThermo::colorMap() const704 { 705 return d_data->colorMap;706 } 707 708 /*! 709 \brief Change the brush of the liquid. 710 711 Changes the QPalette::ButtonText brush of the palette. 712 713 \param brush New brush. 714 \sa fillBrush(), QWidget::setPalette() 715 */ 706 */ 707 const QwtColorMap* QwtThermo::colorMap() const 708 { 709 return m_data->colorMap; 710 } 711 712 /*! 713 \brief Change the brush of the liquid. 714 715 Changes the QPalette::ButtonText brush of the palette. 716 717 \param brush New brush. 718 \sa fillBrush(), QWidget::setPalette() 719 */ 716 720 void QwtThermo::setFillBrush( const QBrush& brush ) 717 721 { … … 722 726 723 727 /*! 724 \return Liquid ( QPalette::ButtonText ) brush. 725 \sa setFillBrush(), QWidget::palette() 726 */ 728 \return Liquid ( QPalette::ButtonText ) brush. 729 \sa setFillBrush(), QWidget::palette() 730 */ 727 731 QBrush QwtThermo::fillBrush() const 728 732 { … … 731 735 732 736 /*! 733 \brief Specify the liquid brush above the alarm threshold 734 735 Changes the QPalette::Highlight brush of the palette. 736 737 \param brush New brush. 738 \sa alarmBrush(), QWidget::setPalette() 739 740 \warning The alarm threshold has no effect, when 737 \brief Specify the liquid brush above the alarm threshold 738 739 Changes the QPalette::Highlight brush of the palette. 740 741 \param brush New brush. 742 \sa alarmBrush(), QWidget::setPalette() 743 744 \warning The alarm threshold has no effect, when 741 745 a color map has been assigned 742 */ 746 */ 743 747 void QwtThermo::setAlarmBrush( const QBrush& brush ) 744 748 { … … 749 753 750 754 /*! 751 \return Liquid brush ( QPalette::Highlight ) above the alarm threshold. 752 \sa setAlarmBrush(), QWidget::palette() 753 754 \warning The alarm threshold has no effect, when 755 \return Liquid brush ( QPalette::Highlight ) above the alarm threshold. 756 \sa setAlarmBrush(), QWidget::palette() 757 758 \warning The alarm threshold has no effect, when 755 759 a color map has been assigned 756 */ 760 */ 757 761 QBrush QwtThermo::alarmBrush() const 758 762 { … … 761 765 762 766 /*! 763 Specify the alarm threshold. 764 765 \param level Alarm threshold 766 \sa alarmLevel() 767 768 \warning The alarm threshold has no effect, when 767 Specify the alarm threshold. 768 769 \param level Alarm threshold 770 \sa alarmLevel() 771 772 \warning The alarm threshold has no effect, when 769 773 a color map has been assigned 770 */ 774 */ 771 775 void QwtThermo::setAlarmLevel( double level ) 772 776 { 773 d_data->alarmLevel = level;774 d_data->alarmEnabled = 1;777 m_data->alarmLevel = level; 778 m_data->alarmEnabled = 1; 775 779 update(); 776 780 } 777 781 778 782 /*! 779 \return Alarm threshold. 780 \sa setAlarmLevel() 781 782 \warning The alarm threshold has no effect, when 783 \return Alarm threshold. 784 \sa setAlarmLevel() 785 786 \warning The alarm threshold has no effect, when 783 787 a color map has been assigned 784 */ 788 */ 785 789 double QwtThermo::alarmLevel() const 786 790 { 787 return d_data->alarmLevel;788 } 789 790 /*! 791 Change the width of the pipe. 792 793 \param width Width of the pipe 794 \sa pipeWidth() 795 */ 791 return m_data->alarmLevel; 792 } 793 794 /*! 795 Change the width of the pipe. 796 797 \param width Width of the pipe 798 \sa pipeWidth() 799 */ 796 800 void QwtThermo::setPipeWidth( int width ) 797 801 { 798 802 if ( width > 0 ) 799 803 { 800 d_data->pipeWidth = width;804 m_data->pipeWidth = width; 801 805 layoutThermo( true ); 802 806 } … … 804 808 805 809 /*! 806 \return Width of the pipe. 807 \sa setPipeWidth() 808 */ 810 \return Width of the pipe. 811 \sa setPipeWidth() 812 */ 809 813 int QwtThermo::pipeWidth() const 810 814 { 811 return d_data->pipeWidth;812 } 813 814 /*! 815 \brief Enable or disable the alarm threshold 816 \param on true (disabled) or false (enabled) 817 818 \warning The alarm threshold has no effect, when 815 return m_data->pipeWidth; 816 } 817 818 /*! 819 \brief Enable or disable the alarm threshold 820 \param on true (disabled) or false (enabled) 821 822 \warning The alarm threshold has no effect, when 819 823 a color map has been assigned 820 */ 824 */ 821 825 void QwtThermo::setAlarmEnabled( bool on ) 822 826 { 823 d_data->alarmEnabled = on;827 m_data->alarmEnabled = on; 824 828 update(); 825 829 } 826 830 827 831 /*! 828 \return True, when the alarm threshold is enabled. 829 830 \warning The alarm threshold has no effect, when 832 \return True, when the alarm threshold is enabled. 833 834 \warning The alarm threshold has no effect, when 831 835 a color map has been assigned 832 */ 836 */ 833 837 bool QwtThermo::alarmEnabled() const 834 838 { 835 return d_data->alarmEnabled;836 } 837 838 /*! 839 \return the minimum size hint 840 \sa minimumSizeHint() 841 */ 839 return m_data->alarmEnabled; 840 } 841 842 /*! 843 \return the minimum size hint 844 \sa minimumSizeHint() 845 */ 842 846 QSize QwtThermo::sizeHint() const 843 847 { … … 846 850 847 851 /*! 848 \return Minimum size hint 849 \warning The return value depends on the font and the scale. 850 \sa sizeHint() 851 */ 852 \return Minimum size hint 853 \warning The return value depends on the font and the scale. 854 \sa sizeHint() 855 */ 852 856 QSize QwtThermo::minimumSizeHint() const 853 857 { 854 858 int w = 0, h = 0; 855 859 856 if ( d_data->scalePosition != NoScale )857 { 858 const int sdExtent = qCeil( scaleDraw()->extent( font() ) ); 860 if ( m_data->scalePosition != NoScale ) 861 { 862 const int sdExtent = qwtCeil( scaleDraw()->extent( font() ) ); 859 863 const int sdLength = scaleDraw()->minLength( font() ); 860 864 861 865 w = sdLength; 862 h = d_data->pipeWidth + sdExtent +d_data->spacing;866 h = m_data->pipeWidth + sdExtent + m_data->spacing; 863 867 864 868 } … … 866 870 { 867 871 w = 200; 868 h = d_data->pipeWidth;869 } 870 871 if ( d_data->orientation == Qt::Vertical )872 h = m_data->pipeWidth; 873 } 874 875 if ( m_data->orientation == Qt::Vertical ) 872 876 qSwap( w, h ); 873 877 874 w += 2 * d_data->borderWidth;875 h += 2 * d_data->borderWidth;878 w += 2 * m_data->borderWidth; 879 h += 2 * m_data->borderWidth; 876 880 877 881 // finally add the margins 878 int left, right, top, bottom; 879 getContentsMargins( &left, &top, &right, &bottom ); 880 w += left + right; 881 h += top + bottom; 882 const QMargins m = contentsMargins(); 883 w += m.left() + m.right(); 884 h += m.top() + m.bottom(); 882 885 883 886 return QSize( w, h ); … … 885 888 886 889 /*! 887 \brief Calculate the filled rectangle of the pipe 888 889 \param pipeRect Rectangle of the pipe 890 \return Rectangle to be filled ( fill and alarm brush ) 891 892 \sa pipeRect(), alarmRect() 893 */ 894 QRect QwtThermo::fillRect( const QRect &pipeRect ) const890 \brief Calculate the filled rectangle of the pipe 891 892 \param pipeRect Rectangle of the pipe 893 \return Rectangle to be filled ( fill and alarm brush ) 894 895 \sa pipeRect(), alarmRect() 896 */ 897 QRect QwtThermo::fillRect( const QRect& pipeRect ) const 895 898 { 896 899 double origin; 897 if ( d_data->originMode == OriginMinimum )900 if ( m_data->originMode == OriginMinimum ) 898 901 { 899 902 origin = qMin( lowerBound(), upperBound() ); 900 903 } 901 else if ( d_data->originMode == OriginMaximum )904 else if ( m_data->originMode == OriginMaximum ) 902 905 { 903 906 origin = qMax( lowerBound(), upperBound() ); … … 905 908 else // OriginCustom 906 909 { 907 origin = d_data->origin;910 origin = m_data->origin; 908 911 } 909 912 910 913 const QwtScaleMap scaleMap = scaleDraw()->scaleMap(); 911 914 912 int from = qRound( scaleMap.transform( d_data->value ) );915 int from = qRound( scaleMap.transform( m_data->value ) ); 913 916 int to = qRound( scaleMap.transform( origin ) ); 914 917 … … 917 920 918 921 QRect fillRect = pipeRect; 919 if ( d_data->orientation == Qt::Horizontal )922 if ( m_data->orientation == Qt::Horizontal ) 920 923 { 921 924 fillRect.setLeft( from ); … … 932 935 933 936 /*! 934 \brief Calculate the alarm rectangle of the pipe 935 936 \param fillRect Filled rectangle in the pipe 937 \return Rectangle to be filled with the alarm brush 938 939 \sa pipeRect(), fillRect(), alarmLevel(), alarmBrush() 940 */ 941 QRect QwtThermo::alarmRect( const QRect &fillRect ) const937 \brief Calculate the alarm rectangle of the pipe 938 939 \param fillRect Filled rectangle in the pipe 940 \return Rectangle to be filled with the alarm brush 941 942 \sa pipeRect(), fillRect(), alarmLevel(), alarmBrush() 943 */ 944 QRect QwtThermo::alarmRect( const QRect& fillRect ) const 942 945 { 943 946 QRect alarmRect( 0, 0, -1, -1); // something invalid 944 947 945 if ( ! d_data->alarmEnabled )948 if ( !m_data->alarmEnabled ) 946 949 return alarmRect; 947 950 … … 949 952 950 953 bool increasing; 951 if ( d_data->originMode == OriginCustom )952 { 953 increasing = d_data->value >d_data->origin;954 if ( m_data->originMode == OriginCustom ) 955 { 956 increasing = m_data->value > m_data->origin; 954 957 } 955 958 else 956 959 { 957 increasing = d_data->originMode == OriginMinimum;960 increasing = m_data->originMode == OriginMinimum; 958 961 } 959 962 960 963 const QwtScaleMap map = scaleDraw()->scaleMap(); 961 const int alarmPos = qRound( map.transform( d_data->alarmLevel ) );962 const int valuePos = qRound( map.transform( d_data->value ) );963 964 if ( d_data->orientation == Qt::Horizontal )964 const int alarmPos = qRound( map.transform( m_data->alarmLevel ) ); 965 const int valuePos = qRound( map.transform( m_data->value ) ); 966 967 if ( m_data->orientation == Qt::Horizontal ) 965 968 { 966 969 int v1, v2; … … 1004 1007 return alarmRect; 1005 1008 } 1009 1010 #include "moc_qwt_thermo.cpp"
Note:
See TracChangeset
for help on using the changeset viewer.
