From 4ba2513ca6fa42c37c45a573b4643b5e1d97db3b Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Wed, 18 Nov 2009 13:25:03 +1000 Subject: tests --- src/declarative/util/qmllistaccessor.cpp | 172 ++++------ src/declarative/util/qmllistaccessor_p.h | 12 +- .../qmllistaccessor/tst_qmllistaccessor.cpp | 373 ++++++++++++++++++++- 3 files changed, 443 insertions(+), 114 deletions(-) diff --git a/src/declarative/util/qmllistaccessor.cpp b/src/declarative/util/qmllistaccessor.cpp index 910f2a5..4adec81 100644 --- a/src/declarative/util/qmllistaccessor.cpp +++ b/src/declarative/util/qmllistaccessor.cpp @@ -77,8 +77,6 @@ void QmlListAccessor::setList(const QVariant &v, QmlEngine *engine) m_type = VariantList; } else if (d.canConvert(QVariant::Int)) { m_type = Integer; - } else if (d.type() != QVariant::UserType) { - m_type = Instance; } else if ((!enginePrivate && QmlMetaType::isObject(d.userType())) || (enginePrivate && enginePrivate->isObject(d.userType()))) { QObject *data = 0; @@ -89,18 +87,15 @@ void QmlListAccessor::setList(const QVariant &v, QmlEngine *engine) (enginePrivate && enginePrivate->isQmlList(d.userType()))) { m_type = QmlList; } else if (QmlMetaType::isList(d.userType())) { - m_type = QList; + m_type = QListPtr; } else { - m_type = Invalid; - d = QVariant(); + m_type = Instance; } } int QmlListAccessor::count() const { switch(m_type) { - case Invalid: - return 0; case StringList: return qvariant_cast(d).count(); case VariantList: @@ -110,23 +105,25 @@ int QmlListAccessor::count() const QmlPrivate::ListInterface *li = *(QmlPrivate::ListInterface **)d.constData(); return li->count(); } - case QList: - return QmlMetaType::listCount(d); + case QListPtr: + { + QList *li = *(QList **)d.constData(); + return li->count(); + } case Instance: return 1; case Integer: return d.toInt(); + default: + case Invalid: + return 0; } - - return 0; } QVariant QmlListAccessor::at(int idx) const { Q_ASSERT(idx >= 0 && idx < count()); switch(m_type) { - case Invalid: - return QVariant(); case StringList: return QVariant::fromValue(qvariant_cast(d).at(idx)); case VariantList: @@ -138,142 +135,119 @@ QVariant QmlListAccessor::at(int idx) const li->at(idx, ptr); return QVariant::fromValue((QObject*)ptr[0]); } - case QList: - return QmlMetaType::listAt(d, idx); + case QListPtr: + { + QList *li = *(QList **)d.constData(); + void *ptr = li->at(idx); + return QVariant::fromValue((QObject*)ptr); + } case Instance: return d; case Integer: + return QVariant(idx); + default: + case Invalid: return QVariant(); } - - return QVariant(); } -void QmlListAccessor::append(const QVariant &value) +bool QmlListAccessor::append(const QVariant &value) { switch(m_type) { - case Invalid: - break; - case StringList: - { - const QString &str = value.toString(); - qvariant_cast(d).append(str); - break; - } - case VariantList: - { - qvariant_cast(d).append(value); - break; - } case QmlList: { QmlPrivate::ListInterface *li = *(QmlPrivate::ListInterface **)d.constData(); - li->append(const_cast(value.constData())); //XXX - break; + li->append(const_cast(value.constData())); //XXX Typesafety + return true; + } + case QListPtr: + { + QList *li = *(QList **)d.constData(); + li->append(*reinterpret_cast(const_cast(value.constData()))); //XXX Typesafety + return true; } - case QList: - QmlMetaType::append(d, value); - break; + case StringList: + case VariantList: + case Invalid: case Instance: case Integer: - //do nothing - break; + default: + return false; } } -void QmlListAccessor::insert(int index, const QVariant &value) +bool QmlListAccessor::insert(int index, const QVariant &value) { switch(m_type) { - case Invalid: - break; - case StringList: - { - const QString &str = value.toString(); - qvariant_cast(d).insert(index, str); - break; - } - case VariantList: - { - qvariant_cast(d).insert(index, value); - break; - } case QmlList: { QmlPrivate::ListInterface *li = *(QmlPrivate::ListInterface **)d.constData(); - li->insert(index, const_cast(value.constData())); //XXX - break; + li->insert(index, const_cast(value.constData())); //XXX Typesafety + return true; + } + case QListPtr: + { + QList *li = *(QList**)d.constData(); + li->insert(index, *reinterpret_cast(const_cast(value.constData()))); //XXX Typesafety + return true; } - case QList: - //XXX needs implementation - qWarning() << "insert function not yet implemented for QLists"; - break; + case StringList: + case VariantList: + case Invalid: case Instance: - //XXX do nothing? - if (index == 0) - setList(value); - break; case Integer: - break; + default: + return false; } } -void QmlListAccessor::removeAt(int index) +bool QmlListAccessor::removeAt(int index) { switch(m_type) { - case Invalid: - break; - case StringList: - qvariant_cast(d).removeAt(index); - break; - case VariantList: - qvariant_cast(d).removeAt(index); - break; case QmlList: { QmlPrivate::ListInterface *li = *(QmlPrivate::ListInterface **)d.constData(); li->removeAt(index); - break; + return true; } - case QList: - //XXX needs implementation - qWarning() << "removeAt function not yet implemented for QLists"; - break; + case QListPtr: + { + QList *li = *(QList**)d.constData(); + li->removeAt(index); + return true; + } + case StringList: + case VariantList: + case Invalid: case Instance: - //XXX do nothing? - if (index == 0) - setList(QVariant()); - break; case Integer: - break; + default: + return false; } } -void QmlListAccessor::clear() +bool QmlListAccessor::clear() { switch(m_type) { - case Invalid: - break; - case StringList: - qvariant_cast(d).clear(); - break; - case VariantList: - qvariant_cast(d).clear(); - break; case QmlList: { QmlPrivate::ListInterface *li = *(QmlPrivate::ListInterface **)d.constData(); li->clear(); - break; + return true; + } + case QListPtr: + { + QList *li = *(QList**)d.constData(); + li->clear(); + return true; } - case QList: - QmlMetaType::clear(d); - break; + case StringList: + case VariantList: + case Invalid: case Instance: - //XXX what should we do here? - setList(QVariant()); - break; case Integer: - d = 0; + default: + return false; } } diff --git a/src/declarative/util/qmllistaccessor_p.h b/src/declarative/util/qmllistaccessor_p.h index 2697606..3c67e3a 100644 --- a/src/declarative/util/qmllistaccessor_p.h +++ b/src/declarative/util/qmllistaccessor_p.h @@ -55,7 +55,7 @@ class Q_DECLARATIVE_EXPORT QmlListAccessor { public: QmlListAccessor(); - virtual ~QmlListAccessor(); + ~QmlListAccessor(); QVariant list() const; void setList(const QVariant &, QmlEngine * = 0); @@ -65,12 +65,12 @@ public: int count() const; QVariant at(int) const; - virtual void append(const QVariant &); - virtual void insert(int, const QVariant &); - virtual void removeAt(int); - virtual void clear(); + bool append(const QVariant &); + bool insert(int, const QVariant &); + bool removeAt(int); + bool clear(); - enum Type { Invalid, StringList, VariantList, QmlList, QList, Instance, Integer }; + enum Type { Invalid, StringList, VariantList, QmlList, QListPtr, Instance, Integer }; Type type() const { return m_type; } private: diff --git a/tests/auto/declarative/qmllistaccessor/tst_qmllistaccessor.cpp b/tests/auto/declarative/qmllistaccessor/tst_qmllistaccessor.cpp index 4c8219a..14de1df 100644 --- a/tests/auto/declarative/qmllistaccessor/tst_qmllistaccessor.cpp +++ b/tests/auto/declarative/qmllistaccessor/tst_qmllistaccessor.cpp @@ -50,29 +50,169 @@ public: tst_QmlListAccessor() {} private slots: + void invalid(); void qmllist(); - //void qlist(); + void qlist(); void qstringlist(); + void qvariantlist(); + void qobject(); + void instance(); + void integer(); }; +void tst_QmlListAccessor::invalid() +{ + QmlListAccessor accessor; + + QCOMPARE(accessor.list(), QVariant()); + QVERIFY(!accessor.isValid()); + QCOMPARE(accessor.type(), QmlListAccessor::Invalid); + + QCOMPARE(accessor.count(), 0); + QCOMPARE(accessor.at(0), QVariant()); + QCOMPARE(accessor.at(4), QVariant()); + QVERIFY(!accessor.append(QVariant(10))); + QVERIFY(!accessor.insert(0, QVariant(10))); + QVERIFY(!accessor.removeAt(0)); + QVERIFY(!accessor.clear()); + + accessor.setList(QVariant()); + + QCOMPARE(accessor.list(), QVariant()); + QVERIFY(!accessor.isValid()); + QCOMPARE(accessor.type(), QmlListAccessor::Invalid); + + QCOMPARE(accessor.count(), 0); + QCOMPARE(accessor.at(0), QVariant()); + QCOMPARE(accessor.at(4), QVariant()); + QVERIFY(!accessor.append(QVariant(10))); + QVERIFY(!accessor.insert(0, QVariant(10))); + QVERIFY(!accessor.removeAt(0)); + QVERIFY(!accessor.clear()); +} + void tst_QmlListAccessor::qmllist() { QmlConcreteList list; - QObject *obj = new QObject; + QObject *obj = new QObject(this); + QObject *obj2 = new QObject(this); + QObject *obj3 = new QObject(this); + list.append(obj); QVERIFY(list.count() == 1); QCOMPARE(list.at(0), obj); QmlListAccessor accessor; accessor.setList(qVariantFromValue((QmlList*)&list)); + QCOMPARE(accessor.list(), qVariantFromValue((QmlList*)&list)); + // type + QCOMPARE(accessor.type(), QmlListAccessor::QmlList); + + // isValid QVERIFY(accessor.isValid()); - QVERIFY(accessor.count() == 1); - QVariant v = accessor.at(0); - QCOMPARE(qvariant_cast(v), obj); + // count + QCOMPARE(accessor.count(), 1); + + // at + QCOMPARE(qvariant_cast(accessor.at(0)), obj); + + // append + accessor.append(qVariantFromValue(obj2)); + QVERIFY(accessor.isValid()); + QCOMPARE(accessor.count(), 2); + QCOMPARE(qvariant_cast(accessor.at(1)), obj2); + QCOMPARE(list.count(), 2); + QCOMPARE(list.at(0), obj); + QCOMPARE(list.at(1), obj2); + + // insert + accessor.insert(1, qVariantFromValue(obj3)); + QVERIFY(accessor.isValid()); + QCOMPARE(accessor.count(), 3); + QCOMPARE(qvariant_cast(accessor.at(1)), obj3); + QCOMPARE(list.count(), 3); + QCOMPARE(list.at(0), obj); + QCOMPARE(list.at(1), obj3); + QCOMPARE(list.at(2), obj2); + + // removeAt + accessor.removeAt(1); + QVERIFY(accessor.isValid()); + QCOMPARE(accessor.count(), 2); + QCOMPARE(qvariant_cast(accessor.at(1)), obj2); + QCOMPARE(list.count(), 2); + QCOMPARE(list.at(0), obj); + QCOMPARE(list.at(1), obj2); + // clear + accessor.clear(); QVERIFY(accessor.isValid()); + QCOMPARE(accessor.count(), 0); + QCOMPARE(list.count(), 0); +} + +void tst_QmlListAccessor::qlist() +{ + QList list; + QObject *obj = new QObject(this); + QObject *obj2 = new QObject(this); + QObject *obj3 = new QObject(this); + + list.append(obj); + QVERIFY(list.count() == 1); + QCOMPARE(list.at(0), obj); + + QmlListAccessor accessor; + accessor.setList(qVariantFromValue((QList*)&list)); + QCOMPARE(accessor.list(), qVariantFromValue((QList*)&list)); + + // type + QCOMPARE(accessor.type(), QmlListAccessor::QListPtr); + + // isValid + QVERIFY(accessor.isValid()); + + // count + QCOMPARE(accessor.count(), 1); + + // at + QCOMPARE(qvariant_cast(accessor.at(0)), obj); + + // append + accessor.append(qVariantFromValue(obj2)); + QVERIFY(accessor.isValid()); + QCOMPARE(accessor.count(), 2); + QCOMPARE(qvariant_cast(accessor.at(1)), obj2); + QCOMPARE(list.count(), 2); + QCOMPARE(list.at(0), obj); + QCOMPARE(list.at(1), obj2); + + // insert + accessor.insert(1, qVariantFromValue(obj3)); + QVERIFY(accessor.isValid()); + QCOMPARE(accessor.count(), 3); + QCOMPARE(qvariant_cast(accessor.at(1)), obj3); + QCOMPARE(list.count(), 3); + QCOMPARE(list.at(0), obj); + QCOMPARE(list.at(1), obj3); + QCOMPARE(list.at(2), obj2); + + // removeAt + accessor.removeAt(1); + QVERIFY(accessor.isValid()); + QCOMPARE(accessor.count(), 2); + QCOMPARE(qvariant_cast(accessor.at(1)), obj2); + QCOMPARE(list.count(), 2); + QCOMPARE(list.at(0), obj); + QCOMPARE(list.at(1), obj2); + + // clear + accessor.clear(); + QVERIFY(accessor.isValid()); + QCOMPARE(accessor.count(), 0); + QCOMPARE(list.count(), 0); } void tst_QmlListAccessor::qstringlist() @@ -85,16 +225,231 @@ void tst_QmlListAccessor::qstringlist() QmlListAccessor accessor; accessor.setList(list); + // type + QCOMPARE(accessor.type(), QmlListAccessor::StringList); + + // isValid + QVERIFY(accessor.isValid()); + + // count + QVERIFY(accessor.count() == 2); + + // at + QCOMPARE(qvariant_cast(accessor.at(0)), QLatin1String("Item1")); + QCOMPARE(qvariant_cast(accessor.at(1)), QLatin1String("Item2")); + + // append + QVERIFY(!accessor.append(QVariant("Item3"))); + QVERIFY(accessor.isValid()); + QVERIFY(accessor.count() == 2); + QCOMPARE(qvariant_cast(accessor.at(0)), QLatin1String("Item1")); + QCOMPARE(qvariant_cast(accessor.at(1)), QLatin1String("Item2")); + + // insert + QVERIFY(!accessor.insert(1, QVariant("MiddleItem"))); + QVERIFY(accessor.isValid()); + QVERIFY(accessor.count() == 2); + QCOMPARE(qvariant_cast(accessor.at(0)), QLatin1String("Item1")); + QCOMPARE(qvariant_cast(accessor.at(1)), QLatin1String("Item2")); + + // removeAt + QVERIFY(!accessor.removeAt(1)); + QVERIFY(accessor.isValid()); + QVERIFY(accessor.count() == 2); + QCOMPARE(qvariant_cast(accessor.at(0)), QLatin1String("Item1")); + QCOMPARE(qvariant_cast(accessor.at(1)), QLatin1String("Item2")); + + // clear + QVERIFY(!accessor.clear()); + QVERIFY(accessor.isValid()); + QVERIFY(accessor.count() == 2); + QCOMPARE(qvariant_cast(accessor.at(0)), QLatin1String("Item1")); + QCOMPARE(qvariant_cast(accessor.at(1)), QLatin1String("Item2")); +} + +void tst_QmlListAccessor::qvariantlist() +{ + QVariantList list; + list.append(QLatin1String("Item1")); + list.append(QLatin1String("Item2")); + QVERIFY(list.count() == 2); + + QmlListAccessor accessor; + accessor.setList(list); + + // type + QCOMPARE(accessor.type(), QmlListAccessor::VariantList); + + // isValid + QVERIFY(accessor.isValid()); + + // count + QVERIFY(accessor.count() == 2); + + // at + QCOMPARE(qvariant_cast(accessor.at(0)), QLatin1String("Item1")); + QCOMPARE(qvariant_cast(accessor.at(1)), QLatin1String("Item2")); + + // append + QVERIFY(!accessor.append(QVariant("Item3"))); QVERIFY(accessor.isValid()); QVERIFY(accessor.count() == 2); + QCOMPARE(qvariant_cast(accessor.at(0)), QLatin1String("Item1")); + QCOMPARE(qvariant_cast(accessor.at(1)), QLatin1String("Item2")); + + // insert + QVERIFY(!accessor.insert(1, QVariant("MiddleItem"))); + QVERIFY(accessor.isValid()); + QVERIFY(accessor.count() == 2); + QCOMPARE(qvariant_cast(accessor.at(0)), QLatin1String("Item1")); + QCOMPARE(qvariant_cast(accessor.at(1)), QLatin1String("Item2")); + + // removeAt + QVERIFY(!accessor.removeAt(1)); + QVERIFY(accessor.isValid()); + QVERIFY(accessor.count() == 2); + QCOMPARE(qvariant_cast(accessor.at(0)), QLatin1String("Item1")); + QCOMPARE(qvariant_cast(accessor.at(1)), QLatin1String("Item2")); + + // clear + QVERIFY(!accessor.clear()); + QVERIFY(accessor.isValid()); + QVERIFY(accessor.count() == 2); + QCOMPARE(qvariant_cast(accessor.at(0)), QLatin1String("Item1")); + QCOMPARE(qvariant_cast(accessor.at(1)), QLatin1String("Item2")); +} + +void tst_QmlListAccessor::qobject() +{ + QObject *obj = new QObject(this); + + QmlListAccessor accessor; + accessor.setList(qVariantFromValue(obj)); - QVariant v = accessor.at(0); - QCOMPARE(qvariant_cast(v), QLatin1String("Item1")); + // type + QCOMPARE(accessor.type(), QmlListAccessor::Instance); - v = accessor.at(1); - QCOMPARE(qvariant_cast(v), QLatin1String("Item2")); + // isValid + QVERIFY(accessor.isValid()); + + // count + QVERIFY(accessor.count() == 1); + + // at + QCOMPARE(accessor.at(0), qVariantFromValue(obj)); + + // append + QVERIFY(!accessor.append(qVariantFromValue((QObject *)0))); + QVERIFY(accessor.isValid()); + QVERIFY(accessor.count() == 1); + QCOMPARE(accessor.at(0), qVariantFromValue(obj)); + + // insert + QVERIFY(!accessor.insert(0, qVariantFromValue((QObject *)0))); + QVERIFY(accessor.isValid()); + QVERIFY(accessor.count() == 1); + QCOMPARE(accessor.at(0), qVariantFromValue(obj)); + + // removeAt + QVERIFY(!accessor.removeAt(0)); + QVERIFY(accessor.isValid()); + QVERIFY(accessor.count() == 1); + QCOMPARE(accessor.at(0), qVariantFromValue(obj)); + + // clear + QVERIFY(!accessor.clear()); + QVERIFY(accessor.isValid()); + QVERIFY(accessor.count() == 1); + QCOMPARE(accessor.at(0), qVariantFromValue(obj)); } +void tst_QmlListAccessor::instance() +{ + QRect r; + + QmlListAccessor accessor; + accessor.setList(r); + + // type + QCOMPARE(accessor.type(), QmlListAccessor::Instance); + + // isValid + QVERIFY(accessor.isValid()); + + // count + QVERIFY(accessor.count() == 1); + + // at + QCOMPARE(accessor.at(0), qVariantFromValue(r)); + + // append + QVERIFY(!accessor.append(qVariantFromValue(r))); + QVERIFY(accessor.isValid()); + QVERIFY(accessor.count() == 1); + QCOMPARE(accessor.at(0), qVariantFromValue(r)); + + // insert + QVERIFY(!accessor.insert(0, qVariantFromValue(r))); + QVERIFY(accessor.isValid()); + QVERIFY(accessor.count() == 1); + QCOMPARE(accessor.at(0), qVariantFromValue(r)); + + // removeAt + QVERIFY(!accessor.removeAt(0)); + QVERIFY(accessor.isValid()); + QVERIFY(accessor.count() == 1); + QCOMPARE(accessor.at(0), qVariantFromValue(r)); + + // clear + QVERIFY(!accessor.clear()); + QVERIFY(accessor.isValid()); + QVERIFY(accessor.count() == 1); + QCOMPARE(accessor.at(0), qVariantFromValue(r)); +} + +void tst_QmlListAccessor::integer() +{ + int r = 13; + + QmlListAccessor accessor; + accessor.setList(r); + + // type + QCOMPARE(accessor.type(), QmlListAccessor::Integer); + + // isValid + QVERIFY(accessor.isValid()); + + // count + QVERIFY(accessor.count() == 13); + + // at + QCOMPARE(accessor.at(4), qVariantFromValue(4)); + + // append + QVERIFY(!accessor.append(qVariantFromValue(r))); + QVERIFY(accessor.isValid()); + QVERIFY(accessor.count() == 13); + QCOMPARE(accessor.at(4), qVariantFromValue(4)); + + // insert + QVERIFY(!accessor.insert(0, qVariantFromValue(r))); + QVERIFY(accessor.isValid()); + QVERIFY(accessor.count() == 13); + QCOMPARE(accessor.at(4), qVariantFromValue(4)); + + // removeAt + QVERIFY(!accessor.removeAt(0)); + QVERIFY(accessor.isValid()); + QVERIFY(accessor.count() == 13); + QCOMPARE(accessor.at(4), qVariantFromValue(4)); + + // clear + QVERIFY(!accessor.clear()); + QVERIFY(accessor.isValid()); + QVERIFY(accessor.count() == 13); + QCOMPARE(accessor.at(4), qVariantFromValue(4)); +} QTEST_MAIN(tst_QmlListAccessor) -- cgit v0.12 From db56fec07c1a8a0a3a6e006ec2613351241cdf54 Mon Sep 17 00:00:00 2001 From: Justin McPherson Date: Wed, 18 Nov 2009 13:56:45 +1000 Subject: Minor doc fixes for animation elements. Reviewed-by: Martin Jones --- src/declarative/util/qmlanimation.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp index 780bc82..475978f 100644 --- a/src/declarative/util/qmlanimation.cpp +++ b/src/declarative/util/qmlanimation.cpp @@ -595,7 +595,7 @@ void QmlAbstractAnimation::timelineComplete() /*! \qmlclass PauseAnimation QmlPauseAnimation \inherits Animation - \brief The PauseAnimation provides a pause for an animation. + \brief The PauseAnimation element provides a pause for an animation. When used in a SequentialAnimation, PauseAnimation is a step when nothing happens, for a specified duration. @@ -668,7 +668,7 @@ QAbstractAnimation *QmlPauseAnimation::qtAnimation() /*! \qmlclass ColorAnimation QmlColorAnimation \inherits PropertyAnimation - \brief The ColorAnimation allows you to animate color changes. + \brief The ColorAnimation element allows you to animate color changes. \code ColorAnimation { from: "white"; to: "#c0c0c0"; duration: 100 } @@ -676,7 +676,7 @@ QAbstractAnimation *QmlPauseAnimation::qtAnimation() When used in a transition, ColorAnimation will by default animate all properties of type color that are changing. If a property or properties - are explicity set for the animation, then those will be used instead. + are explicitly set for the animation, then those will be used instead. */ /*! \internal @@ -731,7 +731,7 @@ QML_DEFINE_TYPE(Qt,4,6,ColorAnimation,QmlColorAnimation) /*! \qmlclass ScriptAction QmlScriptAction \inherits Animation - \brief The ScriptAction allows scripts to be run during an animation. + \brief The ScriptAction element allows scripts to be run during an animation. */ /*! @@ -837,7 +837,7 @@ QML_DEFINE_TYPE(Qt,4,6,ScriptAction,QmlScriptAction) /*! \qmlclass PropertyAction QmlPropertyAction \inherits Animation - \brief The PropertyAction allows immediate property changes during animation. + \brief The PropertyAction element allows immediate property changes during animation. Explicitly set \c theimage.smooth=true during a transition: \code @@ -1303,7 +1303,7 @@ QML_DEFINE_TYPE(Qt,4,6,ParentAction,QmlParentAction) /*! \qmlclass NumberAnimation QmlNumberAnimation \inherits PropertyAnimation - \brief The NumberAnimation allows you to animate changes in properties of type qreal. + \brief The NumberAnimation element allows you to animate changes in properties of type qreal. Animate a set of properties over 200ms, from their values in the start state to their values in the end state of the transition: @@ -1381,7 +1381,7 @@ QmlList *QmlAnimationGroup::animations() /*! \qmlclass SequentialAnimation QmlSequentialAnimation \inherits Animation - \brief The SequentialAnimation allows you to run animations sequentially. + \brief The SequentialAnimation element allows you to run animations sequentially. Animations controlled in SequentialAnimation will be run one after the other. @@ -1456,7 +1456,7 @@ QML_DEFINE_TYPE(Qt,4,6,SequentialAnimation,QmlSequentialAnimation) /*! \qmlclass ParallelAnimation QmlParallelAnimation \inherits Animation - \brief The ParallelAnimation allows you to run animations in parallel. + \brief The ParallelAnimation element allows you to run animations in parallel. Animations contained in ParallelAnimation will be run at the same time. @@ -1580,14 +1580,12 @@ void QmlPropertyAnimationPrivate::convertVariant(QVariant &variant, int type) /*! \qmlclass PropertyAnimation QmlPropertyAnimation \inherits Animation - \brief The PropertyAnimation allows you to animate property changes. + \brief The PropertyAnimation element allows you to animate property changes. Animate a size property over 200ms, from its current size to 20-by-20: \code - VariantAnimation { property: "size"; to: "20x20"; duration: 200 } + PropertyAnimation { property: "size"; to: "20x20"; duration: 200 } \endcode - - \a qmlanimation.html */ QmlPropertyAnimation::QmlPropertyAnimation(QObject *parent) -- cgit v0.12 From ee5d533bfa7b07927a6c62182f0a0377503c0f2b Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 18 Nov 2009 14:23:34 +1000 Subject: More PathView testing --- src/declarative/graphicsitems/qmlgraphicspath.cpp | 16 +- src/declarative/graphicsitems/qmlgraphicspath_p.h | 3 + .../graphicsitems/qmlgraphicspath_p_p.h | 3 +- .../qmlgraphicspathview/data/datamodel.qml | 36 +++ .../tst_qmlgraphicspathview.cpp | 241 +++++++++++++++++++++ 5 files changed, 297 insertions(+), 2 deletions(-) create mode 100644 tests/auto/declarative/qmlgraphicspathview/data/datamodel.qml diff --git a/src/declarative/graphicsitems/qmlgraphicspath.cpp b/src/declarative/graphicsitems/qmlgraphicspath.cpp index 0812d11..1791074 100644 --- a/src/declarative/graphicsitems/qmlgraphicspath.cpp +++ b/src/declarative/graphicsitems/qmlgraphicspath.cpp @@ -107,7 +107,7 @@ QmlGraphicsPath::~QmlGraphicsPath() /*! \qmlproperty real Path::startX \qmlproperty real Path::startY - This property holds the starting position of the path. + These properties hold the starting position of the path. */ qreal QmlGraphicsPath::startX() const { @@ -134,6 +134,16 @@ void QmlGraphicsPath::setStartY(qreal y) } /*! + \qmlproperty bool Path::closed + This property holds whether the start and end of the path are identical. +*/ +bool QmlGraphicsPath::isClosed() const +{ + Q_D(const QmlGraphicsPath); + return d->closed; +} + +/*! \qmlproperty list Path::pathElements This property holds the objects composing the path. @@ -220,12 +230,14 @@ void QmlGraphicsPath::processPath() d->_path.moveTo(d->startX, d->startY); + QmlGraphicsCurve *lastCurve = 0; foreach (QmlGraphicsPathElement *pathElement, d->_pathElements) { if (QmlGraphicsCurve *curve = qobject_cast(pathElement)) { curve->addToPath(d->_path); AttributePoint p; p.origpercent = d->_path.length(); d->_attributePoints << p; + lastCurve = curve; } else if (QmlGraphicsPathAttribute *attribute = qobject_cast(pathElement)) { AttributePoint &point = d->_attributePoints.last(); point.values[attribute->name()] = attribute->value(); @@ -266,6 +278,8 @@ void QmlGraphicsPath::processPath() } } + d->closed = lastCurve && d->startX == lastCurve->x() && d->startY == lastCurve->y(); + emit changed(); } diff --git a/src/declarative/graphicsitems/qmlgraphicspath_p.h b/src/declarative/graphicsitems/qmlgraphicspath_p.h index 4b0c772..30a377e 100644 --- a/src/declarative/graphicsitems/qmlgraphicspath_p.h +++ b/src/declarative/graphicsitems/qmlgraphicspath_p.h @@ -191,6 +191,7 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsPath : public QObject, public QmlParserSta Q_PROPERTY(QList* pathElements READ pathElements) Q_PROPERTY(qreal startX READ startX WRITE setStartX) Q_PROPERTY(qreal startY READ startY WRITE setStartY) + Q_PROPERTY(bool closed READ isClosed NOTIFY changed) Q_CLASSINFO("DefaultProperty", "pathElements") Q_INTERFACES(QmlParserStatus) public: @@ -205,6 +206,8 @@ public: qreal startY() const; void setStartY(qreal y); + bool isClosed() const; + QPainterPath path() const; QStringList attributes() const; qreal attributeAt(const QString &, qreal) const; diff --git a/src/declarative/graphicsitems/qmlgraphicspath_p_p.h b/src/declarative/graphicsitems/qmlgraphicspath_p_p.h index 36e8945..8c4c962 100644 --- a/src/declarative/graphicsitems/qmlgraphicspath_p_p.h +++ b/src/declarative/graphicsitems/qmlgraphicspath_p_p.h @@ -64,7 +64,7 @@ class QmlGraphicsPathPrivate : public QObjectPrivate Q_DECLARE_PUBLIC(QmlGraphicsPath) public: - QmlGraphicsPathPrivate() : startX(0), startY(0) { } + QmlGraphicsPathPrivate() : startX(0), startY(0), closed(false) { } QPainterPath _path; QList _pathElements; @@ -73,6 +73,7 @@ public: QStringList _attributes; int startX; int startY; + bool closed; }; QT_END_NAMESPACE diff --git a/tests/auto/declarative/qmlgraphicspathview/data/datamodel.qml b/tests/auto/declarative/qmlgraphicspathview/data/datamodel.qml new file mode 100644 index 0000000..6aea96b --- /dev/null +++ b/tests/auto/declarative/qmlgraphicspathview/data/datamodel.qml @@ -0,0 +1,36 @@ +import Qt 4.6 + +PathView { + id: pathview + objectName: "pathview" + width: 240; height: 320 + pathItemCount: testObject.pathItemCount + + function checkProperties() { + testObject.error = false; + if (testObject.useModel && view.model != itemModel) { + print("model property incorrect"); + testObject.error = true; + } + } + + model: testObject.useModel ? testData : 0 + + delegate: Component { + id: myDelegate + Rectangle { + id: wrapper + objectName: "wrapper" + width: 20; height: 20; color: name + Text { + objectName: "myText" + text: name + } + } + } + + path: Path { + startX: 120; startY: 20; + PathLine { x: 120; y: 300 } + } +} diff --git a/tests/auto/declarative/qmlgraphicspathview/tst_qmlgraphicspathview.cpp b/tests/auto/declarative/qmlgraphicspathview/tst_qmlgraphicspathview.cpp index 561392a..8aa2691 100644 --- a/tests/auto/declarative/qmlgraphicspathview/tst_qmlgraphicspathview.cpp +++ b/tests/auto/declarative/qmlgraphicspathview/tst_qmlgraphicspathview.cpp @@ -45,6 +45,10 @@ #include #include #include +#include +#include +#include +#include #include #include "../../../shared/util.h" @@ -56,9 +60,107 @@ public: private slots: void initValues(); + void dataModel(); void pathview2(); void pathview3(); void path(); + +private: + QmlView *createView(const QString &filename); + template + T *findItem(QmlGraphicsItem *parent, const QString &objectName, int index=-1); + template + QList findItems(QmlGraphicsItem *parent, const QString &objectName); +}; + +class TestObject : public QObject +{ + Q_OBJECT + + Q_PROPERTY(bool error READ error WRITE setError) + Q_PROPERTY(bool useModel READ useModel NOTIFY useModelChanged) + Q_PROPERTY(int pathItemCount READ pathItemCount NOTIFY pathItemCountChanged) + +public: + TestObject() : QObject(), mError(true), mUseModel(true), mPathItemCount(-1) {} + + bool error() const { return mError; } + void setError(bool err) { mError = err; } + + bool useModel() const { return mUseModel; } + void setUseModel(bool use) { mUseModel = use; emit useModelChanged(); } + + int pathItemCount() const { return mPathItemCount; } + void setPathItemCount(int count) { mPathItemCount = count; emit pathItemCountChanged(); } + +signals: + void useModelChanged(); + void pathItemCountChanged(); + +private: + bool mError; + bool mUseModel; + int mPathItemCount; +}; + +class TestModel : public QAbstractListModel +{ +public: + enum Roles { Name = Qt::UserRole+1, Number = Qt::UserRole+2 }; + + TestModel(QObject *parent=0) : QAbstractListModel(parent) { + QHash roles; + roles[Name] = "name"; + roles[Number] = "number"; + setRoleNames(roles); + } + + int rowCount(const QModelIndex &parent=QModelIndex()) const { return list.count(); } + QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const { + QVariant rv; + if (role == Name) + rv = list.at(index.row()).first; + else if (role == Number) + rv = list.at(index.row()).second; + + return rv; + } + + int count() const { return rowCount(); } + QString name(int index) const { return list.at(index).first; } + QString number(int index) const { return list.at(index).second; } + + void addItem(const QString &name, const QString &number) { + emit beginInsertRows(QModelIndex(), list.count(), list.count()); + list.append(QPair(name, number)); + emit endInsertRows(); + } + + void insertItem(int index, const QString &name, const QString &number) { + emit beginInsertRows(QModelIndex(), index, index); + list.insert(index, QPair(name, number)); + emit endInsertRows(); + } + + void removeItem(int index) { + emit beginRemoveRows(QModelIndex(), index, index); + list.removeAt(index); + emit endRemoveRows(); + } + + void moveItem(int from, int to) { + emit beginMoveRows(QModelIndex(), from, from, QModelIndex(), to); + list.move(from, to); + emit endMoveRows(); + } + + void modifyItem(int idx, const QString &name, const QString &number) { + list[idx] = QPair(name, number); + emit dataChanged(index(idx,0), index(idx,0)); + } + +private: + QList > list; }; @@ -165,6 +267,145 @@ void tst_QmlGraphicsPathView::path() QCOMPARE(cubic->control2Y(), 90.); } +void tst_QmlGraphicsPathView::dataModel() +{ + QmlView *canvas = createView(SRCDIR "/data/datamodel.qml"); + + QmlContext *ctxt = canvas->rootContext(); + TestObject *testObject = new TestObject; + ctxt->setContextProperty("testObject", testObject); + + TestModel model; + model.addItem("red", "1"); + model.addItem("green", "2"); + model.addItem("blue", "3"); + model.addItem("purple", "4"); + model.addItem("gray", "5"); + model.addItem("brown", "6"); + model.addItem("yellow", "7"); + model.addItem("thistle", "8"); + model.addItem("cyan", "9"); + + ctxt->setContextProperty("testData", &model); + + canvas->execute(); + qApp->processEvents(); + + QmlGraphicsPathView *pathview = qobject_cast(canvas->root()); + QVERIFY(pathview != 0); + + QMetaObject::invokeMethod(canvas->root(), "checkProperties"); + QVERIFY(testObject->error() == false); + + QmlGraphicsItem *item = findItem(pathview, "wrapper", 0); + QVERIFY(item); + QCOMPARE(item->x(), 110.0); + QCOMPARE(item->y(), 10.0); + + model.insertItem(4, "orange", "10"); + + int itemCount = findItems(pathview, "wrapper").count(); + QCOMPARE(itemCount, 10); + + QmlGraphicsText *text = findItem(pathview, "myText", 4); + QVERIFY(text); + QCOMPARE(text->text(), model.name(4)); + + model.removeItem(2); + text = findItem(pathview, "myText", 2); + QVERIFY(text); + QCOMPARE(text->text(), model.name(2)); + + testObject->setPathItemCount(5); + QMetaObject::invokeMethod(canvas->root(), "checkProperties"); + QVERIFY(testObject->error() == false); + + itemCount = findItems(pathview, "wrapper").count(); + QCOMPARE(itemCount, 5); + + model.insertItem(2, "pink", "2"); + + itemCount = findItems(pathview, "wrapper").count(); + QCOMPARE(itemCount, 5); + + text = findItem(pathview, "myText", 2); + QVERIFY(text); + QCOMPARE(text->text(), model.name(2)); + + model.removeItem(3); + itemCount = findItems(pathview, "wrapper").count(); + QCOMPARE(itemCount, 5); + text = findItem(pathview, "myText", 3); + QVERIFY(text); + QCOMPARE(text->text(), model.name(3)); + + delete canvas; +} + +QmlView *tst_QmlGraphicsPathView::createView(const QString &filename) +{ + QmlView *canvas = new QmlView(0); + canvas->setFixedSize(240,320); + + QFile file(filename); + file.open(QFile::ReadOnly); + QString qml = file.readAll(); + canvas->setQml(qml, filename); + + return canvas; +} + +/* + Find an item with the specified objectName. If index is supplied then the + item must also evaluate the {index} expression equal to index + */ +template +T *tst_QmlGraphicsPathView::findItem(QmlGraphicsItem *parent, const QString &objectName, int index) +{ + const QMetaObject &mo = T::staticMetaObject; + //qDebug() << parent->QGraphicsObject::children().count() << "children"; + for (int i = 0; i < parent->QGraphicsObject::children().count(); ++i) { + QmlGraphicsItem *item = qobject_cast(parent->QGraphicsObject::children().at(i)); + if(!item) + continue; + //qDebug() << "try" << item; + if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) { + if (index != -1) { + QmlExpression e(qmlContext(item), "index", item); + e.setTrackChange(false); + if (e.value().toInt() == index) + return static_cast(item); + } else { + return static_cast(item); + } + } + item = findItem(item, objectName, index); + if (item) + return static_cast(item); + } + + return 0; +} + +template +QList tst_QmlGraphicsPathView::findItems(QmlGraphicsItem *parent, const QString &objectName) +{ + QList items; + const QMetaObject &mo = T::staticMetaObject; + //qDebug() << parent->QGraphicsObject::children().count() << "children"; + for (int i = 0; i < parent->QGraphicsObject::children().count(); ++i) { + QmlGraphicsItem *item = qobject_cast(parent->QGraphicsObject::children().at(i)); + if(!item) + continue; + //qDebug() << "try" << item; + if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) + items.append(static_cast(item)); + items += findItems(item, objectName); + } + + return items; +} + QTEST_MAIN(tst_QmlGraphicsPathView) #include "tst_qmlgraphicspathview.moc" -- cgit v0.12 From eb58c6b1448eb39cb762bdbcc7fc006057bba325 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 18 Nov 2009 14:24:56 +1000 Subject: Doc. --- src/declarative/graphicsitems/qmlgraphicsgridview.cpp | 4 +++- src/declarative/graphicsitems/qmlgraphicslistview.cpp | 4 +++- src/declarative/graphicsitems/qmlgraphicspathview.cpp | 4 +++- src/declarative/graphicsitems/qmlgraphicsrepeater.cpp | 4 +++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/declarative/graphicsitems/qmlgraphicsgridview.cpp b/src/declarative/graphicsitems/qmlgraphicsgridview.cpp index 9465c4c..5ce2836 100644 --- a/src/declarative/graphicsitems/qmlgraphicsgridview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsgridview.cpp @@ -824,7 +824,9 @@ void QmlGraphicsGridView::setModel(const QVariant &model) /*! \qmlproperty component GridView::delegate - The delegate provides a template describing what each item in the view should look and act like. + The delegate provides a template defining each item instantiated by the view. + The index is exposed as an accessible \c index property. Properties of the + model are also available depending upon the type of \l {qmlmodels}{Data Model}. Here is an example delegate: \snippet doc/src/snippets/declarative/gridview/gridview.qml 0 diff --git a/src/declarative/graphicsitems/qmlgraphicslistview.cpp b/src/declarative/graphicsitems/qmlgraphicslistview.cpp index c075a8a..a166df2 100644 --- a/src/declarative/graphicsitems/qmlgraphicslistview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicslistview.cpp @@ -1139,7 +1139,9 @@ void QmlGraphicsListView::setModel(const QVariant &model) /*! \qmlproperty component ListView::delegate - The delegate provides a template describing what each item in the view should look and act like. + The delegate provides a template defining each item instantiated by the view. + The index is exposed as an accessible \c index property. Properties of the + model are also available depending upon the type of \l {qmlmodels}{Data Model}. Here is an example delegate: \snippet doc/src/snippets/declarative/listview/listview.qml 0 diff --git a/src/declarative/graphicsitems/qmlgraphicspathview.cpp b/src/declarative/graphicsitems/qmlgraphicspathview.cpp index 180954c..92751a0 100644 --- a/src/declarative/graphicsitems/qmlgraphicspathview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicspathview.cpp @@ -298,7 +298,9 @@ void QmlGraphicsPathView::setDragMargin(qreal dragMargin) /*! \qmlproperty component PathView::delegate - The delegate provides a template describing what each item in the view should look and act like. + The delegate provides a template defining each item instantiated by the view. + The index is exposed as an accessible \c index property. Properties of the + model are also available depending upon the type of \l {qmlmodels}{Data Model}. Here is an example delegate: \snippet doc/src/snippets/declarative/pathview/pathview.qml 1 diff --git a/src/declarative/graphicsitems/qmlgraphicsrepeater.cpp b/src/declarative/graphicsitems/qmlgraphicsrepeater.cpp index 7aed760..be10c24 100644 --- a/src/declarative/graphicsitems/qmlgraphicsrepeater.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsrepeater.cpp @@ -199,7 +199,9 @@ void QmlGraphicsRepeater::setModel(const QVariant &model) \qmlproperty Component Repeater::delegate \default - The delegate provides a template describing what each item instantiated by the repeater should look and act like. + The delegate provides a template defining each item instantiated by the repeater. + The index is exposed as an accessible \c index property. Properties of the + model are also available depending upon the type of \l {qmlmodels}{Data Model}. */ QmlComponent *QmlGraphicsRepeater::delegate() const { -- cgit v0.12 From a84c87af73058cb9ce7716aa2c9e767c8851369c Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 18 Nov 2009 14:25:10 +1000 Subject: On more Repeater test. --- tests/auto/declarative/repeater/tst_repeater.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/auto/declarative/repeater/tst_repeater.cpp b/tests/auto/declarative/repeater/tst_repeater.cpp index c0fa645..48ebd2c 100644 --- a/tests/auto/declarative/repeater/tst_repeater.cpp +++ b/tests/auto/declarative/repeater/tst_repeater.cpp @@ -280,8 +280,10 @@ void tst_QmlGraphicsRepeater::dataModel() QCOMPARE(container->childItems().count(), 4); testModel.addItem("four", "4"); - QCOMPARE(container->childItems().count(), 5); + + testModel.removeItem(2); + QCOMPARE(container->childItems().count(), 4); } void tst_QmlGraphicsRepeater::itemModel() -- cgit v0.12 From a8fedac7834029c80ffc2baaecf6aebef2e51c47 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 18 Nov 2009 14:53:14 +1000 Subject: Rename repeater -> qmlgraphicsrepeater --- tests/auto/declarative/declarative.pro | 2 +- .../qmlgraphicsrepeater/data/intmodel.qml | 29 ++ .../qmlgraphicsrepeater/data/itemlist.qml | 49 +++ .../qmlgraphicsrepeater/data/objlist.qml | 21 ++ .../qmlgraphicsrepeater/data/repeater.qml | 28 ++ .../qmlgraphicsrepeater/data/repeater2.qml | 35 ++ .../qmlgraphicsrepeater/qmlgraphicsrepeater.pro | 8 + .../tst_qmlgraphicsrepeater.cpp | 351 +++++++++++++++++++++ tests/auto/declarative/repeater/data/intmodel.qml | 29 -- tests/auto/declarative/repeater/data/itemlist.qml | 49 --- tests/auto/declarative/repeater/data/objlist.qml | 21 -- tests/auto/declarative/repeater/data/repeater.qml | 28 -- tests/auto/declarative/repeater/data/repeater2.qml | 35 -- tests/auto/declarative/repeater/repeater.pro | 8 - tests/auto/declarative/repeater/tst_repeater.cpp | 351 --------------------- 15 files changed, 522 insertions(+), 522 deletions(-) create mode 100644 tests/auto/declarative/qmlgraphicsrepeater/data/intmodel.qml create mode 100644 tests/auto/declarative/qmlgraphicsrepeater/data/itemlist.qml create mode 100644 tests/auto/declarative/qmlgraphicsrepeater/data/objlist.qml create mode 100644 tests/auto/declarative/qmlgraphicsrepeater/data/repeater.qml create mode 100644 tests/auto/declarative/qmlgraphicsrepeater/data/repeater2.qml create mode 100644 tests/auto/declarative/qmlgraphicsrepeater/qmlgraphicsrepeater.pro create mode 100644 tests/auto/declarative/qmlgraphicsrepeater/tst_qmlgraphicsrepeater.cpp delete mode 100644 tests/auto/declarative/repeater/data/intmodel.qml delete mode 100644 tests/auto/declarative/repeater/data/itemlist.qml delete mode 100644 tests/auto/declarative/repeater/data/objlist.qml delete mode 100644 tests/auto/declarative/repeater/data/repeater.qml delete mode 100644 tests/auto/declarative/repeater/data/repeater2.qml delete mode 100644 tests/auto/declarative/repeater/repeater.pro delete mode 100644 tests/auto/declarative/repeater/tst_repeater.cpp diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index e1817d6..33b5afc 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -54,7 +54,7 @@ SUBDIRS += \ qmltimer \ # Cover qmlxmllistmodel \ # Cover qpacketprotocol \ # Cover - repeater \ # Cover + qmlgraphicsrepeater \ # Cover sql \ # Cover states \ # Cover valuetypes \ # Cover diff --git a/tests/auto/declarative/qmlgraphicsrepeater/data/intmodel.qml b/tests/auto/declarative/qmlgraphicsrepeater/data/intmodel.qml new file mode 100644 index 0000000..2d6eae8 --- /dev/null +++ b/tests/auto/declarative/qmlgraphicsrepeater/data/intmodel.qml @@ -0,0 +1,29 @@ +import Qt 4.6 + +Rectangle { + id: container + objectName: "container" + width: 240 + height: 320 + color: "white" + + function checkProperties() { + testObject.error = false; + if (repeater.delegate != comp) { + print("delegate property incorrect"); + testObject.error = true; + } + } + + Component { + id: comp + Item{} + } + + Repeater { + id: repeater + objectName: "repeater" + model: testData + delegate: comp + } +} diff --git a/tests/auto/declarative/qmlgraphicsrepeater/data/itemlist.qml b/tests/auto/declarative/qmlgraphicsrepeater/data/itemlist.qml new file mode 100644 index 0000000..8d28bf8 --- /dev/null +++ b/tests/auto/declarative/qmlgraphicsrepeater/data/itemlist.qml @@ -0,0 +1,49 @@ +// This example demonstrates placing items in a view using +// a VisualItemModel + +import Qt 4.6 + +Rectangle { + color: "lightgray" + width: 240 + height: 320 + + function checkProperties() { + testObject.error = false; + if (testObject.useModel && view.model != itemModel) { + print("model property incorrect"); + testObject.error = true; + } + } + + VisualItemModel { + id: itemModel + objectName: "itemModel" + Rectangle { + objectName: "item1" + height: view.height; width: view.width; color: "#FFFEF0" + Text { objectName: "text1"; text: "index: " + parent.VisualItemModel.index; font.bold: true; anchors.centerIn: parent } + } + Rectangle { + objectName: "item2" + height: view.height; width: view.width; color: "#F0FFF7" + Text { objectName: "text2"; text: "index: " + parent.VisualItemModel.index; font.bold: true; anchors.centerIn: parent } + } + Rectangle { + objectName: "item3" + height: view.height; width: view.width; color: "#F4F0FF" + Text { objectName: "text3"; text: "index: " + parent.VisualItemModel.index; font.bold: true; anchors.centerIn: parent } + } + } + + Column { + objectName: "container" + Repeater { + id: view + objectName: "repeater" + anchors.fill: parent + anchors.bottomMargin: 30 + model: testObject.useModel ? itemModel : 0 + } + } +} diff --git a/tests/auto/declarative/qmlgraphicsrepeater/data/objlist.qml b/tests/auto/declarative/qmlgraphicsrepeater/data/objlist.qml new file mode 100644 index 0000000..ecc6d02 --- /dev/null +++ b/tests/auto/declarative/qmlgraphicsrepeater/data/objlist.qml @@ -0,0 +1,21 @@ +import Qt 4.6 + +Rectangle { + id: container + objectName: "container" + width: 240 + height: 320 + color: "white" + Repeater { + id: repeater + objectName: "repeater" + model: testData + property int errors: 0 + property int instantiated: 0 + Component { + Item{ + Component.onCompleted: {if(index!=modelData.idx) repeater.errors += 1; repeater.instantiated++} + } + } + } +} diff --git a/tests/auto/declarative/qmlgraphicsrepeater/data/repeater.qml b/tests/auto/declarative/qmlgraphicsrepeater/data/repeater.qml new file mode 100644 index 0000000..7d83230 --- /dev/null +++ b/tests/auto/declarative/qmlgraphicsrepeater/data/repeater.qml @@ -0,0 +1,28 @@ +import Qt 4.6 + +Rectangle { + id: container + objectName: "container" + width: 240 + height: 320 + color: "white" + Text { + text: "Zero" + } + Repeater { + id: repeater + objectName: "repeater" + width: 240 + height: 320 + model: testData + Component { + Text { + y: index*20 + text: modelData + } + } + } + Text { + text: "Last" + } +} diff --git a/tests/auto/declarative/qmlgraphicsrepeater/data/repeater2.qml b/tests/auto/declarative/qmlgraphicsrepeater/data/repeater2.qml new file mode 100644 index 0000000..c3c3260 --- /dev/null +++ b/tests/auto/declarative/qmlgraphicsrepeater/data/repeater2.qml @@ -0,0 +1,35 @@ +import Qt 4.6 + +Rectangle { + width: 240 + height: 320 + color: "white" + Component { + id: myDelegate + Item { + objectName: "myDelegate" + height: 20 + Text { + y: index*20 + text: name + } + Text { + y: index*20 + x: 100 + text: number + } + } + } + Column { + id: container + objectName: "container" + Repeater { + id: repeater + objectName: "repeater" + width: 240 + height: 320 + delegate: myDelegate + model: testData + } + } +} diff --git a/tests/auto/declarative/qmlgraphicsrepeater/qmlgraphicsrepeater.pro b/tests/auto/declarative/qmlgraphicsrepeater/qmlgraphicsrepeater.pro new file mode 100644 index 0000000..0a10ec6 --- /dev/null +++ b/tests/auto/declarative/qmlgraphicsrepeater/qmlgraphicsrepeater.pro @@ -0,0 +1,8 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative +macx:CONFIG -= app_bundle + +SOURCES += tst_qmlgraphicsrepeater.cpp + +# Define SRCDIR equal to test's source directory +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qmlgraphicsrepeater/tst_qmlgraphicsrepeater.cpp b/tests/auto/declarative/qmlgraphicsrepeater/tst_qmlgraphicsrepeater.cpp new file mode 100644 index 0000000..e8019d7 --- /dev/null +++ b/tests/auto/declarative/qmlgraphicsrepeater/tst_qmlgraphicsrepeater.cpp @@ -0,0 +1,351 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include +#include +#include +#include +#include + +class tst_QmlGraphicsRepeater : public QObject +{ + Q_OBJECT +public: + tst_QmlGraphicsRepeater(); + +private slots: + void numberModel(); + void objectList(); + void stringList(); + void dataModel(); + void itemModel(); + +private: + QmlView *createView(const QString &filename); + template + T *findItem(QObject *parent, const QString &id); +}; + +class TestObject : public QObject +{ + Q_OBJECT + + Q_PROPERTY(bool error READ error WRITE setError) + Q_PROPERTY(bool useModel READ useModel NOTIFY useModelChanged) + +public: + TestObject() : QObject(), mError(true), mUseModel(false) {} + + bool error() const { return mError; } + void setError(bool err) { mError = err; } + + bool useModel() const { return mUseModel; } + void setUseModel(bool use) { mUseModel = use; emit useModelChanged(); } + +signals: + void useModelChanged(); + +private: + bool mError; + bool mUseModel; +}; + +class TestModel : public QAbstractListModel +{ +public: + enum Roles { Name = Qt::UserRole+1, Number = Qt::UserRole+2 }; + + TestModel(QObject *parent=0) : QAbstractListModel(parent) { + QHash roles; + roles[Name] = "name"; + roles[Number] = "number"; + setRoleNames(roles); + } + + int rowCount(const QModelIndex &parent=QModelIndex()) const { return list.count(); } + QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const { + QVariant rv; + if (role == Name) + rv = list.at(index.row()).first; + else if (role == Number) + rv = list.at(index.row()).second; + + return rv; + } + + int count() const { return rowCount(); } + QString name(int index) const { return list.at(index).first; } + QString number(int index) const { return list.at(index).second; } + + void addItem(const QString &name, const QString &number) { + emit beginInsertRows(QModelIndex(), list.count(), list.count()); + list.append(QPair(name, number)); + emit endInsertRows(); + } + + void insertItem(int index, const QString &name, const QString &number) { + emit beginInsertRows(QModelIndex(), index, index); + list.insert(index, QPair(name, number)); + emit endInsertRows(); + } + + void removeItem(int index) { + emit beginRemoveRows(QModelIndex(), index, index); + list.removeAt(index); + emit endRemoveRows(); + } + + void moveItem(int from, int to) { + emit beginMoveRows(QModelIndex(), from, from, QModelIndex(), to); + list.move(from, to); + emit endMoveRows(); + } + + void modifyItem(int idx, const QString &name, const QString &number) { + list[idx] = QPair(name, number); + emit dataChanged(index(idx,0), index(idx,0)); + } + +private: + QList > list; +}; + + +tst_QmlGraphicsRepeater::tst_QmlGraphicsRepeater() +{ +} + +void tst_QmlGraphicsRepeater::numberModel() +{ + QmlView *canvas = createView(SRCDIR "/data/intmodel.qml"); + + QmlContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testData", 5); + TestObject *testObject = new TestObject; + ctxt->setContextProperty("testObject", testObject); + + canvas->execute(); + qApp->processEvents(); + + QmlGraphicsRepeater *repeater = findItem(canvas->root(), "repeater"); + QVERIFY(repeater != 0); + QCOMPARE(repeater->parentItem()->childItems().count(), 5+1); + + QMetaObject::invokeMethod(canvas->root(), "checkProperties"); + QVERIFY(testObject->error() == false); + + delete canvas; +} + +void tst_QmlGraphicsRepeater::objectList() +{ + QmlView *canvas = createView(SRCDIR "/data/objlist.qml"); + + QObjectList* data = new QObjectList; + for(int i=0; i<100; i++){ + *data << new QObject(); + data->back()->setProperty("idx", i); + } + + QmlContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testData", QVariant::fromValue(data)); + + canvas->execute(); + qApp->processEvents(); + + QmlGraphicsRepeater *repeater = findItem(canvas->root(), "repeater"); + QVERIFY(repeater != 0); + QCOMPARE(repeater->property("errors").toInt(), 0);//If this fails either they are out of order or can't find the object's data + QCOMPARE(repeater->property("instantiated").toInt(), 100); +} + +/* +The Repeater element creates children at its own position in its parent's +stacking order. In this test we insert a repeater between two other Text +elements to test this. +*/ +void tst_QmlGraphicsRepeater::stringList() +{ + QmlView *canvas = createView(SRCDIR "/data/repeater.qml"); + + QStringList data; + data << "One"; + data << "Two"; + data << "Three"; + data << "Four"; + + QmlContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testData", data); + + canvas->execute(); + qApp->processEvents(); + + QmlGraphicsRepeater *repeater = findItem(canvas->root(), "repeater"); + QVERIFY(repeater != 0); + + QmlGraphicsItem *container = findItem(canvas->root(), "container"); + QVERIFY(container != 0); + + QCOMPARE(container->childItems().count(), data.count() + 3); + + bool saw_repeater = false; + for (int i = 0; i < container->childItems().count(); ++i) { + + if (i == 0) { + QmlGraphicsText *name = qobject_cast(container->childItems().at(i)); + QVERIFY(name != 0); + QCOMPARE(name->text(), QLatin1String("Zero")); + } else if (i == container->childItems().count() - 2) { + // The repeater itself + QmlGraphicsRepeater *rep = qobject_cast(container->childItems().at(i)); + QCOMPARE(rep, repeater); + saw_repeater = true; + continue; + } else if (i == container->childItems().count() - 1) { + QmlGraphicsText *name = qobject_cast(container->childItems().at(i)); + QVERIFY(name != 0); + QCOMPARE(name->text(), QLatin1String("Last")); + } else { + QmlGraphicsText *name = qobject_cast(container->childItems().at(i)); + QVERIFY(name != 0); + QCOMPARE(name->text(), data.at(i-1)); + } + } + QVERIFY(saw_repeater); + + delete canvas; +} + +void tst_QmlGraphicsRepeater::dataModel() +{ + QmlView *canvas = createView(SRCDIR "/data/repeater2.qml"); + QmlContext *ctxt = canvas->rootContext(); + TestObject *testObject = new TestObject; + ctxt->setContextProperty("testObject", testObject); + + TestModel testModel; + testModel.addItem("one", "1"); + testModel.addItem("two", "2"); + testModel.addItem("three", "3"); + + ctxt->setContextProperty("testData", &testModel); + + canvas->execute(); + qApp->processEvents(); + + QmlGraphicsRepeater *repeater = findItem(canvas->root(), "repeater"); + QVERIFY(repeater != 0); + + QmlGraphicsItem *container = findItem(canvas->root(), "container"); + QVERIFY(container != 0); + + QCOMPARE(container->childItems().count(), 4); + + testModel.addItem("four", "4"); + QCOMPARE(container->childItems().count(), 5); + + testModel.removeItem(2); + QCOMPARE(container->childItems().count(), 4); +} + +void tst_QmlGraphicsRepeater::itemModel() +{ + QmlView *canvas = createView(SRCDIR "/data/itemlist.qml"); + QmlContext *ctxt = canvas->rootContext(); + TestObject *testObject = new TestObject; + ctxt->setContextProperty("testObject", testObject); + + canvas->execute(); + qApp->processEvents(); + + QmlGraphicsRepeater *repeater = findItem(canvas->root(), "repeater"); + QVERIFY(repeater != 0); + + QmlGraphicsItem *container = findItem(canvas->root(), "container"); + QVERIFY(container != 0); + + QCOMPARE(container->childItems().count(), 1); + + testObject->setUseModel(true); + QMetaObject::invokeMethod(canvas->root(), "checkProperties"); + QVERIFY(testObject->error() == false); + + QCOMPARE(container->childItems().count(), 4); + QVERIFY(qobject_cast(container->childItems().at(0))->objectName() == "item1"); + QVERIFY(qobject_cast(container->childItems().at(1))->objectName() == "item2"); + QVERIFY(qobject_cast(container->childItems().at(2))->objectName() == "item3"); + QVERIFY(container->childItems().at(3) == repeater); + + delete canvas; +} + + +QmlView *tst_QmlGraphicsRepeater::createView(const QString &filename) +{ + QmlView *canvas = new QmlView(0); + canvas->setFixedSize(240,320); + + QFile file(filename); + file.open(QFile::ReadOnly); + QString qml = file.readAll(); + canvas->setQml(qml, filename); + + return canvas; +} + +template +T *tst_QmlGraphicsRepeater::findItem(QObject *parent, const QString &objectName) +{ + const QMetaObject &mo = T::staticMetaObject; + if (mo.cast(parent) && (objectName.isEmpty() || parent->objectName() == objectName)) + return static_cast(parent); + for (int i = 0; i < parent->children().count(); ++i) { + QmlGraphicsItem *item = findItem(parent->children().at(i), objectName); + if (item) + return static_cast(item); + } + + return 0; +} + +QTEST_MAIN(tst_QmlGraphicsRepeater) + +#include "tst_qmlgraphicsrepeater.moc" diff --git a/tests/auto/declarative/repeater/data/intmodel.qml b/tests/auto/declarative/repeater/data/intmodel.qml deleted file mode 100644 index 2d6eae8..0000000 --- a/tests/auto/declarative/repeater/data/intmodel.qml +++ /dev/null @@ -1,29 +0,0 @@ -import Qt 4.6 - -Rectangle { - id: container - objectName: "container" - width: 240 - height: 320 - color: "white" - - function checkProperties() { - testObject.error = false; - if (repeater.delegate != comp) { - print("delegate property incorrect"); - testObject.error = true; - } - } - - Component { - id: comp - Item{} - } - - Repeater { - id: repeater - objectName: "repeater" - model: testData - delegate: comp - } -} diff --git a/tests/auto/declarative/repeater/data/itemlist.qml b/tests/auto/declarative/repeater/data/itemlist.qml deleted file mode 100644 index 8d28bf8..0000000 --- a/tests/auto/declarative/repeater/data/itemlist.qml +++ /dev/null @@ -1,49 +0,0 @@ -// This example demonstrates placing items in a view using -// a VisualItemModel - -import Qt 4.6 - -Rectangle { - color: "lightgray" - width: 240 - height: 320 - - function checkProperties() { - testObject.error = false; - if (testObject.useModel && view.model != itemModel) { - print("model property incorrect"); - testObject.error = true; - } - } - - VisualItemModel { - id: itemModel - objectName: "itemModel" - Rectangle { - objectName: "item1" - height: view.height; width: view.width; color: "#FFFEF0" - Text { objectName: "text1"; text: "index: " + parent.VisualItemModel.index; font.bold: true; anchors.centerIn: parent } - } - Rectangle { - objectName: "item2" - height: view.height; width: view.width; color: "#F0FFF7" - Text { objectName: "text2"; text: "index: " + parent.VisualItemModel.index; font.bold: true; anchors.centerIn: parent } - } - Rectangle { - objectName: "item3" - height: view.height; width: view.width; color: "#F4F0FF" - Text { objectName: "text3"; text: "index: " + parent.VisualItemModel.index; font.bold: true; anchors.centerIn: parent } - } - } - - Column { - objectName: "container" - Repeater { - id: view - objectName: "repeater" - anchors.fill: parent - anchors.bottomMargin: 30 - model: testObject.useModel ? itemModel : 0 - } - } -} diff --git a/tests/auto/declarative/repeater/data/objlist.qml b/tests/auto/declarative/repeater/data/objlist.qml deleted file mode 100644 index ecc6d02..0000000 --- a/tests/auto/declarative/repeater/data/objlist.qml +++ /dev/null @@ -1,21 +0,0 @@ -import Qt 4.6 - -Rectangle { - id: container - objectName: "container" - width: 240 - height: 320 - color: "white" - Repeater { - id: repeater - objectName: "repeater" - model: testData - property int errors: 0 - property int instantiated: 0 - Component { - Item{ - Component.onCompleted: {if(index!=modelData.idx) repeater.errors += 1; repeater.instantiated++} - } - } - } -} diff --git a/tests/auto/declarative/repeater/data/repeater.qml b/tests/auto/declarative/repeater/data/repeater.qml deleted file mode 100644 index 7d83230..0000000 --- a/tests/auto/declarative/repeater/data/repeater.qml +++ /dev/null @@ -1,28 +0,0 @@ -import Qt 4.6 - -Rectangle { - id: container - objectName: "container" - width: 240 - height: 320 - color: "white" - Text { - text: "Zero" - } - Repeater { - id: repeater - objectName: "repeater" - width: 240 - height: 320 - model: testData - Component { - Text { - y: index*20 - text: modelData - } - } - } - Text { - text: "Last" - } -} diff --git a/tests/auto/declarative/repeater/data/repeater2.qml b/tests/auto/declarative/repeater/data/repeater2.qml deleted file mode 100644 index c3c3260..0000000 --- a/tests/auto/declarative/repeater/data/repeater2.qml +++ /dev/null @@ -1,35 +0,0 @@ -import Qt 4.6 - -Rectangle { - width: 240 - height: 320 - color: "white" - Component { - id: myDelegate - Item { - objectName: "myDelegate" - height: 20 - Text { - y: index*20 - text: name - } - Text { - y: index*20 - x: 100 - text: number - } - } - } - Column { - id: container - objectName: "container" - Repeater { - id: repeater - objectName: "repeater" - width: 240 - height: 320 - delegate: myDelegate - model: testData - } - } -} diff --git a/tests/auto/declarative/repeater/repeater.pro b/tests/auto/declarative/repeater/repeater.pro deleted file mode 100644 index 968904b..0000000 --- a/tests/auto/declarative/repeater/repeater.pro +++ /dev/null @@ -1,8 +0,0 @@ -load(qttest_p4) -contains(QT_CONFIG,declarative): QT += declarative -macx:CONFIG -= app_bundle - -SOURCES += tst_repeater.cpp - -# Define SRCDIR equal to test's source directory -DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/repeater/tst_repeater.cpp b/tests/auto/declarative/repeater/tst_repeater.cpp deleted file mode 100644 index 48ebd2c..0000000 --- a/tests/auto/declarative/repeater/tst_repeater.cpp +++ /dev/null @@ -1,351 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include -#include -#include -#include -#include -#include - -class tst_QmlGraphicsRepeater : public QObject -{ - Q_OBJECT -public: - tst_QmlGraphicsRepeater(); - -private slots: - void numberModel(); - void objectList(); - void stringList(); - void dataModel(); - void itemModel(); - -private: - QmlView *createView(const QString &filename); - template - T *findItem(QObject *parent, const QString &id); -}; - -class TestObject : public QObject -{ - Q_OBJECT - - Q_PROPERTY(bool error READ error WRITE setError) - Q_PROPERTY(bool useModel READ useModel NOTIFY useModelChanged) - -public: - TestObject() : QObject(), mError(true), mUseModel(false) {} - - bool error() const { return mError; } - void setError(bool err) { mError = err; } - - bool useModel() const { return mUseModel; } - void setUseModel(bool use) { mUseModel = use; emit useModelChanged(); } - -signals: - void useModelChanged(); - -private: - bool mError; - bool mUseModel; -}; - -class TestModel : public QAbstractListModel -{ -public: - enum Roles { Name = Qt::UserRole+1, Number = Qt::UserRole+2 }; - - TestModel(QObject *parent=0) : QAbstractListModel(parent) { - QHash roles; - roles[Name] = "name"; - roles[Number] = "number"; - setRoleNames(roles); - } - - int rowCount(const QModelIndex &parent=QModelIndex()) const { return list.count(); } - QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const { - QVariant rv; - if (role == Name) - rv = list.at(index.row()).first; - else if (role == Number) - rv = list.at(index.row()).second; - - return rv; - } - - int count() const { return rowCount(); } - QString name(int index) const { return list.at(index).first; } - QString number(int index) const { return list.at(index).second; } - - void addItem(const QString &name, const QString &number) { - emit beginInsertRows(QModelIndex(), list.count(), list.count()); - list.append(QPair(name, number)); - emit endInsertRows(); - } - - void insertItem(int index, const QString &name, const QString &number) { - emit beginInsertRows(QModelIndex(), index, index); - list.insert(index, QPair(name, number)); - emit endInsertRows(); - } - - void removeItem(int index) { - emit beginRemoveRows(QModelIndex(), index, index); - list.removeAt(index); - emit endRemoveRows(); - } - - void moveItem(int from, int to) { - emit beginMoveRows(QModelIndex(), from, from, QModelIndex(), to); - list.move(from, to); - emit endMoveRows(); - } - - void modifyItem(int idx, const QString &name, const QString &number) { - list[idx] = QPair(name, number); - emit dataChanged(index(idx,0), index(idx,0)); - } - -private: - QList > list; -}; - - -tst_QmlGraphicsRepeater::tst_QmlGraphicsRepeater() -{ -} - -void tst_QmlGraphicsRepeater::numberModel() -{ - QmlView *canvas = createView(SRCDIR "/data/intmodel.qml"); - - QmlContext *ctxt = canvas->rootContext(); - ctxt->setContextProperty("testData", 5); - TestObject *testObject = new TestObject; - ctxt->setContextProperty("testObject", testObject); - - canvas->execute(); - qApp->processEvents(); - - QmlGraphicsRepeater *repeater = findItem(canvas->root(), "repeater"); - QVERIFY(repeater != 0); - QCOMPARE(repeater->parentItem()->childItems().count(), 5+1); - - QMetaObject::invokeMethod(canvas->root(), "checkProperties"); - QVERIFY(testObject->error() == false); - - delete canvas; -} - -void tst_QmlGraphicsRepeater::objectList() -{ - QmlView *canvas = createView(SRCDIR "/data/objlist.qml"); - - QObjectList* data = new QObjectList; - for(int i=0; i<100; i++){ - *data << new QObject(); - data->back()->setProperty("idx", i); - } - - QmlContext *ctxt = canvas->rootContext(); - ctxt->setContextProperty("testData", QVariant::fromValue(data)); - - canvas->execute(); - qApp->processEvents(); - - QmlGraphicsRepeater *repeater = findItem(canvas->root(), "repeater"); - QVERIFY(repeater != 0); - QCOMPARE(repeater->property("errors").toInt(), 0);//If this fails either they are out of order or can't find the object's data - QCOMPARE(repeater->property("instantiated").toInt(), 100); -} - -/* -The Repeater element creates children at its own position in its parent's -stacking order. In this test we insert a repeater between two other Text -elements to test this. -*/ -void tst_QmlGraphicsRepeater::stringList() -{ - QmlView *canvas = createView(SRCDIR "/data/repeater.qml"); - - QStringList data; - data << "One"; - data << "Two"; - data << "Three"; - data << "Four"; - - QmlContext *ctxt = canvas->rootContext(); - ctxt->setContextProperty("testData", data); - - canvas->execute(); - qApp->processEvents(); - - QmlGraphicsRepeater *repeater = findItem(canvas->root(), "repeater"); - QVERIFY(repeater != 0); - - QmlGraphicsItem *container = findItem(canvas->root(), "container"); - QVERIFY(container != 0); - - QCOMPARE(container->childItems().count(), data.count() + 3); - - bool saw_repeater = false; - for (int i = 0; i < container->childItems().count(); ++i) { - - if (i == 0) { - QmlGraphicsText *name = qobject_cast(container->childItems().at(i)); - QVERIFY(name != 0); - QCOMPARE(name->text(), QLatin1String("Zero")); - } else if (i == container->childItems().count() - 2) { - // The repeater itself - QmlGraphicsRepeater *rep = qobject_cast(container->childItems().at(i)); - QCOMPARE(rep, repeater); - saw_repeater = true; - continue; - } else if (i == container->childItems().count() - 1) { - QmlGraphicsText *name = qobject_cast(container->childItems().at(i)); - QVERIFY(name != 0); - QCOMPARE(name->text(), QLatin1String("Last")); - } else { - QmlGraphicsText *name = qobject_cast(container->childItems().at(i)); - QVERIFY(name != 0); - QCOMPARE(name->text(), data.at(i-1)); - } - } - QVERIFY(saw_repeater); - - delete canvas; -} - -void tst_QmlGraphicsRepeater::dataModel() -{ - QmlView *canvas = createView(SRCDIR "/data/repeater2.qml"); - QmlContext *ctxt = canvas->rootContext(); - TestObject *testObject = new TestObject; - ctxt->setContextProperty("testObject", testObject); - - TestModel testModel; - testModel.addItem("one", "1"); - testModel.addItem("two", "2"); - testModel.addItem("three", "3"); - - ctxt->setContextProperty("testData", &testModel); - - canvas->execute(); - qApp->processEvents(); - - QmlGraphicsRepeater *repeater = findItem(canvas->root(), "repeater"); - QVERIFY(repeater != 0); - - QmlGraphicsItem *container = findItem(canvas->root(), "container"); - QVERIFY(container != 0); - - QCOMPARE(container->childItems().count(), 4); - - testModel.addItem("four", "4"); - QCOMPARE(container->childItems().count(), 5); - - testModel.removeItem(2); - QCOMPARE(container->childItems().count(), 4); -} - -void tst_QmlGraphicsRepeater::itemModel() -{ - QmlView *canvas = createView(SRCDIR "/data/itemlist.qml"); - QmlContext *ctxt = canvas->rootContext(); - TestObject *testObject = new TestObject; - ctxt->setContextProperty("testObject", testObject); - - canvas->execute(); - qApp->processEvents(); - - QmlGraphicsRepeater *repeater = findItem(canvas->root(), "repeater"); - QVERIFY(repeater != 0); - - QmlGraphicsItem *container = findItem(canvas->root(), "container"); - QVERIFY(container != 0); - - QCOMPARE(container->childItems().count(), 1); - - testObject->setUseModel(true); - QMetaObject::invokeMethod(canvas->root(), "checkProperties"); - QVERIFY(testObject->error() == false); - - QCOMPARE(container->childItems().count(), 4); - QVERIFY(qobject_cast(container->childItems().at(0))->objectName() == "item1"); - QVERIFY(qobject_cast(container->childItems().at(1))->objectName() == "item2"); - QVERIFY(qobject_cast(container->childItems().at(2))->objectName() == "item3"); - QVERIFY(container->childItems().at(3) == repeater); - - delete canvas; -} - - -QmlView *tst_QmlGraphicsRepeater::createView(const QString &filename) -{ - QmlView *canvas = new QmlView(0); - canvas->setFixedSize(240,320); - - QFile file(filename); - file.open(QFile::ReadOnly); - QString qml = file.readAll(); - canvas->setQml(qml, filename); - - return canvas; -} - -template -T *tst_QmlGraphicsRepeater::findItem(QObject *parent, const QString &objectName) -{ - const QMetaObject &mo = T::staticMetaObject; - if (mo.cast(parent) && (objectName.isEmpty() || parent->objectName() == objectName)) - return static_cast(parent); - for (int i = 0; i < parent->children().count(); ++i) { - QmlGraphicsItem *item = findItem(parent->children().at(i), objectName); - if (item) - return static_cast(item); - } - - return 0; -} - -QTEST_MAIN(tst_QmlGraphicsRepeater) - -#include "tst_repeater.moc" -- cgit v0.12 From eaa5d6d945b5bcab2cbdce01a0780ccdadbd2719 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 18 Nov 2009 14:58:37 +1000 Subject: Make sure pathview flicks go through event filter path also. --- tests/auto/declarative/visual/qmlgraphicspathview/test-pathview.qml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/auto/declarative/visual/qmlgraphicspathview/test-pathview.qml b/tests/auto/declarative/visual/qmlgraphicspathview/test-pathview.qml index 1ffbe15..70018b6 100644 --- a/tests/auto/declarative/visual/qmlgraphicspathview/test-pathview.qml +++ b/tests/auto/declarative/visual/qmlgraphicspathview/test-pathview.qml @@ -21,6 +21,8 @@ Rectangle { id: wrapper width: 85; height: 85; color: lColor scale: wrapper.PathView.scale + + MouseRegion { anchors.fill: parent } transform: Rotation { id: itemRotation; origin.x: wrapper.width/2; origin.y: wrapper.height/2 -- cgit v0.12