I was walking around the code today to see what was done in the days
that I was abscent because of work, and this is a little list of
patches for small annoyances that I'v found in the code.

12 just now. :)

With those, it's safe to continue the code on the UnitTests.

Kiss in the shoulder, for the recalque passar longe. <3

Tomaz
From d3b1cc36e7d2f314016c8605e8043d86a898bf76 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Sat, 10 May 2014 19:36:44 -0300
Subject: [PATCH 01/12] Added gitrule to ignore build/ directory

I'm using CMake as buildsystem ( with qmake buildsystem as a spare
one ), so is highly annoying to have a dirty repo only because of that
folder.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 .gitignore | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.gitignore b/.gitignore
index 6dc0218..837ad71 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
+build/
 translations/*.qm
 *.o
 *.orig
-- 
1.9.2

From ac65aac6f710e623bd39b219a0d16986dd30918b Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Sat, 10 May 2014 20:42:27 -0300
Subject: [PATCH 02/12] Moved unit related code to units.h

The units are used everywhere on the application, we don't really
need to include "dive.h" to be able to use unit conversion, so I
changed them to a new file. There are still a lot of non-dive stuff
on dive.h / c, I'll try to move them later.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 dive.h  | 230 +-----------------------------------------------------------
 units.h | 243 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 244 insertions(+), 229 deletions(-)
 create mode 100644 units.h

diff --git a/dive.h b/dive.h
index b4e21a5..5c2c4bf 100644
--- a/dive.h
+++ b/dive.h
@@ -33,6 +33,7 @@ static inline int same_string(const char *a, const char *b)
 #include <libxslt/transform.h>
 
 #include "sha1.h"
+#include "units.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -40,96 +41,6 @@ extern "C" {
 #include <stdbool.h>
 #endif
 
-#define O2_IN_AIR 209 // permille
-#define N2_IN_AIR 781
-#define O2_DENSITY 1429 // mg/Liter
-#define N2_DENSITY 1251
-#define HE_DENSITY 179
-#define SURFACE_PRESSURE 1013 // mbar
-#define SURFACE_PRESSURE_STRING "1013"
-#define ZERO_C_IN_MKELVIN 273150 // mKelvin
-
-/* Salinity is expressed in weight in grams per 10l */
-#define SEAWATER_SALINITY 10300
-#define FRESHWATER_SALINITY 10000
-
-/*
- * Some silly typedefs to make our units very explicit.
- *
- * Also, the units are chosen so that values can be expressible as
- * integers, so that we never have FP rounding issues. And they
- * are small enough that converting to/from imperial units doesn't
- * really matter.
- *
- * We also strive to make '0' a meaningless number saying "not
- * initialized", since many values are things that may not have
- * been reported (eg cylinder pressure or temperature from dive
- * computers that don't support them). But sometimes -1 is an even
- * more explicit way of saying "not there".
- *
- * Thus "millibar" for pressure, for example, or "millikelvin" for
- * temperatures. Doing temperatures in celsius or fahrenheit would
- * make for loss of precision when converting from one to the other,
- * and using millikelvin is SI-like but also means that a temperature
- * of '0' is clearly just a missing temperature or cylinder pressure.
- *
- * Also strive to use units that can not possibly be mistaken for a
- * valid value in a "normal" system without conversion. If the max
- * depth of a dive is '20000', you probably didn't convert from mm on
- * output, or if the max depth gets reported as "0.2ft" it was either
- * a really boring dive, or there was some missing input conversion,
- * and a 60-ft dive got recorded as 60mm.
- *
- * Doing these as "structs containing value" means that we always
- * have to explicitly write out those units in order to get at the
- * actual value. So there is hopefully little fear of using a value
- * in millikelvin as Fahrenheit by mistake.
- *
- * We don't actually use these all yet, so maybe they'll change, but
- * I made a number of types as guidelines.
- */
-typedef int64_t timestamp_t;
-
-typedef struct
-{
-	int seconds;
-} duration_t;
-
-typedef struct
-{
-	int mm;
-} depth_t;
-
-typedef struct
-{
-	int mbar;
-} pressure_t;
-
-typedef struct
-{
-	int mkelvin;
-} temperature_t;
-
-typedef struct
-{
-	int mliter;
-} volume_t;
-
-typedef struct
-{
-	int permille;
-} fraction_t;
-
-typedef struct
-{
-	int grams;
-} weight_t;
-
-typedef struct
-{
-	int udeg;
-} degrees_t;
-
 struct gasmix {
 	fraction_t o2;
 	fraction_t he;
@@ -166,96 +77,10 @@ extern double get_vertical_speed_units(unsigned int mms, int *frac, const char *
 
 extern unsigned int units_to_depth(double depth);
 
-static inline double grams_to_lbs(int grams)
-{
-	return grams / 453.6;
-}
-
-static inline int lbs_to_grams(double lbs)
-{
-	return rint(lbs * 453.6);
-}
-
-static inline double ml_to_cuft(int ml)
-{
-	return ml / 28316.8466;
-}
-
-static inline double cuft_to_l(double cuft)
-{
-	return cuft * 28.3168466;
-}
-
-static inline double mm_to_feet(int mm)
-{
-	return mm * 0.00328084;
-}
-
-static inline unsigned long feet_to_mm(double feet)
-{
-	return rint(feet * 304.8);
-}
-
-static inline int to_feet(depth_t depth)
-{
-	return rint(mm_to_feet(depth.mm));
-}
-
-static inline double mkelvin_to_C(int mkelvin)
-{
-	return (mkelvin - ZERO_C_IN_MKELVIN) / 1000.0;
-}
-
-static inline double mkelvin_to_F(int mkelvin)
-{
-	return mkelvin * 9 / 5000.0 - 459.670;
-}
-
-static inline unsigned long F_to_mkelvin(double f)
-{
-	return rint((f - 32) * 1000 / 1.8 + ZERO_C_IN_MKELVIN);
-}
-
-static inline unsigned long C_to_mkelvin(double c)
-{
-	return rint(c * 1000 + ZERO_C_IN_MKELVIN);
-}
-
-static inline double psi_to_bar(double psi)
-{
-	return psi / 14.5037738;
-}
-
-static inline long psi_to_mbar(double psi)
-{
-	return rint(psi_to_bar(psi) * 1000);
-}
-
-static inline int to_PSI(pressure_t pressure)
-{
-	return rint(pressure.mbar * 0.0145037738);
-}
-
-static inline double bar_to_atm(double bar)
-{
-	return bar / SURFACE_PRESSURE * 1000;
-}
-
-static inline double mbar_to_atm(int mbar)
-{
-	return (double)mbar / SURFACE_PRESSURE;
-}
-
 /* Volume in mliter of a cylinder at pressure 'p' */
 extern int gas_volume(cylinder_t *cyl, pressure_t p);
 extern int wet_volume(double cuft, pressure_t p);
 
-static inline int mbar_to_PSI(int mbar)
-{
-	pressure_t p = { mbar };
-	return to_PSI(p);
-}
-
 static inline int get_o2(const struct gasmix *mix)
 {
 	return mix->o2.permille ?: O2_IN_AIR;
@@ -521,60 +346,7 @@ extern void add_single_dive(int idx, struct dive *dive);
 
 extern void insert_trip(dive_trip_t **trip);
 
-/*
- * We keep our internal data in well-specified units, but
- * the input and output may come in some random format. This
- * keeps track of those units.
- */
-/* turns out in Win32 PASCAL is defined as a calling convention */
-#ifdef WIN32
-#undef PASCAL
-#endif
-struct units {
-	enum {
-		METERS,
-		FEET
-	} length;
-	enum {
-		LITER,
-		CUFT
-	} volume;
-	enum {
-		BAR,
-		PSI,
-		PASCAL
-	} pressure;
-	enum {
-		CELSIUS,
-		FAHRENHEIT,
-		KELVIN
-	} temperature;
-	enum {
-		KG,
-		LBS
-	} weight;
-	enum {
-		SECONDS,
-		MINUTES
-	} vertical_speed_time;
-};
-
-/*
- * We're going to default to SI units for input. Yes,
- * technically the SI unit for pressure is Pascal, but
- * we default to bar (10^5 pascal), which people
- * actually use. Similarly, C instead of Kelvin.
- * And kg instead of g.
- */
-#define SI_UNITS                                                                                                                         \
-	{                                                                                                                                \
-		.length = METERS, .volume = LITER, .pressure = BAR, .temperature = CELSIUS, .weight = KG, .vertical_speed_time = MINUTES \
-	}
 
-#define IMPERIAL_UNITS                                                                                                                    \
-	{                                                                                                                                 \
-		.length = FEET, .volume = CUFT, .pressure = PSI, .temperature = FAHRENHEIT, .weight = LBS, .vertical_speed_time = MINUTES \
-	}
 extern const struct units SI_units, IMPERIAL_units;
 extern struct units xml_parsing_units;
 
diff --git a/units.h b/units.h
new file mode 100644
index 0000000..ef5d93f
--- /dev/null
+++ b/units.h
@@ -0,0 +1,243 @@
+#ifndef UNITS_H
+#define UNITS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+  
+#define O2_IN_AIR 209 // permille
+#define N2_IN_AIR 781
+#define O2_DENSITY 1429 // mg/Liter
+#define N2_DENSITY 1251
+#define HE_DENSITY 179
+#define SURFACE_PRESSURE 1013 // mbar
+#define SURFACE_PRESSURE_STRING "1013"
+#define ZERO_C_IN_MKELVIN 273150 // mKelvin
+
+/* Salinity is expressed in weight in grams per 10l */
+#define SEAWATER_SALINITY 10300
+#define FRESHWATER_SALINITY 10000
+
+/*
+ * Some silly typedefs to make our units very explicit.
+ *
+ * Also, the units are chosen so that values can be expressible as
+ * integers, so that we never have FP rounding issues. And they
+ * are small enough that converting to/from imperial units doesn't
+ * really matter.
+ *
+ * We also strive to make '0' a meaningless number saying "not
+ * initialized", since many values are things that may not have
+ * been reported (eg cylinder pressure or temperature from dive
+ * computers that don't support them). But sometimes -1 is an even
+ * more explicit way of saying "not there".
+ *
+ * Thus "millibar" for pressure, for example, or "millikelvin" for
+ * temperatures. Doing temperatures in celsius or fahrenheit would
+ * make for loss of precision when converting from one to the other,
+ * and using millikelvin is SI-like but also means that a temperature
+ * of '0' is clearly just a missing temperature or cylinder pressure.
+ *
+ * Also strive to use units that can not possibly be mistaken for a
+ * valid value in a "normal" system without conversion. If the max
+ * depth of a dive is '20000', you probably didn't convert from mm on
+ * output, or if the max depth gets reported as "0.2ft" it was either
+ * a really boring dive, or there was some missing input conversion,
+ * and a 60-ft dive got recorded as 60mm.
+ *
+ * Doing these as "structs containing value" means that we always
+ * have to explicitly write out those units in order to get at the
+ * actual value. So there is hopefully little fear of using a value
+ * in millikelvin as Fahrenheit by mistake.
+ *
+ * We don't actually use these all yet, so maybe they'll change, but
+ * I made a number of types as guidelines.
+ */
+typedef int64_t timestamp_t;
+
+typedef struct
+{
+	int seconds;
+} duration_t;
+
+typedef struct
+{
+	int mm;
+} depth_t;
+
+typedef struct
+{
+	int mbar;
+} pressure_t;
+
+typedef struct
+{
+	int mkelvin;
+} temperature_t;
+
+typedef struct
+{
+	int mliter;
+} volume_t;
+
+typedef struct
+{
+	int permille;
+} fraction_t;
+
+typedef struct
+{
+	int grams;
+} weight_t;
+
+typedef struct
+{
+	int udeg;
+} degrees_t;
+
+static inline double grams_to_lbs(int grams)
+{
+	return grams / 453.6;
+}
+
+static inline int lbs_to_grams(double lbs)
+{
+	return rint(lbs * 453.6);
+}
+
+static inline double ml_to_cuft(int ml)
+{
+	return ml / 28316.8466;
+}
+
+static inline double cuft_to_l(double cuft)
+{
+	return cuft * 28.3168466;
+}
+
+static inline double mm_to_feet(int mm)
+{
+	return mm * 0.00328084;
+}
+
+static inline unsigned long feet_to_mm(double feet)
+{
+	return rint(feet * 304.8);
+}
+
+static inline int to_feet(depth_t depth)
+{
+	return rint(mm_to_feet(depth.mm));
+}
+
+static inline double mkelvin_to_C(int mkelvin)
+{
+	return (mkelvin - ZERO_C_IN_MKELVIN) / 1000.0;
+}
+
+static inline double mkelvin_to_F(int mkelvin)
+{
+	return mkelvin * 9 / 5000.0 - 459.670;
+}
+
+static inline unsigned long F_to_mkelvin(double f)
+{
+	return rint((f - 32) * 1000 / 1.8 + ZERO_C_IN_MKELVIN);
+}
+
+static inline unsigned long C_to_mkelvin(double c)
+{
+	return rint(c * 1000 + ZERO_C_IN_MKELVIN);
+}
+
+static inline double psi_to_bar(double psi)
+{
+	return psi / 14.5037738;
+}
+
+static inline long psi_to_mbar(double psi)
+{
+	return rint(psi_to_bar(psi) * 1000);
+}
+
+static inline int to_PSI(pressure_t pressure)
+{
+	return rint(pressure.mbar * 0.0145037738);
+}
+
+static inline double bar_to_atm(double bar)
+{
+	return bar / SURFACE_PRESSURE * 1000;
+}
+
+static inline double mbar_to_atm(int mbar)
+{
+	return (double)mbar / SURFACE_PRESSURE;
+}
+
+static inline int mbar_to_PSI(int mbar)
+{
+	pressure_t p = { mbar };
+	return to_PSI(p);
+}
+
+/*
+ * We keep our internal data in well-specified units, but
+ * the input and output may come in some random format. This
+ * keeps track of those units.
+ */
+/* turns out in Win32 PASCAL is defined as a calling convention */
+#ifdef WIN32
+#undef PASCAL
+#endif
+struct units {
+	enum {
+		METERS,
+		FEET
+	} length;
+	enum {
+		LITER,
+		CUFT
+	} volume;
+	enum {
+		BAR,
+		PSI,
+		PASCAL
+	} pressure;
+	enum {
+		CELSIUS,
+		FAHRENHEIT,
+		KELVIN
+	} temperature;
+	enum {
+		KG,
+		LBS
+	} weight;
+	enum {
+		SECONDS,
+		MINUTES
+	} vertical_speed_time;
+};
+
+/*
+ * We're going to default to SI units for input. Yes,
+ * technically the SI unit for pressure is Pascal, but
+ * we default to bar (10^5 pascal), which people
+ * actually use. Similarly, C instead of Kelvin.
+ * And kg instead of g.
+ */
+#define SI_UNITS                                                                                                                         \
+	{                                                                                                                                \
+		.length = METERS, .volume = LITER, .pressure = BAR, .temperature = CELSIUS, .weight = KG, .vertical_speed_time = MINUTES \
+	}
+
+#define IMPERIAL_UNITS                                                                                                                    \
+	{                                                                                                                                 \
+		.length = FEET, .volume = CUFT, .pressure = PSI, .temperature = FAHRENHEIT, .weight = LBS, .vertical_speed_time = MINUTES \
+	}
+
+#ifdef __cplusplus
+}
+#endif
+  
+#endif
\ No newline at end of file
-- 
1.9.2

From 40f92bbd1e61058f4601fdc79cecf68391b3e64c Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Sat, 10 May 2014 20:48:46 -0300
Subject: [PATCH 03/12] Removed old defines.

Those looks like to be the old defines from the ancient Gtk times
where we hardcoded the white stars and black stars as font glyphs
instead of drawing them. get rid of it.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 dive.h | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/dive.h b/dive.h
index 5c2c4bf..bff5a08 100644
--- a/dive.h
+++ b/dive.h
@@ -576,16 +576,9 @@ const char *monthname(int mon);
 #define UTF8_UPWARDS_ARROW "\xE2\x86\x91"
 #define UTF8_DOWNWARDS_ARROW "\xE2\x86\x93"
 #define UTF8_AVERAGE "\xc3\xb8"
-#define UCS4_DEGREE 0xb0
 #define UTF8_SUBSCRIPT_2 "\xe2\x82\x82"
 #define UTF8_WHITESTAR "\xe2\x98\x86"
 #define UTF8_BLACKSTAR "\xe2\x98\x85"
-#define ZERO_STARS UTF8_WHITESTAR UTF8_WHITESTAR UTF8_WHITESTAR UTF8_WHITESTAR UTF8_WHITESTAR
-#define ONE_STARS UTF8_BLACKSTAR UTF8_WHITESTAR UTF8_WHITESTAR UTF8_WHITESTAR UTF8_WHITESTAR
-#define TWO_STARS UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_WHITESTAR UTF8_WHITESTAR UTF8_WHITESTAR
-#define THREE_STARS UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_WHITESTAR UTF8_WHITESTAR
-#define FOUR_STARS UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_WHITESTAR
-#define FIVE_STARS UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_BLACKSTAR UTF8_BLACKSTAR
 extern const char *star_strings[];
 
 extern const char *existing_filename;
-- 
1.9.2

From fa54abd4182762b232dfb1a3ffa51bd5797d35f6 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Sat, 10 May 2014 20:53:46 -0300
Subject: [PATCH 04/12] Another stuff that was inside, from the Gtk Times.

Die, Die.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 dive.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/dive.h b/dive.h
index bff5a08..af7a4e2 100644
--- a/dive.h
+++ b/dive.h
@@ -579,7 +579,6 @@ const char *monthname(int mon);
 #define UTF8_SUBSCRIPT_2 "\xe2\x82\x82"
 #define UTF8_WHITESTAR "\xe2\x98\x86"
 #define UTF8_BLACKSTAR "\xe2\x98\x85"
-extern const char *star_strings[];
 
 extern const char *existing_filename;
 extern void subsurface_command_line_init(int *, char ***);
-- 
1.9.2

From 3b2a9c772d324069817c4a464425372a0da4a057 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Sat, 10 May 2014 21:09:37 -0300
Subject: [PATCH 05/12] Remove the misuse of a strange way to use the tr method

Dirk used this to fix something on the last month, not the best
way tougth - this one is much nicer, we don't depend on MainWindow
again and the unit tests ( only one, I know ) is being build again.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/maintab.cpp | 4 ----
 qt-ui/maintab.h   | 1 -
 qthelper.cpp      | 9 ++++-----
 3 files changed, 4 insertions(+), 10 deletions(-)

diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index 234a01c..cfc22eb 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -1119,7 +1119,3 @@ void MainTab::updateGpsCoordinates(const struct dive *dive)
 	}
 }
 
-QString MainTab::trHemisphere(const char *orig)
-{
-	return tr(orig);
-}
diff --git a/qt-ui/maintab.h b/qt-ui/maintab.h
index ece2c40..4a0b0b9 100644
--- a/qt-ui/maintab.h
+++ b/qt-ui/maintab.h
@@ -96,7 +96,6 @@ slots:
 	void enableEdition(EditMode newEditMode = NONE);
 	void toggleTriggeredColumn();
 	void updateTextLabels(bool showUnits = true);
-	QString trHemisphere(const char *orig);
 
 private:
 	Ui::MainTab ui;
diff --git a/qthelper.cpp b/qthelper.cpp
index f265833..fdf0432 100644
--- a/qthelper.cpp
+++ b/qthelper.cpp
@@ -120,11 +120,10 @@ bool parseGpsText(const QString &gps_text, double *latitude, double *longitude)
 	} gpsStyle = ISO6709D;
 	int eastWest = 4;
 	int northSouth = 1;
-	QString trHemisphere[4];
-	trHemisphere[0] = MainWindow::instance()->information()->trHemisphere("N");
-	trHemisphere[1] = MainWindow::instance()->information()->trHemisphere("S");
-	trHemisphere[2] = MainWindow::instance()->information()->trHemisphere("E");
-	trHemisphere[3] = MainWindow::instance()->information()->trHemisphere("W");
+	QStringList trHemisphere;
+	#define TR( X ) QObject::tr( X )
+	trHemisphere << TR("N") << TR("S") << TR("E") << TR("W");
+	#undef TR
 	QString regExp;
 	/* an empty string is interpreted as 0.0,0.0 and therefore "no gps location" */
 	if (gps_text.trimmed() == "") {
-- 
1.9.2

From d3863869704ad52b19671b26cc8fea6bfd7b795d Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Sat, 10 May 2014 21:37:18 -0300
Subject: [PATCH 06/12] Correct the usage of std::string and QString on the
 app.

QStrings shouldn't be == "" to check for empty string, use .isEmpty()
QStrings shouldn't be != "" to check for non empty, use .size()
std::string shouldn't be cleared with = "", use .clear()

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-gui.cpp           |  2 +-
 qt-ui/exif.cpp       | 18 +++++++++---------
 qt-ui/globe.cpp      |  4 ++--
 qt-ui/usermanual.cpp |  2 +-
 qthelper.cpp         | 10 +++++-----
 5 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/qt-gui.cpp b/qt-gui.cpp
index f2b655e..868389e 100644
--- a/qt-gui.cpp
+++ b/qt-gui.cpp
@@ -372,7 +372,7 @@ int parseTemperatureToMkelvin(const QString &text)
 	int mkelvin;
 	QString numOnly = text;
 	numOnly.replace(",", ".").remove(QRegExp("[^-0-9.]"));
-	if (numOnly == "")
+	if (numOnly.isEmpty())
 		return 0;
 	double number = numOnly.toDouble();
 	switch (prefs.units.temperature) {
diff --git a/qt-ui/exif.cpp b/qt-ui/exif.cpp
index 2614d52..8260157 100644
--- a/qt-ui/exif.cpp
+++ b/qt-ui/exif.cpp
@@ -525,15 +525,15 @@ int EXIFInfo::parseFromEXIFSegment(const unsigned char *buf, unsigned len)
 void EXIFInfo::clear()
 {
 	// Strings
-	ImageDescription = "";
-	Make = "";
-	Model = "";
-	Software = "";
-	DateTime = "";
-	DateTimeOriginal = "";
-	DateTimeDigitized = "";
-	SubSecTimeOriginal = "";
-	Copyright = "";
+	ImageDescription.clear();
+	Make.clear();
+	Model.clear();
+	Software.clear();
+	DateTime.clear();
+	DateTimeOriginal.clear();
+	DateTimeDigitized.clear();
+	SubSecTimeOriginal.clear();
+	Copyright.clear();
 
 	// Shorts / unsigned / double
 	ByteAlign = 0;
diff --git a/qt-ui/globe.cpp b/qt-ui/globe.cpp
index 9f66e2b..1101500 100644
--- a/qt-ui/globe.cpp
+++ b/qt-ui/globe.cpp
@@ -48,11 +48,11 @@ GlobeGPS::GlobeGPS(QWidget *parent) : MarbleWidget(parent),
 	QDir marble;
 	if (!list.contains("earth/googlesat/googlesat.dgml")) {
 		subsurfaceDataPath = getSubsurfaceDataPath("marbledata");
-		if (subsurfaceDataPath != "") {
+		if (subsurfaceDataPath.size()) {
 			MarbleDirs::setMarbleDataPath(subsurfaceDataPath);
 		} else {
 			subsurfaceDataPath = getSubsurfaceDataPath("data");
-			if (subsurfaceDataPath != "")
+			if (subsurfaceDataPath.size())
 				MarbleDirs::setMarbleDataPath(subsurfaceDataPath);
 		}
 	}
diff --git a/qt-ui/usermanual.cpp b/qt-ui/usermanual.cpp
index 89e556d..0dd39af 100644
--- a/qt-ui/usermanual.cpp
+++ b/qt-ui/usermanual.cpp
@@ -30,7 +30,7 @@ UserManual::UserManual(QWidget *parent) : QMainWindow(parent),
 
 	ui->webView->page()->setLinkDelegationPolicy(QWebPage::DelegateExternalLinks);
 	QString searchPath = getSubsurfaceDataPath("Documentation");
-	if (searchPath != "") {
+	if (searchPath.size()) {
 		QUrl url(searchPath.append("/user-manual.html"));
 		ui->webView->setUrl(url);
 	} else {
diff --git a/qthelper.cpp b/qthelper.cpp
index fdf0432..2339dbe 100644
--- a/qthelper.cpp
+++ b/qthelper.cpp
@@ -66,17 +66,17 @@ const DiveComputerNode *DiveComputerList::get(QString m)
 
 void DiveComputerList::addDC(QString m, uint32_t d, QString n, QString s, QString f)
 {
-	if (m == "" || d == 0)
+	if (m.isEmpty() || d == 0)
 		return;
 	const DiveComputerNode *existNode = this->getExact(m, d);
 	DiveComputerNode newNode(m, d, s, f, n);
 	if (existNode) {
 		if (newNode.changesValues(*existNode)) {
-			if (n != "" && existNode->nickName != n)
+			if (n.size() && existNode->nickName != n)
 				qDebug("new nickname %s for DC model %s deviceId 0x%x", n.toUtf8().data(), m.toUtf8().data(), d);
-			if (f != "" && existNode->firmware != f)
+			if (f.size() && existNode->firmware != f)
 				qDebug("new firmware version %s for DC model %s deviceId 0x%x", f.toUtf8().data(), m.toUtf8().data(), d);
-			if (s != "" && existNode->serialNumber != s)
+			if (s.size() && existNode->serialNumber != s)
 				qDebug("new serial number %s for DC model %s deviceId 0x%x", s.toUtf8().data(), m.toUtf8().data(), d);
 		} else {
 			return;
@@ -126,7 +126,7 @@ bool parseGpsText(const QString &gps_text, double *latitude, double *longitude)
 	#undef TR
 	QString regExp;
 	/* an empty string is interpreted as 0.0,0.0 and therefore "no gps location" */
-	if (gps_text.trimmed() == "") {
+	if (gps_text.trimmed().isEmpty()) {
 		*latitude = 0.0;
 		*longitude = 0.0;
 		return true;
-- 
1.9.2

From fd26fc896632da1fa1c3f337fea06708476c3f4b Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Sat, 10 May 2014 21:51:38 -0300
Subject: [PATCH 07/12] Simplify code.

this is not necessary when you don't have a variable
that has the exact same name as the 'this->variable' name,

also, there's no need to check if a QString is empty
before trying to use the == on them.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qthelper.cpp | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/qthelper.cpp b/qthelper.cpp
index 2339dbe..c5dfa18 100644
--- a/qthelper.cpp
+++ b/qthelper.cpp
@@ -25,11 +25,11 @@ DiveComputerList::~DiveComputerList()
 
 bool DiveComputerNode::operator==(const DiveComputerNode &a) const
 {
-	return this->model == a.model &&
-	       this->deviceId == a.deviceId &&
-	       this->firmware == a.firmware &&
-	       this->serialNumber == a.serialNumber &&
-	       this->nickName == a.nickName;
+	return model == a.model &&
+	       deviceId == a.deviceId &&
+	       firmware == a.firmware &&
+	       serialNumber == a.serialNumber &&
+	       nickName == a.nickName;
 }
 
 bool DiveComputerNode::operator!=(const DiveComputerNode &a) const
@@ -39,13 +39,13 @@ bool DiveComputerNode::operator!=(const DiveComputerNode &a) const
 
 bool DiveComputerNode::changesValues(const DiveComputerNode &b) const
 {
-	if (this->model != b.model || this->deviceId != b.deviceId) {
+	if (model != b.model || deviceId != b.deviceId) {
 		qDebug("DiveComputerNodes were not for the same DC");
 		return false;
 	}
-	return (b.firmware != "" && this->firmware != b.firmware) ||
-	       (b.serialNumber != "" && this->serialNumber != b.serialNumber) ||
-	       (b.nickName != "" && this->nickName != b.nickName);
+	return (firmware != b.firmware) ||
+	       (serialNumber != b.serialNumber) ||
+	       (nickName != b.nickName);
 }
 
 const DiveComputerNode *DiveComputerList::getExact(QString m, uint32_t d)
-- 
1.9.2

From 187bb0dd46475d7b7e25ad3e193cb53ad3900be0 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Sat, 10 May 2014 21:52:40 -0300
Subject: [PATCH 08/12] 'Class' string is unecessary when using a Container.

pretty self explanatory, the 'class' keyword is unecessary
when defining things inside a Container, be it a QList,
QVector, QMap, QHahs or anything else.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qthelper.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/qthelper.h b/qthelper.h
index 42363b8..648a680 100644
--- a/qthelper.h
+++ b/qthelper.h
@@ -35,8 +35,8 @@ public:
 	void rmDC(QString m, uint32_t d);
 	DiveComputerNode matchDC(QString m, uint32_t d);
 	DiveComputerNode matchModel(QString m);
-	QMultiMap<QString, class DiveComputerNode> dcMap;
-	QMultiMap<QString, class DiveComputerNode> dcWorkingMap;
+	QMultiMap<QString, DiveComputerNode> dcMap;
+	QMultiMap<QString, DiveComputerNode> dcWorkingMap;
 };
 
 QString weight_string(int weight_in_grams);
-- 
1.9.2

From de1bbb89fa1c9ae45744a4127f101e09851fc00f Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Sat, 10 May 2014 22:07:02 -0300
Subject: [PATCH 09/12] When creating methods that pass QString, use const
 QString&

This removes unecessary creation and destruction of the object
making the code shine a bit more and be more fluffy. :)

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qthelper.cpp |  8 ++++----
 qthelper.h   | 12 ++++++------
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/qthelper.cpp b/qthelper.cpp
index c5dfa18..10c2b70 100644
--- a/qthelper.cpp
+++ b/qthelper.cpp
@@ -48,7 +48,7 @@ bool DiveComputerNode::changesValues(const DiveComputerNode &b) const
 	       (nickName != b.nickName);
 }
 
-const DiveComputerNode *DiveComputerList::getExact(QString m, uint32_t d)
+const DiveComputerNode *DiveComputerList::getExact(const QString& m, uint32_t d)
 {
 	for (QMap<QString, DiveComputerNode>::iterator it = dcMap.find(m); it != dcMap.end() && it.key() == m; ++it)
 		if (it->deviceId == d)
@@ -56,7 +56,7 @@ const DiveComputerNode *DiveComputerList::getExact(QString m, uint32_t d)
 	return NULL;
 }
 
-const DiveComputerNode *DiveComputerList::get(QString m)
+const DiveComputerNode *DiveComputerList::get(const QString& m)
 {
 	QMap<QString, DiveComputerNode>::iterator it = dcMap.find(m);
 	if (it != dcMap.end())
@@ -64,7 +64,7 @@ const DiveComputerNode *DiveComputerList::get(QString m)
 	return NULL;
 }
 
-void DiveComputerList::addDC(QString m, uint32_t d, QString n, QString s, QString f)
+void DiveComputerList::addDC(const QString& m, uint32_t d, const QString& n, const QString& s,const QString& f)
 {
 	if (m.isEmpty() || d == 0)
 		return;
@@ -86,7 +86,7 @@ void DiveComputerList::addDC(QString m, uint32_t d, QString n, QString s, QStrin
 	dcMap.insert(m, newNode);
 }
 
-void DiveComputerList::rmDC(QString m, uint32_t d)
+void DiveComputerList::rmDC(const QString& m, uint32_t d)
 {
 	const DiveComputerNode *existNode = this->getExact(m, d);
 	dcMap.remove(m, *existNode);
diff --git a/qthelper.h b/qthelper.h
index 648a680..9d31f5a 100644
--- a/qthelper.h
+++ b/qthelper.h
@@ -29,12 +29,12 @@ class DiveComputerList {
 public:
 	DiveComputerList();
 	~DiveComputerList();
-	const DiveComputerNode *getExact(QString m, uint32_t d);
-	const DiveComputerNode *get(QString m);
-	void addDC(QString m, uint32_t d, QString n = "", QString s = "", QString f = "");
-	void rmDC(QString m, uint32_t d);
-	DiveComputerNode matchDC(QString m, uint32_t d);
-	DiveComputerNode matchModel(QString m);
+	const DiveComputerNode *getExact(const QString& m, uint32_t d);
+	const DiveComputerNode *get(const QString& m);
+	void addDC(const QString& m, uint32_t d,const QString& n = QString(),const QString& s = QString(), const QString& f = QString());
+	void rmDC(const QString& m, uint32_t d);
+	DiveComputerNode matchDC(const QString& m, uint32_t d);
+	DiveComputerNode matchModel(const QString& m);
 	QMultiMap<QString, DiveComputerNode> dcMap;
 	QMultiMap<QString, DiveComputerNode> dcWorkingMap;
 };
-- 
1.9.2

From 83cb7c485558fb146fbfe166f008da1305a5ad98 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Sat, 10 May 2014 22:10:09 -0300
Subject: [PATCH 10/12] There was already a #define tr on the header of this
 file.

Removing the already defined tr macro.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qthelper.cpp | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/qthelper.cpp b/qthelper.cpp
index 10c2b70..cadabd3 100644
--- a/qthelper.cpp
+++ b/qthelper.cpp
@@ -121,9 +121,7 @@ bool parseGpsText(const QString &gps_text, double *latitude, double *longitude)
 	int eastWest = 4;
 	int northSouth = 1;
 	QStringList trHemisphere;
-	#define TR( X ) QObject::tr( X )
-	trHemisphere << TR("N") << TR("S") << TR("E") << TR("W");
-	#undef TR
+	trHemisphere << tr("N") << tr("S") << tr("E") << tr("W");
 	QString regExp;
 	/* an empty string is interpreted as 0.0,0.0 and therefore "no gps location" */
 	if (gps_text.trimmed().isEmpty()) {
-- 
1.9.2

From 41f010e52b6387851712bf1e095c646951b950e7 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Sat, 10 May 2014 22:12:40 -0300
Subject: [PATCH 11/12] use for_each_dive instead of hand-written loop.

It's easyer to make a mistake in the loop insteaf of
using the currently correct one that's already written

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qthelper.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/qthelper.cpp b/qthelper.cpp
index cadabd3..b25a596 100644
--- a/qthelper.cpp
+++ b/qthelper.cpp
@@ -243,8 +243,9 @@ bool gpsHasChanged(struct dive *dive, struct dive *master, const QString &gps_te
 QList<int> getDivesInTrip(dive_trip_t *trip)
 {
 	QList<int> ret;
-	for (int i = 0; i < dive_table.nr; i++) {
-		struct dive *d = get_dive(i);
+	int i;
+	struct dive *d;
+	for_each_dive(i, d){
 		if (d->divetrip == trip) {
 			ret.push_back(get_divenr(d));
 		}
-- 
1.9.2

From b62d6454ee3b44d03936b759d467fc34094e4c73 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Sat, 10 May 2014 22:18:37 -0300
Subject: [PATCH 12/12] Prefix a method with 'dive_' because it should workd
 only with dives

I'll be probably adding prefixes to functions to make it easier
to find method via autocomplete from the grep or interface helpers,
do you wanna know all the functions that works with a dive?
ask for the completion for dive_, do you wanna know all the
functions that works with a divelist? ask for the completions
on divelist_ or run grep -rIs divelist_ on the header files.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 dive.c       | 2 +-
 dive.h       | 2 +-
 qthelper.cpp | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/dive.c b/dive.c
index 9c3ab79..0c4b91f 100644
--- a/dive.c
+++ b/dive.c
@@ -955,7 +955,7 @@ struct dive *fixup_dive(struct dive *dive)
 		weightsystem_t *ws = dive->weightsystem + i;
 		add_weightsystem_description(ws);
 	}
-	dive->id = getUniqID(dive);
+	dive->id = dive_getUniqID(dive);
 
 	return dive;
 }
diff --git a/dive.h b/dive.h
index af7a4e2..31115df 100644
--- a/dive.h
+++ b/dive.h
@@ -525,7 +525,7 @@ extern bool has_hr_data(struct divecomputer *dc);
 
 extern void sort_table(struct dive_table *table);
 extern struct dive *fixup_dive(struct dive *dive);
-extern int getUniqID(struct dive *d);
+extern int dive_getUniqID(struct dive *d);
 extern unsigned int dc_airtemp(struct divecomputer *dc);
 extern unsigned int dc_watertemp(struct divecomputer *dc);
 extern struct dive *merge_dives(struct dive *a, struct dive *b, int offset, bool prefer_downloaded);
diff --git a/qthelper.cpp b/qthelper.cpp
index b25a596..e07fb82 100644
--- a/qthelper.cpp
+++ b/qthelper.cpp
@@ -257,7 +257,7 @@ QList<int> getDivesInTrip(dive_trip_t *trip)
 // it doesn't change during the life time of a Subsurface session
 // oh, and it has no meaning whatsoever - that's why we have the
 // silly initial number and increment by 3 :-)
-int getUniqID(struct dive *d)
+int dive_getUniqID(struct dive *d)
 {
 	static QSet<int> ids;
 	static int maxId = 83529;
-- 
1.9.2

_______________________________________________
subsurface mailing list
[email protected]
http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to