aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2017-05-26 17:53:25 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2017-05-27 11:07:20 -0700
commit38e24512b74dcfb0f473fe0c8003c66e99354409 (patch)
treeda874a08a20503079978a32a9a2fe2ee92c06213
parent7858376727ee467ae59a18d84d40e3148ea3e38b (diff)
downloadsubsurface-38e24512b74dcfb0f473fe0c8003c66e99354409.tar.gz
QML UI: add the Downloaded Dive Model
Still to do: - select the dives to save - record the downloaded dives but download is already working. :) Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--mobile-widgets/qml/DownloadFromDiveComputer.qml10
-rw-r--r--qt-models/diveimportedmodel.cpp37
-rw-r--r--qt-models/diveimportedmodel.h11
-rw-r--r--subsurface-mobile-helper.cpp2
4 files changed, 53 insertions, 7 deletions
diff --git a/mobile-widgets/qml/DownloadFromDiveComputer.qml b/mobile-widgets/qml/DownloadFromDiveComputer.qml
index 4587f2e98..a8f052626 100644
--- a/mobile-widgets/qml/DownloadFromDiveComputer.qml
+++ b/mobile-widgets/qml/DownloadFromDiveComputer.qml
@@ -44,6 +44,14 @@ Kirigami.Page {
deviceData.diveId : 0
deviceData.saveDump : false
deviceData.saveLog : false
+
+ onFinished : {
+ importModel.repopulate()
+ }
+ }
+
+ DCImportModel {
+ id: importModel
}
ColumnLayout {
@@ -98,6 +106,8 @@ Kirigami.Page {
Layout.fillWidth: true // The tableview should fill
Layout.fillHeight: true // all remaining vertical space
height: parent.height // on this screen
+ model : importModel
+
QQC1.TableViewColumn {
width: parent.width / 2
role: "datetime"
diff --git a/qt-models/diveimportedmodel.cpp b/qt-models/diveimportedmodel.cpp
index 08c36e7e6..781cd72c6 100644
--- a/qt-models/diveimportedmodel.cpp
+++ b/qt-models/diveimportedmodel.cpp
@@ -7,6 +7,8 @@ DiveImportedModel::DiveImportedModel(QObject *o) : QAbstractTableModel(o),
checkStates(nullptr),
diveTable(nullptr)
{
+ // Defaults to downloadTable, can be changed later.
+ diveTable = &downloadTable;
}
int DiveImportedModel::columnCount(const QModelIndex &model) const
@@ -25,8 +27,16 @@ QVariant DiveImportedModel::headerData(int section, Qt::Orientation orientation,
{
if (orientation == Qt::Vertical)
return QVariant();
+
+ // widgets access the model via index.column(), qml via role.
+ int column = section;
+ if (role == DateTime || role == Duration || role == Depth) {
+ column = role - DateTime;
+ role = Qt::DisplayRole;
+ }
+
if (role == Qt::DisplayRole) {
- switch (section) {
+ switch (column) {
case 0:
return QVariant(tr("Date/time"));
case 1:
@@ -40,7 +50,7 @@ QVariant DiveImportedModel::headerData(int section, Qt::Orientation orientation,
void DiveImportedModel::setDiveTable(struct dive_table* table)
{
- diveTable = table;
+ diveTable = table;
}
QVariant DiveImportedModel::data(const QModelIndex &index, int role) const
@@ -54,8 +64,16 @@ QVariant DiveImportedModel::data(const QModelIndex &index, int role) const
struct dive *d = get_dive_from_table(index.row() + firstIndex, diveTable);
if (!d)
return QVariant();
+
+ // widgets access the model via index.column(), qml via role.
+ int column = index.column();
+ if (role == DateTime || role == Duration || role == Depth) {
+ column = role - DateTime;
+ role = Qt::DisplayRole;
+ }
+
if (role == Qt::DisplayRole) {
- switch (index.column()) {
+ switch (column) {
case 0:
return QVariant(get_short_dive_date_string(d->when));
case 1:
@@ -119,3 +137,16 @@ void DiveImportedModel::setImportedDivesIndexes(int first, int last)
memset(checkStates, true, last - first + 1);
endInsertRows();
}
+
+void DiveImportedModel::repopulate()
+{
+ setImportedDivesIndexes(0, diveTable->nr-1);
+}
+
+QHash<int, QByteArray> DiveImportedModel::roleNames() const {
+ static QHash<int, QByteArray> roles = {
+ { DateTime, "datetime"},
+ { Depth, "depth"},
+ { Duration, "duration"}};
+ return roles;
+}
diff --git a/qt-models/diveimportedmodel.h b/qt-models/diveimportedmodel.h
index 1127fc97e..e68fec0f8 100644
--- a/qt-models/diveimportedmodel.h
+++ b/qt-models/diveimportedmodel.h
@@ -8,8 +8,10 @@ class DiveImportedModel : public QAbstractTableModel
{
Q_OBJECT
public:
- DiveImportedModel(QObject *o);
- void setDiveTable(struct dive_table *table);
+ enum roleTypes { DateTime = Qt::UserRole + 1, Duration, Depth};
+
+ DiveImportedModel(QObject *parent = 0);
+ void setDiveTable(struct dive_table *table);
int columnCount(const QModelIndex& index = QModelIndex()) const;
int rowCount(const QModelIndex& index = QModelIndex()) const;
QVariant data(const QModelIndex& index, int role) const;
@@ -17,7 +19,8 @@ public:
void setImportedDivesIndexes(int first, int last);
Qt::ItemFlags flags(const QModelIndex &index) const;
void clearTable();
-
+ QHash<int, QByteArray> roleNames() const;
+ Q_INVOKABLE void repopulate();
public
slots:
void changeSelected(QModelIndex clickedIndex);
@@ -28,7 +31,7 @@ private:
int firstIndex;
int lastIndex;
bool *checkStates;
- struct dive_table *diveTable;
+ struct dive_table *diveTable;
};
#endif
diff --git a/subsurface-mobile-helper.cpp b/subsurface-mobile-helper.cpp
index dec4fa160..7d9037775 100644
--- a/subsurface-mobile-helper.cpp
+++ b/subsurface-mobile-helper.cpp
@@ -22,6 +22,7 @@
#include "qt-models/gpslistmodel.h"
#include "mobile-widgets/qmlprofile.h"
#include "core/downloadfromdcthread.h"
+#include "qt-models/diveimportedmodel.h"
#include "mobile-widgets/qml/kirigami/src/kirigamiplugin.h"
@@ -39,6 +40,7 @@ void run_ui()
qmlRegisterType<DCDeviceData>("org.subsurfacedivelog.mobile", 1, 0, "DCDeviceData");
qmlRegisterType<DownloadThread>("org.subsurfacedivelog.mobile", 1, 0, "DCDownloadThread");
+ qmlRegisterType<DiveImportedModel>("org.subsurfacedivelog.mobile", 1, 0, "DCImportModel");
QQmlApplicationEngine engine;
KirigamiPlugin::getInstance().registerTypes();