Skip to content

Commit a7cd1c9

Browse files
authored
for Qstrings and QByteArrays prefer isEmpty() over size() and length() (#1409)
* use QString::isEmpty() * use QByteArray::isEmpty()
1 parent df147fb commit a7cd1c9

File tree

15 files changed

+43
-43
lines changed

15 files changed

+43
-43
lines changed

arcdist.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ void ArcDistanceFilter::process()
132132
arcpt2->latitude = arcpt2->longitude = BADVAL;
133133
int argsfound = sscanf(CSTR(line), "%lf %lf", &arcpt2->latitude, &arcpt2->longitude);
134134

135-
if ((argsfound != 2) && (line.trimmed().size() > 0)) {
135+
if ((argsfound != 2) && (!line.trimmed().isEmpty())) {
136136
gbWarning("Warning: Arc file contains unusable vertex on line %d.\n", fileline);
137137
} else {
138138
Waypoint* arcpttmp = arcpt1;

csv_util.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ QString
102102
csv_enquote(const QString& str, const QString& enclosure)
103103
{
104104
QString retval = str;
105-
if (enclosure.size() > 0) {
105+
if (!enclosure.isEmpty()) {
106106
retval = enclosure + retval.replace(enclosure, enclosure + enclosure) + enclosure;
107107
}
108108
return retval;

exif.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ ExifFormat::exif_read_str(ExifTag* tag)
215215
if (auto idx = buf.indexOf('\0'); idx >= 0) {
216216
buf = buf.left(idx);
217217
}
218-
while ((buf.size() > 0) && isspace(buf.back())) {
218+
while ((!buf.isEmpty()) && isspace(buf.back())) {
219219
buf.chop(1);
220220
}
221221
return buf;

googletakeout.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ Waypoint* GoogleTakeoutFormat::takeout_waypoint(
5959
auto* waypoint = new Waypoint();
6060
waypoint->latitude = lat_e7 / 1e7;
6161
waypoint->longitude = lon_e7 / 1e7;
62-
if (shortname && shortname->length() > 0) {
62+
if (shortname && !shortname->isEmpty()) {
6363
waypoint->shortname = *shortname;
6464
}
65-
if (description && description->length() > 0) {
65+
if (description && !description->isEmpty()) {
6666
waypoint->description = *description;
6767
}
68-
if (start_str && start_str->length() > 0) {
68+
if (start_str && !start_str->isEmpty()) {
6969
gpsbabel::DateTime start = QDateTime::fromString(*start_str, Qt::ISODate);
7070
waypoint->SetCreationTime(start);
7171
}
@@ -286,12 +286,12 @@ GoogleTakeoutFormat::add_place_visit(const QJsonObject& placeVisit)
286286
const QString timestamp = placeVisit[DURATION][START_TIMESTAMP].toString();
287287
Waypoint* waypoint;
288288

289-
if (loc.contains(NAME) && loc[NAME].toString().length() > 0) {
289+
if (loc.contains(NAME) && !loc[NAME].toString().isEmpty()) {
290290
QString name = loc[NAME].toString();
291291
waypoint = takeout_waypoint(
292292
loc[LOCATION_LATE7].toInt(),
293293
loc[LOCATION_LONE7].toInt(),
294-
name.length() > 0 ? &name : nullptr,
294+
!name.isEmpty() ? &name : nullptr,
295295
&address,
296296
&timestamp
297297
);

gui/filterdata.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ QStringList TrackFilterData::makeOptionString() const
143143
s += QString(",title=%1").arg(titleString);
144144
}
145145

146-
if (s.length() != 0) {
146+
if (!s.isEmpty()) {
147147
args << "-x" << "track" + s;
148148
}
149149

gui/formatload.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,19 @@ bool FormatLoad::processFormat(Format& format)
8787
} else if (optionType == "string") {
8888
type = FormatOption::OPTstring;
8989
} else if (optionType == "integer") {
90-
type = (optionMax != "" && optionMin != "") ? FormatOption::OPTboundedInt : FormatOption::OPTint;
91-
if (optionMax == "") {
90+
type = (!optionMax.isEmpty() && !optionMin.isEmpty()) ? FormatOption::OPTboundedInt : FormatOption::OPTint;
91+
if (optionMax.isEmpty()) {
9292
optionMax = "2147483647";
9393
}
94-
if (optionMin == "") {
94+
if (optionMin.isEmpty()) {
9595
optionMin = "-2147483647";
9696
}
9797
} else if (optionType == "float") {
9898
type = FormatOption::OPTfloat;
99-
if (optionMax == "") {
99+
if (optionMax.isEmpty()) {
100100
optionMax = "1.0E308";
101101
}
102-
if (optionMin == "") {
102+
if (optionMin.isEmpty()) {
103103
optionMin = "-1.0E308";
104104
}
105105
} else if (optionType == "file") {
@@ -125,7 +125,7 @@ bool FormatLoad::processFormat(Format& format)
125125
optionList,
126126
optionList2, htmlPage);
127127
#ifndef GENERATE_CORE_STRINGS
128-
if (htmlPage.length() > 0 && Format::getHtmlBase().length() == 0) {
128+
if (!htmlPage.isEmpty() && Format::getHtmlBase().isEmpty()) {
129129
QString base = htmlPage;
130130
static const QRegularExpression re("/[^/]+$");
131131
base.replace(re, "/");

gui/gmapdlg.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ void GMapDialog::appendWaypointInfo(QStandardItem* it, const GpxWaypoint& wpt)
8282
{
8383
it->appendRow(new StandardItem(tr("Lat: %1").arg(wpt.getLocation().lat(), 0, 'f', 7)));
8484
it->appendRow(new StandardItem(tr("Lng: %1").arg(wpt.getLocation().lng(), 0, 'f', 7)));
85-
if (wpt.getDescription() != QString()) {
85+
if (!wpt.getDescription().isEmpty()) {
8686
it->appendRow(new StandardItem(tr("Desc: %1").arg(wpt.getDescription())));
8787
}
88-
if (wpt.getComment() != QString() && wpt.getComment() != wpt.getDescription()) {
88+
if (!wpt.getComment().isEmpty() && wpt.getComment() != wpt.getDescription()) {
8989
it->appendRow(new StandardItem(tr("Cmt: %1").arg(wpt.getComment())));
9090
}
9191
if (wpt.getElevation() > -50000) {

gui/mainwindow.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ static QString MakeOptions(const QList<FormatOption>& options)
142142
static QString MakeOptionsNoLeadingComma(const QList<FormatOption>& options)
143143
{
144144
QString str = MakeOptions(options);
145-
return (str.length()) != 0 ? str.mid(1) : str;
145+
return !str.isEmpty() ? str.mid(1) : str;
146146

147147
}
148148

@@ -461,7 +461,7 @@ QString MainWindow::filterForFormat(int idx)
461461
QString MainWindow::ensureExtensionPresent(const QString& name, int idx)
462462
{
463463
QString outname = name;
464-
if (QFileInfo(name).suffix().length() == 0) {
464+
if (QFileInfo(name).suffix().isEmpty()) {
465465
QStringList extensions = formatList_[idx].getExtensions();
466466
if (!extensions.empty() && !extensions[0].isEmpty()) {
467467
outname += "." + extensions[0];
@@ -524,7 +524,7 @@ void MainWindow::browseInputFile()
524524
void MainWindow::browseOutputFile()
525525
{
526526
int idx = currentComboFormatIndex(ui_.outputFormatCombo);
527-
QString startFile = babelData_.outputFileName_.length() == 0 ? babelData_.outputBrowse_ : babelData_.outputFileName_;
527+
QString startFile = babelData_.outputFileName_.isEmpty() ? babelData_.outputBrowse_ : babelData_.outputFileName_;
528528
QFileInfo finfo(startFile);
529529
if (!finfo.isDir() && (!filterForFormatIncludes(idx, finfo.suffix()))) {
530530
startFile = finfo.dir().absolutePath();
@@ -534,7 +534,7 @@ void MainWindow::browseOutputFile()
534534
QFileDialog::getSaveFileName(nullptr, tr("Output File Name"),
535535
startFile,
536536
filterForFormat(idx));
537-
if (str.length() != 0) {
537+
if (!str.isEmpty()) {
538538
str = ensureExtensionPresent(str, idx);
539539
babelData_.outputBrowse_ = str;
540540
babelData_.outputFileName_ = str;
@@ -805,7 +805,7 @@ bool MainWindow::isOkToGo()
805805
babelData_.inputFileNames_ << ui_.inputFileNameText->text();
806806
}
807807
if ((babelData_.outputType_ == BabelData::fileType_) &&
808-
(babelData_.outputFileName_.size() == 0) &&
808+
(babelData_.outputFileName_.isEmpty()) &&
809809
(!ui_.outputFileNameText->text().isEmpty())) {
810810
babelData_.outputFileName_ = ui_.outputFileNameText->text();
811811
}
@@ -825,7 +825,7 @@ bool MainWindow::isOkToGo()
825825
return false;
826826
}
827827
if (babelData_.outputType_ == BabelData::fileType_ &&
828-
babelData_.outputFileName_.length() == 0) {
828+
babelData_.outputFileName_.isEmpty()) {
829829
QMessageBox::information(nullptr, QString(appName), tr("No output file specified"));
830830
return false;
831831
}
@@ -920,7 +920,7 @@ void MainWindow::applyActionX()
920920

921921
// output file or device option
922922
if (outIsFile) {
923-
if (babelData_.outputFileName_ != "") {
923+
if (!babelData_.outputFileName_.isEmpty()) {
924924
args << "-F" << babelData_.outputFileName_;
925925
}
926926
} else if (babelData_.outputType_ == BabelData::deviceType_) {

gui/optionsdlg.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ FileDlgManager::FileDlgManager(QObject* parent,
6060
//------------------------------------------------------------------------
6161
QVariant getOptionValue(QList<FormatOption> opts, int k)
6262
{
63-
if (opts[k].getValue().toString() != "") {
63+
if (!opts[k].getValue().toString().isEmpty()) {
6464
return opts[k].getValue();
6565
}
6666
return opts[k].getDefaultValue();
@@ -80,7 +80,7 @@ void FileDlgManager::buttonClicked()
8080
le->text(),
8181
"All Files (*.*)");
8282
}
83-
if (str != "") {
83+
if (!str.isEmpty()) {
8484
le->setText(str);
8585
}
8686
}

gui/upgrade.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ void UpgradeCheck::httpRequestFinished(QNetworkReply* reply)
323323
}
324324
}
325325

326-
if (response.length() != 0) {
326+
if (!response.isEmpty()) {
327327
QMessageBox information;
328328
information.setWindowTitle(tr("Upgrade"));
329329

0 commit comments

Comments
 (0)