mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	Dive list: move trip selection / deselection logic to divelist.c
This is core logic, not UI code. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
		
							parent
							
								
									032ea24191
								
							
						
					
					
						commit
						dbb86374e0
					
				
					 3 changed files with 24 additions and 17 deletions
				
			
		
							
								
								
									
										18
									
								
								divelist.c
									
										
									
									
									
								
							
							
						
						
									
										18
									
								
								divelist.c
									
										
									
									
									
								
							| 
						 | 
					@ -846,6 +846,24 @@ void deselect_dive(int idx)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void deselect_dives_in_trip(struct dive_trip *trip)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct dive *dive;
 | 
				
			||||||
 | 
						if (!trip)
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						for (dive = trip->dives; dive; dive = dive->next)
 | 
				
			||||||
 | 
							deselect_dive(get_divenr(dive));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void select_dives_in_trip(struct dive_trip *trip)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct dive *dive;
 | 
				
			||||||
 | 
						if (!trip)
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						for (dive = trip->dives; dive; dive = dive->next)
 | 
				
			||||||
 | 
							select_dive(get_divenr(dive));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void mark_divelist_changed(int changed)
 | 
					void mark_divelist_changed(int changed)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	dive_list_changed = changed;
 | 
						dive_list_changed = changed;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -30,6 +30,8 @@ extern struct dive *merge_two_dives(struct dive *a, struct dive *b);
 | 
				
			||||||
extern bool consecutive_selected();
 | 
					extern bool consecutive_selected();
 | 
				
			||||||
extern void select_dive(int idx);
 | 
					extern void select_dive(int idx);
 | 
				
			||||||
extern void deselect_dive(int idx);
 | 
					extern void deselect_dive(int idx);
 | 
				
			||||||
 | 
					extern void select_dives_in_trip(struct dive_trip *trip);
 | 
				
			||||||
 | 
					extern void deselect_dives_in_trip(struct dive_trip *trip);
 | 
				
			||||||
extern void find_new_trip_start_time(dive_trip_t *trip);
 | 
					extern void find_new_trip_start_time(dive_trip_t *trip);
 | 
				
			||||||
extern struct dive *first_selected_dive();
 | 
					extern struct dive *first_selected_dive();
 | 
				
			||||||
extern struct dive *last_selected_dive();
 | 
					extern struct dive *last_selected_dive();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -455,19 +455,11 @@ void DiveListView::selectionChanged(const QItemSelection &selected, const QItemS
 | 
				
			||||||
			continue;
 | 
								continue;
 | 
				
			||||||
		const QAbstractItemModel *model = index.model();
 | 
							const QAbstractItemModel *model = index.model();
 | 
				
			||||||
		struct dive *dive = (struct dive *)model->data(index, DiveTripModel::DIVE_ROLE).value<void *>();
 | 
							struct dive *dive = (struct dive *)model->data(index, DiveTripModel::DIVE_ROLE).value<void *>();
 | 
				
			||||||
		if (!dive) { // it's a trip!
 | 
							if (!dive) // it's a trip!
 | 
				
			||||||
			//TODO: deselect_trip_dives on c-code?
 | 
								deselect_dives_in_trip((dive_trip_t *)model->data(index, DiveTripModel::TRIP_ROLE).value<void *>());
 | 
				
			||||||
			if (model->rowCount(index)) {
 | 
							else
 | 
				
			||||||
				struct dive *child = (struct dive *)model->data(index.child(0, 0), DiveTripModel::DIVE_ROLE).value<void *>();
 | 
					 | 
				
			||||||
				while (child) {
 | 
					 | 
				
			||||||
					deselect_dive(get_divenr(child));
 | 
					 | 
				
			||||||
					child = child->next;
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			deselect_dive(get_divenr(dive));
 | 
								deselect_dive(get_divenr(dive));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	Q_FOREACH (const QModelIndex &index, newSelected.indexes()) {
 | 
						Q_FOREACH (const QModelIndex &index, newSelected.indexes()) {
 | 
				
			||||||
		if (index.column() != 0)
 | 
							if (index.column() != 0)
 | 
				
			||||||
			continue;
 | 
								continue;
 | 
				
			||||||
| 
						 | 
					@ -475,14 +467,9 @@ void DiveListView::selectionChanged(const QItemSelection &selected, const QItemS
 | 
				
			||||||
		const QAbstractItemModel *model = index.model();
 | 
							const QAbstractItemModel *model = index.model();
 | 
				
			||||||
		struct dive *dive = (struct dive *)model->data(index, DiveTripModel::DIVE_ROLE).value<void *>();
 | 
							struct dive *dive = (struct dive *)model->data(index, DiveTripModel::DIVE_ROLE).value<void *>();
 | 
				
			||||||
		if (!dive) { // it's a trip!
 | 
							if (!dive) { // it's a trip!
 | 
				
			||||||
			//TODO: select_trip_dives on C code?
 | 
					 | 
				
			||||||
			if (model->rowCount(index)) {
 | 
								if (model->rowCount(index)) {
 | 
				
			||||||
				QItemSelection selection;
 | 
									QItemSelection selection;
 | 
				
			||||||
				struct dive *child = (struct dive *)model->data(index.child(0, 0), DiveTripModel::DIVE_ROLE).value<void *>();
 | 
									select_dives_in_trip((dive_trip_t *)model->data(index, DiveTripModel::TRIP_ROLE).value<void *>());
 | 
				
			||||||
				while (child) {
 | 
					 | 
				
			||||||
					select_dive(get_divenr(child));
 | 
					 | 
				
			||||||
					child = child->next;
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
				selection.select(index.child(0, 0), index.child(model->rowCount(index) - 1, 0));
 | 
									selection.select(index.child(0, 0), index.child(model->rowCount(index) - 1, 0));
 | 
				
			||||||
				selectionModel()->select(selection, QItemSelectionModel::Select | QItemSelectionModel::Rows);
 | 
									selectionModel()->select(selection, QItemSelectionModel::Select | QItemSelectionModel::Rows);
 | 
				
			||||||
				selectionModel()->setCurrentIndex(index, QItemSelectionModel::Select | QItemSelectionModel::NoUpdate);
 | 
									selectionModel()->setCurrentIndex(index, QItemSelectionModel::Select | QItemSelectionModel::NoUpdate);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue