diff options
author | Bea Lam <bea.lam@nokia.com> | 2009-11-18 06:22:49 (GMT) |
---|---|---|
committer | Bea Lam <bea.lam@nokia.com> | 2009-11-18 06:22:49 (GMT) |
commit | d15ac49efd7fab66258bd5b1e8998146ce204695 (patch) | |
tree | 86fd47a014e805f569f3d77255effc2213d862d3 | |
parent | 1c719c4ea6abef35ccae67f6052d8baa74b4e2b3 (diff) | |
parent | c098fef1f410c54f0655af9532d45f80a77b3a91 (diff) | |
download | Qt-d15ac49efd7fab66258bd5b1e8998146ce204695.zip Qt-d15ac49efd7fab66258bd5b1e8998146ce204695.tar.gz Qt-d15ac49efd7fab66258bd5b1e8998146ce204695.tar.bz2 |
Merge branch 'kinetic-declarativeui' of scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
22 files changed, 350 insertions, 28 deletions
diff --git a/demos/declarative/webbrowser/webbrowser.qml b/demos/declarative/webbrowser/webbrowser.qml index 23e0a20..0f6ed25 100644 --- a/demos/declarative/webbrowser/webbrowser.qml +++ b/demos/declarative/webbrowser/webbrowser.qml @@ -216,7 +216,7 @@ Item { preferredHeight: flickable.height zoomFactor: flickable.width > 980 ? 1 : flickable.width/980 - onUrlChanged: { if (url != null) { webBrowser.urlString = url.toString(); } } + onUrlChanged: { if (url != null) { editUrl.text = url.toString(); } } onDoubleClick: { if (!heuristicZoom(clickX,clickY,2.5)) { var zf = flickable.width > 980 ? 1 : flickable.width/980; diff --git a/src/declarative/graphicsitems/qmlgraphicsgridview.cpp b/src/declarative/graphicsitems/qmlgraphicsgridview.cpp index 9465c4c..473f9e5 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 @@ -948,7 +950,6 @@ void QmlGraphicsGridView::setHighlight(QmlComponent *highlight) { Q_D(QmlGraphicsGridView); if (highlight != d->highlightComponent) { - delete d->highlightComponent; d->highlightComponent = highlight; d->updateCurrent(d->currentIndex); } diff --git a/src/declarative/graphicsitems/qmlgraphicslistview.cpp b/src/declarative/graphicsitems/qmlgraphicslistview.cpp index c075a8a..c6291f2 100644 --- a/src/declarative/graphicsitems/qmlgraphicslistview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicslistview.cpp @@ -503,7 +503,7 @@ void QmlGraphicsListViewPrivate::refill(qreal from, qreal to) return; from -= buffer; to += buffer; - int modelIndex = 0; + int modelIndex = visibleIndex; qreal itemEnd = visiblePos-1; if (!visibleItems.isEmpty()) { visiblePos = visibleItems.first()->position(); @@ -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 @@ -1167,6 +1169,9 @@ void QmlGraphicsListView::setDelegate(QmlComponent *delegate) if (QmlGraphicsVisualDataModel *dataModel = qobject_cast<QmlGraphicsVisualDataModel*>(d->model)) { dataModel->setDelegate(delegate); if (isComponentComplete()) { + for (int i = 0; i < d->visibleItems.count(); ++i) + d->releaseItem(d->visibleItems.at(i)); + d->visibleItems.clear(); refill(); d->moveReason = QmlGraphicsListViewPrivate::SetIndex; d->updateCurrent(d->currentIndex); @@ -1266,9 +1271,10 @@ void QmlGraphicsListView::setHighlight(QmlComponent *highlight) { Q_D(QmlGraphicsListView); if (highlight != d->highlightComponent) { - delete d->highlightComponent; d->highlightComponent = highlight; - d->updateCurrent(d->currentIndex); + d->createHighlight(); + if (d->currentItem) + d->updateHighlight(); } } 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/graphicsitems/qmlgraphicsvisualitemmodel.cpp b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp index cf5fc5e..e8ee196 100644 --- a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp @@ -692,11 +692,16 @@ QmlComponent *QmlGraphicsVisualDataModel::delegate() const void QmlGraphicsVisualDataModel::setDelegate(QmlComponent *delegate) { Q_D(QmlGraphicsVisualDataModel); + bool wasValid = d->m_delegate != 0; d->m_delegate = delegate; - if (d->modelCount()) { + if (!wasValid && d->modelCount() && d->m_delegate) { emit itemsInserted(0, d->modelCount()); emit countChanged(); } + if (wasValid && !d->m_delegate && d->modelCount()) { + emit itemsRemoved(0, d->modelCount()); + emit countChanged(); + } } QString QmlGraphicsVisualDataModel::part() 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/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/qmlgraphicslistview/tst_qmlgraphicslistview.cpp b/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp index 36f4dc5..e9f785b 100644 --- a/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp +++ b/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp @@ -318,13 +318,22 @@ void tst_QmlGraphicsListView::items() testObject->setAnimate(true); QMetaObject::invokeMethod(canvas->root(), "checkProperties"); QVERIFY(testObject->error() == false); + QVERIFY(listview->currentItem()); // set invalid highlight testObject->setInvalidHighlight(true); QMetaObject::invokeMethod(canvas->root(), "checkProperties"); QVERIFY(testObject->error() == false); + QVERIFY(listview->currentItem()); QVERIFY(listview->highlightItem() == 0); + // back to normal highlight + testObject->setInvalidHighlight(false); + QMetaObject::invokeMethod(canvas->root(), "checkProperties"); + QVERIFY(testObject->error() == false); + QVERIFY(listview->currentItem()); + QVERIFY(listview->highlightItem() != 0); + // set an empty model and confirm that items are destroyed T model2; ctxt->setContextProperty("testModel", &model2); 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/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 |