mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	profile: move checking for DiveTextItem into its own function
When creating the context menu, a special menu is created for the dive computer name. This was checked in a loop, that set a flag and exited early. This can all be simplified by moving the loop into its own function. No more flag, less indentation. Overall better. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
		
							parent
							
								
									78f4d7b2b9
								
							
						
					
					
						commit
						c34f0b88a2
					
				
					 1 changed files with 23 additions and 23 deletions
				
			
		| 
						 | 
				
			
			@ -1342,6 +1342,16 @@ static QString printCylinderDescription(int i, const cylinder_t *cylinder)
 | 
			
		|||
	return label;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static bool isDiveTextItem(const QGraphicsItem *item, const DiveTextItem *textItem)
 | 
			
		||||
{
 | 
			
		||||
	while (item) {
 | 
			
		||||
		if (item == textItem)
 | 
			
		||||
			return true;
 | 
			
		||||
		item = item->parentItem();
 | 
			
		||||
	}
 | 
			
		||||
	return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event)
 | 
			
		||||
{
 | 
			
		||||
	if (currentState == ADD || currentState == PLAN) {
 | 
			
		||||
| 
						 | 
				
			
			@ -1349,21 +1359,11 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event)
 | 
			
		|||
		return;
 | 
			
		||||
	}
 | 
			
		||||
	QMenu m;
 | 
			
		||||
	bool isDCName = false;
 | 
			
		||||
	if (!d)
 | 
			
		||||
		return;
 | 
			
		||||
	// figure out if we are ontop of the dive computer name in the profile
 | 
			
		||||
	QGraphicsItem *sceneItem = itemAt(mapFromGlobal(event->globalPos()));
 | 
			
		||||
	if (sceneItem) {
 | 
			
		||||
		QGraphicsItem *parentItem = sceneItem;
 | 
			
		||||
		while (parentItem) {
 | 
			
		||||
			if (parentItem == diveComputerText) {
 | 
			
		||||
				isDCName = true;
 | 
			
		||||
				break;
 | 
			
		||||
			}
 | 
			
		||||
			parentItem = parentItem->parentItem();
 | 
			
		||||
		}
 | 
			
		||||
		if (isDCName) {
 | 
			
		||||
	if (isDiveTextItem(sceneItem, diveComputerText)) {
 | 
			
		||||
		if (dc == 0 && number_of_computers(d) == 1)
 | 
			
		||||
			// nothing to do, can't delete or reorder
 | 
			
		||||
			return;
 | 
			
		||||
| 
						 | 
				
			
			@ -1378,7 +1378,7 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event)
 | 
			
		|||
		// don't show the regular profile context menu
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// create the profile context menu
 | 
			
		||||
	QPointF scenePos = mapToScene(mapFromGlobal(event->globalPos()));
 | 
			
		||||
	qreal sec_val = timeAxis->valueAt(scenePos);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue