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