From 1b003cc481e0f90f216ce46b29ebb4d684e8426a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20K=C3=A4berich?= Date: Wed, 25 Nov 2020 11:55:53 +0100 Subject: [PATCH] Removed warnings, added XY-plot data next to cursor --- .../PC_Application/Traces/tracemarker.cpp | 2 +- Software/PC_Application/Traces/traceplot.cpp | 3 +- .../PC_Application/Traces/tracexyplot.cpp | 53 +++++++++++++++++++ Software/PC_Application/Traces/tracexyplot.h | 5 ++ .../Traces/xyplotaxisdialog.cpp | 24 ++------- .../PC_Application/Traces/xyplotaxisdialog.h | 1 - .../.settings/language.settings.xml | 2 +- 7 files changed, 65 insertions(+), 25 deletions(-) diff --git a/Software/PC_Application/Traces/tracemarker.cpp b/Software/PC_Application/Traces/tracemarker.cpp index 70df22d..a4dd9d3 100644 --- a/Software/PC_Application/Traces/tracemarker.cpp +++ b/Software/PC_Application/Traces/tracemarker.cpp @@ -44,7 +44,7 @@ void TraceMarker::setTimeDomain(bool timeDomain) return; } this->timeDomain = timeDomain; - // TODO handle changed setting and everything + if(timeDomain) { // need to delete this marker if the TDR data of the trace is no longer available connect(parentTrace, &Trace::changedTDRstate, [=](bool tdr_available){ diff --git a/Software/PC_Application/Traces/traceplot.cpp b/Software/PC_Application/Traces/traceplot.cpp index dfd6f89..933dad5 100644 --- a/Software/PC_Application/Traces/traceplot.cpp +++ b/Software/PC_Application/Traces/traceplot.cpp @@ -99,7 +99,7 @@ void TracePlot::contextMenuEvent(QContextMenuEvent *event) void TracePlot::paintEvent(QPaintEvent *event) { - + Q_UNUSED(event) auto pref = Preferences::getInstance(); QPainter p(this); // p.setRenderHint(QPainter::Antialiasing); @@ -172,6 +172,7 @@ void TracePlot::mousePressEvent(QMouseEvent *event) void TracePlot::mouseReleaseEvent(QMouseEvent *event) { + Q_UNUSED(event) selectedMarker = nullptr; } diff --git a/Software/PC_Application/Traces/tracexyplot.cpp b/Software/PC_Application/Traces/tracexyplot.cpp index e16b07b..319e4c3 100644 --- a/Software/PC_Application/Traces/tracexyplot.cpp +++ b/Software/PC_Application/Traces/tracexyplot.cpp @@ -298,6 +298,7 @@ void TraceXYPlot::draw(QPainter &p) case YAxisType::Impulse: labelY = "Impulse Response"; break; case YAxisType::Step: labelY = "Step Response"; break; case YAxisType::Impedance: labelY = "Impedance"; break; + default: break; } auto xStart = i == 0 ? 0 : w.width() - AxisLabelSize * 1.5; p.save(); @@ -719,6 +720,14 @@ QPoint TraceXYPlot::plotValueToPixel(QPointF plotValue, int Yaxis) return p; } +QPointF TraceXYPlot::pixelToPlotValue(QPoint pixel, int Yaxis) +{ + QPointF p; + p.setX(Util::Scale(pixel.x(), plotAreaLeft, plotAreaLeft + plotAreaWidth, XAxis.rangeMin, XAxis.rangeMax)); + p.setY(Util::Scale(pixel.y(), plotAreaBottom, 0, YAxis[Yaxis].rangeMin, YAxis[Yaxis].rangeMax)); + return p; +} + QPoint TraceXYPlot::markerToPixel(TraceMarker *m) { QPoint ret = QPoint(); @@ -791,3 +800,47 @@ void TraceXYPlot::traceDropped(Trace *t, QPoint position) enableTraceAxis(t, 1, true); } } + +QString TraceXYPlot::mouseText(QPoint pos) +{ + QString ret; + if(QRect(plotAreaLeft, 0, plotAreaWidth + 1, plotAreaBottom).contains(pos)) { + // cursor within plot area + QPointF coords[2]; + coords[0] = pixelToPlotValue(pos, 0); + coords[1] = pixelToPlotValue(pos, 1); + int significantDigits = floor(log10(XAxis.rangeMax)) - floor(log10((XAxis.rangeMax - XAxis.rangeMin) / 1000.0)) + 1; + ret += Unit::ToString(coords[0].x(), AxisUnit(XAxis.type), "fpnum kMG", significantDigits) + "\n"; + for(int i=0;i<2;i++) { + if(YAxis[i].type != YAxisType::Disabled) { + auto max = qMax(abs(YAxis[i].rangeMax), abs(YAxis[i].rangeMin)); + auto step = abs(YAxis[i].rangeMax - YAxis[i].rangeMin) / 1000.0; + significantDigits = floor(log10(max)) - floor(log10(step)) + 1; + ret += Unit::ToString(coords[i].y(), AxisUnit(YAxis[i].type), "fpnum kMG", significantDigits) + "\n"; + } + } + } + return ret; +} + +QString TraceXYPlot::AxisUnit(TraceXYPlot::YAxisType type) +{ + switch(type) { + case TraceXYPlot::YAxisType::Magnitude: return "db"; break; + case TraceXYPlot::YAxisType::Phase: return "°"; break; + case TraceXYPlot::YAxisType::VSWR: return ""; break; + case TraceXYPlot::YAxisType::Impulse: return ""; break; + case TraceXYPlot::YAxisType::Step: return ""; break; + case TraceXYPlot::YAxisType::Impedance: return "Ohm"; break; + default: return ""; break; + } +} + +QString TraceXYPlot::AxisUnit(TraceXYPlot::XAxisType type) +{ + switch(type) { + case XAxisType::Frequency: return "Hz"; break; + case XAxisType::Time: return "s"; break; + case XAxisType::Distance: return "m"; break; + } +} diff --git a/Software/PC_Application/Traces/tracexyplot.h b/Software/PC_Application/Traces/tracexyplot.h index 0502513..b94c6ed 100644 --- a/Software/PC_Application/Traces/tracexyplot.h +++ b/Software/PC_Application/Traces/tracexyplot.h @@ -63,9 +63,14 @@ private: unsigned int numTraceSamples(Trace *t); QPoint dataToPixel(Trace::Data d); QPoint plotValueToPixel(QPointF plotValue, int Yaxis); + QPointF pixelToPlotValue(QPoint pixel, int YAxis); QPoint markerToPixel(TraceMarker *m) override; double nearestTracePoint(Trace *t, QPoint pixel) override; void traceDropped(Trace *t, QPoint position) override; + QString mouseText(QPoint pos) override; + + static QString AxisUnit(YAxisType type); + static QString AxisUnit(XAxisType type); std::set tracesAxis[2]; diff --git a/Software/PC_Application/Traces/xyplotaxisdialog.cpp b/Software/PC_Application/Traces/xyplotaxisdialog.cpp index 9f508a2..f454c07 100644 --- a/Software/PC_Application/Traces/xyplotaxisdialog.cpp +++ b/Software/PC_Application/Traces/xyplotaxisdialog.cpp @@ -21,7 +21,7 @@ XYplotAxisDialog::XYplotAxisDialog(TraceXYPlot *plot) : ui->Y1max->setEnabled(index != 0 && !autoRange); ui->Y1divs->setEnabled(index != 0 && !autoRange); auto type = (TraceXYPlot::YAxisType) index; - QString unit = YAxisUnit(type); + QString unit = TraceXYPlot::AxisUnit(type); ui->Y1min->setUnit(unit); ui->Y1max->setUnit(unit); ui->Y1divs->setUnit(unit); @@ -41,7 +41,7 @@ XYplotAxisDialog::XYplotAxisDialog(TraceXYPlot *plot) : ui->Y2max->setEnabled(index != 0 && !autoRange); ui->Y2divs->setEnabled(index != 0 && !autoRange); auto type = (TraceXYPlot::YAxisType) index; - QString unit = YAxisUnit(type); + QString unit = TraceXYPlot::AxisUnit(type); ui->Y2min->setUnit(unit); ui->Y2max->setUnit(unit); ui->Y2divs->setUnit(unit); @@ -160,30 +160,12 @@ void XYplotAxisDialog::XAxisTypeChanged(int XAxisIndex) } } - QString unit; - switch(type) { - case TraceXYPlot::XAxisType::Frequency: unit = "Hz"; break; - case TraceXYPlot::XAxisType::Time: unit = "s"; break; - case TraceXYPlot::XAxisType::Distance: unit = "m"; break; - } + QString unit = TraceXYPlot::AxisUnit(type); ui->Xmin->setUnit(unit); ui->Xmax->setUnit(unit); ui->Xdivs->setUnit(unit); } -QString XYplotAxisDialog::YAxisUnit(TraceXYPlot::YAxisType type) -{ - switch(type) { - case TraceXYPlot::YAxisType::Magnitude: return "db"; break; - case TraceXYPlot::YAxisType::Phase: return "°"; break; - case TraceXYPlot::YAxisType::VSWR: return ""; break; - case TraceXYPlot::YAxisType::Impulse: return ""; break; - case TraceXYPlot::YAxisType::Step: return ""; break; - case TraceXYPlot::YAxisType::Impedance: return "Ohm"; break; - default: return ""; break; - } -} - std::set XYplotAxisDialog::supportedYAxis(TraceXYPlot::XAxisType type) { set ret = {TraceXYPlot::YAxisType::Disabled}; diff --git a/Software/PC_Application/Traces/xyplotaxisdialog.h b/Software/PC_Application/Traces/xyplotaxisdialog.h index 56e8af5..0a75284 100644 --- a/Software/PC_Application/Traces/xyplotaxisdialog.h +++ b/Software/PC_Application/Traces/xyplotaxisdialog.h @@ -21,7 +21,6 @@ private slots: void XAxisTypeChanged(int XAxisIndex); private: - QString YAxisUnit(TraceXYPlot::YAxisType type); std::set supportedYAxis(TraceXYPlot::XAxisType type); Ui::XYplotAxisDialog *ui; TraceXYPlot *plot; diff --git a/Software/VNA_embedded/.settings/language.settings.xml b/Software/VNA_embedded/.settings/language.settings.xml index 1e25ada..aadbc97 100644 --- a/Software/VNA_embedded/.settings/language.settings.xml +++ b/Software/VNA_embedded/.settings/language.settings.xml @@ -11,7 +11,7 @@ - +