mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-13 16:34:14 +02:00
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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user