Better X axis ticks in manual mode, minor cleanup for siunitedit
This commit is contained in:
parent
af8787915c
commit
fe78ccdeeb
@ -16,7 +16,6 @@ SIUnitEdit::SIUnitEdit(QString unit, QString prefixes, int precision, QWidget *p
|
|||||||
this->precision = precision;
|
this->precision = precision;
|
||||||
setAlignment(Qt::AlignCenter);
|
setAlignment(Qt::AlignCenter);
|
||||||
installEventFilter(this);
|
installEventFilter(this);
|
||||||
setValidator(new QDoubleValidator(this));
|
|
||||||
connect(this, &QLineEdit::editingFinished, [this]() {
|
connect(this, &QLineEdit::editingFinished, [this]() {
|
||||||
parseNewValue(1.0);
|
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
|
// most mousewheel have 15 degree increments, the reported delta is in 1/8th degree -> 120
|
||||||
auto increment = wheel->angleDelta().y() / 120.0;
|
auto increment = wheel->angleDelta().y() / 120.0;
|
||||||
// round toward bigger step in case of special higher resolution mousewheel
|
// 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;
|
int sign = increment > 0 ? 1 : -1;
|
||||||
// figure out step increment
|
// figure out step increment
|
||||||
auto newVal = _value;
|
auto newVal = _value;
|
||||||
while(steps > 0) {
|
while(steps > 0) {
|
||||||
// do update in multiple steps because the step size could change inbetween
|
// do update in multiple steps because the step size could change inbetween
|
||||||
constexpr int nthDigit = 3;
|
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;
|
newVal += step_size * sign;
|
||||||
steps--;
|
steps--;
|
||||||
}
|
}
|
||||||
|
@ -237,7 +237,11 @@ void TraceXYPlot::draw(QPainter &p)
|
|||||||
// draw X ticks
|
// draw X ticks
|
||||||
// this only works for evenly distributed ticks:
|
// this only works for evenly distributed ticks:
|
||||||
auto max = qMax(abs(XAxis.ticks.front()), abs(XAxis.ticks.back()));
|
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]);
|
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;
|
int significantDigits = floor(log10(max)) - floor(log10(step)) + 1;
|
||||||
bool displayFullFreq = significantDigits <= 5;
|
bool displayFullFreq = significantDigits <= 5;
|
||||||
constexpr int displayLastDigits = 4;
|
constexpr int displayLastDigits = 4;
|
||||||
|
Loading…
Reference in New Issue
Block a user