/*! \brief Calculate minor/medium ticks for major ticks \param majorTicks Major ticks \param maxMinorSteps Maximum number of minor steps \param stepSize Step size \param minorTicks Array to be filled with the calculated minor ticks \param mediumTicks Array to be filled with the calculated medium ticks */ void QwtLinearScaleEngine::buildMinorTicks( const QList<double>& majorTicks, int maxMinorSteps, double stepSize, QList<double> &minorTicks, QList<double> &mediumTicks ) const { double minStep = qwtStepSize( stepSize, maxMinorSteps, base() ); if ( minStep == 0.0 ) return; // # ticks per interval const int numTicks = qCeil( qAbs( stepSize / minStep ) ) - 1; int medIndex = -1; if ( numTicks % 2 ) medIndex = numTicks / 2; // calculate minor ticks for ( int i = 0; i < majorTicks.count(); i++ ) { double val = majorTicks[i]; for ( int k = 0; k < numTicks; k++ ) { val += minStep; double alignedValue = val; if ( qwtFuzzyCompare( val, 0.0, stepSize ) == 0 ) alignedValue = 0.0; if ( k == medIndex ) mediumTicks += alignedValue; else minorTicks += alignedValue; } } }
static double qwtDivideMajorStep( double stepSize, int maxMinSteps, QwtDate::IntervalType intervalType ) { double minStepSize = 0.0; switch( intervalType ) { case QwtDate::Second: { minStepSize = qwtStepSize( stepSize, maxMinSteps, 10 ); if ( minStepSize == 0.0 ) minStepSize = 0.5 * stepSize; break; } case QwtDate::Minute: { static int limits[] = { 1, 2, 5, 10, 15, 20, 30, 60 }; int numSteps; if ( stepSize > maxMinSteps ) { numSteps = qwtStepCount( stepSize, maxMinSteps, limits, sizeof( limits ) / sizeof( int ) ); } else { numSteps = qwtStepCount( stepSize * 60, maxMinSteps, limits, sizeof( limits ) / sizeof( int ) ); } if ( numSteps > 0 ) minStepSize = double( stepSize ) / numSteps; break; } case QwtDate::Hour: { int numSteps = 0; if ( stepSize > maxMinSteps ) { static int limits[] = { 1, 2, 3, 4, 6, 12, 24, 48, 72 }; numSteps = qwtStepCount( stepSize, maxMinSteps, limits, sizeof( limits ) / sizeof( int ) ); } else { static int limits[] = { 1, 2, 5, 10, 15, 20, 30, 60 }; numSteps = qwtStepCount( stepSize * 60, maxMinSteps, limits, sizeof( limits ) / sizeof( int ) ); } if ( numSteps > 0 ) minStepSize = double( stepSize ) / numSteps; break; } case QwtDate::Day: { int numSteps = 0; if ( stepSize > maxMinSteps ) { static int limits[] = { 1, 2, 3, 7, 14, 28 }; numSteps = qwtStepCount( stepSize, maxMinSteps, limits, sizeof( limits ) / sizeof( int ) ); } else { static int limits[] = { 1, 2, 3, 4, 6, 12, 24, 48, 72 }; numSteps = qwtStepCount( stepSize * 24, maxMinSteps, limits, sizeof( limits ) / sizeof( int ) ); } if ( numSteps > 0 ) minStepSize = double( stepSize ) / numSteps; break; } case QwtDate::Week: { const int daysInStep = stepSize * 7; if ( maxMinSteps >= daysInStep ) { // we want to have one tick per day minStepSize = 1.0 / 7.0; } else { // when the stepSize is more than a week we want to // have a tick for each week const int stepSizeInWeeks = stepSize; if ( stepSizeInWeeks <= maxMinSteps ) { minStepSize = 1; } else { minStepSize = QwtScaleArithmetic::divideInterval( stepSizeInWeeks, maxMinSteps, 10 ); } } break; } case QwtDate::Month: { // fractions of months doesn't make any sense if ( stepSize < maxMinSteps ) maxMinSteps = static_cast<int>( stepSize ); static int limits[] = { 1, 2, 3, 4, 6, 12 }; int numSteps = qwtStepCount( stepSize, maxMinSteps, limits, sizeof( limits ) / sizeof( int ) ); if ( numSteps > 0 ) minStepSize = double( stepSize ) / numSteps; break; } case QwtDate::Year: { if ( stepSize >= maxMinSteps ) { minStepSize = QwtScaleArithmetic::divideInterval( stepSize, maxMinSteps, 10 ); } else { // something in months static int limits[] = { 1, 2, 3, 4, 6, 12 }; int numSteps = qwtStepCount( 12 * stepSize, maxMinSteps, limits, sizeof( limits ) / sizeof( int ) ); if ( numSteps > 0 ) minStepSize = double( stepSize ) / numSteps; } break; } default: break; } if ( intervalType != QwtDate::Month && minStepSize == 0.0 ) { minStepSize = 0.5 * stepSize; } return minStepSize; }