2011-04-27 12:13:26 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
|
|
|
** Copyright (C) 2011 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$
|
|
|
|
** GNU Lesser General Public License Usage
|
2011-07-07 12:52:03 +00:00
|
|
|
** 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.
|
2011-04-27 12:13:26 +00:00
|
|
|
**
|
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-07-07 12:52:03 +00:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2011-04-27 12:13:26 +00:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
2011-07-07 12:52:03 +00:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU General
|
|
|
|
** Public License version 3.0 as published by the Free Software Foundation
|
|
|
|
** and appearing in the file LICENSE.GPL included in the packaging of this
|
|
|
|
** file. Please review the following information to ensure the GNU General
|
|
|
|
** Public License version 3.0 requirements will be met:
|
|
|
|
** http://www.gnu.org/copyleft/gpl.html.
|
|
|
|
**
|
|
|
|
** Other Usage
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
2011-04-27 12:13:26 +00:00
|
|
|
**
|
|
|
|
**
|
|
|
|
**
|
|
|
|
**
|
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <QtTest/QtTest>
|
2011-10-14 08:51:42 +00:00
|
|
|
#include <QtDeclarative/qquickview.h>
|
2011-04-27 12:13:26 +00:00
|
|
|
#include <QtDeclarative/qdeclarativeengine.h>
|
|
|
|
#include <QtDeclarative/qdeclarativecomponent.h>
|
|
|
|
#include <QtDeclarative/qdeclarativecontext.h>
|
|
|
|
#include <QtDeclarative/qdeclarativeexpression.h>
|
2011-10-14 08:51:42 +00:00
|
|
|
#include <QtDeclarative/private/qquickpathview_p.h>
|
2011-04-27 12:13:26 +00:00
|
|
|
#include <QtDeclarative/private/qdeclarativepath_p.h>
|
2011-10-14 08:51:42 +00:00
|
|
|
#include <QtDeclarative/private/qquicktext_p.h>
|
|
|
|
#include <QtDeclarative/private/qquickrectangle_p.h>
|
2011-04-27 12:13:26 +00:00
|
|
|
#include <QtDeclarative/private/qdeclarativelistmodel_p.h>
|
|
|
|
#include <QtDeclarative/private/qdeclarativevaluetype_p.h>
|
|
|
|
#include <QAbstractListModel>
|
|
|
|
#include <QStringListModel>
|
|
|
|
#include <QStandardItemModel>
|
|
|
|
#include <QFile>
|
|
|
|
|
2011-10-12 03:46:02 +00:00
|
|
|
#include "../shared/util.h"
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
static void initStandardTreeModel(QStandardItemModel *model)
|
|
|
|
{
|
|
|
|
QStandardItem *item;
|
|
|
|
item = new QStandardItem(QLatin1String("Row 1 Item"));
|
|
|
|
model->insertRow(0, item);
|
|
|
|
|
|
|
|
item = new QStandardItem(QLatin1String("Row 2 Item"));
|
|
|
|
item->setCheckable(true);
|
|
|
|
model->insertRow(1, item);
|
|
|
|
|
|
|
|
QStandardItem *childItem = new QStandardItem(QLatin1String("Row 2 Child Item"));
|
|
|
|
item->setChild(0, childItem);
|
|
|
|
|
|
|
|
item = new QStandardItem(QLatin1String("Row 3 Item"));
|
|
|
|
item->setIcon(QIcon());
|
|
|
|
model->insertRow(2, item);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
class tst_QQuickPathView : public QObject
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2011-10-14 08:51:42 +00:00
|
|
|
tst_QQuickPathView();
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
private slots:
|
2011-05-16 03:49:56 +00:00
|
|
|
void initTestCase();
|
|
|
|
void cleanupTestCase();
|
2011-04-27 12:13:26 +00:00
|
|
|
void initValues();
|
|
|
|
void items();
|
|
|
|
void dataModel();
|
|
|
|
void pathview2();
|
|
|
|
void pathview3();
|
|
|
|
void path();
|
|
|
|
void pathMoved();
|
|
|
|
void setCurrentIndex();
|
|
|
|
void resetModel();
|
|
|
|
void propertyChanges();
|
|
|
|
void pathChanges();
|
|
|
|
void componentChanges();
|
|
|
|
void modelChanges();
|
|
|
|
void pathUpdateOnStartChanged();
|
|
|
|
void package();
|
|
|
|
void emptyModel();
|
|
|
|
void closed();
|
|
|
|
void pathUpdate();
|
|
|
|
void visualDataModel();
|
|
|
|
void undefinedPath();
|
|
|
|
void mouseDrag();
|
|
|
|
void treeModel();
|
|
|
|
void changePreferredHighlight();
|
2011-07-29 00:41:47 +00:00
|
|
|
void missingPercent();
|
2011-10-07 03:06:26 +00:00
|
|
|
void creationContext();
|
2011-11-09 05:34:01 +00:00
|
|
|
void currentOffsetOnInsertion();
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
private:
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickView *createView();
|
2011-04-27 12:13:26 +00:00
|
|
|
template<typename T>
|
2011-10-14 08:51:42 +00:00
|
|
|
T *findItem(QQuickItem *parent, const QString &objectName, int index=-1);
|
2011-04-27 12:13:26 +00:00
|
|
|
template<typename T>
|
2011-10-14 08:51:42 +00:00
|
|
|
QList<T*> findItems(QQuickItem *parent, const QString &objectName);
|
2011-04-27 12:13:26 +00:00
|
|
|
};
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickPathView::initTestCase()
|
2011-05-16 03:49:56 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickPathView::cleanupTestCase()
|
2011-05-16 03:49:56 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-04-27 12:13:26 +00:00
|
|
|
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 { Q_UNUSED(parent); 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) {
|
|
|
|
beginInsertRows(QModelIndex(), list.count(), list.count());
|
|
|
|
list.append(QPair<QString,QString>(name, number));
|
|
|
|
endInsertRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
void insertItem(int index, const QString &name, const QString &number) {
|
|
|
|
beginInsertRows(QModelIndex(), index, index);
|
|
|
|
list.insert(index, QPair<QString,QString>(name, number));
|
|
|
|
endInsertRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
void removeItem(int index) {
|
|
|
|
beginRemoveRows(QModelIndex(), index, index);
|
|
|
|
list.removeAt(index);
|
|
|
|
endRemoveRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
void moveItem(int from, int to) {
|
|
|
|
beginMoveRows(QModelIndex(), from, from, QModelIndex(), to);
|
|
|
|
list.move(from, to);
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
tst_QQuickPathView::tst_QQuickPathView()
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickPathView::initValues()
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
|
|
|
QDeclarativeEngine engine;
|
2011-10-12 03:46:02 +00:00
|
|
|
QDeclarativeComponent c(&engine, QUrl::fromLocalFile(TESTDATA("pathview1.qml")));
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickPathView *obj = qobject_cast<QQuickPathView*>(c.create());
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
QVERIFY(obj != 0);
|
|
|
|
QVERIFY(obj->path() == 0);
|
|
|
|
QVERIFY(obj->delegate() == 0);
|
|
|
|
QCOMPARE(obj->model(), QVariant());
|
|
|
|
QCOMPARE(obj->currentIndex(), 0);
|
|
|
|
QCOMPARE(obj->offset(), 0.);
|
|
|
|
QCOMPARE(obj->preferredHighlightBegin(), 0.);
|
|
|
|
QCOMPARE(obj->dragMargin(), 0.);
|
|
|
|
QCOMPARE(obj->count(), 0);
|
|
|
|
QCOMPARE(obj->pathItemCount(), -1);
|
2011-11-09 05:34:01 +00:00
|
|
|
|
|
|
|
delete obj;
|
2011-04-27 12:13:26 +00:00
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickPathView::items()
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickView *canvas = createView();
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
TestModel model;
|
|
|
|
model.addItem("Fred", "12345");
|
|
|
|
model.addItem("John", "2345");
|
|
|
|
model.addItem("Bob", "54321");
|
|
|
|
model.addItem("Bill", "4321");
|
|
|
|
|
|
|
|
QDeclarativeContext *ctxt = canvas->rootContext();
|
|
|
|
ctxt->setContextProperty("testModel", &model);
|
|
|
|
|
2011-10-12 03:46:02 +00:00
|
|
|
canvas->setSource(QUrl::fromLocalFile(TESTDATA("pathview0.qml")));
|
2011-04-27 12:13:26 +00:00
|
|
|
qApp->processEvents();
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickPathView *pathview = findItem<QQuickPathView>(canvas->rootObject(), "view");
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(pathview != 0);
|
|
|
|
|
2011-05-30 06:35:52 +00:00
|
|
|
QCOMPARE(pathview->count(), model.count());
|
|
|
|
QCOMPARE(canvas->rootObject()->property("count").toInt(), model.count());
|
2011-04-27 12:13:26 +00:00
|
|
|
QCOMPARE(pathview->childItems().count(), model.count()+1); // assumes all are visible, including highlight
|
|
|
|
|
|
|
|
for (int i = 0; i < model.count(); ++i) {
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickText *name = findItem<QQuickText>(pathview, "textName", i);
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(name != 0);
|
|
|
|
QCOMPARE(name->text(), model.name(i));
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickText *number = findItem<QQuickText>(pathview, "textNumber", i);
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(number != 0);
|
|
|
|
QCOMPARE(number->text(), model.number(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
QDeclarativePath *path = qobject_cast<QDeclarativePath*>(pathview->path());
|
|
|
|
QVERIFY(path);
|
|
|
|
|
|
|
|
QVERIFY(pathview->highlightItem());
|
|
|
|
QPointF start = path->pointAt(0.0);
|
|
|
|
QPointF offset;
|
|
|
|
offset.setX(pathview->highlightItem()->width()/2);
|
|
|
|
offset.setY(pathview->highlightItem()->height()/2);
|
|
|
|
QCOMPARE(pathview->highlightItem()->pos() + offset, start);
|
|
|
|
|
|
|
|
delete canvas;
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickPathView::pathview2()
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
|
|
|
QDeclarativeEngine engine;
|
2011-10-12 03:46:02 +00:00
|
|
|
QDeclarativeComponent c(&engine, QUrl::fromLocalFile(TESTDATA("pathview2.qml")));
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickPathView *obj = qobject_cast<QQuickPathView*>(c.create());
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
QVERIFY(obj != 0);
|
|
|
|
QVERIFY(obj->path() != 0);
|
|
|
|
QVERIFY(obj->delegate() != 0);
|
|
|
|
QVERIFY(obj->model() != QVariant());
|
|
|
|
QCOMPARE(obj->currentIndex(), 0);
|
|
|
|
QCOMPARE(obj->offset(), 0.);
|
|
|
|
QCOMPARE(obj->preferredHighlightBegin(), 0.);
|
|
|
|
QCOMPARE(obj->dragMargin(), 0.);
|
|
|
|
QCOMPARE(obj->count(), 8);
|
|
|
|
QCOMPARE(obj->pathItemCount(), 10);
|
2011-11-09 05:34:01 +00:00
|
|
|
|
|
|
|
delete obj;
|
2011-04-27 12:13:26 +00:00
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickPathView::pathview3()
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
|
|
|
QDeclarativeEngine engine;
|
2011-10-12 03:46:02 +00:00
|
|
|
QDeclarativeComponent c(&engine, QUrl::fromLocalFile(TESTDATA("pathview3.qml")));
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickPathView *obj = qobject_cast<QQuickPathView*>(c.create());
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
QVERIFY(obj != 0);
|
|
|
|
QVERIFY(obj->path() != 0);
|
|
|
|
QVERIFY(obj->delegate() != 0);
|
|
|
|
QVERIFY(obj->model() != QVariant());
|
|
|
|
QCOMPARE(obj->currentIndex(), 0);
|
|
|
|
QCOMPARE(obj->offset(), 1.0);
|
|
|
|
QCOMPARE(obj->preferredHighlightBegin(), 0.5);
|
|
|
|
QCOMPARE(obj->dragMargin(), 24.);
|
|
|
|
QCOMPARE(obj->count(), 8);
|
|
|
|
QCOMPARE(obj->pathItemCount(), 4);
|
2011-11-09 05:34:01 +00:00
|
|
|
|
|
|
|
delete obj;
|
2011-04-27 12:13:26 +00:00
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickPathView::path()
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
|
|
|
QDeclarativeEngine engine;
|
2011-10-12 03:46:02 +00:00
|
|
|
QDeclarativeComponent c(&engine, QUrl::fromLocalFile(TESTDATA("pathtest.qml")));
|
2011-04-27 12:13:26 +00:00
|
|
|
QDeclarativePath *obj = qobject_cast<QDeclarativePath*>(c.create());
|
|
|
|
|
|
|
|
QVERIFY(obj != 0);
|
|
|
|
QCOMPARE(obj->startX(), 120.);
|
|
|
|
QCOMPARE(obj->startY(), 100.);
|
|
|
|
QVERIFY(obj->path() != QPainterPath());
|
|
|
|
|
|
|
|
QDeclarativeListReference list(obj, "pathElements");
|
|
|
|
QCOMPARE(list.count(), 5);
|
|
|
|
|
|
|
|
QDeclarativePathAttribute* attr = qobject_cast<QDeclarativePathAttribute*>(list.at(0));
|
|
|
|
QVERIFY(attr != 0);
|
|
|
|
QCOMPARE(attr->name(), QString("scale"));
|
|
|
|
QCOMPARE(attr->value(), 1.0);
|
|
|
|
|
|
|
|
QDeclarativePathQuad* quad = qobject_cast<QDeclarativePathQuad*>(list.at(1));
|
|
|
|
QVERIFY(quad != 0);
|
|
|
|
QCOMPARE(quad->x(), 120.);
|
|
|
|
QCOMPARE(quad->y(), 25.);
|
|
|
|
QCOMPARE(quad->controlX(), 260.);
|
|
|
|
QCOMPARE(quad->controlY(), 75.);
|
|
|
|
|
|
|
|
QDeclarativePathPercent* perc = qobject_cast<QDeclarativePathPercent*>(list.at(2));
|
|
|
|
QVERIFY(perc != 0);
|
|
|
|
QCOMPARE(perc->value(), 0.3);
|
|
|
|
|
|
|
|
QDeclarativePathLine* line = qobject_cast<QDeclarativePathLine*>(list.at(3));
|
|
|
|
QVERIFY(line != 0);
|
|
|
|
QCOMPARE(line->x(), 120.);
|
|
|
|
QCOMPARE(line->y(), 100.);
|
|
|
|
|
|
|
|
QDeclarativePathCubic* cubic = qobject_cast<QDeclarativePathCubic*>(list.at(4));
|
|
|
|
QVERIFY(cubic != 0);
|
|
|
|
QCOMPARE(cubic->x(), 180.);
|
|
|
|
QCOMPARE(cubic->y(), 0.);
|
|
|
|
QCOMPARE(cubic->control1X(), -10.);
|
|
|
|
QCOMPARE(cubic->control1Y(), 90.);
|
|
|
|
QCOMPARE(cubic->control2X(), 210.);
|
|
|
|
QCOMPARE(cubic->control2Y(), 90.);
|
2011-11-09 05:34:01 +00:00
|
|
|
|
|
|
|
delete obj;
|
2011-04-27 12:13:26 +00:00
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickPathView::dataModel()
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickView *canvas = createView();
|
2011-04-27 12:13:26 +00:00
|
|
|
canvas->show();
|
|
|
|
|
|
|
|
QDeclarativeContext *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");
|
|
|
|
model.addItem("peachpuff", "10");
|
|
|
|
model.addItem("powderblue", "11");
|
|
|
|
model.addItem("gold", "12");
|
|
|
|
model.addItem("sandybrown", "13");
|
|
|
|
|
|
|
|
ctxt->setContextProperty("testData", &model);
|
|
|
|
|
2011-10-12 03:46:02 +00:00
|
|
|
canvas->setSource(QUrl::fromLocalFile(TESTDATA("datamodel.qml")));
|
2011-04-27 12:13:26 +00:00
|
|
|
qApp->processEvents();
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickPathView *pathview = qobject_cast<QQuickPathView*>(canvas->rootObject());
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(pathview != 0);
|
|
|
|
|
|
|
|
QMetaObject::invokeMethod(canvas->rootObject(), "checkProperties");
|
|
|
|
QVERIFY(testObject->error() == false);
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickItem *item = findItem<QQuickItem>(pathview, "wrapper", 0);
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(item);
|
|
|
|
QCOMPARE(item->x(), 110.0);
|
|
|
|
QCOMPARE(item->y(), 10.0);
|
|
|
|
|
|
|
|
model.insertItem(4, "orange", "10");
|
|
|
|
QTest::qWait(100);
|
|
|
|
|
2011-05-30 06:35:52 +00:00
|
|
|
QCOMPARE(canvas->rootObject()->property("viewCount").toInt(), model.count());
|
2011-10-14 08:51:42 +00:00
|
|
|
QTRY_COMPARE(findItems<QQuickItem>(pathview, "wrapper").count(), 14);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
QVERIFY(pathview->currentIndex() == 0);
|
2011-10-14 08:51:42 +00:00
|
|
|
QCOMPARE(pathview->currentItem(), findItem<QQuickItem>(pathview, "wrapper", 0));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickText *text = findItem<QQuickText>(pathview, "myText", 4);
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(text);
|
|
|
|
QCOMPARE(text->text(), model.name(4));
|
|
|
|
|
|
|
|
model.removeItem(2);
|
2011-05-30 06:35:52 +00:00
|
|
|
QCOMPARE(canvas->rootObject()->property("viewCount").toInt(), model.count());
|
2011-10-14 08:51:42 +00:00
|
|
|
text = findItem<QQuickText>(pathview, "myText", 2);
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(text);
|
|
|
|
QCOMPARE(text->text(), model.name(2));
|
2011-10-14 08:51:42 +00:00
|
|
|
QCOMPARE(pathview->currentItem(), findItem<QQuickItem>(pathview, "wrapper", 0));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
testObject->setPathItemCount(5);
|
|
|
|
QMetaObject::invokeMethod(canvas->rootObject(), "checkProperties");
|
|
|
|
QVERIFY(testObject->error() == false);
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QTRY_COMPARE(findItems<QQuickItem>(pathview, "wrapper").count(), 5);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickRectangle *testItem = findItem<QQuickRectangle>(pathview, "wrapper", 4);
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(testItem != 0);
|
2011-10-14 08:51:42 +00:00
|
|
|
testItem = findItem<QQuickRectangle>(pathview, "wrapper", 5);
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(testItem == 0);
|
|
|
|
|
|
|
|
pathview->setCurrentIndex(1);
|
2011-10-14 08:51:42 +00:00
|
|
|
QCOMPARE(pathview->currentItem(), findItem<QQuickItem>(pathview, "wrapper", 1));
|
2011-08-01 03:09:10 +00:00
|
|
|
QTest::qWait(100);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
model.insertItem(2, "pink", "2");
|
|
|
|
QTest::qWait(100);
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QTRY_COMPARE(findItems<QQuickItem>(pathview, "wrapper").count(), 5);
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(pathview->currentIndex() == 1);
|
2011-10-14 08:51:42 +00:00
|
|
|
QCOMPARE(pathview->currentItem(), findItem<QQuickItem>(pathview, "wrapper", 1));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
text = findItem<QQuickText>(pathview, "myText", 2);
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(text);
|
|
|
|
QCOMPARE(text->text(), model.name(2));
|
|
|
|
|
|
|
|
model.removeItem(3);
|
2011-10-14 08:51:42 +00:00
|
|
|
QTRY_COMPARE(findItems<QQuickItem>(pathview, "wrapper").count(), 5);
|
|
|
|
text = findItem<QQuickText>(pathview, "myText", 3);
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(text);
|
|
|
|
QCOMPARE(text->text(), model.name(3));
|
2011-10-14 08:51:42 +00:00
|
|
|
QCOMPARE(pathview->currentItem(), findItem<QQuickItem>(pathview, "wrapper", 1));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
model.moveItem(3, 5);
|
2011-10-14 08:51:42 +00:00
|
|
|
QTRY_COMPARE(findItems<QQuickItem>(pathview, "wrapper").count(), 5);
|
|
|
|
QList<QQuickItem*> items = findItems<QQuickItem>(pathview, "wrapper");
|
|
|
|
foreach (QQuickItem *item, items) {
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(item->property("onPath").toBool());
|
|
|
|
}
|
2011-10-14 08:51:42 +00:00
|
|
|
QCOMPARE(pathview->currentItem(), findItem<QQuickItem>(pathview, "wrapper", 1));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
// QTBUG-14199
|
|
|
|
pathview->setOffset(7);
|
|
|
|
pathview->setOffset(0);
|
2011-10-14 08:51:42 +00:00
|
|
|
QCOMPARE(findItems<QQuickItem>(pathview, "wrapper").count(), 5);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
pathview->setCurrentIndex(model.count()-1);
|
|
|
|
model.removeItem(model.count()-1);
|
|
|
|
QCOMPARE(pathview->currentIndex(), model.count()-1);
|
|
|
|
|
|
|
|
delete canvas;
|
|
|
|
delete testObject;
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickPathView::pathMoved()
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickView *canvas = createView();
|
2011-04-27 12:13:26 +00:00
|
|
|
canvas->show();
|
|
|
|
|
|
|
|
TestModel model;
|
|
|
|
model.addItem("Ben", "12345");
|
|
|
|
model.addItem("Bohn", "2345");
|
|
|
|
model.addItem("Bob", "54321");
|
|
|
|
model.addItem("Bill", "4321");
|
|
|
|
|
|
|
|
QDeclarativeContext *ctxt = canvas->rootContext();
|
|
|
|
ctxt->setContextProperty("testModel", &model);
|
|
|
|
|
2011-10-12 03:46:02 +00:00
|
|
|
canvas->setSource(QUrl::fromLocalFile(TESTDATA("pathview0.qml")));
|
2011-04-27 12:13:26 +00:00
|
|
|
qApp->processEvents();
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickPathView *pathview = findItem<QQuickPathView>(canvas->rootObject(), "view");
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(pathview != 0);
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickRectangle *firstItem = findItem<QQuickRectangle>(pathview, "wrapper", 0);
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(firstItem);
|
|
|
|
QDeclarativePath *path = qobject_cast<QDeclarativePath*>(pathview->path());
|
|
|
|
QVERIFY(path);
|
|
|
|
QPointF start = path->pointAt(0.0);
|
|
|
|
QPointF offset;//Center of item is at point, but pos is from corner
|
|
|
|
offset.setX(firstItem->width()/2);
|
|
|
|
offset.setY(firstItem->height()/2);
|
|
|
|
QCOMPARE(firstItem->pos() + offset, start);
|
|
|
|
pathview->setOffset(1.0);
|
|
|
|
|
2011-10-17 11:03:58 +00:00
|
|
|
for (int i=0; i<model.count(); i++) {
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickRectangle *curItem = findItem<QQuickRectangle>(pathview, "wrapper", i);
|
2011-04-27 12:13:26 +00:00
|
|
|
QPointF itemPos(path->pointAt(0.25 + i*0.25));
|
|
|
|
QCOMPARE(curItem->pos() + offset, QPointF(qRound(itemPos.x()), qRound(itemPos.y())));
|
|
|
|
}
|
|
|
|
|
|
|
|
pathview->setOffset(0.0);
|
|
|
|
QCOMPARE(firstItem->pos() + offset, start);
|
|
|
|
|
|
|
|
// Change delegate size
|
|
|
|
pathview->setOffset(0.1);
|
|
|
|
pathview->setOffset(0.0);
|
|
|
|
canvas->rootObject()->setProperty("delegateWidth", 30);
|
|
|
|
QCOMPARE(firstItem->width(), 30.0);
|
|
|
|
offset.setX(firstItem->width()/2);
|
|
|
|
QTRY_COMPARE(firstItem->pos() + offset, start);
|
|
|
|
|
|
|
|
// Change delegate scale
|
|
|
|
pathview->setOffset(0.1);
|
|
|
|
pathview->setOffset(0.0);
|
|
|
|
canvas->rootObject()->setProperty("delegateScale", 1.2);
|
|
|
|
QTRY_COMPARE(firstItem->pos() + offset, start);
|
|
|
|
|
|
|
|
delete canvas;
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickPathView::setCurrentIndex()
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickView *canvas = createView();
|
2011-04-27 12:13:26 +00:00
|
|
|
canvas->show();
|
|
|
|
|
|
|
|
TestModel model;
|
|
|
|
model.addItem("Ben", "12345");
|
|
|
|
model.addItem("Bohn", "2345");
|
|
|
|
model.addItem("Bob", "54321");
|
|
|
|
model.addItem("Bill", "4321");
|
|
|
|
|
|
|
|
QDeclarativeContext *ctxt = canvas->rootContext();
|
|
|
|
ctxt->setContextProperty("testModel", &model);
|
|
|
|
|
2011-10-12 03:46:02 +00:00
|
|
|
canvas->setSource(QUrl::fromLocalFile(TESTDATA("pathview0.qml")));
|
2011-04-27 12:13:26 +00:00
|
|
|
qApp->processEvents();
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickPathView *pathview = findItem<QQuickPathView>(canvas->rootObject(), "view");
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(pathview != 0);
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickRectangle *firstItem = findItem<QQuickRectangle>(pathview, "wrapper", 0);
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(firstItem);
|
|
|
|
QDeclarativePath *path = qobject_cast<QDeclarativePath*>(pathview->path());
|
|
|
|
QVERIFY(path);
|
|
|
|
QPointF start = path->pointAt(0.0);
|
|
|
|
QPointF offset;//Center of item is at point, but pos is from corner
|
|
|
|
offset.setX(firstItem->width()/2);
|
|
|
|
offset.setY(firstItem->height()/2);
|
|
|
|
QCOMPARE(firstItem->pos() + offset, start);
|
|
|
|
QCOMPARE(canvas->rootObject()->property("currentA").toInt(), 0);
|
|
|
|
QCOMPARE(canvas->rootObject()->property("currentB").toInt(), 0);
|
|
|
|
|
|
|
|
pathview->setCurrentIndex(2);
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
firstItem = findItem<QQuickRectangle>(pathview, "wrapper", 2);
|
2011-04-27 12:13:26 +00:00
|
|
|
QTRY_COMPARE(firstItem->pos() + offset, start);
|
|
|
|
QCOMPARE(canvas->rootObject()->property("currentA").toInt(), 2);
|
|
|
|
QCOMPARE(canvas->rootObject()->property("currentB").toInt(), 2);
|
2011-08-01 03:09:10 +00:00
|
|
|
QCOMPARE(pathview->currentItem(), firstItem);
|
|
|
|
QCOMPARE(firstItem->property("onPath"), QVariant(true));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
pathview->decrementCurrentIndex();
|
|
|
|
QTRY_COMPARE(pathview->currentIndex(), 1);
|
2011-10-14 08:51:42 +00:00
|
|
|
firstItem = findItem<QQuickRectangle>(pathview, "wrapper", 1);
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(firstItem);
|
|
|
|
QTRY_COMPARE(firstItem->pos() + offset, start);
|
2011-08-01 03:09:10 +00:00
|
|
|
QCOMPARE(pathview->currentItem(), firstItem);
|
|
|
|
QCOMPARE(firstItem->property("onPath"), QVariant(true));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
pathview->decrementCurrentIndex();
|
|
|
|
QTRY_COMPARE(pathview->currentIndex(), 0);
|
2011-10-14 08:51:42 +00:00
|
|
|
firstItem = findItem<QQuickRectangle>(pathview, "wrapper", 0);
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(firstItem);
|
|
|
|
QTRY_COMPARE(firstItem->pos() + offset, start);
|
2011-08-01 03:09:10 +00:00
|
|
|
QCOMPARE(pathview->currentItem(), firstItem);
|
|
|
|
QCOMPARE(firstItem->property("onPath"), QVariant(true));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
pathview->decrementCurrentIndex();
|
|
|
|
QTRY_COMPARE(pathview->currentIndex(), 3);
|
2011-10-14 08:51:42 +00:00
|
|
|
firstItem = findItem<QQuickRectangle>(pathview, "wrapper", 3);
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(firstItem);
|
|
|
|
QTRY_COMPARE(firstItem->pos() + offset, start);
|
2011-08-01 03:09:10 +00:00
|
|
|
QCOMPARE(pathview->currentItem(), firstItem);
|
|
|
|
QCOMPARE(firstItem->property("onPath"), QVariant(true));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
pathview->incrementCurrentIndex();
|
|
|
|
QTRY_COMPARE(pathview->currentIndex(), 0);
|
2011-10-14 08:51:42 +00:00
|
|
|
firstItem = findItem<QQuickRectangle>(pathview, "wrapper", 0);
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(firstItem);
|
|
|
|
QTRY_COMPARE(firstItem->pos() + offset, start);
|
2011-08-01 03:09:10 +00:00
|
|
|
QCOMPARE(pathview->currentItem(), firstItem);
|
|
|
|
QCOMPARE(firstItem->property("onPath"), QVariant(true));
|
|
|
|
|
|
|
|
// Check the current item is still created when outside the bounds of pathItemCount.
|
|
|
|
pathview->setPathItemCount(2);
|
2011-10-14 08:51:42 +00:00
|
|
|
pathview->setHighlightRangeMode(QQuickPathView::NoHighlightRange);
|
|
|
|
QVERIFY(findItem<QQuickRectangle>(pathview, "wrapper", 0));
|
|
|
|
QVERIFY(findItem<QQuickRectangle>(pathview, "wrapper", 1));
|
|
|
|
QVERIFY(!findItem<QQuickRectangle>(pathview, "wrapper", 2));
|
|
|
|
QVERIFY(!findItem<QQuickRectangle>(pathview, "wrapper", 3));
|
2011-08-01 03:09:10 +00:00
|
|
|
|
|
|
|
pathview->setCurrentIndex(2);
|
2011-10-14 08:51:42 +00:00
|
|
|
firstItem = findItem<QQuickRectangle>(pathview, "wrapper", 2);
|
2011-08-01 03:09:10 +00:00
|
|
|
QCOMPARE(pathview->currentItem(), firstItem);
|
|
|
|
QCOMPARE(firstItem->property("onPath"), QVariant(false));
|
|
|
|
|
|
|
|
pathview->decrementCurrentIndex();
|
|
|
|
QTRY_COMPARE(pathview->currentIndex(), 1);
|
2011-10-14 08:51:42 +00:00
|
|
|
firstItem = findItem<QQuickRectangle>(pathview, "wrapper", 1);
|
2011-08-01 03:09:10 +00:00
|
|
|
QVERIFY(firstItem);
|
|
|
|
QCOMPARE(pathview->currentItem(), firstItem);
|
|
|
|
QCOMPARE(firstItem->property("onPath"), QVariant(true));
|
|
|
|
|
|
|
|
pathview->decrementCurrentIndex();
|
|
|
|
QTRY_COMPARE(pathview->currentIndex(), 0);
|
2011-10-14 08:51:42 +00:00
|
|
|
firstItem = findItem<QQuickRectangle>(pathview, "wrapper", 0);
|
2011-08-01 03:09:10 +00:00
|
|
|
QVERIFY(firstItem);
|
|
|
|
QCOMPARE(pathview->currentItem(), firstItem);
|
|
|
|
QCOMPARE(firstItem->property("onPath"), QVariant(true));
|
|
|
|
|
|
|
|
pathview->decrementCurrentIndex();
|
|
|
|
QTRY_COMPARE(pathview->currentIndex(), 3);
|
2011-10-14 08:51:42 +00:00
|
|
|
firstItem = findItem<QQuickRectangle>(pathview, "wrapper", 3);
|
2011-08-01 03:09:10 +00:00
|
|
|
QVERIFY(firstItem);
|
|
|
|
QCOMPARE(pathview->currentItem(), firstItem);
|
|
|
|
QCOMPARE(firstItem->property("onPath"), QVariant(false));
|
|
|
|
|
|
|
|
pathview->incrementCurrentIndex();
|
|
|
|
QTRY_COMPARE(pathview->currentIndex(), 0);
|
2011-10-14 08:51:42 +00:00
|
|
|
firstItem = findItem<QQuickRectangle>(pathview, "wrapper", 0);
|
2011-08-01 03:09:10 +00:00
|
|
|
QVERIFY(firstItem);
|
|
|
|
QCOMPARE(pathview->currentItem(), firstItem);
|
|
|
|
QCOMPARE(firstItem->property("onPath"), QVariant(true));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
delete canvas;
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickPathView::resetModel()
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickView *canvas = createView();
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
QStringList strings;
|
|
|
|
strings << "one" << "two" << "three";
|
|
|
|
QStringListModel model(strings);
|
|
|
|
|
|
|
|
QDeclarativeContext *ctxt = canvas->rootContext();
|
|
|
|
ctxt->setContextProperty("testModel", &model);
|
|
|
|
|
2011-10-12 03:46:02 +00:00
|
|
|
canvas->setSource(QUrl::fromLocalFile(TESTDATA("displaypath.qml")));
|
2011-04-27 12:13:26 +00:00
|
|
|
qApp->processEvents();
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickPathView *pathview = findItem<QQuickPathView>(canvas->rootObject(), "view");
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(pathview != 0);
|
|
|
|
|
|
|
|
QCOMPARE(pathview->count(), model.rowCount());
|
|
|
|
|
|
|
|
for (int i = 0; i < model.rowCount(); ++i) {
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickText *display = findItem<QQuickText>(pathview, "displayText", i);
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(display != 0);
|
|
|
|
QCOMPARE(display->text(), strings.at(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
strings.clear();
|
|
|
|
strings << "four" << "five" << "six" << "seven";
|
|
|
|
model.setStringList(strings);
|
|
|
|
|
|
|
|
QCOMPARE(pathview->count(), model.rowCount());
|
|
|
|
|
|
|
|
for (int i = 0; i < model.rowCount(); ++i) {
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickText *display = findItem<QQuickText>(pathview, "displayText", i);
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(display != 0);
|
|
|
|
QCOMPARE(display->text(), strings.at(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
delete canvas;
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickPathView::propertyChanges()
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickView *canvas = createView();
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(canvas);
|
2011-10-12 03:46:02 +00:00
|
|
|
canvas->setSource(QUrl::fromLocalFile(TESTDATA("propertychanges.qml")));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickPathView *pathView = canvas->rootObject()->findChild<QQuickPathView*>("pathView");
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(pathView);
|
|
|
|
|
|
|
|
QSignalSpy snapPositionSpy(pathView, SIGNAL(preferredHighlightBeginChanged()));
|
|
|
|
QSignalSpy dragMarginSpy(pathView, SIGNAL(dragMarginChanged()));
|
|
|
|
|
|
|
|
QCOMPARE(pathView->preferredHighlightBegin(), 0.1);
|
|
|
|
QCOMPARE(pathView->dragMargin(), 5.0);
|
|
|
|
|
|
|
|
pathView->setPreferredHighlightBegin(0.4);
|
|
|
|
pathView->setPreferredHighlightEnd(0.4);
|
|
|
|
pathView->setDragMargin(20.0);
|
|
|
|
|
|
|
|
QCOMPARE(pathView->preferredHighlightBegin(), 0.4);
|
|
|
|
QCOMPARE(pathView->preferredHighlightEnd(), 0.4);
|
|
|
|
QCOMPARE(pathView->dragMargin(), 20.0);
|
|
|
|
|
|
|
|
QCOMPARE(snapPositionSpy.count(), 1);
|
|
|
|
QCOMPARE(dragMarginSpy.count(), 1);
|
|
|
|
|
|
|
|
pathView->setPreferredHighlightBegin(0.4);
|
|
|
|
pathView->setPreferredHighlightEnd(0.4);
|
|
|
|
pathView->setDragMargin(20.0);
|
|
|
|
|
|
|
|
QCOMPARE(snapPositionSpy.count(), 1);
|
|
|
|
QCOMPARE(dragMarginSpy.count(), 1);
|
|
|
|
delete canvas;
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickPathView::pathChanges()
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickView *canvas = createView();
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(canvas);
|
2011-10-12 03:46:02 +00:00
|
|
|
canvas->setSource(QUrl::fromLocalFile(TESTDATA("propertychanges.qml")));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickPathView *pathView = canvas->rootObject()->findChild<QQuickPathView*>("pathView");
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(pathView);
|
|
|
|
|
|
|
|
QDeclarativePath *path = canvas->rootObject()->findChild<QDeclarativePath*>("path");
|
|
|
|
QVERIFY(path);
|
|
|
|
|
|
|
|
QSignalSpy startXSpy(path, SIGNAL(startXChanged()));
|
|
|
|
QSignalSpy startYSpy(path, SIGNAL(startYChanged()));
|
|
|
|
|
|
|
|
QCOMPARE(path->startX(), 220.0);
|
|
|
|
QCOMPARE(path->startY(), 200.0);
|
|
|
|
|
|
|
|
path->setStartX(240.0);
|
|
|
|
path->setStartY(220.0);
|
|
|
|
|
|
|
|
QCOMPARE(path->startX(), 240.0);
|
|
|
|
QCOMPARE(path->startY(), 220.0);
|
|
|
|
|
|
|
|
QCOMPARE(startXSpy.count(),1);
|
|
|
|
QCOMPARE(startYSpy.count(),1);
|
|
|
|
|
|
|
|
path->setStartX(240);
|
|
|
|
path->setStartY(220);
|
|
|
|
|
|
|
|
QCOMPARE(startXSpy.count(),1);
|
|
|
|
QCOMPARE(startYSpy.count(),1);
|
|
|
|
|
|
|
|
QDeclarativePath *alternatePath = canvas->rootObject()->findChild<QDeclarativePath*>("alternatePath");
|
|
|
|
QVERIFY(alternatePath);
|
|
|
|
|
|
|
|
QSignalSpy pathSpy(pathView, SIGNAL(pathChanged()));
|
|
|
|
|
|
|
|
QCOMPARE(pathView->path(), path);
|
|
|
|
|
|
|
|
pathView->setPath(alternatePath);
|
|
|
|
QCOMPARE(pathView->path(), alternatePath);
|
|
|
|
QCOMPARE(pathSpy.count(),1);
|
|
|
|
|
|
|
|
pathView->setPath(alternatePath);
|
|
|
|
QCOMPARE(pathSpy.count(),1);
|
|
|
|
|
|
|
|
QDeclarativePathAttribute *pathAttribute = canvas->rootObject()->findChild<QDeclarativePathAttribute*>("pathAttribute");
|
|
|
|
QVERIFY(pathAttribute);
|
|
|
|
|
|
|
|
QSignalSpy nameSpy(pathAttribute, SIGNAL(nameChanged()));
|
|
|
|
QCOMPARE(pathAttribute->name(), QString("opacity"));
|
|
|
|
|
|
|
|
pathAttribute->setName("scale");
|
|
|
|
QCOMPARE(pathAttribute->name(), QString("scale"));
|
|
|
|
QCOMPARE(nameSpy.count(),1);
|
|
|
|
|
|
|
|
pathAttribute->setName("scale");
|
|
|
|
QCOMPARE(nameSpy.count(),1);
|
|
|
|
delete canvas;
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickPathView::componentChanges()
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickView *canvas = createView();
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(canvas);
|
2011-10-12 03:46:02 +00:00
|
|
|
canvas->setSource(QUrl::fromLocalFile(TESTDATA("propertychanges.qml")));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickPathView *pathView = canvas->rootObject()->findChild<QQuickPathView*>("pathView");
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(pathView);
|
|
|
|
|
|
|
|
QDeclarativeComponent delegateComponent(canvas->engine());
|
|
|
|
delegateComponent.setData("import QtQuick 2.0; Text { text: '<b>Name:</b> ' + name }", QUrl::fromLocalFile(""));
|
|
|
|
|
|
|
|
QSignalSpy delegateSpy(pathView, SIGNAL(delegateChanged()));
|
|
|
|
|
|
|
|
pathView->setDelegate(&delegateComponent);
|
|
|
|
QCOMPARE(pathView->delegate(), &delegateComponent);
|
|
|
|
QCOMPARE(delegateSpy.count(),1);
|
|
|
|
|
|
|
|
pathView->setDelegate(&delegateComponent);
|
|
|
|
QCOMPARE(delegateSpy.count(),1);
|
|
|
|
delete canvas;
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickPathView::modelChanges()
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickView *canvas = createView();
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(canvas);
|
2011-10-12 03:46:02 +00:00
|
|
|
canvas->setSource(QUrl::fromLocalFile(TESTDATA("propertychanges.qml")));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickPathView *pathView = canvas->rootObject()->findChild<QQuickPathView*>("pathView");
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(pathView);
|
|
|
|
|
|
|
|
QDeclarativeListModel *alternateModel = canvas->rootObject()->findChild<QDeclarativeListModel*>("alternateModel");
|
|
|
|
QVERIFY(alternateModel);
|
2011-08-02 05:19:06 +00:00
|
|
|
QVariant modelVariant = QVariant::fromValue<QObject *>(alternateModel);
|
2011-04-27 12:13:26 +00:00
|
|
|
QSignalSpy modelSpy(pathView, SIGNAL(modelChanged()));
|
|
|
|
|
|
|
|
pathView->setModel(modelVariant);
|
|
|
|
QCOMPARE(pathView->model(), modelVariant);
|
|
|
|
QCOMPARE(modelSpy.count(),1);
|
|
|
|
|
|
|
|
pathView->setModel(modelVariant);
|
|
|
|
QCOMPARE(modelSpy.count(),1);
|
|
|
|
|
|
|
|
pathView->setModel(QVariant());
|
|
|
|
QCOMPARE(modelSpy.count(),2);
|
|
|
|
|
|
|
|
delete canvas;
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickPathView::pathUpdateOnStartChanged()
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickView *canvas = createView();
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(canvas);
|
2011-10-12 03:46:02 +00:00
|
|
|
canvas->setSource(QUrl::fromLocalFile(TESTDATA("pathUpdateOnStartChanged.qml")));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickPathView *pathView = canvas->rootObject()->findChild<QQuickPathView*>("pathView");
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(pathView);
|
|
|
|
|
|
|
|
QDeclarativePath *path = canvas->rootObject()->findChild<QDeclarativePath*>("path");
|
|
|
|
QVERIFY(path);
|
|
|
|
QCOMPARE(path->startX(), 400.0);
|
|
|
|
QCOMPARE(path->startY(), 300.0);
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickItem *item = findItem<QQuickItem>(pathView, "wrapper", 0);
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(item);
|
|
|
|
QCOMPARE(item->x(), path->startX() - item->width() / 2.0);
|
|
|
|
QCOMPARE(item->y(), path->startY() - item->height() / 2.0);
|
|
|
|
|
|
|
|
delete canvas;
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickPathView::package()
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickView *canvas = createView();
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(canvas);
|
2011-10-12 03:46:02 +00:00
|
|
|
canvas->setSource(QUrl::fromLocalFile(TESTDATA("pathview_package.qml")));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickPathView *pathView = canvas->rootObject()->findChild<QQuickPathView*>("photoPathView");
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(pathView);
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickItem *item = findItem<QQuickItem>(pathView, "pathItem");
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(item);
|
|
|
|
QVERIFY(item->scale() != 1.0);
|
|
|
|
|
|
|
|
delete canvas;
|
|
|
|
}
|
|
|
|
|
|
|
|
//QTBUG-13017
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickPathView::emptyModel()
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickView *canvas = createView();
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
QStringListModel model;
|
|
|
|
|
|
|
|
QDeclarativeContext *ctxt = canvas->rootContext();
|
|
|
|
ctxt->setContextProperty("emptyModel", &model);
|
|
|
|
|
2011-10-12 03:46:02 +00:00
|
|
|
canvas->setSource(QUrl::fromLocalFile(TESTDATA("emptymodel.qml")));
|
2011-04-27 12:13:26 +00:00
|
|
|
qApp->processEvents();
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickPathView *pathview = qobject_cast<QQuickPathView*>(canvas->rootObject());
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(pathview != 0);
|
|
|
|
|
|
|
|
QCOMPARE(pathview->offset(), qreal(0.0));
|
|
|
|
|
|
|
|
delete canvas;
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickPathView::closed()
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
|
|
|
QDeclarativeEngine engine;
|
|
|
|
|
|
|
|
{
|
2011-10-12 03:46:02 +00:00
|
|
|
QDeclarativeComponent c(&engine, QUrl::fromLocalFile(TESTDATA("openPath.qml")));
|
2011-04-27 12:13:26 +00:00
|
|
|
QDeclarativePath *obj = qobject_cast<QDeclarativePath*>(c.create());
|
|
|
|
QVERIFY(obj);
|
|
|
|
QCOMPARE(obj->isClosed(), false);
|
|
|
|
delete obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2011-10-12 03:46:02 +00:00
|
|
|
QDeclarativeComponent c(&engine, QUrl::fromLocalFile(TESTDATA("closedPath.qml")));
|
2011-04-27 12:13:26 +00:00
|
|
|
QDeclarativePath *obj = qobject_cast<QDeclarativePath*>(c.create());
|
|
|
|
QVERIFY(obj);
|
|
|
|
QCOMPARE(obj->isClosed(), true);
|
|
|
|
delete obj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// QTBUG-14239
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickPathView::pathUpdate()
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickView *canvas = createView();
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(canvas);
|
2011-10-12 03:46:02 +00:00
|
|
|
canvas->setSource(QUrl::fromLocalFile(TESTDATA("pathUpdate.qml")));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickPathView *pathView = canvas->rootObject()->findChild<QQuickPathView*>("pathView");
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(pathView);
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickItem *item = findItem<QQuickItem>(pathView, "wrapper", 0);
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(item);
|
|
|
|
QCOMPARE(item->x(), 150.0);
|
|
|
|
|
|
|
|
delete canvas;
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickPathView::visualDataModel()
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
|
|
|
QDeclarativeEngine engine;
|
2011-10-12 03:46:02 +00:00
|
|
|
QDeclarativeComponent c(&engine, QUrl::fromLocalFile(TESTDATA("vdm.qml")));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickPathView *obj = qobject_cast<QQuickPathView*>(c.create());
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(obj != 0);
|
|
|
|
|
|
|
|
QCOMPARE(obj->count(), 3);
|
|
|
|
|
|
|
|
delete obj;
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickPathView::undefinedPath()
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
|
|
|
QDeclarativeEngine engine;
|
2011-10-12 03:46:02 +00:00
|
|
|
QDeclarativeComponent c(&engine, QUrl::fromLocalFile(TESTDATA("undefinedpath.qml")));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickPathView *obj = qobject_cast<QQuickPathView*>(c.create());
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(obj != 0);
|
|
|
|
|
|
|
|
QCOMPARE(obj->count(), 3);
|
|
|
|
|
|
|
|
delete obj;
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickPathView::mouseDrag()
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickView *canvas = createView();
|
2011-10-12 03:46:02 +00:00
|
|
|
canvas->setSource(QUrl::fromLocalFile(TESTDATA("dragpath.qml")));
|
2011-04-27 12:13:26 +00:00
|
|
|
canvas->show();
|
2011-09-09 12:50:48 +00:00
|
|
|
canvas->requestActivateWindow();
|
2011-04-27 12:13:26 +00:00
|
|
|
QTest::qWaitForWindowShown(canvas);
|
2011-10-06 00:10:24 +00:00
|
|
|
QTRY_COMPARE(canvas, qGuiApp->focusWindow());
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickPathView *pathview = qobject_cast<QQuickPathView*>(canvas->rootObject());
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(pathview != 0);
|
|
|
|
|
|
|
|
int current = pathview->currentIndex();
|
|
|
|
|
|
|
|
QTest::mousePress(canvas, Qt::LeftButton, 0, QPoint(10,100));
|
2011-10-06 00:10:24 +00:00
|
|
|
QTest::qWait(100);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
QMouseEvent mv(QEvent::MouseMove, QPoint(30,100), Qt::LeftButton, Qt::LeftButton,Qt::NoModifier);
|
|
|
|
QApplication::sendEvent(canvas, &mv);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
QMouseEvent mv(QEvent::MouseMove, QPoint(90,100), Qt::LeftButton, Qt::LeftButton,Qt::NoModifier);
|
|
|
|
QApplication::sendEvent(canvas, &mv);
|
|
|
|
}
|
|
|
|
|
|
|
|
QVERIFY(pathview->currentIndex() != current);
|
|
|
|
|
|
|
|
QTest::mouseRelease(canvas, Qt::LeftButton, 0, QPoint(40,100));
|
|
|
|
|
|
|
|
delete canvas;
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickPathView::treeModel()
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickView *canvas = createView();
|
2011-04-27 12:13:26 +00:00
|
|
|
canvas->show();
|
|
|
|
|
|
|
|
QStandardItemModel model;
|
|
|
|
initStandardTreeModel(&model);
|
|
|
|
canvas->engine()->rootContext()->setContextProperty("myModel", &model);
|
|
|
|
|
2011-10-12 03:46:02 +00:00
|
|
|
canvas->setSource(QUrl::fromLocalFile(TESTDATA("treemodel.qml")));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickPathView *pathview = qobject_cast<QQuickPathView*>(canvas->rootObject());
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(pathview != 0);
|
|
|
|
QCOMPARE(pathview->count(), 3);
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickText *item = findItem<QQuickText>(pathview, "wrapper", 0);
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(item);
|
|
|
|
QCOMPARE(item->text(), QLatin1String("Row 1 Item"));
|
|
|
|
|
|
|
|
QVERIFY(QMetaObject::invokeMethod(pathview, "setRoot", Q_ARG(QVariant, 1)));
|
|
|
|
QCOMPARE(pathview->count(), 1);
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QTRY_VERIFY(item = findItem<QQuickText>(pathview, "wrapper", 0));
|
2011-04-27 12:13:26 +00:00
|
|
|
QTRY_COMPARE(item->text(), QLatin1String("Row 2 Child Item"));
|
|
|
|
|
|
|
|
delete canvas;
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickPathView::changePreferredHighlight()
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickView *canvas = createView();
|
2011-09-09 12:50:48 +00:00
|
|
|
canvas->setGeometry(0,0,400,200);
|
2011-10-12 03:46:02 +00:00
|
|
|
canvas->setSource(QUrl::fromLocalFile(TESTDATA("dragpath.qml")));
|
2011-04-27 12:13:26 +00:00
|
|
|
canvas->show();
|
2011-09-09 12:50:48 +00:00
|
|
|
canvas->requestActivateWindow();
|
2011-04-27 12:13:26 +00:00
|
|
|
QTest::qWaitForWindowShown(canvas);
|
2011-10-06 00:10:24 +00:00
|
|
|
QTRY_COMPARE(canvas, qGuiApp->focusWindow());
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickPathView *pathview = qobject_cast<QQuickPathView*>(canvas->rootObject());
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(pathview != 0);
|
|
|
|
|
|
|
|
int current = pathview->currentIndex();
|
|
|
|
QCOMPARE(current, 0);
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickRectangle *firstItem = findItem<QQuickRectangle>(pathview, "wrapper", 0);
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(firstItem);
|
|
|
|
QDeclarativePath *path = qobject_cast<QDeclarativePath*>(pathview->path());
|
|
|
|
QVERIFY(path);
|
|
|
|
QPointF start = path->pointAt(0.5);
|
|
|
|
start.setX(qRound(start.x()));
|
|
|
|
start.setY(qRound(start.y()));
|
|
|
|
QPointF offset;//Center of item is at point, but pos is from corner
|
|
|
|
offset.setX(firstItem->width()/2);
|
|
|
|
offset.setY(firstItem->height()/2);
|
|
|
|
QTRY_COMPARE(firstItem->pos() + offset, start);
|
|
|
|
|
|
|
|
pathview->setPreferredHighlightBegin(0.8);
|
|
|
|
pathview->setPreferredHighlightEnd(0.8);
|
|
|
|
start = path->pointAt(0.8);
|
|
|
|
start.setX(qRound(start.x()));
|
|
|
|
start.setY(qRound(start.y()));
|
|
|
|
QTRY_COMPARE(firstItem->pos() + offset, start);
|
|
|
|
QCOMPARE(pathview->currentIndex(), 0);
|
|
|
|
|
|
|
|
delete canvas;
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickPathView::creationContext()
|
2011-10-07 03:06:26 +00:00
|
|
|
{
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickView canvas;
|
2011-10-07 03:06:26 +00:00
|
|
|
canvas.setGeometry(0,0,240,320);
|
2011-10-12 03:46:02 +00:00
|
|
|
canvas.setSource(QUrl::fromLocalFile(TESTDATA("creationContext.qml")));
|
2011-10-07 03:06:26 +00:00
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickItem *rootItem = qobject_cast<QQuickItem *>(canvas.rootObject());
|
2011-10-07 03:06:26 +00:00
|
|
|
QVERIFY(rootItem);
|
|
|
|
QVERIFY(rootItem->property("count").toInt() > 0);
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickItem *item;
|
|
|
|
QVERIFY(item = findItem<QQuickItem>(rootItem, "listItem", 0));
|
2011-10-07 03:06:26 +00:00
|
|
|
QCOMPARE(item->property("text").toString(), QString("Hello!"));
|
|
|
|
}
|
|
|
|
|
2011-11-09 05:34:01 +00:00
|
|
|
// QTBUG-21320
|
|
|
|
void tst_QQuickPathView::currentOffsetOnInsertion()
|
|
|
|
{
|
|
|
|
QQuickView *canvas = createView();
|
|
|
|
canvas->show();
|
|
|
|
|
|
|
|
TestModel model;
|
|
|
|
|
|
|
|
QDeclarativeContext *ctxt = canvas->rootContext();
|
|
|
|
ctxt->setContextProperty("testModel", &model);
|
|
|
|
|
|
|
|
canvas->setSource(QUrl::fromLocalFile(TESTDATA("pathline.qml")));
|
|
|
|
qApp->processEvents();
|
|
|
|
|
|
|
|
QQuickPathView *pathview = findItem<QQuickPathView>(canvas->rootObject(), "view");
|
|
|
|
QVERIFY(pathview != 0);
|
|
|
|
|
|
|
|
pathview->setPreferredHighlightBegin(0.5);
|
|
|
|
pathview->setPreferredHighlightEnd(0.5);
|
|
|
|
|
|
|
|
QCOMPARE(pathview->count(), model.count());
|
|
|
|
|
|
|
|
model.addItem("item0", "0");
|
|
|
|
|
|
|
|
QCOMPARE(pathview->count(), model.count());
|
|
|
|
|
|
|
|
QQuickRectangle *item = 0;
|
|
|
|
QTRY_VERIFY(item = findItem<QQuickRectangle>(pathview, "wrapper", 0));
|
|
|
|
|
|
|
|
QDeclarativePath *path = qobject_cast<QDeclarativePath*>(pathview->path());
|
|
|
|
QVERIFY(path);
|
|
|
|
|
|
|
|
QPointF start = path->pointAt(0.5);
|
|
|
|
start = QPointF(qRound(start.x()), qRound(start.y()));
|
|
|
|
QPointF offset;//Center of item is at point, but pos is from corner
|
|
|
|
offset.setX(item->width()/2);
|
|
|
|
offset.setY(item->height()/2);
|
|
|
|
QCOMPARE(item->pos() + offset, start);
|
|
|
|
|
|
|
|
QSignalSpy currentIndexSpy(pathview, SIGNAL(currentIndexChanged()));
|
|
|
|
|
|
|
|
// insert an item at the beginning
|
|
|
|
model.insertItem(0, "item1", "1");
|
|
|
|
qApp->processEvents();
|
|
|
|
|
|
|
|
QCOMPARE(currentIndexSpy.count(), 1);
|
|
|
|
|
|
|
|
// currentIndex is now 1
|
|
|
|
QVERIFY(item = findItem<QQuickRectangle>(pathview, "wrapper", 1));
|
|
|
|
|
|
|
|
// verify that current item (item 1) is still at offset 0.5
|
|
|
|
QCOMPARE(item->pos() + offset, start);
|
|
|
|
|
|
|
|
// insert another item at the beginning
|
|
|
|
model.insertItem(0, "item2", "2");
|
|
|
|
qApp->processEvents();
|
|
|
|
|
|
|
|
QCOMPARE(currentIndexSpy.count(), 2);
|
|
|
|
|
|
|
|
// currentIndex is now 2
|
|
|
|
QVERIFY(item = findItem<QQuickRectangle>(pathview, "wrapper", 2));
|
|
|
|
|
|
|
|
// verify that current item (item 2) is still at offset 0.5
|
|
|
|
QCOMPARE(item->pos() + offset, start);
|
|
|
|
|
|
|
|
// verify that remove before current maintains current item
|
|
|
|
model.removeItem(0);
|
|
|
|
qApp->processEvents();
|
|
|
|
|
|
|
|
QCOMPARE(currentIndexSpy.count(), 3);
|
|
|
|
|
|
|
|
// currentIndex is now 1
|
|
|
|
QVERIFY(item = findItem<QQuickRectangle>(pathview, "wrapper", 1));
|
|
|
|
|
|
|
|
// verify that current item (item 1) is still at offset 0.5
|
|
|
|
QCOMPARE(item->pos() + offset, start);
|
|
|
|
|
|
|
|
delete canvas;
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickView *tst_QQuickPathView::createView()
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickView *canvas = new QQuickView(0);
|
2011-09-09 12:50:48 +00:00
|
|
|
canvas->setGeometry(0,0,240,320);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
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>
|
2011-10-14 08:51:42 +00:00
|
|
|
T *tst_QQuickPathView::findItem(QQuickItem *parent, const QString &objectName, int index)
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
|
|
|
const QMetaObject &mo = T::staticMetaObject;
|
|
|
|
//qDebug() << parent->childItems().count() << "children";
|
|
|
|
for (int i = 0; i < parent->childItems().count(); ++i) {
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickItem *item = qobject_cast<QQuickItem*>(parent->childItems().at(i));
|
2011-10-17 11:03:58 +00:00
|
|
|
if (!item)
|
2011-04-27 12:13:26 +00:00
|
|
|
continue;
|
|
|
|
//qDebug() << "try" << item;
|
|
|
|
if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) {
|
|
|
|
if (index != -1) {
|
|
|
|
QDeclarativeExpression e(qmlContext(item), item, "index");
|
|
|
|
if (e.evaluate().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>
|
2011-10-14 08:51:42 +00:00
|
|
|
QList<T*> tst_QQuickPathView::findItems(QQuickItem *parent, const QString &objectName)
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
|
|
|
QList<T*> items;
|
|
|
|
const QMetaObject &mo = T::staticMetaObject;
|
2011-10-14 08:51:42 +00:00
|
|
|
//qDebug() << parent->QQuickItem::children().count() << "children";
|
2011-04-27 12:13:26 +00:00
|
|
|
for (int i = 0; i < parent->childItems().count(); ++i) {
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickItem *item = qobject_cast<QQuickItem*>(parent->childItems().at(i));
|
2011-10-17 11:03:58 +00:00
|
|
|
if (!item)
|
2011-04-27 12:13:26 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickPathView::missingPercent()
|
2011-07-29 00:41:47 +00:00
|
|
|
{
|
|
|
|
QDeclarativeEngine engine;
|
2011-10-12 03:46:02 +00:00
|
|
|
QDeclarativeComponent c(&engine, QUrl::fromLocalFile(TESTDATA("missingPercent.qml")));
|
2011-07-29 00:41:47 +00:00
|
|
|
QDeclarativePath *obj = qobject_cast<QDeclarativePath*>(c.create());
|
|
|
|
QVERIFY(obj);
|
|
|
|
QCOMPARE(obj->attributeAt("_qfx_percent", 1.0), qreal(1.0));
|
|
|
|
delete obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QTEST_MAIN(tst_QQuickPathView)
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
#include "tst_qquickpathview.moc"
|