From: David Llewellyn-Jones Date: Sat, 14 Jul 2018 19:08:51 +0000 (+0100) Subject: Add menu (delete, edit) to journey list items X-Git-Url: https://www.flypig.org.uk/git/?p=harbour-pedalo.git;a=commitdiff_plain;h=4248fa25458b2d282d4e0ed4447e4bc7570046eb Add menu (delete, edit) to journey list items --- diff --git a/qml/pages/JourneyList.qml b/qml/pages/JourneyList.qml index 0468df0..8831f40 100644 --- a/qml/pages/JourneyList.qml +++ b/qml/pages/JourneyList.qml @@ -15,8 +15,9 @@ Page { header: PageHeader { title: qsTr("Journey list") } - delegate: BackgroundItem { + delegate: ListItem { id: delegate + menu: journeyMenuComponent Row { spacing: Theme.paddingLarge @@ -39,6 +40,26 @@ Page { } } onClicked: pageStack.push(Qt.resolvedUrl("AddJourney.qml"), {title: "Edit journey", index: index, start: journeymodel.epochToDateTime(start), duration: duration, overtook: overtook, overtakenby: overtakenby}) + + Component { + id: journeyMenuComponent + ContextMenu { + MenuItem { + text: qsTr("Edit") + onClicked: pageStack.push(Qt.resolvedUrl("AddJourney.qml"), {title: "Edit journey", index: index, start: journeymodel.epochToDateTime(start), duration: duration, overtook: overtook, overtakenby: overtakenby}) + } + MenuItem { + text: qsTr("Delete") + onClicked: remove(index) + } + } + } + + function remove(index) { + remorseAction(qsTr("Deleting journey"), function() { + onClicked: journeymodel.deleteJourney(index) + }) + } } VerticalScrollDecorator {} } diff --git a/src/journeymodel.cpp b/src/journeymodel.cpp index 80a5eb5..5b7b5da 100644 --- a/src/journeymodel.cpp +++ b/src/journeymodel.cpp @@ -30,6 +30,12 @@ void JourneyModel::editJourney(quint32 index, QDateTime start, quint32 duration, emit dataChanged(createIndex(index, 0), createIndex(index, 0)); } +void JourneyModel::deleteJourney(quint32 index) { + beginRemoveRows(QModelIndex(), index, index); + journeys.removeAt(index); + endRemoveRows(); +} + int JourneyModel::rowCount(const QModelIndex & parent) const { Q_UNUSED(parent) return journeys.count(); @@ -99,9 +105,7 @@ void JourneyModel::importFromFile(QFile & file) { QDate JourneyModel::epochToDate(quint64 epoch) { QDateTime date; - qDebug() << "Epoch: " << epoch; date.setMSecsSinceEpoch(epoch); - qDebug() << "Date: " << date.date(); return date.date(); } diff --git a/src/journeymodel.h b/src/journeymodel.h index a068b14..910821c 100644 --- a/src/journeymodel.h +++ b/src/journeymodel.h @@ -25,6 +25,7 @@ public: void addJourney(const Journey &journey); Q_INVOKABLE void addJourney(QDateTime start, quint32 duration, quint32 overtook, quint32 overtakenby); Q_INVOKABLE void editJourney(quint32 index, QDateTime start, quint32 duration, quint32 overtook, quint32 overtakenby); + Q_INVOKABLE void deleteJourney(quint32 index); int rowCount(const QModelIndex & parent = QModelIndex()) const; diff --git a/translations/harbour-pedalo-de.ts b/translations/harbour-pedalo-de.ts index 2a19b3f..bb23457 100644 --- a/translations/harbour-pedalo-de.ts +++ b/translations/harbour-pedalo-de.ts @@ -65,6 +65,18 @@ Journey list + + Edit + + + + Delete + + + + Deleting journey + + MainPage diff --git a/translations/harbour-pedalo.ts b/translations/harbour-pedalo.ts index 74b615b..e580051 100644 --- a/translations/harbour-pedalo.ts +++ b/translations/harbour-pedalo.ts @@ -65,6 +65,18 @@ Journey list + + Edit + + + + Delete + + + + Deleting journey + + MainPage