aboutsummaryrefslogtreecommitdiffstats
path: root/qt-models/divelistmodel.cpp
blob: 4019bee8b1e871a68ed4b8d08e2a3ad025e6f046 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
#include "divelistmodel.h"
#include "helpers.h"

MobileDive::MobileDive(dive *d)
{
	m_thisDive = d;
	setDiveNumber(QString::number(d->number));
	setDiveId(QString::number(d->id));

	dive_trip *trip = d->divetrip;

	if(trip) {
		//trip is valid
		setTrip(trip->location);
	}
	setDate(d->when);
	setDateString(get_dive_date_string(d->when));
	setDepth(get_depth_string(d->maxdepth));
	setDuration(get_dive_duration_string(d->duration.seconds, "h:","min"));

	setupDiveTempDetails();

	weight_t tw = { total_weight(d) };
	setWeight(weight_string(tw.grams));

	setSuit(QString(d->suit));
	setCylinder(QString(d->cylinder[0].type.description));
	setSac(QString::number(d->sac));
	setLocation(get_dive_location(d));
	setNotes(d->notes);
	setBuddy(d->buddy);
	setDivemaster(d->divemaster);
}

QString MobileDive::dateString() const
{
	return m_dateString;
}

void MobileDive::setDateString(const QString &date)
{
	m_dateString = date;
}

timestamp_t MobileDive::date() const
{
	return m_date;
}

void MobileDive::setDate(timestamp_t when)
{
	m_date = when;
}

QString MobileDive::location() const
{
	return m_location;
}

void MobileDive::setLocation(const QString &location)
{
	m_location = location;
}

QString MobileDive::sac() const
{
	return m_sac;
}

void MobileDive::setSac(const QString &sac)
{
	m_sac = sac;
}

QString MobileDive::gas() const
{
	return m_gas;
}

void MobileDive::setGas(const QString &gas)
{
	m_gas = gas;
}

QString MobileDive::cylinder() const
{
	return m_cylinder;
}

void MobileDive::setCylinder(const QString &cylinder)
{
	m_cylinder = cylinder;
}

QString MobileDive::suit() const
{
	return m_suit;
}

void MobileDive::setSuit(const QString &suit)
{
	m_suit = suit;
}

QString MobileDive::weight() const
{
	return m_weight;
}

void MobileDive::setWeight(const QString &weight)
{
	m_weight = weight;
}

QString MobileDive::airtemp() const
{
	return m_airtemp;
}

void MobileDive::setAirTemp(const QString &airtemp)
{
	m_airtemp = airtemp;
}

QString MobileDive::duration() const
{
	return m_duration;
}

void MobileDive::setDuration(const QString &duration)
{
	m_duration = duration;
}

QString MobileDive::depth() const
{
	return m_depth;
}

void MobileDive::setDepth(const QString &depth)
{
	m_depth = depth;
}

QString MobileDive::rating() const
{
	return m_rating;
}

void MobileDive::setRating(const QString &rating)
{
	m_rating = rating;
}

dive *MobileDive::thisDive() const
{
	return m_thisDive;
}

void MobileDive::setThisDive(dive *thisDive)
{
	m_thisDive = thisDive;
}

QString MobileDive::diveNumber() const
{
	return m_diveNumber;
}

void MobileDive::setDiveNumber(const QString &diveNumber)
{
	m_diveNumber = diveNumber;
}

QString MobileDive::notes() const
{
	return m_notes;
}

void MobileDive::setNotes(const QString &notes)
{
	m_notes = notes;
}

QString MobileDive::trip() const
{
	return m_trip;
}

void MobileDive::setTrip(const QString &trip)
{
	m_trip = trip;
}

QString MobileDive::buddy() const
{
	return m_buddy;
}

void MobileDive::setBuddy(const QString &buddy)
{
	m_buddy = buddy;
}

QString MobileDive::divemaster() const
{
	return m_divemaster;
}

void MobileDive::setDivemaster(const QString &divemaster)
{
	m_divemaster = divemaster;
}

QString MobileDive::watertemp() const
{
	return m_watertemp;
}

void MobileDive::setWatertemp(const QString &watertemp)
{
	m_watertemp = watertemp;
}

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;
}








DiveListModel *DiveListModel::m_instance = NULL;

DiveListModel::DiveListModel(QObject *parent) : QAbstractListModel(parent)
{
	m_instance = this;
}

void DiveListModel::addDive(dive *d)
{
	beginInsertRows(QModelIndex(), rowCount(), rowCount());
	m_dives.append(MobileDive(d));
	endInsertRows();
}

int DiveListModel::rowCount(const QModelIndex &) const
{
	return m_dives.count();
}

QVariant DiveListModel::data(const QModelIndex &index, int role) const
{
	if(index.row() < 0 || index.row() > m_dives.count())
		return QVariant();

	const MobileDive &dive = m_dives[index.row()];

	if (role == DiveNumberRole)
		return dive.diveNumber();
	else if (role == DiveTripRole)
		return dive.trip();
	else if (role == DiveDateRole)
		return (qlonglong)dive.date();
	else if (role == DiveDateStringRole)
		return dive.dateString();
	else if (role == DiveRatingRole)
		return dive.rating();
	else if (role == DiveDepthRole)
		return dive.depth();
	else if (role == DiveDurationRole)
		return dive.duration();
	else if (role == DiveAirTemperatureRole)
		return dive.airtemp();
	else if (role == DiveWaterTemperatureRole)
		return dive.watertemp();
	else if (role == DiveWeightRole)
		return dive.weight();
	else if (role == DiveSuitRole)
		return dive.suit();
	else if (role == DiveCylinderRole)
		return dive.cylinder();
	else if (role == DiveGasRole)
		return dive.gas();
	else if (role == DiveSacRole)
		return dive.sac();
	else if (role == DiveLocationRole)
		return dive.location();
	else if (role == DiveNotesRole)
		return dive.notes();
	else if (role == DiveBuddyRole)
		return dive.buddy();
	else if (role == DiveMasterRole)
		return dive.divemaster();
	else if (role == DiveIdRole)
		return dive.diveId();
	return QVariant();


}

QHash<int, QByteArray> DiveListModel::roleNames() const
{
	QHash<int, QByteArray> roles;
	roles[DiveNumberRole] = "diveNumber";
	roles[DiveTripRole] = "trip";
	roles[DiveDateStringRole] = "date";
	roles[DiveRatingRole] = "rating";
	roles[DiveDepthRole] = "depth";
	roles[DiveDurationRole] = "duration";
	roles[DiveAirTemperatureRole] = "airtemp";
	roles[DiveWaterTemperatureRole] = "watertemp";
	roles[DiveWeightRole] = "weight";
	roles[DiveSuitRole] = "suit";
	roles[DiveCylinderRole] = "cylinder";
	roles[DiveGasRole] = "gas";
	roles[DiveSacRole] = "sac";
	roles[DiveLocationRole] = "location";
	roles[DiveNotesRole] = "notes";
	roles[DiveBuddyRole] = "buddy";
	roles[DiveMasterRole] = "divemaster";
	roles[DiveIdRole] = "id";

	return roles;
}

DiveListModel *DiveListModel::instance()
{
	return m_instance;
}