mirror of
https://github.com/jankae/LibreVNA.git
synced 2026-04-05 14:35:23 +00:00
Merge branch 'master' into trace_math
This commit is contained in:
commit
2039c8f74d
14 changed files with 191 additions and 95 deletions
|
|
@ -16,7 +16,6 @@ SIUnitEdit::SIUnitEdit(QString unit, QString prefixes, int precision, QWidget *p
|
|||
this->precision = precision;
|
||||
setAlignment(Qt::AlignCenter);
|
||||
installEventFilter(this);
|
||||
setValidator(new QDoubleValidator(this));
|
||||
connect(this, &QLineEdit::editingFinished, [this]() {
|
||||
parseNewValue(1.0);
|
||||
});
|
||||
|
|
@ -98,20 +97,41 @@ bool SIUnitEdit::eventFilter(QObject *, QEvent *event)
|
|||
// most mousewheel have 15 degree increments, the reported delta is in 1/8th degree -> 120
|
||||
auto increment = wheel->angleDelta().y() / 120.0;
|
||||
// round toward bigger step in case of special higher resolution mousewheel
|
||||
unsigned int steps = abs(increment > 0 ? ceil(increment) : floor(increment));
|
||||
unsigned int steps = std::abs(increment > 0 ? ceil(increment) : floor(increment));
|
||||
int sign = increment > 0 ? 1 : -1;
|
||||
// figure out step increment
|
||||
auto newVal = _value;
|
||||
while(steps > 0) {
|
||||
// do update in multiple steps because the step size could change inbetween
|
||||
auto cursor = cursorPosition();
|
||||
if(cursor == 0) {
|
||||
// no active cursor, use default digit
|
||||
constexpr int nthDigit = 3;
|
||||
auto step_size = pow(10, floor(log10(abs(newVal))) - nthDigit + 1);
|
||||
newVal += step_size * sign;
|
||||
steps--;
|
||||
while(steps > 0) {
|
||||
// do update in multiple steps because the step size could change inbetween
|
||||
auto step_size = pow(10, floor(log10(std::abs(newVal))) - nthDigit + 1);
|
||||
newVal += step_size * sign;
|
||||
steps--;
|
||||
}
|
||||
setValue(newVal);
|
||||
} else {
|
||||
// change the digit at the current cursor
|
||||
int nthDigit = cursor;
|
||||
// account for decimal point/leading zero/sign
|
||||
if(_value < 0) {
|
||||
nthDigit--;
|
||||
}
|
||||
auto dotPos = text().indexOf('.');
|
||||
if(dotPos >= 0 && dotPos < nthDigit) {
|
||||
nthDigit--;
|
||||
}
|
||||
if(text().startsWith("-0.") || text().startsWith("0.")) {
|
||||
nthDigit--;
|
||||
}
|
||||
auto step_size = pow(10, floor(log10(std::abs(newVal))) - nthDigit + 1);
|
||||
newVal += step_size * steps * sign;
|
||||
setValue(newVal);
|
||||
setText(placeholderText());
|
||||
setCursorPosition(cursor);
|
||||
}
|
||||
setValue(newVal);
|
||||
continueEditing();
|
||||
setFocus();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -220,54 +220,66 @@ void TraceXYPlot::draw(QPainter &p)
|
|||
font.setPixelSize(AxisLabelSize);
|
||||
p.setFont(font);
|
||||
p.drawText(QRect(0, w.height()-AxisLabelSize*1.5, w.width(), AxisLabelSize*1.5), Qt::AlignHCenter, labelX);
|
||||
// draw X ticks
|
||||
// this only works for evenly distributed ticks:
|
||||
auto max = qMax(abs(XAxis.ticks.front()), abs(XAxis.ticks.back()));
|
||||
auto step = abs(XAxis.ticks[0] - XAxis.ticks[1]);
|
||||
int significantDigits = floor(log10(max)) - floor(log10(step)) + 1;
|
||||
bool displayFullFreq = significantDigits <= 5;
|
||||
constexpr int displayLastDigits = 4;
|
||||
QString prefixes = "fpnum kMG";
|
||||
QString commonPrefix = QString();
|
||||
if(!displayFullFreq) {
|
||||
auto fullFreq = Unit::ToString(XAxis.ticks.front(), "", prefixes, significantDigits);
|
||||
commonPrefix = fullFreq.at(fullFreq.size() - 1);
|
||||
auto front = fullFreq;
|
||||
front.truncate(fullFreq.size() - displayLastDigits);
|
||||
auto back = fullFreq;
|
||||
back.remove(0, front.size());
|
||||
back.append("..");
|
||||
p.setPen(QPen(QColor("orange")));
|
||||
QRect bounding;
|
||||
p.drawText(QRect(2, plotAreaBottom + AxisLabelSize + 5, w.width(), AxisLabelSize), 0, front, &bounding);
|
||||
p.setPen(pref.General.graphColors.axis);
|
||||
p.drawText(QRect(bounding.x() + bounding.width(), plotAreaBottom + AxisLabelSize + 5, w.width(), AxisLabelSize), 0, back);
|
||||
}
|
||||
|
||||
for(auto t : XAxis.ticks) {
|
||||
auto xCoord = Util::Scale<double>(t, XAxis.rangeMin, XAxis.rangeMax, plotAreaLeft, plotAreaLeft + plotAreaWidth);
|
||||
auto tickValue = Unit::ToString(t, "", prefixes, significantDigits);
|
||||
p.setPen(QPen(pref.General.graphColors.axis, 1));
|
||||
if(displayFullFreq) {
|
||||
p.drawText(QRect(xCoord - 40, plotAreaBottom + 5, 80, AxisLabelSize), Qt::AlignHCenter, tickValue);
|
||||
if(XAxis.ticks.size() >= 1) {
|
||||
// draw X ticks
|
||||
// this only works for evenly distributed ticks:
|
||||
auto max = qMax(abs(XAxis.ticks.front()), abs(XAxis.ticks.back()));
|
||||
auto minLabel = qMin(abs(XAxis.ticks.front()), abs(XAxis.ticks.back()));
|
||||
double step;
|
||||
if(XAxis.ticks.size() >= 2) {
|
||||
step = abs(XAxis.ticks[0] - XAxis.ticks[1]);
|
||||
} else {
|
||||
// check if the same prefix was used as in the fullFreq string
|
||||
if(tickValue.at(tickValue.size() - 1) != commonPrefix) {
|
||||
// prefix changed, we reached the next order of magnitude. Force same prefix as in fullFreq and add extra digit
|
||||
tickValue = Unit::ToString(t, "", commonPrefix, significantDigits + 1);
|
||||
}
|
||||
|
||||
tickValue.remove(0, tickValue.size() - displayLastDigits);
|
||||
QRect bounding;
|
||||
p.drawText(QRect(xCoord - 40, plotAreaBottom + 5, 80, AxisLabelSize), Qt::AlignHCenter, tickValue, &bounding);
|
||||
p.setPen(QPen(QColor("orange")));
|
||||
p.drawText(QRect(0, plotAreaBottom + 5, bounding.x() - 1, AxisLabelSize), Qt::AlignRight, "..");
|
||||
p.setPen(QPen(pref.General.graphColors.axis, 1));
|
||||
// only one tick, set arbitrary number of digits
|
||||
step = max / 1000;
|
||||
}
|
||||
p.drawLine(xCoord, plotAreaBottom, xCoord, plotAreaBottom + 2);
|
||||
if(xCoord != plotAreaLeft && xCoord != plotAreaLeft + plotAreaWidth) {
|
||||
p.setPen(QPen(pref.General.graphColors.divisions, 0.5, Qt::DashLine));
|
||||
p.drawLine(xCoord, 0, xCoord, plotAreaBottom);
|
||||
if(minLabel > 0 && minLabel < step) {
|
||||
step = minLabel;
|
||||
}
|
||||
int significantDigits = floor(log10(max)) - floor(log10(step)) + 1;
|
||||
bool displayFullFreq = significantDigits <= 5;
|
||||
constexpr int displayLastDigits = 4;
|
||||
QString prefixes = "fpnum kMG";
|
||||
QString commonPrefix = QString();
|
||||
if(!displayFullFreq) {
|
||||
auto fullFreq = Unit::ToString(XAxis.ticks.front(), "", prefixes, significantDigits);
|
||||
commonPrefix = fullFreq.at(fullFreq.size() - 1);
|
||||
auto front = fullFreq;
|
||||
front.truncate(fullFreq.size() - displayLastDigits);
|
||||
auto back = fullFreq;
|
||||
back.remove(0, front.size());
|
||||
back.append("..");
|
||||
p.setPen(QPen(QColor("orange")));
|
||||
QRect bounding;
|
||||
p.drawText(QRect(2, plotAreaBottom + AxisLabelSize + 5, w.width(), AxisLabelSize), 0, front, &bounding);
|
||||
p.setPen(pref.General.graphColors.axis);
|
||||
p.drawText(QRect(bounding.x() + bounding.width(), plotAreaBottom + AxisLabelSize + 5, w.width(), AxisLabelSize), 0, back);
|
||||
}
|
||||
|
||||
for(auto t : XAxis.ticks) {
|
||||
auto xCoord = Util::Scale<double>(t, XAxis.rangeMin, XAxis.rangeMax, plotAreaLeft, plotAreaLeft + plotAreaWidth);
|
||||
auto tickValue = Unit::ToString(t, "", prefixes, significantDigits);
|
||||
p.setPen(QPen(pref.General.graphColors.axis, 1));
|
||||
if(displayFullFreq) {
|
||||
p.drawText(QRect(xCoord - 40, plotAreaBottom + 5, 80, AxisLabelSize), Qt::AlignHCenter, tickValue);
|
||||
} else {
|
||||
// check if the same prefix was used as in the fullFreq string
|
||||
if(tickValue.at(tickValue.size() - 1) != commonPrefix) {
|
||||
// prefix changed, we reached the next order of magnitude. Force same prefix as in fullFreq and add extra digit
|
||||
tickValue = Unit::ToString(t, "", commonPrefix, significantDigits + 1);
|
||||
}
|
||||
|
||||
tickValue.remove(0, tickValue.size() - displayLastDigits);
|
||||
QRect bounding;
|
||||
p.drawText(QRect(xCoord - 40, plotAreaBottom + 5, 80, AxisLabelSize), Qt::AlignHCenter, tickValue, &bounding);
|
||||
p.setPen(QPen(QColor("orange")));
|
||||
p.drawText(QRect(0, plotAreaBottom + 5, bounding.x() - 1, AxisLabelSize), Qt::AlignRight, "..");
|
||||
p.setPen(QPen(pref.General.graphColors.axis, 1));
|
||||
}
|
||||
p.drawLine(xCoord, plotAreaBottom, xCoord, plotAreaBottom + 2);
|
||||
if(xCoord != plotAreaLeft && xCoord != plotAreaLeft + plotAreaWidth) {
|
||||
p.setPen(QPen(pref.General.graphColors.divisions, 0.5, Qt::DashLine));
|
||||
p.drawLine(xCoord, 0, xCoord, plotAreaBottom);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -293,10 +305,16 @@ void TraceXYPlot::draw(QPainter &p)
|
|||
p.drawText(QRect(0, 0, w.height()-xAxisSpace, AxisLabelSize*1.5), Qt::AlignHCenter, labelY);
|
||||
p.restore();
|
||||
// draw ticks
|
||||
if(YAxis[0].type != YAxisType::Disabled) {
|
||||
if(YAxis[i].type != YAxisType::Disabled && YAxis[i].ticks.size() > 0) {
|
||||
// this only works for evenly distributed ticks:
|
||||
auto max = qMax(abs(YAxis[i].ticks.front()), abs(YAxis[i].ticks.back()));
|
||||
auto step = abs(YAxis[i].ticks[0] - YAxis[i].ticks[1]);
|
||||
double step;
|
||||
if(YAxis[i].ticks.size() >= 2) {
|
||||
step = abs(YAxis[i].ticks[0] - YAxis[i].ticks[1]);
|
||||
} else {
|
||||
// only one tick, set arbitrary number of digits
|
||||
step = max / 1000;
|
||||
}
|
||||
int significantDigits = floor(log10(max)) - floor(log10(step)) + 1;
|
||||
for(auto t : YAxis[i].ticks) {
|
||||
auto yCoord = Util::Scale<double>(t, YAxis[i].rangeMax, YAxis[i].rangeMin, 0, w.height() - xAxisSpace);
|
||||
|
|
|
|||
|
|
@ -216,16 +216,35 @@ void PortExtension::edit()
|
|||
ui->P2calkit->setEnabled(false);
|
||||
}
|
||||
|
||||
auto updateValuesFromUI = [=](){
|
||||
port1.delay = ui->P1Time->value();
|
||||
port1.velocityFactor = ui->P1Velocity->value();
|
||||
port1.DCloss = ui->P1DCloss->value();
|
||||
port1.loss = ui->P1Loss->value();
|
||||
port1.frequency = ui->P1Frequency->value();
|
||||
port2.delay = ui->P2Time->value();
|
||||
port2.velocityFactor = ui->P2Velocity->value();
|
||||
port2.DCloss = ui->P2DCloss->value();
|
||||
port2.loss = ui->P2Loss->value();
|
||||
port2.frequency = ui->P2Frequency->value();
|
||||
};
|
||||
|
||||
// connections to link delay and distance
|
||||
connect(ui->P1Time, &SIUnitEdit::valueChanged, [=](double newval) {
|
||||
ui->P1Distance->setValueQuiet(newval * ui->P1Velocity->value() * c);
|
||||
updateValuesFromUI();
|
||||
});
|
||||
connect(ui->P1Distance, &SIUnitEdit::valueChanged, [=](double newval) {
|
||||
ui->P1Time->setValueQuiet(newval / (ui->P1Velocity->value() * c));
|
||||
updateValuesFromUI();
|
||||
});
|
||||
connect(ui->P1Velocity, &SIUnitEdit::valueChanged, [=](double newval) {
|
||||
ui->P1Time->setValueQuiet(ui->P1Distance->value() / (newval * c));
|
||||
updateValuesFromUI();
|
||||
});
|
||||
connect(ui->P1DCloss, &SIUnitEdit::valueChanged, updateValuesFromUI);
|
||||
connect(ui->P1Loss, &SIUnitEdit::valueChanged, updateValuesFromUI);
|
||||
connect(ui->P1Frequency, &SIUnitEdit::valueChanged, updateValuesFromUI);
|
||||
connect(ui->P1short, &QPushButton::pressed, [=](){
|
||||
isOpen = false;
|
||||
isPort1 = true;
|
||||
|
|
@ -241,13 +260,19 @@ void PortExtension::edit()
|
|||
|
||||
connect(ui->P2Time, &SIUnitEdit::valueChanged, [=](double newval) {
|
||||
ui->P2Distance->setValueQuiet(newval * ui->P2Velocity->value() * c);
|
||||
updateValuesFromUI();
|
||||
});
|
||||
connect(ui->P2Distance, &SIUnitEdit::valueChanged, [=](double newval) {
|
||||
ui->P2Time->setValueQuiet(newval / (ui->P2Velocity->value() * c));
|
||||
updateValuesFromUI();
|
||||
});
|
||||
connect(ui->P2Velocity, &SIUnitEdit::valueChanged, [=](double newval) {
|
||||
ui->P2Time->setValueQuiet(ui->P2Distance->value() / (newval * c));
|
||||
updateValuesFromUI();
|
||||
});
|
||||
connect(ui->P2DCloss, &SIUnitEdit::valueChanged, updateValuesFromUI);
|
||||
connect(ui->P2Loss, &SIUnitEdit::valueChanged, updateValuesFromUI);
|
||||
connect(ui->P2Frequency, &SIUnitEdit::valueChanged, updateValuesFromUI);
|
||||
connect(ui->P2short, &QPushButton::pressed, [=](){
|
||||
isOpen = false;
|
||||
isPort1 = false;
|
||||
|
|
@ -261,19 +286,7 @@ void PortExtension::edit()
|
|||
startMeasurement();
|
||||
});
|
||||
|
||||
connect(ui->buttonBox, &QDialogButtonBox::accepted, [=](){
|
||||
port1.delay = ui->P1Time->value();
|
||||
port1.velocityFactor = ui->P1Velocity->value();
|
||||
port1.DCloss = ui->P1DCloss->value();
|
||||
port1.loss = ui->P1Loss->value();
|
||||
port1.frequency = ui->P1Frequency->value();
|
||||
port2.delay = ui->P2Time->value();
|
||||
port2.velocityFactor = ui->P2Velocity->value();
|
||||
port2.DCloss = ui->P2DCloss->value();
|
||||
port2.loss = ui->P2Loss->value();
|
||||
port2.frequency = ui->P2Frequency->value();
|
||||
dialog->accept();
|
||||
});
|
||||
connect(ui->buttonBox, &QDialogButtonBox::accepted, dialog, &QDialog::accept);
|
||||
connect(ui->buttonBox, &QDialogButtonBox::rejected, dialog, &QDialog::reject);
|
||||
dialog->show();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue