Просмотр исходного кода

Add validators to project.

CURA-9793
Joey de l'Arago 2 лет назад
Родитель
Сommit
487bf41a7b

+ 1 - 1
resources/qml/ColorDialog.qml

@@ -119,7 +119,7 @@ UM.Dialog
                         text = `#${text}`;
                     }
                 }
-                validator: RegularExpressionValidator { regularExpression: /^#([a-fA-F0-9]{0,6})$/ }
+                validator: Cura.HexColorValidator {}
             }
 
             Rectangle

+ 15 - 0
resources/qml/Validators/DoubleValidator.qml

@@ -0,0 +1,15 @@
+// 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 + "}$"
+    }
+}

+ 8 - 0
resources/qml/Validators/HexColorValidator.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: /^#([a-fA-F0-9]{0,6})$/
+}

+ 4 - 0
resources/qml/qmldir

@@ -19,6 +19,9 @@ SettingView 1.0 SettingView.qml
 ProfileMenu 1.0 ProfileMenu.qml
 PrintSelectorCard 1.0 PrintSelectorCard.qml
 
+# Cura/Validators
+DoubleValidator             1.7 DoubleValidator.qml
+HexColorValidator           1.7 HexColorValidator.qml
 
 # Cura/WelcomePages
 
@@ -42,6 +45,7 @@ SingleSettingExtruderSelectorBar        1.7 SingleSettingExtruderSelectorBar.qml
 ExtruderButton                          1.7 ExtruderButton.qml
 SingleSettingComboBox                   1.7 SingleSettingComboBox.qml
 SingleSettingSlider                     1.7 SingleSettingSlider.qml
+SingleSettingTextFieldWithUnit          1.7 SingleSettingTextFieldWithUnit.qml
 
 
 # Cura/MachineSettings