summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2017-05-28 11:48:30 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2017-05-28 11:54:33 -0700
commit3f0d21046e92701de200a00f12bde20a7ad3a55c (patch)
treed5b4134865a3153da692c913aa7f829f08ad8bd0
parent84b1b63d46e4868808cc8dbd1c4fef8078ddcb16 (diff)
downloadsubsurface-3f0d21046e92701de200a00f12bde20a7ad3a55c.tar.gz
QML UI: add downloaded dives to dive list
This already takes into account which of those dives were selected. Right now all we have is select all or none - this needs actual support in the UI, but once that's there, it will just work (famous last words). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--mobile-widgets/qml/DownloadFromDiveComputer.qml10
-rw-r--r--qt-models/diveimportedmodel.cpp11
-rw-r--r--qt-models/diveimportedmodel.h1
-rw-r--r--qt-models/divelistmodel.cpp12
-rw-r--r--qt-models/divelistmodel.h2
5 files changed, 31 insertions, 5 deletions
diff --git a/mobile-widgets/qml/DownloadFromDiveComputer.qml b/mobile-widgets/qml/DownloadFromDiveComputer.qml
index a794c5bc6..c3bb9ce2d 100644
--- a/mobile-widgets/qml/DownloadFromDiveComputer.qml
+++ b/mobile-widgets/qml/DownloadFromDiveComputer.qml
@@ -123,11 +123,11 @@ Kirigami.Page {
text: qsTr("Accept")
enabled: false
onClicked: {
- manager.appendTextToLog("Save downloaded dives")
- for (var i = 0; i < importModel.rowCount(); i++) {
- // figure out which ones are selected
- // save the selected dive to the diveTable
- }
+ manager.appendTextToLog("Save downloaded dives that were selected")
+ importModel.recordDives()
+ manager.saveChangesLocal()
+ diveModel.clear()
+ diveModel.addAllDives()
stackView.pop();
}
}
diff --git a/qt-models/diveimportedmodel.cpp b/qt-models/diveimportedmodel.cpp
index 781cd72c6..c1f4f7525 100644
--- a/qt-models/diveimportedmodel.cpp
+++ b/qt-models/diveimportedmodel.cpp
@@ -143,6 +143,17 @@ void DiveImportedModel::repopulate()
setImportedDivesIndexes(0, diveTable->nr-1);
}
+void DiveImportedModel::recordDives()
+{
+ for (int i = 0; i < rowCount(); i++) {
+ if (diveTable->dives[i] && checkStates[i]) {
+ record_dive(diveTable->dives[i]);
+ diveTable->dives[i] = NULL;
+ }
+ }
+ diveTable->nr = 0;
+}
+
QHash<int, QByteArray> DiveImportedModel::roleNames() const {
static QHash<int, QByteArray> roles = {
{ DateTime, "datetime"},
diff --git a/qt-models/diveimportedmodel.h b/qt-models/diveimportedmodel.h
index e68fec0f8..240f7f4b5 100644
--- a/qt-models/diveimportedmodel.h
+++ b/qt-models/diveimportedmodel.h
@@ -21,6 +21,7 @@ public:
void clearTable();
QHash<int, QByteArray> roleNames() const;
Q_INVOKABLE void repopulate();
+ Q_INVOKABLE void recordDives();
public
slots:
void changeSelected(QModelIndex clickedIndex);
diff --git a/qt-models/divelistmodel.cpp b/qt-models/divelistmodel.cpp
index 2a77f34fe..a0f181405 100644
--- a/qt-models/divelistmodel.cpp
+++ b/qt-models/divelistmodel.cpp
@@ -25,6 +25,18 @@ int DiveListSortModel::getIdxForId(int id)
return -1;
}
+void DiveListSortModel::clear()
+{
+ DiveListModel *mySourceModel = qobject_cast<DiveListModel *>(sourceModel());
+ mySourceModel->clear();
+}
+
+void DiveListSortModel::addAllDives()
+{
+ DiveListModel *mySourceModel = qobject_cast<DiveListModel *>(sourceModel());
+ mySourceModel->addAllDives();
+}
+
DiveListModel *DiveListModel::m_instance = NULL;
DiveListModel::DiveListModel(QObject *parent) : QAbstractListModel(parent)
diff --git a/qt-models/divelistmodel.h b/qt-models/divelistmodel.h
index d24282776..41bc9107c 100644
--- a/qt-models/divelistmodel.h
+++ b/qt-models/divelistmodel.h
@@ -14,6 +14,8 @@ class DiveListSortModel : public QSortFilterProxyModel
Q_OBJECT
public:
DiveListSortModel(QObject *parent = 0);
+ Q_INVOKABLE void addAllDives();
+ Q_INVOKABLE void clear();
public slots:
int getDiveId(int idx);
int getIdxForId(int id);