mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-01 15:24: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:
@@ -47,8 +47,7 @@ ElementInfoPartWidget::ElementInfoPartWidget(
|
||||
|
||||
if (key_ == QETInformation::ELMT_WIDTH || key_ == QETInformation::ELMT_HEIGHT || key_ == QETInformation::ELMT_DEPTH)
|
||||
{
|
||||
auto *validator = new QRegularExpressionValidator(
|
||||
QETInformation::numericInfoPattern(), ui->line_edit);
|
||||
auto *validator = new QETInformation::NumericInfoValidator(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)"));
|
||||
@@ -78,6 +77,15 @@ QString ElementInfoPartWidget::text() const
|
||||
return (ui->line_edit->text());
|
||||
}
|
||||
|
||||
/**
|
||||
@brief ElementInfoPartWidget::hasAcceptableInput
|
||||
@return whether the line edit's current text satisfies its validator
|
||||
*/
|
||||
bool ElementInfoPartWidget::hasAcceptableInput() const
|
||||
{
|
||||
return ui->line_edit->hasAcceptableInput();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief ElementInfoPartWidget::setText
|
||||
Set text to line edit
|
||||
|
||||
@@ -41,9 +41,9 @@ class ElementInfoPartWidget : public QWidget
|
||||
QWidget *parent = nullptr);
|
||||
~ElementInfoPartWidget() override;
|
||||
|
||||
QString key () const
|
||||
{return key_;}
|
||||
QString key () const {return key_;}
|
||||
QString text () const;
|
||||
bool hasAcceptableInput() const;
|
||||
void setText (const QString &);
|
||||
void setPlaceHolderText (const QString &text);
|
||||
void setFocusTolineEdit();
|
||||
|
||||
@@ -387,6 +387,9 @@ DiagramContext ElementInfoWidget::currentInfo() const
|
||||
|
||||
for (const auto &eipw : std::as_const(m_eipw_list))
|
||||
{
|
||||
if (!eipw->hasAcceptableInput())
|
||||
continue;
|
||||
|
||||
//add value only if they're something to store
|
||||
if (!eipw->text().isEmpty())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user