Commit 45b3c93b authored by Volker Krause's avatar Volker Krause

Fix merging of multi-traveler trips in the presence of country information

parent a03cca3b
......@@ -7,3 +7,4 @@ CMakeLists.txt.user
callgrind.*
heaptrack.*
*.qmlc
*.fail
[
{
"@context": "http://schema.org",
"@type": "FlightReservation",
"reservationFor": {
"@type": "Flight",
"airline": {
"@type": "Airline",
"iataCode": "LH",
"name": "Lufthansa"
},
"arrivalAirport": {
"@type": "Airport",
"address": {
"@type": "PostalAddress",
"addressCountry": "DE"
},
"geo": {
"@type": "GeoCoordinates",
"latitude": 48.35390090942383,
"longitude": 11.786100387573242
},
"iataCode": "MUC",
"name": "Franz Josef Strauss"
},
"arrivalTime": {
"@type": "QDateTime",
"@value": "2000-01-01T14:10:00+01:00",
"timezone": "Europe/Berlin"
},
"departureAirport": {
"@type": "Airport",
"address": {
"@type": "PostalAddress",
"addressCountry": "DE"
},
"geo": {
"@type": "GeoCoordinates",
"latitude": 52.55970001220703,
"longitude": 13.287799835205078
},
"iataCode": "TXL",
"name": "Tegel"
},
"departureDay": "2000-01-01",
"departureTime": {
"@type": "QDateTime",
"@value": "2000-01-01T13:00:00+01:00",
"timezone": "Europe/Berlin"
},
"flightNumber": "2037"
},
"reservationNumber": "XXX007",
"underName": {
"@type": "Person",
"name": "Traveler One"
}
},
{
"@context": "http://schema.org",
"@type": "FlightReservation",
"reservationFor": {
"@type": "Flight",
"airline": {
"@type": "Airline",
"iataCode": "LH",
"name": "Lufthansa"
},
"arrivalAirport": {
"@type": "Airport",
"address": {
"@type": "PostalAddress",
"addressCountry": "DE"
},
"geo": {
"@type": "GeoCoordinates",
"latitude": 48.35390090942383,
"longitude": 11.786100387573242
},
"iataCode": "MUC",
"name": "Franz Josef Strauss"
},
"arrivalTime": {
"@type": "QDateTime",
"@value": "2000-01-01T14:10:00+01:00",
"timezone": "Europe/Berlin"
},
"departureAirport": {
"@type": "Airport",
"address": {
"@type": "PostalAddress",
"addressCountry": "DE"
},
"geo": {
"@type": "GeoCoordinates",
"latitude": 52.55970001220703,
"longitude": 13.287799835205078
},
"iataCode": "TXL",
"name": "Tegel"
},
"departureDay": "2000-01-01",
"departureTime": {
"@type": "QDateTime",
"@value": "2000-01-01T13:00:00+01:00",
"timezone": "Europe/Berlin"
},
"flightNumber": "2037"
},
"reservationNumber": "XXX007",
"underName": {
"@type": "Person",
"name": "Traveler Two"
}
},
{
"@context": "http://schema.org",
"@type": "FlightReservation",
"reservationFor": {
"@type": "Flight",
"airline": {
"@type": "Airline",
"iataCode": "LH",
"name": "Lufthansa"
},
"arrivalAirport": {
"@type": "Airport",
"address": {
"@type": "PostalAddress",
"addressCountry": "IT"
},
"geo": {
"@type": "GeoCoordinates",
"latitude": 43.808799743652344,
"longitude": 11.202899932861328
},
"iataCode": "FLR",
"name": "Peretola"
},
"arrivalTime": {
"@type": "QDateTime",
"@value": "2000-01-01T16:20:00+01:00",
"timezone": "Europe/Rome"
},
"departureAirport": {
"@type": "Airport",
"address": {
"@type": "PostalAddress",
"addressCountry": "DE"
},
"geo": {
"@type": "GeoCoordinates",
"latitude": 48.35390090942383,
"longitude": 11.786100387573242
},
"iataCode": "MUC",
"name": "Franz Josef Strauss"
},
"departureDay": "2000-01-01",
"departureTime": {
"@type": "QDateTime",
"@value": "2000-01-01T15:05:00+01:00",
"timezone": "Europe/Berlin"
},
"flightNumber": "9440"
},
"reservationNumber": "XXX007",
"underName": {
"@type": "Person",
"name": "Traveler One"
}
},
{
"@context": "http://schema.org",
"@type": "FlightReservation",
"reservationFor": {
"@type": "Flight",
"airline": {
"@type": "Airline",
"iataCode": "LH",
"name": "Lufthansa"
},
"arrivalAirport": {
"@type": "Airport",
"address": {
"@type": "PostalAddress",
"addressCountry": "IT"
},
"geo": {
"@type": "GeoCoordinates",
"latitude": 43.808799743652344,
"longitude": 11.202899932861328
},
"iataCode": "FLR",
"name": "Peretola"
},
"arrivalTime": {
"@type": "QDateTime",
"@value": "2000-01-01T16:20:00+01:00",
"timezone": "Europe/Rome"
},
"departureAirport": {
"@type": "Airport",
"address": {
"@type": "PostalAddress",
"addressCountry": "DE"
},
"geo": {
"@type": "GeoCoordinates",
"latitude": 48.35390090942383,
"longitude": 11.786100387573242
},
"iataCode": "MUC",
"name": "Franz Josef Strauss"
},
"departureDay": "2000-01-01",
"departureTime": {
"@type": "QDateTime",
"@value": "2000-01-01T15:05:00+01:00",
"timezone": "Europe/Berlin"
},
"flightNumber": "9440"
},
"reservationNumber": "XXX007",
"underName": {
"@type": "Person",
"name": "Traveler Two"
}
}
]
......@@ -95,7 +95,7 @@ bool ModelVerificationPoint::verify(QAbstractItemModel *model) const
// reference data
QFile file(m_refFile);
if (!file.open(QFile::ReadOnly)) {
qWarning() << file.errorString();
qWarning() << file.fileName() << file.errorString();
return false;
}
const auto doc = QJsonDocument::fromJson(file.readAll());
......
......@@ -29,6 +29,7 @@
#include <KItinerary/Place>
#include <KItinerary/Reservation>
#include <QDirIterator>
#include <QUrl>
#include <QtTest/qtest.h>
#include <QSignalSpy>
......@@ -457,6 +458,41 @@ private slots:
vp3.setRoleFilter({TimelineModel::ReservationIdsRole});
QVERIFY(vp3.verify(&model));
}
void testContent_data()
{
QTest::addColumn<QString>("baseName");
QDirIterator it(QLatin1String(SOURCE_DIR "/data/timeline/"), {QLatin1String("*.json")});
while (it.hasNext()) {
it.next();
const auto baseName = it.fileInfo().baseName();
QTest::newRow(baseName.toUtf8().constData()) << baseName;
}
}
void testContent()
{
QFETCH(QString, baseName);
ReservationManager resMgr;
clearReservations(&resMgr);
resMgr.importReservation(readFile(QLatin1String(SOURCE_DIR "/data/timeline/") + baseName + QLatin1String(".json")));
TimelineModel model;
model.setHomeCountryIsoCode(QStringLiteral("DE"));
model.setCurrentDateTime(QDateTime({1996, 10, 14}, {12, 34}));
model.setReservationManager(&resMgr);
// check state is correct for data imported at the start
ModelVerificationPoint vp(QLatin1String(SOURCE_DIR "/data/timeline/") + baseName + QLatin1String(".model"));
vp.setRoleFilter({TimelineModel::ReservationIdsRole});
QVERIFY(vp.verify(&model));
// retry with loading during runtime
clearReservations(&resMgr);
resMgr.importReservation(readFile(QLatin1String(SOURCE_DIR "/data/timeline/") + baseName + QLatin1String(".json")));
QVERIFY(vp.verify(&model));
}
};
QTEST_GUILESS_MAIN(TimelineModelTest)
......
......@@ -306,6 +306,7 @@ QVariant TimelineModel::data(const QModelIndex& index, int role) const
QVector<QVariant> v;
for (const auto &resId : elem.ids)
v.push_back(m_resMgr->reservation(resId));
std::sort(v.begin(), v.end(), SortUtil::isBefore);
return QVariant::fromValue(v);
}
}
......@@ -507,7 +508,7 @@ void TimelineModel::updateInformationElements()
// add new country info element
auto row = std::distance(m_elements.begin(), it);
beginInsertRows({}, row, row);
it = m_elements.insert(it, Element{CountryInfo, (*it).dt, QVariant::fromValue(newCountry)});
it = m_elements.insert(it, Element{CountryInfo, (*it).dt.addSecs(-1), QVariant::fromValue(newCountry)});
endInsertRows();
previousCountry = newCountry;
......
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