[PATCH 1/2] Models: translate the user entered weight units

Lubomir I. Ivanov neolit123 at gmail.com
Fri Jan 3 04:49:16 UTC 2014


From: "Lubomir I. Ivanov" <neolit123 at gmail.com>

Post c49d3885f this patch should make the input field
in the equipment tab for weight to accept the user
translated strings.

e.g.

'lbs' in Russian is '????' and '??????' in Bulgarian,
while 'kg' is the same for both languages - '??'.

Signed-off-by: Lubomir I. Ivanov <neolit123 at gmail.com>
---
i think for this patch to work the translations have
to be updated, first?

had some troubles here:
- translate() cannot be used, so i had to use tr()
and make the function a class member
- could not find an easy alternative to strncmp() in
QString(), so toUTF8().data() is used, instead.

if you have a better version please replace this patch.
---
 qt-ui/models.cpp | 8 ++++----
 qt-ui/models.h   | 1 +
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp
index ab501a2..dbf377f 100644
--- a/qt-ui/models.cpp
+++ b/qt-ui/models.cpp
@@ -464,16 +464,16 @@ void WeightModel::passInData(const QModelIndex& index, const QVariant& value)
 	}
 }
 
-double string_to_grams(char *str)
+double WeightModel::stringToGrams(char *str) const
 {
 	char *end;
 	double value = strtod_flags(str, &end, 0);
 
 	while (isspace(*end))
 		end++;
-	if (!strncmp(end, "kg", 2))
+	if (!strncmp(end, tr("kg").toUtf8().data(), 2))
 		goto kg;
-	if (!strncmp(end, "lbs", 3))
+	if (!strncmp(end, tr("lbs").toUtf8().data(), 3))
 		goto lbs;
 	if (prefs.units.weight == prefs.units.LBS)
 		goto lbs;
@@ -507,7 +507,7 @@ bool WeightModel::setData(const QModelIndex& index, const QVariant& value, int r
 		break;
 	case WEIGHT:
 		if (CHANGED(data, "", "")) {
-			ws->weight.grams = string_to_grams(vString.toUtf8().data());
+			ws->weight.grams = stringToGrams(vString.toUtf8().data());
 			// now update the ws_info
 			changed = true;
 			WSInfoModel *wsim = WSInfoModel::instance();
diff --git a/qt-ui/models.h b/qt-ui/models.h
index baa7b32..fc3690c 100644
--- a/qt-ui/models.h
+++ b/qt-ui/models.h
@@ -124,6 +124,7 @@ public:
 	void update();
 	void setDive(struct dive *d);
 	weightsystem_t *weightSystemAt(const QModelIndex& index);
+	double stringToGrams(char *str) const;
 	bool changed;
 
 public slots:
-- 
1.7.11.msysgit.0



More information about the subsurface mailing list