| 
									
										
										
										
											2017-04-27 20:24:53 +02:00
										 |  |  | // SPDX-License-Identifier: GPL-2.0
 | 
					
						
							| 
									
										
										
										
											2016-01-07 16:01:24 -02:00
										 |  |  | #include "DiveObjectHelper.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <QDateTime>
 | 
					
						
							|  |  |  | #include <QTextDocument>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-11 08:25:41 -07:00
										 |  |  | #include "core/qthelper.h"
 | 
					
						
							| 
									
										
										
										
											2019-03-04 23:20:29 +01:00
										 |  |  | #include "core/divesite.h"
 | 
					
						
							| 
									
										
										
										
											2019-05-31 16:09:14 +02:00
										 |  |  | #include "core/trip.h"
 | 
					
						
							| 
									
										
										
										
											2018-05-11 08:25:41 -07:00
										 |  |  | #include "core/subsurface-string.h"
 | 
					
						
							|  |  |  | #include "qt-models/tankinfomodel.h"
 | 
					
						
							| 
									
										
										
										
											2016-01-07 16:01:24 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-09 17:19:06 +01:00
										 |  |  | enum returnPressureSelector {START_PRESSURE, END_PRESSURE}; | 
					
						
							| 
									
										
										
										
											2016-01-07 16:01:24 -02:00
										 |  |  | 
 | 
					
						
							|  |  |  | static QString getFormattedWeight(struct dive *dive, unsigned int idx) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-01-11 06:14:45 -08:00
										 |  |  | 	weightsystem_t *weight = &dive->weightsystem[idx]; | 
					
						
							|  |  |  | 	if (!weight->description) | 
					
						
							| 
									
										
										
										
											2018-11-24 08:40:30 +01:00
										 |  |  | 		return QString(); | 
					
						
							| 
									
										
										
										
											2016-01-11 06:14:45 -08:00
										 |  |  | 	QString fmt = QString(weight->description); | 
					
						
							|  |  |  | 	fmt += ", " + get_weight_string(weight->weight, true); | 
					
						
							|  |  |  | 	return fmt; | 
					
						
							| 
									
										
										
										
											2016-01-07 16:01:24 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static QString getFormattedCylinder(struct dive *dive, unsigned int idx) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-01-11 06:14:45 -08:00
										 |  |  | 	cylinder_t *cyl = &dive->cylinder[idx]; | 
					
						
							|  |  |  | 	const char *desc = cyl->type.description; | 
					
						
							|  |  |  | 	if (!desc && idx > 0) | 
					
						
							| 
									
										
										
										
											2018-11-24 08:40:30 +01:00
										 |  |  | 		return QString(); | 
					
						
							| 
									
										
										
										
											2018-07-03 16:52:20 +02:00
										 |  |  | 	QString fmt = desc ? QString(desc) : gettextFromC::tr("unknown"); | 
					
						
							| 
									
										
											  
											
												Don't use "get_volume_string()" for cylinder size string
We had two totally different usage cases for "get_volume_string()": one
that did the obvious "show this volume as a string", and one that tried
to show a cylinder size.
The function used a magic third argument (the working pressure of the
cylinder) to distinguish between the two cases, but it still got it
wrong.
A metric cylinder doesn't necessarily have a working pressure at all,
and the size is a wet size in liters.  We'd pass in zero as the working
pressure, and if the volume units were set to cubic feet, the logic in
"get_volume_string()" would happily convert the metric wet size into the
wet size in cubic feet.
But that's completely wrong.  An imperial cylinder size simply isn't a
wet size.  If you don't have a working pressure, you cannot convert the
cylinder size to cubic feet.  End of story.
So instead of having "get_volume_string()" have magical behavior
depending on working pressure, and getting it wrong anyway, just make
get_volume_string do a pure volume conversion, and create a whole new
function for showing the size of a cylinder.
Now, if the cylinder doesn't have a working pressure, we just show the
metric size, even if the user had asked for cubic feet.
[Dirk Hohndel: added call to translation functions for the units]
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
											
										 
											2016-02-24 14:42:56 -08:00
										 |  |  | 	fmt += ", " + get_volume_string(cyl->type.size, true); | 
					
						
							| 
									
										
										
										
											2016-01-11 06:14:45 -08:00
										 |  |  | 	fmt += ", " + get_pressure_string(cyl->type.workingpressure, true); | 
					
						
							|  |  |  | 	fmt += ", " + get_pressure_string(cyl->start, false) + " - " + get_pressure_string(cyl->end, true); | 
					
						
							|  |  |  | 	fmt += ", " + get_gas_string(cyl->gasmix); | 
					
						
							|  |  |  | 	return fmt; | 
					
						
							| 
									
										
										
										
											2016-01-07 16:01:24 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-17 11:49:42 +02:00
										 |  |  | static QString getPressures(struct dive *dive, int i, enum returnPressureSelector ret) | 
					
						
							| 
									
										
										
										
											2016-02-09 17:19:06 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-17 11:49:42 +02:00
										 |  |  | 	cylinder_t *cyl = &dive->cylinder[i]; | 
					
						
							| 
									
										
										
										
											2016-02-09 17:19:06 +01:00
										 |  |  | 	QString fmt; | 
					
						
							| 
									
										
										
										
											2016-03-03 13:16:12 -08:00
										 |  |  | 	if (ret == START_PRESSURE) { | 
					
						
							| 
									
										
										
										
											2016-02-14 17:33:18 +02:00
										 |  |  | 		if (cyl->start.mbar) | 
					
						
							|  |  |  | 			fmt = get_pressure_string(cyl->start, true); | 
					
						
							|  |  |  | 		else if (cyl->sample_start.mbar) | 
					
						
							|  |  |  | 			fmt = get_pressure_string(cyl->sample_start, true); | 
					
						
							| 
									
										
										
										
											2016-03-03 13:16:12 -08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	if (ret == END_PRESSURE) { | 
					
						
							| 
									
										
										
										
											2016-02-14 17:33:18 +02:00
										 |  |  | 		if (cyl->end.mbar) | 
					
						
							|  |  |  | 			fmt = get_pressure_string(cyl->end, true); | 
					
						
							|  |  |  | 		else if(cyl->sample_end.mbar) | 
					
						
							|  |  |  | 			fmt = get_pressure_string(cyl->sample_end, true); | 
					
						
							| 
									
										
										
										
											2016-03-03 13:16:12 -08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-02-09 17:19:06 +01:00
										 |  |  | 	return fmt; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-11 15:02:13 -02:00
										 |  |  | DiveObjectHelper::DiveObjectHelper(struct dive *d) : | 
					
						
							| 
									
										
										
										
											2016-01-07 16:01:24 -02:00
										 |  |  | 	m_dive(d) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-07-31 22:27:07 +01:00
										 |  |  | 	m_cyls.clear(); | 
					
						
							|  |  |  | 	for (int i = 0; i < MAX_CYLINDERS; i++) { | 
					
						
							|  |  |  | 		//Don't add blank cylinders, only those that have been defined.
 | 
					
						
							|  |  |  | 		if (m_dive->cylinder[i].type.description) | 
					
						
							|  |  |  | 			m_cyls.append(new CylinderObjectHelper(&m_dive->cylinder[i])); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-01-07 16:01:24 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | DiveObjectHelper::~DiveObjectHelper() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-07-31 22:27:07 +01:00
										 |  |  | while (!m_cyls.isEmpty()) | 
					
						
							| 
									
										
										
										
											2016-09-04 10:27:56 -07:00
										 |  |  | 	delete m_cyls.takeFirst(); | 
					
						
							| 
									
										
										
										
											2016-01-07 16:01:24 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int DiveObjectHelper::number() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-01-11 15:02:13 -02:00
										 |  |  | 	return m_dive->number; | 
					
						
							| 
									
										
										
										
											2016-01-07 16:01:24 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int DiveObjectHelper::id() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-01-11 15:04:21 -02:00
										 |  |  | 	return m_dive->id; | 
					
						
							| 
									
										
										
										
											2016-01-07 16:01:24 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-24 21:14:33 +01:00
										 |  |  | struct dive *DiveObjectHelper::getDive() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return m_dive; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-07 16:01:24 -02:00
										 |  |  | QString DiveObjectHelper::date() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-04-28 16:31:37 -07:00
										 |  |  | 	QDateTime localTime = QDateTime::fromMSecsSinceEpoch(1000*m_dive->when, Qt::UTC); | 
					
						
							| 
									
										
										
										
											2016-01-11 16:40:10 -02:00
										 |  |  | 	localTime.setTimeSpec(Qt::UTC); | 
					
						
							| 
									
										
										
										
											2017-06-18 17:48:04 -07:00
										 |  |  | 	return localTime.date().toString(prefs.date_format_short); | 
					
						
							| 
									
										
										
										
											2016-01-07 16:01:24 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | timestamp_t DiveObjectHelper::timestamp() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-01-11 15:34:53 -02:00
										 |  |  | 	return m_dive->when; | 
					
						
							| 
									
										
										
										
											2016-01-07 16:01:24 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QString DiveObjectHelper::time() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-04-28 16:31:37 -07:00
										 |  |  | 	QDateTime localTime = QDateTime::fromMSecsSinceEpoch(1000*m_dive->when, Qt::UTC); | 
					
						
							| 
									
										
										
										
											2016-01-11 16:40:10 -02:00
										 |  |  | 	localTime.setTimeSpec(Qt::UTC); | 
					
						
							|  |  |  | 	return localTime.time().toString(prefs.time_format); | 
					
						
							| 
									
										
										
										
											2016-01-07 16:01:24 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QString DiveObjectHelper::location() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-24 08:40:30 +01:00
										 |  |  | 	return get_dive_location(m_dive) ? QString::fromUtf8(get_dive_location(m_dive)) : QString(); | 
					
						
							| 
									
										
										
										
											2016-01-07 16:01:24 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QString DiveObjectHelper::gps() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-10-26 17:03:54 +02:00
										 |  |  | 	struct dive_site *ds = m_dive->dive_site; | 
					
						
							| 
									
										
										
										
											2019-03-24 21:50:01 +01:00
										 |  |  | 	if (!ds) | 
					
						
							|  |  |  | 		return QString(); | 
					
						
							| 
									
										
										
										
											2019-03-25 09:05:47 +01:00
										 |  |  | 	return printGPSCoords(&ds->location); | 
					
						
							| 
									
										
										
										
											2016-01-07 16:01:24 -02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-03-21 17:52:29 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | QString DiveObjectHelper::gps_decimal() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	bool savep = prefs.coordinates_traditional; | 
					
						
							|  |  |  | 	QString val; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	prefs.coordinates_traditional = false; | 
					
						
							|  |  |  | 	val = gps(); | 
					
						
							|  |  |  | 	prefs.coordinates_traditional = savep; | 
					
						
							| 
									
										
										
										
											2018-02-17 21:21:16 +01:00
										 |  |  | 	return val; | 
					
						
							| 
									
										
										
										
											2017-03-21 17:52:29 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-25 20:46:12 +02:00
										 |  |  | QVariant DiveObjectHelper::dive_site() const | 
					
						
							| 
									
										
										
										
											2018-03-08 21:18:31 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-10-28 22:19:17 +01:00
										 |  |  | 	return QVariant::fromValue(m_dive->dive_site); | 
					
						
							| 
									
										
										
										
											2018-03-08 21:18:31 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-07 16:01:24 -02:00
										 |  |  | QString DiveObjectHelper::duration() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-03 16:52:20 +02:00
										 |  |  | 	return get_dive_duration_string(m_dive->duration.seconds, gettextFromC::tr("h"), gettextFromC::tr("min")); | 
					
						
							| 
									
										
										
										
											2016-01-07 16:01:24 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-14 16:26:37 -08:00
										 |  |  | bool DiveObjectHelper::noDive() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return m_dive->duration.seconds == 0 && m_dive->dc.duration.seconds == 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-07 16:01:24 -02:00
										 |  |  | QString DiveObjectHelper::depth() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-01-11 15:36:12 -02:00
										 |  |  | 	return get_depth_string(m_dive->dc.maxdepth.mm, true, true); | 
					
						
							| 
									
										
										
										
											2016-01-07 16:01:24 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QString DiveObjectHelper::divemaster() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-24 08:40:30 +01:00
										 |  |  | 	return m_dive->divemaster ? m_dive->divemaster : QString(); | 
					
						
							| 
									
										
										
										
											2016-01-07 16:01:24 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QString DiveObjectHelper::buddy() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-24 08:40:30 +01:00
										 |  |  | 	return m_dive->buddy ? m_dive->buddy : QString(); | 
					
						
							| 
									
										
										
										
											2016-01-07 16:01:24 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QString DiveObjectHelper::airTemp() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-24 08:40:30 +01:00
										 |  |  | 	return get_temperature_string(m_dive->airtemp, true); | 
					
						
							| 
									
										
										
										
											2016-01-07 16:01:24 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QString DiveObjectHelper::waterTemp() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-24 08:40:30 +01:00
										 |  |  | 	return get_temperature_string(m_dive->watertemp, true); | 
					
						
							| 
									
										
										
										
											2016-01-07 16:01:24 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QString DiveObjectHelper::notes() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-24 08:40:30 +01:00
										 |  |  | 	QString tmp = m_dive->notes ? QString::fromUtf8(m_dive->notes) : QString(); | 
					
						
							| 
									
										
										
										
											2019-01-01 18:02:04 +01:00
										 |  |  | 	if (is_dc_planner(&m_dive->dc)) { | 
					
						
							| 
									
										
										
										
											2016-01-11 16:04:46 -02:00
										 |  |  | 		QTextDocument notes; | 
					
						
							|  |  |  | 	#define _NOTES_BR "\n"
 | 
					
						
							|  |  |  | 		tmp.replace("<thead>", "<thead>" _NOTES_BR) | 
					
						
							|  |  |  | 			.replace("<br>", "<br>" _NOTES_BR) | 
					
						
							|  |  |  | 			.replace("<tr>", "<tr>" _NOTES_BR) | 
					
						
							|  |  |  | 			.replace("</tr>", "</tr>" _NOTES_BR); | 
					
						
							|  |  |  | 		notes.setHtml(tmp); | 
					
						
							|  |  |  | 		tmp = notes.toPlainText(); | 
					
						
							|  |  |  | 		tmp.replace(_NOTES_BR, "<br>"); | 
					
						
							|  |  |  | 	#undef _NOTES_BR
 | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		tmp.replace("\n", "<br>"); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return tmp; | 
					
						
							| 
									
										
										
										
											2016-01-07 16:01:24 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QString DiveObjectHelper::tags() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-04-09 10:09:34 +02:00
										 |  |  | 	return get_taglist_string(m_dive->tag_list); | 
					
						
							| 
									
										
										
										
											2016-01-07 16:01:24 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QString DiveObjectHelper::gas() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-01-11 16:37:10 -02:00
										 |  |  | 	/*WARNING: here should be the gastlist, returned
 | 
					
						
							|  |  |  | 	 * from the get_gas_string function or this is correct? | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	QString gas, gases; | 
					
						
							|  |  |  | 	for (int i = 0; i < MAX_CYLINDERS; i++) { | 
					
						
							| 
									
										
										
										
											2017-02-03 07:31:03 -08:00
										 |  |  | 		if (!is_cylinder_used(m_dive, i)) | 
					
						
							| 
									
										
										
										
											2016-01-11 16:37:10 -02:00
										 |  |  | 			continue; | 
					
						
							|  |  |  | 		gas = m_dive->cylinder[i].type.description; | 
					
						
							|  |  |  | 		if (!gas.isEmpty()) | 
					
						
							|  |  |  | 			gas += QChar(' '); | 
					
						
							| 
									
										
										
										
											2018-08-16 19:10:10 +02:00
										 |  |  | 		gas += gasname(m_dive->cylinder[i].gasmix); | 
					
						
							| 
									
										
										
										
											2016-01-11 16:37:10 -02:00
										 |  |  | 		// if has a description and if such gas is not already present
 | 
					
						
							|  |  |  | 		if (!gas.isEmpty() && gases.indexOf(gas) == -1) { | 
					
						
							|  |  |  | 			if (!gases.isEmpty()) | 
					
						
							|  |  |  | 				gases += QString(" / "); | 
					
						
							|  |  |  | 			gases += gas; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return gases; | 
					
						
							| 
									
										
										
										
											2016-01-07 16:01:24 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QString DiveObjectHelper::sac() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-01-11 16:16:48 -02:00
										 |  |  | 	if (!m_dive->sac) | 
					
						
							|  |  |  | 		return QString(); | 
					
						
							|  |  |  | 	const char *unit; | 
					
						
							|  |  |  | 	int decimal; | 
					
						
							|  |  |  | 	double value = get_volume_units(m_dive->sac, &decimal, &unit); | 
					
						
							| 
									
										
										
										
											2016-01-21 12:41:40 -08:00
										 |  |  | 	return QString::number(value, 'f', decimal).append(unit); | 
					
						
							| 
									
										
										
										
											2016-01-07 16:01:24 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-29 16:42:07 +02:00
										 |  |  | QString DiveObjectHelper::weightList() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QString weights; | 
					
						
							|  |  |  | 	for (int i = 0; i < MAX_WEIGHTSYSTEMS; i++) { | 
					
						
							|  |  |  | 		QString w = getFormattedWeight(m_dive, i); | 
					
						
							| 
									
										
										
										
											2018-11-24 08:40:30 +01:00
										 |  |  | 		if (w.isEmpty()) | 
					
						
							| 
									
										
										
										
											2016-02-29 16:42:07 +02:00
										 |  |  | 			continue; | 
					
						
							|  |  |  | 		weights += w + "; "; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return weights; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-07 16:01:24 -02:00
										 |  |  | QStringList DiveObjectHelper::weights() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-01-11 16:48:46 -02:00
										 |  |  | 	QStringList weights; | 
					
						
							| 
									
										
										
										
											2016-07-19 06:55:21 +01:00
										 |  |  | 	for (int i = 0; i < MAX_WEIGHTSYSTEMS; i++) { | 
					
						
							|  |  |  | 		QString w = getFormattedWeight(m_dive, i); | 
					
						
							| 
									
										
										
										
											2018-11-24 08:40:30 +01:00
										 |  |  | 		if (w.isEmpty()) | 
					
						
							| 
									
										
										
										
											2016-07-19 06:55:21 +01:00
										 |  |  | 			continue; | 
					
						
							|  |  |  | 		weights << w; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-01-11 16:48:46 -02:00
										 |  |  | 	return weights; | 
					
						
							| 
									
										
										
										
											2016-01-07 16:01:24 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-05 22:53:12 -08:00
										 |  |  | bool DiveObjectHelper::singleWeight() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return weightsystem_none(&m_dive->weightsystem[1]); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-07 16:01:24 -02:00
										 |  |  | QString DiveObjectHelper::weight(int idx) const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-01-11 16:48:46 -02:00
										 |  |  | 	if ( (idx < 0) || idx > MAX_WEIGHTSYSTEMS ) | 
					
						
							| 
									
										
										
										
											2018-11-24 08:40:30 +01:00
										 |  |  | 		return QString(); | 
					
						
							| 
									
										
										
										
											2016-01-11 16:48:46 -02:00
										 |  |  | 	return getFormattedWeight(m_dive, idx); | 
					
						
							| 
									
										
										
										
											2016-01-07 16:01:24 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QString DiveObjectHelper::suit() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-24 08:40:30 +01:00
										 |  |  | 	return m_dive->suit ? m_dive->suit : QString(); | 
					
						
							| 
									
										
										
										
											2016-01-07 16:01:24 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-30 16:24:19 +02:00
										 |  |  | QStringList DiveObjectHelper::cylinderList() const | 
					
						
							| 
									
										
										
										
											2016-02-29 16:42:07 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-08-30 16:24:19 +02:00
										 |  |  | 	QStringList cylinders; | 
					
						
							|  |  |  | 	struct dive *d; | 
					
						
							|  |  |  | 	int i = 0; | 
					
						
							|  |  |  | 	for_each_dive (i, d) { | 
					
						
							|  |  |  | 		for (int j = 0; j < MAX_CYLINDERS; j++) { | 
					
						
							|  |  |  | 			QString cyl = d->cylinder[j].type.description; | 
					
						
							| 
									
										
										
										
											2018-11-24 08:40:30 +01:00
										 |  |  | 			if (cyl.isEmpty()) | 
					
						
							| 
									
										
										
										
											2016-08-30 16:24:19 +02:00
										 |  |  | 				continue; | 
					
						
							|  |  |  | 			cylinders << cyl; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-26 16:05:26 -08:00
										 |  |  | 	for (unsigned long ti = 0; ti < MAX_TANK_INFO && tank_info[ti].name != NULL; ti++) { | 
					
						
							| 
									
										
										
										
											2016-09-04 10:27:56 -07:00
										 |  |  | 		QString cyl = tank_info[ti].name; | 
					
						
							| 
									
										
										
										
											2018-11-24 08:40:30 +01:00
										 |  |  | 		if (cyl.isEmpty()) | 
					
						
							| 
									
										
										
										
											2016-02-29 16:42:07 +02:00
										 |  |  | 			continue; | 
					
						
							| 
									
										
										
										
											2016-08-30 16:24:19 +02:00
										 |  |  | 		cylinders << cyl; | 
					
						
							| 
									
										
										
										
											2016-02-29 16:42:07 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-08-30 16:24:19 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	cylinders.removeDuplicates(); | 
					
						
							|  |  |  | 	cylinders.sort(); | 
					
						
							| 
									
										
										
										
											2016-02-29 16:42:07 +02:00
										 |  |  | 	return cylinders; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-07 16:01:24 -02:00
										 |  |  | QStringList DiveObjectHelper::cylinders() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-01-11 16:48:46 -02:00
										 |  |  | 	QStringList cylinders; | 
					
						
							| 
									
										
										
										
											2016-07-19 00:06:10 +01:00
										 |  |  | 	for (int i = 0; i < MAX_CYLINDERS; i++) { | 
					
						
							|  |  |  | 		QString cyl = getFormattedCylinder(m_dive, i); | 
					
						
							| 
									
										
										
										
											2018-11-24 08:40:30 +01:00
										 |  |  | 		if (cyl.isEmpty()) | 
					
						
							| 
									
										
										
										
											2016-07-19 00:06:10 +01:00
										 |  |  | 			continue; | 
					
						
							|  |  |  | 		cylinders << cyl; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-01-11 16:48:46 -02:00
										 |  |  | 	return cylinders; | 
					
						
							| 
									
										
										
										
											2016-01-07 16:01:24 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QString DiveObjectHelper::cylinder(int idx) const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-01-11 16:48:46 -02:00
										 |  |  | 	if ( (idx < 0) || idx > MAX_CYLINDERS) | 
					
						
							| 
									
										
										
										
											2018-11-24 08:40:30 +01:00
										 |  |  | 		return QString(); | 
					
						
							| 
									
										
										
										
											2016-01-11 16:48:46 -02:00
										 |  |  | 	return getFormattedCylinder(m_dive, idx); | 
					
						
							| 
									
										
										
										
											2016-01-07 16:01:24 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-31 22:27:07 +01:00
										 |  |  | QList<CylinderObjectHelper*> DiveObjectHelper::cylinderObjects() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return m_cyls; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-22 22:10:38 +01:00
										 |  |  | QString DiveObjectHelper::tripId() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return m_dive->divetrip ? QString::number((quint64)m_dive->divetrip, 16) : QString(); | 
					
						
							| 
									
										
										
										
											2016-01-26 20:06:30 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-14 17:34:33 -07:00
										 |  |  | int DiveObjectHelper::tripNrDives() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct dive_trip *dt = m_dive->divetrip; | 
					
						
							| 
									
										
										
										
											2018-11-08 16:58:33 +01:00
										 |  |  | 	return dt ? dt->dives.nr : 0; | 
					
						
							| 
									
										
										
										
											2018-04-14 17:34:33 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-18 23:08:27 +01:00
										 |  |  | int DiveObjectHelper::maxcns() const | 
					
						
							| 
									
										
										
										
											2016-01-07 16:01:24 -02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-07-18 23:08:27 +01:00
										 |  |  | 	return m_dive->maxcns; | 
					
						
							| 
									
										
										
										
											2016-01-07 16:01:24 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-18 23:08:27 +01:00
										 |  |  | int DiveObjectHelper::otu() const | 
					
						
							| 
									
										
										
										
											2016-01-07 16:01:24 -02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-07-18 23:08:27 +01:00
										 |  |  | 	return m_dive->otu; | 
					
						
							| 
									
										
										
										
											2016-01-07 16:01:24 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int DiveObjectHelper::rating() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-01-11 15:05:07 -02:00
										 |  |  | 	return m_dive->rating; | 
					
						
							| 
									
										
										
										
											2016-01-07 16:01:24 -02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2016-01-27 18:34:34 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-16 09:59:05 +01:00
										 |  |  | int DiveObjectHelper::visibility() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return m_dive->visibility; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-27 18:34:34 +01:00
										 |  |  | QString DiveObjectHelper::sumWeight() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-06-05 23:02:25 +02:00
										 |  |  | 	weight_t sum = { total_weight(m_dive) }; | 
					
						
							| 
									
										
										
										
											2016-02-05 22:52:30 -08:00
										 |  |  | 	return get_weight_string(sum, true); | 
					
						
							| 
									
										
										
										
											2016-01-27 18:34:34 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-12 11:57:21 +02:00
										 |  |  | QStringList DiveObjectHelper::getCylinder() const | 
					
						
							| 
									
										
										
										
											2016-01-27 18:34:34 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-12 11:57:21 +02:00
										 |  |  | 	QStringList getCylinder;  | 
					
						
							|  |  |  | 	for (int i = 0; i < MAX_CYLINDERS; i++) { | 
					
						
							|  |  |  | 		if (is_cylinder_used(m_dive, i)) | 
					
						
							|  |  |  | 			getCylinder << m_dive->cylinder[i].type.description; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-01-27 18:34:34 +01:00
										 |  |  | 	return getCylinder; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2016-02-09 17:19:06 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-17 11:49:42 +02:00
										 |  |  | QStringList DiveObjectHelper::startPressure() const | 
					
						
							| 
									
										
										
										
											2016-02-09 17:19:06 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-17 11:49:42 +02:00
										 |  |  | 	QStringList startPressure; | 
					
						
							|  |  |  | 	for (int i = 0; i < MAX_CYLINDERS; i++) { | 
					
						
							|  |  |  | 		if (is_cylinder_used(m_dive, i)) | 
					
						
							|  |  |  | 			startPressure << getPressures(m_dive, i, START_PRESSURE); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-02-09 17:19:06 +01:00
										 |  |  | 	return startPressure; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-17 11:49:42 +02:00
										 |  |  | QStringList DiveObjectHelper::endPressure() const | 
					
						
							| 
									
										
										
										
											2016-02-09 17:19:06 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-17 11:49:42 +02:00
										 |  |  | 	QStringList endPressure; | 
					
						
							|  |  |  | 	for (int i = 0; i < MAX_CYLINDERS; i++) { | 
					
						
							|  |  |  | 		if (is_cylinder_used(m_dive, i)) | 
					
						
							|  |  |  | 			endPressure << getPressures(m_dive, i, END_PRESSURE); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-02-09 17:19:06 +01:00
										 |  |  | 	return endPressure; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2016-02-13 18:34:29 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-16 18:25:21 +02:00
										 |  |  | QStringList DiveObjectHelper::firstGas() const | 
					
						
							| 
									
										
										
										
											2016-02-13 18:34:29 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-16 18:25:21 +02:00
										 |  |  | 	QStringList gas; | 
					
						
							|  |  |  | 	for (int i = 0; i < MAX_CYLINDERS; i++) { | 
					
						
							|  |  |  | 		if (is_cylinder_used(m_dive, i)) | 
					
						
							|  |  |  | 			gas << get_gas_string(m_dive->cylinder[i].gasmix); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-02-13 18:34:29 +01:00
										 |  |  | 	return gas; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-10-16 07:56:41 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | // for a full text search / filter function
 | 
					
						
							|  |  |  | QString DiveObjectHelper::fullText() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-10-19 21:15:56 -04:00
										 |  |  | 	return fullTextNoNotes() + ":-:" + notes(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QString DiveObjectHelper::fullTextNoNotes() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-24 08:40:30 +01:00
										 |  |  | 	QString tripLocation = m_dive->divetrip ? m_dive->divetrip->location : QString(); | 
					
						
							| 
									
										
										
										
											2018-11-22 09:00:50 +01:00
										 |  |  | 	return tripLocation + ":-:" + location() + ":-:" + buddy() + ":-:" + divemaster() + ":-:" + suit() + ":-:" + tags(); | 
					
						
							| 
									
										
										
										
											2018-10-16 07:56:41 -04:00
										 |  |  | } |