aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlbinding.cpp
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2012-07-11 13:01:33 +1000
committerQt by Nokia <qt-info@nokia.com>2012-08-03 03:38:49 +0200
commitaa25ad8d5f476d6db59012a122833ebe677eaf69 (patch)
tree37eb955dabc252304aefe821d03be5e3857f22c9 /src/qml/qml/qqmlbinding.cpp
parentd64224041efe9febc683cf5ee7155a9cc88058d9 (diff)
Make QQmlScriptString opaque.
Allow for future optimization by encapsulating the raw script data. Change-Id: I1863103e8e6d74ede60593cabb240e16f2ae657e Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
Diffstat (limited to 'src/qml/qml/qqmlbinding.cpp')
-rw-r--r--src/qml/qml/qqmlbinding.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/qml/qml/qqmlbinding.cpp b/src/qml/qml/qqmlbinding.cpp
index 38d305a64e..5860cbe19d 100644
--- a/src/qml/qml/qqmlbinding.cpp
+++ b/src/qml/qml/qqmlbinding.cpp
@@ -50,6 +50,7 @@
#include <private/qqmltrace_p.h>
#include <private/qqmlexpression_p.h>
#include <private/qqmlrewrite_p.h>
+#include <private/qqmlscriptstring_p.h>
#include <QVariant>
#include <QtCore/qdebug.h>
@@ -114,6 +115,53 @@ QQmlBinding::QQmlBinding(const QString &str, QObject *obj, QQmlContext *ctxt)
v8function = evalFunction(context(), obj, code, QString(), 0);
}
+QQmlBinding::QQmlBinding(const QQmlScriptString &script, QObject *obj, QQmlContext *ctxt)
+: QQmlJavaScriptExpression(&QQmlBinding_jsvtable), QQmlAbstractBinding(Binding)
+{
+ if (ctxt && !ctxt->isValid())
+ return;
+
+ const QQmlScriptStringPrivate *scriptPrivate = script.d.data();
+ if (!ctxt && (!scriptPrivate->context || !scriptPrivate->context->isValid()))
+ return;
+
+ bool needRewrite = true;
+ QString code;
+
+ int id = scriptPrivate->bindingId;
+ if (id >= 0) {
+ QQmlContextData *ctxtdata = QQmlContextData::get(scriptPrivate->context);
+ QQmlEnginePrivate *engine = QQmlEnginePrivate::get(scriptPrivate->context->engine());
+ if (engine && ctxtdata && !ctxtdata->url.isEmpty()) {
+ QQmlTypeData *typeData = engine->typeLoader.getType(ctxtdata->url);
+ Q_ASSERT(typeData);
+
+ if (QQmlCompiledData *cdata = typeData->compiledData()) {
+ needRewrite = false;
+ code = cdata->primitives.at(id);
+ m_url = cdata->name;
+ }
+
+ typeData->release();
+ }
+ }
+
+ if (needRewrite) {
+ QQmlRewrite::RewriteBinding rewriteBinding;
+ code = rewriteBinding(scriptPrivate->script);
+ }
+
+ setNotifyOnValueChanged(true);
+ QQmlAbstractExpression::setContext(QQmlContextData::get(ctxt ? ctxt : scriptPrivate->context));
+ setScopeObject(obj ? obj : scriptPrivate->scope);
+
+ m_expression = scriptPrivate->script.toUtf8();
+ m_lineNumber = scriptPrivate->lineNumber;
+ m_columnNumber = scriptPrivate->columnNumber;
+
+ v8function = evalFunction(context(), scopeObject(), code, QString(), m_lineNumber);
+}
+
QQmlBinding::QQmlBinding(const QString &str, QObject *obj, QQmlContextData *ctxt)
: QQmlJavaScriptExpression(&QQmlBinding_jsvtable), QQmlAbstractBinding(Binding),
m_lineNumber(-1), m_columnNumber(-1)