mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-09-28 04:54:13 +02:00
Guard numeric elementInformation fields against "." and normalize decimal comma
- ElementInfoWidget::currentInfo() now skips a field whose validator hasn't accepted its text (e.g. a lone "." mid-typing), which previously stored and later parsed to 0. - New QETInformation::NumericInfoValidator rewrites "," to "." before validating, so 80,5 on a German/French keyboard no longer silently becomes 805. Used at both existing call sites. - Restored the header's #1/#2/#3 doc comment (was reflowed into a run-on paragraph by a previous edit).
This commit is contained in:
@@ -228,6 +228,33 @@ QRegularExpression QETInformation::numericInfoPattern()
|
||||
return QRegularExpression(QStringLiteral(R"(^[0-9]+\.?[0-9]{0,2}$|^[0-9]*\.[0-9]{1,2}$)"));
|
||||
}
|
||||
|
||||
/**
|
||||
@brief QETInformation::NumericInfoValidator::NumericInfoValidator
|
||||
@param parent
|
||||
*/
|
||||
QETInformation::NumericInfoValidator::NumericInfoValidator(QObject *parent) :
|
||||
QRegularExpressionValidator(numericInfoPattern(), parent)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
@brief QETInformation::NumericInfoValidator::validate
|
||||
Rewrites any "," in @a input to "." in place, then delegates to
|
||||
the base class for the actual numericInfoPattern() check. @a pos
|
||||
is left untouched by the rewrite itself -- replacing "," with "."
|
||||
never changes the string's length, so the cursor position the
|
||||
caller already tracked stays correct.
|
||||
@param input the text being validated; may be rewritten
|
||||
@param pos the cursor position within @a input
|
||||
@return the resulting validation state
|
||||
*/
|
||||
QValidator::State QETInformation::NumericInfoValidator::validate(QString &input, int &pos) const
|
||||
{
|
||||
if (input.contains(QLatin1Char(',')))
|
||||
input.replace(QLatin1Char(','), QLatin1Char('.'));
|
||||
return QRegularExpressionValidator::validate(input, pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief QETInformation::infoToVar
|
||||
* @param info
|
||||
|
||||
Reference in New Issue
Block a user