Display marker data on graphs if enabled
This commit is contained in:
parent
ee82237993
commit
93f5eba6a8
@ -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::Format> TraceMarker::getGraphDisplayFormats() const
|
||||
{
|
||||
return formatGraph;
|
||||
}
|
||||
|
||||
TraceMarker::Type TraceMarker::getType() const
|
||||
{
|
||||
return type;
|
||||
|
@ -103,6 +103,8 @@ public:
|
||||
unsigned int toHash();
|
||||
|
||||
|
||||
std::set<Format> getGraphDisplayFormats() const;
|
||||
|
||||
public slots:
|
||||
void setPosition(double freq);
|
||||
signals:
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <QPainter>
|
||||
#include <QMimeData>
|
||||
#include <QDebug>
|
||||
#include "unit.h"
|
||||
|
||||
std::set<TracePlot*> 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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
|
||||
|
@ -27,6 +27,7 @@ protected:
|
||||
std::complex<double> 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;
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user