From fe78ccdeeb1c06fab4739c8b86f4f1c50a57075c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20K=C3=A4berich?= Date: Sun, 29 Nov 2020 18:06:58 +0100 Subject: [PATCH] Better X axis ticks in manual mode, minor cleanup for siunitedit --- Software/PC_Application/CustomWidgets/siunitedit.cpp | 5 ++--- Software/PC_Application/Traces/tracexyplot.cpp | 4 ++++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Software/PC_Application/CustomWidgets/siunitedit.cpp b/Software/PC_Application/CustomWidgets/siunitedit.cpp index 4705934..5e95822 100644 --- a/Software/PC_Application/CustomWidgets/siunitedit.cpp +++ b/Software/PC_Application/CustomWidgets/siunitedit.cpp @@ -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,14 +97,14 @@ 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 constexpr int nthDigit = 3; - auto step_size = pow(10, floor(log10(abs(newVal))) - nthDigit + 1); + auto step_size = pow(10, floor(log10(std::abs(newVal))) - nthDigit + 1); newVal += step_size * sign; steps--; } diff --git a/Software/PC_Application/Traces/tracexyplot.cpp b/Software/PC_Application/Traces/tracexyplot.cpp index a62772c..6cd7cb1 100644 --- a/Software/PC_Application/Traces/tracexyplot.cpp +++ b/Software/PC_Application/Traces/tracexyplot.cpp @@ -237,7 +237,11 @@ void TraceXYPlot::draw(QPainter &p) // 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())); auto step = abs(XAxis.ticks[0] - XAxis.ticks[1]); + if(minLabel > 0 && minLabel < step) { + step = minLabel; + } int significantDigits = floor(log10(max)) - floor(log10(step)) + 1; bool displayFullFreq = significantDigits <= 5; constexpr int displayLastDigits = 4;