Skip to content

Commit

Permalink
dBgraph: add markers to the intersection of the cursors with the signal
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Guramulta <[email protected]>
  • Loading branch information
DanielGuramulta authored and adisuciu committed Jul 9, 2018
1 parent a31997c commit 94f2dd2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
39 changes: 37 additions & 2 deletions src/dbgraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,19 @@ dBgraph::dBgraph(QWidget *parent) : QwtPlot(parent),
const int fmw = QFontMetrics(scaleWidget->font()).width("XXXX.XX XX");
scaleWidget->setMinBorderDist(fmw / 2, fmw / 2);

markerIntersection1 = new QwtPlotMarker();
markerIntersection2 = new QwtPlotMarker();
QwtSymbol *symbol = new QwtSymbol(
QwtSymbol::Ellipse, QColor(237, 28, 36),
QPen(QColor(255, 255 ,255, 140), 2, Qt::SolidLine),
QSize(18, 18));
symbol->setSize(5, 5);
markerIntersection1->setSymbol(symbol);
markerIntersection2->setSymbol(symbol);
markerIntersection1->setAxes(QwtPlot::xTop, QwtPlot::yLeft);
markerIntersection2->setAxes(QwtPlot::xTop, QwtPlot::yLeft);


}

dBgraph::~dBgraph()
Expand Down Expand Up @@ -197,6 +210,10 @@ void dBgraph::plot(double x, double y)
ydata.push(y);

curve.setRawSamples(xdata.data(), ydata.data(), xdata.size());

onCursor1Moved(d_vBar1->transform(d_vBar1->plotCoord()).x());
onCursor2Moved(d_vBar2->transform(d_vBar2->plotCoord()).x());

replot();
}

Expand Down Expand Up @@ -423,11 +440,20 @@ void dBgraph::onCursor1Moved(int value)
text = formatter->format(point.x(),"Hz",2);

d_cursorReadouts->setTimeCursor1Text(text);
d_cursorReadouts->setVoltageCursor1Text(cursorIntersection(point.x()));
text = cursorIntersection(point.x());
d_cursorReadouts->setVoltageCursor1Text(text);

int d1 = d_cursorReadouts->voltageCursor1Text().split(" ")[0].toInt();
int d2 = d_cursorReadouts->voltageCursor2Text().split(" ")[0].toInt();

if (text == "-") {
markerIntersection1->detach();
} else {
markerIntersection1->attach(this);
markerIntersection1->setValue(point.x(), d1);
replot();
}

d_cursorReadouts->setVoltageDeltaText(QString::number(d2-d1)+" "+
draw_y->getUnitType());
}
Expand All @@ -440,11 +466,20 @@ void dBgraph::onCursor2Moved(int value)
text = formatter->format(point.x(),"Hz",2);

d_cursorReadouts->setTimeCursor2Text(text);
d_cursorReadouts->setVoltageCursor2Text(cursorIntersection(point.x()));
text = cursorIntersection(point.x());
d_cursorReadouts->setVoltageCursor2Text(text);

int d1 = d_cursorReadouts->voltageCursor1Text().split(" ")[0].toInt();
int d2 = d_cursorReadouts->voltageCursor2Text().split(" ")[0].toInt();

if (text == "-") {
markerIntersection2->detach();
} else {
markerIntersection2->attach(this);
markerIntersection2->setValue(point.x(), d2);
replot();
}

d_cursorReadouts->setVoltageDeltaText(QString::number(d2-d1)+" "+
draw_y->getUnitType());
}
Expand Down
3 changes: 3 additions & 0 deletions src/dbgraph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <qwt_plot.h>
#include <qwt_plot_curve.h>
#include <qwt_plot_marker.h>

#include "customFifo.hpp"
#include "symbol_controller.h"
Expand Down Expand Up @@ -129,6 +130,8 @@ namespace adiscope {

private:
QwtPlotCurve curve;
QwtPlotMarker *markerIntersection1;
QwtPlotMarker *markerIntersection2;
unsigned int numSamples;
double xmin, xmax, ymin, ymax;
QColor color;
Expand Down

0 comments on commit 94f2dd2

Please sign in to comment.