Commit fd5c67bb authored by Oliver Bock's avatar Oliver Bock

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
parent c5768230
...@@ -22,8 +22,7 @@ ...@@ -22,8 +22,7 @@
PulseScopeWidget::PulseScopeWidget(QWidget *parent) : QGraphicsView(parent), PulseScopeWidget::PulseScopeWidget(QWidget *parent) : QGraphicsView(parent),
m_scene(), m_scene(),
m_data(), m_data()
m_marker()
{ {
setViewport(new QGLWidget(QGLFormat(QGL::AlphaChannel | QGL::SampleBuffers))); setViewport(new QGLWidget(QGLFormat(QGL::AlphaChannel | QGL::SampleBuffers)));
QGLWidget *glScope = (QGLWidget*) viewport(); QGLWidget *glScope = (QGLWidget*) viewport();
...@@ -44,17 +43,16 @@ PulseScopeWidget::PulseScopeWidget(QWidget *parent) : QGraphicsView(parent), ...@@ -44,17 +43,16 @@ PulseScopeWidget::PulseScopeWidget(QWidget *parent) : QGraphicsView(parent),
} }
m_scopeSizeH = 360; m_scopeSizeH = 360;
m_scopeSizeV = 0; m_scopeSizeV = 1;
setScene(&m_scene); setScene(&m_scene);
m_data.fill(0.0f, m_scopeSizeH);
m_marker.setPen(QPen(Qt::red));
// TODO: proof of concept only! m_path = NULL;
for(int i = 0; i < m_scopeSizeH; ++i) { m_marker = new QGraphicsLineItem();
m_data[i] = pow(i-180,2); m_marker->setPen(QPen(Qt::red));
} m_marker->setZValue(1);
m_data.fill(0.0f, m_scopeSizeH);
drawCurve(m_data); drawCurve(m_data);
} }
...@@ -74,34 +72,30 @@ void PulseScopeWidget::drawCurve(const QVector<float>& vector) ...@@ -74,34 +72,30 @@ void PulseScopeWidget::drawCurve(const QVector<float>& vector)
{ {
m_data = vector; m_data = vector;
// TODO: proof of concept only! if(m_marker->scene() == 0) {
m_marker->setLine(0.0, 0.0, 0.0, m_scopeSizeV);
QVector<float> checkMax(m_data); m_scene.addItem(m_marker);
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));
QPainterPath pulsePath(QPoint(0.0f, m_scopeSizeV / 2)); QPainterPath pulsePath(QPoint(0.0f, 1.0f));
for(int i = 0; i < m_scopeSizeH; ++i) { 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_path == NULL) {
m_path = m_scene.addPath(pulsePath, QPen(Qt::yellow));
if(m_marker.scene() == 0) { }
m_marker.setLine(0.0, 0.0, 0.0, m_scopeSizeV); else {
m_scene.addItem(&m_marker); m_path->setPath(pulsePath);
} }
fitInView(m_scene.itemsBoundingRect(), Qt::IgnoreAspectRatio); fitInView(m_scene.itemsBoundingRect(), Qt::IgnoreAspectRatio);
} }
void PulseScopeWidget::markerStep(float stepSize) { void PulseScopeWidget::markerStep(float stepSize) {
if(m_marker.line().x1() < m_scopeSizeH) { if(m_marker->line().x1() < m_scopeSizeH) {
QLineF line = m_marker.line(); QLineF line = m_marker->line();
line.translate(stepSize, 0); line.translate(stepSize, 0);
m_marker.setLine(line); m_marker->setLine(line);
} }
else { else {
markerReset(); markerReset();
...@@ -109,5 +103,5 @@ void PulseScopeWidget::markerStep(float stepSize) { ...@@ -109,5 +103,5 @@ void PulseScopeWidget::markerStep(float stepSize) {
} }
void PulseScopeWidget::markerReset() { 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);
} }
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <QGraphicsView> #include <QGraphicsView>
#include <QGraphicsScene> #include <QGraphicsScene>
#include <QGLContext> #include <QGLContext>
#include <QGraphicsPathItem>
#include <QGraphicsLineItem> #include <QGraphicsLineItem>
...@@ -47,7 +48,9 @@ public slots: ...@@ -47,7 +48,9 @@ public slots:
private: private:
QGraphicsScene m_scene; QGraphicsScene m_scene;
QVector<float> m_data; QVector<float> m_data;
QGraphicsLineItem m_marker; QGraphicsPathItem *m_path;
QGraphicsLineItem *m_marker;
int m_scopeSizeH; int m_scopeSizeH;
int m_scopeSizeV; int m_scopeSizeV;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment