mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	Filter: move calculation of shown dives to undo command
The filter-model was catching dives-added / dives-deleted signals from the models to keep track of the number of shown dives. To simplify the data flow, do this directly in the undo-command. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
		
							parent
							
								
									2d09819ddf
								
							
						
					
					
						commit
						6d6d10f03a
					
				
					 5 changed files with 23 additions and 23 deletions
				
			
		|  | @ -40,6 +40,9 @@ DiveToAdd DiveListBase::removeDive(struct dive *d, std::vector<OwningTripPtr> &t | |||
| 	if (idx < 0) | ||||
| 		qWarning("Deletion of unknown dive!"); | ||||
| 
 | ||||
| 	if (!d->hidden_by_filter) | ||||
| 		--shown_dives; | ||||
| 
 | ||||
| 	res.dive.reset(unregister_dive(idx));		// Remove dive from backend
 | ||||
| 
 | ||||
| 	return res; | ||||
|  | @ -67,6 +70,8 @@ dive *DiveListBase::addDive(DiveToAdd &d) | |||
| 	// Set the filter flag according to current filter settings
 | ||||
| 	bool show = MultiFilterSortModel::instance()->showDive(res); | ||||
| 	res->hidden_by_filter = !show; | ||||
| 	if (show) | ||||
| 		++shown_dives; | ||||
| 
 | ||||
| 	int idx = dive_table_get_insertion_index(&dive_table, res); | ||||
| 	add_to_dive_table(&dive_table, idx, res);	// Return ownership to backend
 | ||||
|  | @ -118,6 +123,9 @@ DivesAndTripsToAdd DiveListBase::removeDives(DivesAndSitesToRemove &divesAndSite | |||
| 	divesToAdd.reserve(divesAndSitesToDelete.dives.size()); | ||||
| 	sitesToAdd.reserve(divesAndSitesToDelete.sites.size()); | ||||
| 
 | ||||
| 	// Remember old number of shown dives
 | ||||
| 	int oldShown = shown_dives; | ||||
| 
 | ||||
| 	// 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
 | ||||
| 	// in the core list.
 | ||||
|  | @ -149,6 +157,10 @@ DivesAndTripsToAdd DiveListBase::removeDives(DivesAndSitesToRemove &divesAndSite | |||
| 					       { return ptr.get() == trip; }) != tripsToAdd.end(); | ||||
| 		emit diveListNotifier.divesDeleted(trip, deleteTrip, divesInTrip); | ||||
| 	}); | ||||
| 
 | ||||
| 	if (oldShown != shown_dives) | ||||
| 		emit diveListNotifier.numShownChanged(); | ||||
| 
 | ||||
| 	return { std::move(divesToAdd), std::move(tripsToAdd), std::move(sitesToAdd) }; | ||||
| } | ||||
| 
 | ||||
|  | @ -172,6 +184,9 @@ DivesAndSitesToRemove DiveListBase::addDives(DivesAndTripsToAdd &toAdd) | |||
| 		  [](const DiveToAdd &d, const DiveToAdd &d2) | ||||
| 		  { return dive_less_than(d.dive.get(), d2.dive.get()); }); | ||||
| 
 | ||||
| 	// Remember old number of shown dives
 | ||||
| 	int oldShown = shown_dives; | ||||
| 
 | ||||
| 	// Now, add the dives
 | ||||
| 	// Note: the idiomatic STL-way would be std::transform, but let's use a loop since
 | ||||
| 	// that is closer to classical C-style.
 | ||||
|  | @ -207,6 +222,10 @@ DivesAndSitesToRemove DiveListBase::addDives(DivesAndTripsToAdd &toAdd) | |||
| 		// Finally, emit the signal
 | ||||
| 		emit diveListNotifier.divesAdded(trip, createTrip, divesInTrip); | ||||
| 	}); | ||||
| 
 | ||||
| 	if (oldShown != shown_dives) | ||||
| 		emit diveListNotifier.numShownChanged(); | ||||
| 
 | ||||
| 	return { res, sites }; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue