mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	Add helper functions to ensure we have sane tag lists
There should never be empty or duplicate tags on those lists. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
		
							parent
							
								
									634df1a337
								
							
						
					
					
						commit
						a8a8bcd86a
					
				
					 3 changed files with 29 additions and 2 deletions
				
			
		
							
								
								
									
										24
									
								
								dive.c
									
										
									
									
									
								
							
							
						
						
									
										24
									
								
								dive.c
									
										
									
									
									
								
							| 
						 | 
					@ -2089,6 +2089,30 @@ static void join_dive_computers(struct divecomputer *res, struct divecomputer *a
 | 
				
			||||||
	remove_redundant_dc(res, prefer_downloaded);
 | 
						remove_redundant_dc(res, prefer_downloaded);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static bool tag_seen_before(struct tag_entry *start, struct tag_entry *before)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						while(start && start != before) {
 | 
				
			||||||
 | 
							if (same_string(start->tag->name, before->tag->name))
 | 
				
			||||||
 | 
								return true;
 | 
				
			||||||
 | 
							start = start->next;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return false;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* remove duplicates and empty nodes */
 | 
				
			||||||
 | 
					void taglist_cleanup(struct tag_entry **tag_list)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct tag_entry **tl = tag_list;
 | 
				
			||||||
 | 
						while (*tl) {
 | 
				
			||||||
 | 
							/* skip tags that are empty or that we have seen before */
 | 
				
			||||||
 | 
							if (same_string((*tl)->tag->name, "") || tag_seen_before(*tag_list, *tl)) {
 | 
				
			||||||
 | 
								*tl = (*tl)->next;
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							tl = &(*tl)->next;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int taglist_get_tagstring(struct tag_entry *tag_list, char *buffer, int len)
 | 
					int taglist_get_tagstring(struct tag_entry *tag_list, char *buffer, int len)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int i = 0;
 | 
						int i = 0;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										3
									
								
								dive.h
									
										
									
									
									
								
							
							
						
						
									
										3
									
								
								dive.h
									
										
									
									
									
								
							| 
						 | 
					@ -197,6 +197,9 @@ struct divetag *taglist_add_tag(struct tag_entry **tag_list, const char *tag);
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
int taglist_get_tagstring(struct tag_entry *tag_list, char *buffer, int len);
 | 
					int taglist_get_tagstring(struct tag_entry *tag_list, char *buffer, int len);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* cleans up a list: removes empty tags and duplicates */
 | 
				
			||||||
 | 
					void taglist_cleanup(struct tag_entry **tag_list);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void taglist_init_global();
 | 
					void taglist_init_global();
 | 
				
			||||||
void taglist_free(struct tag_entry *tag_list);
 | 
					void taglist_free(struct tag_entry *tag_list);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -934,9 +934,9 @@ void MainTab::on_timeEdit_timeChanged(const QTime &time)
 | 
				
			||||||
void MainTab::saveTags()
 | 
					void MainTab::saveTags()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct dive *cd = current_dive;
 | 
						struct dive *cd = current_dive;
 | 
				
			||||||
	Q_FOREACH(const QString& tag, ui.tagWidget->getBlockStringList()){
 | 
						Q_FOREACH (const QString& tag, ui.tagWidget->getBlockStringList())
 | 
				
			||||||
		taglist_add_tag(&displayed_dive.tag_list, tag.toUtf8().data());
 | 
							taglist_add_tag(&displayed_dive.tag_list, tag.toUtf8().data());
 | 
				
			||||||
	}
 | 
						taglist_cleanup(&displayed_dive.tag_list);
 | 
				
			||||||
	MODIFY_SELECTED_DIVES(
 | 
						MODIFY_SELECTED_DIVES(
 | 
				
			||||||
		QString tag;
 | 
							QString tag;
 | 
				
			||||||
		taglist_free(mydive->tag_list);
 | 
							taglist_free(mydive->tag_list);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue