diff --git a/src/pulsescopewidget.cpp b/src/pulsescopewidget.cpp index 2e7724c8badd7285458421ec640eff7e8325a2a6..028089f013da5f7ae3fb9aca8abdd52b710e247e 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 b5f547bfb76aa76132f4db5c135fe5fac21e8462..3243e26081b3f7adb5434d95e1370161603c8823 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;