From 73473222211d53e4e6c657393b25a9e50aa21c14 Mon Sep 17 00:00:00 2001 From: Levi Jetzer Date: Tue, 11 Aug 2026 18:01:10 +0200 Subject: [PATCH] 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. --- sources/editor/ui/elementpropertieseditorwidget.cpp | 12 +++++------- sources/ui/elementinfopartwidget.cpp | 11 +++++++++++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/sources/editor/ui/elementpropertieseditorwidget.cpp b/sources/editor/ui/elementpropertieseditorwidget.cpp index 01b4b6497..e04b0bc01 100644 --- a/sources/editor/ui/elementpropertieseditorwidget.cpp +++ b/sources/editor/ui/elementpropertieseditorwidget.cpp @@ -20,7 +20,6 @@ #include "../../qetapp.h" #include "../../qetinformation.h" #include "ui_elementpropertieseditorwidget.h" -#include "../../qetinformation.h" #include #include @@ -67,15 +66,14 @@ class EditorDelegate : public QItemDelegate const QString key = index.sibling(index.row(), 0) .data(Qt::UserRole).toString(); - if (key == QETInformation::ELMT_WIDTH || - key == QETInformation::ELMT_HEIGHT || - key == QETInformation::ELMT_DEPTH) + if (key == QETInformation::ELMT_WIDTH || key == QETInformation::ELMT_HEIGHT || key == QETInformation::ELMT_DEPTH) { auto *line_edit = new QLineEdit(parent); - auto *validator = new QDoubleValidator(0.0, 100000.0, 4, line_edit); - validator->setNotation(QDoubleValidator::StandardNotation); - validator->setLocale(QLocale::c()); + auto *validator = new QRegularExpressionValidator( + QRegularExpression(QStringLiteral(R"(^[0-9]*\.?[0-9]{0,4}$)")), 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)")); return line_edit; } diff --git a/sources/ui/elementinfopartwidget.cpp b/sources/ui/elementinfopartwidget.cpp index 08da68d63..0132de4ca 100644 --- a/sources/ui/elementinfopartwidget.cpp +++ b/sources/ui/elementinfopartwidget.cpp @@ -18,7 +18,9 @@ #include "elementinfopartwidget.h" #include "../SearchAndReplace/searchandreplaceworker.h" +#include "../qetinformation.h" #include "ui_elementinfopartwidget.h" +#include #include @@ -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,