void QQmlQtQuick2DebugStatesDelegate::updateBinding(QQmlContext *context, const QQmlProperty &property, const QVariant &expression, bool isLiteralValue, const QString &fileName, int line, int column, bool *inBaseState) { typedef QPointer<QQuickState> QuickStatePointer; QObject *object = property.object(); QString propertyName = property.name(); foreach (const QuickStatePointer& statePointer, m_allStates) { if (QQuickState *state = statePointer.data()) { // here we assume that the revert list on itself defines the base state if (state->isStateActive() && state->containsPropertyInRevertList(object, propertyName)) { *inBaseState = false; QQmlBinding *newBinding = 0; if (!isLiteralValue) { newBinding = new QQmlBinding(expression.toString(), object, QQmlContextData::get(context), fileName, line, column); newBinding->setTarget(property); newBinding->setNotifyOnValueChanged(true); } state->changeBindingInRevertList(object, propertyName, newBinding); if (isLiteralValue) state->changeValueInRevertList(object, propertyName, expression); } } } }
QString QQmlBinding::expressionIdentifier(QQmlJavaScriptExpression *e) { QQmlBinding *This = static_cast<QQmlBinding *>(e); QQmlEnginePrivate *ep = QQmlEnginePrivate::get(This->context()->engine); QV4::Scope scope(ep->v4engine()); QV4::ScopedValue f(scope, This->v4function.value()); QV4::Function *function = f->asFunctionObject()->function(); QString url = function->sourceFile(); quint16 lineNumber = function->compiledFunction->location.line; quint16 columnNumber = function->compiledFunction->location.column; return url + QLatin1Char(':') + QString::number(lineNumber) + QLatin1Char(':') + QString::number(columnNumber); }
void CustomBinding::componentComplete() { Q_ASSERT(m_target); foreach (const QV4::CompiledData::Binding *binding, bindings) { QString name = cdata->compilationUnit->data->stringAt(binding->propertyNameIndex); int bindingId = binding->value.compiledScriptIndex; QQmlContextData *context = QQmlContextData::get(qmlContext(this)); QV4::Scope scope(QQmlEnginePrivate::getV4Engine(qmlEngine(this))); QV4::ScopedValue function(scope, QV4::QmlBindingWrapper::createQmlCallableForFunction(context, m_target, cdata->compilationUnit->runtimeFunctions[bindingId])); QQmlBinding *qmlBinding = new QQmlBinding(function, m_target, context); QQmlProperty property(m_target, name, qmlContext(this)); qmlBinding->setTarget(property); QQmlPropertyPrivate::setBinding(property, qmlBinding); }
void CustomBinding::componentComplete() { Q_ASSERT(m_target); QDataStream ds(m_bindingData); int count; ds >> count; for (int i = 0; i < count; ++i) { QString name; ds >> name; int bindingId; ds >> bindingId; int line; ds >> line; QQmlBinding *binding = QQmlBinding::createBinding(QQmlBinding::Identifier(bindingId), m_target, qmlContext(this), QString(), line); QQmlProperty property(m_target, name, qmlContext(this)); binding->setTarget(property); QQmlPropertyPrivate::setBinding(property, binding); } }
void QQmlBinding::expressionChanged(QQmlJavaScriptExpression *e) { QQmlBinding *This = static_cast<QQmlBinding *>(e); This->update(); }
void QQmlValueTypeWrapper::put(Managed *m, String *name, const Value &value) { Q_ASSERT(m->as<QQmlValueTypeWrapper>()); ExecutionEngine *v4 = static_cast<QQmlValueTypeWrapper *>(m)->engine(); Scope scope(v4); if (scope.hasException()) return; Scoped<QQmlValueTypeWrapper> r(scope, static_cast<QQmlValueTypeWrapper *>(m)); Scoped<QQmlValueTypeReference> reference(scope, m->d()); int writeBackPropertyType = -1; if (reference) { QMetaProperty writebackProperty = reference->d()->object->metaObject()->property(reference->d()->property); if (!writebackProperty.isWritable() || !reference->readReferenceValue()) return; writeBackPropertyType = writebackProperty.userType(); } const QMetaObject *metaObject = r->d()->propertyCache->metaObject(); const QQmlPropertyData *pd = r->d()->propertyCache->property(name, 0, 0); if (!pd) return; QMetaProperty property = metaObject->property(pd->coreIndex); Q_ASSERT(property.isValid()); QQmlBinding *newBinding = 0; QV4::ScopedFunctionObject f(scope, value); if (reference && f) { if (!f->isBinding()) { // assigning a JS function to a non-var-property is not allowed. QString error = QStringLiteral("Cannot assign JavaScript function to value-type property"); ScopedString e(scope, v4->newString(error)); v4->throwError(e); return; } QQmlContextData *context = QmlContextWrapper::callingContext(v4); QQmlPropertyData cacheData; cacheData.setFlags(QQmlPropertyData::IsWritable | QQmlPropertyData::IsValueTypeVirtual); cacheData.propType = writeBackPropertyType; cacheData.coreIndex = reference->d()->property; cacheData.valueTypeFlags = 0; cacheData.valueTypeCoreIndex = pd->coreIndex; cacheData.valueTypePropType = property.userType(); QV4::Scoped<QQmlBindingFunction> bindingFunction(scope, (const Value &)f); bindingFunction->initBindingLocation(); newBinding = new QQmlBinding(value, reference->d()->object, context); newBinding->setTarget(reference->d()->object, cacheData, context); } if (reference) { QQmlAbstractBinding *oldBinding = QQmlPropertyPrivate::setBinding(reference->d()->object, reference->d()->property, pd->coreIndex, newBinding); if (oldBinding) oldBinding->destroy(); } if (newBinding) return; QVariant v = v4->toVariant(value, property.userType()); if (property.isEnumType() && (QMetaType::Type)v.type() == QMetaType::Double) v = v.toInt(); void *gadget = r->d()->gadgetPtr; property.writeOnGadget(gadget, v); if (reference) { if (writeBackPropertyType == QMetaType::QVariant) { QVariant variantReferenceValue = r->d()->toVariant(); int flags = 0; int status = -1; void *a[] = { &variantReferenceValue, 0, &status, &flags }; QMetaObject::metacall(reference->d()->object, QMetaObject::WriteProperty, reference->d()->property, a); } else { int flags = 0; int status = -1; void *a[] = { r->d()->gadgetPtr, 0, &status, &flags }; QMetaObject::metacall(reference->d()->object, QMetaObject::WriteProperty, reference->d()->property, a); } } }
QQuickStateOperation::ActionList QQuickParentChange::actions() { Q_D(QQuickParentChange); if (!d->target || !d->parent) return ActionList(); ActionList actions; QQuickAction a; a.event = this; actions << a; if (d->xString.isValid()) { bool ok = false; qreal x = d->xString.value.numberLiteral(&ok); if (ok) { QQuickAction xa(d->target, QLatin1String("x"), x); actions << xa; } else { QQmlBinding *newBinding = new QQmlBinding(d->xString.value, d->target, qmlContext(this)); QQmlProperty property(d->target, QLatin1String("x")); newBinding->setTarget(property); QQuickAction xa; xa.property = property; xa.toBinding = QQmlAbstractBinding::getPointer(newBinding); xa.fromValue = xa.property.read(); xa.deletableToBinding = true; actions << xa; } } if (d->yString.isValid()) { bool ok = false; qreal y = d->yString.value.numberLiteral(&ok); if (ok) { QQuickAction ya(d->target, QLatin1String("y"), y); actions << ya; } else { QQmlBinding *newBinding = new QQmlBinding(d->yString.value, d->target, qmlContext(this)); QQmlProperty property(d->target, QLatin1String("y")); newBinding->setTarget(property); QQuickAction ya; ya.property = property; ya.toBinding = QQmlAbstractBinding::getPointer(newBinding); ya.fromValue = ya.property.read(); ya.deletableToBinding = true; actions << ya; } } if (d->scaleString.isValid()) { bool ok = false; qreal scale = d->scaleString.value.numberLiteral(&ok); if (ok) { QQuickAction sa(d->target, QLatin1String("scale"), scale); actions << sa; } else { QQmlBinding *newBinding = new QQmlBinding(d->scaleString.value, d->target, qmlContext(this)); QQmlProperty property(d->target, QLatin1String("scale")); newBinding->setTarget(property); QQuickAction sa; sa.property = property; sa.toBinding = QQmlAbstractBinding::getPointer(newBinding); sa.fromValue = sa.property.read(); sa.deletableToBinding = true; actions << sa; } } if (d->rotationString.isValid()) { bool ok = false; qreal rotation = d->rotationString.value.numberLiteral(&ok); if (ok) { QQuickAction ra(d->target, QLatin1String("rotation"), rotation); actions << ra; } else { QQmlBinding *newBinding = new QQmlBinding(d->rotationString.value, d->target, qmlContext(this)); QQmlProperty property(d->target, QLatin1String("rotation")); newBinding->setTarget(property); QQuickAction ra; ra.property = property; ra.toBinding = QQmlAbstractBinding::getPointer(newBinding); ra.fromValue = ra.property.read(); ra.deletableToBinding = true; actions << ra; } } if (d->widthString.isValid()) { bool ok = false; qreal width = d->widthString.value.numberLiteral(&ok); if (ok) { QQuickAction wa(d->target, QLatin1String("width"), width); actions << wa; } else { QQmlBinding *newBinding = new QQmlBinding(d->widthString.value, d->target, qmlContext(this)); QQmlProperty property(d->target, QLatin1String("width")); newBinding->setTarget(property); QQuickAction wa; wa.property = property; wa.toBinding = QQmlAbstractBinding::getPointer(newBinding); wa.fromValue = wa.property.read(); wa.deletableToBinding = true; actions << wa; } } if (d->heightString.isValid()) { bool ok = false; qreal height = d->heightString.value.numberLiteral(&ok); if (ok) { QQuickAction ha(d->target, QLatin1String("height"), height); actions << ha; } else { QQmlBinding *newBinding = new QQmlBinding(d->heightString.value, d->target, qmlContext(this)); QQmlProperty property(d->target, QLatin1String("height")); newBinding->setTarget(property); QQuickAction ha; ha.property = property; ha.toBinding = QQmlAbstractBinding::getPointer(newBinding); ha.fromValue = ha.property.read(); ha.deletableToBinding = true; actions << ha; } } return actions; }