Commit 83b38b4f authored by Volker Krause's avatar Volker Krause

Insert weather forecast elements after every location change

parent c06343ef
......@@ -240,10 +240,10 @@ private slots:
a.setGeo(geo);
f.setArrivalAirport(a);
f.setDepartureTime(QDateTime(QDate::currentDate().addDays(1), QTime(12, 0)));
f.setArrivalTime(QDateTime(QDate::currentDate().addDays(1), QTime(14, 0)));
res.setReservationFor(f);
resMgr.addReservation(res);
QEXPECT_FAIL("", "weather for location changes not implemented yet", Continue);
QCOMPARE(model.rowCount(), 13); // 2x flight, 1x today, 10x weather
QCOMPARE(model.index(0, 0).data(TimelineModel::ElementTypeRole), TimelineModel::Flight);
QCOMPARE(model.index(1, 0).data(TimelineModel::ElementTypeRole), TimelineModel::TodayMarker);
......@@ -263,21 +263,18 @@ private slots:
QVERIFY(fc.isValid());
QCOMPARE(fc.minimumTemperature(), 8.0f);
QCOMPARE(fc.maximumTemperature(), 46.0f);
QEXPECT_FAIL("", "weather for location changes not implemented yet", Continue);
QCOMPARE(fc.dateTime(), QDateTime(QDate::currentDate().addDays(1), QTime(12, 0)));
QCOMPARE(fc.dateTime(), QDateTime(QDate::currentDate().addDays(1), QTime(14, 0)));
QCOMPARE(model.index(6, 0).data(TimelineModel::ElementTypeRole), TimelineModel::WeatherForecast);
fc = model.index(6, 0).data(TimelineModel::WeatherForecastRole).value<WeatherForecast>();
QCOMPARE(fc.minimumTemperature(), 8.0f);
QCOMPARE(fc.maximumTemperature(), 46.0f);
QVERIFY(fc.isValid());
QEXPECT_FAIL("", "weather for location changes not implemented yet", Continue);
QCOMPARE(fc.dateTime(), QDateTime(QDate::currentDate().addDays(2), QTime(0, 0)));
// check we get update signals for all weather elements
QSignalSpy spy(&model, &TimelineModel::dataChanged);
QVERIFY(spy.isValid());
emit weatherMgr.forecastUpdated();
QEXPECT_FAIL("", "weather for location changes not implemented yet", Continue);
QCOMPARE(spy.size(), 10);
fc = model.index(3, 0).data(TimelineModel::WeatherForecastRole).value<WeatherForecast>();
......@@ -289,7 +286,6 @@ private slots:
QVERIFY(fc.isValid());
QCOMPARE(fc.minimumTemperature(), 8.0f);
QCOMPARE(fc.maximumTemperature(), 46.0f);
QEXPECT_FAIL("", "weather for location changes not implemented yet", Continue);
QCOMPARE(fc.dateTime(), QDateTime(QDate::currentDate().addDays(5), QTime(0, 0)));
// add a location change far in the future, this must not change anything
......@@ -300,7 +296,6 @@ private slots:
f.setDepartureTime(QDateTime(QDate::currentDate().addYears(1), QTime(6, 0)));
res.setReservationFor(f);
resMgr.addReservation(res);
QEXPECT_FAIL("", "weather for location changes not implemented yet", Continue);
QCOMPARE(model.rowCount(), 14);
fc = model.index(3, 0).data(TimelineModel::WeatherForecastRole).value<WeatherForecast>();
......@@ -312,13 +307,11 @@ private slots:
QVERIFY(fc.isValid());
QCOMPARE(fc.minimumTemperature(), 8.0f);
QCOMPARE(fc.maximumTemperature(), 46.0f);
QEXPECT_FAIL("", "weather for location changes not implemented yet", Continue);
QCOMPARE(fc.dateTime(), QDateTime(QDate::currentDate().addDays(5), QTime(0, 0)));
// result is the same when data hasn't been added incrementally
model.setReservationManager(nullptr);
model.setReservationManager(&resMgr);
QEXPECT_FAIL("", "weather for location changes not implemented yet", Continue);
QCOMPARE(model.rowCount(), 14);
fc = model.index(3, 0).data(TimelineModel::WeatherForecastRole).value<WeatherForecast>();
......@@ -330,7 +323,6 @@ private slots:
QVERIFY(fc.isValid());
QCOMPARE(fc.minimumTemperature(), 8.0f);
QCOMPARE(fc.maximumTemperature(), 46.0f);
QEXPECT_FAIL("", "weather for location changes not implemented yet", Continue);
QCOMPARE(fc.dateTime(), QDateTime(QDate::currentDate().addDays(5), QTime(0, 0)));
}
};
......
......@@ -148,9 +148,9 @@ void TimelineModel::setReservationManager(ReservationManager* mgr)
// for auto tests only
if (Q_UNLIKELY(!mgr)) {
beginResetModel();
disconnect(mgr, &ReservationManager::reservationAdded, this, &TimelineModel::reservationAdded);
disconnect(mgr, &ReservationManager::reservationUpdated, this, &TimelineModel::reservationUpdated);
disconnect(mgr, &ReservationManager::reservationRemoved, this, &TimelineModel::reservationRemoved);
disconnect(m_resMgr, &ReservationManager::reservationAdded, this, &TimelineModel::reservationAdded);
disconnect(m_resMgr, &ReservationManager::reservationUpdated, this, &TimelineModel::reservationUpdated);
disconnect(m_resMgr, &ReservationManager::reservationRemoved, this, &TimelineModel::reservationRemoved);
m_resMgr = mgr;
m_elements.clear();
endResetModel();
......@@ -441,6 +441,7 @@ void TimelineModel::updateWeatherElements()
}
auto date = QDateTime::currentDateTime();
date.setTime(QTime(date.time().hour() + 1, 0));
while(it != m_elements.end() && date < m_weatherMgr->maximumForecastTime()) {
if ((*it).dt < date || (*it).elementType == TodayMarker) {
......@@ -455,8 +456,20 @@ void TimelineModel::updateWeatherElements()
continue;
}
// determine the length of the forecast range (at most until the end of the day)
auto endTime = date;
endTime.setTime(QTime(23, 59, 59));
for (auto it2 = it; it2 != m_elements.end(); ++it2) {
if ((*it2).dt >= endTime) {
break;
}
const auto res = m_resMgr->reservation((*it2).id);
const auto newGeo = geoCoordinate(res);
if (isLocationChange(res)) {
endTime = std::min(endTime, relevantDateTime(res, RangeEnd));
break;
}
}
::WeatherForecast fc;
if (geo.isValid()) {
......@@ -477,7 +490,7 @@ void TimelineModel::updateWeatherElements()
it = m_elements.insert(it, Element{{}, QVariant::fromValue(fc), date, WeatherForecast, SelfContained});
endInsertRows();
}
// case 3: we have no forecast data, but a matching weather element: remove
// case 3: we have no forecast data, but a matching weather element: remove
else if ((*it).elementType == WeatherForecast && (*it).dt == date) {
const auto row = std::distance(m_elements.begin(), it);
beginRemoveRows({}, row, row);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment