Changeset 9383 in ntrip for trunk/BNC/qwt/qwt_date_scale_engine.cpp
- Timestamp:
- Mar 19, 2021, 9:15:03 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_date_scale_engine.cpp
r8127 r9383 14 14 #include <limits.h> 15 15 16 static inline double qwtMsecsForType( QwtDate::IntervalTypetype )16 static inline double qwtMsecsForType( int type ) 17 17 { 18 18 static const double msecs[] = … … 44 44 45 45 static double qwtIntervalWidth( const QDateTime &minDate, 46 const QDateTime &maxDate, QwtDate::IntervalType intervalType ) 46 const QDateTime &maxDate, QwtDate::IntervalType intervalType ) 47 47 { 48 48 switch( intervalType ) … … 80 80 case QwtDate::Month: 81 81 { 82 const double years = 82 const double years = 83 83 double( maxDate.date().year() ) - minDate.date().year(); 84 84 … … 91 91 case QwtDate::Year: 92 92 { 93 double years = 93 double years = 94 94 double( maxDate.date().year() ) - minDate.date().year(); 95 95 … … 104 104 } 105 105 106 static double qwtRoundedIntervalWidth( 107 const QDateTime &minDate, const QDateTime &maxDate, 108 QwtDate::IntervalType intervalType ) 106 static double qwtRoundedIntervalWidth( 107 const QDateTime &minDate, const QDateTime &maxDate, 108 QwtDate::IntervalType intervalType ) 109 109 { 110 110 const QDateTime minD = QwtDate::floor( minDate, intervalType ); … … 131 131 } 132 132 133 static int qwtStepSize( int intervalSize, int maxSteps, uint base ) 133 static int qwtStepSize( int intervalSize, int maxSteps, uint base ) 134 134 { 135 135 if ( maxSteps <= 0 ) … … 162 162 } 163 163 164 static int qwtDivideInterval( double intervalSize, int numSteps, 164 static int qwtDivideInterval( double intervalSize, int numSteps, 165 165 const int limits[], size_t numLimits ) 166 166 { … … 181 181 if ( intervalType != QwtDate::Day ) 182 182 { 183 if ( ( intervalSize > numSteps ) && 183 if ( ( intervalSize > numSteps ) && 184 184 ( intervalSize <= 2 * numSteps ) ) 185 185 { … … 196 196 { 197 197 static int limits[] = { 1, 2, 5, 10, 15, 20, 30, 60 }; 198 198 199 199 stepSize = qwtDivideInterval( intervalSize, numSteps, 200 200 limits, sizeof( limits ) / sizeof( int ) ); … … 205 205 { 206 206 static int limits[] = { 1, 2, 3, 4, 6, 12, 24 }; 207 207 208 208 stepSize = qwtDivideInterval( intervalSize, numSteps, 209 209 limits, sizeof( limits ) / sizeof( int ) ); … … 274 274 if ( stepSize > maxMinSteps ) 275 275 { 276 numSteps = qwtStepCount( stepSize, maxMinSteps, 276 numSteps = qwtStepCount( stepSize, maxMinSteps, 277 277 limits, sizeof( limits ) / sizeof( int ) ); 278 278 … … 280 280 else 281 281 { 282 numSteps = qwtStepCount( stepSize * 60, maxMinSteps, 282 numSteps = qwtStepCount( stepSize * 60, maxMinSteps, 283 283 limits, sizeof( limits ) / sizeof( int ) ); 284 284 } … … 359 359 else 360 360 { 361 minStepSize = QwtScaleArithmetic::divideInterval( 361 minStepSize = QwtScaleArithmetic::divideInterval( 362 362 stepSizeInWeeks, maxMinSteps, 10 ); 363 363 } … … 401 401 minStepSize = double( stepSize ) / numSteps; 402 402 } 403 403 404 404 break; 405 405 } … … 445 445 } 446 446 447 static QwtScaleDiv qwtDivideToSeconds( 447 static QwtScaleDiv qwtDivideToSeconds( 448 448 const QDateTime &minDate, const QDateTime &maxDate, 449 449 double stepSize, int maxMinSteps, 450 QwtDate::IntervalType intervalType ) 450 QwtDate::IntervalType intervalType ) 451 451 { 452 452 // calculate the min step size 453 453 double minStepSize = 0; 454 454 455 if ( maxMinSteps > 1 ) 456 { 457 minStepSize = qwtDivideMajorStep( stepSize, 455 if ( maxMinSteps > 1 ) 456 { 457 minStepSize = qwtDivideMajorStep( stepSize, 458 458 maxMinSteps, intervalType ); 459 459 } … … 472 472 const int secondsMajor = static_cast<int>( stepSize * s ); 473 473 const double secondsMinor = minStepSize * s; 474 474 475 475 // UTC excludes daylight savings. So from the difference 476 476 // of a date and its UTC counterpart we can find out … … 484 484 QList<double> minorTicks; 485 485 486 for ( QDateTime dt = minDate; dt <= maxDate; 486 for ( QDateTime dt = minDate; dt <= maxDate; 487 487 dt = dt.addSecs( secondsMajor ) ) 488 488 { … … 501 501 // we add some minor ticks for the DST hour, 502 502 // otherwise the ticks will be unaligned: 0, 2, 3, 5 ... 503 minorTicks += qwtDstTicks( 503 minorTicks += qwtDstTicks( 504 504 dt, secondsMajor, qRound( secondsMinor ) ); 505 505 } … … 517 517 for ( int i = 1; i < numMinorSteps; i++ ) 518 518 { 519 const QDateTime mt = dt.addMSecs( 519 const QDateTime mt = dt.addMSecs( 520 520 qRound64( i * secondsMinor * 1000 ) ); 521 521 … … 529 529 if ( minorTicks.isEmpty() || minorTicks.last() != minorValue ) 530 530 { 531 const bool isMedium = ( numMinorSteps % 2 == 0 ) 531 const bool isMedium = ( numMinorSteps % 2 == 0 ) 532 532 && ( i != 1 ) && ( i == numMinorSteps / 2 ); 533 533 … … 553 553 } 554 554 555 static QwtScaleDiv qwtDivideToMonths( 555 static QwtScaleDiv qwtDivideToMonths( 556 556 QDateTime &minDate, const QDateTime &maxDate, 557 double stepSize, int maxMinSteps ) 558 { 559 // months are intervals with non 560 // equidistant ( in ms ) steps: we have to build the 557 double stepSize, int maxMinSteps ) 558 { 559 // months are intervals with non 560 // equidistant ( in ms ) steps: we have to build the 561 561 // scale division manually 562 562 563 563 int minStepDays = 0; 564 int minStepSize = 0.0; 564 int minStepSize = 0.0; 565 565 566 566 if ( maxMinSteps > 1 ) … … 579 579 else 580 580 { 581 minStepSize = qwtDivideMajorStep( 581 minStepSize = qwtDivideMajorStep( 582 582 stepSize, maxMinSteps, QwtDate::Month ); 583 583 } … … 588 588 QList<double> minorTicks; 589 589 590 for ( QDateTime dt = minDate; 590 for ( QDateTime dt = minDate; 591 591 dt <= maxDate; dt = dt.addMonths( stepSize ) ) 592 592 { … … 598 598 if ( minStepDays > 0 ) 599 599 { 600 for ( int days = minStepDays; 600 for ( int days = minStepDays; 601 601 days < 30; days += minStepDays ) 602 602 { … … 637 637 } 638 638 639 static QwtScaleDiv qwtDivideToYears( 639 static QwtScaleDiv qwtDivideToYears( 640 640 const QDateTime &minDate, const QDateTime &maxDate, 641 double stepSize, int maxMinSteps ) 641 double stepSize, int maxMinSteps ) 642 642 { 643 643 QList<double> majorTicks; … … 649 649 if ( maxMinSteps > 1 ) 650 650 { 651 minStepSize = qwtDivideMajorStep( 651 minStepSize = qwtDivideMajorStep( 652 652 stepSize, maxMinSteps, QwtDate::Year ); 653 653 } … … 702 702 break; 703 703 } 704 } 704 } 705 705 706 706 QwtScaleDiv scaleDiv; … … 730 730 QwtDate::Week0Type week0Type; 731 731 int maxWeeks; 732 }; 732 }; 733 733 734 734 … … 736 736 \brief Constructor 737 737 738 The engine is initialized to build scales for the 738 The engine is initialized to build scales for the 739 739 given time specification. It classifies intervals > 4 weeks 740 740 as >= Qt::Month. The first week of a year is defined like … … 811 811 \sa week0Type(), setMaxWeeks() 812 812 \note week0Type has no effect beside for intervals classified as 813 QwtDate::Week. 813 QwtDate::Week. 814 814 */ 815 815 void QwtDateScaleEngine::setWeek0Type( QwtDate::Week0Type week0Type ) … … 819 819 820 820 /*! 821 \return Setting how to identify the first week of a year. 821 \return Setting how to identify the first week of a year. 822 822 \sa setWeek0Type(), maxWeeks() 823 823 */ … … 835 835 \param weeks Upper limit for the number of weeks 836 836 837 \note In business charts a year is often d evided837 \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 ) … … 863 863 \return Interval classification 864 864 */ 865 QwtDate::IntervalType QwtDateScaleEngine::intervalType( 866 const QDateTime &minDate, const QDateTime &maxDate, 865 QwtDate::IntervalType QwtDateScaleEngine::intervalType( 866 const QDateTime &minDate, const QDateTime &maxDate, 867 867 int maxSteps ) const 868 868 { … … 910 910 Align and divide an interval 911 911 912 The algorithm aligns and divides the interval into steps. 912 The algorithm aligns and divides the interval into steps. 913 913 914 914 Datetime interval divisions are usually not equidistant and the 915 915 calculated stepSize can only be used as an approximation 916 for the steps calculated by divideScale(). 916 for the steps calculated by divideScale(). 917 917 918 918 \param maxNumSteps Max. number of steps … … 951 951 maxNumSteps = 1; 952 952 953 const QwtDate::IntervalType intvType = 953 const QwtDate::IntervalType intvType = 954 954 intervalType( from, to, maxNumSteps ); 955 955 … … 1015 1015 } 1016 1016 1017 const QwtDate::IntervalType intvType = 1017 const QwtDate::IntervalType intvType = 1018 1018 intervalType( from, to, maxMajorSteps ); 1019 1019 … … 1031 1031 const QDateTime maxDate = QwtDate::ceil( to, intvType ); 1032 1032 1033 scaleDiv = buildScaleDiv( minDate, maxDate, 1033 scaleDiv = buildScaleDiv( minDate, maxDate, 1034 1034 maxMajorSteps, maxMinorSteps, intvType ); 1035 1035 … … 1046 1046 } 1047 1047 1048 QwtScaleDiv QwtDateScaleEngine::buildScaleDiv( 1048 QwtScaleDiv QwtDateScaleEngine::buildScaleDiv( 1049 1049 const QDateTime &minDate, const QDateTime &maxDate, 1050 1050 int maxMajorSteps, int maxMinorSteps, … … 1052 1052 { 1053 1053 // calculate the step size 1054 const double stepSize = qwtDivideScale( 1055 qwtIntervalWidth( minDate, maxDate, intervalType ), 1054 const double stepSize = qwtDivideScale( 1055 qwtIntervalWidth( minDate, maxDate, intervalType ), 1056 1056 maxMajorSteps, intervalType ); 1057 1057 … … 1060 1060 if ( !dt0.isValid() ) 1061 1061 { 1062 // the floored date is out of the range of a 1062 // the floored date is out of the range of a 1063 1063 // QDateTime - we ceil instead. 1064 1064 dt0 = alignDate( minDate, stepSize, intervalType, true ); … … 1069 1069 if ( intervalType <= QwtDate::Week ) 1070 1070 { 1071 scaleDiv = qwtDivideToSeconds( dt0, maxDate, 1071 scaleDiv = qwtDivideToSeconds( dt0, maxDate, 1072 1072 stepSize, maxMinorSteps, intervalType ); 1073 1073 } … … 1094 1094 1095 1095 For Qt::Day alignments there is no "natural day 0" - 1096 instead the first day of the year is used to avoid jumping 1096 instead the first day of the year is used to avoid jumping 1097 1097 major ticks positions when panning a scale. For other alignments 1098 1098 ( f.e according to the first day of the month ) alignDate() … … 1106 1106 \return Aligned date/time value 1107 1107 */ 1108 QDateTime QwtDateScaleEngine::alignDate( 1109 const QDateTime &dateTime, double stepSize, 1108 QDateTime QwtDateScaleEngine::alignDate( 1109 const QDateTime &dateTime, double stepSize, 1110 1110 QwtDate::IntervalType intervalType, bool up ) const 1111 1111 { … … 1123 1123 case QwtDate::Millisecond: 1124 1124 { 1125 const int ms = qwtAlignValue( 1125 const int ms = qwtAlignValue( 1126 1126 dt.time().msec(), stepSize, up ) ; 1127 1127 … … 1293 1293 if ( !dt.isValid() ) 1294 1294 { 1295 const QDate date = ( value <= 0.0 ) 1295 const QDate date = ( value <= 0.0 ) 1296 1296 ? QwtDate::minDate() : QwtDate::maxDate(); 1297 1297
Note:
See TracChangeset
for help on using the changeset viewer.