diff --git a/backend-shared/exportfuncs.cpp b/backend-shared/exportfuncs.cpp
index 7f5a237f7..b2ac25469 100644
--- a/backend-shared/exportfuncs.cpp
+++ b/backend-shared/exportfuncs.cpp
@@ -174,9 +174,9 @@ void export_TeX(const char *filename, bool selected_only, bool plain, ExportCall
put_format(&buf, "\\def\\%shour{%02u}\n", ssrf, tm.tm_hour);
put_format(&buf, "\\def\\%sminute{%02u}\n", ssrf, tm.tm_min);
put_format(&buf, "\\def\\%snumber{%d}\n", ssrf, dive->number);
- put_format(&buf, "\\def\\%splace{%s}\n", ssrf, site ? site->name : "");
+ put_format(&buf, "\\def\\%splace{%s}\n", ssrf, site ? site->name.c_str() : "");
put_format(&buf, "\\def\\%sspot{}\n", ssrf);
- put_format(&buf, "\\def\\%ssitename{%s}\n", ssrf, site ? site->name : "");
+ put_format(&buf, "\\def\\%ssitename{%s}\n", ssrf, site ? site->name.c_str() : "");
site ? put_format(&buf, "\\def\\%sgpslat{%f}\n", ssrf, site->location.lat.udeg / 1000000.0) : put_format(&buf, "\\def\\%sgpslat{}\n", ssrf);
site ? put_format(&buf, "\\def\\%sgpslon{%f}\n", ssrf, site->location.lon.udeg / 1000000.0) : put_format(&buf, "\\def\\gpslon{}\n");
put_format(&buf, "\\def\\%scomputer{%s}\n", ssrf, dive->dc.model);
@@ -251,7 +251,7 @@ void export_TeX(const char *filename, bool selected_only, bool plain, ExportCall
// Legacy fields
put_format(&buf, "\\def\\%sspot{}\n", ssrf);
put_format(&buf, "\\def\\%sentrance{}\n", ssrf);
- put_format(&buf, "\\def\\%splace{%s}\n", ssrf, site ? site->name : "");
+ put_format(&buf, "\\def\\%splace{%s}\n", ssrf, site ? site->name.c_str() : "");
dive->maxdepth.mm ? put_format(&buf, "\\def\\%sdepth{%.1f\\%sdepthunit}\n", ssrf, get_depth_units(dive->maxdepth.mm, NULL, &unit), ssrf) : put_format(&buf, "\\def\\%sdepth{}\n", ssrf);
put_format(&buf, "\\%spage\n", ssrf);
diff --git a/commands/command_divesite.cpp b/commands/command_divesite.cpp
index d942ba277..1188e9f81 100644
--- a/commands/command_divesite.cpp
+++ b/commands/command_divesite.cpp
@@ -76,7 +76,7 @@ AddDiveSite::AddDiveSite(const QString &name)
{
setText(Command::Base::tr("add dive site"));
sitesToAdd.push_back(std::make_unique());
- sitesToAdd.back()->name = copy_qstring(name);
+ sitesToAdd.back()->name = name.toStdString();
}
bool AddDiveSite::workToBeDone()
@@ -175,24 +175,15 @@ void PurgeUnusedDiveSites::undo()
sitesToRemove = addDiveSites(sitesToAdd);
}
-// Helper function: swap C and Qt string
-static void swap(char *&c, QString &q)
-{
- QString s = c;
- free(c);
- c = copy_qstring(q);
- q = s;
-}
-
EditDiveSiteName::EditDiveSiteName(dive_site *dsIn, const QString &name) : ds(dsIn),
- value(name)
+ value(name.toStdString())
{
setText(Command::Base::tr("Edit dive site name"));
}
bool EditDiveSiteName::workToBeDone()
{
- return value != QString(ds->name);
+ return value != ds->name;
}
void EditDiveSiteName::redo()
@@ -208,14 +199,14 @@ void EditDiveSiteName::undo()
}
EditDiveSiteDescription::EditDiveSiteDescription(dive_site *dsIn, const QString &description) : ds(dsIn),
- value(description)
+ value(description.toStdString())
{
setText(Command::Base::tr("Edit dive site description"));
}
bool EditDiveSiteDescription::workToBeDone()
{
- return value != QString(ds->description);
+ return value != ds->description;
}
void EditDiveSiteDescription::redo()
@@ -231,14 +222,14 @@ void EditDiveSiteDescription::undo()
}
EditDiveSiteNotes::EditDiveSiteNotes(dive_site *dsIn, const QString ¬es) : ds(dsIn),
- value(notes)
+ value(notes.toStdString())
{
setText(Command::Base::tr("Edit dive site notes"));
}
bool EditDiveSiteNotes::workToBeDone()
{
- return value != QString(ds->notes);
+ return value != ds->notes;
}
void EditDiveSiteNotes::redo()
@@ -400,7 +391,7 @@ ApplyGPSFixes::ApplyGPSFixes(const std::vector &fixes)
siteLocations.push_back({ ds, dl.location });
}
} else {
- ds = create_dive_site(qPrintable(dl.name), divelog.sites);
+ ds = create_dive_site(dl.name.toStdString(), divelog.sites);
ds->location = dl.location;
add_dive_to_dive_site(dl.d, ds);
dl.d->dive_site = nullptr; // This will be set on redo()
diff --git a/commands/command_divesite.h b/commands/command_divesite.h
index b40ee2908..655f75a62 100644
--- a/commands/command_divesite.h
+++ b/commands/command_divesite.h
@@ -89,7 +89,7 @@ private:
void redo() override;
dive_site *ds;
- QString value; // Value to be set
+ std::string value; // Value to be set
};
class EditDiveSiteDescription : public Base {
@@ -101,7 +101,7 @@ private:
void redo() override;
dive_site *ds;
- QString value; // Value to be set
+ std::string value; // Value to be set
};
class EditDiveSiteNotes : public Base {
@@ -113,7 +113,7 @@ private:
void redo() override;
dive_site *ds;
- QString value; // Value to be set
+ std::string value; // Value to be set
};
class EditDiveSiteCountry : public Base {
diff --git a/commands/command_edit.cpp b/commands/command_edit.cpp
index 6c3ea9da2..ef5efaa1c 100644
--- a/commands/command_edit.cpp
+++ b/commands/command_edit.cpp
@@ -374,14 +374,11 @@ void EditDiveSite::redo()
EditDiveSite::undo(); // Undo and redo do the same
}
-static struct dive_site *createDiveSite(const QString &name)
+static struct dive_site *createDiveSite(const std::string &name)
{
struct dive_site *ds = new dive_site;
- struct dive_site *old = current_dive ? current_dive->dive_site : nullptr;
- if (old) {
- copy_dive_site(old, ds);
- free(ds->name); // Free name, as we will overwrite it with our own version
- }
+ if (current_dive && current_dive->dive_site)
+ *ds = *current_dive->dive_site;
// If the current dive has a location, use that as location for the new dive site
if (current_dive) {
@@ -390,12 +387,12 @@ static struct dive_site *createDiveSite(const QString &name)
ds->location = loc;
}
- ds->name = copy_qstring(name);
+ ds->name = name;
return ds;
}
EditDiveSiteNew::EditDiveSiteNew(const QString &newName, bool currentDiveOnly) :
- EditDiveSite(createDiveSite(newName), currentDiveOnly),
+ EditDiveSite(createDiveSite(newName.toStdString()), currentDiveOnly),
diveSiteToAdd(value),
diveSiteToRemove(nullptr)
{
diff --git a/core/datatrak.cpp b/core/datatrak.cpp
index f77fa3c57..05b5aa5c9 100644
--- a/core/datatrak.cpp
+++ b/core/datatrak.cpp
@@ -170,7 +170,6 @@ static char *dt_dive_parser(unsigned char *runner, struct dive *dt_dive, struct
unsigned char tmp_1byte;
unsigned int tmp_2bytes;
unsigned long tmp_4bytes;
- struct dive_site *ds;
char is_nitrox = 0, is_O2 = 0, is_SCR = 0;
device_data_t devdata;
@@ -212,11 +211,13 @@ static char *dt_dive_parser(unsigned char *runner, struct dive *dt_dive, struct
* Subsurface only have a location variable, so we have to merge DTrak's
* Locality and Dive points.
*/
- snprintf(buffer, sizeof(buffer), "%s, %s", locality, dive_point);
- ds = get_dive_site_by_name(buffer, log->sites);
- if (!ds)
- ds = create_dive_site(buffer, log->sites);
- add_dive_to_dive_site(dt_dive, ds);
+ {
+ std::string buffer2 = std::string((char *)locality) + " " + (char *)dive_point;
+ struct dive_site *ds = get_dive_site_by_name(buffer2, log->sites);
+ if (!ds)
+ ds = create_dive_site(buffer2, log->sites);
+ add_dive_to_dive_site(dt_dive, ds);
+ }
free(locality);
locality = NULL;
free(dive_point);
diff --git a/core/dive.cpp b/core/dive.cpp
index 47718bc03..888f92ef5 100644
--- a/core/dive.cpp
+++ b/core/dive.cpp
@@ -3341,12 +3341,10 @@ std::string get_dive_country(const struct dive *dive)
return ds ? taxonomy_get_country(ds->taxonomy) : std::string();
}
-extern "C" const char *get_dive_location(const struct dive *dive)
+std::string get_dive_location(const struct dive *dive)
{
const struct dive_site *ds = dive->dive_site;
- if (ds && ds->name)
- return ds->name;
- return NULL;
+ return ds ? ds->name : std::string();
}
extern "C" unsigned int number_of_computers(const struct dive *dive)
diff --git a/core/dive.h b/core/dive.h
index ec326e40b..9029f7442 100644
--- a/core/dive.h
+++ b/core/dive.h
@@ -118,9 +118,9 @@ extern struct dive_site *get_dive_site_for_dive(const struct dive *dive);
#ifdef __cplusplus
} // TODO: remove
extern std::string get_dive_country(const struct dive *dive);
+extern std::string get_dive_location(const struct dive *dive);
extern "C" {
#endif
-extern const char *get_dive_location(const struct dive *dive);
extern unsigned int number_of_computers(const struct dive *dive);
extern struct divecomputer *get_dive_dc(struct dive *dive, int nr);
extern const struct divecomputer *get_dive_dc_const(const struct dive *dive, int nr);
diff --git a/core/divesite.cpp b/core/divesite.cpp
index 2f9c0846a..2b2a5b448 100644
--- a/core/divesite.cpp
+++ b/core/divesite.cpp
@@ -5,6 +5,7 @@
#include "divelist.h"
#include "divelog.h"
#include "errorhelper.h"
+#include "format.h"
#include "gettextfromc.h"
#include "membuffer.h"
#include "pref.h"
@@ -39,12 +40,12 @@ struct dive_site *get_dive_site_by_uuid(uint32_t uuid, struct dive_site_table *d
}
/* there could be multiple sites of the same name - return the first one */
-struct dive_site *get_dive_site_by_name(const char *name, struct dive_site_table *ds_table)
+struct dive_site *get_dive_site_by_name(const std::string &name, struct dive_site_table *ds_table)
{
int i;
struct dive_site *ds;
for_each_dive_site (i, ds, ds_table) {
- if (same_string(ds->name, name))
+ if (ds->name == name)
return ds;
}
return NULL;
@@ -65,12 +66,12 @@ struct dive_site *get_dive_site_by_gps(const location_t *loc, struct dive_site_t
/* to avoid a bug where we have two dive sites with different name and the same GPS coordinates
* and first get the gps coordinates (reading a V2 file) and happen to get back "the other" name,
* this function allows us to verify if a very specific name/GPS combination already exists */
-struct dive_site *get_dive_site_by_gps_and_name(const char *name, const location_t *loc, struct dive_site_table *ds_table)
+struct dive_site *get_dive_site_by_gps_and_name(const std::string &name, const location_t *loc, struct dive_site_table *ds_table)
{
int i;
struct dive_site *ds;
for_each_dive_site (i, ds, ds_table) {
- if (same_location(loc, &ds->location) && same_string(ds->name, name))
+ if (same_location(loc, &ds->location) && ds->name == name)
return ds;
}
return NULL;
@@ -146,12 +147,12 @@ int add_dive_site_to_table(struct dive_site *ds, struct dive_site_table *ds_tabl
* Make this deterministic for testing. */
if (!ds->uuid) {
SHA1 sha;
- if (ds->name)
- sha.update(ds->name, strlen(ds->name));
- if (ds->description)
- sha.update(ds->description, strlen(ds->description));
- if (ds->notes)
- sha.update(ds->notes, strlen(ds->notes));
+ if (!ds->name.empty())
+ sha.update(ds->name);
+ if (!ds->description.empty())
+ sha.update(ds->description);
+ if (!ds->notes.empty())
+ sha.update(ds->notes);
ds->uuid = sha.hash_uint32();
}
@@ -169,19 +170,16 @@ dive_site::dive_site()
{
}
-dive_site::dive_site(const char *name) : name(copy_string(name))
+dive_site::dive_site(const std::string &name) : name(name)
{
}
-dive_site::dive_site(const char *name, const location_t *loc) : name(copy_string(name)), location(*loc)
+dive_site::dive_site(const std::string &name, const location_t *loc) : name(name), location(*loc)
{
}
dive_site::~dive_site()
{
- free(name);
- free(notes);
- free(description);
}
/* when parsing, dive sites are identified by uuid */
@@ -225,7 +223,7 @@ void delete_dive_site(struct dive_site *ds, struct dive_site_table *ds_table)
}
/* allocate a new site and add it to the table */
-struct dive_site *create_dive_site(const char *name, struct dive_site_table *ds_table)
+struct dive_site *create_dive_site(const std::string &name, struct dive_site_table *ds_table)
{
struct dive_site *ds = new dive_site(name);
add_dive_site_to_table(ds, ds_table);
@@ -233,7 +231,7 @@ struct dive_site *create_dive_site(const char *name, struct dive_site_table *ds_
}
/* same as before, but with GPS data */
-struct dive_site *create_dive_site_with_gps(const char *name, const location_t *loc, struct dive_site_table *ds_table)
+struct dive_site *create_dive_site_with_gps(const std::string &name, const location_t *loc, struct dive_site_table *ds_table)
{
struct dive_site *ds = new dive_site(name, loc);
add_dive_site_to_table(ds, ds_table);
@@ -244,42 +242,26 @@ struct dive_site *create_dive_site_with_gps(const char *name, const location_t *
bool dive_site_is_empty(struct dive_site *ds)
{
return !ds ||
- (empty_string(ds->name) &&
- empty_string(ds->description) &&
- empty_string(ds->notes) &&
- !has_location(&ds->location));
+ (ds->name.empty() &&
+ ds->description.empty() &&
+ ds->notes.empty() &&
+ !has_location(&ds->location));
}
-void copy_dive_site(struct dive_site *orig, struct dive_site *copy)
+static void merge_string(std::string &a, const std::string &b)
{
- free(copy->name);
- free(copy->notes);
- free(copy->description);
-
- copy->location = orig->location;
- copy->name = copy_string(orig->name);
- copy->notes = copy_string(orig->notes);
- copy->description = copy_string(orig->description);
- copy->taxonomy = orig->taxonomy;
-}
-
-static void merge_string(char **a, char **b)
-{
- char *s1 = *a, *s2 = *b;
-
- if (!s2)
+ if (b.empty())
return;
- if (same_string(s1, s2))
+ if (a == b)
return;
- if (!s1) {
- *a = strdup(s2);
+ if (a.empty()) {
+ a = b;
return;
}
- *a = format_string("(%s) or (%s)", s1, s2);
- free(s1);
+ a = format_string_std("(%s) or (%s)", a.c_str(), b.c_str());
}
/* Used to check on import if two dive sites are equivalent.
@@ -290,10 +272,10 @@ static void merge_string(char **a, char **b)
*/
static bool same_dive_site(const struct dive_site *a, const struct dive_site *b)
{
- return same_string(a->name, b->name)
+ return a->name == b->name
&& same_location(&a->location, &b->location)
- && same_string(a->description, b->description)
- && same_string(a->notes, b->notes);
+ && a->description == b->description
+ && a->notes == b->notes;
}
struct dive_site *get_same_dive_site(const struct dive_site *site)
@@ -309,20 +291,20 @@ struct dive_site *get_same_dive_site(const struct dive_site *site)
void merge_dive_site(struct dive_site *a, struct dive_site *b)
{
if (!has_location(&a->location)) a->location = b->location;
- merge_string(&a->name, &b->name);
- merge_string(&a->notes, &b->notes);
- merge_string(&a->description, &b->description);
+ merge_string(a->name, b->name);
+ merge_string(a->notes, b->notes);
+ merge_string(a->description, b->description);
if (a->taxonomy.empty())
a->taxonomy = std::move(b->taxonomy);
}
-struct dive_site *find_or_create_dive_site_with_name(const char *name, struct dive_site_table *ds_table)
+struct dive_site *find_or_create_dive_site_with_name(const std::string &name, struct dive_site_table *ds_table)
{
int i;
struct dive_site *ds;
for_each_dive_site(i,ds, ds_table) {
- if (same_string(name, ds->name))
+ if (name == ds->name)
break;
}
if (ds)
diff --git a/core/divesite.h b/core/divesite.h
index 550d19b0a..dd10819ce 100644
--- a/core/divesite.h
+++ b/core/divesite.h
@@ -13,15 +13,15 @@
struct dive_site
{
uint32_t uuid = 0;
- char *name = nullptr;
+ std::string name;
std::vector dives;
location_t location = { { 9 }, { 0 } };
- char *description = nullptr;
- char *notes = nullptr;
+ std::string description;
+ std::string notes;
taxonomy_data taxonomy;
dive_site();
- dive_site(const char *name);
- dive_site(const char *name, const location_t *loc);
+ dive_site(const std::string &name);
+ dive_site(const std::string &name, const location_t *loc);
~dive_site();
};
@@ -54,19 +54,17 @@ bool is_dive_site_selected(const struct dive_site &ds);
int unregister_dive_site(struct dive_site *ds);
int register_dive_site(struct dive_site *ds);
void delete_dive_site(struct dive_site *ds, struct dive_site_table *ds_table);
-struct dive_site *create_dive_site(const char *name, struct dive_site_table *ds_table);
-struct dive_site *create_dive_site_with_gps(const char *name, const location_t *, struct dive_site_table *ds_table);
-struct dive_site *get_dive_site_by_name(const char *name, struct dive_site_table *ds_table);
+struct dive_site *create_dive_site(const std::string &name, struct dive_site_table *ds_table);
+struct dive_site *create_dive_site_with_gps(const std::string &name, const location_t *, struct dive_site_table *ds_table);
+struct dive_site *get_dive_site_by_name(const std::string &name, struct dive_site_table *ds_table);
struct dive_site *get_dive_site_by_gps(const location_t *, struct dive_site_table *ds_table);
-struct dive_site *get_dive_site_by_gps_and_name(const char *name, const location_t *, struct dive_site_table *ds_table);
+struct dive_site *get_dive_site_by_gps_and_name(const std::string &name, const location_t *, struct dive_site_table *ds_table);
struct dive_site *get_dive_site_by_gps_proximity(const location_t *, int distance, struct dive_site_table *ds_table);
struct dive_site *get_same_dive_site(const struct dive_site *);
bool dive_site_is_empty(struct dive_site *ds);
-void copy_dive_site_taxonomy(struct dive_site *orig, struct dive_site *copy);
-void copy_dive_site(struct dive_site *orig, struct dive_site *copy);
void merge_dive_site(struct dive_site *a, struct dive_site *b);
unsigned int get_distance(const location_t *loc1, const location_t *loc2);
-struct dive_site *find_or_create_dive_site_with_name(const char *name, struct dive_site_table *ds_table);
+struct dive_site *find_or_create_dive_site_with_name(const std::string &name, struct dive_site_table *ds_table);
void purge_empty_dive_sites(struct dive_site_table *ds_table);
void clear_dive_site_table(struct dive_site_table *ds_table);
void move_dive_site_table(struct dive_site_table *src, struct dive_site_table *dst);
diff --git a/core/filterconstraint.cpp b/core/filterconstraint.cpp
index 487d1a1b1..e81752d0c 100644
--- a/core/filterconstraint.cpp
+++ b/core/filterconstraint.cpp
@@ -841,7 +841,7 @@ static bool has_locations(const filter_constraint &c, const struct dive *d)
diveLocations.push_back(QString(d->divetrip->location).trimmed());
if (d->dive_site)
- diveLocations.push_back(QString(d->dive_site->name).trimmed());
+ diveLocations.push_back(QString::fromStdString(d->dive_site->name).trimmed());
return check(c, diveLocations);
}
diff --git a/core/fulltext.cpp b/core/fulltext.cpp
index 101ac876f..64899b647 100644
--- a/core/fulltext.cpp
+++ b/core/fulltext.cpp
@@ -140,7 +140,7 @@ static std::vector getWords(const dive *d)
// TODO: We should tokenize all dive-sites and trips first and then
// take the tokens from a cache.
if (d->dive_site) {
- tokenize(d->dive_site->name, res);
+ tokenize(QString::fromStdString(d->dive_site->name), res);
std::string country = taxonomy_get_country(d->dive_site->taxonomy);
if (!country.empty())
tokenize(country.c_str(), res);
diff --git a/core/import-cobalt.cpp b/core/import-cobalt.cpp
index e0fcefa8e..093232328 100644
--- a/core/import-cobalt.cpp
+++ b/core/import-cobalt.cpp
@@ -181,15 +181,8 @@ static int cobalt_dive(void *param, int, char **data, char **)
}
if (location && location_site) {
- char *tmp = (char *)malloc(strlen(location) + strlen(location_site) + 4);
- if (!tmp) {
- free(location);
- free(location_site);
- return 1;
- }
- sprintf(tmp, "%s / %s", location, location_site);
+ std::string tmp = std::string(location) + " / " + location_site;
add_dive_to_dive_site(state->cur_dive, find_or_create_dive_site_with_name(tmp, state->log->sites));
- free(tmp);
}
free(location);
free(location_site);
@@ -206,7 +199,6 @@ static int cobalt_dive(void *param, int, char **data, char **)
return SQLITE_OK;
}
-
extern "C" int parse_cobalt_buffer(sqlite3 *handle, const char *url, const char *, int, struct divelog *log)
{
int retval;
diff --git a/core/import-divinglog.cpp b/core/import-divinglog.cpp
index 545c26c31..04b0a9a3a 100644
--- a/core/import-divinglog.cpp
+++ b/core/import-divinglog.cpp
@@ -275,7 +275,7 @@ static int divinglog_dive(void *param, int, char **data, char **)
state->cur_dive->when = (time_t)(atol(data[1]));
if (data[2])
- add_dive_to_dive_site(state->cur_dive, find_or_create_dive_site_with_name(data[2], state->log->sites));
+ add_dive_to_dive_site(state->cur_dive, find_or_create_dive_site_with_name(std::string(data[2]), state->log->sites));
if (data[3])
utf8_string(data[3], &state->cur_dive->buddy);
diff --git a/core/libdivecomputer.cpp b/core/libdivecomputer.cpp
index 081218f16..bd86f38c5 100644
--- a/core/libdivecomputer.cpp
+++ b/core/libdivecomputer.cpp
@@ -637,7 +637,7 @@ static void parse_string_field(device_data_t *devdata, struct dive *dive, dc_fie
if (location.lat.udeg && location.lon.udeg) {
unregister_dive_from_dive_site(dive);
- add_dive_to_dive_site(dive, create_dive_site_with_gps(str->value, &location, devdata->log->sites));
+ add_dive_to_dive_site(dive, create_dive_site_with_gps(std::string(str->value), &location, devdata->log->sites));
}
}
}
diff --git a/core/liquivision.cpp b/core/liquivision.cpp
index f748a2de6..64d9338c2 100644
--- a/core/liquivision.cpp
+++ b/core/liquivision.cpp
@@ -191,7 +191,7 @@ static void parse_dives(int log_version, const unsigned char *buf, unsigned int
/* Store the location only if we have one */
if (!location.empty())
- add_dive_to_dive_site(dive, find_or_create_dive_site_with_name(location.c_str(), sites));
+ add_dive_to_dive_site(dive, find_or_create_dive_site_with_name(location, sites));
ptr += len + 4 + place_len;
diff --git a/core/load-git.cpp b/core/load-git.cpp
index 8ff71b990..f5e786c83 100644
--- a/core/load-git.cpp
+++ b/core/load-git.cpp
@@ -178,7 +178,7 @@ static void parse_dive_gps(char *line, struct git_parser_state *state)
if (!ds) {
ds = get_dive_site_by_gps(&location, state->log->sites);
if (!ds)
- ds = create_dive_site_with_gps("", &location, state->log->sites);
+ ds = create_dive_site_with_gps(std::string(), &location, state->log->sites);
add_dive_to_dive_site(state->active_dive, ds);
} else {
if (dive_site_has_gps_location(ds) && !same_location(&ds->location, &location)) {
@@ -189,10 +189,8 @@ static void parse_dive_gps(char *line, struct git_parser_state *state)
// note 2: we could include the first newline in the
// translation string, but that would be weird and cause
// a new string.
- std::string new_text = std::string(ds->notes) + '\n' +
- format_string_std(translate("gettextFromC", "multiple GPS locations for this dive site; also %s\n"), coords.c_str());
- free(ds->notes);
- ds->notes = strdup(new_text.c_str());
+ ds->notes += '\n';
+ ds->notes += format_string_std(translate("gettextFromC", "multiple GPS locations for this dive site; also %s\n"), coords.c_str());
}
ds->location = location;
}
@@ -224,21 +222,19 @@ static void parse_dive_location(char *, struct git_parser_state *state)
std::string name = get_first_converted_string(state);
struct dive_site *ds = get_dive_site_for_dive(state->active_dive);
if (!ds) {
- ds = get_dive_site_by_name(name.c_str(), state->log->sites);
+ ds = get_dive_site_by_name(name, state->log->sites);
if (!ds)
- ds = create_dive_site(name.c_str(), state->log->sites);
+ ds = create_dive_site(name, state->log->sites);
add_dive_to_dive_site(state->active_dive, ds);
} else {
// we already had a dive site linked to the dive
- if (empty_string(ds->name)) {
- free(ds->name); // empty_string could mean pointer to a 0-byte!
- ds->name = strdup(name.c_str());
+ if (ds->name.empty()) {
+ ds->name = name.c_str();
} else {
// and that dive site had a name. that's weird - if our name is different, add it to the notes
- if (!same_string(ds->name, name.c_str())) {
- std::string new_string = std::string(ds->notes) + '\n' +
- format_string_std(translate("gettextFromC", "additional name for site: %s\n"), name.c_str());
- ds->notes = strdup(new_string.c_str());
+ if (ds->name == name) {
+ ds->notes += '\n';
+ ds->notes += format_string_std(translate("gettextFromC", "additional name for site: %s\n"), name.c_str());
}
}
}
@@ -314,7 +310,7 @@ static void parse_dive_invalid(char *, struct git_parser_state *state)
}
static void parse_site_description(char *, struct git_parser_state *state)
-{ state->active_site->description = get_first_converted_string_c(state); }
+{ state->active_site->description = get_first_converted_string(state); }
static void parse_site_name(char *, struct git_parser_state *state)
{ state->active_site->name = get_first_converted_string_c(state); }
diff --git a/core/parse-xml.cpp b/core/parse-xml.cpp
index f25d4533c..15a15b336 100644
--- a/core/parse-xml.cpp
+++ b/core/parse-xml.cpp
@@ -978,10 +978,9 @@ static void try_to_fill_sample(struct sample *sample, const char *name, char *bu
static void divinglog_place(const char *place, struct dive *d, struct parser_state *state)
{
- char buffer[1024];
struct dive_site *ds;
- snprintf(buffer, sizeof(buffer),
+ std::string buffer = format_string_std(
"%s%s%s%s%s",
place,
!state->city.empty() ? ", " : "",
@@ -1160,10 +1159,11 @@ static void gps_lat(const char *buffer, struct dive *dive, struct parser_state *
location.lat = parse_degrees(buffer, &end);
if (!ds) {
- add_dive_to_dive_site(dive, create_dive_site_with_gps(NULL, &location, state->log->sites));
+ add_dive_to_dive_site(dive, create_dive_site_with_gps(std::string(), &location, state->log->sites));
} else {
if (ds->location.lat.udeg && ds->location.lat.udeg != location.lat.udeg)
- report_info("Oops, changing the latitude of existing dive site id %8x name %s; not good", ds->uuid, ds->name ?: "(unknown)");
+ report_info("Oops, changing the latitude of existing dive site id %8x name %s; not good", ds->uuid,
+ ds->name.empty() ? "(unknown)" : ds->name.c_str());
ds->location.lat = location.lat;
}
}
@@ -1176,10 +1176,11 @@ static void gps_long(const char *buffer, struct dive *dive, struct parser_state
location.lon = parse_degrees(buffer, &end);
if (!ds) {
- add_dive_to_dive_site(dive, create_dive_site_with_gps(NULL, &location, state->log->sites));
+ add_dive_to_dive_site(dive, create_dive_site_with_gps(std::string(), &location, state->log->sites));
} else {
if (ds->location.lon.udeg && ds->location.lon.udeg != location.lon.udeg)
- report_info("Oops, changing the longitude of existing dive site id %8x name %s; not good", ds->uuid, ds->name ?: "(unknown)");
+ report_info("Oops, changing the longitude of existing dive site id %8x name %s; not good", ds->uuid,
+ ds->name.empty() ? "(unknown)" : ds->name.c_str());
ds->location.lon = location.lon;
}
}
@@ -1213,7 +1214,7 @@ static void gps_in_dive(const char *buffer, struct dive *dive, struct parser_sta
// remember the original coordinates so we can create the correct dive site later
state->cur_location = location;
} else {
- ds = create_dive_site_with_gps("", &location, state->log->sites);
+ ds = create_dive_site_with_gps(std::string(), &location, state->log->sites);
}
add_dive_to_dive_site(dive, ds);
} else {
@@ -1224,7 +1225,8 @@ static void gps_in_dive(const char *buffer, struct dive *dive, struct parser_sta
ds->location.lat.udeg / 1000000.0, ds->location.lon.udeg / 1000000.0,
location.lat.udeg / 1000000.0, location.lon.udeg / 1000000.0);
std::string coords = printGPSCoordsC(&location);
- ds->notes = add_to_string(ds->notes, translate("gettextFromC", "multiple GPS locations for this dive site; also %s\n"), coords.c_str());
+ ds->notes += '\n';
+ ds->notes += format_string_std(translate("gettextFromC", "multiple GPS locations for this dive site; also %s\n"), coords.c_str());
} else {
ds->location = location;
}
@@ -1417,11 +1419,11 @@ static void try_to_fill_dive_site(struct parser_state *state, const char *name,
if (MATCH("uuid", hex_value, &ds->uuid))
return;
- if (MATCH("name", utf8_string, &ds->name))
+ if (MATCH("name", utf8_string_std, &ds->name))
return;
- if (MATCH("description", utf8_string, &ds->description))
+ if (MATCH("description", utf8_string_std, &ds->description))
return;
- if (MATCH("notes", utf8_string, &ds->notes))
+ if (MATCH("notes", utf8_string_std, &ds->notes))
return;
if (MATCH("gps", gps_location, ds.get()))
return;
@@ -1802,6 +1804,7 @@ static timestamp_t parse_dlf_timestamp(unsigned char *buffer)
extern "C" int parse_dlf_buffer(unsigned char *buffer, size_t size, struct divelog *log)
{
+ using namespace std::string_literals;
unsigned char *ptr = buffer;
unsigned char event;
bool found;
@@ -2232,7 +2235,7 @@ extern "C" int parse_dlf_buffer(unsigned char *buffer, size_t size, struct divel
/* Measure GPS */
state.cur_location.lat.udeg = (int)((ptr[7] << 24) + (ptr[6] << 16) + (ptr[5] << 8) + (ptr[4] << 0));
state.cur_location.lon.udeg = (int)((ptr[11] << 24) + (ptr[10] << 16) + (ptr[9] << 8) + (ptr[8] << 0));
- add_dive_to_dive_site(state.cur_dive, create_dive_site_with_gps("DLF imported", &state.cur_location, state.log->sites));
+ add_dive_to_dive_site(state.cur_dive, create_dive_site_with_gps("DLF imported"s, &state.cur_location, state.log->sites));
break;
default:
break;
diff --git a/core/parse.cpp b/core/parse.cpp
index bb493d5a5..d3d36b766 100644
--- a/core/parse.cpp
+++ b/core/parse.cpp
@@ -12,6 +12,7 @@
#include "divelog.h"
#include "divesite.h"
#include "errorhelper.h"
+#include "format.h"
#include "sample.h"
#include "subsurface-string.h"
#include "picture.h"
@@ -203,7 +204,7 @@ void dive_site_end(struct parser_state *state)
merge_dive_site(ds, state->cur_dive_site.get());
if (verbose > 3)
- printf("completed dive site uuid %x8 name {%s}\n", ds->uuid, ds->name);
+ printf("completed dive site uuid %x8 name {%s}\n", ds->uuid, ds->name.c_str());
state->cur_dive_site.reset();
}
@@ -470,18 +471,18 @@ void add_dive_site(const char *ds_name, struct dive *dive, struct parser_state *
struct dive_site *ds = dive->dive_site;
if (!ds) {
// if the dive doesn't have a dive site, check if there's already a dive site by this name
- ds = get_dive_site_by_name(trimmed.c_str(), state->log->sites);
+ ds = get_dive_site_by_name(trimmed, state->log->sites);
}
if (ds) {
// we have a dive site, let's hope there isn't a different name
- if (empty_string(ds->name)) {
- ds->name = copy_string(trimmed.c_str());
+ if (ds->name.empty()) {
+ ds->name = trimmed;
} else if (trimmed != ds->name) {
// if it's not the same name, it's not the same dive site
// but wait, we could have gotten this one based on GPS coords and could
// have had two different names for the same site... so let's search the other
// way around
- struct dive_site *exact_match = get_dive_site_by_gps_and_name(trimmed.c_str(), &ds->location, state->log->sites);
+ struct dive_site *exact_match = get_dive_site_by_gps_and_name(trimmed, &ds->location, state->log->sites);
if (exact_match) {
unregister_dive_from_dive_site(dive);
add_dive_to_dive_site(dive, exact_match);
@@ -495,7 +496,8 @@ void add_dive_site(const char *ds_name, struct dive *dive, struct parser_state *
} else {
newds->location = ds->location;
}
- newds->notes = add_to_string(newds->notes, translate("gettextFromC", "additional name for site: %s\n"), ds->name);
+ newds->notes += '\n';
+ newds->notes += format_string_std(translate("gettextFromC", "additional name for site: %s\n"), ds->name.c_str());
}
} else if (dive->dive_site != ds) {
// add the existing dive site to the current dive
@@ -503,7 +505,7 @@ void add_dive_site(const char *ds_name, struct dive *dive, struct parser_state *
add_dive_to_dive_site(dive, ds);
}
} else {
- add_dive_to_dive_site(dive, create_dive_site(trimmed.c_str(), state->log->sites));
+ add_dive_to_dive_site(dive, create_dive_site(trimmed, state->log->sites));
}
}
}
diff --git a/core/save-git.cpp b/core/save-git.cpp
index dbc4a21bb..c38fc1b03 100644
--- a/core/save-git.cpp
+++ b/core/save-git.cpp
@@ -929,9 +929,9 @@ static void save_divesites(git_repository *repo, struct dir *tree)
struct dive_site *ds = get_dive_site(i, divelog.sites);
struct membufferpp site_file_name;
put_format(&site_file_name, "Site-%08x", ds->uuid);
- show_utf8(&b, "name ", ds->name, "\n");
- show_utf8(&b, "description ", ds->description, "\n");
- show_utf8(&b, "notes ", ds->notes, "\n");
+ show_utf8(&b, "name ", ds->name.c_str(), "\n");
+ show_utf8(&b, "description ", ds->description.c_str(), "\n");
+ show_utf8(&b, "notes ", ds->notes.c_str(), "\n");
put_location(&b, &ds->location, "gps ", "\n");
for (const auto &t: ds->taxonomy) {
if (t.category != TC_NONE && !t.value.empty()) {
@@ -1142,15 +1142,17 @@ static void create_commit_message(struct membuffer *msg, bool create_empty)
put_format(msg, "Changes made: \n\n%s\n", changes_made.c_str());
} else if (dive) {
dive_trip_t *trip = dive->divetrip;
- const char *location = get_dive_location(dive) ? : "no location";
+ std::string location = get_dive_location(dive);
+ if (location.empty())
+ location = "no location";
struct divecomputer *dc = &dive->dc;
const char *sep = "\n";
if (dive->number)
nr = dive->number;
- put_format(msg, "dive %d: %s", nr, location);
- if (trip && !empty_string(trip->location) && strcmp(trip->location, location))
+ put_format(msg, "dive %d: %s", nr, location.c_str());
+ if (trip && !empty_string(trip->location) && location != trip->location)
put_format(msg, " (%s)", trip->location);
put_format(msg, "\n");
do {
diff --git a/core/save-html.cpp b/core/save-html.cpp
index cb1c785e6..c604deca6 100644
--- a/core/save-html.cpp
+++ b/core/save-html.cpp
@@ -355,7 +355,7 @@ static void write_one_dive(struct membuffer *b, struct dive *dive, const char *p
put_format(b, "\"subsurface_number\":%d,", dive->number);
put_HTML_date(b, dive, "\"date\":\"", "\",");
put_HTML_time(b, dive, "\"time\":\"", "\",");
- write_attribute(b, "location", get_dive_location(dive), ", ");
+ write_attribute(b, "location", get_dive_location(dive).c_str(), ", ");
put_HTML_coordinates(b, dive);
put_format(b, "\"rating\":%d,", dive->rating);
put_format(b, "\"visibility\":%d,", dive->visibility);
diff --git a/core/save-xml.cpp b/core/save-xml.cpp
index 9a5d76bd5..941820be4 100644
--- a/core/save-xml.cpp
+++ b/core/save-xml.cpp
@@ -711,11 +711,11 @@ static void save_dives_buffer(struct membuffer *b, bool select_only, bool anonym
continue;
put_format(b, "uuid);
- show_utf8_blanked(b, ds->name, " name='", "'", 1, anonymize);
+ show_utf8_blanked(b, ds->name.c_str(), " name='", "'", 1, anonymize);
put_location(b, &ds->location, " gps='", "'");
- show_utf8_blanked(b, ds->description, " description='", "'", 1, anonymize);
+ show_utf8_blanked(b, ds->description.c_str(), " description='", "'", 1, anonymize);
put_format(b, ">\n");
- show_utf8_blanked(b, ds->notes, " ", " \n", 0, anonymize);
+ show_utf8_blanked(b, ds->notes.c_str(), " ", " \n", 0, anonymize);
for (auto const &t: ds->taxonomy) {
if (t.category != TC_NONE && !t.value.empty()) {
put_format(b, " uuid);
- show_utf8_blanked(b, ds->name, " name='", "'", 1, anonymize);
+ show_utf8_blanked(b, ds->name.c_str(), " name='", "'", 1, anonymize);
put_location(b, &ds->location, " gps='", "'");
- show_utf8_blanked(b, ds->description, " description='", "'", 1, anonymize);
+ show_utf8_blanked(b, ds->description.c_str(), " description='", "'", 1, anonymize);
put_format(b, ">\n");
- show_utf8_blanked(b, ds->notes, " ", " \n", 0, anonymize);
+ show_utf8_blanked(b, ds->notes.c_str(), " ", " \n", 0, anonymize);
for (const auto &t: ds->taxonomy) {
if (t.category != TC_NONE && !t.value.empty()) {
put_format(b, " location = copy_string(get_dive_location(dive));
+ trip->location = copy_string(get_dive_location(dive).c_str());
return trip;
}
@@ -265,8 +265,9 @@ dive_trip_t *get_dives_to_autogroup(struct dive_table *table, int start, int *fr
if (dive->divetrip || dive->notrip ||
dive->when >= lastdive->when + TRIP_THRESHOLD)
break;
- if (get_dive_location(dive) && !trip->location)
- trip->location = copy_string(get_dive_location(dive));
+ std::string location = get_dive_location(dive);
+ if (!location.empty() && !trip->location)
+ trip->location = copy_string(get_dive_location(dive).c_str());
lastdive = dive;
}
return trip;
diff --git a/core/uemis-downloader.cpp b/core/uemis-downloader.cpp
index c6380ae76..496f7e5e7 100644
--- a/core/uemis-downloader.cpp
+++ b/core/uemis-downloader.cpp
@@ -808,6 +808,7 @@ static bool uemis_delete_dive(device_data_t *devdata, uint32_t diveid)
* the addresses of those fields for every dive that references the dive spot. */
static bool process_raw_buffer(device_data_t *devdata, uint32_t deviceid, std::string_view buf, int &max_divenr, int *for_dive)
{
+ using namespace std::string_literals;
bool done = false;
bool is_log = false, is_dive = false;
std::vector sections;
@@ -914,7 +915,7 @@ static bool process_raw_buffer(device_data_t *devdata, uint32_t deviceid, std::s
} else if (!is_log && dive && tag == "divespot_id") {
int divespot_id;
if (from_chars(val, divespot_id).ec != std::errc::invalid_argument) {
- struct dive_site *ds = create_dive_site("from Uemis", devdata->log->sites);
+ struct dive_site *ds = create_dive_site("from Uemis"s, devdata->log->sites);
unregister_dive_from_dive_site(dive);
add_dive_to_dive_site(dive, ds);
uemis_obj.mark_divelocation(dive->dc.diveid, divespot_id, ds);
@@ -1099,17 +1100,16 @@ static void get_uemis_divespot(device_data_t *devdata, const std::string &mountp
struct dive_site *ds = it->second;
unregister_dive_from_dive_site(dive);
add_dive_to_dive_site(dive, ds);
- } else if (nds && nds->name && strstr(nds->name,"from Uemis")) {
+ } else if (nds && !nds->name.empty() && nds->name.find("from Uemis") != std::string::npos) {
if (load_uemis_divespot(mountpath, divespot_id)) {
/* get the divesite based on the diveid, this should give us
* the newly created site
*/
- struct dive_site *ods;
/* with the divesite name we got from parse_dive, that is called on load_uemis_divespot
* we search all existing divesites if we have one with the same name already. The function
* returns the first found which is luckily not the newly created.
*/
- ods = get_dive_site_by_name(nds->name, devdata->log->sites);
+ struct dive_site *ods = get_dive_site_by_name(nds->name, devdata->log->sites);
if (ods) {
/* if the uuid's are the same, the new site is a duplicate and can be deleted */
if (nds->uuid != ods->uuid) {
diff --git a/core/uemis.cpp b/core/uemis.cpp
index 5b224833f..1957d68c5 100644
--- a/core/uemis.cpp
+++ b/core/uemis.cpp
@@ -165,8 +165,7 @@ void uemis::set_divelocation(int divespot, const std::string &text, double longi
if (it.second.divespot == divespot) {
struct dive_site *ds = it.second.dive_site;
if (ds) {
- free(ds->name);
- ds->name = strdup(text.c_str());
+ ds->name = text;
ds->location = create_location(latitude, longitude);
}
}
diff --git a/core/uploadDiveLogsDE.cpp b/core/uploadDiveLogsDE.cpp
index e4660a94f..4cdbb3a2c 100644
--- a/core/uploadDiveLogsDE.cpp
+++ b/core/uploadDiveLogsDE.cpp
@@ -112,7 +112,7 @@ bool uploadDiveLogsDE::prepareDives(const QString &tempfile, bool selected)
if (ds) {
put_format(&mb, "location, " gps='", "'");
put_format(&mb, ">\n");
diff --git a/core/worldmap-save.cpp b/core/worldmap-save.cpp
index 76826da66..8bfa14d66 100644
--- a/core/worldmap-save.cpp
+++ b/core/worldmap-save.cpp
@@ -61,7 +61,7 @@ static void writeMarkers(struct membuffer *b, bool selected_only)
put_HTML_watertemp(b, dive, " ", "
");
pre = format_string_std("%s ", translate("gettextFromC", "Location:"));
put_string(b, pre.c_str());
- put_HTML_quoted(b, get_dive_location(dive));
+ put_HTML_quoted(b, get_dive_location(dive).c_str());
put_string(b, "
");
pre = format_string_std(" %s ", translate("gettextFromC", "Notes:"));
put_HTML_notes(b, dive, pre.c_str(), "
");
diff --git a/desktop-widgets/divesiteimportdialog.cpp b/desktop-widgets/divesiteimportdialog.cpp
index 3ab94732e..55dfaf7e1 100644
--- a/desktop-widgets/divesiteimportdialog.cpp
+++ b/desktop-widgets/divesiteimportdialog.cpp
@@ -68,7 +68,7 @@ void DivesiteImportDialog::on_ok_clicked()
for (int i = 0; i < importedSites.nr; i++)
if (divesiteImportedModel->data(divesiteImportedModel->index(i, 0), Qt::CheckStateRole) == Qt::Checked) {
struct dive_site *newSite = new dive_site;
- copy_dive_site(importedSites.dive_sites[i], newSite);
+ *newSite = *importedSites.dive_sites[i];
add_dive_site_to_table(newSite, &selectedSites);
}
diff --git a/desktop-widgets/locationinformation.cpp b/desktop-widgets/locationinformation.cpp
index 9acee5072..96a4fcd2e 100644
--- a/desktop-widgets/locationinformation.cpp
+++ b/desktop-widgets/locationinformation.cpp
@@ -129,8 +129,8 @@ void LocationInformationWidget::updateLabels()
clearLabels();
return;
}
- if (diveSite->name)
- ui.diveSiteName->setText(diveSite->name);
+ if (!diveSite->name.empty())
+ ui.diveSiteName->setText(QString::fromStdString(diveSite->name));
else
ui.diveSiteName->clear();
std::string country = taxonomy_get_country(diveSite->taxonomy);
@@ -138,12 +138,12 @@ void LocationInformationWidget::updateLabels()
ui.diveSiteCountry->setText(QString::fromStdString(country));
else
ui.diveSiteCountry->clear();
- if (diveSite->description)
- ui.diveSiteDescription->setText(diveSite->description);
+ if (!diveSite->description.empty())
+ ui.diveSiteDescription->setText(QString::fromStdString(diveSite->description));
else
ui.diveSiteDescription->clear();
- if (diveSite->notes)
- ui.diveSiteNotes->setPlainText(diveSite->notes);
+ if (!diveSite->notes.empty())
+ ui.diveSiteNotes->setPlainText(QString::fromStdString(diveSite->notes));
else
ui.diveSiteNotes->clear();
if (has_location(&diveSite->location))
@@ -172,13 +172,13 @@ void LocationInformationWidget::diveSiteChanged(struct dive_site *ds, int field)
return; // A different dive site was changed -> do nothing.
switch (field) {
case LocationInformationModel::NAME:
- ui.diveSiteName->setText(diveSite->name);
+ ui.diveSiteName->setText(QString::fromStdString(diveSite->name));
return;
case LocationInformationModel::DESCRIPTION:
- ui.diveSiteDescription->setText(diveSite->description);
+ ui.diveSiteDescription->setText(QString::fromStdString(diveSite->description));
return;
case LocationInformationModel::NOTES:
- ui.diveSiteNotes->setText(diveSite->notes);
+ ui.diveSiteNotes->setText(QString::fromStdString(diveSite->notes));
return;
case LocationInformationModel::TAXONOMY:
ui.diveSiteCountry->setText(QString::fromStdString(taxonomy_get_country(diveSite->taxonomy)));
@@ -563,7 +563,7 @@ static struct dive_site *get_dive_site_name_start_which_str(const QString &str)
struct dive_site *ds;
int i;
for_each_dive_site (i, ds, divelog.sites) {
- QString dsName(ds->name);
+ QString dsName = QString::fromStdString(ds->name);
if (dsName.toLower().startsWith(str.toLower()))
return ds;
}
@@ -585,10 +585,10 @@ void DiveLocationLineEdit::setTemporaryDiveSiteName(const QString &name)
// the user entered text.
QString i1_name;
if (struct dive_site *ds = get_dive_site_name_start_which_str(name)) {
- const QString orig_name = QString(ds->name).toLower();
+ const QString orig_name = QString::fromStdString(ds->name).toLower();
const QString new_name = name.toLower();
if (new_name != orig_name)
- i1_name = QString(ds->name);
+ i1_name = QString::fromStdString(ds->name);
}
model->setData(i1, i1_name);
@@ -674,7 +674,7 @@ void DiveLocationLineEdit::setCurrentDiveSite(struct dive *d)
if (!currDs)
clear();
else
- setText(currDs->name);
+ setText(QString::fromStdString(currDs->name));
proxy->setCurrentLocation(currentLocation);
delegate.setCurrentLocation(currentLocation);
}
diff --git a/desktop-widgets/simplewidgets.cpp b/desktop-widgets/simplewidgets.cpp
index ad06e84d9..748820d31 100644
--- a/desktop-widgets/simplewidgets.cpp
+++ b/desktop-widgets/simplewidgets.cpp
@@ -325,7 +325,7 @@ void DiveComponentSelection::buttonClicked(QAbstractButton *button)
QString cliptext;
text.setString(&cliptext);
if (what->divesite && current_dive->dive_site)
- text << tr("Dive site: ") << current_dive->dive_site->name << "\n";
+ text << tr("Dive site: ") << QString::fromStdString(current_dive->dive_site->name) << "\n";
if (what->diveguide)
text << tr("Dive guide: ") << current_dive->diveguide << "\n";
if (what->buddy)
diff --git a/desktop-widgets/templatelayout.cpp b/desktop-widgets/templatelayout.cpp
index ecfde679b..4278ea524 100644
--- a/desktop-widgets/templatelayout.cpp
+++ b/desktop-widgets/templatelayout.cpp
@@ -526,7 +526,7 @@ QVariant TemplateLayout::getValue(QString list, QString property, const State &s
} else if (property == "timestamp") {
return QVariant::fromValue(d->when);
} else if (property == "location") {
- return get_dive_location(d);
+ return QString::fromStdString(get_dive_location(d));
} else if (property == "gps") {
return formatDiveGPS(d);
} else if (property == "gps_decimal") {
diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp
index 685696a4a..2027a673b 100644
--- a/mobile-widgets/qmlmanager.cpp
+++ b/mobile-widgets/qmlmanager.cpp
@@ -1068,9 +1068,9 @@ bool QMLManager::checkLocation(DiveSiteChange &res, struct dive *d, QString loca
{
struct dive_site *ds = get_dive_site_for_dive(d);
bool changed = false;
- QString oldLocation = get_dive_location(d);
+ QString oldLocation = QString::fromStdString(get_dive_location(d));
if (oldLocation != location) {
- ds = get_dive_site_by_name(qPrintable(location), divelog.sites);
+ ds = get_dive_site_by_name(location.toStdString(), divelog.sites);
if (!ds && !location.isEmpty()) {
res.createdDs = std::make_unique(qPrintable(location));
res.changed = true;
@@ -1817,9 +1817,7 @@ QString QMLManager::getVersion() const
QString QMLManager::getGpsFromSiteName(const QString &siteName)
{
- struct dive_site *ds;
-
- ds = get_dive_site_by_name(qPrintable(siteName), divelog.sites);
+ struct dive_site *ds = get_dive_site_by_name(siteName.toStdString(), divelog.sites);
if (!ds)
return QString();
return printGPSCoords(&ds->location);
diff --git a/qt-models/divelocationmodel.cpp b/qt-models/divelocationmodel.cpp
index da6c12885..17e40b250 100644
--- a/qt-models/divelocationmodel.cpp
+++ b/qt-models/divelocationmodel.cpp
@@ -91,11 +91,11 @@ QVariant LocationInformationModel::getDiveSiteData(const struct dive_site *ds, i
case Qt::DisplayRole:
switch(column) {
case DIVESITE: return QVariant::fromValue((dive_site *)ds); // Not nice: casting away const
- case NAME: return QString(ds->name);
+ case NAME: return QString::fromStdString(ds->name);
case NUM_DIVES: return static_cast(ds->dives.size());
case LOCATION: return "TODO";
- case DESCRIPTION: return QString(ds->description);
- case NOTES: return QString(ds->name);
+ case DESCRIPTION: return QString::fromStdString(ds->description);
+ case NOTES: return QString::fromStdString(ds->notes);
case TAXONOMY: return "TODO";
}
break;
@@ -184,7 +184,7 @@ bool DiveSiteSortedModel::filterAcceptsRow(int sourceRow, const QModelIndex &sou
if (sourceRow < 0 || sourceRow > divelog.sites->nr)
return false;
struct dive_site *ds = divelog.sites->dive_sites[sourceRow];
- QString text = QString(ds->name) + QString(ds->description) + QString(ds->notes);
+ QString text = QString::fromStdString(ds->name + ds->description + ds->notes);
return text.contains(fullText, Qt::CaseInsensitive);
}
@@ -200,18 +200,18 @@ bool DiveSiteSortedModel::lessThan(const QModelIndex &i1, const QModelIndex &i2)
switch (i1.column()) {
case LocationInformationModel::NAME:
default:
- return QString::localeAwareCompare(QString(ds1->name), QString(ds2->name)) < 0; // TODO: avoid copy
+ return QString::localeAwareCompare(QString::fromStdString(ds1->name), QString::fromStdString(ds2->name)) < 0; // TODO: avoid copy
case LocationInformationModel::DESCRIPTION: {
- int cmp = QString::localeAwareCompare(QString(ds1->description), QString(ds2->description)); // TODO: avoid copy
+ int cmp = QString::localeAwareCompare(QString::fromStdString(ds1->description), QString::fromStdString(ds2->description)); // TODO: avoid copy
return cmp != 0 ? cmp < 0 :
- QString::localeAwareCompare(QString(ds1->name), QString(ds2->name)) < 0; // TODO: avoid copy
+ QString::localeAwareCompare(QString::fromStdString(ds1->name), QString::fromStdString(ds2->name)) < 0; // TODO: avoid copy
}
case LocationInformationModel::NUM_DIVES: {
int cmp = static_cast(ds1->dives.size()) - static_cast(ds2->dives.size());
// Since by default nr dives is descending, invert sort direction of names, such that
// the names are listed as ascending.
return cmp != 0 ? cmp < 0 :
- QString::localeAwareCompare(QString(ds1->name), QString(ds2->name)) < 0; // TODO: avoid copy
+ QString::localeAwareCompare(QString::fromStdString(ds1->name), QString::fromStdString(ds2->name)) < 0; // TODO: avoid copy
}
}
}
@@ -234,7 +234,7 @@ QStringList DiveSiteSortedModel::allSiteNames() const
report_info("DiveSiteSortedModel::allSiteNames(): invalid index");
continue;
}
- locationNames << QString(divelog.sites->dive_sites[idx]->name);
+ locationNames << QString::fromStdString(divelog.sites->dive_sites[idx]->name);
}
return locationNames;
}
diff --git a/qt-models/divesiteimportmodel.cpp b/qt-models/divesiteimportmodel.cpp
index 4854fbb6b..363a4e7b4 100644
--- a/qt-models/divesiteimportmodel.cpp
+++ b/qt-models/divesiteimportmodel.cpp
@@ -59,7 +59,7 @@ QVariant DivesiteImportedModel::data(const QModelIndex &index, int role) const
if (role == Qt::DisplayRole) {
switch (index.column()) {
case NAME:
- return QString(ds->name);
+ return QString::fromStdString(ds->name);
case LOCATION:
return printGPSCoords(&ds->location);
case COUNTRY:
@@ -70,7 +70,7 @@ QVariant DivesiteImportedModel::data(const QModelIndex &index, int role) const
get_dive_site_by_gps_proximity(&ds->location,
40075000, divelog.sites);
if (nearest_ds)
- return QString(nearest_ds->name);
+ return QString::fromStdString(nearest_ds->name);
else
return QString();
}
diff --git a/qt-models/divetripmodel.cpp b/qt-models/divetripmodel.cpp
index 7a90612e4..e020fdd5b 100644
--- a/qt-models/divetripmodel.cpp
+++ b/qt-models/divetripmodel.cpp
@@ -280,7 +280,7 @@ QVariant DiveTripModelBase::diveData(const struct dive *d, int column, int role)
case MobileListModel::DateTimeRole: return formatDiveDateTime(d);
case MobileListModel::IdRole: return d->id;
case MobileListModel::NumberRole: return d->number;
- case MobileListModel::LocationRole: return get_dive_location(d);
+ case MobileListModel::LocationRole: return QString::fromStdString(get_dive_location(d));
case MobileListModel::DepthRole: return get_depth_string(d->dc.maxdepth.mm, true, true);
case MobileListModel::DurationRole: return formatDiveDuration(d);
case MobileListModel::DepthDurationRole: return QStringLiteral("%1 / %2").arg(get_depth_string(d->dc.maxdepth.mm, true, true),
@@ -357,7 +357,7 @@ QVariant DiveTripModelBase::diveData(const struct dive *d, int column, int role)
case DIVEGUIDE:
return QString(d->diveguide);
case LOCATION:
- return QString(get_dive_location(d));
+ return QString::fromStdString(get_dive_location(d));
case GAS:
return formatDiveGasString(d);
case NOTES:
@@ -1776,7 +1776,7 @@ bool DiveTripModelList::lessThan(const QModelIndex &i1, const QModelIndex &i2) c
case DIVEGUIDE:
return lessThanHelper(strCmp(d1->diveguide, d2->diveguide), row_diff);
case LOCATION:
- return lessThanHelper(strCmp(get_dive_location(d1), get_dive_location(d2)), row_diff);
+ return lessThanHelper(strCmp(get_dive_location(d1).c_str(), get_dive_location(d2).c_str()), row_diff);
case NOTES:
return lessThanHelper(strCmp(d1->notes, d2->notes), row_diff);
case DIVEMODE:
diff --git a/qt-models/maplocationmodel.cpp b/qt-models/maplocationmodel.cpp
index 3cbfbdcc3..82ced53ba 100644
--- a/qt-models/maplocationmodel.cpp
+++ b/qt-models/maplocationmodel.cpp
@@ -17,10 +17,10 @@
// Example:
// Japan/Izu Peninsula/Atami/Chinsen-Aft
// Short name: Chinsen-Aft
-static QString siteMapDisplayName(const char *sitename)
+static QString siteMapDisplayName(const std::string &sitename)
{
const char Separator = '/';
- QString fullname(sitename);
+ QString fullname = QString::fromStdString(sitename);
if (!qPrefDisplay::map_short_names() )
return fullname;
diff --git a/smtk-import/smartrak.cpp b/smtk-import/smartrak.cpp
index 58192683f..4d48bb46c 100644
--- a/smtk-import/smartrak.cpp
+++ b/smtk-import/smartrak.cpp
@@ -347,7 +347,7 @@ static void smtk_wreck_site(MdbHandle *mdb, char *site_idx, struct dive_site *ds
break;
}
}
- concat(&ds->notes, "\n", notes);
+ concat(ds->notes, "\n", notes);
break;
}
}
@@ -423,18 +423,17 @@ static void smtk_build_location(MdbHandle *mdb, char *idx, struct dive_site **lo
concat(str, ", ", table.get_string_view(1)); // Locality
concat(str, ", ", site);
- ds = get_dive_site_by_name(str.c_str(), log->sites);
+ ds = get_dive_site_by_name(str, log->sites);
if (!ds) {
if (!has_location(&loc))
- ds = create_dive_site(str.c_str(), log->sites);
+ ds = create_dive_site(str, log->sites);
else
- ds = create_dive_site_with_gps(str.c_str(), &loc, log->sites);
+ ds = create_dive_site_with_gps(str, &loc, log->sites);
}
*location = ds;
/* Insert site notes */
- free(ds->notes);
- ds->notes = strdup(notes.c_str());
+ ds->notes = notes.c_str();
/* Check if we have a wreck */
smtk_wreck_site(mdb, idx, ds);
diff --git a/stats/statsvariables.cpp b/stats/statsvariables.cpp
index 3f8bacd6f..b705f2716 100644
--- a/stats/statsvariables.cpp
+++ b/stats/statsvariables.cpp
@@ -47,7 +47,7 @@ struct DiveSiteWrapper {
const dive_site *ds;
QString name;
DiveSiteWrapper(const dive_site *ds) : ds(ds),
- name(ds ? ds->name : "")
+ name(ds ? QString::fromStdString(ds->name) : QString())
{
}
bool operator<(const DiveSiteWrapper &d2) const {
diff --git a/tests/testparse.cpp b/tests/testparse.cpp
index eba98d513..d43698856 100644
--- a/tests/testparse.cpp
+++ b/tests/testparse.cpp
@@ -93,7 +93,7 @@ int TestParse::parseDivingLog()
{
// Parsing of DivingLog import from SQLite database
struct dive_site *ds = alloc_or_get_dive_site(0xdeadbeef, divelog.sites);
- ds->name = copy_string("Suomi - - Hälvälä");
+ ds->name = "Suomi - - Hälvälä";
int ret = sqlite3_open(SUBSURFACE_TEST_DATA "/dives/TestDivingLog4.1.1.sql", &_sqlite3_handle);
if (ret == 0)