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 @@
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);
}
......@@ -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;
......
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