Skip to content

Commit

Permalink
General bug fixes in cursors.
Browse files Browse the repository at this point in the history
Fixed bugs in cursors for spectrum analyzer and oscilloscope instruments.
Added in spectrum analyzer the track cursor functionality.

Signed-off-by: Andreea Grigorovici <[email protected]>
  • Loading branch information
grigorovici-andreea authored and ioanachelaru committed Jun 16, 2021
1 parent 034486a commit 5492b59
Show file tree
Hide file tree
Showing 9 changed files with 317 additions and 77 deletions.
53 changes: 33 additions & 20 deletions src/DisplayPlot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -599,23 +599,7 @@ DisplayPlot::DisplayPlot(int nplots, QWidget* parent, bool isdBgraph,

((QFrame*) canvas())->setLineWidth(0);

// Avoid jumping when labels with more/less digits
// appear/disappear when scrolling vertically

QwtLegend* legendDisplay = new QwtLegend(this);

#if QWT_VERSION < 0x060100
legendDisplay->setItemMode(QwtLegend::CheckableItem);
insertLegend(legendDisplay);
connect(this, SIGNAL(legendChecked(QwtPlotItem *, bool)),
this, SLOT(legendEntryChecked(QwtPlotItem *, bool)));
#else /* QWT_VERSION < 0x060100 */
legendDisplay->setDefaultItemMode(QwtLegendData::Checkable);
insertLegend(legendDisplay);
connect(legendDisplay, SIGNAL(checked(const QVariant&, bool, int)),
this, SLOT(legendEntryChecked(const QVariant&, bool, int)));
#endif /* QWT_VERSION < 0x060100 */

//Set up the grid and the legend for all displayplots, but dBgraph
setupDisplayPlotDiv(isdBgraph);

d_symbolCtrl = new SymbolController(this);
Expand Down Expand Up @@ -655,6 +639,23 @@ DisplayPlot::DisplayPlot(int nplots, QWidget* parent, bool isdBgraph,
void DisplayPlot::setupDisplayPlotDiv(bool isdBgraph) {
if(!isdBgraph)
{

// Avoid jumping when labels with more/less digits
// appear/disappear when scrolling vertically
QwtLegend* legendDisplay = new QwtLegend(this);

#if QWT_VERSION < 0x060100
legendDisplay->setItemMode(QwtLegend::CheckableItem);
insertLegend(legendDisplay);
connect(this, SIGNAL(legendChecked(QwtPlotItem *, bool)),
this, SLOT(legendEntryChecked(QwtPlotItem *, bool)));
#else /* QWT_VERSION < 0x060100 */
legendDisplay->setDefaultItemMode(QwtLegendData::Checkable);
insertLegend(legendDisplay);
connect(legendDisplay, SIGNAL(checked(const QVariant&, bool, int)),
this, SLOT(legendEntryChecked(const QVariant&, bool, int)));
#endif /* QWT_VERSION < 0x060100 */

for (unsigned int i = 0; i < 4; i++) {
QwtScaleDraw::Alignment scale =
static_cast<QwtScaleDraw::Alignment>(i);
Expand Down Expand Up @@ -1029,7 +1030,8 @@ void DisplayPlot::toggleCursors(bool en)
d_vBar2->setVisible(en);

if(d_vertCursorsHandleEnabled)
{ d_hCursorHandle1->setVisible(en);
{
d_hCursorHandle1->setVisible(en);
d_hCursorHandle2->setVisible(en);
}

Expand Down Expand Up @@ -1169,8 +1171,18 @@ void DisplayPlot::displayIntersection()
attachmk2 = false;
}

markerIntersection1->setAxes(QwtPlot::xBottom, QwtAxisId(QwtPlot::yLeft, d_selected_channel));
markerIntersection2->setAxes(QwtPlot::xBottom, QwtAxisId(QwtPlot::yLeft, d_selected_channel));
bool value = isAxisValid(QwtAxisId(QwtPlot::yLeft, d_selected_channel));

if(value)
{
markerIntersection1->setAxes(QwtPlot::xBottom, QwtAxisId(QwtPlot::yLeft, d_selected_channel));
markerIntersection2->setAxes(QwtPlot::xBottom, QwtAxisId(QwtPlot::yLeft, d_selected_channel));
}
else
{
markerIntersection1->setAxes(QwtPlot::xBottom, QwtAxisId(QwtPlot::yLeft, 0));
markerIntersection2->setAxes(QwtPlot::xBottom, QwtAxisId(QwtPlot::yLeft, 0));
}

markerIntersection1->setValue(d_vBar1->plotCoord().x(), intersectionCursor1);
markerIntersection2->setValue(d_vBar2->plotCoord().x(), intersectionCursor2);
Expand Down Expand Up @@ -1810,6 +1822,7 @@ void DisplayPlot::bringCurveToFront(unsigned int curveIdx)
{
DetachCurve(curveIdx);
AttachCurve(curveIdx);
displayIntersection();
replot();
}

Expand Down
112 changes: 73 additions & 39 deletions src/FftDisplayPlot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include <qwt_symbol.h>
#include <boost/make_shared.hpp>

#define ERROR_VALUE -10000000

using namespace adiscope;

class FftDisplayZoomer: public LimitedPlotZoomer
Expand Down Expand Up @@ -162,6 +164,8 @@ FftDisplayPlot::FftDisplayPlot(int nplots, QWidget *parent) :

setYaxisNumDiv(11);

d_selected_channel = 0;

d_topHandlesArea->setMinimumHeight(50);
d_topHandlesArea->setLargestChildWidth(50);

Expand Down Expand Up @@ -232,17 +236,15 @@ QString FftDisplayPlot::formatYValue(double value, int precision) const

void FftDisplayPlot::setupReadouts()
{
d_cursorReadouts = new CursorReadouts(this);
d_cursorReadouts->setTopLeftStartingPoint(QPoint(8, 8));
d_cursorReadouts->setTimeReadoutVisible(false);
d_cursorReadouts->setVoltageReadoutVisible(false);

d_cursorReadouts->setTimeCursor1LabelText("Mag1 = ");
d_cursorReadouts->setTimeCursor2LabelText("Mag2 = ");
d_cursorReadouts->setTimeDeltaLabelText("ΔMag = ");
d_cursorReadouts->setVoltageCursor1LabelText("F1 = ");
d_cursorReadouts->setVoltageCursor2LabelText("F2 = ");
d_cursorReadouts->setDeltaVoltageLabelText("ΔF = ");
d_cursorReadouts->setTimeCursor1LabelText("F1 = ");
d_cursorReadouts->setTimeCursor2LabelText("F2 = ");
d_cursorReadouts->setTimeDeltaLabelText("ΔF = ");
d_cursorReadouts->setVoltageCursor1LabelText("Mag1 = ");
d_cursorReadouts->setVoltageCursor2LabelText("Mag2 = ");
d_cursorReadouts->setDeltaVoltageLabelText("ΔMag = ");

d_cursorReadouts->setFrequencyDeltaVisible(false);
d_cursorReadouts->setTransparency(0);
Expand All @@ -267,72 +269,97 @@ void FftDisplayPlot::updateHandleAreaPadding()
void FftDisplayPlot::onHCursor1Moved(double value)
{
QString text;
bool error = false;
if (d_trackMode) {
if (value == ERROR_VALUE) {
error = true;
}
}

value *= d_displayScale;
text = d_formatter->format(value, "dB", 3);
d_cursorReadouts->setTimeCursor1Text(text);
d_cursorReadoutsText.t1 = text;
d_cursorReadouts->setVoltageCursor1Text(error ? "-" : text);
d_cursorReadoutsText.t1 = error ? "-" : text;

double valueCursor2;
if (d_trackMode) {
valueCursor2 = getHorizontalCursorIntersection(d_vBar2->plotCoord().x());
} else {
valueCursor2 = d_hBar2->plotCoord().y();
}

double diff = value - d_hBar2->plotCoord().y();
double diff = value - (valueCursor2 * d_displayScale);
text = d_formatter->format(diff, "dB", 3);
d_cursorReadouts->setTimeDeltaText(text);
d_cursorReadoutsText.tDelta = text;
d_cursorReadouts->setVoltageDeltaText(error ? "-" : text);
d_cursorReadoutsText.tDelta = error ? "-" : text;

Q_EMIT cursorReadoutsChanged(d_cursorReadoutsText);
}

void FftDisplayPlot::onHCursor2Moved(double value)
{
QString text;
bool error = false;
if (d_trackMode) {
if (value == ERROR_VALUE) {
error = true;
}
}

value *= d_displayScale;
text = d_formatter->format(value, "dB", 3);
d_cursorReadouts->setTimeCursor2Text(text);
d_cursorReadoutsText.t2 = text;
d_cursorReadouts->setVoltageCursor2Text(error ? "-" : text);
d_cursorReadoutsText.t2 = error ? "-" : text;

double diff = d_hBar1->plotCoord().y() - value;
double valueCursor1;
if (d_trackMode) {
valueCursor1 = getHorizontalCursorIntersection(d_vBar1->plotCoord().x());
} else {
valueCursor1 = d_hBar1->plotCoord().y();
}

double diff = (valueCursor1 * d_displayScale) - value;
text = d_formatter->format(diff, "dB", 3);
d_cursorReadouts->setTimeDeltaText(text);
d_cursorReadoutsText.tDelta = text;
d_cursorReadouts->setVoltageDeltaText(error ? "-" : text);
d_cursorReadoutsText.tDelta = error ? "-" : text;

Q_EMIT cursorReadoutsChanged(d_cursorReadoutsText);
}

void FftDisplayPlot::onVCursor1Moved(double value)
{

QString text;
bool error = false;

value *= d_displayScale;
text = d_formatter->format(value, "Hz", 3);
d_cursorReadouts->setVoltageCursor1Text(error ? "-" : text);
d_cursorReadoutsText.v1 = error ? "-" : text;

double valueCursor2 = d_vBar2->plotCoord().x();
d_cursorReadouts->setTimeCursor1Text(text);
d_cursorReadoutsText.v1 = text;

double diff = value - (valueCursor2 * d_displayScale) ;
double diff = value - d_vBar2->plotCoord().x();
text = d_formatter->format(diff, "Hz", 3);
d_cursorReadouts->setVoltageDeltaText(error ? "-" : text);
d_cursorReadoutsText.vDelta = error ? "-" : text;
d_cursorReadouts->setTimeDeltaText(text);
d_cursorReadoutsText.vDelta = text;

if (d_trackMode) {
onHCursor1Moved(getHorizontalCursorIntersection(d_vBar1->plotCoord().x()));
}

Q_EMIT cursorReadoutsChanged(d_cursorReadoutsText);
}

void FftDisplayPlot::onVCursor2Moved(double value)
{
QString text;
bool error = false;

value *= d_displayScale;
text = d_formatter->format(value, "Hz", 3);
d_cursorReadouts->setVoltageCursor2Text(error ? "-" : text);
d_cursorReadoutsText.v2 = error ? "-" : text;

double valueCursor1 = d_vBar1->plotCoord().x();
d_cursorReadouts->setTimeCursor2Text(text);
d_cursorReadoutsText.v2 = text;

double diff = (valueCursor1 * d_displayScale) - value;
double diff = d_vBar1->plotCoord().x() - value;
text = d_formatter->format(diff, "Hz", 3);
d_cursorReadouts->setVoltageDeltaText(error ? "-" : text);
d_cursorReadoutsText.vDelta = error ? "-" : text;
d_cursorReadouts->setTimeDeltaText(text);
d_cursorReadoutsText.vDelta = text;

if (d_trackMode) {
onHCursor2Moved(getHorizontalCursorIntersection(d_vBar2->plotCoord().x()));
}

Q_EMIT cursorReadoutsChanged(d_cursorReadoutsText);
}
Expand Down Expand Up @@ -371,6 +398,13 @@ void FftDisplayPlot::showEvent(QShowEvent *event)
d_hCursorHandle2->triggerMove();
}

void FftDisplayPlot::setSelectedChannel(int id)
{
if (d_selected_channel != id) {
d_selected_channel = id;
}
}

void FftDisplayPlot::setZoomerEnabled()
{
enableAxis(QwtPlot::xBottom, true);
Expand Down
1 change: 1 addition & 0 deletions src/FftDisplayPlot.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ namespace adiscope {
void customEvent(QEvent *e);
void showEvent(QShowEvent *event);
bool getLogScale() const;
void setSelectedChannel(int id);
};
}

Expand Down
11 changes: 5 additions & 6 deletions src/dbgraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@ void dBgraph::setupVerticalBars()

void dBgraph::setupReadouts()
{
d_cursorReadouts = new CursorReadouts(this);
d_cursorReadouts->setAxis(QwtPlot::xTop,QwtPlot::yLeft);
d_cursorReadouts->setTopLeftStartingPoint(QPoint(8, 8));
d_cursorReadouts->moveToPosition(CustomPlotPositionButton::topLeft);

d_cursorReadouts->setTimeReadoutVisible(false);
d_cursorReadouts->setVoltageReadoutVisible(false);

Expand Down Expand Up @@ -150,6 +145,10 @@ dBgraph::dBgraph(QWidget *parent, bool isdBgraph)
d_leftHandlesArea->setBottomPadding(0);
d_leftHandlesArea->setMinimumHeight(this->minimumHeight());

d_rightHandlesArea->setMinimumWidth(40);
d_rightHandlesArea->setMinimumHeight(this->minimumHeight());


d_topHandlesArea->setMinimumHeight(20);
d_topHandlesArea->setLargestChildWidth(60);

Expand Down Expand Up @@ -310,7 +309,7 @@ bool dBgraph::eventFilter(QObject *object, QEvent *event)

d_leftHandlesArea->repaint();
d_bottomHandlesArea->setLeftPadding(d_leftHandlesArea->width() + 10);
d_bottomHandlesArea->setRightPadding(80);
d_bottomHandlesArea->setRightPadding(d_rightHandlesArea->width() + 24);

d_hCursorHandle1->triggerMove();
d_hCursorHandle2->triggerMove();
Expand Down
17 changes: 16 additions & 1 deletion src/network_analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ NetworkAnalyzer::NetworkAnalyzer(struct iio_context *ctx, Filter *filt,

ui->gridLayout_plots->addWidget(bufferPreviewer, 0, 1, 1, 1);
ui->gridLayout_plots->addWidget(ui->statusWidget, 1, 1, 1, 1);
ui->gridLayout_plots->addWidget(m_dBgraph.rightHandlesArea(), 0, 2, 6, 1);
ui->gridLayout_plots->addWidget(m_dBgraph.topHandlesArea(), 2, 0, 1, 2);
ui->gridLayout_plots->addWidget(m_dBgraph.leftHandlesArea(), 3, 0, 1, 1);
ui->gridLayout_plots->addWidget(&m_dBgraph, 3, 1, 1, 1);
Expand All @@ -432,7 +433,7 @@ NetworkAnalyzer::NetworkAnalyzer(struct iio_context *ctx, Filter *filt,
ui->gridLayout_plots->addWidget(m_phaseGraph.leftHandlesArea(), 5, 0, 1, 1);
ui->gridLayout_plots->addWidget(&m_phaseGraph, 5, 1, 1, 1);

ui->gridLayout_plots->addWidget(m_dBgraph.bottomHandlesArea(), 6, 0, 1, 2);
ui->gridLayout_plots->addWidget(m_dBgraph.bottomHandlesArea(), 6, 0, 1, 3);

m_phaseGraph.enableXaxisLabels();
m_dBgraph.enableXaxisLabels();
Expand Down Expand Up @@ -586,6 +587,20 @@ NetworkAnalyzer::NetworkAnalyzer(struct iio_context *ctx, Filter *filt,
m_phaseGraph.setCursorReadoutsTransparency(value);
});

setDynamicProperty(ui->btnLockHorizontal, "use_icon", true);

connect(ui->btnLockHorizontal, &QPushButton::toggled,
&m_dBgraph, &dBgraph::setHorizCursorsLocked);

connect(ui->btnLockHorizontal, &QPushButton::toggled,
&m_phaseGraph, &dBgraph::setHorizCursorsLocked);

connect(ui->hCursorsEnable, &QPushButton::toggled,
&m_dBgraph, &dBgraph::toggleCursors);

connect(ui->hCursorsEnable, &QPushButton::toggled,
&m_phaseGraph, &dBgraph::toggleCursors);

connect(ui->posSelect, &CustomPlotPositionButton::positionChanged,
[=](CustomPlotPositionButton::ReadoutsPosition position) {
m_dBgraph.moveCursorReadouts(position);
Expand Down
16 changes: 8 additions & 8 deletions src/oscilloscope_plot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,8 @@ void CapturePlot::enableTimeTrigger(bool enable)
d_timeTriggerHandle->setVisible(enable);
}

void CapturePlot::onVCursor1Moved(double value) {
void CapturePlot::onVCursor1Moved(double value)
{
QString text;
text = d_cursorTimeFormatter.format(value, "", 3);
d_cursorReadouts->setTimeCursor1Text(text);
Expand All @@ -483,10 +484,9 @@ void CapturePlot::onVCursor1Moved(double value) {
Q_EMIT cursorReadoutsChanged(d_cursorReadoutsText);
}

void CapturePlot::onVCursor2Moved(double value){

void CapturePlot::onVCursor2Moved(double value)
{
QString text;

text = d_cursorTimeFormatter.format(value, "", 3);
d_cursorReadouts->setTimeCursor2Text(text);
d_cursorReadoutsText.t2 = text;
Expand All @@ -510,8 +510,8 @@ void CapturePlot::onVCursor2Moved(double value){
Q_EMIT cursorReadoutsChanged(d_cursorReadoutsText);
}

void CapturePlot::onHCursor1Moved(double value) {

void CapturePlot::onHCursor1Moved(double value)
{
QString text;

bool error = false;
Expand Down Expand Up @@ -542,8 +542,8 @@ void CapturePlot::onHCursor1Moved(double value) {
Q_EMIT cursorReadoutsChanged(d_cursorReadoutsText);
}

void CapturePlot::onHCursor2Moved(double value) {

void CapturePlot::onHCursor2Moved(double value)
{
QString text;

bool error = false;
Expand Down
Loading

0 comments on commit 5492b59

Please sign in to comment.