From 9c4716416e660b2ede59dab40553064e4d6b5c1e Mon Sep 17 00:00:00 2001 From: Joey de l'Arago Date: Thu, 1 Dec 2022 16:58:29 +0100 Subject: [PATCH] Add validators that match validators for SettingTextField. CURA-9793 --- resources/qml/Validators/DoubleValidator.qml | 15 --------------- resources/qml/Validators/FloatValidator.qml | 11 +++++++++++ resources/qml/Validators/IntListValidator.qml | 8 ++++++++ resources/qml/Validators/IntValidator.qml | 10 ++++++++++ 4 files changed, 29 insertions(+), 15 deletions(-) delete mode 100644 resources/qml/Validators/DoubleValidator.qml create mode 100644 resources/qml/Validators/FloatValidator.qml create mode 100644 resources/qml/Validators/IntListValidator.qml create mode 100644 resources/qml/Validators/IntValidator.qml diff --git a/resources/qml/Validators/DoubleValidator.qml b/resources/qml/Validators/DoubleValidator.qml deleted file mode 100644 index dc92dbd1ae..0000000000 --- a/resources/qml/Validators/DoubleValidator.qml +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2022 UltiMaker B.V. -// Cura is released under the terms of the LGPLv3 or higher. -import QtQuick 2.15 - -RegularExpressionValidator -{ - property int maxBeforeDecimal: 10 - property int maxAfterDecimal: 10 - - regularExpression: - { - // The build in DoubleValidator doesn't handle "," and "." interchangably. - return "^-?[0-9]{0," + maxBeforeDecimal + "}[.,]?[0-9]{0," + maxAfterDecimal + "}$" - } -} \ No newline at end of file diff --git a/resources/qml/Validators/FloatValidator.qml b/resources/qml/Validators/FloatValidator.qml new file mode 100644 index 0000000000..62ff981e2e --- /dev/null +++ b/resources/qml/Validators/FloatValidator.qml @@ -0,0 +1,11 @@ +// Copyright (c) 2022 UltiMaker B.V. +// Cura is released under the terms of the LGPLv3 or higher. +import QtQuick 2.15 + +RegularExpressionValidator +{ + property int maxBeforeDecimal: 11 + property int maxAfterDecimal: 3 + + regularExpression: new RegExp("^-?[0-9]{0,%0}[.,]?[0-9]{0,%1}$".arg(maxBeforeDecimal).arg(maxAfterDecimal)) +} \ No newline at end of file diff --git a/resources/qml/Validators/IntListValidator.qml b/resources/qml/Validators/IntListValidator.qml new file mode 100644 index 0000000000..2f5b3c829a --- /dev/null +++ b/resources/qml/Validators/IntListValidator.qml @@ -0,0 +1,8 @@ +// Copyright (c) 2022 UltiMaker B.V. +// Cura is released under the terms of the LGPLv3 or higher. +import QtQuick 2.15 + +RegularExpressionValidator +{ + regularExpression: new RegExp("^\[?(\s*-?[0-9]{0,11}\s*,)*(\s*-?[0-9]{0,11})\s*\]?$") +} \ No newline at end of file diff --git a/resources/qml/Validators/IntValidator.qml b/resources/qml/Validators/IntValidator.qml new file mode 100644 index 0000000000..6b7ced9ce8 --- /dev/null +++ b/resources/qml/Validators/IntValidator.qml @@ -0,0 +1,10 @@ +// Copyright (c) 2022 UltiMaker B.V. +// Cura is released under the terms of the LGPLv3 or higher. +import QtQuick 2.15 + +RegularExpressionValidator +{ + property int maxNumbers: 12 + + regularExpression: new RegExp("^-?[0-9]{0,%0}$".arg(maxNumbers)) +} \ No newline at end of file