mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	Fix renumbering of dives
The implementation in commit 182fe790c9 ("Add ability to undo
renumbering of dives") looks perfectly reasonable, but it depends on an
implementation detail: it assumes that the keys of the QMap are returned
in the same order in which they were placed there. Which apparently isn't
the case for some version of Qt.
With this commit we simply remember both the old and the new number for
each dive and therefore the order in which they are processed doesn't
matter.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
			
			
This commit is contained in:
		
							parent
							
								
									a524c01c3f
								
							
						
					
					
						commit
						8d05c71ca2
					
				
					 3 changed files with 12 additions and 12 deletions
				
			
		| 
						 | 
				
			
			@ -63,20 +63,20 @@ void UndoShiftTime::redo()
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
UndoRenumberDives::UndoRenumberDives(QMap<int, int> originalNumbers, int startNumber)
 | 
			
		||||
UndoRenumberDives::UndoRenumberDives(QMap<int, QPair<int, int> > originalNumbers)
 | 
			
		||||
{
 | 
			
		||||
	oldNumbers = originalNumbers;
 | 
			
		||||
	start = startNumber;
 | 
			
		||||
	setText("renumber dive");
 | 
			
		||||
	if (oldNumbers.count() > 1)
 | 
			
		||||
		setText(QString("renumber %1 dives").arg(QString::number(oldNumbers.count())));
 | 
			
		||||
	else
 | 
			
		||||
		setText("renumber dive");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void UndoRenumberDives::undo()
 | 
			
		||||
{
 | 
			
		||||
	foreach (int key, oldNumbers.keys()) {
 | 
			
		||||
		struct dive* d = get_dive_by_uniq_id(key);
 | 
			
		||||
		d->number = oldNumbers.value(key);
 | 
			
		||||
		d->number = oldNumbers.value(key).first;
 | 
			
		||||
	}
 | 
			
		||||
	mark_divelist_changed(true);
 | 
			
		||||
	MainWindow::instance()->refreshDisplay();
 | 
			
		||||
| 
						 | 
				
			
			@ -84,10 +84,9 @@ void UndoRenumberDives::undo()
 | 
			
		|||
 | 
			
		||||
void UndoRenumberDives::redo()
 | 
			
		||||
{
 | 
			
		||||
	int i = start;
 | 
			
		||||
	foreach (int key, oldNumbers.keys()) {
 | 
			
		||||
		struct dive* d = get_dive_by_uniq_id(key);
 | 
			
		||||
		d->number = i++;
 | 
			
		||||
		d->number = oldNumbers.value(key).second;
 | 
			
		||||
	}
 | 
			
		||||
	mark_divelist_changed(true);
 | 
			
		||||
	MainWindow::instance()->refreshDisplay();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue