summaryrefslogtreecommitdiffstats
path: root/desktop-widgets
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-02-28 23:37:09 +0100
committerGravatar Lubomir I. Ivanov <neolit123@gmail.com>2018-03-14 13:55:36 +0200
commitd1572a8d9574e80955796b8667317c8dbd376081 (patch)
treeab58f9920a20b5c55bd54474f2edcfdc4eb2b904 /desktop-widgets
parentb72cc1f31784346884c8552c22f1e4c3c6d5ed1d (diff)
downloadsubsurface-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 'desktop-widgets')
-rw-r--r--desktop-widgets/configuredivecomputerdialog.cpp8
-rw-r--r--desktop-widgets/divelistview.cpp2
-rw-r--r--desktop-widgets/divelogimportdialog.cpp4
-rw-r--r--desktop-widgets/downloadfromdivecomputer.cpp6
-rw-r--r--desktop-widgets/locationinformation.cpp8
-rw-r--r--desktop-widgets/mainwindow.cpp4
-rw-r--r--desktop-widgets/tab-widgets/maintab.cpp20
7 files changed, 26 insertions, 26 deletions
diff --git a/desktop-widgets/configuredivecomputerdialog.cpp b/desktop-widgets/configuredivecomputerdialog.cpp
index 165f4d0d9..bf6b9cc34 100644
--- a/desktop-widgets/configuredivecomputerdialog.cpp
+++ b/desktop-widgets/configuredivecomputerdialog.cpp
@@ -910,9 +910,9 @@ void ConfigureDiveComputerDialog::getDeviceData()
#else
QString device = ui.device->currentText();
#endif
- device_data.devname = strdup(qPrintable(device));
- device_data.vendor = strdup(qPrintable(selected_vendor));
- device_data.product = strdup(qPrintable(selected_product));
+ device_data.devname = copy_qstring(device);
+ device_data.vendor = copy_qstring(selected_vendor);
+ device_data.product = copy_qstring(selected_product);
device_data.descriptor = descriptorLookup.value(selected_vendor + selected_product);
device_data.deviceid = device_data.diveid = 0;
@@ -1479,7 +1479,7 @@ void ConfigureDiveComputerDialog::pickLogFile()
filename, tr("Log files") + " (*.log)");
if (!logFile.isEmpty()) {
free(logfile_name);
- logfile_name = strdup(qPrintable(logFile));
+ logfile_name = copy_qstring(logFile);
}
}
diff --git a/desktop-widgets/divelistview.cpp b/desktop-widgets/divelistview.cpp
index ce9f2e47d..95e0e3fe9 100644
--- a/desktop-widgets/divelistview.cpp
+++ b/desktop-widgets/divelistview.cpp
@@ -949,7 +949,7 @@ void DiveListView::matchImagesToDives(QStringList fileNames)
for_each_dive (j, dive) {
if (!dive->selected)
continue;
- dive_create_picture(dive, copy_string(qPrintable(fileName)), shiftDialog.amount(), shiftDialog.matchAll());
+ dive_create_picture(dive, copy_qstring(fileName), shiftDialog.amount(), shiftDialog.matchAll());
}
}
diff --git a/desktop-widgets/divelogimportdialog.cpp b/desktop-widgets/divelogimportdialog.cpp
index 091de35e0..006f9b742 100644
--- a/desktop-widgets/divelogimportdialog.cpp
+++ b/desktop-widgets/divelogimportdialog.cpp
@@ -788,10 +788,10 @@ int DiveLogImportDialog::setup_csv_params(QStringList r, char **params, int pnr)
params[pnr++] = intdup(ui->CSVUnits->currentIndex());
if (hw.length()) {
params[pnr++] = strdup("hw");
- params[pnr++] = strdup(qPrintable(hw));
+ params[pnr++] = copy_qstring(hw);
} else if (ui->knownImports->currentText().length() > 0) {
params[pnr++] = strdup("hw");
- params[pnr++] = strdup(qPrintable(ui->knownImports->currentText().prepend("\"").append("\"")));
+ params[pnr++] = copy_qstring(ui->knownImports->currentText().prepend("\"").append("\""));
}
params[pnr++] = NULL;
diff --git a/desktop-widgets/downloadfromdivecomputer.cpp b/desktop-widgets/downloadfromdivecomputer.cpp
index c2bf7740e..ad8416a07 100644
--- a/desktop-widgets/downloadfromdivecomputer.cpp
+++ b/desktop-widgets/downloadfromdivecomputer.cpp
@@ -297,7 +297,7 @@ void DownloadFromDCWidget::on_downloadCancelRetryButton_clicked()
#endif
if (data->vendor() == "Uemis") {
char *colon;
- char *devname = strdup(qPrintable(ui.device->currentText()));
+ char *devname = copy_qstring(ui.device->currentText());
if ((colon = strstr(devname, ":\\ (UEMISSDA)")) != NULL) {
*(colon + 2) = '\0';
@@ -362,7 +362,7 @@ void DownloadFromDCWidget::pickLogFile()
filename, tr("Log files") + " (*.log)");
if (!logFile.isEmpty()) {
free(logfile_name);
- logfile_name = copy_string(qPrintable(logFile));
+ logfile_name = copy_qstring(logFile);
}
}
@@ -388,7 +388,7 @@ void DownloadFromDCWidget::pickDumpFile()
filename, tr("Dump files") + " (*.bin)");
if (!dumpFile.isEmpty()) {
free(dumpfile_name);
- dumpfile_name = copy_string(qPrintable(dumpFile));
+ dumpfile_name = copy_qstring(dumpFile);
}
}
diff --git a/desktop-widgets/locationinformation.cpp b/desktop-widgets/locationinformation.cpp
index 7818bc29e..0f3d2b4f3 100644
--- a/desktop-widgets/locationinformation.cpp
+++ b/desktop-widgets/locationinformation.cpp
@@ -158,7 +158,7 @@ void LocationInformationWidget::acceptChanges()
{
char *uiString;
struct dive_site *currentDs;
- uiString = copy_string(qPrintable(ui.diveSiteName->text()));
+ uiString = copy_qstring(ui.diveSiteName->text());
if (get_dive_site_by_uuid(displayed_dive_site.uuid) != NULL) {
currentDs = get_dive_site_by_uuid(displayed_dive_site.uuid);
} else {
@@ -175,14 +175,14 @@ void LocationInformationWidget::acceptChanges()
} else {
free(uiString);
}
- uiString = copy_string(qPrintable(ui.diveSiteDescription->text()));
+ uiString = copy_qstring(ui.diveSiteDescription->text());
if (!same_string(uiString, currentDs->description)) {
free(currentDs->description);
currentDs->description = uiString;
} else {
free(uiString);
}
- uiString = copy_string(qPrintable(ui.diveSiteCountry->text()));
+ uiString = copy_qstring(ui.diveSiteCountry->text());
// if the user entered a different contriy, first update the taxonomy
// for the displayed dive site; this below will get copied into the currentDs
if (!same_string(uiString, taxonomy_get_country(&displayed_dive_site.taxonomy)) &&
@@ -193,7 +193,7 @@ void LocationInformationWidget::acceptChanges()
// now update the currentDs (which we then later copy back ontop of displayed_dive_site
copy_dive_site_taxonomy(&displayed_dive_site, currentDs);
- uiString = copy_string(qPrintable(ui.diveSiteNotes->document()->toPlainText()));
+ uiString = copy_qstring(ui.diveSiteNotes->document()->toPlainText());
if (!same_string(uiString, currentDs->notes)) {
free(currentDs->notes);
currentDs->notes = uiString;
diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp
index 990629154..d0c5a0790 100644
--- a/desktop-widgets/mainwindow.cpp
+++ b/desktop-widgets/mainwindow.cpp
@@ -935,7 +935,7 @@ void MainWindow::updateVariations(QString variations)
{
QString notes = QString(displayed_dive.notes);
free(displayed_dive.notes);
- displayed_dive.notes = strdup(qPrintable(notes.replace("VARIATIONS", variations)));
+ displayed_dive.notes = copy_qstring(notes.replace("VARIATIONS", variations));
plannerDetails()->divePlanOutput()->setHtml(displayed_dive.notes);
}
@@ -1652,7 +1652,7 @@ int MainWindow::file_save_as(void)
filename.remove(prefs.cloud_git_url);
filename.remove(0, filename.indexOf("[") + 1);
filename.replace("]", ".ssrf");
- default_filename = strdup(qPrintable(filename));
+ default_filename = copy_qstring(filename);
}
// create a file dialog that allows us to save to a new file
QFileDialog selection_dialog(this, tr("Save file as"), default_filename,
diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp
index 3a1f80cea..1f1997507 100644
--- a/desktop-widgets/tab-widgets/maintab.cpp
+++ b/desktop-widgets/tab-widgets/maintab.cpp
@@ -745,7 +745,7 @@ uint32_t MainTab::updateDiveSite(uint32_t pickedUuid, int divenr)
if(createdNewDive) {
copy_dive_site(origDs, newDs);
free(newDs->name);
- newDs->name = copy_string(qPrintable(ui.location->text().constData()));
+ newDs->name = copy_qstring(ui.location->text());
newDs->uuid = pickedUuid;
qDebug() << "Creating and copying dive site";
} else if (newDs->latitude.udeg == 0 && newDs->longitude.udeg == 0) {
@@ -1090,7 +1090,7 @@ void MainTab::on_buddy_textChanged()
text_list[i] = text_list[i].trimmed();
QString text = text_list.join(", ");
free(displayed_dive.buddy);
- displayed_dive.buddy = strdup(qPrintable(text));
+ displayed_dive.buddy = copy_qstring(text);
markChangedWidget(ui.buddy);
}
@@ -1107,7 +1107,7 @@ void MainTab::on_divemaster_textChanged()
text_list[i] = text_list[i].trimmed();
QString text = text_list.join(", ");
free(displayed_dive.divemaster);
- displayed_dive.divemaster = strdup(qPrintable(text));
+ displayed_dive.divemaster = copy_qstring(text);
markChangedWidget(ui.divemaster);
}
@@ -1303,7 +1303,7 @@ void MainTab::saveTaggedStrings()
}
}
free(mydive->buddy);
- mydive->buddy = copy_string(qPrintable(newString));
+ mydive->buddy = copy_qstring(newString);
);
addedList.clear();
removedList.clear();
@@ -1325,7 +1325,7 @@ void MainTab::saveTaggedStrings()
}
}
free(mydive->divemaster);
- mydive->divemaster = copy_string(qPrintable(newString));
+ mydive->divemaster = copy_qstring(newString);
);
}
@@ -1397,7 +1397,7 @@ void MainTab::on_diveTripLocation_textEdited(const QString& text)
{
if (currentTrip) {
free(displayedTrip.location);
- displayedTrip.location = strdup(qPrintable(text));
+ displayedTrip.location = copy_qstring(text);
markChangedWidget(ui.diveTripLocation);
}
}
@@ -1407,7 +1407,7 @@ void MainTab::on_suit_textChanged(const QString &text)
if (editMode == IGNORE || acceptingEdit == true)
return;
free(displayed_dive.suit);
- displayed_dive.suit = strdup(qPrintable(text));
+ displayed_dive.suit = copy_qstring(text);
markChangedWidget(ui.suit);
}
@@ -1419,15 +1419,15 @@ void MainTab::on_notes_textChanged()
if (same_string(displayedTrip.notes, qPrintable(ui.notes->toPlainText())))
return;
free(displayedTrip.notes);
- displayedTrip.notes = strdup(qPrintable(ui.notes->toPlainText()));
+ displayedTrip.notes = copy_qstring(ui.notes->toPlainText());
} else {
if (same_string(displayed_dive.notes, qPrintable(ui.notes->toPlainText())))
return;
free(displayed_dive.notes);
if (ui.notes->toHtml().indexOf("<table") != -1)
- displayed_dive.notes = strdup(qPrintable(ui.notes->toHtml()));
+ displayed_dive.notes = copy_qstring(ui.notes->toHtml());
else
- displayed_dive.notes = strdup(qPrintable(ui.notes->toPlainText()));
+ displayed_dive.notes = copy_qstring(ui.notes->toPlainText());
}
markChangedWidget(ui.notes);
}