#1800 Ensure auto-scaling of QWT plots with date scale will not miss points in the upper end of the plot

This commit is contained in:
Bjørnar Grip Fjær 2017-08-22 11:23:52 +02:00
parent 46919b463d
commit b66e957e28

View File

@ -1123,31 +1123,57 @@ QDateTime QwtDateScaleEngine::alignDate(
} }
case QwtDate::Second: case QwtDate::Second:
{ {
const int s = qwtAlignValue( // Manually patched from QWT trunk
dt.time().second(), stepSize, up ); int second = dt.time().second();
if (up)
{
if (dt.time().msec() > 0)
second++;
}
const int s = qwtAlignValue(second, stepSize, up);
dt = QwtDate::floor(dt, QwtDate::Minute);
dt = dt.addSecs(s);
dt = QwtDate::floor( dt, QwtDate::Minute );
dt = dt.addSecs( s );
break; break;
} }
case QwtDate::Minute: case QwtDate::Minute:
{ {
const int m = qwtAlignValue( // Manually patched from QWT trunk
dt.time().minute(), stepSize, up ); int minute = dt.time().minute();
if (up)
{
if (dt.time().msec() > 0 || dt.time().second() > 0)
minute++;
}
const int m = qwtAlignValue(minute, stepSize, up);
dt = QwtDate::floor(dt, QwtDate::Hour);
dt = dt.addSecs(m * 60);
dt = QwtDate::floor( dt, QwtDate::Hour );
dt = dt.addSecs( m * 60 );
break; break;
} }
case QwtDate::Hour: case QwtDate::Hour:
{ {
const int h = qwtAlignValue( // Manually patched from QWT trunk
dt.time().hour(), stepSize, up ); int hour = dt.time().hour();
if (up)
{
if (dt.time().msec() > 0 || dt.time().second() > 0
|| dt.time().minute() > 0)
{
hour++;
}
}
const int h = qwtAlignValue(hour, stepSize, up);
dt = QwtDate::floor(dt, QwtDate::Day);
dt = dt.addSecs(h * 3600);
dt = QwtDate::floor( dt, QwtDate::Day );
dt = dt.addSecs( h * 3600 );
break; break;
} }
@ -1157,11 +1183,18 @@ QDateTime QwtDateScaleEngine::alignDate(
// Aligning them to the beginning of the year avoids at least // Aligning them to the beginning of the year avoids at least
// jumping major ticks when panning // jumping major ticks when panning
const int d = qwtAlignValue( // Manually patched from QWT trunk
dt.date().dayOfYear(), stepSize, up ); int day = dt.date().dayOfYear();
if (up)
{
if (dt.time() > QTime(0, 0))
day++;
}
dt = QwtDate::floor( dt, QwtDate::Year ); const int d = qwtAlignValue(day, stepSize, up);
dt = dt.addDays( d - 1 );
dt = QwtDate::floor(dt, QwtDate::Year);
dt = dt.addDays(d - 1);
break; break;
} }
@ -1191,30 +1224,51 @@ QDateTime QwtDateScaleEngine::alignDate(
} }
case QwtDate::Month: case QwtDate::Month:
{ {
const int m = qwtAlignValue( // Manually patched from QWT trunk
dt.date().month() - 1, stepSize, up ); int month = dt.date().month();
if (up)
{
if (dt.date().day() > 1 ||
dt.time() > QTime(0, 0))
{
month++;
}
}
dt = QwtDate::floor( dt, QwtDate::Year ); const int m = qwtAlignValue(month - 1, stepSize, up);
dt = dt.addMonths( m );
dt = QwtDate::floor(dt, QwtDate::Year);
dt = dt.addMonths(m);
break; break;
} }
case QwtDate::Year: case QwtDate::Year:
{ {
const int y = qwtAlignValue( // Manually patched from QWT trunk
dateTime.date().year(), stepSize, up ); int year = dateTime.date().year();
if (up)
{
if (dateTime.date().dayOfYear() > 1 ||
dt.time() > QTime(0, 0))
{
year++;
}
}
dt = QwtDate::floor( dt, QwtDate::Day ); const int y = qwtAlignValue(year, stepSize, up);
if ( y == 0 )
dt = QwtDate::floor(dt, QwtDate::Day);
if (y == 0)
{ {
// there is no year 0 in the Julian calendar // there is no year 0 in the Julian calendar
dt.setDate( QDate( stepSize, 1, 1 ).addYears( -stepSize ) ); dt.setDate(QDate(stepSize, 1, 1).addYears(-stepSize));
} }
else else
{ {
dt.setDate( QDate( y, 1, 1 ) ); dt.setDate(QDate(y, 1, 1));
} }
break; break;
} }
} }