Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2015-07-17 11:57:21 -07:00
commit d595f5c167
10 changed files with 167 additions and 4 deletions

View file

@ -458,7 +458,7 @@ endif()
# create the executables # create the executables
if(SUBSURFACE_MOBILE) 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) add_definitions(-DSUBSURFACE_MOBILE)
qt5_add_resources(MOBILE_RESOURCES qt-mobile/mobile-resources.qrc) qt5_add_resources(MOBILE_RESOURCES qt-mobile/mobile-resources.qrc)
if(ANDROID) if(ANDROID)

View file

@ -19,6 +19,7 @@
#include <QQmlContext> #include <QQmlContext>
#include "qt-mobile/qmlmanager.h" #include "qt-mobile/qmlmanager.h"
#include "qt-models/divelistmodel.h" #include "qt-models/divelistmodel.h"
#include "qt-mobile/qmlprofile.h"
QObject *qqWindowObject = NULL; QObject *qqWindowObject = NULL;
#endif #endif
@ -40,6 +41,7 @@ void run_ui()
#ifdef SUBSURFACE_MOBILE #ifdef SUBSURFACE_MOBILE
window->hide(); window->hide();
qmlRegisterType<QMLManager>("org.subsurfacedivelog.mobile", 1, 0, "QMLManager"); qmlRegisterType<QMLManager>("org.subsurfacedivelog.mobile", 1, 0, "QMLManager");
qmlRegisterType<QMLProfile>("org.subsurfacedivelog.mobile", 1, 0, "QMLProfile");
QQmlApplicationEngine engine; QQmlApplicationEngine engine;
DiveListModel diveListModel; DiveListModel diveListModel;
QQmlContext *ctxt = engine.rootContext(); QQmlContext *ctxt = engine.rootContext();

View file

@ -77,6 +77,13 @@ Rectangle {
id: editorDetails id: editorDetails
width: detailsPage.width width: detailsPage.width
columns: 2 columns: 2
Text { }
QMLProfile {
diveId: id
height: 400
Layout.fillWidth: true
}
Text { text: "Location:"; font.bold: true } Text { text: "Location:"; font.bold: true }
TextField { id: txtLocation; text: location; Layout.fillWidth: true } TextField { id: txtLocation; text: location; Layout.fillWidth: true }
Text { text: "Air Temp:"; font.bold: true } Text { text: "Air Temp:"; font.bold: true }
@ -109,7 +116,16 @@ Rectangle {
opacity: dive.detailsOpacity opacity: dive.detailsOpacity
text: "Close" text: "Close"
onClicked: dive.state = ''; onClicked: {
manager.commitChanges(
id,
txtSuit.text,
txtBuddy.text,
txtDiveMaster.text,
txtNotes.text
)
dive.state = '';
}
} }
states: State { states: State {

View file

@ -54,6 +54,14 @@ ApplicationWindow {
manager.loadDives(); manager.loadDives();
} }
} }
Button {
id: saveChanges
text: "Save Changes"
onClicked: {
manager.saveChanges();
}
}
} }
} }

View file

@ -66,7 +66,53 @@ void QMLManager::loadDives()
struct dive *d; struct dive *d;
for_each_dive(i, 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 QString QMLManager::cloudPassword() const

View file

@ -22,6 +22,8 @@ public:
public slots: public slots:
void savePreferences(); void savePreferences();
void loadDives(); void loadDives();
void commitChanges(QString diveId, QString suit, QString buddy, QString diveMaster, QString notes);
void saveChanges();
private: private:
QString m_cloudUserName; QString m_cloudUserName;
QString m_cloudPassword; QString m_cloudPassword;

43
qt-mobile/qmlprofile.cpp Normal file
View 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
View 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

View file

@ -5,6 +5,7 @@ MobileDive::MobileDive(dive *d)
{ {
m_thisDive = d; m_thisDive = d;
setDiveNumber(QString::number(d->number)); setDiveNumber(QString::number(d->number));
setDiveId(QString::number(d->id));
dive_trip *trip = d->divetrip; dive_trip *trip = d->divetrip;
@ -216,6 +217,16 @@ void MobileDive::setupDiveTempDetails()
setWatertemp(get_temperature_string(m_thisDive->watertemp, true)); setWatertemp(get_temperature_string(m_thisDive->watertemp, true));
setAirTemp(get_temperature_string(m_thisDive->airtemp, 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(); return dive.buddy();
else if (role == DiveMasterRole) else if (role == DiveMasterRole)
return dive.divemaster(); return dive.divemaster();
else if (role == DiveIdRole)
return dive.diveId();
return QVariant(); return QVariant();
@ -308,6 +321,7 @@ QHash<int, QByteArray> DiveListModel::roleNames() const
roles[DiveNotesRole] = "notes"; roles[DiveNotesRole] = "notes";
roles[DiveBuddyRole] = "buddy"; roles[DiveBuddyRole] = "buddy";
roles[DiveMasterRole] = "divemaster"; roles[DiveMasterRole] = "divemaster";
roles[DiveIdRole] = "id";
return roles; return roles;
} }

View file

@ -62,6 +62,9 @@ public:
QString watertemp() const; QString watertemp() const;
void setWatertemp(const QString &watertemp); void setWatertemp(const QString &watertemp);
QString diveId() const;
void setDiveId(const QString &diveId);
private: private:
void setupDiveTempDetails(); void setupDiveTempDetails();
@ -82,6 +85,7 @@ private:
QString m_notes; QString m_notes;
QString m_buddy; QString m_buddy;
QString m_divemaster; QString m_divemaster;
QString m_diveId;
dive *m_thisDive; dive *m_thisDive;
@ -109,7 +113,8 @@ public:
DiveLocationRole, DiveLocationRole,
DiveNotesRole, DiveNotesRole,
DiveBuddyRole, DiveBuddyRole,
DiveMasterRole DiveMasterRole,
DiveIdRole
}; };
static DiveListModel *instance(); static DiveListModel *instance();