void QDeclarativeQtScriptExpression::setNotifyObject(QObject *object, int notifyIndex)
{
    if (guardList) clearGuards();

    if (!object || notifyIndex == -1) {
        guardObject = 0;
        notifyIndex = -1;
    } else {
        guardObject = object;
        guardObjectNotifyIndex = notifyIndex;

    }
}
Exemplo n.º 2
0
QVariant QDeclarativeExpressionPrivate::value(QObject *secondaryScope, bool *isUndefined)
{
    Q_Q(QDeclarativeExpression);

    QVariant rv;
    if (!q->engine()) {
        qWarning("QDeclarativeExpression: Attempted to evaluate an expression in an invalid context");
        return rv;
    }

    if (data->expression.isEmpty())
        return rv;

    QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(q->engine());

    QDeclarativeExpression *lastCurrentExpression = ep->currentExpression;
    bool lastCaptureProperties = ep->captureProperties;
    QPODVector<QDeclarativeEnginePrivate::CapturedProperty> lastCapturedProperties;
    ep->capturedProperties.copyAndClear(lastCapturedProperties);

    ep->currentExpression = q;
    ep->captureProperties = data->trackChange;

    // This object might be deleted during the eval
    QDeclarativeExpressionData *localData = data;
    localData->addref();

    rv = evalQtScript(secondaryScope, isUndefined);

    ep->currentExpression = lastCurrentExpression;
    ep->captureProperties = lastCaptureProperties;

    // Check if we were deleted
    if (localData->q) {
        if ((!data->trackChange || !ep->capturedProperties.count()) && data->guardList) {
            clearGuards();
        } else if(data->trackChange) {
            updateGuards(ep->capturedProperties);
        }
    }

    localData->release();

    lastCapturedProperties.copyAndClear(ep->capturedProperties);

    return rv;
}
QScriptValue QDeclarativeQtScriptExpression::scriptValue(QObject *secondaryScope, bool *isUndefined)
{
    Q_ASSERT(context() && context()->engine);
    Q_ASSERT(!trackChange || (guardObject && guardObjectNotifyIndex != -1));

    if (!expressionFunction.isValid()) {
        if (isUndefined) *isUndefined = true;
        return QScriptValue();
    }

    DeleteWatcher watcher(this);

    QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(context()->engine);

    bool lastCaptureProperties = ep->captureProperties;
    QPODVector<QDeclarativeEnginePrivate::CapturedProperty> lastCapturedProperties;
    ep->captureProperties = trackChange;
    ep->capturedProperties.copyAndClear(lastCapturedProperties);

    QScriptValue value = eval(secondaryScope, isUndefined);

    if (!watcher.wasDeleted() && trackChange) {
        if (ep->capturedProperties.count() == 0) {

            if (guardList) clearGuards();

        } else {

            updateGuards(ep->capturedProperties);

        }
    }

    lastCapturedProperties.copyAndClear(ep->capturedProperties);
    ep->captureProperties = lastCaptureProperties;

    return value;
}
void QQmlJavaScriptExpression::setNotifyOnValueChanged(bool v)
{
    activeGuards.setFlagValue(v);
    if (!v) clearGuards();
}
QQmlJavaScriptExpression::~QQmlJavaScriptExpression()
{
    clearGuards();
    if (m_scopeObject.isT2()) // notify DeleteWatcher of our deletion.
        m_scopeObject.asT2()->_s = 0;
}
void QQmlJavaScriptExpression::resetNotifyOnValueChanged()
{
    clearGuards();
}
void QDeclarativeQtScriptExpression::resetNotifyOnChange()
{
    clearGuards();
}
void QDeclarativeQtScriptExpression::setNotifyOnValueChange(bool notify)
{
    trackChange = notify;
    if (!notify && guardList) 
        clearGuards();
}