vp->putIndexed(id, sv);
}
+void QQmlVMEMetaObject::writeProperty(int id, QObject* v)
+{
+ if (!ensurePropertiesAllocated())
+ return;
+
+ QV4::Scope scope(properties.engine());
+ QV4::ScopedObject vp(scope, properties.value());
+
+ QQmlEnginePrivate *ep = QQmlEnginePrivate::get(ctxt->engine);
+ QV4::ExecutionEngine *v4 = ep->v4engine();
+ vp->putIndexed(id, QV4::ScopedObject(scope, QV4::QObjectWrapper::wrap(v4, v)));
+
+ QQmlVMEVariantQObjectPtr *guard = getQObjectGuardForProperty(id);
+ if (v && !guard) {
+ guard = new QQmlVMEVariantQObjectPtr(true);
+ varObjectGuards.append(guard);
+ }
+ if (guard)
+ guard->setGuardedValue(v, this, id);
+}
+
int QQmlVMEMetaObject::readPropertyAsInt(int id)
{
if (!ensurePropertiesAllocated())
return v->d()->data.value<QPointF>();
}
+QObject* QQmlVMEMetaObject::readPropertyAsQObject(int id)
+{
+ if (!ensurePropertiesAllocated())
+ return 0;
+
+ QV4::Scope scope(properties.engine());
+ QV4::ScopedObject vp(scope, properties.value());
+ QV4::ScopedValue sv(scope, vp->getIndexed(id));
+ const QV4::QObjectWrapper *wrapper = sv->as<QV4::QObjectWrapper>();
+ if (!wrapper) {
+ writeProperty(id, static_cast<QObject*>(Q_NULLPTR));
+ return 0;
+ }
+ return wrapper->object();
+}
+
QRectF QQmlVMEMetaObject::readPropertyAsRectF(int id)
{
if (!ensurePropertiesAllocated())
*reinterpret_cast<QPointF *>(a[0]) = readPropertyAsPointF(id);
break;
case QMetaType::QObjectStar:
- *reinterpret_cast<QObject **>(a[0]) = data[id].asQObject();
+ *reinterpret_cast<QObject **>(a[0]) = readPropertyAsQObject(id);
break;
case QMetaType::QVariant:
*reinterpret_cast<QVariant *>(a[0]) = readPropertyAsVariant(id);
writeProperty(id, *reinterpret_cast<QPointF *>(a[0]));
break;
case QMetaType::QObjectStar:
- needActivate = *reinterpret_cast<QObject **>(a[0]) != data[id].asQObject();
- data[id].setValue(*reinterpret_cast<QObject **>(a[0]), this, id);
+ needActivate = *reinterpret_cast<QObject **>(a[0]) != readPropertyAsQObject(id);
+ writeProperty(id, *reinterpret_cast<QObject **>(a[0]));
break;
case QMetaType::QVariant:
writeProperty(id, *reinterpret_cast<QVariant *>(a[0]));
}
return QVariant();
} else {
- if (data[id].dataType() == QMetaType::QObjectStar) {
- return QVariant::fromValue(data[id].asQObject());
- } else {
- return data[id].asQVariant();
+ if (ensurePropertiesAllocated()) {
+ QV4::ExecutionEngine *v4 = properties.engine();
+ QV4::Scope scope(v4);
+ QV4::ScopedObject o(scope, properties.value());
+ QV4::ScopedValue sv(scope, o->getIndexed(id));
+ const QV4::QObjectWrapper *wrapper = sv->as<QV4::QObjectWrapper>();
+ if (wrapper)
+ return QVariant::fromValue(wrapper->object());
}
+ return data[id].asQVariant();
}
}
bool needActivate = false;
if (value.userType() == QMetaType::QObjectStar) {
QObject *o = *(QObject *const *)value.data();
- needActivate = (data[id].dataType() != QMetaType::QObjectStar || data[id].asQObject() != o);
- data[id].setValue(o, this, id);
+ needActivate = readPropertyAsQObject(id) != o; // TODO: still correct?
+ writeProperty(id, o);
} else {
needActivate = (data[id].dataType() != qMetaTypeId<QVariant>() ||
data[id].asQVariant().userType() != value.userType() ||
properties.markOnce(e);
- // add references created by VMEVariant properties
- int maxDataIdx = metaData->propertyCount - metaData->varPropertyCount;
- for (int ii = 0; ii < maxDataIdx; ++ii) { // XXX TODO: optimize?
- if (data[ii].dataType() == QMetaType::QObjectStar) {
- // possible QObject reference.
- if (QObject *ref = data[ii].asQObject())
- QV4::QObjectWrapper::markWrapper(ref, e);
- }
- }
-
if (QQmlVMEMetaObject *parent = parentVMEMetaObject())
parent->mark(e);
}
inline void setGuardedValue(QObject *obj, QQmlVMEMetaObject *target, int index);
QQmlVMEMetaObject *m_target;
- unsigned m_isVar : 1;
+ unsigned m_isVar : 1; // TODO: remove?
int m_index : 31;
};
QDate readPropertyAsDate(int id);
QDateTime readPropertyAsDateTime(int id);
QRectF readPropertyAsRectF(int id);
+ QObject* readPropertyAsQObject(int id);
void writeProperty(int id, int v);
void writeProperty(int id, bool v);
void writeProperty(int id, const QDate& v);
void writeProperty(int id, const QDateTime& v);
void writeProperty(int id, const QRectF& v);
+ void writeProperty(int id, QObject *v);
void ensureQObjectWrapper();