mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
core: use divelog in importDives() and process_imported_dives()
Instead of a long argument list. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
9c253ee6c5
commit
8cd451fc33
17 changed files with 103 additions and 121 deletions
|
@ -18,11 +18,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, struct dive_site_table *sites,
|
||||
struct device_table *devices, struct filter_preset_table *presets,
|
||||
int flags, const QString &source)
|
||||
void importDives(struct divelog *log, int flags, const QString &source)
|
||||
{
|
||||
execute(new ImportDives(dives, trips, sites, devices, presets, flags, source));
|
||||
execute(new ImportDives(log, flags, source));
|
||||
}
|
||||
|
||||
void deleteDive(const QVector<struct dive*> &divesToDelete)
|
||||
|
|
|
@ -2,17 +2,23 @@
|
|||
#ifndef COMMAND_H
|
||||
#define COMMAND_H
|
||||
|
||||
#include "core/dive.h"
|
||||
#include "core/divelog.h"
|
||||
#include "core/equipment.h"
|
||||
#include "core/pictureobj.h"
|
||||
#include "core/taxonomy.h"
|
||||
#include <QVector>
|
||||
#include <QAction>
|
||||
#include <vector>
|
||||
|
||||
struct divecomputer;
|
||||
struct divelog;
|
||||
struct dive_components;
|
||||
struct dive_site;
|
||||
struct dive_trip;
|
||||
struct event;
|
||||
struct DiveAndLocation;
|
||||
struct FilterData;
|
||||
struct filter_preset_table;
|
||||
struct device_table;
|
||||
|
||||
// We put everything in a namespace, so that we can shorten names without polluting the global namespace
|
||||
namespace Command {
|
||||
|
@ -35,10 +41,7 @@ bool placingCommand(); // Currently executing a new command -> might not have
|
|||
// If newNumber is true, the dive is assigned a new number, depending on the
|
||||
// insertion position.
|
||||
void addDive(dive *d, bool autogroup, bool newNumber);
|
||||
void importDives(struct dive_table *dives, struct trip_table *trips,
|
||||
struct dive_site_table *sites, struct device_table *devices,
|
||||
struct filter_preset_table *filter_presets,
|
||||
int flags, const QString &source); // The tables are consumed!
|
||||
void importDives(struct divelog *log, int flags, const QString &source); // The tables are consumed!
|
||||
void deleteDive(const QVector<struct dive*> &divesToDelete);
|
||||
void shiftTime(const std::vector<dive *> &changedDives, int amount);
|
||||
void renumberDives(const QVector<QPair<dive *, int>> &divesToRenumber);
|
||||
|
|
|
@ -468,11 +468,9 @@ void AddDive::undoit()
|
|||
setSelection(selection, currentDive);
|
||||
}
|
||||
|
||||
ImportDives::ImportDives(struct dive_table *dives, struct trip_table *trips, struct dive_site_table *sites,
|
||||
struct device_table *devices, struct filter_preset_table *filter_presets, int flags,
|
||||
const QString &source)
|
||||
ImportDives::ImportDives(struct divelog *log, int flags, const QString &source)
|
||||
{
|
||||
setText(Command::Base::tr("import %n dive(s) from %1", "", dives->nr).arg(source));
|
||||
setText(Command::Base::tr("import %n dive(s) from %1", "", log->dives->nr).arg(source));
|
||||
|
||||
// this only matters if undoit were called before redoit
|
||||
currentDive = nullptr;
|
||||
|
@ -481,7 +479,7 @@ ImportDives::ImportDives(struct dive_table *dives, struct trip_table *trips, str
|
|||
struct dive_table dives_to_remove = empty_dive_table;
|
||||
struct trip_table trips_to_add = empty_trip_table;
|
||||
struct dive_site_table sites_to_add = empty_dive_site_table;
|
||||
process_imported_dives(dives, trips, sites, devices, flags,
|
||||
process_imported_dives(log, flags,
|
||||
&dives_to_add, &dives_to_remove, &trips_to_add,
|
||||
&sites_to_add, &devicesToAddAndRemove);
|
||||
|
||||
|
@ -515,18 +513,13 @@ ImportDives::ImportDives(struct dive_table *dives, struct trip_table *trips, str
|
|||
|
||||
// When encountering filter presets with equal names, check whether they are
|
||||
// the same. If they are, ignore them.
|
||||
if (filter_presets) {
|
||||
for (const filter_preset &preset: *filter_presets) {
|
||||
QString name = preset.name;
|
||||
auto it = std::find_if(divelog.filter_presets->begin(), divelog.filter_presets->end(),
|
||||
[&name](const filter_preset &preset) { return preset.name == name; });
|
||||
if (it != divelog.filter_presets->end() && it->data == preset.data)
|
||||
continue;
|
||||
filterPresetsToAdd.emplace_back(preset.name, preset.data);
|
||||
}
|
||||
|
||||
// Consume the table for analogy with the other tables.
|
||||
filter_presets->clear();
|
||||
for (const filter_preset &preset: *log->filter_presets) {
|
||||
QString name = preset.name;
|
||||
auto it = std::find_if(divelog.filter_presets->begin(), divelog.filter_presets->end(),
|
||||
[&name](const filter_preset &preset) { return preset.name == name; });
|
||||
if (it != divelog.filter_presets->end() && it->data == preset.data)
|
||||
continue;
|
||||
filterPresetsToAdd.emplace_back(preset.name, preset.data);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -99,9 +99,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, struct dive_site_table *sites,
|
||||
struct device_table *devices, struct filter_preset_table *filter_presets, int flags,
|
||||
const QString &source);
|
||||
ImportDives(struct divelog *log, int flags, const QString &source);
|
||||
private:
|
||||
void undoit() override;
|
||||
void redoit() override;
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include "command_base.h"
|
||||
#include "command.h" // for EditCylinderType
|
||||
#include "core/divecomputer.h"
|
||||
#include "core/subsurface-qt/divelistnotifier.h"
|
||||
|
||||
#include <QVector>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue