core: convert divesite strings to std::string

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-05-04 17:18:08 +02:00
parent 3394ce7931
commit 160f06db8d
38 changed files with 181 additions and 222 deletions

View file

@ -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 *>((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<int>(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<int>(ds1->dives.size()) - static_cast<int>(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;
}

View file

@ -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();
}

View file

@ -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:

View file

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