Commit 5e9a9cc8 authored by Volker Krause's avatar Volker Krause

Force-expand the currently active trip group

This fixes various issues due to "now" ending up in a collapsed time
range.
parent d352812d
This diff is collapsed.
This diff is collapsed.
[
{
"isToday": false,
"rangeType": 0,
"sectionHeader": "Sunday, 10 Sep 2017",
"tripGroup": {
"@context": "http://schema.org",
"@type": "TripGroup",
"beginDateTime": {
"@type": "QDateTime",
"@value": "2017-09-10T06:45:00+02:00",
"timezone": "Europe/Berlin"
},
"endDateTime": {
"@type": "QDateTime",
"@value": "2017-09-15T22:15:00+02:00",
"timezone": "Europe/Berlin"
},
"name": "Randa (September 2017)"
},
"type": 2
},
{
"isToday": true,
"isTodayEmpty": true,
"rangeType": 0,
"sectionHeader": "Today",
"type": 1
}
]
......@@ -116,6 +116,52 @@ private Q_SLOTS:
proxy.expand(addSpy.at(0).at(0).toString());
QVERIFY(vp0.verify(&proxy));
}
void testCurrentGroup()
{
ReservationManager resMgr;
clearReservations(&resMgr);
resMgr.importReservation(readFile(QLatin1String(SOURCE_DIR "/../tests/randa2017.json")));
TripGroupManager groupMgr;
QSignalSpy addSpy(&groupMgr, &TripGroupManager::tripGroupAdded);
groupMgr.setReservationManager(&resMgr);
QCOMPARE(groupMgr.tripGroups().size(), 1);
QCOMPARE(addSpy.size(), 1);
TimelineModel model;
model.setHomeCountryIsoCode(QStringLiteral("DE"));
model.setCurrentDateTime(QDateTime({2017, 9, 9}, {12, 34}));
model.setReservationManager(&resMgr);
model.setTripGroupManager(&groupMgr);
TripGroupProxyModel proxy;
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
QAbstractItemModelTester tester(&proxy);
#endif
proxy.setSourceModel(&model);
// future event, should be expanded
ModelVerificationPoint vp0(QLatin1String(SOURCE_DIR "/data/tripgroupproxy/current-r0.model"));
vp0.setRoleFilter({TimelineModel::BatchIdRole, TimelineModel::TripGroupIdRole});
QVERIFY(vp0.verify(&proxy));
// current event, must be expanded and not collapsable
model.setCurrentDateTime(QDateTime({2017, 9, 14}, {12, 34}));
ModelVerificationPoint vp1(QLatin1String(SOURCE_DIR "/data/tripgroupproxy/current-r1.model"));
vp1.setRoleFilter({TimelineModel::BatchIdRole, TimelineModel::TripGroupIdRole});
QVERIFY(vp1.verify(&proxy));
proxy.collapse(addSpy.at(0).at(0).toString());
QVERIFY(vp1.verify(&proxy));
// past event, should be collapsed
model.setCurrentDateTime(QDateTime({2018, 9, 9}, {12, 34}));
ModelVerificationPoint vp2(QLatin1String(SOURCE_DIR "/data/tripgroupproxy/current-r2.model"));
vp2.setRoleFilter({TimelineModel::BatchIdRole, TimelineModel::TripGroupIdRole});
QCOMPARE(proxy.rowCount(), 2);
QVERIFY(vp2.verify(&proxy));
}
};
QTEST_GUILESS_MAIN(TripGroupProxyTest)
......
......@@ -416,6 +416,7 @@ void TimelineModel::updateTodayMarker()
beginRemoveRows({}, oldRow, oldRow);
m_elements.erase(m_elements.begin() + oldRow);
endRemoveRows();
emit todayRowChanged();
}
void TimelineModel::updateInformationElements()
......
......@@ -98,6 +98,8 @@ public:
// for unit testing
void setCurrentDateTime(const QDateTime &dt);
QDateTime now() const;
QDate today() const;
Q_SIGNALS:
void todayRowChanged();
......@@ -133,9 +135,6 @@ private:
std::vector<Element>::iterator erasePreviousCountyInfo(std::vector<Element>::iterator it);
void updateWeatherElements();
QDateTime now() const;
QDate today() const;
ReservationManager *m_resMgr = nullptr;
WeatherForecastManager *m_weatherMgr = nullptr;
TripGroupManager *m_tripGroupManager = nullptr;
......
......@@ -40,6 +40,7 @@ void TripGroupProxyModel::setSourceModel(QAbstractItemModel *sourceModel)
m_sourceModel = qobject_cast<TimelineModel*>(sourceModel);
Q_ASSERT(m_sourceModel);
connect(m_sourceModel, &TimelineModel::todayRowChanged, this, &TripGroupProxyModel::todayRowChanged);
connect(m_sourceModel, &TimelineModel::todayRowChanged, this, &TripGroupProxyModel::invalidateFilter);
QSortFilterProxyModel::setSourceModel(m_sourceModel);
}
......@@ -118,12 +119,16 @@ void TripGroupProxyModel::expand(const QString &groupId)
bool TripGroupProxyModel::isCollapsed(const QString &groupId) const
{
const auto g = m_sourceModel->tripGroupManager()->tripGroup(groupId);
if (g.beginDateTime() <= m_sourceModel->now() && m_sourceModel->now() <= g.endDateTime()) {
return false; // the current trip must always be expanded
}
const auto it = m_collapsed.constFind(groupId);
if (it != m_collapsed.constEnd()) {
return it.value();
}
// by default collapse past trips
const auto g = m_sourceModel->tripGroupManager()->tripGroup(groupId);
return g.endDateTime() < QDateTime::currentDateTime();
return g.endDateTime() < m_sourceModel->now();
}
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