mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	Remove only the Uneeded Ticks / Labels when a update is requested.
This patch makes the updateTicks method not remove / readd everything when it's triggered, but to only remove the ticks / labels that are no longer needed on the current display. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
		
							parent
							
								
									49f4052c67
								
							
						
					
					
						commit
						ca979044d0
					
				
					 1 changed files with 8 additions and 38 deletions
				
			
		| 
						 | 
				
			
			@ -44,48 +44,18 @@ void DiveCartesianAxis::setOrientation(Qt::Orientation o)
 | 
			
		|||
 | 
			
		||||
void DiveCartesianAxis::updateTicks()
 | 
			
		||||
{
 | 
			
		||||
	qDeleteAll(ticks);
 | 
			
		||||
	ticks.clear();
 | 
			
		||||
	qDeleteAll(labels);
 | 
			
		||||
	labels.clear();
 | 
			
		||||
 | 
			
		||||
	QLineF m = line();
 | 
			
		||||
	DiveLineItem *item = NULL;
 | 
			
		||||
	DiveTextItem *label = NULL;
 | 
			
		||||
 | 
			
		||||
	QGraphicsView *view = scene()->views().first();
 | 
			
		||||
	double steps = (max - min) / interval;
 | 
			
		||||
	qreal pos;
 | 
			
		||||
	double currValue = min;
 | 
			
		||||
 | 
			
		||||
	if (orientation == Qt::Horizontal) {
 | 
			
		||||
		double stepSize = (m.x2() - m.x1()) / steps;
 | 
			
		||||
		for (pos = m.x1(); pos <= m.x2(); pos += stepSize, currValue += interval) {
 | 
			
		||||
			item = new DiveLineItem(this);
 | 
			
		||||
			item->setLine(pos, m.y1(), pos, m.y1() + tickSize);
 | 
			
		||||
			item->setPen(pen());
 | 
			
		||||
			ticks.push_back(item);
 | 
			
		||||
 | 
			
		||||
			label = new DiveTextItem(this);
 | 
			
		||||
			label->setText(QString::number(currValue));
 | 
			
		||||
			label->setBrush(QBrush(textColor));
 | 
			
		||||
			label->setFlag(ItemIgnoresTransformations);
 | 
			
		||||
			label->setPos(pos - label->boundingRect().width()/2, m.y1() + tickSize + 5);
 | 
			
		||||
			labels.push_back(label);
 | 
			
		||||
		}
 | 
			
		||||
	} else {
 | 
			
		||||
		double stepSize = (m.y2() - m.y1()) / steps;
 | 
			
		||||
		for (pos = m.y1(); pos <= m.y2(); pos += stepSize, currValue += interval) {
 | 
			
		||||
			item = new DiveLineItem(this);
 | 
			
		||||
			item->setLine(m.x1(), pos, m.x1() - tickSize, pos);
 | 
			
		||||
			item->setPen(pen());
 | 
			
		||||
			ticks.push_back(item);
 | 
			
		||||
 | 
			
		||||
			label = new DiveTextItem(this);
 | 
			
		||||
			label->setText(get_depth_string(currValue, false, false));
 | 
			
		||||
			label->setBrush(QBrush(textColor));
 | 
			
		||||
			label->setFlag(ItemIgnoresTransformations);
 | 
			
		||||
			label->setPos(m.x2() - 80, pos);
 | 
			
		||||
			labels.push_back(label);
 | 
			
		||||
	// Remove the uneeded Ticks / Texts.
 | 
			
		||||
	if (ticks.size() > steps){
 | 
			
		||||
		while (ticks.size() > steps){
 | 
			
		||||
			DiveLineItem *removedLine = ticks.takeLast();
 | 
			
		||||
			removedLine->animatedHide();
 | 
			
		||||
			DiveTextItem *removedText = labels.takeLast();
 | 
			
		||||
			removedText->animatedHide();
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue