diff --git a/sources/editor/ui/elementpropertieseditorwidget.cpp b/sources/editor/ui/elementpropertieseditorwidget.cpp index e04b0bc01..e63f8338f 100644 --- a/sources/editor/ui/elementpropertieseditorwidget.cpp +++ b/sources/editor/ui/elementpropertieseditorwidget.cpp @@ -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)")); diff --git a/sources/qetinformation.cpp b/sources/qetinformation.cpp index d5df1cea1..d6c2f769b 100644 --- a/sources/qetinformation.cpp +++ b/sources/qetinformation.cpp @@ -216,6 +216,18 @@ QString QETInformation::elementInfoToVar(const QString &info) return (QString ("%{void}")); } +/** + * @brief QETInformation::numericInfoPattern + * @return the pattern used to validate numeric elementInformation + * fields (currently width/height/depth): digits with an optional "." + * as decimal separator, requiring at least one digit overall so a + * lone "." can never be a complete, acceptable value on its own. + */ +QRegularExpression QETInformation::numericInfoPattern() +{ + return QRegularExpression(QStringLiteral(R"(^[0-9]+\.?[0-9]{0,2}$|^[0-9]*\.[0-9]{1,2}$)")); +} + /** * @brief QETInformation::infoToVar * @param info diff --git a/sources/qetinformation.h b/sources/qetinformation.h index 569d9021b..492258b17 100644 --- a/sources/qetinformation.h +++ b/sources/qetinformation.h @@ -18,17 +18,19 @@ #ifndef QETINFORMATION_H #define QETINFORMATION_H -#include #include +#include +#include /** * Inside this namespace you will find all information used in QElectrotech for * element, conductor and diagram. * Each information have 3 values : - * #1 the info key = the key of an information as a QString used in the code (example : label) - * #2 the info key to variable = the key in form of a variable. - * This is used by the user to replace a variable by the string of this variable (example : %{label}) - * #3 the info key translated to the current local (example label in dutch = Betriebsmittelkennzeichen) + * #1 the info key = the key of an information as a QString used in the code + * (example : label) #2 the info key to variable = the key in form of a + * variable. This is used by the user to replace a variable by the string of + * this variable (example : %{label}) #3 the info key translated to the current + * local (example label in dutch = Betriebsmittelkennzeichen) */ namespace QETInformation { @@ -158,6 +160,8 @@ namespace QETInformation QStringList elementEditorElementInfoKeys(); QString elementInfoToVar(const QString &info); + QRegularExpression numericInfoPattern(); + QStringList terminalElementInfoKeys(); QString infoToVar(const QString &info); diff --git a/sources/ui/elementinfopartwidget.cpp b/sources/ui/elementinfopartwidget.cpp index dcb5f6842..2c44e51bd 100644 --- a/sources/ui/elementinfopartwidget.cpp +++ b/sources/ui/elementinfopartwidget.cpp @@ -48,7 +48,7 @@ ElementInfoPartWidget::ElementInfoPartWidget( 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); + QETInformation::numericInfoPattern(), 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)"));