#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,32 +1123,58 @@ 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 = QwtDate::floor(dt, QwtDate::Minute);
dt = dt.addSecs(s); 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 = QwtDate::floor(dt, QwtDate::Hour);
dt = dt.addSecs(m * 60); 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 = QwtDate::floor(dt, QwtDate::Day);
dt = dt.addSecs(h * 3600); dt = dt.addSecs(h * 3600);
break; break;
} }
case QwtDate::Day: case QwtDate::Day:
@ -1157,8 +1183,15 @@ 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++;
}
const int d = qwtAlignValue(day, stepSize, up);
dt = QwtDate::floor(dt, QwtDate::Year); dt = QwtDate::floor(dt, QwtDate::Year);
dt = dt.addDays(d - 1); dt = dt.addDays(d - 1);
@ -1191,8 +1224,18 @@ 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++;
}
}
const int m = qwtAlignValue(month - 1, stepSize, up);
dt = QwtDate::floor(dt, QwtDate::Year); dt = QwtDate::floor(dt, QwtDate::Year);
dt = dt.addMonths(m); dt = dt.addMonths(m);
@ -1201,8 +1244,18 @@ QDateTime QwtDateScaleEngine::alignDate(
} }
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++;
}
}
const int y = qwtAlignValue(year, stepSize, up);
dt = QwtDate::floor(dt, QwtDate::Day); dt = QwtDate::floor(dt, QwtDate::Day);
if (y == 0) if (y == 0)
@ -1215,6 +1268,7 @@ QDateTime QwtDateScaleEngine::alignDate(
dt.setDate(QDate(y, 1, 1)); dt.setDate(QDate(y, 1, 1));
} }
break; break;
} }
} }