diff options
author | Chris Adams <christopher.adams@nokia.com> | 2012-03-27 16:56:08 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-03-29 00:40:48 +0200 |
commit | 53d5deb5034bf5adb8719723bc66eb3a61638a32 (patch) | |
tree | 011c99abcadf6c4ef723586e25c8f56cd6f3b113 /src/qml/qml/qqmlboundsignal_p.h | |
parent | e4baefacff3e04ea3b599c5279e883d75d2ad489 (diff) |
Use minimal javascript expression for bound signals
Previously, QQmlBoundSignal used QQmlExpression internally. This
commit adds a new, more optimal QQmlJavaScriptExpression subclass
specifically designed for QQmlBoundSignal, and converts the code
to use it instead of QQmlExpression where appropriate.
Task-number: QTBUG-24460
Change-Id: I2865a119ce840235e27a7722d8052ca61c265f69
Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
Diffstat (limited to 'src/qml/qml/qqmlboundsignal_p.h')
-rw-r--r-- | src/qml/qml/qqmlboundsignal_p.h | 57 |
1 files changed, 47 insertions, 10 deletions
diff --git a/src/qml/qml/qqmlboundsignal_p.h b/src/qml/qml/qqmlboundsignal_p.h index 5fc8c3522f..22cc5a9f83 100644 --- a/src/qml/qml/qqmlboundsignal_p.h +++ b/src/qml/qml/qqmlboundsignal_p.h @@ -53,15 +53,52 @@ // We mean it. // -#include "qqmlexpression.h" - #include <QtCore/qmetaobject.h> +#include <private/qqmlabstractexpression_p.h> +#include <private/qqmljavascriptexpression_p.h> #include <private/qqmlnotifier_p.h> #include <private/qobject_p.h> QT_BEGIN_NAMESPACE +class Q_QML_PRIVATE_EXPORT QQmlBoundSignalExpression : public QQmlAbstractExpression, public QQmlJavaScriptExpression +{ +public: + QQmlBoundSignalExpression(QQmlContextData *ctxt, QObject *scope, const QByteArray &expression, + bool isRewritten, const QString &fileName, int line, int column); + QQmlBoundSignalExpression(QQmlContextData *ctxt, QObject *scope, const QString &expression, + bool isRewritten, const QString &fileName, int line, int column); + ~QQmlBoundSignalExpression(); + + // "inherited" from QQmlJavaScriptExpression. + static QString expressionIdentifier(QQmlJavaScriptExpression *); + static void expressionChanged(QQmlJavaScriptExpression *); + + // evaluation of a bound signal expression doesn't return any value + void evaluate(QObject *secondaryScope = 0); + + QString sourceFile() const { return m_fileName; } + int lineNumber() const { return m_line; } + int columnNumber() const { return m_column; } + QString expression() const { return m_expression; } + + QQmlEngine *engine() const { return context() ? context()->engine : 0; } + +private: + v8::Persistent<v8::Object> m_v8qmlscope; + v8::Persistent<v8::Function> m_v8function; + + QString m_expression; + QString m_functionName; // hint for debugger + QString m_fileName; + int m_line; + int m_column; + + bool m_expressionFunctionValid:1; + bool m_expressionFunctionRewritten:1; +}; + class Q_QML_EXPORT QQmlAbstractBoundSignal { public: @@ -69,8 +106,8 @@ public: virtual ~QQmlAbstractBoundSignal(); virtual int index() const = 0; - virtual QQmlExpression *expression() const = 0; - virtual QQmlExpression *setExpression(QQmlExpression *) = 0; + virtual QQmlBoundSignalExpression *expression() const = 0; + virtual QQmlBoundSignalExpression *setExpression(QQmlBoundSignalExpression *) = 0; virtual QObject *object() = 0; void addToObject(); @@ -93,8 +130,8 @@ public: int index() const; - QQmlExpression *expression() const; - QQmlExpression *setExpression(QQmlExpression *); + QQmlBoundSignalExpression *expression() const; + QQmlBoundSignalExpression *setExpression(QQmlBoundSignalExpression *); QObject *object() { return m_owner; } bool isEvaluating() const { return m_isEvaluating; } @@ -103,7 +140,7 @@ protected: virtual int qt_metacall(QMetaObject::Call c, int id, void **a); private: - QQmlExpression *m_expression; + QQmlBoundSignalExpression *m_expression; QMetaMethod m_signal; bool m_paramsValid : 1; bool m_isEvaluating : 1; @@ -120,8 +157,8 @@ public: int index() const; - QQmlExpression *expression() const; - QQmlExpression *setExpression(QQmlExpression *); + QQmlBoundSignalExpression *expression() const; + QQmlBoundSignalExpression *setExpression(QQmlBoundSignalExpression *); QObject *object() { return m_owner; } static void subscriptionCallback(QQmlNotifierEndpoint *e); @@ -129,7 +166,7 @@ public: bool isEvaluating() const { return m_isEvaluating; } private: - QQmlExpression *m_expression; + QQmlBoundSignalExpression *m_expression; QObject *m_owner; int m_index; bool m_isEvaluating; |