KItinerary
mergeutil.cpp
79static bool equalAndPresent(QStringView lhs, QStringView rhs, Qt::CaseSensitivity caseSensitive = Qt::CaseSensitive)
84static typename std::enable_if<!std::is_same_v<T, QString>, bool>::type equalAndPresent(const T &lhs, const T &rhs)
94static bool conflictIfPresent(QStringView lhs, QStringView rhs, Qt::CaseSensitivity caseSensitive = Qt::CaseSensitive)
99static typename std::enable_if<!std::is_same_v<T, QString>, bool>::type conflictIfPresent(const T &lhs, const T &rhs)
117static bool isSameTouristAttractionVisit(const TouristAttractionVisit &lhs, const TouristAttractionVisit &rhs);
135 if (conflictIfPresent(lhsTicket.ticketedSeat().seatNumber(), rhsTicket.ticketedSeat().seatNumber(), Qt::CaseInsensitive)) {
149 if (!lhsMo || !rhsMo || (lhsMt.flags() & QMetaType::IsGadget) == 0 || (rhsMt.flags() & QMetaType::IsGadget) == 0) {
174 // flight ticket tokens (IATA BCBP) can differ, so we need to compare the relevant bits in them manually
177 // for other ticket tokens (e.g. Renfe), shorter and longer versions of the same token exist as well
179 if (!JsonLd::isA<FlightReservation>(lhs) && !TicketTokenComparator::isSame(lhsTicket.ticketTokenData(), rhsTicket.ticketTokenData())) {
183 // one side is a minimal cancellation, matches the reservation number and has a plausible modification time
194 if (conflictIfPresent(lhsRes.reservationNumber(), rhsRes.reservationNumber()) || conflictIfPresent(lhsRes.passengerSequenceNumber(), rhsRes.passengerSequenceNumber())) {
254 return isSame(lhsRes.reservationFor(), rhsRes.reservationFor()) && lhsRes.checkinTime().date() == rhsRes.checkinTime().date();
264 return isSame(lhsRes.reservationFor(), rhsRes.reservationFor()) && lhsRes.pickupTime().date() == rhsRes.pickupTime().date();
279 return isSame(lhsRes.reservationFor(), rhsRes.reservationFor()) && lhsRes.pickupTime().date() == rhsRes.pickupTime().date();
299 return isSame(lhsRes.reservationFor(), rhsRes.reservationFor()) && lhsRes.startTime().date() == endTime.date();
319 ((lhsRes.reservationFor().isNull() ^ rhsRes.reservationFor().isNull()) && equalAndPresent(lhsRes.reservationNumber(), rhsRes.reservationNumber()));
370 const auto it = std::lower_bound(s_mergeCompareFuncs.begin(), s_mergeCompareFuncs.end(), lhs.userType());
380 // if there is a conflict on where this is going, or when, this is obviously not the same flight
398 // we get here if we have matching origin/destination on the same day, but mismatching flight numbers
401 // (that is, if this is ever made available as standalone API, the last return should not be true)
411static bool isSameLineName(const Iter &lBegin, const Iter &lEnd, const Iter &rBegin, const Iter &rEnd)
459 static QRegularExpression rx(QStringLiteral(R"(^(?<type>[A-Za-z]+) (?<line>\d+)(?: \((?<route>\d{4,})\))?$)"));
466 (equalAndPresent(lhsMatch.capturedView(u"line"), rhsMatch.capturedView(u"line")) && !conflictIfPresent(lhsMatch.capturedView(u"route"), rhsMatch.capturedView(u"route")))
467 || (equalAndPresent(lhsMatch.capturedView(u"line"), rhsMatch.capturedView(u"route")) && lhsMatch.capturedView(u"route").isEmpty())
468 || (equalAndPresent(lhsMatch.capturedView(u"route"), rhsMatch.capturedView(u"line")) && rhsMatch.capturedView(u"route").isEmpty())
481 qCDebug(CompareLog) << "unbound trip" << lhs.departureStation().name() << rhs.departureStation().name() << lhs.arrivalStation().name() << rhs.arrivalStation().name();
482 return LocationUtil::isSameLocation(lhs.departureStation(), rhs.departureStation(), LocationUtil::Exact)
483 && LocationUtil::isSameLocation(lhs.arrivalStation(), rhs.arrivalStation(), LocationUtil::Exact);
486 qCDebug(CompareLog) << "departure time" << lhs.departureTime() << rhs.departureTime() <<equalAndPresent(lhs.departureTime(), rhs.departureTime());
491 // only one departure time exists, so check if the locations don't conflict and rely on the train number for the rest
492 if (!LocationUtil::isSameLocation(lhs.departureStation(), rhs.departureStation(), LocationUtil::CityLevel)
493 || !LocationUtil::isSameLocation(lhs.arrivalStation(), rhs.arrivalStation(), LocationUtil::CityLevel)) {
498 // arrival times (when present) should either match exactly, or be almost the same at a matching arrival location
499 // (tickets even for the same connection booked on the same day sometimes have slight variation in the arrival time...)
505 if (!LocationUtil::isSameLocation(lhs.arrivalStation(), rhs.arrivalStation(), LocationUtil::Exact)) {
513 return LocationUtil::isSameLocation(lhs.departureStation(), rhs.departureStation(), LocationUtil::Exact)
514 && LocationUtil::isSameLocation(lhs.arrivalStation(), rhs.arrivalStation(), LocationUtil::Exact);
533 (LocationUtil::isSameLocation(lhs.departureBusStop(), rhs.departureBusStop()) && LocationUtil::isSameLocation(lhs.arrivalBusStop(), rhs.arrivalBusStop()));
556static bool isSameTouristAttractionVisit(const TouristAttractionVisit &lhs, const TouristAttractionVisit &rhs)
558 return lhs.arrivalTime() == rhs.arrivalTime() && isSameTouristAttraction(lhs.touristAttraction(), rhs.touristAttraction());
581 if ((j < rhs.size() && (lhs.size() < rhs.size() || (lhs.size() == rhs.size() && j < i))) || i == lhs.size()) {
617 if (fullName.familyName().isEmpty() || fullName.givenName().isEmpty() || !fullName.givenName().startsWith(partialName.givenName(), Qt::CaseInsensitive)) {
620 return isNameEqualish(fullName.familyName(), partialName.name()) || isNameEqualish(fullName.familyName(), partialName.familyName());
626 (isNameEqualish(lhs.givenName(), rhs.givenName()) && isNameEqualish(lhs.familyName(), rhs.familyName()))) {
654 return namePrefix == 1.0f || (namePrefix > 0.65f && LocationUtil::isSameLocation(lhs.location(), rhs.location(), LocationUtil::Exact));
670 if (lhs.userType() != rhs.userType() || !JsonLd::canConvert<Reservation>(lhs) || !JsonLd::canConvert<Reservation>(rhs)) {
702 if (lhs.isValid() && lhs.timeSpec() == Qt::TimeZone && rhs.isValid() && rhs.timeSpec() == Qt::TimeZone) {
706 return lhs.isValid() && lhs.timeSpec() == Qt::TimeZone && rhs.timeSpec() != Qt::TimeZone ? lhs : rhs;
755 if (t.ticketTokenType() == Token::Url && lhs.ticketTokenType() != Token::Url && lhs.ticketTokenType() != Token::Unknown) {
759 t.setTicketToken(ticketTokenSize(lhs.ticketTokenData()) > ticketTokenSize(rhs.ticketTokenData()) ? lhs.ticketToken() : rhs.ticketToken());
843 const bool lhsTrainOrBus = JsonLd::isA<TrainReservation>(lhs) || JsonLd::isA<BusReservation>(lhs);
844 const bool rhsTrainOrBus = JsonLd::isA<TrainReservation>(rhs) || JsonLd::isA<BusReservation>(rhs);
845 return (lhsTrainOrBus && rhsTrainOrBus) || (JsonLd::isA<FlightReservation>(lhs) && JsonLd::isA<FlightReservation>(rhs));
863 return LocationUtil::isSameLocation(LocationUtil::departureLocation(lhs), LocationUtil::departureLocation(rhs), LocationUtil::Exact);
890 return LocationUtil::isSameLocation(LocationUtil::arrivalLocation(lhs), LocationUtil::arrivalLocation(rhs), LocationUtil::Exact);
897 return LocationUtil::isSameLocation(LocationUtil::arrivalLocation(lhs), LocationUtil::arrivalLocation(rhs), LocationUtil::CityLevel);
903void MergeUtil::registerComparator(int metaTypeId, std::function<bool (const QVariant&, const QVariant&)> &&func)
QString passengerSequenceNumber
Passenger sequence number Despite the name, do not expect this to be a number, infants without their ...
Definition reservation.h:97
static QVariant apply(const QVariant &lhs, const QVariant &rhs)
Apply all properties of rhs on to lhs.
Definition jsonlddocument.cpp:564
static QVariant merge(const QVariant &lhs, const QVariant &rhs)
Merge the two given objects.
Definition mergeutil.cpp:764
static void registerComparator(bool(*func)(const T &, const T &))
Register a comparator function for a custom type that will be used by isSame.
Definition mergeutil.h:75
static bool isSameIncidence(const QVariant &lhs, const QVariant &rhs)
Checks whether to elements refer to the same thing, just for different people.
Definition mergeutil.cpp:668
static bool isSamePerson(const Person &lhs, const Person &rhs)
Checks if two Person objects refer to the same person.
Definition mergeutil.cpp:623
static bool hasSameArrival(const QVariant &lhs, const QVariant &rhs)
Checks whether two transport reservation elements refer to the same arrival.
Definition mergeutil.cpp:875
static bool isSame(const QVariant &lhs, const QVariant &rhs)
Checks if two Reservation or Trip values refer to the same booking element.
Definition mergeutil.cpp:155
static bool hasSameDeparture(const QVariant &lhs, const QVariant &rhs)
Checks whether two transport reservation elements refer to the same departure.
Definition mergeutil.cpp:848
A frequent traveler, bonus points or discount scheme program membership.
Definition programmembership.h:22
QVariant tokenData
The token payload for barcodes, otherwise the same as ticketToken.
Definition programmembership.h:41
QDateTime validFrom
Non-standard extension for ticket validity time ranges.
Definition programmembership.h:44
QVariant ticketTokenData
The ticket token payload for barcodes, otherwise the same as ticketToken.
Definition ticket.h:57
KItinerary::Token::TokenType ticketTokenType
The type of the content in ticketToken.
Definition ticket.h:53
@ Url
A download URL, if shown in a barcode its format can be determined by the application.
Definition token.h:30
QString fullName(const PartType &type)
bool canConvert(const QVariant &value)
Checks if the given value can be up-cast to T.
Definition datatypes.h:31
bool valueIsNull(const QVariant &v)
Checks whether v holds a null-like value.
Definition jsonlddocument.cpp:370
bool isSameLocation(const QVariant &lhs, const QVariant &rhs, Accuracy accuracy=Exact)
Returns true if the given locations are the same.
Definition locationutil.cpp:302
QVariant departureLocation(const QVariant &res)
Returns the departure location of the given reservation.
Definition locationutil.cpp:75
QVariant arrivalLocation(const QVariant &res)
Returns the arrival location of the given reservation.
Definition locationutil.cpp:55
QDateTime startDateTime(const QVariant &elem)
Returns the (start) time associated with the given element.
Definition sortutil.cpp:29
bool hasStartTime(const QVariant &elem)
Returns whether the given element has a start time.
Definition sortutil.cpp:198
bool hasEndTime(const QVariant &elem)
Returns whether the given element has an end time.
Definition sortutil.cpp:216
QDateTime endDateTime(const QVariant &res)
Returns the (end) time associated with the given element.
Definition sortutil.cpp:101
QString normalize(QStringView str)
Strips out diacritics and converts to case-folded form.
Definition stringutil.cpp:19
QString transliterate(QStringView s)
Transliterate diacritics or other special characters.
Definition stringutil.cpp:171
float prefixSimilarity(QStringView s1, QStringView s2)
Returns how much of the prefix of two given strings are equal, in relation to the longer of the two i...
Definition stringutil.cpp:134
QStringView betterString(QStringView lhs, QStringView rhs)
Assuming both sides are describing the same thing, this tries to find the "better" string.
Definition stringutil.cpp:79
Classes for reservation/travel data models, data extraction and data augmentation.
Definition berelement.h:17
KGuiItem cancel()
bool operator<(const PosRange< Trait > &l, const PosRange< Trait > &r)
qsizetype size() const const
QDate date() const const
bool isValid() const const
qint64 secsTo(const QDateTime &other) const const
Qt::TimeSpec timeSpec() const const
QTimeZone timeZone() const const
QString
IsGadget
const QMetaObject * metaObject() const const
iterator begin()
iterator end()
bool isEmpty() const const
reverse_iterator rbegin()
QString & remove(QChar ch, Qt::CaseSensitivity cs)
reverse_iterator rend()
qsizetype size() const const
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
QString toUpper() const const
QString trimmed() const const
int compare(QChar ch) const const
bool isEmpty() const const
bool startsWith(QChar ch) const const
QString toString() const const
CaseSensitivity
LocalTime
LocalTime
QTimeZone utc()
const void * constData() const const
bool isNull() const const
QByteArray toByteArray() const const
QString toString() const const
int userType() const const
T value() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 20 2024 11:52:37 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 20 2024 11:52:37 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.