Merge pull request #10 from nbgsmk/master

Check some invalid conditions
This commit is contained in:
jankae 2020-11-23 12:21:20 +01:00 committed by GitHub
commit bcb47717b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 12 deletions

View file

@ -5,6 +5,7 @@
#include <QEvent>
#include <QKeyEvent>
#include <QDebug>
#include <QTimer>
SIUnitEdit::SIUnitEdit(QString unit, QString prefixes, int precision, QWidget *parent)
: QLineEdit(parent)
@ -83,6 +84,16 @@ bool SIUnitEdit::eventFilter(QObject *, QEvent *event)
} else if(event->type() == QEvent::FocusOut) {
parseNewValue(1.0);
emit focusLost();
} else if(event->type() == QEvent::FocusIn) {
// online found clumsy way to select all text when clicked!?!
// just selectAll() alone does _not_ work!
QTimer::singleShot(0, this, &QLineEdit::selectAll);
/*
* However, this widget does not loose focus when clicking on a smith chart from here
* At the same time, clicking on x-y plot does loose focus as expected
* This behaviour existed before this mod, but it was not obvious due to properties of placeholdertext
*/
}
return false;
}
@ -91,7 +102,8 @@ void SIUnitEdit::setValueQuiet(double value)
{
_value = value;
clear();
setPlaceholderText(Unit::ToString(value, unit, prefixes, precision));
setPlaceholderText(Unit::ToString(value, unit, prefixes, precision)); // didn't remove it because maybe needed elsewhere
setText(Unit::ToString(value, unit, prefixes, precision)); // because selectAll() only affects setText() (placeholder text is igonred)
}
void SIUnitEdit::parseNewValue(double factor)
@ -118,7 +130,7 @@ void SIUnitEdit::parseNewValue(double factor)
} else {
qWarning() << "SIUnit conversion failure:" << input;
}
clear();
// clear(); // removed due to funny behaviour when clicking repeatedly between start, center, span, stop, but without editing anything
}
}