summaryrefslogtreecommitdiffstats
path: root/src/declarative/qml
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2009-09-22 08:50:50 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2009-09-22 08:50:50 (GMT)
commit8d5a395e176239b7e3ee8822cb251b2e631c21de (patch)
tree60dee6cd158820944b892183c0d77a1af47fab97 /src/declarative/qml
parent65e7073bb151bd9281b2d0be53f0c13cce90f3c0 (diff)
downloadQt-8d5a395e176239b7e3ee8822cb251b2e631c21de.zip
Qt-8d5a395e176239b7e3ee8822cb251b2e631c21de.tar.gz
Qt-8d5a395e176239b7e3ee8822cb251b2e631c21de.tar.bz2
Slight simplification of parameterized signals
Diffstat (limited to 'src/declarative/qml')
-rw-r--r--src/declarative/qml/qmlboundsignal.cpp8
-rw-r--r--src/declarative/qml/qmlexpression.cpp45
-rw-r--r--src/declarative/qml/qmlexpression_p.h8
-rw-r--r--src/declarative/qml/qmlvme.cpp2
4 files changed, 40 insertions, 23 deletions
diff --git a/src/declarative/qml/qmlboundsignal.cpp b/src/declarative/qml/qmlboundsignal.cpp
index 9af4003..c43097e 100644
--- a/src/declarative/qml/qmlboundsignal.cpp
+++ b/src/declarative/qml/qmlboundsignal.cpp
@@ -42,6 +42,7 @@
#include "qmlboundsignal_p.h"
#include "private/qmetaobjectbuilder_p.h"
#include "private/qmlengine_p.h"
+#include "private/qmlexpression_p.h"
#include "private/qmlcontext_p.h"
#include <qfxglobal.h>
#include <qmlmetatype.h>
@@ -60,7 +61,8 @@ QmlBoundSignal::QmlBoundSignal(QmlContext *ctxt, const QString &val, QObject *me
// This is thread safe. Although it may be updated by two threads, they
// will both set it to the same value - so the worst thing that can happen
// is that they both do the work to figure it out. Boo hoo.
- if (evaluateIdx == -1) evaluateIdx = QmlExpression::staticMetaObject.indexOfMethod("value()");
+ if (evaluateIdx == -1)
+ evaluateIdx = QmlExpression::staticMetaObject.indexOfMethod("value()");
setTrackChange(false);
QFx_setParent_noEvent(this, parent);
@@ -73,15 +75,13 @@ QmlBoundSignalProxy::QmlBoundSignalProxy(QmlContext *ctxt, const QString &val, Q
QMetaMethod signal = me->metaObject()->method(idx);
params = new QmlBoundSignalParameters(signal, this);
-
- ctxt->d_func()->addDefaultObject(params, QmlContextPrivate::HighPriority);
}
int QmlBoundSignalProxy::qt_metacall(QMetaObject::Call c, int id, void **a)
{
if (c == QMetaObject::InvokeMetaMethod && id == evaluateIdx) {
params->setValues(a);
- value();
+ QmlExpressionPrivate::get(this)->value(params);
params->clearValues();
return -1;
} else {
diff --git a/src/declarative/qml/qmlexpression.cpp b/src/declarative/qml/qmlexpression.cpp
index 845dcf6..db9d39f 100644
--- a/src/declarative/qml/qmlexpression.cpp
+++ b/src/declarative/qml/qmlexpression.cpp
@@ -212,7 +212,7 @@ QVariant QmlExpressionPrivate::evalSSE()
return rv;
}
-QVariant QmlExpressionPrivate::evalQtScript()
+QVariant QmlExpressionPrivate::evalQtScript(QObject *secondaryScope)
{
#ifdef Q_ENABLE_PERFORMANCE_LOG
QFxPerfTimer<QFxPerf::BindValueQt> perfqt;
@@ -223,6 +223,9 @@ QVariant QmlExpressionPrivate::evalQtScript()
if (me)
ctxtPriv->defaultObjects.insert(ctxtPriv->highPriorityCount, me);
+ if (secondaryScope)
+ ctxtPriv->defaultObjects.insert(ctxtPriv->highPriorityCount,
+ secondaryScope);
QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine);
@@ -263,6 +266,8 @@ QVariant QmlExpressionPrivate::evalQtScript()
if (me)
ctxtPriv->defaultObjects.removeAt(ctxtPriv->highPriorityCount);
+ if (secondaryScope)
+ ctxtPriv->defaultObjects.removeAt(ctxtPriv->highPriorityCount);
QVariant rv;
@@ -306,42 +311,38 @@ QVariant QmlExpressionPrivate::evalQtScript()
return rv;
}
-/*!
- Returns the value of the expression, or an invalid QVariant if the
- expression is invalid or has an error.
-*/
-QVariant QmlExpression::value()
+QVariant QmlExpressionPrivate::value(QObject *secondaryScope)
{
- Q_D(QmlExpression);
+ Q_Q(QmlExpression);
QVariant rv;
- if (!engine() || (!d->sse.isValid() && d->expression.isEmpty()))
+ if (!q->engine() || (!sse.isValid() && expression.isEmpty()))
return rv;
#ifdef Q_ENABLE_PERFORMANCE_LOG
QFxPerfTimer<QFxPerf::BindValue> perf;
#endif
- QmlEnginePrivate *ep = QmlEnginePrivate::get(engine());
+ QmlEnginePrivate *ep = QmlEnginePrivate::get(q->engine());
QmlExpression *lastCurrentExpression = ep->currentExpression;
QPODVector<QmlEnginePrivate::CapturedProperty> lastCapturedProperties;
ep->capturedProperties.copyAndClear(lastCapturedProperties);
- ep->currentExpression = this;
+ ep->currentExpression = q;
- if (d->sse.isValid()) {
- rv = d->evalSSE();
+ if (sse.isValid()) {
+ rv = evalSSE();
} else {
- rv = d->evalQtScript();
+ rv = evalQtScript(secondaryScope);
}
ep->currentExpression = lastCurrentExpression;
- if ((!trackChange() || !ep->capturedProperties.count()) && d->guardList) {
- d->clearGuards();
- } else if(trackChange()) {
- d->updateGuards(ep->capturedProperties);
+ if ((!q->trackChange() || !ep->capturedProperties.count()) && guardList) {
+ clearGuards();
+ } else if(q->trackChange()) {
+ updateGuards(ep->capturedProperties);
}
lastCapturedProperties.copyAndClear(ep->capturedProperties);
@@ -350,6 +351,16 @@ QVariant QmlExpression::value()
}
/*!
+ Returns the value of the expression, or an invalid QVariant if the
+ expression is invalid or has an error.
+*/
+QVariant QmlExpression::value()
+{
+ Q_D(QmlExpression);
+ return d->value();
+}
+
+/*!
Returns true if the expression results in a constant value.
QmlExpression::value() must have been invoked at least once before the
return from this method is valid.
diff --git a/src/declarative/qml/qmlexpression_p.h b/src/declarative/qml/qmlexpression_p.h
index 997bf8d..501e5d8 100644
--- a/src/declarative/qml/qmlexpression_p.h
+++ b/src/declarative/qml/qmlexpression_p.h
@@ -93,6 +93,7 @@ public:
PreTransformedQtScriptData = 2
};
+
void init(QmlContext *, const QString &, QObject *);
void init(QmlContext *, void *, QmlRefCount *, QObject *);
@@ -108,8 +109,9 @@ public:
QString fileName;
int line;
+ QVariant value(QObject *secondaryScope = 0);
QVariant evalSSE();
- QVariant evalQtScript();
+ QVariant evalQtScript(QObject *secondaryScope);
struct SignalGuard : public QGuard<QObject> {
SignalGuard() : isDuplicate(false), notifyIndex(-1) {}
@@ -132,6 +134,10 @@ public:
int guardListLength;
void updateGuards(const QPODVector<QmlEnginePrivate::CapturedProperty> &properties);
void clearGuards();
+
+ static QmlExpressionPrivate *get(QmlExpression *expr) {
+ return static_cast<QmlExpressionPrivate *>(QObjectPrivate::get(expr));
+ }
};
QT_END_NAMESPACE
diff --git a/src/declarative/qml/qmlvme.cpp b/src/declarative/qml/qmlvme.cpp
index 4d133e3..ca88455 100644
--- a/src/declarative/qml/qmlvme.cpp
+++ b/src/declarative/qml/qmlvme.cpp
@@ -540,7 +540,7 @@ QObject *QmlVME::run(QStack<QObject *> &stack, QmlContext *ctxt, QmlCompiledData
if (signal.parameterTypes().isEmpty()) {
(void *)new QmlBoundSignal(ctxt, primitives.at(instr.storeSignal.value), target, instr.storeSignal.signalIndex, target);
} else {
- (void *)new QmlBoundSignalProxy(new QmlContext(ctxt, target, true), primitives.at(instr.storeSignal.value), target, instr.storeSignal.signalIndex, target);
+ (void *)new QmlBoundSignalProxy(ctxt, primitives.at(instr.storeSignal.value), target, instr.storeSignal.signalIndex, target);
}
}
break;