Commit ed51f0e7 authored by Oliver Bock's avatar Oliver Bock

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