Changeset 8127 in ntrip for trunk/BNC/qwt/qwt_scale_draw.cpp
- Timestamp:
- May 10, 2017, 3:20:54 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_scale_draw.cpp
r4271 r8127 17 17 #include <qmath.h> 18 18 19 #if QT_VERSION < 0x040601 20 #define qFastSin(x) qSin(x) 21 #define qFastCos(x) qCos(x) 22 #endif 23 19 24 class QwtScaleDraw::PrivateData 20 25 { … … 59 64 Return alignment of the scale 60 65 \sa setAlignment() 66 \return Alignment of the scale 61 67 */ 62 68 QwtScaleDraw::Alignment QwtScaleDraw::alignment() const … … 67 73 /*! 68 74 Set the alignment of the scale 75 76 \param align Alignment of the scale 69 77 70 78 The default alignment is QwtScaleDraw::BottomScale … … 81 89 TopScale, BottomScale are horizontal (Qt::Horizontal) scales, 82 90 LeftScale, RightScale are vertical (Qt::Vertical) scales. 91 92 \return Orientation of the scale 83 93 84 94 \sa alignment() … … 108 118 \param end End border distance 109 119 */ 110 void QwtScaleDraw::getBorderDistHint( const QFont &font,111 120 void QwtScaleDraw::getBorderDistHint( 121 const QFont &font, int &start, int &end ) const 112 122 { 113 123 start = 0; 114 end = 0;124 end = 1.0; 115 125 116 126 if ( !hasComponent( QwtAbstractScaleDraw::Labels ) ) … … 189 199 190 200 const QList<double> &ticks = scaleDiv().ticks( QwtScaleDiv::MajorTick ); 191 if ( ticks. count() == 0)201 if ( ticks.isEmpty() ) 192 202 return 0; 193 203 … … 200 210 if ( vertical ) 201 211 { 202 bRect2.setRect( -bRect2.bottom(), 0, bRect2.height(), bRect2.width() ); 203 } 204 int maxDist = 0; 212 bRect2.setRect( -bRect2.bottom(), 0.0, bRect2.height(), bRect2.width() ); 213 } 214 215 double maxDist = 0.0; 205 216 206 217 for ( int i = 1; i < ticks.count(); i++ ) … … 210 221 if ( vertical ) 211 222 { 212 bRect2.setRect( -bRect2.bottom(), 0 ,223 bRect2.setRect( -bRect2.bottom(), 0.0, 213 224 bRect2.height(), bRect2.width() ); 214 225 } 215 226 216 intdist = fm.leading(); // space between the labels227 double dist = fm.leading(); // space between the labels 217 228 if ( bRect1.right() > 0 ) 218 229 dist += bRect1.right(); … … 224 235 } 225 236 226 double angle = labelRotation() / 180.0 * M_PI;237 double angle = qwtRadians( labelRotation() ); 227 238 if ( vertical ) 228 239 angle += M_PI / 2; 229 240 230 if ( qSin( angle ) == 0.0 ) 231 return maxDist; 241 const double sinA = qFastSin( angle ); // qreal -> double 242 if ( qFuzzyCompare( sinA + 1.0, 1.0 ) ) 243 return qCeil( maxDist ); 232 244 233 245 const int fmHeight = fm.ascent() - 2; … … 235 247 // The distance we need until there is 236 248 // the height of the label font. This height is needed 237 // for the neighbo ur labal.238 239 int labelDist = qFloor( fmHeight / qSin( angle ) * qCos( angle ));249 // for the neighbored label. 250 251 double labelDist = fmHeight / qFastSin( angle ) * qFastCos( angle ); 240 252 if ( labelDist < 0 ) 241 253 labelDist = -labelDist; 242 254 243 // The cast above floored labelDist. We want to ceil.244 labelDist++;245 246 255 // For text orientations close to the scale orientation 247 256 … … 255 264 labelDist = fmHeight; 256 265 257 return labelDist;266 return qCeil( labelDist ); 258 267 } 259 268 … … 267 276 268 277 \param font Font used for painting the labels 278 \return Extent 269 279 270 280 \sa minLength() … … 292 302 if ( hasComponent( QwtAbstractScaleDraw::Backbone ) ) 293 303 { 294 const double pw = qMax( 1, penWidth() ); // pen width can be zero304 const double pw = qMax( 1, penWidth() ); // pen width can be zero 295 305 d += pw; 296 306 } … … 304 314 305 315 \param font Font used for painting the labels 316 \return Minimum length that is needed to draw the scale 306 317 307 318 \sa extent() … … 337 348 Find the position, where to paint a label 338 349 339 The position has a distance of majTickLength() + spacing() + 1340 from the backbone. The direction depends on the alignment()350 The position has a distance that depends on the length of the ticks 351 in direction of the alignment(). 341 352 342 353 \param value Value 354 \return Position, where to paint a label 343 355 */ 344 356 QPointF QwtScaleDraw::labelPosition( double value ) const … … 391 403 \param painter Painter 392 404 \param value Value of the tick 393 \param len Leng htof the tick405 \param len Length of the tick 394 406 395 407 \sa drawBackbone(), drawLabel() … … 597 609 overlapping labels. 598 610 611 \param length Length of the backbone 612 599 613 \sa move(), minLabelDist() 600 614 */ 601 615 void QwtScaleDraw::setLength( double length ) 602 616 { 617 #if 1 603 618 if ( length >= 0 && length < 10 ) 604 619 length = 10; 620 621 // why should we accept negative lengths ??? 605 622 if ( length < 0 && length > -10 ) 606 623 length = -10; 624 #else 625 length = qMax( length, 10 ); 626 #endif 607 627 608 628 d_data->len = length; … … 648 668 649 669 /*! 650 Find the bounding rect for the label. The coordinates of 651 the rect are absolute coordinates ( calculated from pos() ). 670 \brief Find the bounding rectangle for the label. 671 672 The coordinates of the rectangle are absolute ( calculated from pos() ). 652 673 in direction of the tick. 653 674 … … 655 676 \param value Value 656 677 678 \return Bounding rectangle 657 679 \sa labelRect() 658 680 */ … … 677 699 \param size Size of the label 678 700 701 \return Transformation matrix 679 702 \sa setLabelAlignment(), setLabelRotation() 680 703 */ … … 740 763 741 764 /*! 742 Find the bounding rect for the label. The coordinates of743 the rect are relative to spacing + ticklength from the backbone765 Find the bounding rectangle for the label. The coordinates of 766 the rectangle are relative to spacing + tick length from the backbone 744 767 in direction of the tick. 745 768 746 769 \param font Font used for painting 747 770 \param value Value 771 772 \return Bounding rectangle that is needed to draw a label 748 773 */ 749 774 QRectF QwtScaleDraw::labelRect( const QFont &font, double value ) const … … 769 794 \param font Label font 770 795 \param value Value 796 797 \return Size that is needed to draw a label 771 798 */ 772 799 QSizeF QwtScaleDraw::labelSize( const QFont &font, double value ) const … … 805 832 \brief Change the label flags 806 833 807 Labels are aligned to the point tick length + spacing away from the backbone.834 Labels are aligned to the point tick length + spacing away from the backbone. 808 835 809 836 The alignment is relative to the orientation of the label text. … … 824 851 The alignment of the label is not the alignment 825 852 of the scale and is not the alignment of the flags 826 ( QwtText::flags()) returned from QwtAbstractScaleDraw::label().853 ( QwtText::flags() ) returned from QwtAbstractScaleDraw::label(). 827 854 */ 828 855 … … 847 874 int QwtScaleDraw::maxLabelWidth( const QFont &font ) const 848 875 { 849 int maxWidth =0;876 double maxWidth = 0.0; 850 877 851 878 const QList<double> &ticks = scaleDiv().ticks( QwtScaleDiv::MajorTick ); … … 855 882 if ( scaleDiv().contains( v ) ) 856 883 { 857 const intw = labelSize( font, ticks[i] ).width();884 const double w = labelSize( font, ticks[i] ).width(); 858 885 if ( w > maxWidth ) 859 886 maxWidth = w; … … 861 888 } 862 889 863 return maxWidth;890 return qCeil( maxWidth ); 864 891 } 865 892 … … 870 897 int QwtScaleDraw::maxLabelHeight( const QFont &font ) const 871 898 { 872 int maxHeight =0;899 double maxHeight = 0.0; 873 900 874 901 const QList<double> &ticks = scaleDiv().ticks( QwtScaleDiv::MajorTick ); … … 878 905 if ( scaleDiv().contains( v ) ) 879 906 { 880 const inth = labelSize( font, ticks[i] ).height();907 const double h = labelSize( font, ticks[i] ).height(); 881 908 if ( h > maxHeight ) 882 909 maxHeight = h; … … 884 911 } 885 912 886 return maxHeight;913 return qCeil( maxHeight ); 887 914 } 888 915
Note:
See TracChangeset
for help on using the changeset viewer.