/tests/testapplications/elements/content/RegExpValidatorElement.qml

https://gitlab.com/f3822/qtdeclarative · QML · 102 lines · 66 code · 9 blank · 27 comment · 6 complexity · c2bee8777890bf52182636f7eeada9c5 MD5 · raw file

  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2016 The Qt Company Ltd.
  4. ** Contact: https://www.qt.io/licensing/
  5. **
  6. ** This file is part of the test suite of the Qt Toolkit.
  7. **
  8. ** $QT_BEGIN_LICENSE:GPL-EXCEPT$
  9. ** Commercial License Usage
  10. ** Licensees holding valid commercial Qt licenses may use this file in
  11. ** accordance with the commercial license agreement provided with the
  12. ** Software or, alternatively, in accordance with the terms contained in
  13. ** a written agreement between you and The Qt Company. For licensing terms
  14. ** and conditions see https://www.qt.io/terms-conditions. For further
  15. ** information use the contact form at https://www.qt.io/contact-us.
  16. **
  17. ** GNU General Public License Usage
  18. ** Alternatively, this file may be used under the terms of the GNU
  19. ** General Public License version 3 as published by the Free Software
  20. ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
  21. ** included in the packaging of this file. Please review the following
  22. ** information to ensure the GNU General Public License requirements will
  23. ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
  24. **
  25. ** $QT_END_LICENSE$
  26. **
  27. ****************************************************************************/
  28. import QtQuick 2.14
  29. Item {
  30. id: regexpvalidatorelementtest
  31. anchors.fill: parent
  32. property string testtext: ""
  33. property variant regexp: /[a-z]{3}/
  34. RegularExpressionValidator { id: regexpvalidatorelement; regularExpression: regexp }
  35. Rectangle {
  36. id: regexpvalidatorelementbackground
  37. color: regexpvalidatorelementinput.acceptableInput ? "green" : "red"; height: 50; width: parent.width *.8
  38. border.color: "gray"; opacity: 0.7; radius: 5
  39. anchors.horizontalCenter: parent.horizontalCenter
  40. anchors.bottom: parent.bottom
  41. anchors.bottomMargin: 15
  42. TextInput {
  43. id: regexpvalidatorelementinput
  44. font.pointSize: 12; width: parent.width; text: "0"; horizontalAlignment: Text.AlignHCenter; validator: regexpvalidatorelement
  45. anchors.centerIn: parent
  46. Behavior on font.pointSize { NumberAnimation { duration: 1000 } }
  47. Behavior on color { ColorAnimation { duration: 1000 } }
  48. }
  49. }
  50. Text{
  51. anchors.top: regexpvalidatorelementbackground.bottom; anchors.topMargin: 50; anchors.horizontalCenter: parent.horizontalCenter
  52. text: "Regular Expression: " + regexp
  53. }
  54. SystemTestHelp { id: helpbubble; visible: statenum != 0
  55. anchors { top: parent.top; horizontalCenter: parent.horizontalCenter; topMargin: 50 }
  56. }
  57. BugPanel { id: bugpanel }
  58. states: [
  59. State { name: "start"; when: statenum == 1
  60. PropertyChanges { target: regexpvalidatorelementinput; text: "abc" }
  61. PropertyChanges { target: regexpvalidatorelementtest
  62. testtext: "This is a TextInput element using an RegularExpressionValidator for input masking. At present it should be indicating abc.\n"+
  63. "The regularExpression value will only match to a value that has three alpha characters\n"+
  64. "Next, let's attempt to enter text that does not match the regular expression: 123" }
  65. },
  66. State { name: "notmatch"; when: statenum == 2
  67. PropertyChanges { target: regexpvalidatorelementinput; text: "123" }
  68. PropertyChanges { target: regexpvalidatorelementtest
  69. testtext: "The TextInput background should be showing red - input is not acceptable.\n"+
  70. "Next, let's enter a word with not enough characters to match: aa." }
  71. },
  72. State { name: "notenough"; when: statenum == 3
  73. PropertyChanges { target: regexpvalidatorelementinput; text: "aa" }
  74. PropertyChanges { target: regexpvalidatorelementtest
  75. testtext: "The TextInput background should be showing red - input is not acceptable.\n"+
  76. "Next, let's attempt to enter a word with too many characters to match: abcd" }
  77. },
  78. State { name: "toomany"; when: statenum == 4
  79. PropertyChanges { target: regexpvalidatorelementinput; text: "abcd" }
  80. PropertyChanges { target: regexpvalidatorelementtest
  81. testtext: "The TextInput background should still be showing red - input is not acceptable.\n"+
  82. "Next, let's change the regex to accept the new value." }
  83. },
  84. State { name: "changedregex"; when: statenum == 5
  85. PropertyChanges { target: regexpvalidatorelementinput; text: "abcd" }
  86. PropertyChanges { target: regexpvalidatorelementtest; regexp: /[a-z]{4}/
  87. testtext: "The regular expression should have changed to match four characters, "+
  88. "thus making the text valid and turning the input background green.\n"+
  89. "Press advance to restart the test." }
  90. PropertyChanges { target: bugpanel; bugnumber: "19956" }
  91. }
  92. ]
  93. }