mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	profile: only keep pointer to plot_info in ruler objects
Now this one was strange: The ruler items keep a copy of the plot_info struct. However, only a shallow copy is made (the actual plot data is not copied). This means that the data is only valid as long as the source plot_info is valid. But if that is guaranteed, we simply can keep a pointer instead of the full object. I wonder if it wouldn't be better still to keep a pointer to the profile and query that for the plot info? Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
		
							parent
							
								
									f9b9582a64
								
							
						
					
					
						commit
						ed83f6ce32
					
				
					 2 changed files with 14 additions and 14 deletions
				
			
		|  | @ -8,12 +8,12 @@ | |||
| #include "core/profile.h" | ||||
| 
 | ||||
| RulerNodeItem2::RulerNodeItem2() : | ||||
| 	pInfo(NULL), | ||||
| 	idx(-1), | ||||
| 	ruler(NULL), | ||||
| 	timeAxis(NULL), | ||||
| 	depthAxis(NULL) | ||||
| { | ||||
| 	init_plot_info(&pInfo); | ||||
| 	setRect(-8, -8, 16, 16); | ||||
| 	setBrush(QColor(0xff, 0, 0, 127)); | ||||
| 	setPen(QColor(Qt::red)); | ||||
|  | @ -24,7 +24,7 @@ RulerNodeItem2::RulerNodeItem2() : | |||
| 
 | ||||
| void RulerNodeItem2::setPlotInfo(const plot_info &info) | ||||
| { | ||||
| 	pInfo = info; | ||||
| 	pInfo = &info; | ||||
| 	idx = 0; | ||||
| } | ||||
| 
 | ||||
|  | @ -35,19 +35,19 @@ void RulerNodeItem2::setRuler(RulerItem2 *r) | |||
| 
 | ||||
| void RulerNodeItem2::recalculate() | ||||
| { | ||||
| 	if (pInfo.nr <= 0) | ||||
| 	if (!pInfo || pInfo->nr <= 0) | ||||
| 		return; | ||||
| 
 | ||||
| 	const struct plot_data &last = pInfo.entry[pInfo.nr - 1]; | ||||
| 	const struct plot_data &last = pInfo->entry[pInfo->nr - 1]; | ||||
| 	if (x() < 0) { | ||||
| 		setPos(0, y()); | ||||
| 	} else if (x() > timeAxis->posAtValue(last.sec)) { | ||||
| 		setPos(timeAxis->posAtValue(last.sec), depthAxis->posAtValue(last.depth)); | ||||
| 	} else { | ||||
| 		idx = 0; | ||||
| 		while (idx < pInfo.nr && timeAxis->posAtValue(pInfo.entry[idx].sec) < x()) | ||||
| 		while (idx < pInfo->nr && timeAxis->posAtValue(pInfo->entry[idx].sec) < x()) | ||||
| 			++idx; | ||||
| 		const struct plot_data &data = pInfo.entry[idx]; | ||||
| 		const struct plot_data &data = pInfo->entry[idx]; | ||||
| 		setPos(timeAxis->posAtValue(data.sec), depthAxis->posAtValue(data.depth)); | ||||
| 	} | ||||
| } | ||||
|  | @ -62,14 +62,14 @@ void RulerNodeItem2::mouseMoveEvent(QGraphicsSceneMouseEvent *event) | |||
| 	ruler->recalculate(); | ||||
| } | ||||
| 
 | ||||
| RulerItem2::RulerItem2() : source(new RulerNodeItem2()), | ||||
| RulerItem2::RulerItem2() : pInfo(NULL), | ||||
| 	source(new RulerNodeItem2()), | ||||
| 	dest(new RulerNodeItem2()), | ||||
| 	timeAxis(NULL), | ||||
| 	depthAxis(NULL), | ||||
| 	textItemBack(new QGraphicsRectItem(this)), | ||||
| 	textItem(new QGraphicsSimpleTextItem(this)) | ||||
| { | ||||
| 	memset(&pInfo, 0, sizeof(pInfo)); | ||||
| 	source->setRuler(this); | ||||
| 	dest->setRuler(this); | ||||
| 	textItem->setFlag(QGraphicsItem::ItemIgnoresTransformations); | ||||
|  | @ -98,7 +98,7 @@ void RulerItem2::recalculate() | |||
| 	QFont font; | ||||
| 	QFontMetrics fm(font); | ||||
| 
 | ||||
| 	if (timeAxis == NULL || depthAxis == NULL || pInfo.nr == 0) | ||||
| 	if (timeAxis == NULL || depthAxis == NULL || !pInfo || pInfo->nr == 0) | ||||
| 		return; | ||||
| 
 | ||||
| 	prepareGeometryChange(); | ||||
|  | @ -112,7 +112,7 @@ void RulerItem2::recalculate() | |||
| 	} | ||||
| 	QLineF line(startPoint, endPoint); | ||||
| 	setLine(line); | ||||
| 	compare_samples(dive, &pInfo, source->idx, dest->idx, buffer, 500, 1); | ||||
| 	compare_samples(dive, pInfo, source->idx, dest->idx, buffer, 500, 1); | ||||
| 	text = QString(buffer); | ||||
| 
 | ||||
| 	// draw text
 | ||||
|  | @ -150,7 +150,7 @@ RulerNodeItem2 *RulerItem2::destNode() const | |||
| void RulerItem2::setPlotInfo(const struct dive *d, const plot_info &info) | ||||
| { | ||||
| 	dive = d; | ||||
| 	pInfo = info; | ||||
| 	pInfo = &info; | ||||
| 	dest->setPlotInfo(info); | ||||
| 	source->setPlotInfo(info); | ||||
| 	dest->recalculate(); | ||||
|  |  | |||
|  | @ -6,9 +6,9 @@ | |||
| #include <QGraphicsEllipseItem> | ||||
| #include <QGraphicsObject> | ||||
| #include "profile-widget/divecartesianaxis.h" | ||||
| #include "core/profile.h" | ||||
| 
 | ||||
| struct plot_data; | ||||
| struct plot_info; | ||||
| class RulerItem2; | ||||
| 
 | ||||
| class RulerNodeItem2 : public QObject, public QGraphicsEllipseItem { | ||||
|  | @ -23,7 +23,7 @@ public: | |||
| 
 | ||||
| private: | ||||
| 	void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override; | ||||
| 	struct plot_info pInfo; | ||||
| 	const struct plot_info *pInfo; | ||||
| 	int idx; | ||||
| 	RulerItem2 *ruler; | ||||
| 	DiveCartesianAxis *timeAxis; | ||||
|  | @ -48,7 +48,7 @@ slots: | |||
| 
 | ||||
| private: | ||||
| 	const struct dive *dive; | ||||
| 	struct plot_info pInfo; | ||||
| 	const struct plot_info *pInfo; | ||||
| 	QPointF startPoint, endPoint; | ||||
| 	RulerNodeItem2 *source, *dest; | ||||
| 	QString text; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue