Commit 1d0216ff authored by Volker Krause's avatar Volker Krause

Port timeline model to the new multi-traveler batching

Also, fix a few more corner cases in batching found by the timeline model
unit tests.
parent 9ce96498
......@@ -52,9 +52,11 @@ private:
void clearReservations(ReservationManager *mgr)
{
for (const auto &id : mgr->reservations()) {
mgr->removeReservation(id);
const auto batches = mgr->batches(); // copy, as this is getting modified in the process
for (const auto &id : batches) {
mgr->removeBatch(id);
}
QCOMPARE(mgr->batches().size(), 0);
}
QByteArray readFile(const QString &fn)
......
......@@ -226,10 +226,12 @@ void ReservationManager::addReservation(const QVariant &res)
void ReservationManager::updateReservation(const QString &resId, const QVariant &res)
{
const auto oldRes = reservation(resId);
storeReservation(resId, res);
emit reservationUpdated(resId);
updateBatch(resId, res);
updateBatch(resId, res, oldRes);
}
void ReservationManager::storeReservation(const QString &resId, const QVariant &res) const
......@@ -387,25 +389,25 @@ void ReservationManager::initialBatchCreate()
it.next();
const auto resId = it.fileInfo().baseName();
const auto res = reservation(resId);
updateBatch(resId, res);
updateBatch(resId, res, res);
}
}
void ReservationManager::updateBatch(const QString &resId, const QVariant &res)
void ReservationManager::updateBatch(const QString &resId, const QVariant &newRes, const QVariant &oldRes)
{
const auto oldBatchId = batchForReservation(resId);
QString newBatchId;
// find the destination batch
const auto beginIt = std::lower_bound(m_batches.begin(), m_batches.end(), res, [this](const auto &lhs, const auto &rhs) {
const auto beginIt = std::lower_bound(m_batches.begin(), m_batches.end(), newRes, [this](const auto &lhs, const auto &rhs) {
return SortUtil::startDateTime(reservation(lhs)) < SortUtil::startDateTime(rhs);
});
for (auto it = beginIt; it != m_batches.end(); ++it) {
const auto otherRes = reservation(*it);
if (SortUtil::startDateTime(otherRes) != SortUtil::startDateTime(res)) {
const auto otherRes = (resId == (*it)) ? oldRes : reservation(*it);
if (SortUtil::startDateTime(otherRes) != SortUtil::startDateTime(newRes)) {
break; // no hit
}
if (isSameTrip(res, otherRes)) {
if (isSameTrip(newRes, otherRes)) {
newBatchId = *it;
break;
}
......@@ -426,10 +428,10 @@ void ReservationManager::updateBatch(const QString &resId, const QVariant &res)
if (newBatchId.isEmpty()) {
// we are starting a new batch
// re-run search for insertion point, could be invalid due to the above deletions
const auto it = std::lower_bound(m_batches.begin(), m_batches.end(), res, [this](const auto &lhs, const auto &rhs) {
const auto it = std::lower_bound(m_batches.begin(), m_batches.end(), newRes, [this](const auto &lhs, const auto &rhs) {
return SortUtil::startDateTime(reservation(lhs)) < SortUtil::startDateTime(rhs);
});
m_batches.insert(it, resId);
m_batches.insert(it, QString(resId));
m_batchToResMap.insert(resId, {resId});
m_resToBatchMap.insert(resId, resId);
emit batchAdded(resId);
......
......@@ -97,7 +97,7 @@ private:
void storeBatch(const QString &batchId) const;
void storeRemoveBatch(const QString &batchId) const;
void updateBatch(const QString &resId, const QVariant &res);
void updateBatch(const QString &resId, const QVariant &newRes, const QVariant &oldRes);
void removeFromBatch(const QString &resId, const QString &batchId);
mutable QHash<QString, QVariant> m_reservations;
......
This diff is collapsed.
......@@ -107,7 +107,7 @@ private:
explicit Element(ElementType type, const QDateTime &dateTime, const QVariant &data = {});
explicit Element(const QString &resId, const QVariant &res, RangeType rt);
QStringList ids; // reservation ids (multiple entries in case of mult-traveller merging), QStringList as we need QML compatibility...
QString batchId; // reservation batch id
QVariant content; // non-reservation content
QDateTime dt; // relevant date/time
ElementType elementType;
......@@ -116,11 +116,12 @@ private:
static bool elementLessThan(const Element &lhs, const Element &rhs);
void reservationAdded(const QString &resId);
void batchAdded(const QString &resId);
void insertElement(Element &&elem);
void reservationUpdated(const QString &resId);
void batchChanged(const QString &resId);
void updateElement(const QString &resId, const QVariant &res, RangeType rangeType);
void reservationRemoved(const QString &resId);
void batchRenamed(const QString &oldBatchId, const QString &newBatchId);
void batchRemoved(const QString &resId);
void tripGroupAdded(const QString &groupId);
void tripGroupChanged(const QString &groupId);
......
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