mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	devices: add devices in Command::importTable()
Add a device_table parameters to Command::importTable() and add_imported_dives(). The content of this table will be added to the global device list (respectively removed on undo). This is currently a no-op, as the parser doesn't yet fill out the device table, but adds devices directly to the global device table. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
		
							parent
							
								
									fadea413cd
								
							
						
					
					
						commit
						39a4090c0a
					
				
					 17 changed files with 113 additions and 40 deletions
				
			
		|  | @ -18,9 +18,10 @@ void addDive(dive *d, bool autogroup, bool newNumber) | |||
| } | ||||
| 
 | ||||
| void importDives(struct dive_table *dives, struct trip_table *trips, struct dive_site_table *sites, | ||||
| 		 struct filter_preset_table *presets, int flags, const QString &source) | ||||
| 		 struct device_table *devices, struct filter_preset_table *presets, | ||||
| 		 int flags, const QString &source) | ||||
| { | ||||
| 	execute(new ImportDives(dives, trips, sites, presets, flags, source)); | ||||
| 	execute(new ImportDives(dives, trips, sites, devices, presets, flags, source)); | ||||
| } | ||||
| 
 | ||||
| void deleteDive(const QVector<struct dive*> &divesToDelete) | ||||
|  |  | |||
|  | @ -3,7 +3,6 @@ | |||
| #define COMMAND_H | ||||
| 
 | ||||
| #include "core/dive.h" | ||||
| #include "core/filterpreset.h" | ||||
| #include "core/pictureobj.h" | ||||
| #include <QVector> | ||||
| #include <QAction> | ||||
|  | @ -11,6 +10,8 @@ | |||
| 
 | ||||
| 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 { | ||||
|  | @ -33,7 +34,8 @@ QString changesMade();			// return a string with the texts from all commands on | |||
| // 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 filter_preset_table *filter_presets, | ||||
| 		 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 deleteDive(const QVector<struct dive*> &divesToDelete); | ||||
| void shiftTime(const std::vector<dive *> &changedDives, int amount); | ||||
|  |  | |||
|  | @ -470,7 +470,8 @@ void AddDive::undoit() | |||
| } | ||||
| 
 | ||||
| ImportDives::ImportDives(struct dive_table *dives, struct trip_table *trips, struct dive_site_table *sites, | ||||
| 			 struct filter_preset_table *filter_presets, int flags, const QString &source) | ||||
| 			 struct device_table *devices, struct filter_preset_table *filter_presets, int flags, | ||||
| 			 const QString &source) | ||||
| { | ||||
| 	setText(Command::Base::tr("import %n dive(s) from %1", "", dives->nr).arg(source)); | ||||
| 
 | ||||
|  | @ -481,7 +482,9 @@ 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, flags, &dives_to_add, &dives_to_remove, &trips_to_add, &sites_to_add); | ||||
| 	process_imported_dives(dives, trips, sites, devices, flags, | ||||
| 			       &dives_to_add, &dives_to_remove, &trips_to_add, | ||||
| 			       &sites_to_add, &devicesToAddAndRemove); | ||||
| 
 | ||||
| 	// Add trips to the divesToAdd.trips structure
 | ||||
| 	divesToAdd.trips.reserve(trips_to_add.nr); | ||||
|  | @ -550,6 +553,12 @@ void ImportDives::redoit() | |||
| 	// Remember dives and sites to remove
 | ||||
| 	divesAndSitesToRemove = std::move(divesAndSitesToRemoveNew); | ||||
| 
 | ||||
| 	// Add devices
 | ||||
| 	for (const device &dev: devicesToAddAndRemove.devices) { | ||||
| 		int idx = add_to_device_table(&device_table, &dev); | ||||
| 		emit diveListNotifier.deviceAdded(idx); | ||||
| 	} | ||||
| 
 | ||||
| 	// Add new filter presets
 | ||||
| 	for (auto &it: filterPresetsToAdd) { | ||||
| 		filterPresetsToRemove.push_back(filter_preset_add(it.first, it.second)); | ||||
|  | @ -572,6 +581,13 @@ void ImportDives::undoit() | |||
| 	// ...and restore the selection
 | ||||
| 	setSelection(selection, currentDive); | ||||
| 
 | ||||
| 	// Remove devices
 | ||||
| 	for (const device &dev: devicesToAddAndRemove.devices) { | ||||
| 		int idx = remove_device(&device_table, &dev); | ||||
| 		if (idx >= 0) | ||||
| 			emit diveListNotifier.deviceDeleted(idx); | ||||
| 	} | ||||
| 
 | ||||
| 	// Remove filter presets. Do this in reverse order.
 | ||||
| 	for (auto it = filterPresetsToRemove.rbegin(); it != filterPresetsToRemove.rend(); ++it) { | ||||
| 		int index = *it; | ||||
|  |  | |||
|  | @ -6,6 +6,7 @@ | |||
| 
 | ||||
| #include "command_base.h" | ||||
| #include "core/filterpreset.h" | ||||
| #include "core/device.h" | ||||
| 
 | ||||
| #include <QVector> | ||||
| 
 | ||||
|  | @ -99,7 +100,8 @@ 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 filter_preset_table *filter_presets, int flags, const QString &source); | ||||
| 		    struct device_table *devices, struct filter_preset_table *filter_presets, int flags, | ||||
| 		    const QString &source); | ||||
| private: | ||||
| 	void undoit() override; | ||||
| 	void redoit() override; | ||||
|  | @ -108,6 +110,7 @@ private: | |||
| 	// For redo and undo
 | ||||
| 	DivesAndTripsToAdd	divesToAdd; | ||||
| 	DivesAndSitesToRemove	divesAndSitesToRemove; | ||||
| 	struct device_table	devicesToAddAndRemove; | ||||
| 
 | ||||
| 	// For redo
 | ||||
| 	std::vector<OwningDiveSitePtr>	sitesToAdd; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue