Ejemplo n.º 1
0
/*!
    Set the \a value of the \a name property on this context.

    QDeclarativeContext does \bold not take ownership of \a value.
*/
void QDeclarativeContext::setContextProperty(const QString &name, QObject *value)
{
    Q_D(QDeclarativeContext);
    if (d->notifyIndex == -1)
        d->notifyIndex = this->metaObject()->methodCount();

    QDeclarativeContextData *data = d->data;

    if (data->isInternal) {
        qWarning("QDeclarativeContext: Cannot set property on internal context.");
        return;
    }

    if (!isValid()) {
        qWarning("QDeclarativeContext: Cannot set property on invalid context.");
        return;
    }

    if (!data->propertyNames) data->propertyNames = new QDeclarativeIntegerCache(data->engine);
    int idx = data->propertyNames->value(name);

    if (idx == -1) {
        data->propertyNames->add(name, data->idValueCount + d->propertyValues.count());
        d->propertyValues.append(QVariant::fromValue(value));

        data->refreshExpressions();
    } else {
        d->propertyValues[idx] = QVariant::fromValue(value);
        QMetaObject::activate(this, idx + d->notifyIndex, 0);
    }
}
Ejemplo n.º 2
0
/*
Refreshes all expressions that could possibly depend on this context.  Refreshing flushes all
context-tree dependent caches in the expressions, and should occur every time the context tree
 *structure* (not values) changes.
*/
void QDeclarativeContextData::refreshExpressions()
{
    QDeclarativeContextData *child = childContexts;
    while (child) {
        child->refreshExpressions();
        child = child->nextChild;
    }

    QDeclarativeAbstractExpression *expression = expressions;
    while (expression) {
        expression->refresh();
        expression = expression->m_nextExpression;
    }
}