summaryrefslogtreecommitdiffstats
path: root/qt-models
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-02-25 13:51:41 +0100
committerGravatar Lubomir I. Ivanov <neolit123@gmail.com>2018-03-14 13:55:36 +0200
commitb72cc1f31784346884c8552c22f1e4c3c6d5ed1d (patch)
tree00a04967dc56ccdc69ee998058c13911292ecef7 /qt-models
parent4e44fe7598430f9879736ec2d00b99b15dc05451 (diff)
downloadsubsurface-b72cc1f31784346884c8552c22f1e4c3c6d5ed1d.tar.gz
Cleanup: consistently use qPrintable()
Replace constructs of the kind s.toUtf8().data(), s.toUtf8().constData(), s.toLocal8Bit().data(), s.toLocal8Bit.constData() or qUtf8Printable(s) by qPrintable(s). This is concise, consistent and - in principle - more performant than the .data() versions. Sadly, owing to a suboptimal implementation, qPrintable(s) currently is a pessimization compared to s.toUtf8().data(). A fix is scheduled for new Qt versions: https://codereview.qt-project.org/#/c/221331/ Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models')
-rw-r--r--qt-models/cylindermodel.cpp24
-rw-r--r--qt-models/divepicturemodel.cpp2
-rw-r--r--qt-models/diveplannermodel.cpp10
-rw-r--r--qt-models/filtermodels.cpp2
-rw-r--r--qt-models/messagehandlermodel.cpp2
-rw-r--r--qt-models/weightmodel.cpp4
6 files changed, 22 insertions, 22 deletions
diff --git a/qt-models/cylindermodel.cpp b/qt-models/cylindermodel.cpp
index e81a127a9..652f57dbf 100644
--- a/qt-models/cylindermodel.cpp
+++ b/qt-models/cylindermodel.cpp
@@ -320,7 +320,7 @@ bool CylindersModel::setData(const QModelIndex &index, const QVariant &value, in
TankInfoModel *tanks = TankInfoModel::instance();
QModelIndexList matches = tanks->match(tanks->index(0, 0), Qt::DisplayRole, cyl->type.description);
- cyl->type.size = string_to_volume(vString.toUtf8().data(), cyl->type.workingpressure);
+ cyl->type.size = string_to_volume(qPrintable(vString), cyl->type.workingpressure);
mark_divelist_changed(true);
if (!matches.isEmpty())
tanks->setData(tanks->index(matches.first().row(), TankInfoModel::ML), cyl->type.size.mliter);
@@ -331,7 +331,7 @@ bool CylindersModel::setData(const QModelIndex &index, const QVariant &value, in
if (CHANGED()) {
TankInfoModel *tanks = TankInfoModel::instance();
QModelIndexList matches = tanks->match(tanks->index(0, 0), Qt::DisplayRole, cyl->type.description);
- cyl->type.workingpressure = string_to_pressure(vString.toUtf8().data());
+ cyl->type.workingpressure = string_to_pressure(qPrintable(vString));
if (!matches.isEmpty())
tanks->setData(tanks->index(matches.first().row(), TankInfoModel::BAR), cyl->type.workingpressure.mbar / 1000.0);
changed = true;
@@ -339,20 +339,20 @@ bool CylindersModel::setData(const QModelIndex &index, const QVariant &value, in
break;
case START:
if (CHANGED()) {
- cyl->start = string_to_pressure(vString.toUtf8().data());
+ cyl->start = string_to_pressure(qPrintable(vString));
changed = true;
}
break;
case END:
if (CHANGED()) {
- //&& (!cyl->start.mbar || string_to_pressure(vString.toUtf8().data()).mbar <= cyl->start.mbar)) {
- cyl->end = string_to_pressure(vString.toUtf8().data());
+ //&& (!cyl->start.mbar || string_to_pressure(qPrintable(vString)).mbar <= cyl->start.mbar)) {
+ cyl->end = string_to_pressure(qPrintable(vString));
changed = true;
}
break;
case O2:
if (CHANGED()) {
- cyl->gasmix.o2 = string_to_fraction(vString.toUtf8().data());
+ cyl->gasmix.o2 = string_to_fraction(qPrintable(vString));
// fO2 + fHe must not be greater than 1
if (get_o2(&cyl->gasmix) + get_he(&cyl->gasmix) > 1000)
cyl->gasmix.he.permille = 1000 - get_o2(&cyl->gasmix);
@@ -369,7 +369,7 @@ bool CylindersModel::setData(const QModelIndex &index, const QVariant &value, in
break;
case HE:
if (CHANGED()) {
- cyl->gasmix.he = string_to_fraction(vString.toUtf8().data());
+ cyl->gasmix.he = string_to_fraction(qPrintable(vString));
// fO2 + fHe must not be greater than 1
if (get_o2(&cyl->gasmix) + get_he(&cyl->gasmix) > 1000)
cyl->gasmix.o2.permille = 1000 - get_he(&cyl->gasmix);
@@ -379,20 +379,20 @@ bool CylindersModel::setData(const QModelIndex &index, const QVariant &value, in
break;
case DEPTH:
if (CHANGED()) {
- cyl->depth = string_to_depth(vString.toUtf8().data());
+ cyl->depth = string_to_depth(qPrintable(vString));
changed = true;
}
break;
case MOD:
if (CHANGED()) {
- if (QString::compare(vString.toUtf8().data(), "*") == 0) {
+ if (QString::compare(qPrintable(vString), "*") == 0) {
cyl->bestmix_o2 = true;
// Calculate fO2 for max. depth
cyl->gasmix.o2 = best_o2(displayed_dive.maxdepth, &displayed_dive);
} else {
cyl->bestmix_o2 = false;
// Calculate fO2 for input depth
- cyl->gasmix.o2 = best_o2(string_to_depth(vString.toUtf8().data()), &displayed_dive);
+ cyl->gasmix.o2 = best_o2(string_to_depth(qPrintable(vString)), &displayed_dive);
}
pressure_t modpO2;
modpO2.mbar = prefs.decopo2;
@@ -402,14 +402,14 @@ bool CylindersModel::setData(const QModelIndex &index, const QVariant &value, in
break;
case MND:
if (CHANGED()) {
- if (QString::compare(vString.toUtf8().data(), "*") == 0) {
+ if (QString::compare(qPrintable(vString), "*") == 0) {
cyl->bestmix_he = true;
// Calculate fO2 for max. depth
cyl->gasmix.he = best_he(displayed_dive.maxdepth, &displayed_dive);
} else {
cyl->bestmix_he = false;
// Calculate fHe for input depth
- cyl->gasmix.he = best_he(string_to_depth(vString.toUtf8().data()), &displayed_dive);
+ cyl->gasmix.he = best_he(string_to_depth(qPrintable(vString)), &displayed_dive);
}
changed = true;
}
diff --git a/qt-models/divepicturemodel.cpp b/qt-models/divepicturemodel.cpp
index ef60001b4..6cb8cae07 100644
--- a/qt-models/divepicturemodel.cpp
+++ b/qt-models/divepicturemodel.cpp
@@ -161,7 +161,7 @@ void DivePictureModel::removePicture(const QString &fileUrl, bool last)
int i;
struct dive *dive;
for_each_dive (i, dive) {
- if (dive->selected && dive_remove_picture(dive, fileUrl.toUtf8().data()))
+ if (dive->selected && dive_remove_picture(dive, qPrintable(fileUrl)))
break;
}
if (last) {
diff --git a/qt-models/diveplannermodel.cpp b/qt-models/diveplannermodel.cpp
index 9af6833f0..831fe7842 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(tr("unknown").toUtf8().constData());
+ displayed_dive.cylinder[0].type.description = strdup(qPrintable(tr("unknown")));
displayed_dive.cylinder[0].type.size.mliter = 11100;
displayed_dive.cylinder[0].type.workingpressure.mbar = 207000;
}
@@ -1063,9 +1063,9 @@ void DivePlannerPointsModel::computeVariations(struct diveplan *original_plan, s
restore_deco_state(save, &ds, false);
char buf[200];
- sprintf(buf, ", %s: + %d:%02d /%s + %d:%02d /min", tr("Stop times").toUtf8().data(),
- FRACTION(analyzeVariations(shallower, original, deeper, depth_units.toUtf8().data()), 60), depth_units.toUtf8().data(),
- FRACTION(analyzeVariations(shorter, original, longer, time_units.toUtf8().data()), 60));
+ sprintf(buf, ", %s: + %d:%02d /%s + %d:%02d /min", qPrintable(tr("Stop times")),
+ FRACTION(analyzeVariations(shallower, original, deeper, qPrintable(depth_units)), 60), qPrintable(depth_units),
+ FRACTION(analyzeVariations(shorter, original, longer, qPrintable(time_units)), 60));
emit variationsComputed(QString(buf));
#ifdef DEBUG_STOPVAR
@@ -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(oldnotes.toUtf8().data());
+ displayed_dive.notes = strdup(qPrintable(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/filtermodels.cpp b/qt-models/filtermodels.cpp
index 6eb94736d..89fd2853f 100644
--- a/qt-models/filtermodels.cpp
+++ b/qt-models/filtermodels.cpp
@@ -88,7 +88,7 @@ QVariant FilterModelBase::data(const QModelIndex &index, int role) const
return checkState[index.row()] ? Qt::Checked : Qt::Unchecked;
} else if (role == Qt::DisplayRole) {
QString value = stringList()[index.row()];
- int count = countDives((index.row() == rowCount() - 1) ? "" : value.toUtf8().data());
+ int count = countDives((index.row() == rowCount() - 1) ? "" : qPrintable(value));
return value + QString(" (%1)").arg(count);
}
return QVariant();
diff --git a/qt-models/messagehandlermodel.cpp b/qt-models/messagehandlermodel.cpp
index d783a3da6..e14aaf89c 100644
--- a/qt-models/messagehandlermodel.cpp
+++ b/qt-models/messagehandlermodel.cpp
@@ -42,7 +42,7 @@ void MessageHandlerModel::addLog(QtMsgType type, const QString& message)
beginInsertRows(QModelIndex(), rowCount(), rowCount());
m_data.append({message, type});
endInsertRows();
- INFO("%s", message.toUtf8().constData());
+ INFO("%s", qPrintable(message));
#if defined (Q_OS_ANDROID)
writeToAppLogFile(message);
#endif
diff --git a/qt-models/weightmodel.cpp b/qt-models/weightmodel.cpp
index 66c8158c4..0c91c467d 100644
--- a/qt-models/weightmodel.cpp
+++ b/qt-models/weightmodel.cpp
@@ -114,14 +114,14 @@ 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(vString.toUtf8().constData());
+ ws->description = strdup(qPrintable(vString));
changed = true;
}
}
break;
case WEIGHT:
if (CHANGED()) {
- ws->weight = string_to_weight(vString.toUtf8().data());
+ ws->weight = string_to_weight(qPrintable(vString));
// now update the ws_info
changed = true;
WSInfoModel *wsim = WSInfoModel::instance();