core: turn struct dive string data into std::string

Much easier memory management!

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-05-29 20:40:18 +02:00 committed by bstoeger
parent 2b3d2f1020
commit 3cb04d230b
34 changed files with 208 additions and 313 deletions

View file

@ -28,13 +28,13 @@ void CompletionModelBase::divesChanged(const QVector<dive *> &, DiveField field)
updateModel();
}
static QStringList getCSVList(char *dive::*item)
static QStringList getCSVList(const std::string dive::*item)
{
QSet<QString> set;
struct dive *dive;
int i = 0;
for_each_dive (i, dive) {
QString str(dive->*item);
QString str = QString::fromStdString(dive->*item);
for (const QString &value: str.split(",", SKIP_EMPTY))
set.insert(value.trimmed());
}
@ -69,7 +69,7 @@ QStringList SuitCompletionModel::getStrings()
struct dive *dive;
int i = 0;
for_each_dive (i, dive) {
QString suit(dive->suit);
QString suit = QString::fromStdString(dive->suit);
if (!list.contains(suit))
list.append(suit);
}

View file

@ -1093,7 +1093,7 @@ void DivePlannerPointsModel::updateDiveProfile()
#endif
final_deco_state = plan_deco_state;
}
emit calculatedPlanNotes(QString(d->notes));
emit calculatedPlanNotes(QString::fromStdString(d->notes));
#if DEBUG_PLAN
@ -1268,10 +1268,10 @@ finish:
void DivePlannerPointsModel::computeVariationsDone(QString variations)
{
QString notes = QString(d->notes);
free(d->notes);
d->notes = copy_qstring(notes.replace("VARIATIONS", variations));
emit calculatedPlanNotes(QString(d->notes));
QString notes = QString::fromStdString(d->notes);
notes = notes.replace("VARIATIONS", variations);
d->notes = notes.toStdString();
emit calculatedPlanNotes(notes);
}
void DivePlannerPointsModel::createPlan(bool saveAsNew)
@ -1298,7 +1298,7 @@ void DivePlannerPointsModel::createPlan(bool saveAsNew)
// Try to identify old planner output and remove only this part
// Treat user provided text as plain text.
QTextDocument notesDocument;
notesDocument.setHtml(current_dive->notes);
notesDocument.setHtml(QString::fromStdString(current_dive->notes));
QString oldnotes(notesDocument.toPlainText());
QString disclaimer = get_planner_disclaimer();
int disclaimerMid = disclaimer.indexOf("%s");
@ -1320,8 +1320,8 @@ void DivePlannerPointsModel::createPlan(bool saveAsNew)
}
// Deal with line breaks
oldnotes.replace("\n", "<br>");
oldnotes.append(d->notes);
d->notes = copy_qstring(oldnotes);
oldnotes.append(QString::fromStdString(d->notes));
d->notes = oldnotes.toStdString();
// If we save as new create a copy of the dive here
}

View file

@ -287,13 +287,13 @@ QVariant DiveTripModelBase::diveData(const struct dive *d, int column, int role)
formatDiveDuration(d));
case MobileListModel::RatingRole: return d->rating;
case MobileListModel::VizRole: return d->visibility;
case MobileListModel::SuitRole: return QString(d->suit);
case MobileListModel::SuitRole: return QString::fromStdString(d->suit);
case MobileListModel::AirTempRole: return get_temperature_string(d->airtemp, true);
case MobileListModel::WaterTempRole: return get_temperature_string(d->watertemp, true);
case MobileListModel::SacRole: return formatSac(d);
case MobileListModel::SumWeightRole: return formatSumWeight(d);
case MobileListModel::DiveGuideRole: return QString(d->diveguide);
case MobileListModel::BuddyRole: return QString(d->buddy);
case MobileListModel::DiveGuideRole: return QString::fromStdString(d->diveguide);
case MobileListModel::BuddyRole: return QString::fromStdString(d->buddy);
case MobileListModel::TagsRole: return QString::fromStdString(taglist_get_tagstring(d->tags));
case MobileListModel::NotesRole: return formatNotes(d);
case MobileListModel::GpsRole: return formatDiveGPS(d);
@ -334,7 +334,7 @@ QVariant DiveTripModelBase::diveData(const struct dive *d, int column, int role)
case TOTALWEIGHT:
return displayWeight(d, prefs.units.show_units_table);
case SUIT:
return QString(d->suit);
return QString::fromStdString(d->suit);
case CYLINDER:
return !d->cylinders.empty() ? QString::fromStdString(d->cylinders[0].type.description) : QString();
case SAC:
@ -353,15 +353,15 @@ QVariant DiveTripModelBase::diveData(const struct dive *d, int column, int role)
case COUNTRY:
return QString::fromStdString(get_dive_country(d));
case BUDDIES:
return QString(d->buddy);
return QString::fromStdString(d->buddy);
case DIVEGUIDE:
return QString(d->diveguide);
return QString::fromStdString(d->diveguide);
case LOCATION:
return QString::fromStdString(get_dive_location(d));
case GAS:
return formatDiveGasString(d);
case NOTES:
return QString(d->notes);
return QString::fromStdString(d->notes);
case DIVEMODE:
return QString(divemode_text_ui[(int)d->dcs[0].divemode]);
}
@ -1712,15 +1712,6 @@ static bool lessThanHelper(int diff1, int diff2)
return diff1 < 0 || (diff1 == 0 && diff2 < 0);
}
static int strCmp(const char *s1, const char *s2)
{
if (!s1)
return !s2 ? 0 : -1;
if (!s2)
return 1;
return QString::localeAwareCompare(QString(s1), QString(s2)); // TODO: avoid copy
}
static int strCmp(const std::string &s1, const std::string &s2)
{
return QString::localeAwareCompare(QString::fromStdString(s1), QString::fromStdString(s2)); // TODO: avoid copy