mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
b72cc1f317
commit
d1572a8d95
19 changed files with 116 additions and 108 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue