10#include <private/qqmldebugserviceinterfaces_p.h>
11#include <private/qqmldebugconnector_p.h>
13#include <private/qqmlprofiler_p.h>
14#include <private/qqmlexpression_p.h>
15#include <private/qqmlscriptstring_p.h>
16#include <private/qqmlbuiltinfunctions_p.h>
17#include <private/qqmlvmemetaobject_p.h>
18#include <private/qqmlvaluetypewrapper_p.h>
19#include <private/qv4qmlcontext_p.h>
20#include <private/qv4qobjectwrapper_p.h>
21#include <private/qv4variantobject_p.h>
22#include <private/qv4jscall_p.h>
23#include <private/qjsvalue_p.h>
25#include <qtqml_tracepoints_p.h>
28#include <QtCore/qdebug.h>
33Q_TRACE_POINT(qtqml, QQmlBinding_entry,
const QQmlEngine *engine,
const QString &function,
const QString &fileName,
int line,
int column)
34Q_TRACE_POINT(qtqml, QQmlBinding_exit)
36QQmlBinding *QQmlBinding::create(
const QQmlPropertyData *property,
const QQmlScriptString &script, QObject *obj, QQmlContext *ctxt)
38 QQmlBinding *b = newBinding(property);
40 if (ctxt && !ctxt->isValid())
43 const QQmlScriptStringPrivate *scriptPrivate = script.d.data();
44 if (!ctxt && (!scriptPrivate->context || !scriptPrivate->context->isValid()))
48 QV4::Function *runtimeFunction =
nullptr;
50 QQmlRefPointer<QQmlContextData> ctxtdata = QQmlContextData::get(scriptPrivate->context);
51 QQmlEnginePrivate *engine = QQmlEnginePrivate::get(scriptPrivate->context->engine());
52 if (engine && ctxtdata && !ctxtdata->urlString().isEmpty() && ctxtdata->typeCompilationUnit()) {
53 url = ctxtdata->urlString();
54 if (scriptPrivate->bindingId != QQmlBinding::Invalid)
55 runtimeFunction = ctxtdata->typeCompilationUnit()->runtimeFunctions.at(scriptPrivate->bindingId);
58 b->setNotifyOnValueChanged(
true);
59 b->QQmlJavaScriptExpression::setContext(QQmlContextData::get(ctxt ? ctxt : scriptPrivate->context));
60 b->setScopeObject(obj ? obj : scriptPrivate->scope);
62 QV4::ExecutionEngine *v4 = b->engine()->handle();
63 if (runtimeFunction) {
65 QV4::Scoped<QV4::QmlContext> qmlContext(scope, QV4::QmlContext::create(v4->rootContext(), ctxtdata, b->scopeObject()));
66 b->setupFunction(qmlContext, runtimeFunction);
68 QString code = scriptPrivate->script;
69 b->createQmlBinding(b->context(), b->scopeObject(), code, url, scriptPrivate->lineNumber);
75QQmlSourceLocation QQmlBinding::sourceLocation()
const
78 return *m_sourceLocation;
79 return QQmlJavaScriptExpression::sourceLocation();
82void QQmlBinding::setSourceLocation(
const QQmlSourceLocation &location)
85 delete m_sourceLocation;
86 m_sourceLocation =
new QQmlSourceLocation(location);
90QQmlBinding *QQmlBinding::create(
91 const QQmlPropertyData *property,
const QString &str, QObject *obj,
92 const QQmlRefPointer<QQmlContextData> &ctxt,
const QString &url, quint16 lineNumber)
94 QQmlBinding *b = newBinding(property);
96 b->setNotifyOnValueChanged(
true);
97 b->QQmlJavaScriptExpression::setContext(ctxt);
98 b->setScopeObject(obj);
100 b->createQmlBinding(ctxt, obj, str, url, lineNumber);
105QQmlBinding *QQmlBinding::create(
106 const QQmlPropertyData *property, QV4::Function *function, QObject *obj,
107 const QQmlRefPointer<QQmlContextData> &ctxt, QV4::ExecutionContext *scope)
109 return create(property ? property->propType() : QMetaType(), function, obj, ctxt, scope);
112QQmlBinding *QQmlBinding::create(QMetaType propertyType, QV4::Function *function, QObject *obj,
113 const QQmlRefPointer<QQmlContextData> &ctxt,
114 QV4::ExecutionContext *scope)
116 QQmlBinding *b = newBinding(propertyType);
118 b->setNotifyOnValueChanged(
true);
119 b->QQmlJavaScriptExpression::setContext(ctxt);
120 b->setScopeObject(obj);
123 b->setupFunction(scope, function);
128QQmlBinding::~QQmlBinding()
130 delete m_sourceLocation;
133void QQmlBinding::update(QQmlPropertyData::WriteFlags flags)
135 if (!enabledFlag() || !hasValidContext())
139 if (QQmlData::wasDeleted(targetObject()))
143 if (Q_UNLIKELY(updatingFlag())) {
144 const QQmlPropertyData *d =
nullptr;
145 QQmlPropertyData vtd;
146 getPropertyData(&d, &vtd);
148 QQmlProperty p = QQmlPropertyPrivate::restore(targetObject(), *d, &vtd,
nullptr);
149 printBindingLoopError(p);
152 setUpdatingFlag(
true);
154 DeleteWatcher watcher(
this);
156 QQmlEngine *qmlEngine = engine();
157 QV4::Scope scope(qmlEngine->handle());
159 if (canUseAccessor())
160 flags.setFlag(QQmlPropertyData::BypassInterceptor);
162 Q_TRACE_SCOPE(QQmlBinding, qmlEngine, function() ? function()->name()->toQString() : QString(),
163 sourceLocation().sourceFile, sourceLocation().line, sourceLocation().column);
164 QQmlBindingProfiler prof(QQmlEnginePrivate::get(qmlEngine)->profiler, function());
165 doUpdate(watcher, flags, scope);
167 if (!watcher.wasDeleted())
168 setUpdatingFlag(
false);
171void QQmlBinding::printBindingLoopError(
const QQmlProperty &prop)
173 qmlWarning(prop.object()) << QString(QLatin1String(
"Binding loop detected for property \"%1\":\n%2"))
174 .arg(prop.name(), expressionIdentifier());
177QV4::ReturnedValue QQmlBinding::evaluate(
bool *isUndefined)
179 QV4::ExecutionEngine *v4 = engine()->handle();
181 const QV4::Value *argv =
nullptr;
182 const QV4::Value *thisObject =
nullptr;
183 QV4::BoundFunction *b =
nullptr;
184 if ((b =
static_cast<QV4::BoundFunction *>(m_boundFunction.valueRef()))) {
185 QV4::Heap::MemberData *args = b->boundArgs();
187 argc = args->values.size;
188 argv = args->values.data();
190 thisObject = &b->d()->boundThis;
192 QV4::Scope scope(v4);
193 QV4::JSCallData jsCall(thisObject, argv, argc);
195 return QQmlJavaScriptExpression::evaluate(jsCall.callData(scope), isUndefined);
198template<
int StaticPropType>
204 QQmlPropertyData::WriteFlags flags)
override final
206 const QQmlPropertyData *pd;
207 QQmlPropertyData vpd;
208 getPropertyData(&pd, &vpd);
211 if (isUndefined || vpd.isValid())
212 return slowWrite(*pd, vpd, result, type, isUndefined, flags);
214 if ((StaticPropType == QMetaType::UnknownType && pd->propType() == type)
215 || StaticPropType == type.id()) {
216 Q_ASSERT(targetObject());
217 return pd->writeProperty(targetObject(), result, flags);
221 QV4::Scope scope(engine()->handle());
222 QV4::ScopedValue value(scope, engine()->handle()->metaTypeToJS(type, result));
223 return write(value, isUndefined, flags);
228 QQmlPropertyData::WriteFlags flags)
override final
230 Q_ASSERT(targetObject());
232 const QQmlPropertyData *pd;
233 QQmlPropertyData vpd;
234 getPropertyData(&pd, &vpd);
237 int propertyType = StaticPropType;
238 if (propertyType == QMetaType::UnknownType)
239 propertyType = pd->propType().id();
241 if (Q_LIKELY(!isUndefined && !vpd.isValid())) {
242 switch (propertyType) {
243 case QMetaType::Bool:
244 if (result.isBoolean())
245 return doStore<
bool>(result.booleanValue(), pd, flags);
247 return doStore<
bool>(result.toBoolean(), pd, flags);
249 if (result.isInteger())
250 return doStore<
int>(result.integerValue(), pd, flags);
251 else if (result.isNumber()) {
252 return doStore<
int>(result.toInt32(), pd, flags);
255 case QMetaType::Double:
256 if (result.isNumber())
257 return doStore<
double>(result.asDouble(), pd, flags);
259 case QMetaType::Float:
260 if (result.isNumber())
261 return doStore<
float>(result.asDouble(), pd, flags);
263 case QMetaType::QString:
264 if (result.isString())
265 return doStore<QString>(result.toQStringNoThrow(), pd, flags);
268 if (
const QV4::QQmlValueTypeWrapper *vtw = result.as<
const QV4::QQmlValueTypeWrapper>()) {
269 if (vtw->d()->metaType() == pd->propType()) {
270 return vtw->write(m_target.data(), pd->coreIndex());
277 return slowWrite(*pd, vpd, result, isUndefined, flags);
280 template <
typename T>
284 return pd->writeProperty(targetObject(), o, flags);
293 setCompilationUnit(compilationUnit);
294 setSource(QQmlEnginePrivate::get(compilationUnit->engine)->translationLanguage);
303 QQmlPropertyData::WriteFlags flags, QV4::Scope &scope)
override final
305 if (watcher.wasDeleted())
308 if (!isAddedToObject() || hasError())
311 const QString result =
this->bindingValue();
313 Q_ASSERT(targetObject());
315 const QQmlPropertyData *pd;
316 QQmlPropertyData vpd;
317 getPropertyData(&pd, &vpd);
319 if (pd->propType().id() == QMetaType::QString) {
320 doStore(result, pd, flags);
322 QV4::ScopedString value(scope, scope.engine->newString(result));
323 slowWrite(*pd, vpd, value,
false, flags);
336 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &compilationUnit,
344 return this->m_compilationUnit->bindingValueAsString(m_binding);
349 return QQmlSourceLocation(m_compilationUnit->fileName(), m_binding->valueLocation.line(),
350 m_binding->valueLocation.column());
356 QQmlTranslation m_translationData;
363 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &compilationUnit,
364 const QQmlTranslation &translationData, quint16 line, quint16 column)
376 return QQmlSourceLocation(m_compilationUnit->fileName(), m_line, m_column);
380QQmlBinding *QQmlBinding::createTranslationBinding(
381 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &unit,
382 const QV4::CompiledData::Binding *binding, QObject *obj,
383 const QQmlRefPointer<QQmlContextData> &ctxt)
385 QQmlTranslationBinding *b =
new QQmlTranslationBindingFromBinding(unit, binding);
387 b->setNotifyOnValueChanged(
true);
388 b->QQmlJavaScriptExpression::setContext(ctxt);
389 b->setScopeObject(obj);
390#if QT_CONFIG(translation) && QT_CONFIG(qml_debug)
391 if (QQmlDebugTranslationService *service
392 = QQmlDebugConnector::service<QQmlDebugTranslationService>()) {
393 service->foundTranslationBinding(
394 TranslationBindingInformation::create(unit, binding, b->scopeObject(), ctxt));
400QQmlBinding *QQmlBinding::createTranslationBinding(
401 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &unit,
402 const QQmlRefPointer<QQmlContextData> &ctxt,
const QString &propertyName,
403 const QQmlTranslation &translationData,
const QQmlSourceLocation &location, QObject *obj)
405 QQmlTranslationBinding *b =
new QQmlTranslationBindingFromTranslationInfo(
406 unit, translationData, location.column, location.line);
408 b->setNotifyOnValueChanged(
true);
409 b->QQmlJavaScriptExpression::setContext(ctxt);
410 b->setScopeObject(obj);
412#if QT_CONFIG(translation) && QT_CONFIG(qml_debug)
413 QString originString;
414 if (QQmlDebugTranslationService *service =
415 QQmlDebugConnector::service<QQmlDebugTranslationService>()) {
416 service->foundTranslationBinding({ unit, b->scopeObject(), ctxt,
418 propertyName, translationData,
420 location.line, location.column });
423 Q_UNUSED(propertyName)
428bool QQmlBinding::slowWrite(
429 const QQmlPropertyData &core,
const QQmlPropertyData &valueTypeData,
const void *result,
430 QMetaType resultType,
bool isUndefined, QQmlPropertyData::WriteFlags flags)
439 QQmlEngine *qmlEngine = engine();
440 const QMetaType metaType = valueTypeData.isValid() ? valueTypeData.propType() : core.propType();
441 QQmlJavaScriptExpression::DeleteWatcher watcher(
this);
443 if (core.isVarProperty()) {
444 QQmlVMEMetaObject *vmemo = QQmlVMEMetaObject::get(m_target.data());
446 QV4::Scope scope(qmlEngine->handle());
447 QV4::ScopedValue value(scope, qmlEngine->handle()->metaTypeToJS(resultType, result));
448 vmemo->setVMEProperty(core.coreIndex(),
450 }
else if (isUndefined && core.isResettable()) {
451 void *args[] = {
nullptr };
452 QMetaObject::metacall(m_target.data(), QMetaObject::ResetProperty, core.coreIndex(), args);
453 }
else if (isUndefined && metaType == QMetaType::fromType<QVariant>()) {
454 QQmlPropertyPrivate::writeValueProperty(
455 m_target.data(), core, valueTypeData, QVariant(), context(), flags);
456 }
else if (metaType == QMetaType::fromType<QJSValue>()) {
457 QQmlPropertyPrivate::writeValueProperty(
458 m_target.data(), core, valueTypeData,
459 QVariant(resultType, result), context(), flags);
460 }
else if (isUndefined) {
461 const char *name = metaType.name();
462 const QString typeName = name
463 ? QString::fromUtf8(name)
464 : QStringLiteral(
"[unknown property type]");
465 delayedError()->setErrorDescription(
466 QStringLiteral(
"Unable to assign [undefined] to ") + typeName);
468 }
else if (!QQmlPropertyPrivate::writeValueProperty(
469 m_target.data(), core, valueTypeData, QVariant(resultType, result),
471 if (watcher.wasDeleted())
473 handleWriteError(result, resultType, metaType);
480Q_NEVER_INLINE
bool QQmlBinding::slowWrite(
const QQmlPropertyData &core,
481 const QQmlPropertyData &valueTypeData,
482 const QV4::Value &result,
483 bool isUndefined, QQmlPropertyData::WriteFlags flags)
485 const QMetaType metaType = valueTypeData.isValid() ? valueTypeData.propType() : core.propType();
486 const int type = metaType.id();
488 QQmlJavaScriptExpression::DeleteWatcher watcher(
this);
491 bool isVarProperty = core.isVarProperty();
494 }
else if (core.isQList()) {
495 if (core.propType().flags() & QMetaType::IsQmlList)
496 value = QV4::ExecutionEngine::toVariant(result, QMetaType::fromType<QList<QObject*>>());
498 value = QV4::ExecutionEngine::toVariant(result, core.propType());
499 }
else if (result.isNull() && core.isQObject()) {
500 value = QVariant::fromValue((QObject *)
nullptr);
501 }
else if (core.propType() == QMetaType::fromType<QList<QUrl>>()) {
502 const QVariant resultVariant
503 = QV4::ExecutionEngine::toVariant(result, QMetaType::fromType<QList<QUrl>>());
504 value = QVariant::fromValue(QQmlPropertyPrivate::resolveUrlsOnAssignment()
505 ? QQmlPropertyPrivate::urlSequence(resultVariant, context())
506 : QQmlPropertyPrivate::urlSequence(resultVariant));
507 }
else if (!isVarProperty && metaType != QMetaType::fromType<QJSValue>()) {
508 value = QV4::ExecutionEngine::toVariant(result, metaType);
513 }
else if (isVarProperty) {
514 const QV4::FunctionObject *f = result.as<QV4::FunctionObject>();
515 if (f && f->isBinding()) {
518 delayedError()->setErrorDescription(QLatin1String(
"Invalid use of Qt.binding() in a binding declaration."));
522 QQmlVMEMetaObject *vmemo = QQmlVMEMetaObject::get(m_target.data());
524 vmemo->setVMEProperty(core.coreIndex(), result);
525 }
else if (isUndefined
526 && (valueTypeData.isValid() ? valueTypeData.isResettable() : core.isResettable())) {
527 QQmlPropertyPrivate::resetValueProperty(
528 m_target.data(), core, valueTypeData, context(), flags);
529 }
else if (isUndefined && type == QMetaType::QVariant) {
530 QQmlPropertyPrivate::writeValueProperty(m_target.data(), core, valueTypeData, QVariant(), context(), flags);
531 }
else if (metaType == QMetaType::fromType<QJSValue>()) {
532 const QV4::FunctionObject *f = result.as<QV4::FunctionObject>();
533 if (f && f->isBinding()) {
534 delayedError()->setErrorDescription(QLatin1String(
"Invalid use of Qt.binding() in a binding declaration."));
537 QQmlPropertyPrivate::writeValueProperty(
538 m_target.data(), core, valueTypeData,
539 QVariant::fromValue(QJSValuePrivate::fromReturnedValue(result.asReturnedValue())),
541 }
else if (isUndefined) {
542 const char *name = QMetaType(type).name();
543 const QLatin1String typeName(name ? name :
"[unknown property type]");
544 delayedError()->setErrorDescription(QLatin1String(
"Unable to assign [undefined] to ")
547 }
else if (
const QV4::FunctionObject *f = result.as<QV4::FunctionObject>();
548 f && !f->as<QV4::QQmlTypeWrapper>()) {
550 delayedError()->setErrorDescription(QLatin1String(
"Invalid use of Qt.binding() in a binding declaration."));
552 delayedError()->setErrorDescription(QLatin1String(
"Unable to assign a function to a property of any type other than var."));
554 }
else if (!QQmlPropertyPrivate::writeValueProperty(m_target.data(), core, valueTypeData, value, context(), flags)) {
556 if (watcher.wasDeleted())
558 handleWriteError(value.constData(), value.metaType(), metaType);
565void QQmlBinding::handleWriteError(
const void *result, QMetaType resultType, QMetaType metaType)
567 const char *valueType =
nullptr;
568 const char *propertyType =
nullptr;
570 if (resultType.flags() & QMetaType::PointerToQObject) {
571 if (QObject *o = *(QObject *
const *)result) {
572 valueType = o->metaObject()->className();
573 QQmlMetaObject propertyMetaObject = QQmlPropertyPrivate::rawMetaObjectForType(metaType);
574 if (!propertyMetaObject.isNull())
575 propertyType = propertyMetaObject.className();
577 }
else if (resultType.isValid()) {
578 if (resultType == QMetaType::fromType<std::nullptr_t>()
579 || resultType == QMetaType::fromType<
void *>()) {
582 valueType = resultType.name();
587 valueType =
"undefined";
589 propertyType = metaType.name();
591 propertyType =
"[unknown property type]";
593 delayedError()->setErrorDescription(QStringLiteral(
"Unable to assign ")
594 + QString::fromUtf8(valueType)
595 + QStringLiteral(
" to ")
596 + QString::fromUtf8(propertyType));
599QVariant QQmlBinding::evaluate()
601 QQmlEngine *qmlEngine = engine();
602 QQmlEnginePrivate *ep = QQmlEnginePrivate::get(qmlEngine);
603 ep->referenceScarceResources();
605 bool isUndefined =
false;
607 QV4::Scope scope(qmlEngine->handle());
608 QV4::ScopedValue result(scope, QQmlJavaScriptExpression::evaluate(&isUndefined));
610 ep->dereferenceScarceResources();
612 return QV4::ExecutionEngine::toVariant(result, QMetaType::fromType<QList<QObject*> >());
615void QQmlBinding::expressionChanged()
620void QQmlBinding::refresh()
625void QQmlBinding::setEnabled(
bool e, QQmlPropertyData::WriteFlags flags)
627 const bool wasEnabled = enabledFlag();
629 setNotifyOnValueChanged(e);
630 updateCanUseAccessor();
632 if (e && !wasEnabled)
636QString QQmlBinding::expression()
const
638 return QStringLiteral(
"function() { [native code] }");
641QVector<QQmlProperty> QQmlBinding::dependencies()
const
643 QVector<QQmlProperty> dependencies;
644 if (!m_target.data())
647 for (QQmlJavaScriptExpressionGuard *guard = activeGuards.first(); guard; guard = activeGuards.next(guard)) {
648 if (guard->signalIndex() == -1)
651 QObject *senderObject = guard->senderAsObject();
655 const QMetaObject *senderMeta = senderObject->metaObject();
659 for (
int i = 0; i < senderMeta->propertyCount(); i++) {
660 QMetaProperty property = senderMeta->property(i);
661 if (property.notifySignalIndex() == QMetaObjectPrivate::signal(senderMeta, guard->signalIndex()).methodIndex()) {
662 dependencies.push_back(QQmlProperty(senderObject, QString::fromUtf8(property.name())));
667 for (
auto trigger = qpropertyChangeTriggers; trigger; trigger = trigger->next) {
668 QMetaProperty prop = trigger->property();
670 dependencies.push_back(QQmlProperty(trigger->target, QString::fromUtf8(prop.name())));
676bool QQmlBinding::hasDependencies()
const
678 return !activeGuards.isEmpty() || qpropertyChangeTriggers;
681void QQmlBinding::doUpdate(
const DeleteWatcher &watcher, QQmlPropertyData::WriteFlags flags, QV4::Scope &scope)
683 auto ep = QQmlEnginePrivate::get(scope.engine);
684 ep->referenceScarceResources();
687 auto canWrite = [&]() {
return !watcher.wasDeleted() && isAddedToObject() && !hasError(); };
688 const QV4::Function *v4Function = function();
689 if (v4Function && v4Function->kind == QV4::Function::AotCompiled && !hasBoundFunction()) {
690 const auto returnType = v4Function->aotCompiledFunction.types[0];
691 if (returnType == QMetaType::fromType<QVariant>()) {
693 const bool isUndefined = !evaluate(&result, returnType);
695 error = !write(result.data(), result.metaType(), isUndefined, flags);
697 const auto size = returnType.sizeOf();
698 if (Q_LIKELY(size > 0)) {
699 Q_ALLOCA_VAR(
void, result, size);
700 if (returnType.flags() & QMetaType::NeedsConstruction)
701 returnType.construct(result);
702 const bool isUndefined = !evaluate(result, returnType);
704 error = !write(result, returnType, isUndefined, flags);
705 if (returnType.flags() & QMetaType::NeedsDestruction)
706 returnType.destruct(result);
707 }
else if (canWrite()) {
708 error = !write(QV4::Value::undefinded(),
true, flags);
712 bool isUndefined =
false;
713 QV4::ScopedValue result(scope, evaluate(&isUndefined));
715 error = !write(result, isUndefined, flags);
718 if (!watcher.wasDeleted()) {
721 delayedError()->setErrorLocation(sourceLocation());
722 delayedError()->setErrorObject(m_target.data());
726 if (!delayedError()->addError(ep)) ep->warning(
this->error(engine()));
732 ep->dereferenceScarceResources();
737 QQmlMetaObject targetMetaObject;
746 QQmlPropertyData::WriteFlags flags)
override final
748 const QQmlPropertyData *pd;
749 QQmlPropertyData vtpd;
750 getPropertyData(&pd, &vtpd);
751 if (Q_UNLIKELY(isUndefined || vtpd.isValid()))
752 return slowWrite(*pd, vtpd, result, type, isUndefined, flags);
755 QObject *resultObject =
nullptr;
756 QQmlMetaObject resultMo;
757 const auto typeFlags = type.flags();
758 if (!result || ((typeFlags & QMetaType::IsPointer) && !*
static_cast<
void **>(result))) {
760 return pd->writeProperty(targetObject(), &resultObject, flags);
761 }
else if (typeFlags & QMetaType::PointerToQObject) {
762 resultObject = *
static_cast<QObject **>(result);
764 return pd->writeProperty(targetObject(), &resultObject, flags);
765 if (QQmlData *ddata = QQmlData::get(resultObject,
false))
766 resultMo = ddata->propertyCache;
767 if (resultMo.isNull())
768 resultMo = resultObject->metaObject();
769 }
else if (type == QMetaType::fromType<QVariant>()) {
770 const QVariant value = *
static_cast<QVariant *>(result);
771 resultMo = QQmlPropertyPrivate::rawMetaObjectForType(value.metaType());
772 if (resultMo.isNull())
773 return slowWrite(*pd, vtpd, result, type, isUndefined, flags);
774 resultObject = *
static_cast<QObject *
const *>(value.constData());
776 return slowWrite(*pd, vtpd, result, type, isUndefined, flags);
779 return compareAndSet(resultMo, resultObject, pd, flags, [&]() {
780 return slowWrite(*pd, vtpd, result, type, isUndefined, flags);
785 QQmlPropertyData::WriteFlags flags)
override final
787 const QQmlPropertyData *pd;
788 QQmlPropertyData vtpd;
789 getPropertyData(&pd, &vtpd);
790 if (Q_UNLIKELY(isUndefined || vtpd.isValid()))
791 return slowWrite(*pd, vtpd, result, isUndefined, flags);
794 QObject *resultObject =
nullptr;
795 QQmlMetaObject resultMo;
796 if (result.isNull()) {
798 return pd->writeProperty(targetObject(), &resultObject, flags);
799 }
else if (
auto wrapper = result.as<QV4::QObjectWrapper>()) {
800 resultObject = wrapper->object();
802 return pd->writeProperty(targetObject(), &resultObject, flags);
803 if (QQmlData *ddata = QQmlData::get(resultObject,
false))
804 resultMo = ddata->propertyCache;
805 if (resultMo.isNull()) {
806 resultMo = resultObject->metaObject();
808 }
else if (
auto variant = result.as<QV4::VariantObject>()) {
809 const QVariant value = variant->d()->data();
810 resultMo = QQmlPropertyPrivate::rawMetaObjectForType(value.metaType());
811 if (resultMo.isNull())
812 return slowWrite(*pd, vtpd, result, isUndefined, flags);
813 resultObject = *
static_cast<QObject *
const *>(value.constData());
815 return slowWrite(*pd, vtpd, result, isUndefined, flags);
818 return compareAndSet(resultMo, resultObject, pd, flags, [&]() {
819 return slowWrite(*pd, vtpd, result, isUndefined, flags);
826 template<
typename SlowWrite>
827 bool compareAndSet(
const QQmlMetaObject &resultMo, QObject *resultObject,
const QQmlPropertyData *pd,
828 QQmlPropertyData::WriteFlags flags,
const SlowWrite &slowWrite)
const
830 if (QQmlMetaObject::canConvert(resultMo, targetMetaObject)) {
831 return pd->writeProperty(targetObject(), &resultObject, flags);
832 }
else if (!resultObject && QQmlMetaObject::canConvert(targetMetaObject, resultMo)) {
836 return pd->writeProperty(targetObject(), &resultObject, flags);
843QQmlBinding *QQmlBinding::newBinding(
const QQmlPropertyData *property)
845 return newBinding(property ? property->propType() : QMetaType());
848QQmlBinding *QQmlBinding::newBinding(QMetaType propertyType)
850 if (propertyType.flags() & QMetaType::PointerToQObject)
851 return new QObjectPointerBinding(propertyType);
853 switch (propertyType.id()) {
854 case QMetaType::Bool:
855 return new GenericBinding<QMetaType::Bool>;
857 return new GenericBinding<QMetaType::Int>;
858 case QMetaType::Double:
859 return new GenericBinding<QMetaType::Double>;
860 case QMetaType::Float:
861 return new GenericBinding<QMetaType::Float>;
862 case QMetaType::QString:
863 return new GenericBinding<QMetaType::QString>;
865 return new GenericBinding<QMetaType::UnknownType>;
Q_ALWAYS_INLINE bool write(const QV4::Value &result, bool isUndefined, QQmlPropertyData::WriteFlags flags) override final
Q_ALWAYS_INLINE bool write(void *result, QMetaType type, bool isUndefined, QQmlPropertyData::WriteFlags flags) override final
Q_ALWAYS_INLINE bool doStore(T value, const QQmlPropertyData *pd, QQmlPropertyData::WriteFlags flags) const
QObjectPointerBinding(QMetaType propertyType)
Q_ALWAYS_INLINE bool write(const QV4::Value &result, bool isUndefined, QQmlPropertyData::WriteFlags flags) override final
Q_ALWAYS_INLINE bool write(void *result, QMetaType type, bool isUndefined, QQmlPropertyData::WriteFlags flags) override final
QString bindingValue() const override
QQmlSourceLocation sourceLocation() const override final
QQmlTranslationBindingFromBinding(const QQmlRefPointer< QV4::ExecutableCompilationUnit > &compilationUnit, const QV4::CompiledData::Binding *binding)
QQmlSourceLocation sourceLocation() const override final
QQmlTranslationBindingFromTranslationInfo(const QQmlRefPointer< QV4::ExecutableCompilationUnit > &compilationUnit, const QQmlTranslation &translationData, quint16 line, quint16 column)
virtual QString bindingValue() const override
QQmlTranslationBinding(const QQmlRefPointer< QV4::ExecutableCompilationUnit > &compilationUnit)
void doUpdate(const DeleteWatcher &watcher, QQmlPropertyData::WriteFlags flags, QV4::Scope &scope) override final
static void onLanguageChange(QPropertyObserver *observer, QUntypedPropertyData *)
virtual QString bindingValue() const =0
bool hasDependencies() const override final
Combined button and popup list for selecting options.