From ee9452ae8ace9e5ec6b6c99ebb01ec3748e1bfaa Mon Sep 17 00:00:00 2001
From: Grace Karanja <gracie.karanja89@gmail.com>
Date: Thu, 11 Jun 2015 09:39:32 +0300
Subject: Group dives by trips

Group dives according to the allocated dive trips.

Signed-off-by: Grace Karanja <gracie.karanja89@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
---
 qt-models/divelistmodel.cpp | 21 +++++++++++++++++++++
 qt-models/divelistmodel.h   |  5 +++++
 2 files changed, 26 insertions(+)

(limited to 'qt-models')

diff --git a/qt-models/divelistmodel.cpp b/qt-models/divelistmodel.cpp
index c1862b829..ad360965f 100644
--- a/qt-models/divelistmodel.cpp
+++ b/qt-models/divelistmodel.cpp
@@ -5,6 +5,14 @@ Dive::Dive(dive *d)
 {
 	m_thisDive = d;
 	setDiveNumber(QString::number(d->number));
+
+	dive_trip *trip = d->divetrip;
+
+	if(trip) {
+		//trip is valid
+		setTrip(trip->location);
+	}
+
 	setDate(get_dive_date_string(d->when));
 	setDepth(get_depth_string(d->maxdepth));
 	setDuration(get_dive_duration_string(d->duration.seconds, "h:","min"));
@@ -153,6 +161,16 @@ void Dive::setNotes(const QString &notes)
 {
 	m_notes = notes;
 }
+QString Dive::trip() const
+{
+	return m_trip;
+}
+
+void Dive::setTrip(const QString &trip)
+{
+	m_trip = trip;
+}
+
 
 
 
@@ -184,6 +202,8 @@ QVariant DiveListModel::data(const QModelIndex &index, int role) const
 
 	if (role == DiveNumberRole)
 		return dive.diveNumber();
+	else if (role == DiveTripRole)
+		return dive.trip();
 	else if (role == DiveDateRole)
 		return dive.date();
 	else if (role == DiveRatingRole)
@@ -217,6 +237,7 @@ QHash<int, QByteArray> DiveListModel::roleNames() const
 {
 	QHash<int, QByteArray> roles;
 	roles[DiveNumberRole] = "diveNumber";
+	roles[DiveTripRole] = "trip";
 	roles[DiveDateRole] = "date";
 	roles[DiveRatingRole] = "rating";
 	roles[DiveDepthRole] = "depth";
diff --git a/qt-models/divelistmodel.h b/qt-models/divelistmodel.h
index 307008cc1..f58040508 100644
--- a/qt-models/divelistmodel.h
+++ b/qt-models/divelistmodel.h
@@ -50,8 +50,12 @@ public:
 	QString notes() const;
 	void setNotes(const QString &notes);
 
+	QString trip() const;
+	void setTrip(const QString &trip);
+
 private:
 	QString m_diveNumber;
+	QString m_trip;
 	QString m_date;
 	QString m_rating;
 	QString m_depth;
@@ -76,6 +80,7 @@ public:
 
 	enum DiveListRoles {
 		DiveNumberRole = Qt::UserRole + 1,
+		DiveTripRole,
 		DiveDateRole,
 		DiveRatingRole,
 		DiveDepthRole,
-- 
cgit v1.2.3-70-g09d2