diff options
author | Warwick Allison <warwick.allison@nokia.com> | 2009-11-18 05:10:17 (GMT) |
---|---|---|
committer | Warwick Allison <warwick.allison@nokia.com> | 2009-11-18 05:10:17 (GMT) |
commit | bbcba4d1266fcfbd7e976fb4611cda39964f4529 (patch) | |
tree | f2db8af7baac046292bdf0a93b4a16647a6720f0 | |
parent | 46c4a95f70deb36c8877d4d8a1e419490d9100ab (diff) | |
parent | eaa5d6d945b5bcab2cbdce01a0780ccdadbd2719 (diff) | |
download | Qt-bbcba4d1266fcfbd7e976fb4611cda39964f4529.zip Qt-bbcba4d1266fcfbd7e976fb4611cda39964f4529.tar.gz Qt-bbcba4d1266fcfbd7e976fb4611cda39964f4529.tar.bz2 |
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
22 files changed, 770 insertions, 136 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/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<PathElement> 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<QmlGraphicsCurve *>(pathElement)) { curve->addToPath(d->_path); AttributePoint p; p.origpercent = d->_path.length(); d->_attributePoints << p; + lastCurve = curve; } else if (QmlGraphicsPathAttribute *attribute = qobject_cast<QmlGraphicsPathAttribute *>(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<QmlGraphicsPathElement *>* 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<QmlGraphicsPathElement*> _pathElements; @@ -73,6 +73,7 @@ public: QStringList _attributes; int startX; int startY; + bool closed; }; QT_END_NAMESPACE 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 { 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<QmlAbstractAnimation *> *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) 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<QStringList>(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<void *> *li = *(QList<void *> **)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<QStringList>(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<void *> *li = *(QList<void *> **)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<QStringList>(d).append(str); - break; - } - case VariantList: - { - qvariant_cast<QVariantList>(d).append(value); - break; - } case QmlList: { QmlPrivate::ListInterface *li = *(QmlPrivate::ListInterface **)d.constData(); - li->append(const_cast<void *>(value.constData())); //XXX - break; + li->append(const_cast<void *>(value.constData())); //XXX Typesafety + return true; + } + case QListPtr: + { + QList<void *> *li = *(QList<void *> **)d.constData(); + li->append(*reinterpret_cast<void **>(const_cast<void *>(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<QStringList>(d).insert(index, str); - break; - } - case VariantList: - { - qvariant_cast<QVariantList>(d).insert(index, value); - break; - } case QmlList: { QmlPrivate::ListInterface *li = *(QmlPrivate::ListInterface **)d.constData(); - li->insert(index, const_cast<void *>(value.constData())); //XXX - break; + li->insert(index, const_cast<void *>(value.constData())); //XXX Typesafety + return true; + } + case QListPtr: + { + QList<void *> *li = *(QList<void *>**)d.constData(); + li->insert(index, *reinterpret_cast<void **>(const_cast<void *>(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<QStringList>(d).removeAt(index); - break; - case VariantList: - qvariant_cast<QVariantList>(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<void *> *li = *(QList<void *>**)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<QStringList>(d).clear(); - break; - case VariantList: - qvariant_cast<QVariantList>(d).clear(); - break; case QmlList: { QmlPrivate::ListInterface *li = *(QmlPrivate::ListInterface **)d.constData(); li->clear(); - break; + return true; + } + case QListPtr: + { + QList<void *> *li = *(QList<void *>**)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/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/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 <qtest.h> #include <QtDeclarative/qmlengine.h> #include <QtDeclarative/qmlcomponent.h> +#include <QtDeclarative/qmlview.h> +#include <QtDeclarative/private/qmlgraphicstext_p.h> +#include <QAbstractListModel> +#include <QFile> #include <private/qmlvaluetype_p.h> #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<typename T> + T *findItem(QmlGraphicsItem *parent, const QString &objectName, int index=-1); + template<typename T> + QList<T*> 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<int, QByteArray> 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<QString,QString>(name, number)); + emit endInsertRows(); + } + + void insertItem(int index, const QString &name, const QString &number) { + emit beginInsertRows(QModelIndex(), index, index); + list.insert(index, QPair<QString,QString>(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<QString,QString>(name, number); + emit dataChanged(index(idx,0), index(idx,0)); + } + +private: + QList<QPair<QString,QString> > 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<QmlGraphicsPathView*>(canvas->root()); + QVERIFY(pathview != 0); + + QMetaObject::invokeMethod(canvas->root(), "checkProperties"); + QVERIFY(testObject->error() == false); + + QmlGraphicsItem *item = findItem<QmlGraphicsItem>(pathview, "wrapper", 0); + QVERIFY(item); + QCOMPARE(item->x(), 110.0); + QCOMPARE(item->y(), 10.0); + + model.insertItem(4, "orange", "10"); + + int itemCount = findItems<QmlGraphicsItem>(pathview, "wrapper").count(); + QCOMPARE(itemCount, 10); + + QmlGraphicsText *text = findItem<QmlGraphicsText>(pathview, "myText", 4); + QVERIFY(text); + QCOMPARE(text->text(), model.name(4)); + + model.removeItem(2); + text = findItem<QmlGraphicsText>(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<QmlGraphicsItem>(pathview, "wrapper").count(); + QCOMPARE(itemCount, 5); + + model.insertItem(2, "pink", "2"); + + itemCount = findItems<QmlGraphicsItem>(pathview, "wrapper").count(); + QCOMPARE(itemCount, 5); + + text = findItem<QmlGraphicsText>(pathview, "myText", 2); + QVERIFY(text); + QCOMPARE(text->text(), model.name(2)); + + model.removeItem(3); + itemCount = findItems<QmlGraphicsItem>(pathview, "wrapper").count(); + QCOMPARE(itemCount, 5); + text = findItem<QmlGraphicsText>(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<typename T> +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<QmlGraphicsItem*>(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<T*>(item); + } else { + return static_cast<T*>(item); + } + } + item = findItem<T>(item, objectName, index); + if (item) + return static_cast<T*>(item); + } + + return 0; +} + +template<typename T> +QList<T*> tst_QmlGraphicsPathView::findItems(QmlGraphicsItem *parent, const QString &objectName) +{ + QList<T*> 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<QmlGraphicsItem*>(parent->QGraphicsObject::children().at(i)); + if(!item) + continue; + //qDebug() << "try" << item; + if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) + items.append(static_cast<T*>(item)); + items += findItems<T>(item, objectName); + } + + return items; +} + QTEST_MAIN(tst_QmlGraphicsPathView) #include "tst_qmlgraphicspathview.moc" diff --git a/tests/auto/declarative/repeater/data/intmodel.qml b/tests/auto/declarative/qmlgraphicsrepeater/data/intmodel.qml index 2d6eae8..2d6eae8 100644 --- a/tests/auto/declarative/repeater/data/intmodel.qml +++ b/tests/auto/declarative/qmlgraphicsrepeater/data/intmodel.qml diff --git a/tests/auto/declarative/repeater/data/itemlist.qml b/tests/auto/declarative/qmlgraphicsrepeater/data/itemlist.qml index 8d28bf8..8d28bf8 100644 --- a/tests/auto/declarative/repeater/data/itemlist.qml +++ b/tests/auto/declarative/qmlgraphicsrepeater/data/itemlist.qml diff --git a/tests/auto/declarative/repeater/data/objlist.qml b/tests/auto/declarative/qmlgraphicsrepeater/data/objlist.qml index ecc6d02..ecc6d02 100644 --- a/tests/auto/declarative/repeater/data/objlist.qml +++ b/tests/auto/declarative/qmlgraphicsrepeater/data/objlist.qml diff --git a/tests/auto/declarative/repeater/data/repeater.qml b/tests/auto/declarative/qmlgraphicsrepeater/data/repeater.qml index 7d83230..7d83230 100644 --- a/tests/auto/declarative/repeater/data/repeater.qml +++ b/tests/auto/declarative/qmlgraphicsrepeater/data/repeater.qml diff --git a/tests/auto/declarative/repeater/data/repeater2.qml b/tests/auto/declarative/qmlgraphicsrepeater/data/repeater2.qml index c3c3260..c3c3260 100644 --- a/tests/auto/declarative/repeater/data/repeater2.qml +++ b/tests/auto/declarative/qmlgraphicsrepeater/data/repeater2.qml diff --git a/tests/auto/declarative/repeater/repeater.pro b/tests/auto/declarative/qmlgraphicsrepeater/qmlgraphicsrepeater.pro index 968904b..0a10ec6 100644 --- a/tests/auto/declarative/repeater/repeater.pro +++ b/tests/auto/declarative/qmlgraphicsrepeater/qmlgraphicsrepeater.pro @@ -2,7 +2,7 @@ load(qttest_p4) contains(QT_CONFIG,declarative): QT += declarative macx:CONFIG -= app_bundle -SOURCES += tst_repeater.cpp +SOURCES += tst_qmlgraphicsrepeater.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/qmlgraphicsrepeater/tst_qmlgraphicsrepeater.cpp index c0fa645..e8019d7 100644 --- a/tests/auto/declarative/repeater/tst_repeater.cpp +++ b/tests/auto/declarative/qmlgraphicsrepeater/tst_qmlgraphicsrepeater.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() @@ -346,4 +348,4 @@ T *tst_QmlGraphicsRepeater::findItem(QObject *parent, const QString &objectName) QTEST_MAIN(tst_QmlGraphicsRepeater) -#include "tst_repeater.moc" +#include "tst_qmlgraphicsrepeater.moc" 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<QObject*> 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<QObject*>*)&list)); + QCOMPARE(accessor.list(), qVariantFromValue((QmlList<QObject*>*)&list)); + // type + QCOMPARE(accessor.type(), QmlListAccessor::QmlList); + + // isValid QVERIFY(accessor.isValid()); - QVERIFY(accessor.count() == 1); - QVariant v = accessor.at(0); - QCOMPARE(qvariant_cast<QObject*>(v), obj); + // count + QCOMPARE(accessor.count(), 1); + + // at + QCOMPARE(qvariant_cast<QObject*>(accessor.at(0)), obj); + + // append + accessor.append(qVariantFromValue(obj2)); + QVERIFY(accessor.isValid()); + QCOMPARE(accessor.count(), 2); + QCOMPARE(qvariant_cast<QObject*>(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<QObject*>(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<QObject*>(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<QObject*> 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<QObject*>*)&list)); + QCOMPARE(accessor.list(), qVariantFromValue((QList<QObject*>*)&list)); + + // type + QCOMPARE(accessor.type(), QmlListAccessor::QListPtr); + + // isValid + QVERIFY(accessor.isValid()); + + // count + QCOMPARE(accessor.count(), 1); + + // at + QCOMPARE(qvariant_cast<QObject*>(accessor.at(0)), obj); + + // append + accessor.append(qVariantFromValue(obj2)); + QVERIFY(accessor.isValid()); + QCOMPARE(accessor.count(), 2); + QCOMPARE(qvariant_cast<QObject*>(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<QObject*>(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<QObject*>(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<QString>(accessor.at(0)), QLatin1String("Item1")); + QCOMPARE(qvariant_cast<QString>(accessor.at(1)), QLatin1String("Item2")); + + // append + QVERIFY(!accessor.append(QVariant("Item3"))); + QVERIFY(accessor.isValid()); + QVERIFY(accessor.count() == 2); + QCOMPARE(qvariant_cast<QString>(accessor.at(0)), QLatin1String("Item1")); + QCOMPARE(qvariant_cast<QString>(accessor.at(1)), QLatin1String("Item2")); + + // insert + QVERIFY(!accessor.insert(1, QVariant("MiddleItem"))); + QVERIFY(accessor.isValid()); + QVERIFY(accessor.count() == 2); + QCOMPARE(qvariant_cast<QString>(accessor.at(0)), QLatin1String("Item1")); + QCOMPARE(qvariant_cast<QString>(accessor.at(1)), QLatin1String("Item2")); + + // removeAt + QVERIFY(!accessor.removeAt(1)); + QVERIFY(accessor.isValid()); + QVERIFY(accessor.count() == 2); + QCOMPARE(qvariant_cast<QString>(accessor.at(0)), QLatin1String("Item1")); + QCOMPARE(qvariant_cast<QString>(accessor.at(1)), QLatin1String("Item2")); + + // clear + QVERIFY(!accessor.clear()); + QVERIFY(accessor.isValid()); + QVERIFY(accessor.count() == 2); + QCOMPARE(qvariant_cast<QString>(accessor.at(0)), QLatin1String("Item1")); + QCOMPARE(qvariant_cast<QString>(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<QString>(accessor.at(0)), QLatin1String("Item1")); + QCOMPARE(qvariant_cast<QString>(accessor.at(1)), QLatin1String("Item2")); + + // append + QVERIFY(!accessor.append(QVariant("Item3"))); QVERIFY(accessor.isValid()); QVERIFY(accessor.count() == 2); + QCOMPARE(qvariant_cast<QString>(accessor.at(0)), QLatin1String("Item1")); + QCOMPARE(qvariant_cast<QString>(accessor.at(1)), QLatin1String("Item2")); + + // insert + QVERIFY(!accessor.insert(1, QVariant("MiddleItem"))); + QVERIFY(accessor.isValid()); + QVERIFY(accessor.count() == 2); + QCOMPARE(qvariant_cast<QString>(accessor.at(0)), QLatin1String("Item1")); + QCOMPARE(qvariant_cast<QString>(accessor.at(1)), QLatin1String("Item2")); + + // removeAt + QVERIFY(!accessor.removeAt(1)); + QVERIFY(accessor.isValid()); + QVERIFY(accessor.count() == 2); + QCOMPARE(qvariant_cast<QString>(accessor.at(0)), QLatin1String("Item1")); + QCOMPARE(qvariant_cast<QString>(accessor.at(1)), QLatin1String("Item2")); + + // clear + QVERIFY(!accessor.clear()); + QVERIFY(accessor.isValid()); + QVERIFY(accessor.count() == 2); + QCOMPARE(qvariant_cast<QString>(accessor.at(0)), QLatin1String("Item1")); + QCOMPARE(qvariant_cast<QString>(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<QString>(v), QLatin1String("Item1")); + // type + QCOMPARE(accessor.type(), QmlListAccessor::Instance); - v = accessor.at(1); - QCOMPARE(qvariant_cast<QString>(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) 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 |