Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_scale_draw.cpp
- Timestamp:
- Nov 3, 2026, 10:53:35 AM (3 weeks ago)
- File:
-
- 1 edited
-
trunk/BNC/qwt/qwt_scale_draw.cpp (modified) (32 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_scale_draw.cpp
r9383 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_math.h" 14 14 #include "qwt_painter.h" 15 #include <qpen.h> 15 #include "qwt_text.h" 16 16 17 #include <qpainter.h> 18 #include <qpaintengine.h> 17 19 #include <qmath.h> 18 20 19 #if QT_VERSION < 0x040601 20 #define qFastSin(x) qSin(x) 21 #define qFastCos(x) qCos(x) 21 static inline double qwtEffectivePenWidth( const QwtAbstractScaleDraw* scaleDraw ) 22 { 23 return qwtMaxF( scaleDraw->penWidthF(), 1.0 ); 24 } 25 26 namespace QwtScaleRendererReal 27 { 28 inline qreal penWidth( const QPainter* painter, const QwtScaleDraw* scaleDraw ) 29 { 30 qreal width = scaleDraw->penWidthF(); 31 #if 1 32 if ( width <= 0.0 ) 33 width = 1.0; 22 34 #endif 23 35 36 if ( painter->pen().isCosmetic() ) 37 { 38 const QTransform& transform = painter->transform(); 39 40 switch ( scaleDraw->alignment() ) 41 { 42 case QwtScaleDraw::LeftScale: 43 case QwtScaleDraw::RightScale: 44 { 45 width /= transform.m11(); 46 break; 47 } 48 case QwtScaleDraw::TopScale: 49 case QwtScaleDraw::BottomScale: 50 { 51 width /= transform.m22(); 52 break; 53 } 54 } 55 } 56 57 return width; 58 } 59 60 inline void drawBackbone( QPainter* painter, const QwtScaleDraw* scaleDraw ) 61 { 62 const qreal pw2 = 0.5 * penWidth( painter, scaleDraw ); 63 64 const QPointF pos = scaleDraw->pos(); 65 const qreal length = scaleDraw->length(); 66 67 switch ( scaleDraw->alignment() ) 68 { 69 case QwtScaleDraw::LeftScale: 70 { 71 const qreal x = pos.x() + 1.0 - pw2; 72 QwtPainter::drawLine( painter, x, pos.y(), x, pos.y() + length ); 73 74 break; 75 } 76 case QwtScaleDraw::RightScale: 77 { 78 const qreal x = pos.x() - 1.0 + pw2; 79 QwtPainter::drawLine( painter, x, pos.y(), x, pos.y() + length ); 80 81 break; 82 } 83 case QwtScaleDraw::TopScale: 84 { 85 const qreal y = pos.y() + 1.0 - pw2; 86 QwtPainter::drawLine( painter, pos.x(), y, pos.x() + length, y ); 87 88 break; 89 } 90 case QwtScaleDraw::BottomScale: 91 { 92 const qreal y = pos.y() - 1.0 + pw2; 93 QwtPainter::drawLine( painter, pos.x(), y, pos.x() + length, y ); 94 95 break; 96 } 97 } 98 } 99 100 inline void drawTick( QPainter* painter, 101 const QwtScaleDraw* scaleDraw, qreal tickPos, qreal tickLength ) 102 { 103 const QPointF pos = scaleDraw->pos(); 104 105 qreal pw = 0.0; 106 107 if ( scaleDraw->hasComponent( QwtScaleDraw::Backbone ) ) 108 pw = penWidth( painter, scaleDraw ); 109 110 const qreal length = tickLength + pw; 111 112 /* 113 Those correction offsets have been found by try and error. 114 They need to be understood and replaced by a calculation, 115 that makes sense. TODO ... 116 */ 117 const qreal off1 = 1.0; 118 const qreal off2 = ( scaleDraw->penWidthF() <= 0.0 ) ? 0.5 : 0.0; 119 120 switch ( scaleDraw->alignment() ) 121 { 122 case QwtScaleDraw::LeftScale: 123 { 124 const qreal x = pos.x() + off1 - off2; 125 QwtPainter::drawLine( painter, x, tickPos, x - length, tickPos ); 126 127 break; 128 } 129 case QwtScaleDraw::RightScale: 130 { 131 const qreal x = pos.x() - off1 + off2; 132 QwtPainter::drawLine( painter, x, tickPos, x + length, tickPos ); 133 break; 134 } 135 case QwtScaleDraw::TopScale: 136 { 137 const qreal y = pos.y() + off1 - 2 * off2; 138 QwtPainter::drawLine( painter, tickPos, y, tickPos, y - length ); 139 140 break; 141 } 142 case QwtScaleDraw::BottomScale: 143 { 144 const qreal y = pos.y() - off1 + off2; 145 QwtPainter::drawLine( painter, tickPos, y, tickPos, y + length ); 146 147 break; 148 } 149 } 150 } 151 } 152 153 namespace QwtScaleRendererInt 154 { 155 inline void drawBackbone( QPainter* painter, const QwtScaleDraw* scaleDraw ) 156 { 157 const int pw = qMax( qRound( scaleDraw->penWidthF() ), 1 ); 158 159 const qreal length = scaleDraw->length(); 160 const QPointF pos = scaleDraw->pos(); 161 162 switch ( scaleDraw->alignment() ) 163 { 164 case QwtScaleDraw::LeftScale: 165 { 166 const qreal x = qRound( pos.x() - ( pw - 1 ) / 2 ); 167 QwtPainter::drawLine( painter, x, pos.y(), x, pos.y() + length ); 168 169 break; 170 } 171 case QwtScaleDraw::RightScale: 172 { 173 const qreal x = qRound( pos.x() + pw / 2 ); 174 QwtPainter::drawLine( painter, x, pos.y(), x, pos.y() + length ); 175 176 break; 177 } 178 case QwtScaleDraw::TopScale: 179 { 180 const qreal y = qRound( pos.y() - ( pw - 1 ) / 2 ); 181 QwtPainter::drawLine( painter, pos.x(), y, pos.x() + length, y ); 182 183 break; 184 } 185 case QwtScaleDraw::BottomScale: 186 { 187 const qreal y = qRound( pos.y() + pw / 2 ); 188 QwtPainter::drawLine( painter, pos.x(), y, pos.x() + length, y ); 189 190 break; 191 } 192 } 193 } 194 195 inline void drawTick( QPainter* painter, 196 const QwtScaleDraw* scaleDraw, qreal tickPos, qreal tickLength ) 197 { 198 const QPointF pos = scaleDraw->pos(); 199 tickPos = qRound( tickPos ); 200 201 int pw = 0; 202 if ( scaleDraw->hasComponent( QwtScaleDraw::Backbone ) ) 203 pw = qMax( qRound( scaleDraw->penWidthF() ), 1 ); 204 205 int len = qMax( qRound( tickLength ), 1 ); 206 207 // the width of ticks at the borders might extent the backbone 208 len += pw; 209 210 if ( painter->pen().capStyle() == Qt::FlatCap ) 211 len++; // the end point is not rendered 212 213 qreal off = 0.0; 214 215 if ( painter->paintEngine()->type() == QPaintEngine::X11 ) 216 { 217 if ( pw == 1 ) 218 { 219 // In opposite to raster, X11 paints the end point 220 off = 1.0; 221 } 222 } 223 224 switch ( scaleDraw->alignment() ) 225 { 226 case QwtScaleDraw::LeftScale: 227 { 228 const qreal x1 = qRound( pos.x() ) + 1; 229 const qreal x2 = x1 - len + 1; 230 231 QwtPainter::drawLine( painter, x2, tickPos, x1 - off, tickPos ); 232 233 break; 234 } 235 case QwtScaleDraw::RightScale: 236 { 237 const qreal x1 = qRound( pos.x() ); 238 const qreal x2 = x1 + len - 1; 239 240 QwtPainter::drawLine( painter, x1, tickPos, x2 - off, tickPos ); 241 242 break; 243 } 244 case QwtScaleDraw::BottomScale: 245 { 246 const qreal y1 = qRound( pos.y() ); 247 const qreal y2 = y1 + len - 1; 248 249 QwtPainter::drawLine( painter, tickPos, y1, tickPos, y2 - off ); 250 251 break; 252 } 253 case QwtScaleDraw::TopScale: 254 { 255 const qreal y1 = qRound( pos.y() ); 256 const qreal y2 = y1 - len + 1; 257 258 QwtPainter::drawLine( painter, tickPos, y2 + 1, tickPos, y1 + 1 - off ); 259 260 break; 261 } 262 } 263 } 264 } 265 24 266 class QwtScaleDraw::PrivateData 25 267 { 26 public: 27 PrivateData(): 28 len( 0 ), 29 alignment( QwtScaleDraw::BottomScale ), 30 labelAlignment( 0 ), 31 labelRotation( 0.0 ) 268 public: 269 PrivateData() 270 : len( 0 ) 271 , alignment( QwtScaleDraw::BottomScale ) 272 , labelRotation( 0.0 ) 32 273 { 33 274 } … … 43 284 44 285 /*! 45 \brief Constructor 46 47 The range of the scale is initialized to [0, 100], 48 The position is at (0, 0) with a length of 100. 49 The orientation is QwtAbstractScaleDraw::Bottom. 50 */ 286 \brief Constructor 287 288 The range of the scale is initialized to [0, 100], 289 The position is at (0, 0) with a length of 100. 290 The orientation is QwtAbstractScaleDraw::Bottom. 291 */ 51 292 QwtScaleDraw::QwtScaleDraw() 52 293 { 53 d_data = new QwtScaleDraw::PrivateData;294 m_data = new QwtScaleDraw::PrivateData; 54 295 setLength( 100 ); 55 296 } … … 58 299 QwtScaleDraw::~QwtScaleDraw() 59 300 { 60 delete d_data;301 delete m_data; 61 302 } 62 303 … … 65 306 \sa setAlignment() 66 307 \return Alignment of the scale 67 */ 308 */ 68 309 QwtScaleDraw::Alignment QwtScaleDraw::alignment() const 69 310 { 70 return d_data->alignment;311 return m_data->alignment; 71 312 } 72 313 … … 78 319 The default alignment is QwtScaleDraw::BottomScale 79 320 \sa alignment() 80 */ 321 */ 81 322 void QwtScaleDraw::setAlignment( Alignment align ) 82 323 { 83 d_data->alignment = align;84 } 85 86 /*! 87 Return the orientation 88 89 TopScale, BottomScale are horizontal (Qt::Horizontal) scales, 90 LeftScale, RightScale are vertical (Qt::Vertical) scales. 91 92 \return Orientation of the scale 93 94 \sa alignment() 95 */ 324 m_data->alignment = align; 325 } 326 327 /*! 328 Return the orientation 329 330 TopScale, BottomScale are horizontal (Qt::Horizontal) scales, 331 LeftScale, RightScale are vertical (Qt::Vertical) scales. 332 333 \return Orientation of the scale 334 335 \sa alignment() 336 */ 96 337 Qt::Orientation QwtScaleDraw::orientation() const 97 338 { 98 switch ( d_data->alignment )339 switch ( m_data->alignment ) 99 340 { 100 341 case TopScale: … … 109 350 110 351 /*! 111 \brief Determine the minimum border distance 112 113 This member function returns the minimum space 114 needed to draw the mark labels at the scale's endpoints. 115 116 \param font Font 117 \param start Start border distance 118 \param end End border distance 119 */ 352 \brief Determine the minimum border distance 353 354 This member function returns the minimum space 355 needed to draw the mark labels at the scale's endpoints. 356 357 \param font Font 358 \param start Start border distance 359 \param end End border distance 360 */ 120 361 void QwtScaleDraw::getBorderDistHint( 121 const QFont &font, int&start, int&end ) const362 const QFont& font, int& start, int& end ) const 122 363 { 123 364 start = 0; … … 127 368 return; 128 369 129 const QList< double> &ticks = scaleDiv().ticks( QwtScaleDiv::MajorTick );370 const QList< double >& ticks = scaleDiv().ticks( QwtScaleDiv::MajorTick ); 130 371 if ( ticks.count() == 0 ) 131 372 return; … … 179 420 e = 0.0; 180 421 181 start = qCeil( s ); 182 end = qCeil( e ); 183 } 184 185 /*! 186 Determine the minimum distance between two labels, that is necessary 187 that the texts don't overlap. 188 189 \param font Font 190 \return The maximum width of a label 191 192 \sa getBorderDistHint() 193 */ 194 195 int QwtScaleDraw::minLabelDist( const QFont &font ) const422 start = qwtCeil( s ); 423 end = qwtCeil( e ); 424 } 425 426 /*! 427 Determine the minimum distance between two labels, that is necessary 428 that the texts don't overlap. 429 430 \param font Font 431 \return The maximum width of a label 432 433 \sa getBorderDistHint() 434 */ 435 436 int QwtScaleDraw::minLabelDist( const QFont& font ) const 196 437 { 197 438 if ( !hasComponent( QwtAbstractScaleDraw::Labels ) ) 198 439 return 0; 199 440 200 const QList< double> &ticks = scaleDiv().ticks( QwtScaleDiv::MajorTick );441 const QList< double >& ticks = scaleDiv().ticks( QwtScaleDiv::MajorTick ); 201 442 if ( ticks.isEmpty() ) 202 443 return 0; … … 279 520 280 521 \sa minLength() 281 */ 282 double QwtScaleDraw::extent( const QFont &font ) const522 */ 523 double QwtScaleDraw::extent( const QFont& font ) const 283 524 { 284 525 double d = 0; … … 302 543 if ( hasComponent( QwtAbstractScaleDraw::Backbone ) ) 303 544 { 304 const double pw = qMax( 1, penWidth() ); // pen width can be zero 305 d += pw; 306 } 307 308 d = qMax( d, minimumExtent() ); 545 d += qwtEffectivePenWidth( this ); 546 } 547 548 d = qwtMaxF( d, minimumExtent() ); 309 549 return d; 310 550 } … … 317 557 318 558 \sa extent() 319 */ 320 int QwtScaleDraw::minLength( const QFont &font ) const559 */ 560 int QwtScaleDraw::minLength( const QFont& font ) const 321 561 { 322 562 int startDist, endDist; 323 563 getBorderDistHint( font, startDist, endDist ); 324 564 325 const QwtScaleDiv &sd = scaleDiv();565 const QwtScaleDiv& sd = scaleDiv(); 326 566 327 567 const uint minorCount = … … 338 578 if ( hasComponent( QwtAbstractScaleDraw::Ticks ) ) 339 579 { 340 const double pw = q Max( 1, penWidth() ); // penwidth can be zero580 const double pw = qwtEffectivePenWidth( this ); 341 581 lengthForTicks = qCeil( ( majorCount + minorCount ) * ( pw + 1.0 ) ); 342 582 } … … 353 593 \param value Value 354 594 \return Position, where to paint a label 355 */ 595 */ 356 596 QPointF QwtScaleDraw::labelPosition( double value ) const 357 597 { … … 359 599 double dist = spacing(); 360 600 if ( hasComponent( QwtAbstractScaleDraw::Backbone ) ) 361 dist += q Max( 1, penWidth());601 dist += qwtEffectivePenWidth( this ); 362 602 363 603 if ( hasComponent( QwtAbstractScaleDraw::Ticks ) ) … … 371 611 case RightScale: 372 612 { 373 px = d_data->pos.x() + dist;613 px = m_data->pos.x() + dist; 374 614 py = tval; 375 615 break; … … 377 617 case LeftScale: 378 618 { 379 px = d_data->pos.x() - dist;619 px = m_data->pos.x() - dist; 380 620 py = tval; 381 621 break; … … 384 624 { 385 625 px = tval; 386 py = d_data->pos.y() + dist;626 py = m_data->pos.y() + dist; 387 627 break; 388 628 } … … 390 630 { 391 631 px = tval; 392 py = d_data->pos.y() - dist;632 py = m_data->pos.y() - dist; 393 633 break; 394 634 } … … 406 646 407 647 \sa drawBackbone(), drawLabel() 408 */ 409 void QwtScaleDraw::drawTick( QPainter *painter, double value, double len ) const648 */ 649 void QwtScaleDraw::drawTick( QPainter* painter, double value, double len ) const 410 650 { 411 651 if ( len <= 0 ) 412 652 return; 413 653 414 const bool roundingAlignment = QwtPainter::roundingAlignment( painter ); 415 416 QPointF pos = d_data->pos; 417 418 double tval = scaleMap().transform( value ); 419 if ( roundingAlignment ) 420 tval = qRound( tval ); 421 422 const int pw = penWidth(); 423 int a = 0; 424 if ( pw > 1 && roundingAlignment ) 425 a = 1; 426 427 switch ( alignment() ) 428 { 429 case LeftScale: 430 { 431 double x1 = pos.x() + a; 432 double x2 = pos.x() + a - pw - len; 433 if ( roundingAlignment ) 434 { 435 x1 = qRound( x1 ); 436 x2 = qRound( x2 ); 437 } 438 439 QwtPainter::drawLine( painter, x1, tval, x2, tval ); 440 break; 441 } 442 443 case RightScale: 444 { 445 double x1 = pos.x(); 446 double x2 = pos.x() + pw + len; 447 if ( roundingAlignment ) 448 { 449 x1 = qRound( x1 ); 450 x2 = qRound( x2 ); 451 } 452 453 QwtPainter::drawLine( painter, x1, tval, x2, tval ); 454 break; 455 } 456 457 case BottomScale: 458 { 459 double y1 = pos.y(); 460 double y2 = pos.y() + pw + len; 461 if ( roundingAlignment ) 462 { 463 y1 = qRound( y1 ); 464 y2 = qRound( y2 ); 465 } 466 467 QwtPainter::drawLine( painter, tval, y1, tval, y2 ); 468 break; 469 } 470 471 case TopScale: 472 { 473 double y1 = pos.y() + a; 474 double y2 = pos.y() - pw - len + a; 475 if ( roundingAlignment ) 476 { 477 y1 = qRound( y1 ); 478 y2 = qRound( y2 ); 479 } 480 481 QwtPainter::drawLine( painter, tval, y1, tval, y2 ); 482 break; 483 } 484 } 654 const double tval = scaleMap().transform( value ); 655 656 if ( QwtPainter::roundingAlignment( painter ) ) 657 QwtScaleRendererInt::drawTick( painter, this, tval, len ); 658 else 659 QwtScaleRendererReal::drawTick( painter, this, tval, len ); 485 660 } 486 661 … … 490 665 491 666 \sa drawTick(), drawLabel() 492 */ 493 void QwtScaleDraw::drawBackbone( QPainter *painter ) const 494 { 495 const bool doAlign = QwtPainter::roundingAlignment( painter ); 496 497 const QPointF &pos = d_data->pos; 498 const double len = d_data->len; 499 const int pw = qMax( penWidth(), 1 ); 500 501 // pos indicates a border not the center of the backbone line 502 // so we need to shift its position depending on the pen width 503 // and the alignment of the scale 504 505 double off; 506 if ( doAlign ) 507 { 508 if ( alignment() == LeftScale || alignment() == TopScale ) 509 off = ( pw - 1 ) / 2; 510 else 511 off = pw / 2; 512 } 667 */ 668 void QwtScaleDraw::drawBackbone( QPainter* painter ) const 669 { 670 if ( QwtPainter::roundingAlignment( painter ) ) 671 QwtScaleRendererInt::drawBackbone( painter, this ); 513 672 else 514 { 515 off = 0.5 * penWidth(); 516 } 517 518 switch ( alignment() ) 519 { 520 case LeftScale: 521 { 522 double x = pos.x() - off; 523 if ( doAlign ) 524 x = qRound( x ); 525 526 QwtPainter::drawLine( painter, x, pos.y(), x, pos.y() + len ); 527 break; 528 } 529 case RightScale: 530 { 531 double x = pos.x() + off; 532 if ( doAlign ) 533 x = qRound( x ); 534 535 QwtPainter::drawLine( painter, x, pos.y(), x, pos.y() + len ); 536 break; 537 } 538 case TopScale: 539 { 540 double y = pos.y() - off; 541 if ( doAlign ) 542 y = qRound( y ); 543 544 QwtPainter::drawLine( painter, pos.x(), y, pos.x() + len, y ); 545 break; 546 } 547 case BottomScale: 548 { 549 double y = pos.y() + off; 550 if ( doAlign ) 551 y = qRound( y ); 552 553 QwtPainter::drawLine( painter, pos.x(), y, pos.x() + len, y ); 554 break; 555 } 556 } 557 } 558 559 /*! 560 \brief Move the position of the scale 561 562 The meaning of the parameter pos depends on the alignment: 563 <dl> 564 <dt>QwtScaleDraw::LeftScale 565 <dd>The origin is the topmost point of the 673 QwtScaleRendererReal::drawBackbone( painter, this ); 674 } 675 676 /*! 677 \brief Move the position of the scale 678 679 The meaning of the parameter pos depends on the alignment: 680 <dl> 681 <dt>QwtScaleDraw::LeftScale 682 <dd>The origin is the topmost point of the 566 683 backbone. The backbone is a vertical line. 567 684 Scale marks and labels are drawn 568 685 at the left of the backbone. 569 <dt>QwtScaleDraw::RightScale 570 <dd>The origin is the topmost point of the 686 <dt>QwtScaleDraw::RightScale 687 <dd>The origin is the topmost point of the 571 688 backbone. The backbone is a vertical line. 572 689 Scale marks and labels are drawn 573 690 at the right of the backbone. 574 <dt>QwtScaleDraw::TopScale 575 <dd>The origin is the leftmost point of the 691 <dt>QwtScaleDraw::TopScale 692 <dd>The origin is the leftmost point of the 576 693 backbone. The backbone is a horizontal line. 577 694 Scale marks and labels are drawn 578 695 above the backbone. 579 <dt>QwtScaleDraw::BottomScale 580 <dd>The origin is the leftmost point of the 696 <dt>QwtScaleDraw::BottomScale 697 <dd>The origin is the leftmost point of the 581 698 backbone. The backbone is a horizontal line 582 699 Scale marks and labels are drawn 583 700 below the backbone. 584 </dl> 585 586 \param pos Origin of the scale 587 588 \sa pos(), setLength() 589 */ 590 void QwtScaleDraw::move( const QPointF &pos )591 { 592 d_data->pos = pos;701 </dl> 702 703 \param pos Origin of the scale 704 705 \sa pos(), setLength() 706 */ 707 void QwtScaleDraw::move( const QPointF& pos ) 708 { 709 m_data->pos = pos; 593 710 updateMap(); 594 711 } … … 597 714 \return Origin of the scale 598 715 \sa move(), length() 599 */ 716 */ 600 717 QPointF QwtScaleDraw::pos() const 601 718 { 602 return d_data->pos;603 } 604 605 /*! 606 Set the length of the backbone. 607 608 The length doesn't include the space needed for 609 overlapping labels. 610 611 \param length Length of the backbone 612 613 \sa move(), minLabelDist() 614 */ 719 return m_data->pos; 720 } 721 722 /*! 723 Set the length of the backbone. 724 725 The length doesn't include the space needed for 726 overlapping labels. 727 728 \param length Length of the backbone 729 730 \sa move(), minLabelDist() 731 */ 615 732 void QwtScaleDraw::setLength( double length ) 616 733 { 617 #if 1618 734 if ( length >= 0 && length < 10 ) 619 735 length = 10; 620 736 621 // why should we accept negative lengths ???737 // f.e the left/bottom scales of a polar plot 622 738 if ( length < 0 && length > -10 ) 623 739 length = -10; 624 #else 625 length = qMax( length, 10 ); 626 #endif 627 628 d_data->len = length; 740 741 m_data->len = length; 629 742 updateMap(); 630 743 } … … 633 746 \return the length of the backbone 634 747 \sa setLength(), pos() 635 */ 748 */ 636 749 double QwtScaleDraw::length() const 637 750 { 638 return d_data->len;751 return m_data->len; 639 752 } 640 753 … … 646 759 647 760 \sa drawTick(), drawBackbone(), boundingLabelRect() 648 */ 649 void QwtScaleDraw::drawLabel( QPainter *painter, double value ) const761 */ 762 void QwtScaleDraw::drawLabel( QPainter* painter, double value ) const 650 763 { 651 764 QwtText lbl = tickLabel( painter->font(), value ); … … 668 781 669 782 /*! 670 \brief Find the bounding rectangle for the label. 671 672 The coordinates of the rectangle are absolute ( calculated from pos() ). 673 in direction of the tick. 674 675 \param font Font used for painting 676 \param value Value 677 678 \return Bounding rectangle 679 \sa labelRect() 680 */ 681 QRect QwtScaleDraw::boundingLabelRect( const QFont &font, double value ) const783 \brief Find the bounding rectangle for the label. 784 785 The coordinates of the rectangle are absolute ( calculated from pos() ). 786 in direction of the tick. 787 788 \param font Font used for painting 789 \param value Value 790 791 \return Bounding rectangle 792 \sa labelRect() 793 */ 794 QRect QwtScaleDraw::boundingLabelRect( const QFont& font, double value ) const 682 795 { 683 796 QwtText lbl = tickLabel( font, value ); … … 701 814 \return Transformation matrix 702 815 \sa setLabelAlignment(), setLabelRotation() 703 */ 816 */ 704 817 QTransform QwtScaleDraw::labelTransformation( 705 const QPointF &pos, const QSizeF&size ) const818 const QPointF& pos, const QSizeF& size ) const 706 819 { 707 820 QTransform transform; … … 763 876 764 877 /*! 765 Find the bounding rectangle for the label. The coordinates of 766 the rectangle are relative to spacing + tick length from the backbone 767 in direction of the tick. 768 769 \param font Font used for painting 770 \param value Value 878 Find the bounding rectangle for the label. The coordinates of 879 the rectangle are relative to spacing + tick length from the backbone 880 in direction of the tick. 881 882 \param font Font used for painting 883 \param value Value 771 884 772 885 \return Bounding rectangle that is needed to draw a label 773 */ 774 QRectF QwtScaleDraw::labelRect( const QFont &font, double value ) const886 */ 887 QRectF QwtScaleDraw::labelRect( const QFont& font, double value ) const 775 888 { 776 889 QwtText lbl = tickLabel( font, value ); … … 796 909 797 910 \return Size that is needed to draw a label 798 */ 799 QSizeF QwtScaleDraw::labelSize( const QFont &font, double value ) const911 */ 912 QSizeF QwtScaleDraw::labelSize( const QFont& font, double value ) const 800 913 { 801 914 return labelRect( font, value ).size(); … … 803 916 804 917 /*! 805 Rotate all labels. 806 807 When changing the rotation, it might be necessary to 808 adjust the label flags too. Finding a useful combination is 809 often the result of try and error. 810 811 \param rotation Angle in degrees. When changing the label rotation, 918 Rotate all labels. 919 920 When changing the rotation, it might be necessary to 921 adjust the label flags too. Finding a useful combination is 922 often the result of try and error. 923 924 \param rotation Angle in degrees. When changing the label rotation, 812 925 the label flags often needs to be adjusted too. 813 926 814 \sa setLabelAlignment(), labelRotation(), labelAlignment(). 815 816 */ 927 \sa setLabelAlignment(), labelRotation(), labelAlignment(). 928 929 */ 817 930 void QwtScaleDraw::setLabelRotation( double rotation ) 818 931 { 819 d_data->labelRotation = rotation;820 } 821 822 /*! 823 \return the label rotation 824 \sa setLabelRotation(), labelAlignment() 825 */ 932 m_data->labelRotation = rotation; 933 } 934 935 /*! 936 \return the label rotation 937 \sa setLabelRotation(), labelAlignment() 938 */ 826 939 double QwtScaleDraw::labelRotation() const 827 940 { 828 return d_data->labelRotation;829 } 830 831 /*! 832 \brief Change the label flags 833 834 Labels are aligned to the point tick length + spacing away from the backbone. 835 836 The alignment is relative to the orientation of the label text. 837 In case of an flags of 0 the label will be aligned 838 depending on the orientation of the scale: 941 return m_data->labelRotation; 942 } 943 944 /*! 945 \brief Change the label flags 946 947 Labels are aligned to the point tick length + spacing away from the backbone. 948 949 The alignment is relative to the orientation of the label text. 950 In case of an flags of 0 the label will be aligned 951 depending on the orientation of the scale: 839 952 840 953 QwtScaleDraw::TopScale: Qt::AlignHCenter | Qt::AlignTop\n … … 843 956 QwtScaleDraw::RightScale: Qt::AlignRight | Qt::AlignVCenter\n 844 957 845 Changing the alignment is often necessary for rotated labels. 846 847 \param alignment Or'd Qt::AlignmentFlags see <qnamespace.h> 848 849 \sa setLabelRotation(), labelRotation(), labelAlignment() 850 \warning The various alignments might be confusing. 958 Changing the alignment is often necessary for rotated labels. 959 960 \param alignment Or'd Qt::AlignmentFlags see <qnamespace.h> 961 962 \sa setLabelRotation(), labelRotation(), labelAlignment() 963 \warning The various alignments might be confusing. 851 964 The alignment of the label is not the alignment 852 965 of the scale and is not the alignment of the flags 853 966 ( QwtText::flags() ) returned from QwtAbstractScaleDraw::label(). 854 */ 967 */ 855 968 856 969 void QwtScaleDraw::setLabelAlignment( Qt::Alignment alignment ) 857 970 { 858 d_data->labelAlignment = alignment;859 } 860 861 /*! 862 \return the label flags 863 \sa setLabelAlignment(), labelRotation() 864 */ 971 m_data->labelAlignment = alignment; 972 } 973 974 /*! 975 \return the label flags 976 \sa setLabelAlignment(), labelRotation() 977 */ 865 978 Qt::Alignment QwtScaleDraw::labelAlignment() const 866 979 { 867 return d_data->labelAlignment;868 } 869 870 /*! 871 \param font Font 872 \return the maximum width of a label 873 */ 874 int QwtScaleDraw::maxLabelWidth( const QFont &font ) const980 return m_data->labelAlignment; 981 } 982 983 /*! 984 \param font Font 985 \return the maximum width of a label 986 */ 987 int QwtScaleDraw::maxLabelWidth( const QFont& font ) const 875 988 { 876 989 double maxWidth = 0.0; 877 990 878 const QList< double> &ticks = scaleDiv().ticks( QwtScaleDiv::MajorTick );991 const QList< double >& ticks = scaleDiv().ticks( QwtScaleDiv::MajorTick ); 879 992 for ( int i = 0; i < ticks.count(); i++ ) 880 993 { … … 892 1005 893 1006 /*! 894 \param font Font 895 \return the maximum height of a label 896 */ 897 int QwtScaleDraw::maxLabelHeight( const QFont &font ) const1007 \param font Font 1008 \return the maximum height of a label 1009 */ 1010 int QwtScaleDraw::maxLabelHeight( const QFont& font ) const 898 1011 { 899 1012 double maxHeight = 0.0; 900 1013 901 const QList< double> &ticks = scaleDiv().ticks( QwtScaleDiv::MajorTick );1014 const QList< double >& ticks = scaleDiv().ticks( QwtScaleDiv::MajorTick ); 902 1015 for ( int i = 0; i < ticks.count(); i++ ) 903 1016 { … … 916 1029 void QwtScaleDraw::updateMap() 917 1030 { 918 const QPointF pos = d_data->pos;919 double len = d_data->len;920 921 QwtScaleMap &sm = scaleMap();1031 const QPointF pos = m_data->pos; 1032 double len = m_data->len; 1033 1034 QwtScaleMap& sm = scaleMap(); 922 1035 if ( orientation() == Qt::Vertical ) 923 1036 sm.setPaintInterval( pos.y() + len, pos.y() );
Note:
See TracChangeset
for help on using the changeset viewer.
