From ed51f0e798fbb4558ec7af09deaa148ccb6cc1fc Mon Sep 17 00:00:00 2001
From: Oliver Bock <oliver.bock@aei.mpg.de>
Date: Fri, 30 Jan 2009 19:47:25 +0100
Subject: [PATCH] Fixed and improved marker handling

* Marker was invisible due to erratic pulse profile values (remove workaround when fixed!)
* Improved updates of profile and marker items
---
 src/pulsescopewidget.cpp | 31 ++++++++++++++++---------------
 src/pulsescopewidget.h   |  3 +--
 2 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/src/pulsescopewidget.cpp b/src/pulsescopewidget.cpp
index 028089f..836bb82 100644
--- a/src/pulsescopewidget.cpp
+++ b/src/pulsescopewidget.cpp
@@ -45,20 +45,19 @@ PulseScopeWidget::PulseScopeWidget(QWidget *parent) : QGraphicsView(parent),
 	m_scopeSizeH = 360;
 	m_scopeSizeV = 1;
 
-	setScene(&m_scene);
-
 	m_path = NULL;
-	m_marker = new QGraphicsLineItem();
-	m_marker->setPen(QPen(Qt::red));
+	m_marker = m_scene.addLine(0.0f, 0.0f, 0.0f, m_scopeSizeV, QPen(Qt::red));
 	m_marker->setZValue(1);
 
+	setScene(&m_scene);
+
 	m_data.fill(0.0f, m_scopeSizeH);
 	drawCurve(m_data);
 }
 
 PulseScopeWidget::~PulseScopeWidget()
 {
-
+	m_scene.clear();
 }
 
 void PulseScopeWidget::resizeEvent(QResizeEvent *event)
@@ -72,14 +71,14 @@ void PulseScopeWidget::drawCurve(const QVector<float>& vector)
 {
 	m_data = vector;
 
-	if(m_marker->scene() == 0) {
-		m_marker->setLine(0.0, 0.0, 0.0, m_scopeSizeV);
-		m_scene.addItem(m_marker);
-	}
+	// FIXME: to be removed later because amplitude should be normalized to 1!
+	QVector<float> test(vector);
+	qSort(test.begin(), test.end());
+	if(test.last() > 1) m_scopeSizeV = 1-test.last();
 
 	QPainterPath pulsePath(QPoint(0.0f, 1.0f));
 	for(int i = 0; i < m_scopeSizeH; ++i) {
-		pulsePath.lineTo(i, 1-m_data[i]);
+		pulsePath.lineTo(i, 1-m_data.at(i));
 	}
 	if(m_path == NULL) {
 		m_path = m_scene.addPath(pulsePath, QPen(Qt::yellow));
@@ -92,16 +91,18 @@ void PulseScopeWidget::drawCurve(const QVector<float>& vector)
 }
 
 void PulseScopeWidget::markerStep(float stepSize) {
-	if(m_marker->line().x1() < m_scopeSizeH) {
-		QLineF line = m_marker->line();
-		line.translate(stepSize, 0);
-		m_marker->setLine(line);
+	static float x = 0.0f;
+
+	if(x < m_scopeSizeH) {
+		x += stepSize;
+		m_marker->setLine(x, 0.0f, x, m_scopeSizeV);
 	}
 	else {
+		x = 0.0f;
 		markerReset();
 	}
 }
 
 void PulseScopeWidget::markerReset() {
-	m_marker->setLine(0.0, 0.0, 0.0, m_scopeSizeV);
+	m_marker->setLine(0.0f, 0.0f, 0.0f, m_scopeSizeV);
 }
diff --git a/src/pulsescopewidget.h b/src/pulsescopewidget.h
index 3243e26..9a3bb43 100644
--- a/src/pulsescopewidget.h
+++ b/src/pulsescopewidget.h
@@ -51,9 +51,8 @@ private:
 	QGraphicsPathItem *m_path;
 	QGraphicsLineItem *m_marker;
 
-
 	int m_scopeSizeH;
-	int m_scopeSizeV;
+	float m_scopeSizeV;
 };
 
 #endif /* PULSESCOPEWIDGET_H_ */
-- 
GitLab