mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	Undo: don't send signals batched by trip
Since the default view is batched by trips, signals were sent trip-wise. This seemed like a good idea at first, but when more and more parts used these signals, it became a burden. Therefore push the batching to the part of the code where it is needed: the trip view. The divesAdded and divesDeleted are not yet converted, because these are combined with trip addition/deletion. This should also be detangled, but not now. Since the dive-lists were sorted in the processByTrip function, the dive-list model now does its own sorting. This will have to be audited. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
		
							parent
							
								
									cbcddaa396
								
							
						
					
					
						commit
						27944a52b1
					
				
					 18 changed files with 193 additions and 185 deletions
				
			
		| 
						 | 
					@ -37,39 +37,29 @@ enum class TripField {
 | 
				
			||||||
class DiveListNotifier : public QObject {
 | 
					class DiveListNotifier : public QObject {
 | 
				
			||||||
	Q_OBJECT
 | 
						Q_OBJECT
 | 
				
			||||||
signals:
 | 
					signals:
 | 
				
			||||||
 | 
						// Note that there are no signals for trips being added and created
 | 
				
			||||||
	// Note that there are no signals for trips being added / created / time-shifted,
 | 
						// because these events never happen without a dive being added, removed or moved.
 | 
				
			||||||
	// because these events never happen without a dive being added / created / time-shifted.
 | 
						// The dives are always sorted according to the dives_less_than() function of the core.
 | 
				
			||||||
 | 
					 | 
				
			||||||
	// We send one divesAdded, divesDeleted, divesChanged and divesTimeChanged, divesSelected
 | 
					 | 
				
			||||||
	// signal per trip (non-associated dives being considered part of the null trip). This is
 | 
					 | 
				
			||||||
	// ideal for the tree-view, but might be not-so-perfect for the list view, if trips intermingle
 | 
					 | 
				
			||||||
	// or the deletion spans multiple trips. But most of the time only dives of a single trip
 | 
					 | 
				
			||||||
	// will be affected and trips don't overlap, so these considerations are moot.
 | 
					 | 
				
			||||||
	// Notes:
 | 
					 | 
				
			||||||
	// - The dives are always sorted by according to the dives_less_than() function of the core.
 | 
					 | 
				
			||||||
	// - The "trip" arguments are null for top-level-dives.
 | 
					 | 
				
			||||||
	void divesAdded(dive_trip *trip, bool addTrip, const QVector<dive *> &dives);
 | 
						void divesAdded(dive_trip *trip, bool addTrip, const QVector<dive *> &dives);
 | 
				
			||||||
	void divesDeleted(dive_trip *trip, bool deleteTrip, const QVector<dive *> &dives);
 | 
						void divesDeleted(dive_trip *trip, bool deleteTrip, const QVector<dive *> &dives);
 | 
				
			||||||
	void divesChanged(dive_trip *trip, const QVector<dive *> &dives, DiveField field);
 | 
					 | 
				
			||||||
	void divesMovedBetweenTrips(dive_trip *from, dive_trip *to, bool deleteFrom, bool createTo, const QVector<dive *> &dives);
 | 
						void divesMovedBetweenTrips(dive_trip *from, dive_trip *to, bool deleteFrom, bool createTo, const QVector<dive *> &dives);
 | 
				
			||||||
	void divesTimeChanged(dive_trip *trip, timestamp_t delta, const QVector<dive *> &dives);
 | 
						void divesChanged(const QVector<dive *> &dives, DiveField field);
 | 
				
			||||||
 | 
						void divesTimeChanged(timestamp_t delta, const QVector<dive *> &dives);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void cylindersReset(dive_trip *trip, const QVector<dive *> &dives);
 | 
						void cylindersReset(const QVector<dive *> &dives);
 | 
				
			||||||
	void weightsystemsReset(dive_trip *trip, const QVector<dive *> &dives);
 | 
						void weightsystemsReset(const QVector<dive *> &dives);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Trip edited signal
 | 
						// Trip edited signal
 | 
				
			||||||
	void tripChanged(dive_trip *trip, TripField field);
 | 
						void tripChanged(dive_trip *trip, TripField field);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Selection-signals come in two kinds:
 | 
						// Selection-signals come in two kinds:
 | 
				
			||||||
	//  - divesSelected, divesDeselected and currentDiveChanged are finer grained and are
 | 
						//  - divesSelected, divesDeselected and currentDiveChanged are are used by the dive-list
 | 
				
			||||||
	//    called batch-wise per trip (except currentDiveChanged, of course). These signals
 | 
						//    model and view to correctly highlight the correct dives.
 | 
				
			||||||
	//    are used by the dive-list model and view to correctly highlight the correct dives.
 | 
					 | 
				
			||||||
	//  - selectionChanged() is called once at the end of commands if either the selection
 | 
						//  - selectionChanged() is called once at the end of commands if either the selection
 | 
				
			||||||
	//    or the current dive changed. It is used by the main-window / profile to update
 | 
						//    or the current dive changed. It is used by the main-window / profile to update
 | 
				
			||||||
	//    their data.
 | 
						//    their data.
 | 
				
			||||||
	void divesSelected(dive_trip *trip, const QVector<dive *> &dives);
 | 
						void divesSelected(const QVector<dive *> &dives);
 | 
				
			||||||
	void divesDeselected(dive_trip *trip, const QVector<dive *> &dives);
 | 
						void divesDeselected(const QVector<dive *> &dives);
 | 
				
			||||||
	void currentDiveChanged();
 | 
						void currentDiveChanged();
 | 
				
			||||||
	void selectionChanged();
 | 
						void selectionChanged();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -89,6 +89,37 @@ dive *DiveListBase::addDive(DiveToAdd &d)
 | 
				
			||||||
	return res;
 | 
						return res;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Some signals are sent in batches per trip. To avoid writing the same loop
 | 
				
			||||||
 | 
					// twice, this template takes a vector of trip / dive pairs, sorts it
 | 
				
			||||||
 | 
					// by trip and then calls a function-object with trip and a QVector of dives in that trip.
 | 
				
			||||||
 | 
					// The dives are sorted by the dive_less_than() function defined in the core.
 | 
				
			||||||
 | 
					// Input parameters:
 | 
				
			||||||
 | 
					//	- dives: a vector of trip,dive pairs, which will be sorted and processed in batches by trip.
 | 
				
			||||||
 | 
					//	- action: a function object, taking a trip-pointer and a QVector of dives, which will be called for each batch.
 | 
				
			||||||
 | 
					template<typename Function>
 | 
				
			||||||
 | 
					void processByTrip(std::vector<std::pair<dive_trip *, dive *>> &dives, Function action)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						// Sort lexicographically by trip then according to the dive_less_than() function.
 | 
				
			||||||
 | 
						std::sort(dives.begin(), dives.end(),
 | 
				
			||||||
 | 
							  [](const std::pair<dive_trip *, dive *> &e1, const std::pair<dive_trip *, dive *> &e2)
 | 
				
			||||||
 | 
							  { return e1.first == e2.first ? dive_less_than(e1.second, e2.second) : e1.first < e2.first; });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Then, process the dives in batches by trip
 | 
				
			||||||
 | 
						size_t i, j; // Begin and end of batch
 | 
				
			||||||
 | 
						for (i = 0; i < dives.size(); i = j) {
 | 
				
			||||||
 | 
							dive_trip *trip = dives[i].first;
 | 
				
			||||||
 | 
							for (j = i + 1; j < dives.size() && dives[j].first == trip; ++j)
 | 
				
			||||||
 | 
								; // pass
 | 
				
			||||||
 | 
							// Copy dives into a QVector. Some sort of "range_view" would be ideal, but Qt doesn't work this way.
 | 
				
			||||||
 | 
							QVector<dive *> divesInTrip(j - i);
 | 
				
			||||||
 | 
							for (size_t k = i; k < j; ++k)
 | 
				
			||||||
 | 
								divesInTrip[k - i] = dives[k].second;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Finally, emit the signal
 | 
				
			||||||
 | 
							action(trip, divesInTrip);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// This helper function calls removeDive() on a list of dives to be removed and
 | 
					// This helper function calls removeDive() on a list of dives to be removed and
 | 
				
			||||||
// returns a vector of corresponding DiveToAdd objects, which can later be readded.
 | 
					// returns a vector of corresponding DiveToAdd objects, which can later be readded.
 | 
				
			||||||
// Moreover, a vector of deleted trips is returned, if trips became empty.
 | 
					// Moreover, a vector of deleted trips is returned, if trips became empty.
 | 
				
			||||||
| 
						 | 
					@ -143,8 +174,10 @@ DivesAndSitesToRemove DiveListBase::addDives(DivesAndTripsToAdd &toAdd)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	std::vector<dive *> res;
 | 
						std::vector<dive *> res;
 | 
				
			||||||
	std::vector<dive_site *> sites;
 | 
						std::vector<dive_site *> sites;
 | 
				
			||||||
 | 
						std::vector<std::pair<dive_trip *, dive *>> dives;
 | 
				
			||||||
	res.resize(toAdd.dives.size());
 | 
						res.resize(toAdd.dives.size());
 | 
				
			||||||
	sites.reserve(toAdd.sites.size());
 | 
						sites.reserve(toAdd.sites.size());
 | 
				
			||||||
 | 
						dives.reserve(toAdd.sites.size());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Make sure that the dive list is sorted. The added dives will be sent in a signal
 | 
						// Make sure that the dive list is sorted. The added dives will be sent in a signal
 | 
				
			||||||
	// and the recipients assume that the dives are sorted the same way as they are
 | 
						// and the recipients assume that the dives are sorted the same way as they are
 | 
				
			||||||
| 
						 | 
					@ -157,8 +190,10 @@ DivesAndSitesToRemove DiveListBase::addDives(DivesAndTripsToAdd &toAdd)
 | 
				
			||||||
	// Note: the idiomatic STL-way would be std::transform, but let's use a loop since
 | 
						// Note: the idiomatic STL-way would be std::transform, but let's use a loop since
 | 
				
			||||||
	// that is closer to classical C-style.
 | 
						// that is closer to classical C-style.
 | 
				
			||||||
	auto it2 = res.rbegin();
 | 
						auto it2 = res.rbegin();
 | 
				
			||||||
	for (auto it = toAdd.dives.rbegin(); it != toAdd.dives.rend(); ++it, ++it2)
 | 
						for (auto it = toAdd.dives.rbegin(); it != toAdd.dives.rend(); ++it, ++it2) {
 | 
				
			||||||
		*it2 = addDive(*it);
 | 
							*it2 = addDive(*it);
 | 
				
			||||||
 | 
							dives.push_back({ (*it2)->divetrip, *it2 });
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	toAdd.dives.clear();
 | 
						toAdd.dives.clear();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// If the dives belong to new trips, add these as well.
 | 
						// If the dives belong to new trips, add these as well.
 | 
				
			||||||
| 
						 | 
					@ -180,7 +215,7 @@ DivesAndSitesToRemove DiveListBase::addDives(DivesAndTripsToAdd &toAdd)
 | 
				
			||||||
	toAdd.sites.clear();
 | 
						toAdd.sites.clear();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Send signals by trip.
 | 
						// Send signals by trip.
 | 
				
			||||||
	processByTrip(res, [&](dive_trip *trip, const QVector<dive *> &divesInTrip) {
 | 
						processByTrip(dives, [&](dive_trip *trip, const QVector<dive *> &divesInTrip) {
 | 
				
			||||||
		// Now, let's check if this trip is supposed to be created, by checking if it was marked as "add it".
 | 
							// Now, let's check if this trip is supposed to be created, by checking if it was marked as "add it".
 | 
				
			||||||
		bool createTrip = trip && std::find(addedTrips.begin(), addedTrips.end(), trip) != addedTrips.end();
 | 
							bool createTrip = trip && std::find(addedTrips.begin(), addedTrips.end(), trip) != addedTrips.end();
 | 
				
			||||||
		// Finally, emit the signal
 | 
							// Finally, emit the signal
 | 
				
			||||||
| 
						 | 
					@ -191,30 +226,21 @@ DivesAndSitesToRemove DiveListBase::addDives(DivesAndTripsToAdd &toAdd)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// This helper function renumbers dives according to an array of id/number pairs.
 | 
					// This helper function renumbers dives according to an array of id/number pairs.
 | 
				
			||||||
// The old numbers are stored in the array, thus calling this function twice has no effect.
 | 
					// The old numbers are stored in the array, thus calling this function twice has no effect.
 | 
				
			||||||
// TODO: switch from uniq-id to indices once all divelist-actions are controlled by undo-able commands
 | 
					 | 
				
			||||||
static void renumberDives(QVector<QPair<dive *, int>> &divesToRenumber)
 | 
					static void renumberDives(QVector<QPair<dive *, int>> &divesToRenumber)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						QVector<dive *> dives;
 | 
				
			||||||
 | 
						dives.reserve(divesToRenumber.size());
 | 
				
			||||||
	for (auto &pair: divesToRenumber) {
 | 
						for (auto &pair: divesToRenumber) {
 | 
				
			||||||
		dive *d = pair.first;
 | 
							dive *d = pair.first;
 | 
				
			||||||
		if (!d)
 | 
							if (!d)
 | 
				
			||||||
			continue;
 | 
								continue;
 | 
				
			||||||
		std::swap(d->number, pair.second);
 | 
							std::swap(d->number, pair.second);
 | 
				
			||||||
 | 
							dives.push_back(d);
 | 
				
			||||||
		invalidate_dive_cache(d);
 | 
							invalidate_dive_cache(d);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Emit changed signals per trip.
 | 
					 | 
				
			||||||
	// First, collect all dives and sort by trip
 | 
					 | 
				
			||||||
	std::vector<std::pair<dive_trip *, dive *>> dives;
 | 
					 | 
				
			||||||
	dives.reserve(divesToRenumber.size());
 | 
					 | 
				
			||||||
	for (const auto &pair: divesToRenumber) {
 | 
					 | 
				
			||||||
		dive *d = pair.first;
 | 
					 | 
				
			||||||
		dives.push_back({ d->divetrip, d });
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// Send signals.
 | 
						// Send signals.
 | 
				
			||||||
	processByTrip(dives, [&](dive_trip *trip, const QVector<dive *> &divesInTrip) {
 | 
						emit diveListNotifier.divesChanged(dives, DiveField::NR);
 | 
				
			||||||
		emit diveListNotifier.divesChanged(trip, divesInTrip, DiveField::NR);
 | 
					 | 
				
			||||||
	});
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// This helper function moves a dive to a trip. The old trip is recorded in the
 | 
					// This helper function moves a dive to a trip. The old trip is recorded in the
 | 
				
			||||||
| 
						 | 
					@ -571,20 +597,22 @@ ShiftTime::ShiftTime(const QVector<dive *> &changedDives, int amount)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void ShiftTime::redoit()
 | 
					void ShiftTime::redoit()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	for (dive *d: diveList)
 | 
						std::vector<dive_trip *> trips;
 | 
				
			||||||
 | 
						for (dive *d: diveList) {
 | 
				
			||||||
		d->when += timeChanged;
 | 
							d->when += timeChanged;
 | 
				
			||||||
 | 
							if (d->divetrip && std::find(trips.begin(), trips.end(), d->divetrip) == trips.end())
 | 
				
			||||||
 | 
								trips.push_back(d->divetrip);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Changing times may have unsorted the dive table
 | 
						// Changing times may have unsorted the dive and trip tables
 | 
				
			||||||
	sort_dive_table(&dive_table);
 | 
						sort_dive_table(&dive_table);
 | 
				
			||||||
	sort_trip_table(&trip_table);
 | 
						sort_trip_table(&trip_table);
 | 
				
			||||||
 | 
						for (dive_trip *trip: trips)
 | 
				
			||||||
	// Send signals per trip (see comments in DiveListNotifier.h) and sort tables.
 | 
					 | 
				
			||||||
	processByTrip(diveList, [&](dive_trip *trip, const QVector<dive *> &divesInTrip) {
 | 
					 | 
				
			||||||
		if (trip)
 | 
					 | 
				
			||||||
		sort_dive_table(&trip->dives); // Keep the trip-table in order
 | 
							sort_dive_table(&trip->dives); // Keep the trip-table in order
 | 
				
			||||||
		emit diveListNotifier.divesTimeChanged(trip, timeChanged, divesInTrip);
 | 
					
 | 
				
			||||||
		emit diveListNotifier.divesChanged(trip, divesInTrip, DiveField::DATETIME);
 | 
						// Send signals
 | 
				
			||||||
	});
 | 
						emit diveListNotifier.divesTimeChanged(timeChanged, diveList);
 | 
				
			||||||
 | 
						emit diveListNotifier.divesChanged(diveList, DiveField::DATETIME);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Negate the time-shift so that the next call does the reverse
 | 
						// Negate the time-shift so that the next call does the reverse
 | 
				
			||||||
	timeChanged = -timeChanged;
 | 
						timeChanged = -timeChanged;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -18,7 +18,7 @@ namespace Command {
 | 
				
			||||||
static std::vector<dive_site *> addDiveSites(std::vector<OwningDiveSitePtr> &sites)
 | 
					static std::vector<dive_site *> addDiveSites(std::vector<OwningDiveSitePtr> &sites)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	std::vector<dive_site *> res;
 | 
						std::vector<dive_site *> res;
 | 
				
			||||||
	std::vector<dive *> changedDives;
 | 
						QVector<dive *> changedDives;
 | 
				
			||||||
	res.reserve(sites.size());
 | 
						res.reserve(sites.size());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (OwningDiveSitePtr &ds: sites) {
 | 
						for (OwningDiveSitePtr &ds: sites) {
 | 
				
			||||||
| 
						 | 
					@ -36,9 +36,7 @@ static std::vector<dive_site *> addDiveSites(std::vector<OwningDiveSitePtr> &sit
 | 
				
			||||||
		emit diveListNotifier.diveSiteAdded(res.back(), idx); // Inform frontend of new dive site.
 | 
							emit diveListNotifier.diveSiteAdded(res.back(), idx); // Inform frontend of new dive site.
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	processByTrip(changedDives, [&](dive_trip *trip, const QVector<dive *> &divesInTrip) {
 | 
						emit diveListNotifier.divesChanged(changedDives, DiveField::DIVESITE);
 | 
				
			||||||
		emit diveListNotifier.divesChanged(trip, divesInTrip, DiveField::DIVESITE);
 | 
					 | 
				
			||||||
	});
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Clear vector of unused owning pointers
 | 
						// Clear vector of unused owning pointers
 | 
				
			||||||
	sites.clear();
 | 
						sites.clear();
 | 
				
			||||||
| 
						 | 
					@ -52,7 +50,7 @@ static std::vector<dive_site *> addDiveSites(std::vector<OwningDiveSitePtr> &sit
 | 
				
			||||||
static std::vector<OwningDiveSitePtr> removeDiveSites(std::vector<dive_site *> &sites)
 | 
					static std::vector<OwningDiveSitePtr> removeDiveSites(std::vector<dive_site *> &sites)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	std::vector<OwningDiveSitePtr> res;
 | 
						std::vector<OwningDiveSitePtr> res;
 | 
				
			||||||
	std::vector<dive *> changedDives;
 | 
						QVector<dive *> changedDives;
 | 
				
			||||||
	res.reserve(sites.size());
 | 
						res.reserve(sites.size());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (dive_site *ds: sites) {
 | 
						for (dive_site *ds: sites) {
 | 
				
			||||||
| 
						 | 
					@ -69,9 +67,7 @@ static std::vector<OwningDiveSitePtr> removeDiveSites(std::vector<dive_site *> &
 | 
				
			||||||
		emit diveListNotifier.diveSiteDeleted(ds, idx); // Inform frontend of removed dive site.
 | 
							emit diveListNotifier.diveSiteDeleted(ds, idx); // Inform frontend of removed dive site.
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	processByTrip(changedDives, [&](dive_trip *trip, const QVector<dive *> &divesInTrip) {
 | 
						emit diveListNotifier.divesChanged(changedDives, DiveField::DIVESITE);
 | 
				
			||||||
		emit diveListNotifier.divesChanged(trip, divesInTrip, DiveField::DIVESITE);
 | 
					 | 
				
			||||||
	});
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	sites.clear();
 | 
						sites.clear();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -363,7 +359,7 @@ void MergeDiveSites::redo()
 | 
				
			||||||
	sitesToAdd = std::move(removeDiveSites(sitesToRemove));
 | 
						sitesToAdd = std::move(removeDiveSites(sitesToRemove));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Remember which dives changed so that we can send a single dives-edited signal
 | 
						// Remember which dives changed so that we can send a single dives-edited signal
 | 
				
			||||||
	std::vector<dive *> divesChanged;
 | 
						QVector<dive *> divesChanged;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// The dives of the above dive sites were reset to no dive sites.
 | 
						// The dives of the above dive sites were reset to no dive sites.
 | 
				
			||||||
	// Add them to the merged-into dive site. Thankfully, we remember
 | 
						// Add them to the merged-into dive site. Thankfully, we remember
 | 
				
			||||||
| 
						 | 
					@ -374,15 +370,13 @@ void MergeDiveSites::redo()
 | 
				
			||||||
			divesChanged.push_back(site->dives.dives[i]);
 | 
								divesChanged.push_back(site->dives.dives[i]);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	processByTrip(divesChanged, [&](dive_trip *trip, const QVector<dive *> &divesInTrip) {
 | 
						emit diveListNotifier.divesChanged(divesChanged, DiveField::DIVESITE);
 | 
				
			||||||
		emit diveListNotifier.divesChanged(trip, divesInTrip, DiveField::DIVESITE);
 | 
					 | 
				
			||||||
	});
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void MergeDiveSites::undo()
 | 
					void MergeDiveSites::undo()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	// Remember which dives changed so that we can send a single dives-edited signal
 | 
						// Remember which dives changed so that we can send a single dives-edited signal
 | 
				
			||||||
	std::vector<dive *> divesChanged;
 | 
						QVector<dive *> divesChanged;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Before readding the dive sites, unregister the corresponding dives so that they can be
 | 
						// Before readding the dive sites, unregister the corresponding dives so that they can be
 | 
				
			||||||
	// readded to their old dive sites.
 | 
						// readded to their old dive sites.
 | 
				
			||||||
| 
						 | 
					@ -395,9 +389,7 @@ void MergeDiveSites::undo()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	sitesToRemove = std::move(addDiveSites(sitesToAdd));
 | 
						sitesToRemove = std::move(addDiveSites(sitesToAdd));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	processByTrip(divesChanged, [&](dive_trip *trip, const QVector<dive *> &divesInTrip) {
 | 
						emit diveListNotifier.divesChanged(divesChanged, DiveField::DIVESITE);
 | 
				
			||||||
		emit diveListNotifier.divesChanged(trip, divesInTrip, DiveField::DIVESITE);
 | 
					 | 
				
			||||||
	});
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} // namespace Command
 | 
					} // namespace Command
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -97,9 +97,7 @@ void EditBase<T>::undo()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Send signals.
 | 
						// Send signals.
 | 
				
			||||||
	DiveField id = fieldId();
 | 
						DiveField id = fieldId();
 | 
				
			||||||
	processByTrip(dives, [&](dive_trip *trip, const QVector<dive *> &divesInTrip) {
 | 
						emit diveListNotifier.divesChanged(QVector<dive *>::fromStdVector(dives), id);
 | 
				
			||||||
		emit diveListNotifier.divesChanged(trip, divesInTrip, id);
 | 
					 | 
				
			||||||
	});
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (setSelection(selectedDives, current))
 | 
						if (setSelection(selectedDives, current))
 | 
				
			||||||
		emit diveListNotifier.selectionChanged(); // If the selection changed -> tell the frontend
 | 
							emit diveListNotifier.selectionChanged(); // If the selection changed -> tell the frontend
 | 
				
			||||||
| 
						 | 
					@ -539,9 +537,7 @@ void EditTagsBase::undo()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Send signals.
 | 
						// Send signals.
 | 
				
			||||||
	DiveField id = fieldId();
 | 
						DiveField id = fieldId();
 | 
				
			||||||
	processByTrip(dives, [&](dive_trip *trip, const QVector<dive *> &divesInTrip) {
 | 
						emit diveListNotifier.divesChanged(QVector<dive *>::fromStdVector(dives), id);
 | 
				
			||||||
		emit diveListNotifier.divesChanged(trip, divesInTrip, id);
 | 
					 | 
				
			||||||
	});
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (setSelection(selectedDives, current))
 | 
						if (setSelection(selectedDives, current))
 | 
				
			||||||
		emit diveListNotifier.selectionChanged(); // If the selection changed -> tell the frontend
 | 
							emit diveListNotifier.selectionChanged(); // If the selection changed -> tell the frontend
 | 
				
			||||||
| 
						 | 
					@ -750,7 +746,7 @@ void PasteDives::undo()
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	ownedDiveSites.clear();
 | 
						ownedDiveSites.clear();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	std::vector<dive *> divesToNotify; // Remember dives so that we can send signals later
 | 
						QVector<dive *> divesToNotify; // Remember dives so that we can send signals later
 | 
				
			||||||
	divesToNotify.reserve(dives.size());
 | 
						divesToNotify.reserve(dives.size());
 | 
				
			||||||
	for (PasteState &state: dives) {
 | 
						for (PasteState &state: dives) {
 | 
				
			||||||
		divesToNotify.push_back(state.d);
 | 
							divesToNotify.push_back(state.d);
 | 
				
			||||||
| 
						 | 
					@ -780,28 +776,26 @@ void PasteDives::undo()
 | 
				
			||||||
	// TODO: We send one signal per changed field. This means that the dive list may
 | 
						// TODO: We send one signal per changed field. This means that the dive list may
 | 
				
			||||||
	// update the entry numerous times. Perhaps change the field-id into flags?
 | 
						// update the entry numerous times. Perhaps change the field-id into flags?
 | 
				
			||||||
	// There seems to be a number of enums / flags describing dive fields. Perhaps unify them all?
 | 
						// There seems to be a number of enums / flags describing dive fields. Perhaps unify them all?
 | 
				
			||||||
	processByTrip(divesToNotify, [&](dive_trip *trip, const QVector<dive *> &divesInTrip) {
 | 
					 | 
				
			||||||
	if (what.notes)
 | 
						if (what.notes)
 | 
				
			||||||
			emit diveListNotifier.divesChanged(trip, divesInTrip, DiveField::NOTES);
 | 
							emit diveListNotifier.divesChanged(divesToNotify, DiveField::NOTES);
 | 
				
			||||||
	if (what.divemaster)
 | 
						if (what.divemaster)
 | 
				
			||||||
			emit diveListNotifier.divesChanged(trip, divesInTrip, DiveField::DIVEMASTER);
 | 
							emit diveListNotifier.divesChanged(divesToNotify, DiveField::DIVEMASTER);
 | 
				
			||||||
	if (what.buddy)
 | 
						if (what.buddy)
 | 
				
			||||||
			emit diveListNotifier.divesChanged(trip, divesInTrip, DiveField::BUDDY);
 | 
							emit diveListNotifier.divesChanged(divesToNotify, DiveField::BUDDY);
 | 
				
			||||||
	if (what.suit)
 | 
						if (what.suit)
 | 
				
			||||||
			emit diveListNotifier.divesChanged(trip, divesInTrip, DiveField::SUIT);
 | 
							emit diveListNotifier.divesChanged(divesToNotify, DiveField::SUIT);
 | 
				
			||||||
	if (what.rating)
 | 
						if (what.rating)
 | 
				
			||||||
			emit diveListNotifier.divesChanged(trip, divesInTrip, DiveField::RATING);
 | 
							emit diveListNotifier.divesChanged(divesToNotify, DiveField::RATING);
 | 
				
			||||||
	if (what.visibility)
 | 
						if (what.visibility)
 | 
				
			||||||
			emit diveListNotifier.divesChanged(trip, divesInTrip, DiveField::VISIBILITY);
 | 
							emit diveListNotifier.divesChanged(divesToNotify, DiveField::VISIBILITY);
 | 
				
			||||||
	if (what.divesite)
 | 
						if (what.divesite)
 | 
				
			||||||
			emit diveListNotifier.divesChanged(trip, divesInTrip, DiveField::DIVESITE);
 | 
							emit diveListNotifier.divesChanged(divesToNotify, DiveField::DIVESITE);
 | 
				
			||||||
	if (what.tags)
 | 
						if (what.tags)
 | 
				
			||||||
			emit diveListNotifier.divesChanged(trip, divesInTrip, DiveField::TAGS);
 | 
							emit diveListNotifier.divesChanged(divesToNotify, DiveField::TAGS);
 | 
				
			||||||
	if (what.cylinders)
 | 
						if (what.cylinders)
 | 
				
			||||||
			emit diveListNotifier.cylindersReset(trip, divesInTrip);
 | 
							emit diveListNotifier.cylindersReset(divesToNotify);
 | 
				
			||||||
	if (what.weights)
 | 
						if (what.weights)
 | 
				
			||||||
			emit diveListNotifier.weightsystemsReset(trip, divesInTrip);
 | 
							emit diveListNotifier.weightsystemsReset(divesToNotify);
 | 
				
			||||||
	});
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (diveSiteListChanged)
 | 
						if (diveSiteListChanged)
 | 
				
			||||||
		MapWidget::instance()->reload();
 | 
							MapWidget::instance()->reload();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -46,8 +46,8 @@ bool setSelection(const std::vector<dive *> &selection, dive *currentDive)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	// To do so, generate vectors of dives to be selected and deselected.
 | 
						// To do so, generate vectors of dives to be selected and deselected.
 | 
				
			||||||
	// We send signals batched by trip, so keep track of trip/dive pairs.
 | 
						// We send signals batched by trip, so keep track of trip/dive pairs.
 | 
				
			||||||
	std::vector<std::pair<dive_trip *, dive *>> divesToSelect;
 | 
						QVector<dive *> divesToSelect;
 | 
				
			||||||
	std::vector<std::pair<dive_trip *, dive *>> divesToDeselect;
 | 
						QVector<dive *> divesToDeselect;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// TODO: We might want to keep track of selected dives in a more efficient way!
 | 
						// TODO: We might want to keep track of selected dives in a more efficient way!
 | 
				
			||||||
	int i;
 | 
						int i;
 | 
				
			||||||
| 
						 | 
					@ -73,20 +73,16 @@ bool setSelection(const std::vector<dive *> &selection, dive *currentDive)
 | 
				
			||||||
		if (newState && !d->selected) {
 | 
							if (newState && !d->selected) {
 | 
				
			||||||
			d->selected = true;
 | 
								d->selected = true;
 | 
				
			||||||
			++amount_selected;
 | 
								++amount_selected;
 | 
				
			||||||
			divesToSelect.push_back({ d->divetrip, d });
 | 
								divesToSelect.push_back(d);
 | 
				
			||||||
		} else if (!newState && d->selected) {
 | 
							} else if (!newState && d->selected) {
 | 
				
			||||||
			d->selected = false;
 | 
								d->selected = false;
 | 
				
			||||||
			divesToDeselect.push_back({ d->divetrip, d });
 | 
								divesToDeselect.push_back(d);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Send the select and deselect signals
 | 
						// Send the select and deselect signals
 | 
				
			||||||
	processByTrip(divesToSelect, [&](dive_trip *trip, const QVector<dive *> &divesInTrip) {
 | 
						emit diveListNotifier.divesSelected(divesToSelect);
 | 
				
			||||||
		emit diveListNotifier.divesSelected(trip, divesInTrip);
 | 
						emit diveListNotifier.divesDeselected(divesToDeselect);
 | 
				
			||||||
	});
 | 
					 | 
				
			||||||
	processByTrip(divesToDeselect, [&](dive_trip *trip, const QVector<dive *> &divesInTrip) {
 | 
					 | 
				
			||||||
		emit diveListNotifier.divesDeselected(trip, divesInTrip);
 | 
					 | 
				
			||||||
	});
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	bool currentDiveChanged = false;
 | 
						bool currentDiveChanged = false;
 | 
				
			||||||
	if (!currentDive) {
 | 
						if (!currentDive) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -12,50 +12,6 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace Command {
 | 
					namespace Command {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Generally, signals are sent in batches per trip. To avoid writing the same loop
 | 
					 | 
				
			||||||
// again and again, this template takes a vector of trip / dive pairs, sorts it
 | 
					 | 
				
			||||||
// by trip and then calls a function-object with trip and a QVector of dives in that trip.
 | 
					 | 
				
			||||||
// The dives are sorted by the dive_less_than() function defined in the core.
 | 
					 | 
				
			||||||
// Input parameters:
 | 
					 | 
				
			||||||
//	- dives: a vector of trip,dive pairs, which will be sorted and processed in batches by trip.
 | 
					 | 
				
			||||||
//	- action: a function object, taking a trip-pointer and a QVector of dives, which will be called for each batch.
 | 
					 | 
				
			||||||
template<typename Function>
 | 
					 | 
				
			||||||
void processByTrip(std::vector<std::pair<dive_trip *, dive *>> &dives, Function action)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	// Use std::tie for lexicographical sorting of trip, then start-time
 | 
					 | 
				
			||||||
	std::sort(dives.begin(), dives.end(),
 | 
					 | 
				
			||||||
		  [](const std::pair<dive_trip *, dive *> &e1, const std::pair<dive_trip *, dive *> &e2)
 | 
					 | 
				
			||||||
		  { return e1.first == e2.first ? dive_less_than(e1.second, e2.second) : e1.first < e2.first; });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// Then, process the dives in batches by trip
 | 
					 | 
				
			||||||
	size_t i, j; // Begin and end of batch
 | 
					 | 
				
			||||||
	for (i = 0; i < dives.size(); i = j) {
 | 
					 | 
				
			||||||
		dive_trip *trip = dives[i].first;
 | 
					 | 
				
			||||||
		for (j = i + 1; j < dives.size() && dives[j].first == trip; ++j)
 | 
					 | 
				
			||||||
			; // pass
 | 
					 | 
				
			||||||
		// Copy dives into a QVector. Some sort of "range_view" would be ideal, but Qt doesn't work this way.
 | 
					 | 
				
			||||||
		QVector<dive *> divesInTrip(j - i);
 | 
					 | 
				
			||||||
		for (size_t k = i; k < j; ++k)
 | 
					 | 
				
			||||||
			divesInTrip[k - i] = dives[k].second;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		// Finally, emit the signal
 | 
					 | 
				
			||||||
		action(trip, divesInTrip);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// The processByTrip() function above takes a vector if (trip, dive) pairs.
 | 
					 | 
				
			||||||
// This overload takes a vector of dives.
 | 
					 | 
				
			||||||
template<typename Vector, typename Function>
 | 
					 | 
				
			||||||
void processByTrip(Vector &divesIn, Function action)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	std::vector<std::pair<dive_trip *, dive *>> dives;
 | 
					 | 
				
			||||||
	dives.reserve(divesIn.size());
 | 
					 | 
				
			||||||
	for (dive *d: divesIn)
 | 
					 | 
				
			||||||
		dives.push_back({ d->divetrip, d });
 | 
					 | 
				
			||||||
	processByTrip(dives, action);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Reset the selection to the dives of the "selection" vector and send the appropriate signals.
 | 
					// Reset the selection to the dives of the "selection" vector and send the appropriate signals.
 | 
				
			||||||
// Set the current dive to "currentDive". "currentDive" must be an element of "selection" (or
 | 
					// Set the current dive to "currentDive". "currentDive" must be an element of "selection" (or
 | 
				
			||||||
// null if "seletion" is empty). Return true if the selection or current dive changed.
 | 
					// null if "seletion" is empty). Return true if the selection or current dive changed.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -12,7 +12,6 @@
 | 
				
			||||||
#include "mainwindow.h"
 | 
					#include "mainwindow.h"
 | 
				
			||||||
#include "divelistview.h"
 | 
					#include "divelistview.h"
 | 
				
			||||||
#include "command.h"
 | 
					#include "command.h"
 | 
				
			||||||
#include "core/trip.h" // TODO: Needed because divesChanged uses a trip parameter -> remove that!
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const QUrl urlMapWidget = QUrl(QStringLiteral("qrc:/qml/MapWidget.qml"));
 | 
					static const QUrl urlMapWidget = QUrl(QStringLiteral("qrc:/qml/MapWidget.qml"));
 | 
				
			||||||
static const QUrl urlMapWidgetError = QUrl(QStringLiteral("qrc:/qml/MapWidgetError.qml"));
 | 
					static const QUrl urlMapWidgetError = QUrl(QStringLiteral("qrc:/qml/MapWidgetError.qml"));
 | 
				
			||||||
| 
						 | 
					@ -91,7 +90,7 @@ void MapWidget::coordinatesChanged(struct dive_site *ds, const location_t &locat
 | 
				
			||||||
	Command::editDiveSiteLocation(ds, location);
 | 
						Command::editDiveSiteLocation(ds, location);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void MapWidget::divesChanged(dive_trip *, const QVector<dive *> &, DiveField field)
 | 
					void MapWidget::divesChanged(const QVector<dive *> &, DiveField field)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (field == DiveField::DIVESITE)
 | 
						if (field == DiveField::DIVESITE)
 | 
				
			||||||
		reload();
 | 
							reload();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -31,7 +31,7 @@ public slots:
 | 
				
			||||||
	void selectedDivesChanged(const QList<int> &);
 | 
						void selectedDivesChanged(const QList<int> &);
 | 
				
			||||||
	void coordinatesChanged(struct dive_site *ds, const location_t &);
 | 
						void coordinatesChanged(struct dive_site *ds, const location_t &);
 | 
				
			||||||
	void doneLoading(QQuickWidget::Status status);
 | 
						void doneLoading(QQuickWidget::Status status);
 | 
				
			||||||
	void divesChanged(dive_trip *, const QVector<dive *> &, DiveField field);
 | 
						void divesChanged(const QVector<dive *> &, DiveField field);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
	static MapWidget *m_instance;
 | 
						static MapWidget *m_instance;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,7 +5,6 @@
 | 
				
			||||||
#include "core/units.h"
 | 
					#include "core/units.h"
 | 
				
			||||||
#include "core/dive.h"
 | 
					#include "core/dive.h"
 | 
				
			||||||
#include "desktop-widgets/command.h"
 | 
					#include "desktop-widgets/command.h"
 | 
				
			||||||
#include "core/trip.h" // TODO: Needed because divesChanged uses a trip parameter -> remove that!
 | 
					 | 
				
			||||||
#include "core/qthelper.h"
 | 
					#include "core/qthelper.h"
 | 
				
			||||||
#include "core/statistics.h"
 | 
					#include "core/statistics.h"
 | 
				
			||||||
#include "core/display.h"
 | 
					#include "core/display.h"
 | 
				
			||||||
| 
						 | 
					@ -131,7 +130,7 @@ void TabDiveInformation::updateData()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// This function gets called if a field gets updated by an undo command.
 | 
					// This function gets called if a field gets updated by an undo command.
 | 
				
			||||||
// Refresh the corresponding UI field.
 | 
					// Refresh the corresponding UI field.
 | 
				
			||||||
void TabDiveInformation::divesChanged(dive_trip *trip, const QVector<dive *> &dives, DiveField field)
 | 
					void TabDiveInformation::divesChanged(const QVector<dive *> &dives, DiveField field)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	// If the current dive is not in list of changed dives, do nothing
 | 
						// If the current dive is not in list of changed dives, do nothing
 | 
				
			||||||
	if (!current_dive || !dives.contains(current_dive))
 | 
						if (!current_dive || !dives.contains(current_dive))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -17,7 +17,7 @@ public:
 | 
				
			||||||
	void updateData() override;
 | 
						void updateData() override;
 | 
				
			||||||
	void clear() override;
 | 
						void clear() override;
 | 
				
			||||||
private slots:
 | 
					private slots:
 | 
				
			||||||
	void divesChanged(dive_trip *trip, const QVector<dive *> &dives, DiveField field);
 | 
						void divesChanged(const QVector<dive *> &dives, DiveField field);
 | 
				
			||||||
	void on_atmPressVal_editingFinished();
 | 
						void on_atmPressVal_editingFinished();
 | 
				
			||||||
	void on_atmPressType_currentIndexChanged(int index);
 | 
						void on_atmPressType_currentIndexChanged(int index);
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -281,7 +281,7 @@ static void profileFromDive(struct dive *d)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// This function gets called if a field gets updated by an undo command.
 | 
					// This function gets called if a field gets updated by an undo command.
 | 
				
			||||||
// Refresh the corresponding UI field.
 | 
					// Refresh the corresponding UI field.
 | 
				
			||||||
void MainTab::divesChanged(dive_trip *trip, const QVector<dive *> &dives, DiveField field)
 | 
					void MainTab::divesChanged(const QVector<dive *> &dives, DiveField field)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	// If the current dive is not in list of changed dives, do nothing
 | 
						// If the current dive is not in list of changed dives, do nothing
 | 
				
			||||||
	if (!current_dive || !dives.contains(current_dive))
 | 
						if (!current_dive || !dives.contains(current_dive))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -46,7 +46,7 @@ public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public
 | 
					public
 | 
				
			||||||
slots:
 | 
					slots:
 | 
				
			||||||
	void divesChanged(dive_trip *trip, const QVector<dive *> &dives, DiveField field);
 | 
						void divesChanged(const QVector<dive *> &dives, DiveField field);
 | 
				
			||||||
	void diveSiteEdited(dive_site *ds, int field);
 | 
						void diveSiteEdited(dive_site *ds, int field);
 | 
				
			||||||
	void tripChanged(dive_trip *trip, TripField field);
 | 
						void tripChanged(dive_trip *trip, TripField field);
 | 
				
			||||||
	void updateDiveInfo();
 | 
						void updateDiveInfo();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,7 +7,6 @@
 | 
				
			||||||
#include "qt-models/diveplannermodel.h"
 | 
					#include "qt-models/diveplannermodel.h"
 | 
				
			||||||
#include "core/gettextfromc.h"
 | 
					#include "core/gettextfromc.h"
 | 
				
			||||||
#include "core/subsurface-qt/DiveListNotifier.h"
 | 
					#include "core/subsurface-qt/DiveListNotifier.h"
 | 
				
			||||||
#include "core/trip.h" // TODO: Needed because cylindersReset uses a trip parameter -> remove that!
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
CylindersModel::CylindersModel(QObject *parent) :
 | 
					CylindersModel::CylindersModel(QObject *parent) :
 | 
				
			||||||
	CleanerTableModel(parent),
 | 
						CleanerTableModel(parent),
 | 
				
			||||||
| 
						 | 
					@ -619,7 +618,7 @@ bool CylindersModel::updateBestMixes()
 | 
				
			||||||
	return gasUpdated;
 | 
						return gasUpdated;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void CylindersModel::cylindersReset(dive_trip *trip, const QVector<dive *> &dives)
 | 
					void CylindersModel::cylindersReset(const QVector<dive *> &dives)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	// This model only concerns the currently displayed dive. If this is not among the
 | 
						// This model only concerns the currently displayed dive. If this is not among the
 | 
				
			||||||
	// dives that had their cylinders reset, exit.
 | 
						// dives that had their cylinders reset, exit.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -48,7 +48,7 @@ public:
 | 
				
			||||||
public
 | 
					public
 | 
				
			||||||
slots:
 | 
					slots:
 | 
				
			||||||
	void remove(const QModelIndex &index);
 | 
						void remove(const QModelIndex &index);
 | 
				
			||||||
	void cylindersReset(dive_trip *trip, const QVector<dive *> &dives);
 | 
						void cylindersReset(const QVector<dive *> &dives);
 | 
				
			||||||
	bool updateBestMixes();
 | 
						bool updateBestMixes();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -417,14 +417,14 @@ bool DiveTripModelBase::setData(const QModelIndex &index, const QVariant &value,
 | 
				
			||||||
	return true;
 | 
						return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void DiveTripModelBase::divesSelected(dive_trip *trip, const QVector<dive *> &dives)
 | 
					void DiveTripModelBase::divesSelected(const QVector<dive *> &dives)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	changeDiveSelection(trip, dives, true);
 | 
						changeDiveSelection(dives, true);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void DiveTripModelBase::divesDeselected(dive_trip *trip, const QVector<dive *> &dives)
 | 
					void DiveTripModelBase::divesDeselected(const QVector<dive *> &dives)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	changeDiveSelection(trip, dives, false);
 | 
						changeDiveSelection(dives, false);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Find a range of matching elements in a vector.
 | 
					// Find a range of matching elements in a vector.
 | 
				
			||||||
| 
						 | 
					@ -915,7 +915,38 @@ void DiveTripModelTree::divesDeleted(dive_trip *trip, bool deleteTrip, const QVe
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void DiveTripModelTree::divesChanged(dive_trip *trip, const QVector<dive *> &dives)
 | 
					// The tree-version of the model wants to process the dives per trip.
 | 
				
			||||||
 | 
					// This template takes a vector of dives and calls a function batchwise for each trip.
 | 
				
			||||||
 | 
					template<typename Function>
 | 
				
			||||||
 | 
					void processByTrip(QVector<dive *> dives, Function action)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						// Sort lexicographically by trip then according to the dive_less_than() function.
 | 
				
			||||||
 | 
						std::sort(dives.begin(), dives.end(), [](const dive *d1, const dive *d2)
 | 
				
			||||||
 | 
							  { return d1->divetrip == d2->divetrip ? dive_less_than(d1, d2) : d1->divetrip < d2->divetrip; });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Then, process the dives in batches by trip
 | 
				
			||||||
 | 
						int i, j; // Begin and end of batch
 | 
				
			||||||
 | 
						for (i = 0; i < dives.size(); i = j) {
 | 
				
			||||||
 | 
							dive_trip *trip = dives[i]->divetrip;
 | 
				
			||||||
 | 
							for (j = i + 1; j < dives.size() && dives[j]->divetrip == trip; ++j)
 | 
				
			||||||
 | 
								; // pass
 | 
				
			||||||
 | 
							// Copy dives into a QVector. Some sort of "range_view" would be ideal.
 | 
				
			||||||
 | 
							QVector<dive *> divesInTrip(j - i);
 | 
				
			||||||
 | 
							for (int k = i; k < j; ++k)
 | 
				
			||||||
 | 
								divesInTrip[k - i] = dives[k];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Finally, emit the signal
 | 
				
			||||||
 | 
							action(trip, divesInTrip);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void DiveTripModelTree::divesChanged(const QVector<dive *> &dives)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						processByTrip(dives, [this] (dive_trip *trip, const QVector<dive *> &divesInTrip)
 | 
				
			||||||
 | 
							      { divesChangedTrip(trip, divesInTrip); });
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void DiveTripModelTree::divesChangedTrip(dive_trip *trip, const QVector<dive *> &dives)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	// Update filter flags. TODO: The filter should update the flag by itself when
 | 
						// Update filter flags. TODO: The filter should update the flag by itself when
 | 
				
			||||||
	// recieving the signals below.
 | 
						// recieving the signals below.
 | 
				
			||||||
| 
						 | 
					@ -992,7 +1023,7 @@ void DiveTripModelTree::divesMovedBetweenTrips(dive_trip *from, dive_trip *to, b
 | 
				
			||||||
	// Move dives between trips. This is an "interesting" problem, as we might
 | 
						// Move dives between trips. This is an "interesting" problem, as we might
 | 
				
			||||||
	// move from trip to trip, from trip to top-level or from top-level to trip.
 | 
						// move from trip to trip, from trip to top-level or from top-level to trip.
 | 
				
			||||||
	// Moreover, we might have to add a trip first or delete an old trip.
 | 
						// Moreover, we might have to add a trip first or delete an old trip.
 | 
				
			||||||
	// For simplicity, we will simply used the already existing divesAdded() / divesDeleted()
 | 
						// For simplicity, we will simply use the already existing divesAdded() / divesDeleted()
 | 
				
			||||||
	// functions. This *is* cheating. But let's just try this and see how graceful
 | 
						// functions. This *is* cheating. But let's just try this and see how graceful
 | 
				
			||||||
	// this is handled by Qt and if it gives some ugly UI behavior!
 | 
						// this is handled by Qt and if it gives some ugly UI behavior!
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1006,10 +1037,16 @@ void DiveTripModelTree::divesMovedBetweenTrips(dive_trip *from, dive_trip *to, b
 | 
				
			||||||
	QVector<dive *> selectedDives = filterSelectedDives(dives);
 | 
						QVector<dive *> selectedDives = filterSelectedDives(dives);
 | 
				
			||||||
	divesAdded(to, createTo, dives);
 | 
						divesAdded(to, createTo, dives);
 | 
				
			||||||
	divesDeleted(from, deleteFrom, dives);
 | 
						divesDeleted(from, deleteFrom, dives);
 | 
				
			||||||
	divesSelected(to, selectedDives);
 | 
						changeDiveSelectionTrip(to, dives, true);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void DiveTripModelTree::divesTimeChanged(dive_trip *trip, timestamp_t delta, const QVector<dive *> &dives)
 | 
					void DiveTripModelTree::divesTimeChanged(timestamp_t delta, const QVector<dive *> &dives)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						processByTrip(dives, [this, delta] (dive_trip *trip, const QVector<dive *> &divesInTrip)
 | 
				
			||||||
 | 
							      { divesTimeChangedTrip(trip, delta, divesInTrip); });
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void DiveTripModelTree::divesTimeChangedTrip(dive_trip *trip, timestamp_t delta, const QVector<dive *> &dives)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	// As in the case of divesMovedBetweenTrips(), this is a tricky, but solvable, problem.
 | 
						// As in the case of divesMovedBetweenTrips(), this is a tricky, but solvable, problem.
 | 
				
			||||||
	// We have to consider the direction (delta < 0 or delta >0) and that dives at their destination
 | 
						// We have to consider the direction (delta < 0 or delta >0) and that dives at their destination
 | 
				
			||||||
| 
						 | 
					@ -1024,10 +1061,16 @@ void DiveTripModelTree::divesTimeChanged(dive_trip *trip, timestamp_t delta, con
 | 
				
			||||||
	QVector<dive *> selectedDives = filterSelectedDives(dives);
 | 
						QVector<dive *> selectedDives = filterSelectedDives(dives);
 | 
				
			||||||
	divesDeleted(trip, false, dives);
 | 
						divesDeleted(trip, false, dives);
 | 
				
			||||||
	divesAdded(trip, false, dives);
 | 
						divesAdded(trip, false, dives);
 | 
				
			||||||
	divesSelected(trip, selectedDives);
 | 
						changeDiveSelectionTrip(trip, selectedDives, true);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void DiveTripModelTree::changeDiveSelection(dive_trip *trip, const QVector<dive *> &dives, bool select)
 | 
					void DiveTripModelTree::changeDiveSelection(const QVector<dive *> &dives, bool select)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						processByTrip(dives, [this, select] (dive_trip *trip, const QVector<dive *> &divesInTrip)
 | 
				
			||||||
 | 
							      { changeDiveSelectionTrip(trip, divesInTrip, select); });
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void DiveTripModelTree::changeDiveSelectionTrip(dive_trip *trip, const QVector<dive *> &dives, bool select)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	// We got a number of dives that have been selected. Turn this into QModelIndexes and
 | 
						// We got a number of dives that have been selected. Turn this into QModelIndexes and
 | 
				
			||||||
	// emit a signal, so that views can change the selection.
 | 
						// emit a signal, so that views can change the selection.
 | 
				
			||||||
| 
						 | 
					@ -1198,8 +1241,10 @@ QVariant DiveTripModelList::data(const QModelIndex &index, int role) const
 | 
				
			||||||
	return d ? diveData(d, index.column(), role) : QVariant();
 | 
						return d ? diveData(d, index.column(), role) : QVariant();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void DiveTripModelList::divesAdded(dive_trip *, bool, const QVector<dive *> &dives)
 | 
					void DiveTripModelList::divesAdded(dive_trip *, bool, const QVector<dive *> &divesIn)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						QVector<dive *> dives = divesIn;
 | 
				
			||||||
 | 
						std::sort(dives.begin(), dives.end(), dive_less_than);
 | 
				
			||||||
	addInBatches(items, dives,
 | 
						addInBatches(items, dives,
 | 
				
			||||||
		     &dive_less_than, // comp
 | 
							     &dive_less_than, // comp
 | 
				
			||||||
		     [&](std::vector<dive *> &items, const QVector<dive *> &dives, int idx, int from, int to) { // inserter
 | 
							     [&](std::vector<dive *> &items, const QVector<dive *> &dives, int idx, int from, int to) { // inserter
 | 
				
			||||||
| 
						 | 
					@ -1209,8 +1254,10 @@ void DiveTripModelList::divesAdded(dive_trip *, bool, const QVector<dive *> &div
 | 
				
			||||||
		     });
 | 
							     });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void DiveTripModelList::divesDeleted(dive_trip *trip, bool deleteTrip, const QVector<dive *> &dives)
 | 
					void DiveTripModelList::divesDeleted(dive_trip *, bool, const QVector<dive *> &divesIn)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						QVector<dive *> dives = divesIn;
 | 
				
			||||||
 | 
						std::sort(dives.begin(), dives.end(), dive_less_than);
 | 
				
			||||||
	processRangesZip(items, dives,
 | 
						processRangesZip(items, dives,
 | 
				
			||||||
			 [](const dive *d1, const dive *d2) { return d1 == d2; }, // Condition (std::equal_to only in C++14)
 | 
								 [](const dive *d1, const dive *d2) { return d1 == d2; }, // Condition (std::equal_to only in C++14)
 | 
				
			||||||
			 [&](std::vector<dive *> &items, const QVector<dive *> &, int from, int to, int) -> int { // Action
 | 
								 [&](std::vector<dive *> &items, const QVector<dive *> &, int from, int to, int) -> int { // Action
 | 
				
			||||||
| 
						 | 
					@ -1221,8 +1268,11 @@ void DiveTripModelList::divesDeleted(dive_trip *trip, bool deleteTrip, const QVe
 | 
				
			||||||
				 });
 | 
									 });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void DiveTripModelList::divesChanged(dive_trip *trip, const QVector<dive *> &dives)
 | 
					void DiveTripModelList::divesChanged(const QVector<dive *> &divesIn)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						QVector<dive *> dives = divesIn;
 | 
				
			||||||
 | 
						std::sort(dives.begin(), dives.end(), dive_less_than);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Update filter flags. TODO: The filter should update the flag by itself when
 | 
						// Update filter flags. TODO: The filter should update the flag by itself when
 | 
				
			||||||
	// recieving the signals below.
 | 
						// recieving the signals below.
 | 
				
			||||||
	for (dive *d: dives)
 | 
						for (dive *d: dives)
 | 
				
			||||||
| 
						 | 
					@ -1240,16 +1290,19 @@ void DiveTripModelList::divesChanged(dive_trip *trip, const QVector<dive *> &div
 | 
				
			||||||
			 });
 | 
								 });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void DiveTripModelList::divesTimeChanged(dive_trip *trip, timestamp_t delta, const QVector<dive *> &dives)
 | 
					void DiveTripModelList::divesTimeChanged(timestamp_t delta, const QVector<dive *> &divesIn)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						QVector<dive *> dives = divesIn;
 | 
				
			||||||
 | 
						std::sort(dives.begin(), dives.end(), dive_less_than);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// See comment for DiveTripModelTree::divesTimeChanged above.
 | 
						// See comment for DiveTripModelTree::divesTimeChanged above.
 | 
				
			||||||
	QVector<dive *> selectedDives = filterSelectedDives(dives);
 | 
						QVector<dive *> selectedDives = filterSelectedDives(dives);
 | 
				
			||||||
	divesDeleted(trip, false, dives);
 | 
						divesDeleted(nullptr, false, dives);
 | 
				
			||||||
	divesAdded(trip, false, dives);
 | 
						divesAdded(nullptr, false, dives);
 | 
				
			||||||
	divesSelected(trip, selectedDives);
 | 
						divesSelected(selectedDives);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void DiveTripModelList::changeDiveSelection(dive_trip *trip, const QVector<dive *> &dives, bool select)
 | 
					void DiveTripModelList::changeDiveSelection(const QVector<dive *> &dives, bool select)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	// We got a number of dives that have been selected. Turn this into QModelIndexes and
 | 
						// We got a number of dives that have been selected. Turn this into QModelIndexes and
 | 
				
			||||||
	// emit a signal, so that views can change the selection.
 | 
						// emit a signal, so that views can change the selection.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -92,15 +92,15 @@ signals:
 | 
				
			||||||
	void selectionChanged(const QVector<QModelIndex> &indexes, bool select);
 | 
						void selectionChanged(const QVector<QModelIndex> &indexes, bool select);
 | 
				
			||||||
	void newCurrentDive(QModelIndex index);
 | 
						void newCurrentDive(QModelIndex index);
 | 
				
			||||||
protected slots:
 | 
					protected slots:
 | 
				
			||||||
	void divesSelected(dive_trip *trip, const QVector<dive *> &dives);
 | 
						void divesSelected(const QVector<dive *> &dives);
 | 
				
			||||||
	void divesDeselected(dive_trip *trip, const QVector<dive *> &dives);
 | 
						void divesDeselected(const QVector<dive *> &dives);
 | 
				
			||||||
protected:
 | 
					protected:
 | 
				
			||||||
	// Access trip and dive data
 | 
						// Access trip and dive data
 | 
				
			||||||
	static QVariant diveData(const struct dive *d, int column, int role);
 | 
						static QVariant diveData(const struct dive *d, int column, int role);
 | 
				
			||||||
	static QVariant tripData(const dive_trip *trip, int column, int role);
 | 
						static QVariant tripData(const dive_trip *trip, int column, int role);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Select or deselect dives
 | 
						// Select or deselect dives
 | 
				
			||||||
	virtual void changeDiveSelection(dive_trip *trip, const QVector<dive *> &dives, bool select) = 0;
 | 
						virtual void changeDiveSelection(const QVector<dive *> &dives, bool select) = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	virtual dive *diveOrNull(const QModelIndex &index) const = 0;	// Returns a dive if this index represents a dive, null otherwise
 | 
						virtual dive *diveOrNull(const QModelIndex &index) const = 0;	// Returns a dive if this index represents a dive, null otherwise
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
| 
						 | 
					@ -111,9 +111,9 @@ class DiveTripModelTree : public DiveTripModelBase
 | 
				
			||||||
public slots:
 | 
					public slots:
 | 
				
			||||||
	void divesAdded(dive_trip *trip, bool addTrip, const QVector<dive *> &dives);
 | 
						void divesAdded(dive_trip *trip, bool addTrip, const QVector<dive *> &dives);
 | 
				
			||||||
	void divesDeleted(dive_trip *trip, bool deleteTrip, const QVector<dive *> &dives);
 | 
						void divesDeleted(dive_trip *trip, bool deleteTrip, const QVector<dive *> &dives);
 | 
				
			||||||
	void divesChanged(dive_trip *trip, const QVector<dive *> &dives);
 | 
					 | 
				
			||||||
	void divesTimeChanged(dive_trip *trip, timestamp_t delta, const QVector<dive *> &dives);
 | 
					 | 
				
			||||||
	void divesMovedBetweenTrips(dive_trip *from, dive_trip *to, bool deleteFrom, bool createTo, const QVector<dive *> &dives);
 | 
						void divesMovedBetweenTrips(dive_trip *from, dive_trip *to, bool deleteFrom, bool createTo, const QVector<dive *> &dives);
 | 
				
			||||||
 | 
						void divesChanged(const QVector<dive *> &dives);
 | 
				
			||||||
 | 
						void divesTimeChanged(timestamp_t delta, const QVector<dive *> &dives);
 | 
				
			||||||
	void currentDiveChanged();
 | 
						void currentDiveChanged();
 | 
				
			||||||
	void tripChanged(dive_trip *trip, TripField);
 | 
						void tripChanged(dive_trip *trip, TripField);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -126,9 +126,12 @@ private:
 | 
				
			||||||
	QVariant data(const QModelIndex &index, int role) const override;
 | 
						QVariant data(const QModelIndex &index, int role) const override;
 | 
				
			||||||
	void filterFinished() override;
 | 
						void filterFinished() override;
 | 
				
			||||||
	bool lessThan(const QModelIndex &i1, const QModelIndex &i2) const override;
 | 
						bool lessThan(const QModelIndex &i1, const QModelIndex &i2) const override;
 | 
				
			||||||
	void changeDiveSelection(dive_trip *trip, const QVector<dive *> &dives, bool select) override;
 | 
						void changeDiveSelection(const QVector<dive *> &dives, bool select) override;
 | 
				
			||||||
 | 
						void changeDiveSelectionTrip(dive_trip *trip, const QVector<dive *> &dives, bool select);
 | 
				
			||||||
	dive *diveOrNull(const QModelIndex &index) const override;
 | 
						dive *diveOrNull(const QModelIndex &index) const override;
 | 
				
			||||||
	bool setShown(const QModelIndex &idx, bool shown);
 | 
						bool setShown(const QModelIndex &idx, bool shown);
 | 
				
			||||||
 | 
						void divesChangedTrip(dive_trip *trip, const QVector<dive *> &dives);
 | 
				
			||||||
 | 
						void divesTimeChangedTrip(dive_trip *trip, timestamp_t delta, const QVector<dive *> &dives);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// The tree model has two levels. At the top level, we have either trips or dives
 | 
						// The tree model has two levels. At the top level, we have either trips or dives
 | 
				
			||||||
	// that do not belong to trips. Such a top-level item is represented by the "Item"
 | 
						// that do not belong to trips. Such a top-level item is represented by the "Item"
 | 
				
			||||||
| 
						 | 
					@ -174,8 +177,8 @@ class DiveTripModelList : public DiveTripModelBase
 | 
				
			||||||
public slots:
 | 
					public slots:
 | 
				
			||||||
	void divesAdded(dive_trip *trip, bool addTrip, const QVector<dive *> &dives);
 | 
						void divesAdded(dive_trip *trip, bool addTrip, const QVector<dive *> &dives);
 | 
				
			||||||
	void divesDeleted(dive_trip *trip, bool deleteTrip, const QVector<dive *> &dives);
 | 
						void divesDeleted(dive_trip *trip, bool deleteTrip, const QVector<dive *> &dives);
 | 
				
			||||||
	void divesChanged(dive_trip *trip, const QVector<dive *> &dives);
 | 
						void divesChanged(const QVector<dive *> &dives);
 | 
				
			||||||
	void divesTimeChanged(dive_trip *trip, timestamp_t delta, const QVector<dive *> &dives);
 | 
						void divesTimeChanged(timestamp_t delta, const QVector<dive *> &dives);
 | 
				
			||||||
	// Does nothing in list view.
 | 
						// Does nothing in list view.
 | 
				
			||||||
	//void divesMovedBetweenTrips(dive_trip *from, dive_trip *to, bool deleteFrom, bool createTo, const QVector<dive *> &dives);
 | 
						//void divesMovedBetweenTrips(dive_trip *from, dive_trip *to, bool deleteFrom, bool createTo, const QVector<dive *> &dives);
 | 
				
			||||||
	void currentDiveChanged();
 | 
						void currentDiveChanged();
 | 
				
			||||||
| 
						 | 
					@ -189,7 +192,7 @@ private:
 | 
				
			||||||
	QVariant data(const QModelIndex &index, int role) const override;
 | 
						QVariant data(const QModelIndex &index, int role) const override;
 | 
				
			||||||
	void filterFinished() override;
 | 
						void filterFinished() override;
 | 
				
			||||||
	bool lessThan(const QModelIndex &i1, const QModelIndex &i2) const override;
 | 
						bool lessThan(const QModelIndex &i1, const QModelIndex &i2) const override;
 | 
				
			||||||
	void changeDiveSelection(dive_trip *trip, const QVector<dive *> &dives, bool select) override;
 | 
						void changeDiveSelection(const QVector<dive *> &dives, bool select) override;
 | 
				
			||||||
	dive *diveOrNull(const QModelIndex &index) const override;
 | 
						dive *diveOrNull(const QModelIndex &index) const override;
 | 
				
			||||||
	bool setShown(const QModelIndex &idx, bool shown);
 | 
						bool setShown(const QModelIndex &idx, bool shown);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,7 +6,6 @@
 | 
				
			||||||
#include "core/qthelper.h"
 | 
					#include "core/qthelper.h"
 | 
				
			||||||
#include "core/subsurface-qt/DiveListNotifier.h"
 | 
					#include "core/subsurface-qt/DiveListNotifier.h"
 | 
				
			||||||
#include "qt-models/weightsysteminfomodel.h"
 | 
					#include "qt-models/weightsysteminfomodel.h"
 | 
				
			||||||
#include "core/trip.h" // TODO: Needed because weightsystemsReset uses a trip parameter -> remove that!
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
WeightModel::WeightModel(QObject *parent) : CleanerTableModel(parent),
 | 
					WeightModel::WeightModel(QObject *parent) : CleanerTableModel(parent),
 | 
				
			||||||
	changed(false),
 | 
						changed(false),
 | 
				
			||||||
| 
						 | 
					@ -168,7 +167,7 @@ void WeightModel::updateDive()
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void WeightModel::weightsystemsReset(dive_trip *trip, const QVector<dive *> &dives)
 | 
					void WeightModel::weightsystemsReset(const QVector<dive *> &dives)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	// This model only concerns the currently displayed dive. If this is not among the
 | 
						// This model only concerns the currently displayed dive. If this is not among the
 | 
				
			||||||
	// dives that had their cylinders reset, exit.
 | 
						// dives that had their cylinders reset, exit.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -32,7 +32,7 @@ public:
 | 
				
			||||||
public
 | 
					public
 | 
				
			||||||
slots:
 | 
					slots:
 | 
				
			||||||
	void remove(const QModelIndex &index);
 | 
						void remove(const QModelIndex &index);
 | 
				
			||||||
	void weightsystemsReset(dive_trip *trip, const QVector<dive *> &dives);
 | 
						void weightsystemsReset(const QVector<dive *> &dives);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
	int rows;
 | 
						int rows;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue