Replace QDoubleValidator with QRegularExpressionValidator on width/height/depth fields

The selection properties dock (elementinfopartwidget.cpp) and the
element editor's information tree (elementpropertieseditorwidget.cpp's
EditorDelegate) both restrict the width/height/depth fields added for
cabinet layout support to numeric input via a validator.

QDoubleValidator follows the system/UI locale for its decimal
separator, which meant a comma was accepted as an intermediate state
and left the field impossible to leave in some contexts, even though
it was never a valid final value.

Switch both to a QRegularExpressionValidator matching
^[0-9]*\.?[0-9]{0,4}$: "." is a literal character in the pattern, not
locale-dependent, and [0-9] (rather than \d) excludes non-ASCII
digits. This guarantees a value entered this way can always be read
back with QString::toDouble() without locale handling. The check for
which keys are numeric (QETInformation::isNumericInfoKey) is shared
between both call sites; the validator setup itself stays local to
each, since QETInformation intentionally has no Qt Widgets dependency.

Also adds a placeholder ("ex. 80.5") and tooltip explaining the
expected format.
This commit is contained in:
Levi Jetzer
2026-08-11 18:01:10 +02:00
parent c23999acd1
commit 7347322221
2 changed files with 16 additions and 7 deletions
+11
View File
@@ -18,7 +18,9 @@
#include "elementinfopartwidget.h"
#include "../SearchAndReplace/searchandreplaceworker.h"
#include "../qetinformation.h"
#include "ui_elementinfopartwidget.h"
#include <QRegularExpressionValidator>
#include <utility>
@@ -43,6 +45,15 @@ ElementInfoPartWidget::ElementInfoPartWidget(
ui->label_->setText(translated_key);
ui->m_erase_text->setVisible(false);
if (key == QETInformation::ELMT_WIDTH || key == QETInformation::ELMT_HEIGHT || key == QETInformation::ELMT_DEPTH)
{
auto *validator = new QRegularExpressionValidator(
QRegularExpression(QStringLiteral(R"(^[0-9]*\.?[0-9]{0,4}$)")), ui->line_edit);
ui->line_edit->setValidator(validator);
ui->line_edit->setPlaceholderText(tr("ex. 80.5"));
ui->line_edit->setToolTip(tr("Nombre décimal avec un point comme séparateur (ex. 80.5)"));
}
connect(ui->line_edit, &QLineEdit::textEdited,
this, &ElementInfoPartWidget::textEdited);
connect(ui->line_edit, &QLineEdit::textChanged,