diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-01-13 22:53:57 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-01-19 13:48:17 -0800 |
commit | 891fcbf520f28ef6016d6171eba83c6773efca00 (patch) | |
tree | 22952fe84f0ff56f9ceffdac35c1e1329c7534e3 /desktop-widgets | |
parent | ff9506b21bbb9910256841dcb577bcb2e19047e8 (diff) | |
download | subsurface-891fcbf520f28ef6016d6171eba83c6773efca00.tar.gz |
Import: control process_imported_dives() by flags
process_imported_dives() takes four boolean parameters. Replace these
by flags. This makes the function calls much more descriptive. Morover,
it becomes easier to add or remove flags.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets')
-rw-r--r-- | desktop-widgets/command.cpp | 6 | ||||
-rw-r--r-- | desktop-widgets/command.h | 4 | ||||
-rw-r--r-- | desktop-widgets/command_divelist.cpp | 7 | ||||
-rw-r--r-- | desktop-widgets/command_divelist.h | 4 | ||||
-rw-r--r-- | desktop-widgets/divelogimportdialog.cpp | 2 | ||||
-rw-r--r-- | desktop-widgets/downloadfromdivecomputer.cpp | 7 | ||||
-rw-r--r-- | desktop-widgets/mainwindow.cpp | 2 | ||||
-rw-r--r-- | desktop-widgets/subsurfacewebservices.cpp | 2 |
8 files changed, 15 insertions, 19 deletions
diff --git a/desktop-widgets/command.cpp b/desktop-widgets/command.cpp index e297f70d0..84f21265d 100644 --- a/desktop-widgets/command.cpp +++ b/desktop-widgets/command.cpp @@ -11,11 +11,9 @@ void addDive(dive *d, bool autogroup, bool newNumber) execute(new AddDive(d, autogroup, newNumber)); } -void importDives(struct dive_table *dives, struct trip_table *trips, - bool prefer_imported, bool downloaded, bool merge_all_trips, - bool add_to_new_trip, const QString &source) +void importDives(struct dive_table *dives, struct trip_table *trips, int flags, const QString &source) { - execute(new ImportDives(dives, trips, prefer_imported, downloaded, merge_all_trips, add_to_new_trip, source)); + execute(new ImportDives(dives, trips, flags, source)); } void deleteDive(const QVector<struct dive*> &divesToDelete) diff --git a/desktop-widgets/command.h b/desktop-widgets/command.h index cbc416e23..d527fff3b 100644 --- a/desktop-widgets/command.h +++ b/desktop-widgets/command.h @@ -21,9 +21,7 @@ void addDive(dive *d, bool autogroup, bool newNumber); // If d->dive_trip is nul // distance are added to a trip. dive d is consumed (the structure is reset)! // If newNumber is true, the dive is assigned a new number, depending on the // insertion position. -void importDives(struct dive_table *dives, struct trip_table *trips, - bool prefer_imported, bool downloaded, bool merge_all_trips, - bool add_to_new_trip, const QString &source); +void importDives(struct dive_table *dives, struct trip_table *trips, int flags, const QString &source); void deleteDive(const QVector<struct dive*> &divesToDelete); void shiftTime(const QVector<dive *> &changedDives, int amount); void renumberDives(const QVector<QPair<dive *, int>> &divesToRenumber); diff --git a/desktop-widgets/command_divelist.cpp b/desktop-widgets/command_divelist.cpp index e7edaaa54..cf8feed0b 100644 --- a/desktop-widgets/command_divelist.cpp +++ b/desktop-widgets/command_divelist.cpp @@ -552,17 +552,14 @@ void AddDive::undoit() MainWindow::instance()->refreshDisplay(false); } -ImportDives::ImportDives(struct dive_table *dives, struct trip_table *trips, - bool prefer_imported, bool downloaded, bool merge_all_trips, - bool add_to_new_trip, const QString &source) +ImportDives::ImportDives(struct dive_table *dives, struct trip_table *trips, int flags, const QString &source) { setText(tr("import %n dive(s) from %1", "", dives->nr).arg(source)); struct dive_table dives_to_add = { 0 }; struct dive_table dives_to_remove = { 0 }; struct trip_table trips_to_add = { 0 }; - process_imported_dives(dives, trips, prefer_imported, downloaded, merge_all_trips, - add_to_new_trip, &dives_to_add, &dives_to_remove, &trips_to_add); + process_imported_dives(dives, trips, flags, &dives_to_add, &dives_to_remove, &trips_to_add); // Add trips to the divesToAdd.trips structure divesToAdd.trips.reserve(trips_to_add.nr); diff --git a/desktop-widgets/command_divelist.h b/desktop-widgets/command_divelist.h index b823da7e7..6cf7f48ab 100644 --- a/desktop-widgets/command_divelist.h +++ b/desktop-widgets/command_divelist.h @@ -98,9 +98,7 @@ private: class ImportDives : public DiveListBase { public: // Note: dives and trips are consumed - after the call they will be empty. - ImportDives(struct dive_table *dives, struct trip_table *trips, - bool prefer_imported, bool downloaded, bool merge_all_trips, - bool add_to_new_trip, const QString &source); + ImportDives(struct dive_table *dives, struct trip_table *trips, int flags, const QString &source); private: void undoit() override; void redoit() override; diff --git a/desktop-widgets/divelogimportdialog.cpp b/desktop-widgets/divelogimportdialog.cpp index 869fb9d25..6965da06c 100644 --- a/desktop-widgets/divelogimportdialog.cpp +++ b/desktop-widgets/divelogimportdialog.cpp @@ -1012,7 +1012,7 @@ void DiveLogImportDialog::on_buttonBox_accepted() } QString source = fileNames.size() == 1 ? fileNames[0] : tr("multiple files"); - Command::importDives(&table, &trips, false, false, true, false, source); + Command::importDives(&table, &trips, IMPORT_MERGE_ALL_TRIPS, source); } TagDragDelegate::TagDragDelegate(QObject *parent) : QStyledItemDelegate(parent) diff --git a/desktop-widgets/downloadfromdivecomputer.cpp b/desktop-widgets/downloadfromdivecomputer.cpp index 3376d5c39..2bad04d1c 100644 --- a/desktop-widgets/downloadfromdivecomputer.cpp +++ b/desktop-widgets/downloadfromdivecomputer.cpp @@ -516,7 +516,12 @@ void DownloadFromDCWidget::on_ok_clicked() if (table->nr > 0) { auto data = thread.data(); - Command::importDives(table, nullptr, preferDownloaded(), true, false, ui.createNewTrip->isChecked(), data->devName()); + int flags = IMPORT_IS_DOWNLOADED; + if (preferDownloaded()) + flags |= IMPORT_IS_DOWNLOADED; + if (ui.createNewTrip->isChecked()) + flags |= IMPORT_ADD_TO_NEW_TRIP; + Command::importDives(table, nullptr, flags, data->devName()); } if (ostcFirmwareCheck && currentState == DONE) diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index 18b1bd5fa..2fd7232a6 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -1716,7 +1716,7 @@ void MainWindow::importFiles(const QStringList fileNames) parse_file(fileNamePtr.data(), &table, &trips); } QString source = fileNames.size() == 1 ? fileNames[0] : tr("multiple files"); - Command::importDives(&table, &trips, false, false, true, false, source); + Command::importDives(&table, &trips, IMPORT_MERGE_ALL_TRIPS, source); } void MainWindow::loadFiles(const QStringList fileNames) diff --git a/desktop-widgets/subsurfacewebservices.cpp b/desktop-widgets/subsurfacewebservices.cpp index 9dac4dab3..65166b33f 100644 --- a/desktop-widgets/subsurfacewebservices.cpp +++ b/desktop-widgets/subsurfacewebservices.cpp @@ -772,7 +772,7 @@ void DivelogsDeWebServices::buttonClicked(QAbstractButton *button) struct dive_table table = { 0 }; struct trip_table trips = { 0 }; parse_file(QFile::encodeName(zipFile.fileName()), &table, &trips); - Command::importDives(&table, &trips, false, false, true, false, QStringLiteral("divelogs.de")); + Command::importDives(&table, &trips, IMPORT_MERGE_ALL_TRIPS, QStringLiteral("divelogs.de")); /* store last entered user/pass in config */ QSettings s; |