Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_date_scale_engine.cpp
- Timestamp:
- Nov 3, 2026, 10:53:35 AM (3 weeks ago)
- File:
-
- 1 edited
-
trunk/BNC/qwt/qwt_date_scale_engine.cpp (modified) (43 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_date_scale_engine.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 10 10 #include "qwt_date_scale_engine.h" 11 11 #include "qwt_math.h" 12 #include "qwt_transform.h" 12 #include "qwt_interval.h" 13 13 14 #include <qdatetime.h> 14 #include <limits.h> 15 16 #include <limits> 15 17 16 18 static inline double qwtMsecsForType( int type ) … … 28 30 }; 29 31 30 if ( type < 0 || type >= static_cast< int>( sizeof( msecs ) / sizeof( msecs[0] ) ) )32 if ( type < 0 || type >= static_cast< int >( sizeof( msecs ) / sizeof( msecs[0] ) ) ) 31 33 return 1.0; 32 34 … … 38 40 { 39 41 double d = value / stepSize; 40 d = up ? ::ceil( d ) : ::floor( d ); 41 42 return static_cast< int>( d * stepSize );43 } 44 45 static double qwtIntervalWidth( const QDateTime &minDate,46 const QDateTime &maxDate, QwtDate::IntervalType intervalType )42 d = up ? std::ceil( d ) : std::floor( d ); 43 44 return static_cast< int >( d * stepSize ); 45 } 46 47 static double qwtIntervalWidth( const QDateTime& minDate, 48 const QDateTime& maxDate, QwtDate::IntervalType intervalType ) 47 49 { 48 50 switch( intervalType ) … … 50 52 case QwtDate::Millisecond: 51 53 { 54 return minDate.msecsTo( maxDate ); 55 } 56 case QwtDate::Second: 57 { 58 return minDate.secsTo( maxDate ); 59 } 60 case QwtDate::Minute: 61 { 52 62 const double secsTo = minDate.secsTo( maxDate ); 53 const double msecs = maxDate.time().msec() - 54 minDate.time().msec(); 55 56 return secsTo * 1000 + msecs; 57 } 58 case QwtDate::Second: 59 { 60 return minDate.secsTo( maxDate ); 61 } 62 case QwtDate::Minute: 63 return std::floor( secsTo / 60 ); 64 } 65 case QwtDate::Hour: 63 66 { 64 67 const double secsTo = minDate.secsTo( maxDate ); 65 return ::floor( secsTo / 60 ); 66 } 67 case QwtDate::Hour: 68 { 69 const double secsTo = minDate.secsTo( maxDate ); 70 return ::floor( secsTo / 3600 ); 68 return std::floor( secsTo / 3600 ); 71 69 } 72 70 case QwtDate::Day: … … 76 74 case QwtDate::Week: 77 75 { 78 return ::floor( minDate.daysTo( maxDate ) / 7.0 ); 76 return std::floor( minDate.daysTo( maxDate ) / 7.0 ); 79 77 } 80 78 case QwtDate::Month: … … 105 103 106 104 static double qwtRoundedIntervalWidth( 107 const QDateTime &minDate, const QDateTime&maxDate,105 const QDateTime& minDate, const QDateTime& maxDate, 108 106 QwtDate::IntervalType intervalType ) 109 107 { … … 142 140 const double stepSize = double( intervalSize ) / numSteps; 143 141 144 const double p = ::floor( ::log( stepSize ) / ::log( double( base ) ) ); 145 const double fraction = qPow( base, p );142 const double p = std::floor( std::log( stepSize ) / std::log( double( base ) ) ); 143 const double fraction = std::pow( base, p ); 146 144 147 145 for ( uint n = base; n >= 1; n /= 2 ) … … 165 163 const int limits[], size_t numLimits ) 166 164 { 167 const int v = qCeil( intervalSize / double( numSteps ) ); 165 const int v = qwtCeil( intervalSize / double( numSteps ) ); 168 166 169 167 for ( uint i = 0; i < numLimits - 1; i++ ) … … 215 213 const double v = intervalSize / double( numSteps ); 216 214 if ( v <= 5.0 ) 217 stepSize = qCeil( v );215 stepSize = std::ceil( v ); 218 216 else 219 stepSize = qCeil( v / 7 ) * 7;217 stepSize = std::ceil( v / 7 ) * 7; 220 218 221 219 break; … … 285 283 286 284 if ( numSteps > 0 ) 287 minStepSize = double( stepSize )/ numSteps;285 minStepSize = stepSize / numSteps; 288 286 289 287 break; … … 309 307 310 308 if ( numSteps > 0 ) 311 minStepSize = double( stepSize )/ numSteps;309 minStepSize = stepSize / numSteps; 312 310 313 311 break; … … 333 331 334 332 if ( numSteps > 0 ) 335 minStepSize = double( stepSize )/ numSteps;333 minStepSize = stepSize / numSteps; 336 334 337 335 break; … … 370 368 371 369 if ( stepSize < maxMinSteps ) 372 maxMinSteps = static_cast< int>( stepSize );370 maxMinSteps = static_cast< int >( stepSize ); 373 371 374 372 static int limits[] = { 1, 2, 3, 4, 6, 12 }; … … 378 376 379 377 if ( numSteps > 0 ) 380 minStepSize = double( stepSize )/ numSteps;378 minStepSize = stepSize / numSteps; 381 379 382 380 break; … … 399 397 400 398 if ( numSteps > 0 ) 401 minStepSize = double( stepSize )/ numSteps;399 minStepSize = stepSize / numSteps; 402 400 } 403 401 … … 417 415 } 418 416 419 static QList< double> qwtDstTicks( const QDateTime&dateTime,417 static QList< double > qwtDstTicks( const QDateTime& dateTime, 420 418 int secondsMajor, int secondsMinor ) 421 419 { 422 420 if ( secondsMinor <= 0 ) 423 QList<double>();421 return QList< double >(); 424 422 425 423 QDateTime minDate = dateTime.addSecs( -secondsMajor ); … … 438 436 } 439 437 440 QList<double> ticks; 438 QList< double > ticks; 439 ticks.reserve( 3600 / secondsMinor); 440 441 441 for ( int i = 0; i < 3600; i += secondsMinor ) 442 442 ticks += dstMin + i * 1000.0; … … 446 446 447 447 static QwtScaleDiv qwtDivideToSeconds( 448 const QDateTime &minDate, const QDateTime&maxDate,448 const QDateTime& minDate, const QDateTime& maxDate, 449 449 double stepSize, int maxMinSteps, 450 450 QwtDate::IntervalType intervalType ) … … 470 470 471 471 const double s = qwtMsecsForType( intervalType ) / 1000; 472 const int secondsMajor = static_cast< int>( stepSize * s );472 const int secondsMajor = static_cast< int >( stepSize * s ); 473 473 const double secondsMinor = minStepSize * s; 474 474 … … 480 480 double dstOff = 0; 481 481 482 QList< double> majorTicks;483 QList< double> mediumTicks;484 QList< double> minorTicks;482 QList< double > majorTicks; 483 QList< double > mediumTicks; 484 QList< double > minorTicks; 485 485 486 486 for ( QDateTime dt = minDate; dt <= maxDate; … … 513 513 if ( secondsMinor > 0.0 ) 514 514 { 515 const int numMinorSteps = qFloor( secondsMajor / secondsMinor ); 515 const int numMinorSteps = qwtFloor( secondsMajor / secondsMinor ); 516 516 517 517 for ( int i = 1; i < numMinorSteps; i++ ) … … 554 554 555 555 static QwtScaleDiv qwtDivideToMonths( 556 QDateTime &minDate, const QDateTime&maxDate,556 QDateTime& minDate, const QDateTime& maxDate, 557 557 double stepSize, int maxMinSteps ) 558 558 { … … 584 584 } 585 585 586 QList< double> majorTicks;587 QList< double> mediumTicks;588 QList< double> minorTicks;586 QList< double > majorTicks; 587 QList< double > mediumTicks; 588 QList< double > minorTicks; 589 589 590 590 for ( QDateTime dt = minDate; … … 638 638 639 639 static QwtScaleDiv qwtDivideToYears( 640 const QDateTime &minDate, const QDateTime&maxDate,640 const QDateTime& minDate, const QDateTime& maxDate, 641 641 double stepSize, int maxMinSteps ) 642 642 { 643 QList< double> majorTicks;644 QList< double> mediumTicks;645 QList< double> minorTicks;643 QList< double > majorTicks; 644 QList< double > mediumTicks; 645 QList< double > minorTicks; 646 646 647 647 double minStepSize = 0.0; … … 655 655 int numMinorSteps = 0; 656 656 if ( minStepSize > 0.0 ) 657 numMinorSteps = qFloor( stepSize / minStepSize ); 657 numMinorSteps = qwtFloor( stepSize / minStepSize ); 658 658 659 659 bool dateBC = minDate.date().year() < -1; … … 679 679 680 680 const double years = qRound( i * minStepSize ); 681 if ( years >= INT_MAX/ 12 )681 if ( years >= std::numeric_limits< int >::max() / 12 ) 682 682 { 683 683 tickDate = dt.addYears( years ); … … 717 717 class QwtDateScaleEngine::PrivateData 718 718 { 719 public: 720 PrivateData( Qt::TimeSpec spec ) :721 timeSpec( spec ) ,722 utcOffset( 0 ) ,723 week0Type( QwtDate::FirstThursday ) ,724 maxWeeks( 4 ) 719 public: 720 explicit PrivateData( Qt::TimeSpec spec ) 721 : timeSpec( spec ) 722 , utcOffset( 0 ) 723 , week0Type( QwtDate::FirstThursday ) 724 , maxWeeks( 4 ) 725 725 { 726 726 } … … 734 734 735 735 /*! 736 \brief Constructor 737 738 The engine is initialized to build scales for the 739 given time specification. It classifies intervals > 4 weeks 740 as >= Qt::Month. The first week of a year is defined like 741 for QwtDate::FirstThursday. 742 743 \param timeSpec Time specification 744 745 \sa setTimeSpec(), setMaxWeeks(), setWeek0Type() 736 \brief Constructor 737 738 The engine is initialized to build scales for the 739 given time specification. It classifies intervals > 4 weeks 740 as >= Qt::Month. The first week of a year is defined like 741 for QwtDate::FirstThursday. 742 743 \param timeSpec Time specification 744 745 \sa setTimeSpec(), setMaxWeeks(), setWeek0Type() 746 746 */ 747 QwtDateScaleEngine::QwtDateScaleEngine( Qt::TimeSpec timeSpec ) :748 QwtLinearScaleEngine( 10 ) 749 { 750 d_data = new PrivateData( timeSpec );747 QwtDateScaleEngine::QwtDateScaleEngine( Qt::TimeSpec timeSpec ) 748 : QwtLinearScaleEngine( 10 ) 749 { 750 m_data = new PrivateData( timeSpec ); 751 751 } 752 752 … … 754 754 QwtDateScaleEngine::~QwtDateScaleEngine() 755 755 { 756 delete d_data;756 delete m_data; 757 757 } 758 758 759 759 /*! 760 Set the time specification used by the engine 761 762 \param timeSpec Time specification 763 \sa timeSpec(), setUtcOffset(), toDateTime() 760 Set the time specification used by the engine 761 762 \param timeSpec Time specification 763 \sa timeSpec(), setUtcOffset(), toDateTime() 764 764 */ 765 765 void QwtDateScaleEngine::setTimeSpec( Qt::TimeSpec timeSpec ) 766 766 { 767 d_data->timeSpec = timeSpec;767 m_data->timeSpec = timeSpec; 768 768 } 769 769 770 770 /*! 771 \return Time specification used by the engine 772 \sa setTimeSpec(), utcOffset(), toDateTime() 771 \return Time specification used by the engine 772 \sa setTimeSpec(), utcOffset(), toDateTime() 773 773 */ 774 774 Qt::TimeSpec QwtDateScaleEngine::timeSpec() const 775 775 { 776 return d_data->timeSpec;776 return m_data->timeSpec; 777 777 } 778 778 779 779 /*! 780 Set the offset in seconds from Coordinated Universal Time 781 782 \param seconds Offset in seconds 783 784 \note The offset has no effect beside for the time specification 780 Set the offset in seconds from Coordinated Universal Time 781 782 \param seconds Offset in seconds 783 784 \note The offset has no effect beside for the time specification 785 785 Qt::OffsetFromUTC. 786 786 787 \sa QDate::utcOffset(), setTimeSpec(), toDateTime() 787 \sa QDate::utcOffset(), setTimeSpec(), toDateTime() 788 788 */ 789 789 void QwtDateScaleEngine::setUtcOffset( int seconds ) 790 790 { 791 d_data->utcOffset = seconds;791 m_data->utcOffset = seconds; 792 792 } 793 793 794 794 /*! 795 \return Offset in seconds from Coordinated Universal Time 796 \note The offset has no effect beside for the time specification 795 \return Offset in seconds from Coordinated Universal Time 796 \note The offset has no effect beside for the time specification 797 797 Qt::OffsetFromUTC. 798 798 799 \sa QDate::setUtcOffset(), setTimeSpec(), toDateTime() 799 \sa QDate::setUtcOffset(), setTimeSpec(), toDateTime() 800 800 */ 801 801 int QwtDateScaleEngine::utcOffset() const 802 802 { 803 return d_data->utcOffset;803 return m_data->utcOffset; 804 804 } 805 805 806 806 /*! 807 Sets how to identify the first week of a year. 808 809 \param week0Type Mode how to identify the first week of a year 810 811 \sa week0Type(), setMaxWeeks() 812 \note week0Type has no effect beside for intervals classified as 807 Sets how to identify the first week of a year. 808 809 \param week0Type Mode how to identify the first week of a year 810 811 \sa week0Type(), setMaxWeeks() 812 \note week0Type has no effect beside for intervals classified as 813 813 QwtDate::Week. 814 814 */ 815 815 void QwtDateScaleEngine::setWeek0Type( QwtDate::Week0Type week0Type ) 816 816 { 817 d_data->week0Type = week0Type;817 m_data->week0Type = week0Type; 818 818 } 819 819 820 820 /*! 821 \return Setting how to identify the first week of a year. 822 \sa setWeek0Type(), maxWeeks() 821 \return Setting how to identify the first week of a year. 822 \sa setWeek0Type(), maxWeeks() 823 823 */ 824 824 QwtDate::Week0Type QwtDateScaleEngine::week0Type() const 825 825 { 826 return d_data->week0Type;826 return m_data->week0Type; 827 827 } 828 828 829 829 /*! 830 Set a upper limit for the number of weeks, when an interval 831 can be classified as Qt::Week. 832 833 The default setting is 4 weeks. 834 835 \param weeks Upper limit for the number of weeks 836 837 \note In business charts a year is often divided 830 Set a upper limit for the number of weeks, when an interval 831 can be classified as Qt::Week. 832 833 The default setting is 4 weeks. 834 835 \param weeks Upper limit for the number of weeks 836 837 \note In business charts a year is often divided 838 838 into weeks [1-52] 839 \sa maxWeeks(), setWeek0Type() 839 \sa maxWeeks(), setWeek0Type() 840 840 */ 841 841 void QwtDateScaleEngine::setMaxWeeks( int weeks ) 842 842 { 843 d_data->maxWeeks = qMax( weeks, 0 );843 m_data->maxWeeks = qMax( weeks, 0 ); 844 844 } 845 845 846 846 /*! 847 \return Upper limit for the number of weeks, when an interval 847 \return Upper limit for the number of weeks, when an interval 848 848 can be classified as Qt::Week. 849 \sa setMaxWeeks(), week0Type() 849 \sa setMaxWeeks(), week0Type() 850 850 */ 851 851 int QwtDateScaleEngine::maxWeeks() const 852 852 { 853 return d_data->maxWeeks;853 return m_data->maxWeeks; 854 854 } 855 855 856 856 /*! 857 Classification of a date/time interval division 858 859 \param minDate Minimum ( = earlier ) of the interval 860 \param maxDate Maximum ( = later ) of the interval 861 \param maxSteps Maximum for the number of steps 862 863 \return Interval classification 857 Classification of a date/time interval division 858 859 \param minDate Minimum ( = earlier ) of the interval 860 \param maxDate Maximum ( = later ) of the interval 861 \param maxSteps Maximum for the number of steps 862 863 \return Interval classification 864 864 */ 865 865 QwtDate::IntervalType QwtDateScaleEngine::intervalType( 866 const QDateTime &minDate, const QDateTime&maxDate,866 const QDateTime& minDate, const QDateTime& maxDate, 867 867 int maxSteps ) const 868 868 { … … 880 880 const int weeks = qwtRoundedIntervalWidth( minDate, maxDate, QwtDate::Week ); 881 881 882 if ( weeks > d_data->maxWeeks )882 if ( weeks > m_data->maxWeeks ) 883 883 { 884 884 if ( days > 4 * maxSteps * 7 ) … … 908 908 909 909 /*! 910 Align and divide an interval 911 912 The algorithm aligns and divides the interval into steps. 913 914 Datetime interval divisions are usually not equidistant and the 915 calculated stepSize can only be used as an approximation 916 for the steps calculated by divideScale(). 917 918 \param maxNumSteps Max. number of steps 919 \param x1 First limit of the interval (In/Out) 920 \param x2 Second limit of the interval (In/Out) 921 \param stepSize Step size (Out) 922 923 \sa QwtScaleEngine::setAttribute() 924 */ 910 Align and divide an interval 911 912 The algorithm aligns and divides the interval into steps. 913 914 Datetime interval divisions are usually not equidistant and the 915 calculated stepSize can only be used as an approximation 916 for the steps calculated by divideScale(). 917 918 \param maxNumSteps Max. number of steps 919 \param x1 First limit of the interval (In/Out) 920 \param x2 Second limit of the interval (In/Out) 921 \param stepSize Step size (Out) 922 923 \sa QwtScaleEngine::setAttribute() 924 */ 925 925 void QwtDateScaleEngine::autoScale( int maxNumSteps, 926 double &x1, double&x2, double&stepSize ) const926 double& x1, double& x2, double& stepSize ) const 927 927 { 928 928 stepSize = 0.0; … … 989 989 calculates one. 990 990 \return Calculated scale division 991 */ 991 */ 992 992 QwtScaleDiv QwtDateScaleEngine::divideScale( double x1, double x2, 993 993 int maxMajorSteps, int maxMinorSteps, double stepSize ) const … … 996 996 maxMajorSteps = 1; 997 997 998 const double min = q Min( x1, x2 );999 const double max = q Max( x1, x2 );998 const double min = qwtMinF( x1, x2 ); 999 const double max = qwtMaxF( x1, x2 ); 1000 1000 1001 1001 const QDateTime from = toDateTime( min ); … … 1012 1012 // the stepSize is used as a hint only 1013 1013 1014 maxMajorSteps = qCeil( ( max - min ) / stepSize ); 1014 maxMajorSteps = qwtCeil( ( max - min ) / stepSize ); 1015 1015 } 1016 1016 … … 1047 1047 1048 1048 QwtScaleDiv QwtDateScaleEngine::buildScaleDiv( 1049 const QDateTime &minDate, const QDateTime&maxDate,1049 const QDateTime& minDate, const QDateTime& maxDate, 1050 1050 int maxMajorSteps, int maxMinorSteps, 1051 1051 QwtDate::IntervalType intervalType ) const … … 1091 1091 1092 1092 /*! 1093 Align a date/time value for a step size 1094 1095 For Qt::Day alignments there is no "natural day 0" - 1096 instead the first day of the year is used to avoid jumping 1097 major ticks positions when panning a scale. For other alignments 1098 ( f.e according to the first day of the month ) alignDate() 1099 has to be overloaded. 1100 1101 \param dateTime Date/time value 1102 \param stepSize Step size 1103 \param intervalType Interval type 1104 \param up When true dateTime is ceiled - otherwise it is floored 1105 1106 \return Aligned date/time value 1093 Align a date/time value for a step size 1094 1095 For Qt::Day alignments there is no "natural day 0" - 1096 instead the first day of the year is used to avoid jumping 1097 major ticks positions when panning a scale. For other alignments 1098 ( f.e according to the first day of the month ) alignDate() 1099 has to be overloaded. 1100 1101 \param dateTime Date/time value 1102 \param stepSize Step size 1103 \param intervalType Interval type 1104 \param up When true dateTime is ceiled - otherwise it is floored 1105 1106 \return Aligned date/time value 1107 1107 */ 1108 1108 QDateTime QwtDateScaleEngine::alignDate( 1109 const QDateTime &dateTime, double stepSize,1109 const QDateTime& dateTime, double stepSize, 1110 1110 QwtDate::IntervalType intervalType, bool up ) const 1111 1111 { … … 1116 1116 if ( dateTime.timeSpec() == Qt::OffsetFromUTC ) 1117 1117 { 1118 #if QT_VERSION >= 0x050200 1119 dt.setOffsetFromUtc( 0 ); 1120 #else 1118 1121 dt.setUtcOffset( 0 ); 1122 #endif 1119 1123 } 1120 1124 … … 1124 1128 { 1125 1129 const int ms = qwtAlignValue( 1126 dt.time().msec(), stepSize, up ) ;1130 dt.time().msec(), stepSize, up ); 1127 1131 1128 1132 dt = QwtDate::floor( dateTime, QwtDate::Second ); … … 1204 1208 { 1205 1209 const QDate date = QwtDate::dateOfWeek0( 1206 dt.date().year(), d_data->week0Type );1210 dt.date().year(), m_data->week0Type ); 1207 1211 1208 1212 int numWeeks = date.daysTo( dt.date() ) / 7; … … 1274 1278 if ( dateTime.timeSpec() == Qt::OffsetFromUTC ) 1275 1279 { 1280 #if QT_VERSION >= 0x050200 1281 dt.setOffsetFromUtc( dateTime.offsetFromUtc() ); 1282 #else 1276 1283 dt.setUtcOffset( dateTime.utcOffset() ); 1284 #endif 1277 1285 } 1278 1286 … … 1281 1289 1282 1290 /*! 1283 Translate a double value into a QDateTime object. 1284 1285 For QDateTime result is bounded by QwtDate::minDate() and QwtDate::maxDate() 1286 1287 \return QDateTime object initialized with timeSpec() and utcOffset(). 1288 \sa timeSpec(), utcOffset(), QwtDate::toDateTime() 1291 Translate a double value into a QDateTime object. 1292 1293 For QDateTime result is bounded by QwtDate::minDate() and QwtDate::maxDate() 1294 1295 \return QDateTime object initialized with timeSpec() and utcOffset(). 1296 \sa timeSpec(), utcOffset(), QwtDate::toDateTime() 1289 1297 */ 1290 1298 QDateTime QwtDateScaleEngine::toDateTime( double value ) const 1291 1299 { 1292 QDateTime dt = QwtDate::toDateTime( value, d_data->timeSpec );1300 QDateTime dt = QwtDate::toDateTime( value, m_data->timeSpec ); 1293 1301 if ( !dt.isValid() ) 1294 1302 { … … 1296 1304 ? QwtDate::minDate() : QwtDate::maxDate(); 1297 1305 1298 dt = QDateTime( date, QTime( 0, 0 ), d_data->timeSpec ); 1299 } 1300 1301 if ( d_data->timeSpec == Qt::OffsetFromUTC ) 1302 { 1303 dt = dt.addSecs( d_data->utcOffset ); 1304 dt.setUtcOffset( d_data->utcOffset ); 1306 dt = QDateTime( date, QTime( 0, 0 ), m_data->timeSpec ); 1307 } 1308 1309 if ( m_data->timeSpec == Qt::OffsetFromUTC ) 1310 { 1311 dt = dt.addSecs( m_data->utcOffset ); 1312 #if QT_VERSION >= 0x050200 1313 dt.setOffsetFromUtc( m_data->utcOffset ); 1314 #else 1315 dt.setUtcOffset( m_data->utcOffset ); 1316 #endif 1305 1317 } 1306 1318
Note:
See TracChangeset
for help on using the changeset viewer.
