diff options
-rw-r--r-- | doc/src/declarative/elements.qdoc | 1 | ||||
-rw-r--r-- | doc/src/declarative/qmlviewer.qdoc | 2 | ||||
-rw-r--r-- | src/declarative/graphicsitems/qmlgraphicstextinput.cpp | 21 | ||||
-rw-r--r-- | src/declarative/graphicsitems/qmlgraphicstextinput_p.h | 2 | ||||
-rw-r--r-- | src/declarative/qml/qmlengine.cpp | 19 | ||||
-rw-r--r-- | src/gui/widgets/qvalidator.h | 5 | ||||
-rw-r--r-- | tests/auto/declarative/qmlgraphicstextinput/tst_qmlgraphicstextinput.cpp | 95 |
7 files changed, 136 insertions, 9 deletions
diff --git a/doc/src/declarative/elements.qdoc b/doc/src/declarative/elements.qdoc index 81a6c96..cfbabf2 100644 --- a/doc/src/declarative/elements.qdoc +++ b/doc/src/declarative/elements.qdoc @@ -99,6 +99,7 @@ The following table lists the QML elements provided by the Qt Declarative module \o \l Connection \o \l Component \o \l Timer +\o \l QtObject \endlist \endtable diff --git a/doc/src/declarative/qmlviewer.qdoc b/doc/src/declarative/qmlviewer.qdoc index 6a107ce..a5cb671 100644 --- a/doc/src/declarative/qmlviewer.qdoc +++ b/doc/src/declarative/qmlviewer.qdoc @@ -84,7 +84,7 @@ To use this from within your QML file, import QmlViewer 1.0 and create a Screen object. This object has a property, orientation, which can be either - Screen.Lanscape or Screen.Portrait and which can be bound to in your + Screen.Landscape or Screen.Portrait and which can be bound to in your application. An example is below: \code diff --git a/src/declarative/graphicsitems/qmlgraphicstextinput.cpp b/src/declarative/graphicsitems/qmlgraphicstextinput.cpp index 427f9ff..6d79c7a 100644 --- a/src/declarative/graphicsitems/qmlgraphicstextinput.cpp +++ b/src/declarative/graphicsitems/qmlgraphicstextinput.cpp @@ -54,6 +54,8 @@ QT_BEGIN_NAMESPACE QML_DEFINE_TYPE(Qt,4,6,TextInput,QmlGraphicsTextInput); QML_DEFINE_NOCREATE_TYPE(QValidator); QML_DEFINE_TYPE(Qt,4,6,QIntValidator,QIntValidator); +QML_DEFINE_TYPE(Qt,4,6,QDoubleValidator,QDoubleValidator); +QML_DEFINE_TYPE(Qt,4,6,QRegExpValidator,QRegExpValidator); /*! \qmlclass TextInput QmlGraphicsTextInput @@ -437,6 +439,25 @@ void QmlGraphicsTextInput::setFocusOnPress(bool b) an acceptable or intermediate state. The accepted signal will only be sent if the text is in an acceptable state when enter is pressed. + Currently supported validators are QIntValidator, QDoubleValidator and + QRegExpValidator. For details, refer to their C++ documentation and remember + that all Q_PROPERTIES are accessible from Qml. A brief usage guide follows: + + QIntValidator and QDoubleValidator both are controllable through two properties, + top and bottom. The difference is that for QIntValidator the top and bottom properties + should be integers, and for QDoubleValidator they should be doubles. QRegExpValidator + has a single string property, regExp, which should be set to the regular expression to + be used for validation. An example of using validators is shown below, which allows + input of integers between 11 and 31 into the text input: + + \code + import Qt 4.6 + TextInput{ + validator: QIntValidator{bottom: 11; top: 31;} + focus: true + } + \endcode + \sa acceptableInput, inputMask */ QValidator* QmlGraphicsTextInput::validator() const diff --git a/src/declarative/graphicsitems/qmlgraphicstextinput_p.h b/src/declarative/graphicsitems/qmlgraphicstextinput_p.h index 56f16a5..68f28f8 100644 --- a/src/declarative/graphicsitems/qmlgraphicstextinput_p.h +++ b/src/declarative/graphicsitems/qmlgraphicstextinput_p.h @@ -220,6 +220,8 @@ QT_END_NAMESPACE QML_DECLARE_TYPE(QmlGraphicsTextInput) QML_DECLARE_TYPE(QValidator) QML_DECLARE_TYPE(QIntValidator) +QML_DECLARE_TYPE(QDoubleValidator) +QML_DECLARE_TYPE(QRegExpValidator) QT_END_HEADER diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index 5624da1..bb26d30 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -110,6 +110,25 @@ QT_BEGIN_NAMESPACE DEFINE_BOOL_CONFIG_OPTION(qmlImportTrace, QML_IMPORT_TRACE) QML_DEFINE_TYPE(Qt,4,6,QtObject,QObject) +/*! + \qmlclass QtObject QObject + \brief The QtObject element is the most basic element in QML + + The QtObject element is a non-visual element which contains only + the objectName property. It is useful for when you need an extremely + lightweight element to place your own custom properties in. + + It can also be useful for C++ integration, as it is just a plain QObject. See + the QObject documentation for further details. +*/ +/*! + \qmlproperty string QtObject::objectName + This property allows you to give a name to this specific object instance. + + See \l{scripting.html#accessing-child-qobjects}{Accessing Child QObjects} + in the scripting documentation for details how objectName can be used from + scripts. +*/ struct StaticQtMetaObject : public QObject { diff --git a/src/gui/widgets/qvalidator.h b/src/gui/widgets/qvalidator.h index e996a01..63734ca 100644 --- a/src/gui/widgets/qvalidator.h +++ b/src/gui/widgets/qvalidator.h @@ -137,10 +137,11 @@ class Q_GUI_EXPORT QDoubleValidator : public QValidator Q_PROPERTY(double bottom READ bottom WRITE setBottom) Q_PROPERTY(double top READ top WRITE setTop) Q_PROPERTY(int decimals READ decimals WRITE setDecimals) + Q_ENUMS(Notation) Q_PROPERTY(Notation notation READ notation WRITE setNotation) public: - explicit QDoubleValidator(QObject * parent); + explicit QDoubleValidator(QObject * parent = 0); QDoubleValidator(double bottom, double top, int decimals, QObject * parent); ~QDoubleValidator(); @@ -184,7 +185,7 @@ class Q_GUI_EXPORT QRegExpValidator : public QValidator Q_PROPERTY(QRegExp regExp READ regExp WRITE setRegExp) public: - explicit QRegExpValidator(QObject *parent); + explicit QRegExpValidator(QObject *parent = 0); QRegExpValidator(const QRegExp& rx, QObject *parent); ~QRegExpValidator(); diff --git a/tests/auto/declarative/qmlgraphicstextinput/tst_qmlgraphicstextinput.cpp b/tests/auto/declarative/qmlgraphicstextinput/tst_qmlgraphicstextinput.cpp index 7223ff9..7896464 100644 --- a/tests/auto/declarative/qmlgraphicstextinput/tst_qmlgraphicstextinput.cpp +++ b/tests/auto/declarative/qmlgraphicstextinput/tst_qmlgraphicstextinput.cpp @@ -397,13 +397,96 @@ void tst_qmlgraphicstextinput::masks() void tst_qmlgraphicstextinput::validators() { - QString componentStr = "import Qt 4.6\nTextInput { maximumLength: 10; }"; - QmlComponent textinputComponent(&engine); - textinputComponent.setData(componentStr.toLatin1(), QUrl()); - QmlGraphicsTextInput *textinputObject = qobject_cast<QmlGraphicsTextInput*>(textinputComponent.create()); - QVERIFY(textinputObject != 0); + // Note that this test assumes that the validators are working properly + // so you may need to run their tests first. All validators are checked + // here to ensure that their exposure to QML is working. + + QmlView *canvas = createView(SRCDIR "/data/validators.qml"); + canvas->execute(); + canvas->show(); + canvas->setFocus(); + + QVERIFY(canvas->root() != 0); - //TODO: Me + QmlGraphicsTextInput *intInput = qobject_cast<QmlGraphicsTextInput *>(qvariant_cast<QObject *>(canvas->root()->property("intInput"))); + QVERIFY(intInput); + intInput->setFocus(true); + QTRY_VERIFY(intInput->hasFocus()); + QTest::keyPress(canvas, Qt::Key_1); + QTest::keyRelease(canvas, Qt::Key_1, Qt::NoModifier ,10); + QCOMPARE(intInput->text(), QLatin1String("1")); + QCOMPARE(intInput->hasAcceptableInput(), false); + QTest::keyPress(canvas, Qt::Key_2); + QTest::keyRelease(canvas, Qt::Key_2, Qt::NoModifier ,10); + QCOMPARE(intInput->text(), QLatin1String("1")); + QCOMPARE(intInput->hasAcceptableInput(), false); + QTest::keyPress(canvas, Qt::Key_1); + QTest::keyRelease(canvas, Qt::Key_1, Qt::NoModifier ,10); + QCOMPARE(intInput->text(), QLatin1String("11")); + QCOMPARE(intInput->hasAcceptableInput(), true); + QTest::keyPress(canvas, Qt::Key_0); + QTest::keyRelease(canvas, Qt::Key_0, Qt::NoModifier ,10); + QCOMPARE(intInput->text(), QLatin1String("11")); + QCOMPARE(intInput->hasAcceptableInput(), true); + + QmlGraphicsTextInput *dblInput = qobject_cast<QmlGraphicsTextInput *>(qvariant_cast<QObject *>(canvas->root()->property("dblInput"))); + QTRY_VERIFY(dblInput); + dblInput->setFocus(true); + QVERIFY(dblInput->hasFocus() == true); + QTest::keyPress(canvas, Qt::Key_1); + QTest::keyRelease(canvas, Qt::Key_1, Qt::NoModifier ,10); + QCOMPARE(dblInput->text(), QLatin1String("1")); + QCOMPARE(dblInput->hasAcceptableInput(), false); + QTest::keyPress(canvas, Qt::Key_2); + QTest::keyRelease(canvas, Qt::Key_2, Qt::NoModifier ,10); + QCOMPARE(dblInput->text(), QLatin1String("12")); + QCOMPARE(dblInput->hasAcceptableInput(), true); + QTest::keyPress(canvas, Qt::Key_Period); + QTest::keyRelease(canvas, Qt::Key_Period, Qt::NoModifier ,10); + QCOMPARE(dblInput->text(), QLatin1String("12.")); + QCOMPARE(dblInput->hasAcceptableInput(), true); + QTest::keyPress(canvas, Qt::Key_1); + QTest::keyRelease(canvas, Qt::Key_1, Qt::NoModifier ,10); + QCOMPARE(dblInput->text(), QLatin1String("12.1")); + QCOMPARE(dblInput->hasAcceptableInput(), true); + QTest::keyPress(canvas, Qt::Key_1); + QTest::keyRelease(canvas, Qt::Key_1, Qt::NoModifier ,10); + QCOMPARE(dblInput->text(), QLatin1String("12.11")); + QCOMPARE(dblInput->hasAcceptableInput(), true); + QTest::keyPress(canvas, Qt::Key_1); + QTest::keyRelease(canvas, Qt::Key_1, Qt::NoModifier ,10); + QCOMPARE(dblInput->text(), QLatin1String("12.11")); + QCOMPARE(dblInput->hasAcceptableInput(), true); + + QmlGraphicsTextInput *strInput = qobject_cast<QmlGraphicsTextInput *>(qvariant_cast<QObject *>(canvas->root()->property("strInput"))); + QTRY_VERIFY(strInput); + strInput->setFocus(true); + QVERIFY(strInput->hasFocus() == true); + QTest::keyPress(canvas, Qt::Key_1); + QTest::keyRelease(canvas, Qt::Key_1, Qt::NoModifier ,10); + QEXPECT_FAIL("","Will not work until QTBUG-8025 is resolved", Abort); + QCOMPARE(strInput->text(), QLatin1String("")); + QCOMPARE(strInput->hasAcceptableInput(), false); + QTest::keyPress(canvas, Qt::Key_A); + QTest::keyRelease(canvas, Qt::Key_A, Qt::NoModifier ,10); + QCOMPARE(strInput->text(), QLatin1String("a")); + QCOMPARE(strInput->hasAcceptableInput(), false); + QTest::keyPress(canvas, Qt::Key_A); + QTest::keyRelease(canvas, Qt::Key_A, Qt::NoModifier ,10); + QCOMPARE(strInput->text(), QLatin1String("aa")); + QCOMPARE(strInput->hasAcceptableInput(), true); + QTest::keyPress(canvas, Qt::Key_A); + QTest::keyRelease(canvas, Qt::Key_A, Qt::NoModifier ,10); + QCOMPARE(strInput->text(), QLatin1String("aaa")); + QCOMPARE(strInput->hasAcceptableInput(), true); + QTest::keyPress(canvas, Qt::Key_A); + QTest::keyRelease(canvas, Qt::Key_A, Qt::NoModifier ,10); + QCOMPARE(strInput->text(), QLatin1String("aaaa")); + QCOMPARE(strInput->hasAcceptableInput(), true); + QTest::keyPress(canvas, Qt::Key_A); + QTest::keyRelease(canvas, Qt::Key_A, Qt::NoModifier ,10); + QCOMPARE(strInput->text(), QLatin1String("aaaa")); + QCOMPARE(strInput->hasAcceptableInput(), true); } /* |