mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	Core: let count_divecomputers() operate on an arbitrary dive
Currently, count_divecomputers only works on the current_dive. Instead, let it take a pointer to an arbitrary dive. This is in preparation for being smarter in the undo code concerning which dive computer to show on deletion. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
		
							parent
							
								
									ac590235c9
								
							
						
					
					
						commit
						4fe9b39cdb
					
				
					 3 changed files with 6 additions and 7 deletions
				
			
		| 
						 | 
					@ -4189,11 +4189,10 @@ struct dive *make_first_dc(const struct dive *d, int dc_number)
 | 
				
			||||||
	return res;
 | 
						return res;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* always acts on the current dive */
 | 
					int count_divecomputers(const struct dive *d)
 | 
				
			||||||
unsigned int count_divecomputers(void)
 | 
					 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int ret = 1;
 | 
						int ret = 1;
 | 
				
			||||||
	struct divecomputer *dc = current_dive->dc.next;
 | 
						struct divecomputer *dc = d->dc.next;
 | 
				
			||||||
	while (dc) {
 | 
						while (dc) {
 | 
				
			||||||
		ret++;
 | 
							ret++;
 | 
				
			||||||
		dc = dc->next;
 | 
							dc = dc->next;
 | 
				
			||||||
| 
						 | 
					@ -4229,7 +4228,7 @@ static void delete_divecomputer(struct dive *d, int num)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* If this is the currently displayed dive, we might have to adjust
 | 
						/* If this is the currently displayed dive, we might have to adjust
 | 
				
			||||||
	 * the currently displayed dive computer. */
 | 
						 * the currently displayed dive computer. */
 | 
				
			||||||
	if (d == current_dive && dc_number >= count_divecomputers())
 | 
						if (d == current_dive && dc_number >= count_divecomputers(d))
 | 
				
			||||||
		dc_number--;
 | 
							dc_number--;
 | 
				
			||||||
	invalidate_dive_cache(d);
 | 
						invalidate_dive_cache(d);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -435,7 +435,7 @@ extern struct divecomputer *get_dive_dc(struct dive *dive, int nr);
 | 
				
			||||||
extern timestamp_t dive_endtime(const struct dive *dive);
 | 
					extern timestamp_t dive_endtime(const struct dive *dive);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern struct dive *make_first_dc(const struct dive *d, int dc_number);
 | 
					extern struct dive *make_first_dc(const struct dive *d, int dc_number);
 | 
				
			||||||
extern unsigned int count_divecomputers(void);
 | 
					extern int count_divecomputers(const struct dive *d);
 | 
				
			||||||
extern struct dive *clone_delete_divecomputer(const struct dive *d, int dc_number);
 | 
					extern struct dive *clone_delete_divecomputer(const struct dive *d, int dc_number);
 | 
				
			||||||
void split_divecomputer(const struct dive *src, int num, struct dive **out1, struct dive **out2);
 | 
					void split_divecomputer(const struct dive *src, int num, struct dive **out1, struct dive **out2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1430,13 +1430,13 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event)
 | 
				
			||||||
			parentItem = parentItem->parentItem();
 | 
								parentItem = parentItem->parentItem();
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if (isDCName) {
 | 
							if (isDCName) {
 | 
				
			||||||
			if (dc_number == 0 && count_divecomputers() == 1)
 | 
								if (dc_number == 0 && count_divecomputers(current_dive) == 1)
 | 
				
			||||||
				// nothing to do, can't delete or reorder
 | 
									// nothing to do, can't delete or reorder
 | 
				
			||||||
				return;
 | 
									return;
 | 
				
			||||||
			// create menu to show when right clicking on dive computer name
 | 
								// create menu to show when right clicking on dive computer name
 | 
				
			||||||
			if (dc_number > 0)
 | 
								if (dc_number > 0)
 | 
				
			||||||
				m.addAction(tr("Make first dive computer"), this, SLOT(makeFirstDC()));
 | 
									m.addAction(tr("Make first dive computer"), this, SLOT(makeFirstDC()));
 | 
				
			||||||
			if (count_divecomputers() > 1) {
 | 
								if (count_divecomputers(current_dive) > 1) {
 | 
				
			||||||
				m.addAction(tr("Delete this dive computer"), this, SLOT(deleteCurrentDC()));
 | 
									m.addAction(tr("Delete this dive computer"), this, SLOT(deleteCurrentDC()));
 | 
				
			||||||
				m.addAction(tr("Split this dive computer into own dive"), this, SLOT(splitCurrentDC()));
 | 
									m.addAction(tr("Split this dive computer into own dive"), this, SLOT(splitCurrentDC()));
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue