diff options
Diffstat (limited to 'src/declarative')
-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/parser/qmljsglobal_p.h | 4 | ||||
-rw-r--r-- | src/declarative/qml/parser/qmljsgrammar_p.h | 2 | ||||
-rw-r--r-- | src/declarative/qml/qmlengine.cpp | 19 | ||||
-rw-r--r-- | src/declarative/qml/qmlxmlhttprequest.cpp | 90 | ||||
-rw-r--r-- | src/declarative/util/qmlopenmetaobject.cpp | 17 | ||||
-rw-r--r-- | src/declarative/util/qmlopenmetaobject_p.h | 7 |
8 files changed, 113 insertions, 49 deletions
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/parser/qmljsglobal_p.h b/src/declarative/qml/parser/qmljsglobal_p.h index 59762ff..49e50cf 100644 --- a/src/declarative/qml/parser/qmljsglobal_p.h +++ b/src/declarative/qml/parser/qmljsglobal_p.h @@ -47,13 +47,13 @@ # define QT_QML_BEGIN_NAMESPACE # define QT_QML_END_NAMESPACE -# ifdef QML_BUILD_LIB +# ifdef QMLJS_BUILD_DIR # define QML_PARSER_EXPORT Q_DECL_EXPORT # elif QML_BUILD_STATIC_LIB # define QML_PARSER_EXPORT # else # define QML_PARSER_EXPORT Q_DECL_IMPORT -# endif // QML_BUILD_LIB +# endif // QMLJS_BUILD_DIR #else // !QT_CREATOR # define QT_QML_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE diff --git a/src/declarative/qml/parser/qmljsgrammar_p.h b/src/declarative/qml/parser/qmljsgrammar_p.h index 903e2c4..c2e2693 100644 --- a/src/declarative/qml/parser/qmljsgrammar_p.h +++ b/src/declarative/qml/parser/qmljsgrammar_p.h @@ -61,7 +61,7 @@ QT_BEGIN_NAMESPACE class QmlJSGrammar { public: - enum { + enum VariousConstants { EOF_SYMBOL = 0, REDUCE_HERE = 99, SHIFT_THERE = 98, 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/declarative/qml/qmlxmlhttprequest.cpp b/src/declarative/qml/qmlxmlhttprequest.cpp index 86bec20..1883d1b 100644 --- a/src/declarative/qml/qmlxmlhttprequest.cpp +++ b/src/declarative/qml/qmlxmlhttprequest.cpp @@ -943,21 +943,19 @@ public: QmlXMLHttpRequest(QNetworkAccessManager *manager); virtual ~QmlXMLHttpRequest(); - QScriptValue callback() const; - void setCallback(const QScriptValue &); - bool sendFlag() const; bool errorFlag() const; quint32 readyState() const; int replyStatus() const; QString replyStatusText() const; - QScriptValue open(const QString &, const QUrl &); + QScriptValue open(QScriptValue *me, const QString &, const QUrl &); + void addHeader(const QString &, const QString &); QString header(const QString &name); QString headers(); - QScriptValue send(const QByteArray &); - QScriptValue abort(); + QScriptValue send(QScriptValue *me, const QByteArray &); + QScriptValue abort(QScriptValue *me); QString responseBody() const; private slots: @@ -982,8 +980,9 @@ private: HeadersList m_headersList; void fillHeadersList(); - QScriptValue dispatchCallback(); - QScriptValue m_callback; + QScriptValue m_me; // Set to the data object while a send() is ongoing (to access the callback) + + QScriptValue dispatchCallback(QScriptValue *me); void printError(const QScriptValue&); int m_status; @@ -1007,16 +1006,6 @@ QmlXMLHttpRequest::~QmlXMLHttpRequest() destroyNetwork(); } -QScriptValue QmlXMLHttpRequest::callback() const -{ - return m_callback; -} - -void QmlXMLHttpRequest::setCallback(const QScriptValue &c) -{ - m_callback = c; -} - bool QmlXMLHttpRequest::sendFlag() const { return m_sendFlag; @@ -1042,7 +1031,7 @@ QString QmlXMLHttpRequest::replyStatusText() const return m_statusText; } -QScriptValue QmlXMLHttpRequest::open(const QString &method, const QUrl &url) +QScriptValue QmlXMLHttpRequest::open(QScriptValue *me, const QString &method, const QUrl &url) { destroyNetwork(); m_sendFlag = false; @@ -1051,7 +1040,7 @@ QScriptValue QmlXMLHttpRequest::open(const QString &method, const QUrl &url) m_method = method; m_url = url; m_state = Opened; - return dispatchCallback(); + return dispatchCallback(me); } void QmlXMLHttpRequest::addHeader(const QString &name, const QString &value) @@ -1155,19 +1144,20 @@ void QmlXMLHttpRequest::requestFromUrl(const QUrl &url) this, SLOT(finished())); } -QScriptValue QmlXMLHttpRequest::send(const QByteArray &data) +QScriptValue QmlXMLHttpRequest::send(QScriptValue *me, const QByteArray &data) { m_errorFlag = false; m_sendFlag = true; m_redirectCount = 0; m_data = data; + m_me = *me; requestFromUrl(m_url); return QScriptValue(); } -QScriptValue QmlXMLHttpRequest::abort() +QScriptValue QmlXMLHttpRequest::abort(QScriptValue *me) { destroyNetwork(); m_responseEntityBody = QByteArray(); @@ -1180,7 +1170,7 @@ QScriptValue QmlXMLHttpRequest::abort() m_state = Done; m_sendFlag = false; - QScriptValue cbv = dispatchCallback(); + QScriptValue cbv = dispatchCallback(me); if (cbv.isError()) return cbv; } @@ -1200,7 +1190,7 @@ void QmlXMLHttpRequest::downloadProgress(qint64 bytes) if (m_state < HeadersReceived) { m_state = HeadersReceived; fillHeadersList (); - QScriptValue cbv = dispatchCallback(); + QScriptValue cbv = dispatchCallback(&m_me); if (cbv.isError()) printError(cbv); } @@ -1208,7 +1198,7 @@ void QmlXMLHttpRequest::downloadProgress(qint64 bytes) m_responseEntityBody.append(m_network->readAll()); if (wasEmpty && !m_responseEntityBody.isEmpty()) { m_state = Loading; - QScriptValue cbv = dispatchCallback(); + QScriptValue cbv = dispatchCallback(&m_me); if (cbv.isError()) printError(cbv); } } @@ -1233,14 +1223,14 @@ void QmlXMLHttpRequest::error(QNetworkReply::NetworkError error) error == QNetworkReply::AuthenticationRequiredError || error == QNetworkReply::ContentReSendError) { m_state = Loading; - QScriptValue cbv = dispatchCallback(); + QScriptValue cbv = dispatchCallback(&m_me); if (cbv.isError()) printError(cbv); } else { m_errorFlag = true; } m_state = Done; - QScriptValue cbv = dispatchCallback(); + QScriptValue cbv = dispatchCallback(&m_me); if (cbv.isError()) printError(cbv); } @@ -1266,7 +1256,7 @@ void QmlXMLHttpRequest::finished() if (m_state < HeadersReceived) { m_state = HeadersReceived; fillHeadersList (); - QScriptValue cbv = dispatchCallback(); + QScriptValue cbv = dispatchCallback(&m_me); if (cbv.isError()) printError(cbv); } m_responseEntityBody.append(m_network->readAll()); @@ -1274,12 +1264,14 @@ void QmlXMLHttpRequest::finished() destroyNetwork(); if (m_state < Loading) { m_state = Loading; - QScriptValue cbv = dispatchCallback(); + QScriptValue cbv = dispatchCallback(&m_me); if (cbv.isError()) printError(cbv); } m_state = Done; - QScriptValue cbv = dispatchCallback(); + QScriptValue cbv = dispatchCallback(&m_me); if (cbv.isError()) printError(cbv); + + m_me = QScriptValue(); } @@ -1288,9 +1280,10 @@ QString QmlXMLHttpRequest::responseBody() const return QString::fromUtf8(m_responseEntityBody); } -QScriptValue QmlXMLHttpRequest::dispatchCallback() +QScriptValue QmlXMLHttpRequest::dispatchCallback(QScriptValue *me) { - return m_callback.call(); + QScriptValue v = me->property(QLatin1String("callback")); + return v.call(); } void QmlXMLHttpRequest::printError(const QScriptValue& sv) @@ -1312,7 +1305,8 @@ void QmlXMLHttpRequest::destroyNetwork() // XMLHttpRequest methods static QScriptValue qmlxmlhttprequest_open(QScriptContext *context, QScriptEngine *engine) { - QmlXMLHttpRequest *request = qobject_cast<QmlXMLHttpRequest *>(context->thisObject().data().toQObject()); + QScriptValue dataObject = context->thisObject().data(); + QmlXMLHttpRequest *request = qobject_cast<QmlXMLHttpRequest *>(dataObject.toQObject()); if (!request) THROW_REFERENCE("Not an XMLHttpRequest object"); @@ -1354,7 +1348,7 @@ static QScriptValue qmlxmlhttprequest_open(QScriptContext *context, QScriptEngin if (!username.isNull()) url.setUserName(username); if (!password.isNull()) url.setPassword(password); - return request->open(method, url); + return request->open(&dataObject, method, url); } static QScriptValue qmlxmlhttprequest_setRequestHeader(QScriptContext *context, QScriptEngine *engine) @@ -1405,9 +1399,10 @@ static QScriptValue qmlxmlhttprequest_setRequestHeader(QScriptContext *context, return engine->undefinedValue(); } -static QScriptValue qmlxmlhttprequest_send(QScriptContext *context, QScriptEngine *engine) +static QScriptValue qmlxmlhttprequest_send(QScriptContext *context, QScriptEngine *) { - QmlXMLHttpRequest *request = qobject_cast<QmlXMLHttpRequest *>(context->thisObject().data().toQObject()); + QScriptValue dataObject = context->thisObject().data(); + QmlXMLHttpRequest *request = qobject_cast<QmlXMLHttpRequest *>(dataObject.toQObject()); if (!request) THROW_REFERENCE("Not an XMLHttpRequest object"); @@ -1421,16 +1416,17 @@ static QScriptValue qmlxmlhttprequest_send(QScriptContext *context, QScriptEngin if (context->argumentCount() > 0) data = context->argument(0).toString().toUtf8(); - return request->send(data); + return request->send(&dataObject, data); } static QScriptValue qmlxmlhttprequest_abort(QScriptContext *context, QScriptEngine *) { - QmlXMLHttpRequest *request = qobject_cast<QmlXMLHttpRequest *>(context->thisObject().data().toQObject()); + QScriptValue dataObject = context->thisObject().data(); + QmlXMLHttpRequest *request = qobject_cast<QmlXMLHttpRequest *>(dataObject.toQObject()); if (!request) THROW_REFERENCE("Not an XMLHttpRequest object"); - return request->abort(); + return request->abort(&dataObject); } static QScriptValue qmlxmlhttprequest_getResponseHeader(QScriptContext *context, QScriptEngine *engine) @@ -1545,15 +1541,19 @@ static QScriptValue qmlxmlhttprequest_responseXML(QScriptContext *context, QScri static QScriptValue qmlxmlhttprequest_onreadystatechange(QScriptContext *context, QScriptEngine *engine) { - Q_UNUSED(engine) - QmlXMLHttpRequest *request = qobject_cast<QmlXMLHttpRequest *>(context->thisObject().data().toQObject()); + Q_UNUSED(engine); + QScriptValue dataObject = context->thisObject().data(); + QmlXMLHttpRequest *request = qobject_cast<QmlXMLHttpRequest *>(dataObject.toQObject()); if (!request) THROW_REFERENCE("Not an XMLHttpRequest object"); - if (context->argumentCount()) - request->setCallback(context->argument(0)); - - return request->callback(); + if (context->argumentCount()) { + QScriptValue v = context->argument(0); + dataObject.setProperty(QLatin1String("callback"), v); + return v; + } else { + return dataObject.property(QLatin1String("callback")); + } } // Constructor diff --git a/src/declarative/util/qmlopenmetaobject.cpp b/src/declarative/util/qmlopenmetaobject.cpp index 373be2d..1be81de 100644 --- a/src/declarative/util/qmlopenmetaobject.cpp +++ b/src/declarative/util/qmlopenmetaobject.cpp @@ -81,6 +81,17 @@ QmlOpenMetaObjectType::~QmlOpenMetaObjectType() delete d; } + +int QmlOpenMetaObjectType::propertyOffset() const +{ + return d->propertyOffset; +} + +int QmlOpenMetaObjectType::signalOffset() const +{ + return d->signalOffset; +} + int QmlOpenMetaObjectType::createProperty(const QByteArray &name) { int id = d->mob.propertyCount(); @@ -226,6 +237,11 @@ int QmlOpenMetaObject::metaCall(QMetaObject::Call c, int id, void **a) } } +QAbstractDynamicMetaObject *QmlOpenMetaObject::parent() const +{ + return d->parent; +} + QVariant QmlOpenMetaObject::value(int id) const { return d->getData(id); @@ -293,6 +309,7 @@ void QmlOpenMetaObject::setCached(bool c) } } + int QmlOpenMetaObject::createProperty(const char *name, const char *) { if (d->autoCreate) diff --git a/src/declarative/util/qmlopenmetaobject_p.h b/src/declarative/util/qmlopenmetaobject_p.h index 450f258..c6da71a 100644 --- a/src/declarative/util/qmlopenmetaobject_p.h +++ b/src/declarative/util/qmlopenmetaobject_p.h @@ -57,7 +57,7 @@ QT_MODULE(Declarative) class QmlEngine; class QMetaPropertyBuilder; class QmlOpenMetaObjectTypePrivate; -class QmlOpenMetaObjectType : public QmlRefCount +class Q_DECLARATIVE_EXPORT QmlOpenMetaObjectType : public QmlRefCount { public: QmlOpenMetaObjectType(const QMetaObject *base, QmlEngine *engine); @@ -65,6 +65,9 @@ public: int createProperty(const QByteArray &name); + int propertyOffset() const; + int signalOffset() const; + protected: virtual void propertyCreated(int, QMetaPropertyBuilder &); @@ -108,6 +111,8 @@ protected: virtual void propertyWrite(int); virtual void propertyCreated(int, QMetaPropertyBuilder &); + QAbstractDynamicMetaObject *parent() const; + private: QmlOpenMetaObjectPrivate *d; friend class QmlOpenMetaObjectType; |