mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
Merge branch 'devel' of https://github.com/gracie89/subsurface
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
commit
d595f5c167
10 changed files with 167 additions and 4 deletions
|
@ -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)
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -54,6 +54,14 @@ ApplicationWindow {
|
|||
manager.loadDives();
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
id: saveChanges
|
||||
text: "Save Changes"
|
||||
onClicked: {
|
||||
manager.saveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -69,6 +69,52 @@ void QMLManager::loadDives()
|
|||
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
|
||||
{
|
||||
return m_cloudPassword;
|
||||
|
|
|
@ -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;
|
||||
|
|
43
qt-mobile/qmlprofile.cpp
Normal file
43
qt-mobile/qmlprofile.cpp
Normal file
|
@ -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;
|
||||
}
|
27
qt-mobile/qmlprofile.h
Normal file
27
qt-mobile/qmlprofile.h
Normal file
|
@ -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
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue