From fd5c67bbf9f1eaa6ebb06bfa6f5c0139095de2a2 Mon Sep 17 00:00:00 2001
From: Oliver Bock <oliver.bock@aei.mpg.de>
Date: Fri, 30 Jan 2009 17:33:22 +0100
Subject: [PATCH] Completed preliminary scope implementation

* Fixed item handling (store them on heap)
* Removed scope axes
* Vertical size now determined by marker/pulse (normalized to 1)
* Removed dummy data
* FIXME: marker not visible despite higher z-layer
---
 src/pulsescopewidget.cpp | 50 ++++++++++++++++++----------------------
 src/pulsescopewidget.h   |  5 +++-
 2 files changed, 26 insertions(+), 29 deletions(-)

diff --git a/src/pulsescopewidget.cpp b/src/pulsescopewidget.cpp
index 2e7724c..028089f 100644
--- a/src/pulsescopewidget.cpp
+++ b/src/pulsescopewidget.cpp
@@ -22,8 +22,7 @@
 
 PulseScopeWidget::PulseScopeWidget(QWidget *parent) : QGraphicsView(parent),
 	m_scene(),
-	m_data(),
-	m_marker()
+	m_data()
 {
 	setViewport(new QGLWidget(QGLFormat(QGL::AlphaChannel | QGL::SampleBuffers)));
 	QGLWidget *glScope = (QGLWidget*) viewport();
@@ -44,17 +43,16 @@ PulseScopeWidget::PulseScopeWidget(QWidget *parent) : QGraphicsView(parent),
 	}
 
 	m_scopeSizeH = 360;
-	m_scopeSizeV = 0;
+	m_scopeSizeV = 1;
 
 	setScene(&m_scene);
-	m_data.fill(0.0f, m_scopeSizeH);
-	m_marker.setPen(QPen(Qt::red));
 
-	// TODO: proof of concept only!
-	for(int i = 0; i < m_scopeSizeH; ++i) {
-		m_data[i] = pow(i-180,2);
-	}
+	m_path = NULL;
+	m_marker = new QGraphicsLineItem();
+	m_marker->setPen(QPen(Qt::red));
+	m_marker->setZValue(1);
 
+	m_data.fill(0.0f, m_scopeSizeH);
 	drawCurve(m_data);
 }
 
@@ -74,34 +72,30 @@ void PulseScopeWidget::drawCurve(const QVector<float>& vector)
 {
 	m_data = vector;
 
-	// TODO: proof of concept only!
-
-	QVector<float> checkMax(m_data);
-	qSort(checkMax.begin(), checkMax.end());
-	m_scopeSizeV = (int)ceil(checkMax.last()) * 2;
-
-	m_scene.addLine(0.0f, 0.0f, 0.0f, m_scopeSizeV, QPen(Qt::white));
-	m_scene.addLine(0.0f, m_scopeSizeV / 2, m_scopeSizeH, m_scopeSizeV / 2, QPen(Qt::white));
+	if(m_marker->scene() == 0) {
+		m_marker->setLine(0.0, 0.0, 0.0, m_scopeSizeV);
+		m_scene.addItem(m_marker);
+	}
 
-	QPainterPath pulsePath(QPoint(0.0f, m_scopeSizeV / 2));
+	QPainterPath pulsePath(QPoint(0.0f, 1.0f));
 	for(int i = 0; i < m_scopeSizeH; ++i) {
-		pulsePath.lineTo(i,m_data[i]);
+		pulsePath.lineTo(i, 1-m_data[i]);
 	}
-	m_scene.addPath(pulsePath, QPen(Qt::yellow));
-
-	if(m_marker.scene() == 0) {
-		m_marker.setLine(0.0, 0.0, 0.0, m_scopeSizeV);
-		m_scene.addItem(&m_marker);
+	if(m_path == NULL) {
+		m_path = m_scene.addPath(pulsePath, QPen(Qt::yellow));
+	}
+	else {
+		m_path->setPath(pulsePath);
 	}
 
 	fitInView(m_scene.itemsBoundingRect(), Qt::IgnoreAspectRatio);
 }
 
 void PulseScopeWidget::markerStep(float stepSize) {
-	if(m_marker.line().x1() < m_scopeSizeH) {
-		QLineF line = m_marker.line();
+	if(m_marker->line().x1() < m_scopeSizeH) {
+		QLineF line = m_marker->line();
 		line.translate(stepSize, 0);
-		m_marker.setLine(line);
+		m_marker->setLine(line);
 	}
 	else {
 		markerReset();
@@ -109,5 +103,5 @@ void PulseScopeWidget::markerStep(float stepSize) {
 }
 
 void PulseScopeWidget::markerReset() {
-	m_marker.setLine(0.0, 0.0, 0.0, m_scopeSizeV);
+	m_marker->setLine(0.0, 0.0, 0.0, m_scopeSizeV);
 }
diff --git a/src/pulsescopewidget.h b/src/pulsescopewidget.h
index b5f547b..3243e26 100644
--- a/src/pulsescopewidget.h
+++ b/src/pulsescopewidget.h
@@ -26,6 +26,7 @@
 #include <QGraphicsView>
 #include <QGraphicsScene>
 #include <QGLContext>
+#include <QGraphicsPathItem>
 #include <QGraphicsLineItem>
 
 
@@ -47,7 +48,9 @@ public slots:
 private:
 	QGraphicsScene m_scene;
 	QVector<float> m_data;
-	QGraphicsLineItem m_marker;
+	QGraphicsPathItem *m_path;
+	QGraphicsLineItem *m_marker;
+
 
 	int m_scopeSizeH;
 	int m_scopeSizeV;
-- 
GitLab