Better X axis ticks in manual mode, minor cleanup for siunitedit

This commit is contained in:
Jan Käberich 2020-11-29 18:06:58 +01:00
parent af8787915c
commit fe78ccdeeb
2 changed files with 6 additions and 3 deletions

View File

@ -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--;
}

View File

@ -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;