aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2015-07-17 11:57:21 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-07-17 12:00:38 -0700
commitd595f5c167c7283dc22f902ed0b18a7d6da2221e (patch)
tree10efaa6874740510a90fb9144facd7abe86ab577
parent76e61bd8d9baea008628bf5b176cf8f0b664e78f (diff)
parent0c9756c5d786158f25aaf1ad2d9c316be9e2b9e5 (diff)
downloadsubsurface-d595f5c167c7283dc22f902ed0b18a7d6da2221e.tar.gz
Merge branch 'devel' of https://github.com/gracie89/subsurface
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--CMakeLists.txt2
-rw-r--r--qt-gui.cpp2
-rw-r--r--qt-mobile/DiveList.qml18
-rw-r--r--qt-mobile/main.qml8
-rw-r--r--qt-mobile/qmlmanager.cpp48
-rw-r--r--qt-mobile/qmlmanager.h2
-rw-r--r--qt-mobile/qmlprofile.cpp43
-rw-r--r--qt-mobile/qmlprofile.h27
-rw-r--r--qt-models/divelistmodel.cpp14
-rw-r--r--qt-models/divelistmodel.h7
10 files changed, 167 insertions, 4 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ab7be1bfc..a3fbb1cb3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -458,7 +458,7 @@ endif()
# create the executables
if(SUBSURFACE_MOBILE)
- set(MOBILE_SRC qt-mobile/qmlmanager.cpp qt-models/divelistmodel.cpp)
+ set(MOBILE_SRC qt-mobile/qmlmanager.cpp qt-mobile/qmlprofile.cpp qt-models/divelistmodel.cpp)
add_definitions(-DSUBSURFACE_MOBILE)
qt5_add_resources(MOBILE_RESOURCES qt-mobile/mobile-resources.qrc)
if(ANDROID)
diff --git a/qt-gui.cpp b/qt-gui.cpp
index 175e9c27d..fac743a43 100644
--- a/qt-gui.cpp
+++ b/qt-gui.cpp
@@ -19,6 +19,7 @@
#include <QQmlContext>
#include "qt-mobile/qmlmanager.h"
#include "qt-models/divelistmodel.h"
+#include "qt-mobile/qmlprofile.h"
QObject *qqWindowObject = NULL;
#endif
@@ -40,6 +41,7 @@ void run_ui()
#ifdef SUBSURFACE_MOBILE
window->hide();
qmlRegisterType<QMLManager>("org.subsurfacedivelog.mobile", 1, 0, "QMLManager");
+ qmlRegisterType<QMLProfile>("org.subsurfacedivelog.mobile", 1, 0, "QMLProfile");
QQmlApplicationEngine engine;
DiveListModel diveListModel;
QQmlContext *ctxt = engine.rootContext();
diff --git a/qt-mobile/DiveList.qml b/qt-mobile/DiveList.qml
index 40507e26a..7fa7a53f0 100644
--- a/qt-mobile/DiveList.qml
+++ b/qt-mobile/DiveList.qml
@@ -77,6 +77,13 @@ Rectangle {
id: editorDetails
width: detailsPage.width
columns: 2
+ Text { }
+ QMLProfile {
+ diveId: id
+ height: 400
+ Layout.fillWidth: true
+ }
+
Text { text: "Location:"; font.bold: true }
TextField { id: txtLocation; text: location; Layout.fillWidth: true }
Text { text: "Air Temp:"; font.bold: true }
@@ -109,7 +116,16 @@ Rectangle {
opacity: dive.detailsOpacity
text: "Close"
- onClicked: dive.state = '';
+ onClicked: {
+ manager.commitChanges(
+ id,
+ txtSuit.text,
+ txtBuddy.text,
+ txtDiveMaster.text,
+ txtNotes.text
+ )
+ dive.state = '';
+ }
}
states: State {
diff --git a/qt-mobile/main.qml b/qt-mobile/main.qml
index dac37e09b..d64c27760 100644
--- a/qt-mobile/main.qml
+++ b/qt-mobile/main.qml
@@ -54,6 +54,14 @@ ApplicationWindow {
manager.loadDives();
}
}
+
+ Button {
+ id: saveChanges
+ text: "Save Changes"
+ onClicked: {
+ manager.saveChanges();
+ }
+ }
}
}
diff --git a/qt-mobile/qmlmanager.cpp b/qt-mobile/qmlmanager.cpp
index 118465a2d..a1c64191b 100644
--- a/qt-mobile/qmlmanager.cpp
+++ b/qt-mobile/qmlmanager.cpp
@@ -66,7 +66,53 @@ void QMLManager::loadDives()
struct dive *d;
for_each_dive(i, d)
- DiveListModel::instance()->addDive(d);
+ DiveListModel::instance()->addDive(d);
+}
+
+void QMLManager::commitChanges(QString diveId, QString suit, QString buddy, QString diveMaster, QString notes)
+{
+ struct dive *d = get_dive_by_uniq_id(diveId.toInt());
+ bool diveChanged = false;
+
+ if (d->suit != suit.toUtf8().data()) {
+ diveChanged = true;
+ free(d->suit);
+ d->suit = strdup(suit.toUtf8().data());
+ }
+ if (d->buddy != buddy.toUtf8().data()) {
+ diveChanged = true;
+ free(d->buddy);
+ d->buddy = strdup(buddy.toUtf8().data());
+ }
+ if (d->divemaster != diveMaster.toUtf8().data()) {
+ diveChanged = true;
+ free(d->divemaster);
+ d->divemaster = strdup(diveMaster.toUtf8().data());
+ }
+ if (d->notes != notes.toUtf8().data()) {
+ diveChanged = true;
+ free(d->notes);
+ d->notes = strdup(notes.toUtf8().data());
+ }
+}
+
+void QMLManager::saveChanges()
+{
+ showMessage("Saving dives.");
+ QString fileName;
+ if (getCloudURL(fileName)) {
+ showMessage(get_error_string());
+ return;
+ }
+
+ if (save_dives(fileName.toUtf8().data())) {
+ showMessage(get_error_string());
+ return;
+ }
+
+ showMessage("Dives saved.");
+ set_filename(fileName.toUtf8().data(), true);
+ mark_divelist_changed(false);
}
QString QMLManager::cloudPassword() const
diff --git a/qt-mobile/qmlmanager.h b/qt-mobile/qmlmanager.h
index 558249e4e..2f5ac2894 100644
--- a/qt-mobile/qmlmanager.h
+++ b/qt-mobile/qmlmanager.h
@@ -22,6 +22,8 @@ public:
public slots:
void savePreferences();
void loadDives();
+ void commitChanges(QString diveId, QString suit, QString buddy, QString diveMaster, QString notes);
+ void saveChanges();
private:
QString m_cloudUserName;
QString m_cloudPassword;
diff --git a/qt-mobile/qmlprofile.cpp b/qt-mobile/qmlprofile.cpp
new file mode 100644
index 000000000..351b5b1ce
--- /dev/null
+++ b/qt-mobile/qmlprofile.cpp
@@ -0,0 +1,43 @@
+#include "qmlprofile.h"
+#include "profilewidget2.h"
+#include "dive.h"
+
+QMLProfile::QMLProfile(QQuickItem *parent) :
+ QQuickPaintedItem(parent)
+{
+ profile = new ProfileWidget2(0);
+ profile->setProfileState();
+ profile->setToolTipVisibile(false);
+}
+
+void QMLProfile::paint(QPainter *painter)
+{
+ if (m_diveId.toInt() < 1)
+ return;
+
+ struct dive *d;
+ d = get_dive_by_uniq_id(m_diveId.toInt());
+ if (!d)
+ return;
+
+ int old_animation_speed = prefs.animation_speed;
+ prefs.animation_speed = 0; // no animations while rendering the QGraphicsView
+ profile->plotDive(d);
+ // we need to show the widget so it gets populated, but then
+ // hide it right away so we get to draw it ourselves below
+ profile->show();
+ profile->hide();
+ profile->resize(this->width(), this->height());
+ profile->render(painter, profile->geometry());
+ prefs.animation_speed = old_animation_speed;
+}
+
+QString QMLProfile::diveId() const
+{
+ return m_diveId;
+}
+
+void QMLProfile::setDiveId(const QString &diveId)
+{
+ m_diveId = diveId;
+}
diff --git a/qt-mobile/qmlprofile.h b/qt-mobile/qmlprofile.h
new file mode 100644
index 000000000..b5192913a
--- /dev/null
+++ b/qt-mobile/qmlprofile.h
@@ -0,0 +1,27 @@
+#ifndef QMLPROFILE_H
+#define QMLPROFILE_H
+
+#include <QQuickPaintedItem>
+
+class ProfileWidget2;
+
+class QMLProfile : public QQuickPaintedItem
+{
+ Q_OBJECT
+ Q_PROPERTY(QString diveId READ diveId WRITE setDiveId NOTIFY diveIdChanged)
+public:
+ explicit QMLProfile(QQuickItem *parent = 0);
+ void paint(QPainter *painter);
+
+ QString diveId() const;
+ void setDiveId(const QString &diveId);
+
+private:
+ QString m_diveId;
+ ProfileWidget2 *profile;
+signals:
+ void rightAlignedChanged();
+ void diveIdChanged();
+};
+
+#endif // QMLPROFILE_H
diff --git a/qt-models/divelistmodel.cpp b/qt-models/divelistmodel.cpp
index 0fb1cbbf9..8bb895fc8 100644
--- a/qt-models/divelistmodel.cpp
+++ b/qt-models/divelistmodel.cpp
@@ -5,6 +5,7 @@ MobileDive::MobileDive(dive *d)
{
m_thisDive = d;
setDiveNumber(QString::number(d->number));
+ setDiveId(QString::number(d->id));
dive_trip *trip = d->divetrip;
@@ -216,6 +217,16 @@ void MobileDive::setupDiveTempDetails()
setWatertemp(get_temperature_string(m_thisDive->watertemp, true));
setAirTemp(get_temperature_string(m_thisDive->airtemp, true));
}
+QString MobileDive::diveId() const
+{
+ return m_diveId;
+}
+
+void MobileDive::setDiveId(const QString &diveId)
+{
+ m_diveId = diveId;
+}
+
@@ -283,6 +294,8 @@ QVariant DiveListModel::data(const QModelIndex &index, int role) const
return dive.buddy();
else if (role == DiveMasterRole)
return dive.divemaster();
+ else if (role == DiveIdRole)
+ return dive.diveId();
return QVariant();
@@ -308,6 +321,7 @@ QHash<int, QByteArray> DiveListModel::roleNames() const
roles[DiveNotesRole] = "notes";
roles[DiveBuddyRole] = "buddy";
roles[DiveMasterRole] = "divemaster";
+ roles[DiveIdRole] = "id";
return roles;
}
diff --git a/qt-models/divelistmodel.h b/qt-models/divelistmodel.h
index 68f0c6fa7..89f793bbc 100644
--- a/qt-models/divelistmodel.h
+++ b/qt-models/divelistmodel.h
@@ -62,6 +62,9 @@ public:
QString watertemp() const;
void setWatertemp(const QString &watertemp);
+ QString diveId() const;
+ void setDiveId(const QString &diveId);
+
private:
void setupDiveTempDetails();
@@ -82,6 +85,7 @@ private:
QString m_notes;
QString m_buddy;
QString m_divemaster;
+ QString m_diveId;
dive *m_thisDive;
@@ -109,7 +113,8 @@ public:
DiveLocationRole,
DiveNotesRole,
DiveBuddyRole,
- DiveMasterRole
+ DiveMasterRole,
+ DiveIdRole
};
static DiveListModel *instance();