diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-02-28 23:37:09 +0100 |
---|---|---|
committer | Lubomir I. Ivanov <neolit123@gmail.com> | 2018-03-14 13:55:36 +0200 |
commit | d1572a8d9574e80955796b8667317c8dbd376081 (patch) | |
tree | ab58f9920a20b5c55bd54474f2edcfdc4eb2b904 /qt-models | |
parent | b72cc1f31784346884c8552c22f1e4c3c6d5ed1d (diff) | |
download | subsurface-d1572a8d9574e80955796b8667317c8dbd376081.tar.gz |
Cleanup: introduce copy_qstring() function
strdup(qPrintable(s)) and copy_string(qPrintable(s)) were such common
occurrences that they seem worthy of a short helper-function.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models')
-rw-r--r-- | qt-models/divelocationmodel.cpp | 4 | ||||
-rw-r--r-- | qt-models/diveplannermodel.cpp | 4 | ||||
-rw-r--r-- | qt-models/weightmodel.cpp | 2 |
3 files changed, 5 insertions, 5 deletions
diff --git a/qt-models/divelocationmodel.cpp b/qt-models/divelocationmodel.cpp index 8cd37a615..3de2c1159 100644 --- a/qt-models/divelocationmodel.cpp +++ b/qt-models/divelocationmodel.cpp @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 #include "core/units.h" #include "qt-models/divelocationmodel.h" -#include "core/dive.h" +#include "core/qthelper.h" #include <QDebug> #include <QLineEdit> #include <QIcon> @@ -149,7 +149,7 @@ bool LocationInformationModel::setData(const QModelIndex &index, const QVariant struct dive_site *ds = get_dive_site(index.row()); free(ds->name); - ds->name = copy_string(qPrintable(value.toString())); + ds->name = copy_qstring(value.toString()); emit dataChanged(index, index); return true; } diff --git a/qt-models/diveplannermodel.cpp b/qt-models/diveplannermodel.cpp index 831fe7842..0745c362d 100644 --- a/qt-models/diveplannermodel.cpp +++ b/qt-models/diveplannermodel.cpp @@ -160,7 +160,7 @@ void DivePlannerPointsModel::setupCylinders() } if (cylinder_none(&displayed_dive.cylinder[0])) { // roughly an AL80 - displayed_dive.cylinder[0].type.description = strdup(qPrintable(tr("unknown"))); + displayed_dive.cylinder[0].type.description = copy_qstring(tr("unknown")); displayed_dive.cylinder[0].type.size.mliter = 11100; displayed_dive.cylinder[0].type.workingpressure.mbar = 207000; } @@ -1123,7 +1123,7 @@ void DivePlannerPointsModel::createPlan(bool replanCopy) // Deal with line breaks oldnotes.replace("\n", "<br>"); oldnotes.append(displayed_dive.notes); - displayed_dive.notes = strdup(qPrintable(oldnotes)); + displayed_dive.notes = copy_qstring(oldnotes); // If we save as new create a copy of the dive here if (replanCopy) { struct dive *copy = alloc_dive(); diff --git a/qt-models/weightmodel.cpp b/qt-models/weightmodel.cpp index 0c91c467d..8dd9b0223 100644 --- a/qt-models/weightmodel.cpp +++ b/qt-models/weightmodel.cpp @@ -114,7 +114,7 @@ bool WeightModel::setData(const QModelIndex &index, const QVariant &value, int r } } if (ws_info[i].name == NULL) // didn't find a match - ws->description = strdup(qPrintable(vString)); + ws->description = copy_qstring(vString); changed = true; } } |