예제 #1
0
QQmlListReference QQmlListReferencePrivate::init(const QQmlListProperty<QObject> &prop, int propType, QQmlEngine *engine)
{
    QQmlListReference rv;

    if (!prop.object) return rv;

    QQmlEnginePrivate *p = engine?QQmlEnginePrivate::get(engine):0;

    int listType = p?p->listType(propType):QQmlMetaType::listType(propType);
    if (listType == -1) return rv;

    rv.d = new QQmlListReferencePrivate;
    rv.d->object = prop.object;
    rv.d->elementType = QQmlPropertyPrivate::rawMetaObjectForType(p, listType);
    rv.d->property = prop;
    rv.d->propertyType = propType;

    return rv;
}
예제 #2
0
/*!
Constructs a QQmlListReference for \a object's \a property.  If \a property is not a list
property, an invalid QQmlListReference is created.  If \a object is destroyed after
the reference is constructed, it will automatically become invalid.  That is, it is safe to hold
QQmlListReference instances even after \a object is deleted.

Passing \a engine is required to access some QML created list properties.  If in doubt, and an engine
is available, pass it.
*/
QQmlListReference::QQmlListReference(QObject *object, const char *property, QQmlEngine *engine)
: d(0)
{
    if (!object || !property) return;

    QQmlPropertyData local;
    QQmlPropertyData *data =
        QQmlPropertyCache::property(engine, object, QLatin1String(property), 0, local);

    if (!data || !data->isQList()) return;

    QQmlEnginePrivate *p = engine?QQmlEnginePrivate::get(engine):0;

    int listType = p?p->listType(data->propType()):QQmlMetaType::listType(data->propType());
    if (listType == -1) return;

    d = new QQmlListReferencePrivate;
    d->object = object;
    d->elementType = p ? p->rawMetaObjectForType(listType) : QQmlMetaType::qmlType(listType).baseMetaObject();
    d->propertyType = data->propType();

    void *args[] = { &d->property, 0 };
    QMetaObject::metacall(object, QMetaObject::ReadProperty, data->coreIndex(), args);
}