mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	Fix a crash on changing dives when the ruler is used.
The ruler is a weird beast - it has two child objects that access the parent to call another function, that call the child functions. When I updated the plot_info I didn't take that into consideration, what happened is that when I set the parent's plot_info, the children's plot_info are still invalid, but the update method is called anyhow. This patch updates all plot_info's before calling anything else. Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
		
							parent
							
								
									8034106219
								
							
						
					
					
						commit
						6dec4b0556
					
				
					 3 changed files with 18 additions and 10 deletions
				
			
		|  | @ -365,7 +365,6 @@ void ProfileWidget2::plotDives(QList<dive *> dives) | ||||||
| 		heartBeatAxis->setVisible(false); | 		heartBeatAxis->setVisible(false); | ||||||
| 	} | 	} | ||||||
| 	timeAxis->setMaximum(maxtime); | 	timeAxis->setMaximum(maxtime); | ||||||
| 	rulerItem->setPlotInfo(pInfo); |  | ||||||
| 	int i, incr; | 	int i, incr; | ||||||
| 	static int increments[8] = { 10, 20, 30, 60, 5 * 60, 10 * 60, 15 * 60, 30 * 60 }; | 	static int increments[8] = { 10, 20, 30, 60, 5 * 60, 10 * 60, 15 * 60, 30 * 60 }; | ||||||
| 	/* Time markers: at most every 10 seconds, but no more than 12 markers.
 | 	/* Time markers: at most every 10 seconds, but no more than 12 markers.
 | ||||||
|  | @ -385,6 +384,8 @@ void ProfileWidget2::plotDives(QList<dive *> dives) | ||||||
| 	timeAxis->updateTicks(); | 	timeAxis->updateTicks(); | ||||||
| 	cylinderPressureAxis->setMinimum(pInfo.minpressure); | 	cylinderPressureAxis->setMinimum(pInfo.minpressure); | ||||||
| 	cylinderPressureAxis->setMaximum(pInfo.maxpressure); | 	cylinderPressureAxis->setMaximum(pInfo.maxpressure); | ||||||
|  | 
 | ||||||
|  | 	rulerItem->setPlotInfo(pInfo); | ||||||
| 	meanDepth->setMeanDepth(pInfo.meandepth); | 	meanDepth->setMeanDepth(pInfo.meandepth); | ||||||
| 	meanDepth->setLine(0, 0, timeAxis->posAtValue(d->duration.seconds), 0); | 	meanDepth->setLine(0, 0, timeAxis->posAtValue(d->duration.seconds), 0); | ||||||
| 	meanDepth->animateMoveTo(3, profileYAxis->posAtValue(pInfo.meandepth)); | 	meanDepth->animateMoveTo(3, profileYAxis->posAtValue(pInfo.meandepth)); | ||||||
|  |  | ||||||
|  | @ -13,8 +13,9 @@ | ||||||
| #include "profile.h" | #include "profile.h" | ||||||
| #include "display.h" | #include "display.h" | ||||||
| 
 | 
 | ||||||
| RulerNodeItem2::RulerNodeItem2(struct plot_info &info) : pInfo(info), entry(NULL), ruler(NULL) | RulerNodeItem2::RulerNodeItem2() : entry(NULL), ruler(NULL) | ||||||
| { | { | ||||||
|  | 	memset(&pInfo, 0, sizeof(pInfo)); | ||||||
| 	setRect(QRect(QPoint(-8, 8), QPoint(8, -8))); | 	setRect(QRect(QPoint(-8, 8), QPoint(8, -8))); | ||||||
| 	setBrush(QColor(0xff, 0, 0, 127)); | 	setBrush(QColor(0xff, 0, 0, 127)); | ||||||
| 	setPen(QColor("#FF0000")); | 	setPen(QColor("#FF0000")); | ||||||
|  | @ -23,6 +24,12 @@ RulerNodeItem2::RulerNodeItem2(struct plot_info &info) : pInfo(info), entry(NULL | ||||||
| 	setFlag(ItemIgnoresTransformations); | 	setFlag(ItemIgnoresTransformations); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void RulerNodeItem2::setPlotInfo(plot_info& info) | ||||||
|  | { | ||||||
|  | 	pInfo = info; | ||||||
|  | 	entry = pInfo.entry; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| void RulerNodeItem2::setRuler(RulerItem2 *r) | void RulerNodeItem2::setRuler(RulerItem2 *r) | ||||||
| { | { | ||||||
| 	ruler = r; | 	ruler = r; | ||||||
|  | @ -54,17 +61,14 @@ QVariant RulerNodeItem2::itemChange(GraphicsItemChange change, const QVariant &v | ||||||
| 		recalculate(); | 		recalculate(); | ||||||
| 		if (ruler != NULL) | 		if (ruler != NULL) | ||||||
| 			ruler->recalculate(); | 			ruler->recalculate(); | ||||||
| 		if (scene()) { |  | ||||||
| 			scene()->update(); |  | ||||||
| 		} |  | ||||||
| 	} | 	} | ||||||
| 	return QGraphicsEllipseItem::itemChange(change, value); | 	return QGraphicsEllipseItem::itemChange(change, value); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| RulerItem2::RulerItem2() : timeAxis(NULL), | RulerItem2::RulerItem2() : timeAxis(NULL), | ||||||
| 	depthAxis(NULL), | 	depthAxis(NULL), | ||||||
| 	source(new RulerNodeItem2(pInfo)), | 	source(new RulerNodeItem2()), | ||||||
| 	dest(new RulerNodeItem2(pInfo)), | 	dest(new RulerNodeItem2()), | ||||||
| 	textItem(new QGraphicsSimpleTextItem(this)) | 	textItem(new QGraphicsSimpleTextItem(this)) | ||||||
| { | { | ||||||
| 	memset(&pInfo, 0, sizeof(pInfo)); | 	memset(&pInfo, 0, sizeof(pInfo)); | ||||||
|  | @ -157,9 +161,11 @@ QPainterPath RulerItem2::shape() const | ||||||
| void RulerItem2::setPlotInfo(plot_info info) | void RulerItem2::setPlotInfo(plot_info info) | ||||||
| { | { | ||||||
| 	pInfo = info; | 	pInfo = info; | ||||||
| 	recalculate(); | 	dest->setPlotInfo(info); | ||||||
|  | 	source->setPlotInfo(info); | ||||||
| 	dest->recalculate(); | 	dest->recalculate(); | ||||||
| 	source->recalculate(); | 	source->recalculate(); | ||||||
|  | 	recalculate(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void RulerItem2::setAxis(DiveCartesianAxis *time, DiveCartesianAxis *depth) | void RulerItem2::setAxis(DiveCartesianAxis *time, DiveCartesianAxis *depth) | ||||||
|  |  | ||||||
|  | @ -15,15 +15,16 @@ class RulerNodeItem2 : public QObject, public QGraphicsEllipseItem { | ||||||
| 	friend class RulerItem2; | 	friend class RulerItem2; | ||||||
| 
 | 
 | ||||||
| public: | public: | ||||||
| 	explicit RulerNodeItem2(struct plot_info &info); | 	explicit RulerNodeItem2(); | ||||||
| 	void setRuler(RulerItem2 *r); | 	void setRuler(RulerItem2 *r); | ||||||
|  | 	void setPlotInfo(struct plot_info& info); | ||||||
| 	void recalculate(); | 	void recalculate(); | ||||||
| 
 | 
 | ||||||
| protected: | protected: | ||||||
| 	QVariant itemChange(GraphicsItemChange change, const QVariant &value); | 	QVariant itemChange(GraphicsItemChange change, const QVariant &value); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
| 	struct plot_info &pInfo; | 	struct plot_info pInfo; | ||||||
| 	struct plot_data *entry; | 	struct plot_data *entry; | ||||||
| 	RulerItem2 *ruler; | 	RulerItem2 *ruler; | ||||||
| 	DiveCartesianAxis *timeAxis; | 	DiveCartesianAxis *timeAxis; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue