Fix numeric field validation gaps found in review

Address feedback on the width/height/depth elementInformation fields:

- The regex accepted "." alone as a complete value ([0-9]* permits
  zero digits on both sides), meaning a field could be committed with
  a literal "." saved to the XML. Require at least one digit either
  before or after the separator.
- The same pattern was duplicated verbatim in elementinfopartwidget.cpp
  and elementpropertieseditorwidget.cpp's EditorDelegate. Factored into
  QETInformation::numericInfoPattern(), a single shared definition both
  call sites now use.
- Tightened the pattern to at most 2 decimal places (down from 4) to
  match the precision actually meaningful for these fields.

Not changed, by design:
- Storage stays a plain string, consistent with every other numeric
  elementInformation field (quantity etc.) in this codebase -- values
  round-trip through XML text regardless, so a long/micron
  representation wouldn't avoid the string<->number conversion, only
  relocate it.
- No decimal-comma normalization needed: with the fixed pattern, only
  digits and "." are ever accepted at the keystroke level, so an
  alternate separator can't enter the field in the first place.
This commit is contained in:
Levi Jetzer
2026-08-12 08:43:42 +02:00
parent c6e7c5d371
commit 5dbb9f28de
4 changed files with 23 additions and 7 deletions
@@ -70,7 +70,7 @@ class EditorDelegate : public QItemDelegate
{
auto *line_edit = new QLineEdit(parent);
auto *validator = new QRegularExpressionValidator(
QRegularExpression(QStringLiteral(R"(^[0-9]*\.?[0-9]{0,4}$)")), line_edit);
QETInformation::numericInfoPattern(), line_edit);
line_edit->setValidator(validator);
line_edit->setPlaceholderText(tr("ex. 80.5"));
line_edit->setToolTip(tr("Nombre décimal avec un point comme séparateur (ex. 80.5)"));