Commit 9dfd0963 authored by Volker Krause's avatar Volker Krause
Browse files

Implement deleting entire trip groups

Fixes #29.
parent d2eaee48
......@@ -203,6 +203,23 @@ private Q_SLOTS:
QCOMPARE(g.elements().size(), resMgr.batches().size() - 1);
QCOMPARE(g.name(), QStringLiteral("Oslo Airport (June 2000)"));
}
void testDeletion()
{
ReservationManager resMgr;
clearReservations(&resMgr);
resMgr.importReservation(readFile(QStringLiteral(SOURCE_DIR "/../tests/randa2017.json")));
TripGroupManager mgr;
QSignalSpy addSpy(&mgr, &TripGroupManager::tripGroupAdded);
mgr.setReservationManager(&resMgr);
QCOMPARE(addSpy.size(), 1);
QVERIFY(resMgr.batches().size() > 8);
const auto groupId = addSpy.at(0).at(0).toString();
const auto g = mgr.tripGroup(groupId);
mgr.removeReservationsInGroup(groupId);
QCOMPARE(resMgr.batches().size(), 0);
QCOMPARE(mgr.tripGroups().size(), 0);
}
};
QTEST_GUILESS_MAIN(TripGroupTest)
......
......@@ -124,6 +124,28 @@ Kirigami.ScrollablePage {
}
}
Kirigami.OverlaySheet {
id: deleteTripGroupWarningSheet
property string tripGroupId
QQC2.Label {
text: i18n("Do you really want to delete this trip?")
wrapMode: Text.WordWrap
}
footer: RowLayout {
QQC2.Button {
Layout.alignment: Qt.AlignHCenter
text: i18n("Delete")
icon.name: "edit-delete"
onClicked: {
deleteTripGroupWarningSheet.sheetOpen = false;
TripGroupManager.removeReservationsInGroup(deleteTripGroupWarningSheet.tripGroupId);
}
}
}
}
Kirigami.CardsListView {
id: listView
model: TripGroupProxyModel
......
......@@ -69,7 +69,7 @@ Kirigami.AbstractCard {
Localizer.formatDateTime(root.tripGroup, "beginDateTime"))
}
RowLayout {
Row {
visible: weatherForecast.valid
Kirigami.Icon {
......@@ -103,6 +103,22 @@ Kirigami.AbstractCard {
}
}
Kirigami.Separator {
visible: root.rangeType == TimelineElement.RangeBegin
}
Row {
visible: root.rangeType == TimelineElement.RangeBegin
anchors.right: parent.right
QQC2.ToolButton {
icon.name: "edit-delete"
onClicked: {
deleteTripGroupWarningSheet.tripGroupId = root.tripGroupId
deleteTripGroupWarningSheet.sheetOpen = true
}
}
}
Component.onCompleted: {
// hide content entirely in the header-only end elements
parent.visible = contentLayout.visible
......
......@@ -143,6 +143,19 @@ void TripGroupManager::clear()
d.removeRecursively();
}
void TripGroupManager::removeReservationsInGroup(const QString &groupId)
{
const auto groupIt = m_tripGroups.constFind(groupId);
if (groupIt == m_tripGroups.constEnd()) {
return;
}
const auto elements = groupIt.value().elements();
for (const auto &element : elements) {
m_resMgr->removeBatch(element);
}
}
void TripGroupManager::batchAdded(const QString &resId)
{
auto it = std::lower_bound(m_reservations.begin(), m_reservations.end(), resId, [this](const auto &lhs, const auto &rhs) {
......
......@@ -33,6 +33,9 @@ public:
static void clear(); // for testing only!
/** Deletes all elements in the trip group with Identifier @p id. */
Q_INVOKABLE void removeReservationsInGroup(const QString &groupId);
Q_SIGNALS:
void tripGroupAdded(const QString &id);
void tripGroupChanged(const QString &id);
......
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