From e82735cb4d65025693204346e0e0359da0afd6c3 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 26 Aug 2009 09:08:24 +1000 Subject: Update docs to reflect layouts renaming --- doc/src/declarative/anchor-layout.qdoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/src/declarative/anchor-layout.qdoc b/doc/src/declarative/anchor-layout.qdoc index 69e2eda..5b2f068 100644 --- a/doc/src/declarative/anchor-layout.qdoc +++ b/doc/src/declarative/anchor-layout.qdoc @@ -3,11 +3,11 @@ \target anchor-layout \title Anchor-based Layout -In additional to the more traditional Fx layouts GridLayout, HorizontalLayout, and VerticalLayout, QML also provides a way to layout items using the concept of anchors. Each visual Fx item can be thought of as having a set of 6 invisible "anchor lines": \e left, \e horizontalCenter, \e right, \e top, \e verticalCenter, and \e bottom. +In additional to the more traditional layouts Grid, Row, and Column, QML also provides a way to layout items using the concept of anchors. Each visual item can be thought of as having a set of 6 invisible "anchor lines": \e left, \e horizontalCenter, \e right, \e top, \e verticalCenter, and \e bottom. \image edges_qml.png -The Fx anchoring system allows you to define relationships between the anchor lines of different items. For example, you can write: +The anchoring system allows you to define relationships between the anchor lines of different items. For example, you can write: \code Rectangle { id: rect1; ... } -- cgit v0.12 From a488a04e5a5af4255d560d5dfa6423caa48ed5f3 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 27 Aug 2009 11:01:55 +1000 Subject: Make QmlPropertyValueSource an interface. 1st step in animation class heirarchy redesign. --- src/declarative/extra/qmlbehaviour.cpp | 2 +- src/declarative/extra/qmlbehaviour.h | 2 +- src/declarative/qml/qml.h | 1 + src/declarative/qml/qmlcompiler.cpp | 29 ++++++++----------------- src/declarative/qml/qmlinstruction.cpp | 2 +- src/declarative/qml/qmlinstruction_p.h | 1 + src/declarative/qml/qmlmetatype.cpp | 30 ++++++++++++++++++++------ src/declarative/qml/qmlmetatype.h | 20 +++++++++++------ src/declarative/qml/qmlpropertyvaluesource.cpp | 22 +++---------------- src/declarative/qml/qmlpropertyvaluesource.h | 23 +++++--------------- src/declarative/qml/qmlvme.cpp | 9 ++++---- src/declarative/util/qmlanimation.cpp | 4 ++-- src/declarative/util/qmlanimation.h | 2 +- src/declarative/util/qmlfollow.cpp | 2 +- src/declarative/util/qmlfollow.h | 3 ++- 15 files changed, 70 insertions(+), 82 deletions(-) diff --git a/src/declarative/extra/qmlbehaviour.cpp b/src/declarative/extra/qmlbehaviour.cpp index 767f1ed..5401b0d 100644 --- a/src/declarative/extra/qmlbehaviour.cpp +++ b/src/declarative/extra/qmlbehaviour.cpp @@ -122,7 +122,7 @@ public: */ QmlBehaviour::QmlBehaviour(QObject *parent) -: QmlPropertyValueSource(*(new QmlBehaviourPrivate), parent) +: QObject(*(new QmlBehaviourPrivate), parent) { Q_D(QmlBehaviour); d->group = new QParallelAnimationGroup; diff --git a/src/declarative/extra/qmlbehaviour.h b/src/declarative/extra/qmlbehaviour.h index 99fc779..b33d72a 100644 --- a/src/declarative/extra/qmlbehaviour.h +++ b/src/declarative/extra/qmlbehaviour.h @@ -54,7 +54,7 @@ QT_MODULE(Declarative) class QmlAbstractAnimation; class QmlBehaviourPrivate; -class Q_DECLARATIVE_EXPORT QmlBehaviour : public QmlPropertyValueSource +class Q_DECLARATIVE_EXPORT QmlBehaviour : public QObject, public QmlPropertyValueSource { Q_OBJECT Q_DECLARE_PRIVATE(QmlBehaviour) diff --git a/src/declarative/qml/qml.h b/src/declarative/qml/qml.h index bced8f2..23f2f1e 100644 --- a/src/declarative/qml/qml.h +++ b/src/declarative/qml/qml.h @@ -50,6 +50,7 @@ #include #include #include +#include #include QT_BEGIN_HEADER diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp index bbcc64d..3af7137 100644 --- a/src/declarative/qml/qmlcompiler.cpp +++ b/src/declarative/qml/qmlcompiler.cpp @@ -1411,7 +1411,6 @@ void QmlCompiler::genPropertyAssignment(QmlParser::Property *prop, } } else if (v->type == Value::ValueSource) { - genObject(v->object); QmlInstruction store; @@ -1425,6 +1424,8 @@ void QmlCompiler::genPropertyAssignment(QmlParser::Property *prop, QmlMetaPropertyPrivate::saveProperty(prop->index); store.assignValueSource.owner = 0; } + QmlType *valueType = QmlMetaType::qmlType(v->object->metatype); + store.assignValueSource.castValue = valueType->propertyValueSourceCast(); output->bytecode << store; } else if (v->type == Value::PropertyBinding) { @@ -1584,15 +1585,7 @@ bool QmlCompiler::buildValueTypeProperty(QObject *type, Value *value = prop->values.at(0); if (value->object) { - const QMetaObject *c = - output->types.at(value->object->type).metaObject(); - bool isPropertyValue = false; - while (c && !isPropertyValue) { - isPropertyValue = - (c == &QmlPropertyValueSource::staticMetaObject); - c = c->superClass(); - } - + bool isPropertyValue = output->types.at(value->object->type).type->propertyValueSourceCast() != -1; if (!isPropertyValue) { COMPILE_EXCEPTION(prop, "Invalid property use"); } else { @@ -1762,30 +1755,26 @@ bool QmlCompiler::buildPropertyObjectAssignment(QmlParser::Property *prop, v->object->metatype = output->types.at(v->object->type).metaObject(); Q_ASSERT(v->object->metaObject()); + // Will be true if the assigned type inherits QmlPropertyValueSource + bool isPropertyValue = false; + if (QmlType *valueType = QmlMetaType::qmlType(v->object->metatype)) + isPropertyValue = valueType->propertyValueSourceCast() != -1; + // We want to raw metaObject here as the raw metaobject is the // actual property type before we applied any extensions that might // effect the properties on the type, but don't effect assignability const QMetaObject *propertyMetaObject = QmlMetaType::rawMetaObjectForType(prop->type); - // Will be true if the assigned type inherits QmlPropertyValueSource - bool isPropertyValue = false; // Will be true if the assgned type inherits propertyMetaObject bool isAssignable = false; - // Determine isPropertyValue and isAssignable values + // Determine isAssignable value if (propertyMetaObject) { const QMetaObject *c = v->object->metatype; while(c) { - isPropertyValue |= (c == &QmlPropertyValueSource::staticMetaObject); isAssignable |= (c == propertyMetaObject); c = c->superClass(); } - } else { - const QMetaObject *c = v->object->metatype; - while(!isPropertyValue && c) { - isPropertyValue |= (c == &QmlPropertyValueSource::staticMetaObject); - c = c->superClass(); - } } if (isAssignable) { diff --git a/src/declarative/qml/qmlinstruction.cpp b/src/declarative/qml/qmlinstruction.cpp index 02e4883..b71c6e3 100644 --- a/src/declarative/qml/qmlinstruction.cpp +++ b/src/declarative/qml/qmlinstruction.cpp @@ -147,7 +147,7 @@ void QmlCompiledData::dump(QmlInstruction *instr, int idx) qWarning() << idx << "\t" << line << "\t" << "STORE_COMPILED_BINDING\t" << instr->assignBinding.property << "\t" << instr->assignBinding.value << "\t\t" << instr->assignBinding.context; break; case QmlInstruction::StoreValueSource: - qWarning() << idx << "\t" << line << "\t" << "STORE_VALUE_SOURCE\t" << instr->assignValueSource.property; + qWarning() << idx << "\t" << line << "\t" << "STORE_VALUE_SOURCE\t" << instr->assignValueSource.property << "\t" << instr->assignValueSource.castValue; break; case QmlInstruction::BeginObject: qWarning() << idx << "\t" << line << "\t" << "BEGIN\t\t\t" << instr->begin.castValue; diff --git a/src/declarative/qml/qmlinstruction_p.h b/src/declarative/qml/qmlinstruction_p.h index 0f2995a..8861609a 100644 --- a/src/declarative/qml/qmlinstruction_p.h +++ b/src/declarative/qml/qmlinstruction_p.h @@ -183,6 +183,7 @@ public: struct { int property; int owner; + int castValue; } assignValueSource; struct { int property; diff --git a/src/declarative/qml/qmlmetatype.cpp b/src/declarative/qml/qmlmetatype.cpp index ab64079..c488c13 100644 --- a/src/declarative/qml/qmlmetatype.cpp +++ b/src/declarative/qml/qmlmetatype.cpp @@ -120,6 +120,7 @@ public: QmlAttachedPropertiesFunc m_attachedPropertiesFunc; const QMetaObject *m_attachedPropertiesType; int m_parserStatusCast; + int m_propertyValueSourceCast; QmlPrivate::CreateFunc m_extFunc; const QMetaObject *m_extMetaObject; int m_index; @@ -132,8 +133,8 @@ public: QmlTypePrivate::QmlTypePrivate() : m_isInterface(false), m_iid(0), m_typeId(0), m_listId(0), m_qmlListId(0), m_opFunc(0), m_baseMetaObject(0), m_attachedPropertiesFunc(0), m_attachedPropertiesType(0), - m_parserStatusCast(-1), m_extFunc(0), m_extMetaObject(0), m_index(-1), - m_customParser(0), m_isSetup(false) + m_parserStatusCast(-1), m_propertyValueSourceCast(-1), m_extFunc(0), m_extMetaObject(0), + m_index(-1), m_customParser(0), m_isSetup(false) { } @@ -161,7 +162,7 @@ QmlType::QmlType(int type, int listType, int qmlListType, const QMetaObject *metaObject, QmlAttachedPropertiesFunc attachedPropertiesFunc, const QMetaObject *attachedType, - int parserStatusCast, QmlPrivate::CreateFunc extFunc, + int parserStatusCast, int propertyValueSourceCast, QmlPrivate::CreateFunc extFunc, const QMetaObject *extMetaObject, int index, QmlCustomParser *customParser) : d(new QmlTypePrivate) @@ -178,6 +179,7 @@ QmlType::QmlType(int type, int listType, int qmlListType, d->m_attachedPropertiesFunc = attachedPropertiesFunc; d->m_attachedPropertiesType = attachedType; d->m_parserStatusCast = parserStatusCast; + d->m_propertyValueSourceCast = propertyValueSourceCast; d->m_extFunc = extFunc; d->m_index = index; d->m_customParser = customParser; @@ -397,6 +399,11 @@ int QmlType::parserStatusCast() const return d->m_parserStatusCast; } +int QmlType::propertyValueSourceCast() const +{ + return d->m_propertyValueSourceCast; +} + QVariant QmlType::fromObject(QObject *obj) const { QVariant rv; @@ -452,7 +459,7 @@ int QmlMetaType::registerInterface(const QmlPrivate::MetaTypeIds &id, int QmlMetaType::registerType(const QmlPrivate::MetaTypeIds &id, QmlPrivate::Func func, const char *uri, int version_maj, int version_min_from, int version_min_to, const char *cname, const QMetaObject *mo, QmlAttachedPropertiesFunc attach, const QMetaObject *attachMo, - int pStatus, int object, QmlPrivate::CreateFunc extFunc, const QMetaObject *extmo, QmlCustomParser *parser) + int pStatus, int object, int valueSource, QmlPrivate::CreateFunc extFunc, const QMetaObject *extmo, QmlCustomParser *parser) { Q_UNUSED(object); @@ -476,8 +483,8 @@ int QmlMetaType::registerType(const QmlPrivate::MetaTypeIds &id, QmlPrivate::Fun name.replace('.','/'); QmlType *type = new QmlType(id.typeId, id.listId, id.qmlListId, - func, name, version_maj, version_min_from, version_min_to, mo, attach, attachMo, pStatus, extFunc, - extmo, index, parser); + func, name, version_maj, version_min_from, version_min_to, mo, attach, attachMo, pStatus, + valueSource, extFunc, extmo, index, parser); data->types.append(type); data->idToType.insert(type->typeId(), type); @@ -513,6 +520,17 @@ int QmlMetaType::qmlParserStatusCast(int userType) return -1; } +int QmlMetaType::qmlPropertyValueSourceCast(int userType) +{ + QReadLocker lock(metaTypeDataLock()); + QmlMetaTypeData *data = metaTypeData(); + QmlType *type = data->idToType.value(userType); + if (type && type->typeId() == userType) + return type->propertyValueSourceCast(); + else + return -1; +} + QObject *QmlMetaType::toQObject(const QVariant &v) { if (!isObject(v.userType())) diff --git a/src/declarative/qml/qmlmetatype.h b/src/declarative/qml/qmlmetatype.h index c388b1a..5ed9a5a 100644 --- a/src/declarative/qml/qmlmetatype.h +++ b/src/declarative/qml/qmlmetatype.h @@ -47,6 +47,7 @@ #include #include #include +#include QT_BEGIN_HEADER @@ -59,7 +60,7 @@ class QmlCustomParser; class Q_DECLARATIVE_EXPORT QmlMetaType { public: - static int registerType(const QmlPrivate::MetaTypeIds &, QmlPrivate::Func, const char *, int vmaj, int vmin_from, int vmin_to, const char *qmlName, const QMetaObject *, QmlAttachedPropertiesFunc, const QMetaObject *, int pStatus, int object, QmlPrivate::CreateFunc extFunc, const QMetaObject *extmo, QmlCustomParser *); + static int registerType(const QmlPrivate::MetaTypeIds &, QmlPrivate::Func, const char *, int vmaj, int vmin_from, int vmin_to, const char *qmlName, const QMetaObject *, QmlAttachedPropertiesFunc, const QMetaObject *, int pStatus, int object, int valueSource, QmlPrivate::CreateFunc extFunc, const QMetaObject *extmo, QmlCustomParser *); static int registerInterface(const QmlPrivate::MetaTypeIds &, QmlPrivate::Func, const char *); static bool copy(int type, void *data, const void *copy = 0); @@ -78,6 +79,7 @@ public: static QMetaProperty property(QObject *, const char *); static QObject *toQObject(const QVariant &); static int qmlParserStatusCast(int); + static int qmlPropertyValueSourceCast(int); static int listType(int); static bool clear(const QVariant &); static bool append(const QVariant &, const QVariant &); @@ -143,13 +145,14 @@ public: int parserStatusCast() const; QVariant fromObject(QObject *) const; const char *interfaceIId() const; + int propertyValueSourceCast() const; int index() const; private: friend class QmlMetaType; friend class QmlTypePrivate; QmlType(int, int, int, QmlPrivate::Func, const char *, int); - QmlType(int, int, int, QmlPrivate::Func, const char *, int, int, int, const QMetaObject *, QmlAttachedPropertiesFunc, const QMetaObject *, int, QmlPrivate::CreateFunc, const QMetaObject *, int, QmlCustomParser *); + QmlType(int, int, int, QmlPrivate::Func, const char *, int, int, int, const QMetaObject *, QmlAttachedPropertiesFunc, const QMetaObject *, int, int, QmlPrivate::CreateFunc, const QMetaObject *, int, QmlCustomParser *); ~QmlType(); QmlTypePrivate *d; @@ -170,7 +173,8 @@ int qmlRegisterType(const char *typeName) QmlPrivate::attachedPropertiesFunc(), QmlPrivate::attachedPropertiesMetaObject(), QmlPrivate::StaticCastSelector::cast(), - QmlPrivate::StaticCastSelector::cast(), + QmlPrivate::StaticCastSelector::cast(), + QmlPrivate::StaticCastSelector::cast(), 0, 0, 0); } @@ -191,6 +195,7 @@ int qmlRegisterType(const char *uri, int version_maj, int version_min_from, int QmlPrivate::attachedPropertiesMetaObject(), QmlPrivate::StaticCastSelector::cast(), QmlPrivate::StaticCastSelector::cast(), + QmlPrivate::StaticCastSelector::cast(), 0, 0, 0); } @@ -216,7 +221,8 @@ int qmlRegisterExtendedType(const char *typeName) return QmlMetaType::registerType(ids, QmlPrivate::list_nocreate_op, 0, 0, 0, 0, 0, &T::staticMetaObject, attached, attachedMo, QmlPrivate::StaticCastSelector::cast(), - QmlPrivate::StaticCastSelector::cast(), + QmlPrivate::StaticCastSelector::cast(), + QmlPrivate::StaticCastSelector::cast(), &QmlPrivate::CreateParent::create, &E::staticMetaObject, 0); } @@ -244,7 +250,8 @@ int qmlRegisterExtendedType(const char *uri, int version_maj, int version_min_fr &T::staticMetaObject, attached, attachedMo, QmlPrivate::StaticCastSelector::cast(), - QmlPrivate::StaticCastSelector::cast(), + QmlPrivate::StaticCastSelector::cast(), + QmlPrivate::StaticCastSelector::cast(), &QmlPrivate::CreateParent::create, &E::staticMetaObject, 0); } @@ -280,7 +287,8 @@ int qmlRegisterCustomType(const char *uri, int version_maj, int version_min_from QmlPrivate::attachedPropertiesFunc(), QmlPrivate::attachedPropertiesMetaObject(), QmlPrivate::StaticCastSelector::cast(), - QmlPrivate::StaticCastSelector::cast(), + QmlPrivate::StaticCastSelector::cast(), + QmlPrivate::StaticCastSelector::cast(), 0, 0, parser); } diff --git a/src/declarative/qml/qmlpropertyvaluesource.cpp b/src/declarative/qml/qmlpropertyvaluesource.cpp index c6ff596..429080b 100644 --- a/src/declarative/qml/qmlpropertyvaluesource.cpp +++ b/src/declarative/qml/qmlpropertyvaluesource.cpp @@ -48,34 +48,18 @@ QT_BEGIN_NAMESPACE \class QmlPropertyValueSource \brief The QmlPropertyValueSource class is inherited by property value sources such as animations and bindings. */ -QML_DEFINE_NOCREATE_TYPE(QmlPropertyValueSource) /*! - Constructs a QmlPropertyValueSource with parent \a parent. + Constructs a QmlPropertyValueSource. */ -QmlPropertyValueSource::QmlPropertyValueSource(QObject *parent) - : QObject(parent) - -{ -} - -/*! - \internal - */ -QmlPropertyValueSource::QmlPropertyValueSource(QObjectPrivate &dd, QObject *parent) - : QObject(dd, parent) +QmlPropertyValueSource::QmlPropertyValueSource() { } /*! + \fn void QmlPropertyValueSource::setTarget(const QmlMetaProperty &property) Set the target \a property for the value source. This method will be called by the QML engine when assigning a value source. - - The default implementation does nothing. */ -void QmlPropertyValueSource::setTarget(const QmlMetaProperty &property) -{ - Q_UNUSED(property); -} QT_END_NAMESPACE diff --git a/src/declarative/qml/qmlpropertyvaluesource.h b/src/declarative/qml/qmlpropertyvaluesource.h index 4e5f1c5..ee4ea2c 100644 --- a/src/declarative/qml/qmlpropertyvaluesource.h +++ b/src/declarative/qml/qmlpropertyvaluesource.h @@ -42,9 +42,7 @@ #ifndef QMLPROPERTYVALUESOURCE_H #define QMLPROPERTYVALUESOURCE_H -#include -#include -#include +#include QT_BEGIN_HEADER @@ -52,28 +50,17 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -class QObjectPrivate; class QmlMetaProperty; -class Q_DECLARATIVE_EXPORT QmlPropertyValueSource : public QObject +class Q_DECLARATIVE_EXPORT QmlPropertyValueSource { - Q_OBJECT - Q_DECLARE_PRIVATE(QObject) - public: - QmlPropertyValueSource(QObject *parent); - virtual void setTarget(const QmlMetaProperty &); - -protected: - QmlPropertyValueSource(QObjectPrivate &dd, QObject *parent); - -private: - Q_DISABLE_COPY(QmlPropertyValueSource) + QmlPropertyValueSource(); + virtual void setTarget(const QmlMetaProperty &) = 0; }; +Q_DECLARE_INTERFACE(QmlPropertyValueSource, "com.trolltech.qml.QmlPropertyValueSource") QT_END_NAMESPACE -QML_DECLARE_TYPE(QmlPropertyValueSource) - QT_END_HEADER #endif // QMLPROPERTYVALUESOURCE_H diff --git a/src/declarative/qml/qmlvme.cpp b/src/declarative/qml/qmlvme.cpp index 7455eb4..930e6e4 100644 --- a/src/declarative/qml/qmlvme.cpp +++ b/src/declarative/qml/qmlvme.cpp @@ -591,13 +591,12 @@ QObject *QmlVME::run(QStack &stack, QmlContext *ctxt, QmlCompiledData case QmlInstruction::StoreValueSource: { - QmlPropertyValueSource *vs = - static_cast(stack.pop()); - QObject *target = - stack.at(stack.count() - 1 - instr.assignValueSource.owner); + QObject *obj = stack.pop(); + QmlPropertyValueSource *vs = reinterpret_cast(reinterpret_cast(obj) + instr.assignValueSource.castValue); + QObject *target = stack.at(stack.count() - 1 - instr.assignValueSource.owner); QmlMetaProperty prop; prop.restore(instr.assignValueSource.property, target, ctxt); - vs->setParent(target); + obj->setParent(target); vs->setTarget(prop); } break; diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp index 720a045..6cc6db7 100644 --- a/src/declarative/util/qmlanimation.cpp +++ b/src/declarative/util/qmlanimation.cpp @@ -154,7 +154,7 @@ QML_DEFINE_NOCREATE_TYPE(QmlAbstractAnimation) */ QmlAbstractAnimation::QmlAbstractAnimation(QObject *parent) -: QmlPropertyValueSource(*(new QmlAbstractAnimationPrivate), parent) +: QObject(*(new QmlAbstractAnimationPrivate), parent) { } @@ -163,7 +163,7 @@ QmlAbstractAnimation::~QmlAbstractAnimation() } QmlAbstractAnimation::QmlAbstractAnimation(QmlAbstractAnimationPrivate &dd, QObject *parent) -: QmlPropertyValueSource(dd, parent) +: QObject(dd, parent) { } diff --git a/src/declarative/util/qmlanimation.h b/src/declarative/util/qmlanimation.h index f5180a5..67a2045 100644 --- a/src/declarative/util/qmlanimation.h +++ b/src/declarative/util/qmlanimation.h @@ -58,7 +58,7 @@ QT_MODULE(Declarative) class QmlAbstractAnimationPrivate; class QmlAnimationGroup; -class QmlAbstractAnimation : public QmlPropertyValueSource, public QmlParserStatus +class QmlAbstractAnimation : public QObject, public QmlPropertyValueSource, public QmlParserStatus { Q_OBJECT Q_DECLARE_PRIVATE(QmlAbstractAnimation) diff --git a/src/declarative/util/qmlfollow.cpp b/src/declarative/util/qmlfollow.cpp index eec2480..fe5303f 100644 --- a/src/declarative/util/qmlfollow.cpp +++ b/src/declarative/util/qmlfollow.cpp @@ -239,7 +239,7 @@ void QmlFollowPrivate::stop() */ QmlFollow::QmlFollow(QObject *parent) -: QmlPropertyValueSource(*(new QmlFollowPrivate),parent) +: QObject(*(new QmlFollowPrivate),parent) { } diff --git a/src/declarative/util/qmlfollow.h b/src/declarative/util/qmlfollow.h index 07b2f49..1f6376a 100644 --- a/src/declarative/util/qmlfollow.h +++ b/src/declarative/util/qmlfollow.h @@ -52,11 +52,12 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) class QmlFollowPrivate; -class Q_DECLARATIVE_EXPORT QmlFollow : public QmlPropertyValueSource, +class Q_DECLARATIVE_EXPORT QmlFollow : public QObject, public QmlPropertyValueSource, public QmlParserStatus { Q_OBJECT Q_DECLARE_PRIVATE(QmlFollow) + Q_INTERFACES(QmlPropertyValueSource) Q_INTERFACES(QmlParserStatus) Q_PROPERTY(qreal source READ sourceValue WRITE setSourceValue) -- cgit v0.12 From 0d12a574ca3624ecfe62d4183e02e43f3bfb6509 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Thu, 27 Aug 2009 11:25:21 +1000 Subject: Repeater API updates. --- examples/declarative/easing/easing.qml | 2 +- examples/declarative/follow/pong.qml | 2 +- examples/declarative/listview/itemlist.qml | 2 +- examples/declarative/minehunt/minehunt.qml | 2 +- examples/declarative/velocity/Day.qml | 2 +- examples/declarative/velocity/velocity.qml | 2 +- src/declarative/fx/qfxlistview.cpp | 2 +- src/declarative/fx/qfxrepeater.cpp | 93 ++++++++++++------------------ src/declarative/fx/qfxrepeater.h | 19 +++--- src/declarative/fx/qfxrepeater_p.h | 1 + 10 files changed, 57 insertions(+), 70 deletions(-) diff --git a/examples/declarative/easing/easing.qml b/examples/declarative/easing/easing.qml index 60c2040..df301d8 100644 --- a/examples/declarative/easing/easing.qml +++ b/examples/declarative/easing/easing.qml @@ -56,7 +56,7 @@ Rectangle { anchors.left: Window.left anchors.right: Window.right Repeater { - dataSource: EasingTypes + model: EasingTypes Component { Text { id: Text diff --git a/examples/declarative/follow/pong.qml b/examples/declarative/follow/pong.qml index d2aaba9..0314bb8 100644 --- a/examples/declarative/follow/pong.qml +++ b/examples/declarative/follow/pong.qml @@ -63,7 +63,7 @@ Rectangle { Rectangle { color: "#00ee00"; x: Page.width/2+40; y: 0; width: 40; height: 60 } Rectangle { color: "#000000"; x: Page.width/2+50; y: 10; width: 20; height: 40 } Repeater { - dataSource: Page.height/20 + model: Page.height/20 Rectangle { color: "#00ee00"; x: Page.width/2-5; y: index*20; width: 10; height: 10 } } } diff --git a/examples/declarative/listview/itemlist.qml b/examples/declarative/listview/itemlist.qml index c25ee59..061fab3 100644 --- a/examples/declarative/listview/itemlist.qml +++ b/examples/declarative/listview/itemlist.qml @@ -44,7 +44,7 @@ Rectangle { anchors.centerIn: parent spacing: 20 Repeater { - dataSource: ItemModel.count + model: ItemModel.count Rectangle { width: 5; height: 5 radius: 3 diff --git a/examples/declarative/minehunt/minehunt.qml b/examples/declarative/minehunt/minehunt.qml index 11748a8..4bae64d 100644 --- a/examples/declarative/minehunt/minehunt.qml +++ b/examples/declarative/minehunt/minehunt.qml @@ -130,7 +130,7 @@ Item { anchors.verticalCenter: parent.verticalCenter } Repeater { - dataSource: tiles + model: tiles x: 1 y: 1 Component { diff --git a/examples/declarative/velocity/Day.qml b/examples/declarative/velocity/Day.qml index e488ae1..1a336b7 100644 --- a/examples/declarative/velocity/Day.qml +++ b/examples/declarative/velocity/Day.qml @@ -26,7 +26,7 @@ Rectangle { styleColor: "#dedede" } Repeater { - dataSource: Page.stickies + model: Page.stickies Item { x: Math.random() * 200 + 100 y: Math.random() * 300 + 50 diff --git a/examples/declarative/velocity/velocity.qml b/examples/declarative/velocity/velocity.qml index c2425da..8ac42e1 100644 --- a/examples/declarative/velocity/velocity.qml +++ b/examples/declarative/velocity/velocity.qml @@ -101,7 +101,7 @@ Rectangle { Row { id: Lay Repeater { - dataSource: List + model: List Component { Day { day: name diff --git a/src/declarative/fx/qfxlistview.cpp b/src/declarative/fx/qfxlistview.cpp index 048cb0f..b2c9a59 100644 --- a/src/declarative/fx/qfxlistview.cpp +++ b/src/declarative/fx/qfxlistview.cpp @@ -894,7 +894,7 @@ QFxListView::~QFxListView() provided by a C++ model object. The C++ model object must be a \l {QAbstractItemModel} subclass, a VisualModel, or a simple list. - Models can also be created directly in QML, using a \l{ListModel}. + Models can also be created directly in QML, using a \l{ListModel} or \l{XmlListModel}. */ QVariant QFxListView::model() const { diff --git a/src/declarative/fx/qfxrepeater.cpp b/src/declarative/fx/qfxrepeater.cpp index a9d9977..fa44f8f 100644 --- a/src/declarative/fx/qfxrepeater.cpp +++ b/src/declarative/fx/qfxrepeater.cpp @@ -47,7 +47,7 @@ QT_BEGIN_NAMESPACE QFxRepeaterPrivate::QFxRepeaterPrivate() -: component(0) +: component(0), count(0) { } @@ -112,42 +112,8 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Repeater,QFxRepeater) /*! \internal \class QFxRepeater - \ingroup group_utility \qmlclass Repeater - \brief The QFxRepeater class allows you to repeat a component based on a - data source. - - The QFxRepeater class is used when you want to create a large number of - similar items. For each entry in the data source, an item is instantiated - in a context seeded with data from the data source. - - The data source may be either an object list, a string list or a Qt model. - In each case, the data element and the index is exposed to each instantiated - component. The index is always exposed as an accessible \c index property. - In the case of an object or string list, the data element (of type string - or object) is available as the \c modelData property. In the case of a Qt model, - all roles are available as named properties just like in the view classes. - - As a special case the data source can also be merely a number. In this case it will - create that many instances of the component. They will also be assigned an index - based on the order they are created. - - Items instantiated by the QFxRepeater class are inserted, in order, as - children of the repeater's parent. The insertion starts immediately after - the repeater's position in its parent stacking list. This is to allow - you to use a repeater inside a layout. The following QML example shows how - the instantiated items would visually appear stacked between the red and - blue rectangles. - - \snippet doc/src/snippets/declarative/repeater.qml 0 - - The QFxRepeater instance continues to own all items it instantiates, even - if they are otherwise manipulated. It is illegal to manually delete an item - created by the repeater. On destruction, the repeater will clean up any - items it has instantiated. - - XXX Repeater is very conservative in how it instatiates/deletes items. Also new model entries will not be created and old ones will not be removed. */ @@ -177,27 +143,27 @@ QFxRepeater::~QFxRepeater() } /*! - \qmlproperty any Repeater::dataSource + \qmlproperty any Repeater::model - The Repeater's data source. + The model providing data for the repeater. - The data source may be either an object list, a string list or a Qt model. + The model may be either an object list, a string list or a Qt model. In each case, the data element and the index is exposed to each instantiated component. The index is always exposed as an accessible \c index property. In the case of an object or string list, the data element (of type string or object) is available as the \c modelData property. In the case of a Qt model, all roles are available as named properties just like in the view classes. - As a special case the data source can also be merely a number. In this case it will + As a special case the model can also be merely a number. In this case it will create that many instances of the component. They will also be assigned an index based on the order they are created. */ -QVariant QFxRepeater::dataSource() const +QVariant QFxRepeater::model() const { return QVariant(); } -void QFxRepeater::setDataSource(const QVariant &v) +void QFxRepeater::setModel(const QVariant &v) { Q_D(QFxRepeater); d->dataSource = v; @@ -205,18 +171,18 @@ void QFxRepeater::setDataSource(const QVariant &v) } /*! - \qmlproperty Component Repeater::component + \qmlproperty Component Repeater::delegate \default - The component to repeat. + The delegate provides a template describing what each item instantiated by the repeater should look and act like. */ -QmlComponent *QFxRepeater::component() const +QmlComponent *QFxRepeater::delegate() const { Q_D(const QFxRepeater); return d->component; } -void QFxRepeater::setComponent(QmlComponent *_c) +void QFxRepeater::setDelegate(QmlComponent *_c) { Q_D(QFxRepeater); d->component = _c; @@ -224,6 +190,18 @@ void QFxRepeater::setComponent(QmlComponent *_c) } /*! + \qmlproperty int Repeater::count + + This property holds the number of items in the repeater. +*/ +int QFxRepeater::count() const +{ + Q_D(const QFxRepeater); + return d->count; +} + + +/*! \internal */ void QFxRepeater::componentComplete() @@ -260,10 +238,13 @@ void QFxRepeater::regenerate() QFxItem *lastItem = this; + int count = 0; + if (d->dataSource.type() == QVariant::StringList) { QStringList sl = qvariant_cast(d->dataSource); - for (int ii = 0; ii < sl.size(); ++ii) { + count = sl.size(); + for (int ii = 0; ii < count; ++ii) { QmlContext *ctxt = new QmlContext(qmlContext(this), this); d->deletables << ctxt; @@ -274,11 +255,11 @@ void QFxRepeater::regenerate() lastItem = item; } } else if (QmlMetaType::isList(d->dataSource)) { - int cnt = QmlMetaType::listCount(d->dataSource); - if (cnt <= 0) + count = QmlMetaType::listCount(d->dataSource); + if (count <= 0) return; - for (int ii = 0; ii < cnt; ++ii) { + for (int ii = 0; ii < count; ++ii) { QVariant v = QmlMetaType::listAt(d->dataSource, ii); QObject *o = QmlMetaType::toQObject(v); @@ -292,11 +273,11 @@ void QFxRepeater::regenerate() lastItem = item; } } else if (QListModelInterface *model = qobject_cast(d->dataSource.value())) { - int cnt = model->count(); - if (cnt <= 0) + count = model->count(); + if (count <= 0) return; - for (int ii = 0; ii < cnt; ++ii) { + for (int ii = 0; ii < count; ++ii) { QmlContext *ctxt = new QmlContext(qmlContext(this), this); d->deletables << ctxt; @@ -322,13 +303,14 @@ void QFxRepeater::regenerate() d->deletables << ctxt; ctxt->setContextProperty(QLatin1String("index"), QVariant(0)); - for (int ii = 1; ii < object->metaObject()->propertyCount(); ++ii) { + count = object->metaObject()->propertyCount(); + for (int ii = 1; ii < count; ++ii) { const QMetaProperty &prop = object->metaObject()->property(ii); ctxt->setContextProperty(QLatin1String(prop.name()), prop.read(object)); } //for compatability with other lists, assign data if there is only a single role (excluding objectName) - if (object->metaObject()->propertyCount() == 2) { + if (count == 2) { const QMetaProperty &prop = object->metaObject()->property(1); ctxt->setContextProperty(QLatin1String("modelData"), prop.read(object)); } @@ -337,7 +319,7 @@ void QFxRepeater::regenerate() } else if (d->dataSource.canConvert(QVariant::Int)){ - int count = qvariant_cast(d->dataSource); + count = qvariant_cast(d->dataSource); for (int ii = 0; ii < count; ++ii) { QmlContext *ctxt = new QmlContext(qmlContext(this), this); @@ -349,5 +331,6 @@ void QFxRepeater::regenerate() lastItem = item; } } + d->count = count; } QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxrepeater.h b/src/declarative/fx/qfxrepeater.h index 3013b61..43afd63 100644 --- a/src/declarative/fx/qfxrepeater.h +++ b/src/declarative/fx/qfxrepeater.h @@ -55,19 +55,22 @@ class Q_DECLARATIVE_EXPORT QFxRepeater : public QFxItem { Q_OBJECT - Q_PROPERTY(QVariant dataSource READ dataSource WRITE setDataSource) //### model - Q_PROPERTY(QmlComponent *component READ component WRITE setComponent) //### delegate - Q_CLASSINFO("DefaultProperty", "component") - //### count + Q_PROPERTY(QVariant model READ model WRITE setModel) + Q_PROPERTY(QmlComponent *delegate READ delegate WRITE setDelegate) + Q_PROPERTY(int count READ count NOTIFY countChanged) + Q_CLASSINFO("DefaultProperty", "delegate") + public: QFxRepeater(QFxItem *parent=0); virtual ~QFxRepeater(); - QVariant dataSource() const; - void setDataSource(const QVariant &); + QVariant model() const; + void setModel(const QVariant &); + + QmlComponent *delegate() const; + void setDelegate(QmlComponent *); - QmlComponent *component() const; - void setComponent(QmlComponent *); + int count() const; private: void regenerate(); diff --git a/src/declarative/fx/qfxrepeater_p.h b/src/declarative/fx/qfxrepeater_p.h index ba69658..65b0973 100644 --- a/src/declarative/fx/qfxrepeater_p.h +++ b/src/declarative/fx/qfxrepeater_p.h @@ -73,6 +73,7 @@ public: QVariant dataSource; QmlComponent *component; + int count; QList > deletables; }; -- cgit v0.12 From 8edaa5f5d1d7b78007e07e65987e26bd843970e8 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Thu, 27 Aug 2009 13:11:38 +1000 Subject: Support using a QAbstractItemModel with Repeater. --- src/declarative/fx/qfxrepeater.cpp | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/declarative/fx/qfxrepeater.cpp b/src/declarative/fx/qfxrepeater.cpp index fa44f8f..67d4d69 100644 --- a/src/declarative/fx/qfxrepeater.cpp +++ b/src/declarative/fx/qfxrepeater.cpp @@ -157,10 +157,13 @@ QFxRepeater::~QFxRepeater() As a special case the model can also be merely a number. In this case it will create that many instances of the component. They will also be assigned an index based on the order they are created. + + Models can also be created directly in QML, using a \l{ListModel} or \l{XmlListModel}. */ QVariant QFxRepeater::model() const { - return QVariant(); + Q_D(const QFxRepeater); + return d->dataSource; } void QFxRepeater::setModel(const QVariant &v) @@ -296,6 +299,38 @@ void QFxRepeater::regenerate() if (QFxItem *item = d->addItem(ctxt, lastItem)) lastItem = item; } + } else if (QAbstractItemModel *model = qobject_cast(d->dataSource.value())) { + count = model->rowCount(); + if (count <= 0) + return; + + for (int ii = 0; ii < count; ++ii) { + QmlContext *ctxt = new QmlContext(qmlContext(this), this); + d->deletables << ctxt; + + ctxt->setContextProperty(QLatin1String("index"), ii); + + QList roles; + QStringList roleNames; + QHash data; + for (QHash::const_iterator it = model->roleNames().begin(); + it != model->roleNames().end(); ++it) { + roles.append(it.key()); + roleNames.append(QLatin1String(*it)); + } + + QModelIndex index = model->index(ii, 0); + for (int j = 0; j < roles.size(); ++j) { + ctxt->setContextProperty(roleNames.at(j), model->data(index, roles.at(j))); + } + + //for compatability with other lists, assign data if there is only a single role + if (roles.size() == 1) + ctxt->setContextProperty(QLatin1String("modelData"), data.value(roles.at(0))); + + if (QFxItem *item = d->addItem(ctxt, lastItem)) + lastItem = item; + } } else if (QObject *object = d->dataSource.value()) { // A single object (i.e. list of size 1). // Properties are the roles (excluding objectName). -- cgit v0.12