diff --git a/Software/PC_Application/Traces/tracemarker.cpp b/Software/PC_Application/Traces/tracemarker.cpp index 8cde9f6..de84e5a 100644 --- a/Software/PC_Application/Traces/tracemarker.cpp +++ b/Software/PC_Application/Traces/tracemarker.cpp @@ -204,7 +204,7 @@ QString TraceMarker::readableData(Format f) if(type != Type::Delta) { switch(f) { case Format::dB: - return Unit::ToString(Unit::dB(data), "dB", " ", 3); + return Unit::ToString(Unit::dB(data), "dB", " ", 4); case Format::RealImag: return Unit::ToString(data.real(), "", " ", 5) + "+"+Unit::ToString(data.imag(), "", " ", 5)+"j"; case Format::Impedance: { @@ -222,7 +222,7 @@ QString TraceMarker::readableData(Format f) } switch(f) { case Format::dB: - return "Δ:"+Unit::ToString(Unit::dB(data) - Unit::dB(delta->data), "dB", " ", 3); + return "Δ:"+Unit::ToString(Unit::dB(data) - Unit::dB(delta->data), "dB", " ", 4); case Format::RealImag: return "Δ:"+Unit::ToString(data.real() - delta->data.real(), "", " ", 5) + "+"+Unit::ToString(data.imag() - delta->data.real(), "", " ", 5)+"j"; case Format::Impedance: { @@ -246,8 +246,8 @@ QString TraceMarker::readableData(Format f) return "TODO"; default: switch(f) { - case Format::dB: return Unit::ToString(Unit::dB(data), "dB", " ", 3); - case Format::dBAngle: return Unit::ToString(Unit::dB(data), "dB", " ", 3) + "/"+Unit::ToString(arg(data)*180/M_PI, "°", " ", 3); + case Format::dB: return Unit::ToString(Unit::dB(data), "dB", " ", 4); + case Format::dBAngle: return Unit::ToString(Unit::dB(data), "dB", " ", 4) + "/"+Unit::ToString(arg(data)*180/M_PI, "°", " ", 3); case Format::RealImag: return Unit::ToString(data.real(), "", " ", 5) + "+"+Unit::ToString(data.imag(), "", " ", 5)+"j"; case Format::Noise: return Unit::ToString(parentTrace->getNoise(position), "dbm/Hz", " ", 3); case Format::TOI: { @@ -751,6 +751,11 @@ void TraceMarker::setTableFormat(TraceMarker::Format f) emit dataChanged(this); } +std::set TraceMarker::getGraphDisplayFormats() const +{ + return formatGraph; +} + TraceMarker::Type TraceMarker::getType() const { return type; diff --git a/Software/PC_Application/Traces/tracemarker.h b/Software/PC_Application/Traces/tracemarker.h index 34f6f1d..efe61ee 100644 --- a/Software/PC_Application/Traces/tracemarker.h +++ b/Software/PC_Application/Traces/tracemarker.h @@ -103,6 +103,8 @@ public: unsigned int toHash(); + std::set getGraphDisplayFormats() const; + public slots: void setPosition(double freq); signals: diff --git a/Software/PC_Application/Traces/traceplot.cpp b/Software/PC_Application/Traces/traceplot.cpp index 34aca49..c089a62 100644 --- a/Software/PC_Application/Traces/traceplot.cpp +++ b/Software/PC_Application/Traces/traceplot.cpp @@ -4,6 +4,7 @@ #include #include #include +#include "unit.h" std::set TracePlot::plots; @@ -118,28 +119,63 @@ void TracePlot::paintEvent(QPaintEvent *event) p.setBackground(QBrush(pref.General.graphColors.background)); p.fillRect(0, 0, width(), height(), QBrush(pref.General.graphColors.background)); - // show names of active traces - QFont font = p.font(); - font.setPixelSize(12); - p.setFont(font); - int x = 1; + // show names of active traces and marker data (if enabled) + bool hasMarkerData = false; + int x = 1; // xcoordinate for the next trace name + int y = marginTop; // ycoordinate for the next marker data for(auto t : traces) { if(!t.second || !t.first->isVisible()) { continue; } auto textArea = QRect(x, 0, width() - x, marginTop); QRect usedArea; + QFont font = p.font(); + font.setPixelSize(12); + p.setFont(font); p.setPen(t.first->color()); p.drawText(textArea, 0, t.first->name() + " ", &usedArea); x += usedArea.width(); - if(x >= width()) { - // used up all available space - break; + + auto tmarkers = t.first->getMarkers(); + + font.setPixelSize(12); + p.setFont(font); + for(auto m : tmarkers) { + if(!xCoordinateVisible(m->getPosition())) { + // marker not visible with current plot settings + continue; + } + if(m->getGraphDisplayFormats().size() == 0) { + // this marker has nothing to display + continue; + } + hasMarkerData = true; + + auto textArea = QRect(width() - marginRight - marginMarkerData, y, width() - marginRight, y + 100); + p.drawText(textArea, 0, "Marker "+QString::number(m->getNumber())+m->getSuffix()+": "+Unit::ToString(m->getPosition(), "", "pnum kMG", 6), &usedArea); + y += usedArea.height(); + + for(auto f : m->getGraphDisplayFormats()) { + auto textArea = QRect(width() - marginRight - marginMarkerData, y, width() - marginRight, y + 100); + p.drawText(textArea, 0, m->readableData(f), &usedArea); + y += usedArea.height(); + } + // leave one row empty between markers + y += usedArea.height(); } } - p.setViewport(marginLeft, marginTop, width() - marginLeft - marginRight, height() - marginTop - marginBottom); - p.setWindow(0, 0, width() - marginLeft - marginRight, height() - marginTop - marginBottom); + unsigned int l = marginLeft; + unsigned int t = marginTop; + unsigned int w = width() - marginLeft - marginRight; + unsigned int h = height() - marginTop - marginBottom; + + if(hasMarkerData) { + w -= marginMarkerData; + } + + p.setViewport(l, t, w, h); + p.setWindow(0, 0, w, h); draw(p); } diff --git a/Software/PC_Application/Traces/traceplot.h b/Software/PC_Application/Traces/traceplot.h index afdb63a..f5a5bfb 100644 --- a/Software/PC_Application/Traces/traceplot.h +++ b/Software/PC_Application/Traces/traceplot.h @@ -72,11 +72,15 @@ protected slots: void checkIfStillSupported(Trace *t); virtual void markerAdded(TraceMarker *m); virtual void markerRemoved(TraceMarker *m); + virtual bool xCoordinateVisible(double x) = 0; protected: static constexpr unsigned int marginTop = 20; static constexpr unsigned int marginBottom = 0; static constexpr unsigned int marginLeft = 0; static constexpr unsigned int marginRight = 0; + + static constexpr unsigned int marginMarkerData = 150; + double sweep_fmin, sweep_fmax; TraceModel &model; TraceMarker *selectedMarker; diff --git a/Software/PC_Application/Traces/tracesmithchart.cpp b/Software/PC_Application/Traces/tracesmithchart.cpp index c0d12ce..55c524b 100644 --- a/Software/PC_Application/Traces/tracesmithchart.cpp +++ b/Software/PC_Application/Traces/tracesmithchart.cpp @@ -115,6 +115,20 @@ double TraceSmithChart::nearestTracePoint(Trace *t, QPoint pixel) return t->sample(closestIndex).x; } +bool TraceSmithChart::xCoordinateVisible(double x) +{ + if(limitToSpan) { + if(x >= sweep_fmin && x <= sweep_fmax) { + return true; + } else { + return false; + } + } else { + // complete traces visible + return true; + } +} + void TraceSmithChart::draw(QPainter &p) { auto pref = Preferences::getInstance(); diff --git a/Software/PC_Application/Traces/tracesmithchart.h b/Software/PC_Application/Traces/tracesmithchart.h index 4fecfab..32dcd91 100644 --- a/Software/PC_Application/Traces/tracesmithchart.h +++ b/Software/PC_Application/Traces/tracesmithchart.h @@ -27,6 +27,7 @@ protected: std::complex pixelToData(QPoint p); QPoint markerToPixel(TraceMarker *m) override; double nearestTracePoint(Trace *t, QPoint pixel) override; + virtual bool xCoordinateVisible(double x); //void paintEvent(QPaintEvent *event) override; virtual void updateContextMenu() override; diff --git a/Software/PC_Application/Traces/tracexyplot.cpp b/Software/PC_Application/Traces/tracexyplot.cpp index 5c08435..12e44db 100644 --- a/Software/PC_Application/Traces/tracexyplot.cpp +++ b/Software/PC_Application/Traces/tracexyplot.cpp @@ -930,6 +930,15 @@ double TraceXYPlot::nearestTracePoint(Trace *t, QPoint pixel) return closestXpos; } +bool TraceXYPlot::xCoordinateVisible(double x) +{ + if(x >= min(XAxis.rangeMin, XAxis.rangeMax) && x <= max(XAxis.rangeMax, XAxis.rangeMin)) { + return true; + } else { + return false; + } +} + void TraceXYPlot::traceDropped(Trace *t, QPoint position) { if(t->outputType() == Trace::DataType::Frequency && XAxis.type != XAxisType::Frequency) { diff --git a/Software/PC_Application/Traces/tracexyplot.h b/Software/PC_Application/Traces/tracexyplot.h index bee6e50..b5fdf2c 100644 --- a/Software/PC_Application/Traces/tracexyplot.h +++ b/Software/PC_Application/Traces/tracexyplot.h @@ -77,6 +77,7 @@ private: QPointF pixelToPlotValue(QPoint pixel, int YAxis); QPoint markerToPixel(TraceMarker *m) override; double nearestTracePoint(Trace *t, QPoint pixel) override; + virtual bool xCoordinateVisible(double x); void traceDropped(Trace *t, QPoint position) override; QString mouseText(QPoint pos) override;