2011-04-27 12:13:26 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2012-01-05 04:29:18 +00:00
|
|
|
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
2012-01-20 04:04:27 +00:00
|
|
|
** Contact: http://www.qt-project.org/
|
2011-04-27 12:13:26 +00:00
|
|
|
**
|
|
|
|
** 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
|
|
|
**
|
|
|
|
**
|
|
|
|
**
|
|
|
|
**
|
|
|
|
**
|
2012-01-24 03:37:23 +00:00
|
|
|
**
|
2011-04-27 12:13:26 +00:00
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <QtTest/QtTest>
|
Say hello to QtQuick module
This change moves the QtQuick 2 types and C++ API (including
SceneGraph) to a new module (AKA library), QtQuick.
99% of this change is moving files from src/declarative to
src/quick, and from tests/auto/declarative to
tests/auto/qtquick2.
The loading of QtQuick 2 ("import QtQuick 2.0") is now delegated to
a plugin, src/imports/qtquick2, just like it's done for QtQuick 1.
All tools, examples, and tests that use QtQuick C++ API have gotten
"QT += quick" or "QT += quick-private" added to their .pro file.
A few additional internal QtDeclarative classes had to be exported
(via Q_DECLARATIVE_PRIVATE_EXPORT) since they're needed by the
QtQuick 2 implementation.
The old header locations (e.g. QtDeclarative/qquickitem.h) will
still be supported for some time, but will produce compile-time
warnings. (To avoid the QtQuick implementation using the
compatibility headers (since QtDeclarative's includepath comes
first), a few include statements were modified, e.g. from
"#include <qsgnode.h>" to "#include <QtQuick/qsgnode.h>".)
There's a change in qtbase that automatically adds QtQuick to the
module list if QtDeclarative is used. Together with the compatibility
headers, this should help reduce the migration pain for existing
projects.
In theory, simply getting an existing QtDeclarative-based project
to compile and link shouldn't require any changes for now -- but
porting to the new scheme is of course recommended, and will
eventually become mandatory.
Task-number: QTBUG-22889
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Change-Id: Ia52be9373172ba2f37e7623231ecb060316c96a7
Reviewed-by: Kent Hansen <kent.hansen@nokia.com>
Reviewed-by: Sergio Ahumada <sergio.ahumada@nokia.com>
2011-11-23 14:14:07 +00:00
|
|
|
#include <QtQuick/qquickview.h>
|
2012-02-16 04:43:03 +00:00
|
|
|
#include <QtQml/qqmlengine.h>
|
|
|
|
#include <QtQml/qqmlcomponent.h>
|
|
|
|
#include <QtQml/qqmlcontext.h>
|
|
|
|
#include <QtQml/qqmlexpression.h>
|
|
|
|
#include <QtQml/qqmlincubator.h>
|
Say hello to QtQuick module
This change moves the QtQuick 2 types and C++ API (including
SceneGraph) to a new module (AKA library), QtQuick.
99% of this change is moving files from src/declarative to
src/quick, and from tests/auto/declarative to
tests/auto/qtquick2.
The loading of QtQuick 2 ("import QtQuick 2.0") is now delegated to
a plugin, src/imports/qtquick2, just like it's done for QtQuick 1.
All tools, examples, and tests that use QtQuick C++ API have gotten
"QT += quick" or "QT += quick-private" added to their .pro file.
A few additional internal QtDeclarative classes had to be exported
(via Q_DECLARATIVE_PRIVATE_EXPORT) since they're needed by the
QtQuick 2 implementation.
The old header locations (e.g. QtDeclarative/qquickitem.h) will
still be supported for some time, but will produce compile-time
warnings. (To avoid the QtQuick implementation using the
compatibility headers (since QtDeclarative's includepath comes
first), a few include statements were modified, e.g. from
"#include <qsgnode.h>" to "#include <QtQuick/qsgnode.h>".)
There's a change in qtbase that automatically adds QtQuick to the
module list if QtDeclarative is used. Together with the compatibility
headers, this should help reduce the migration pain for existing
projects.
In theory, simply getting an existing QtDeclarative-based project
to compile and link shouldn't require any changes for now -- but
porting to the new scheme is of course recommended, and will
eventually become mandatory.
Task-number: QTBUG-22889
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Change-Id: Ia52be9373172ba2f37e7623231ecb060316c96a7
Reviewed-by: Kent Hansen <kent.hansen@nokia.com>
Reviewed-by: Sergio Ahumada <sergio.ahumada@nokia.com>
2011-11-23 14:14:07 +00:00
|
|
|
#include <QtQuick/private/qquickpathview_p.h>
|
2012-02-16 04:43:03 +00:00
|
|
|
#include <QtQuick/private/qquickpath_p.h>
|
Say hello to QtQuick module
This change moves the QtQuick 2 types and C++ API (including
SceneGraph) to a new module (AKA library), QtQuick.
99% of this change is moving files from src/declarative to
src/quick, and from tests/auto/declarative to
tests/auto/qtquick2.
The loading of QtQuick 2 ("import QtQuick 2.0") is now delegated to
a plugin, src/imports/qtquick2, just like it's done for QtQuick 1.
All tools, examples, and tests that use QtQuick C++ API have gotten
"QT += quick" or "QT += quick-private" added to their .pro file.
A few additional internal QtDeclarative classes had to be exported
(via Q_DECLARATIVE_PRIVATE_EXPORT) since they're needed by the
QtQuick 2 implementation.
The old header locations (e.g. QtDeclarative/qquickitem.h) will
still be supported for some time, but will produce compile-time
warnings. (To avoid the QtQuick implementation using the
compatibility headers (since QtDeclarative's includepath comes
first), a few include statements were modified, e.g. from
"#include <qsgnode.h>" to "#include <QtQuick/qsgnode.h>".)
There's a change in qtbase that automatically adds QtQuick to the
module list if QtDeclarative is used. Together with the compatibility
headers, this should help reduce the migration pain for existing
projects.
In theory, simply getting an existing QtDeclarative-based project
to compile and link shouldn't require any changes for now -- but
porting to the new scheme is of course recommended, and will
eventually become mandatory.
Task-number: QTBUG-22889
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Change-Id: Ia52be9373172ba2f37e7623231ecb060316c96a7
Reviewed-by: Kent Hansen <kent.hansen@nokia.com>
Reviewed-by: Sergio Ahumada <sergio.ahumada@nokia.com>
2011-11-23 14:14:07 +00:00
|
|
|
#include <QtQuick/private/qquicktext_p.h>
|
|
|
|
#include <QtQuick/private/qquickrectangle_p.h>
|
2012-02-16 04:43:03 +00:00
|
|
|
#include <QtQml/private/qquicklistmodel_p.h>
|
|
|
|
#include <QtQml/private/qqmlvaluetype_p.h>
|
2011-04-27 12:13:26 +00:00
|
|
|
#include <QStringListModel>
|
|
|
|
#include <QStandardItemModel>
|
|
|
|
#include <QFile>
|
|
|
|
|
Say hello to QtQuick module
This change moves the QtQuick 2 types and C++ API (including
SceneGraph) to a new module (AKA library), QtQuick.
99% of this change is moving files from src/declarative to
src/quick, and from tests/auto/declarative to
tests/auto/qtquick2.
The loading of QtQuick 2 ("import QtQuick 2.0") is now delegated to
a plugin, src/imports/qtquick2, just like it's done for QtQuick 1.
All tools, examples, and tests that use QtQuick C++ API have gotten
"QT += quick" or "QT += quick-private" added to their .pro file.
A few additional internal QtDeclarative classes had to be exported
(via Q_DECLARATIVE_PRIVATE_EXPORT) since they're needed by the
QtQuick 2 implementation.
The old header locations (e.g. QtDeclarative/qquickitem.h) will
still be supported for some time, but will produce compile-time
warnings. (To avoid the QtQuick implementation using the
compatibility headers (since QtDeclarative's includepath comes
first), a few include statements were modified, e.g. from
"#include <qsgnode.h>" to "#include <QtQuick/qsgnode.h>".)
There's a change in qtbase that automatically adds QtQuick to the
module list if QtDeclarative is used. Together with the compatibility
headers, this should help reduce the migration pain for existing
projects.
In theory, simply getting an existing QtDeclarative-based project
to compile and link shouldn't require any changes for now -- but
porting to the new scheme is of course recommended, and will
eventually become mandatory.
Task-number: QTBUG-22889
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Change-Id: Ia52be9373172ba2f37e7623231ecb060316c96a7
Reviewed-by: Kent Hansen <kent.hansen@nokia.com>
Reviewed-by: Sergio Ahumada <sergio.ahumada@nokia.com>
2011-11-23 14:14:07 +00:00
|
|
|
#include "../../shared/util.h"
|
2012-01-31 07:15:00 +00:00
|
|
|
#include "../shared/viewtestutil.h"
|
|
|
|
#include "../shared/visualtestutil.h"
|
|
|
|
|
|
|
|
using namespace QQuickViewTestUtil;
|
|
|
|
using namespace QQuickVisualTestUtil;
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
class tst_QQuickPathView : public QQmlDataTest
|
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:
|
|
|
|
void initValues();
|
|
|
|
void items();
|
|
|
|
void dataModel();
|
|
|
|
void pathview2();
|
|
|
|
void pathview3();
|
2011-11-22 07:26:49 +00:00
|
|
|
void insertModel_data();
|
|
|
|
void insertModel();
|
|
|
|
void removeModel_data();
|
|
|
|
void removeModel();
|
|
|
|
void moveModel_data();
|
|
|
|
void moveModel();
|
2011-04-27 12:13:26 +00:00
|
|
|
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-11-03 05:52:13 +00:00
|
|
|
void asynchronous();
|
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;
|
|
|
|
};
|
|
|
|
|
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
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlEngine engine;
|
|
|
|
QQmlComponent c(&engine, testFileUrl("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
|
|
|
|
2012-01-31 07:15:00 +00:00
|
|
|
QaimModel model;
|
2011-04-27 12:13:26 +00:00
|
|
|
model.addItem("Fred", "12345");
|
|
|
|
model.addItem("John", "2345");
|
|
|
|
model.addItem("Bob", "54321");
|
|
|
|
model.addItem("Bill", "4321");
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlContext *ctxt = canvas->rootContext();
|
2011-04-27 12:13:26 +00:00
|
|
|
ctxt->setContextProperty("testModel", &model);
|
|
|
|
|
2011-12-21 08:06:26 +00:00
|
|
|
canvas->setSource(testFileUrl("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));
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickPath *path = qobject_cast<QQuickPath*>(pathview->path());
|
2011-04-27 12:13:26 +00:00
|
|
|
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
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlEngine engine;
|
|
|
|
QQmlComponent c(&engine, testFileUrl("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
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlEngine engine;
|
|
|
|
QQmlComponent c(&engine, testFileUrl("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-11-22 07:26:49 +00:00
|
|
|
void tst_QQuickPathView::insertModel_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<int>("mode");
|
|
|
|
QTest::addColumn<int>("idx");
|
|
|
|
QTest::addColumn<int>("count");
|
|
|
|
QTest::addColumn<qreal>("offset");
|
|
|
|
|
|
|
|
// We have 8 items, with currentIndex == 4
|
|
|
|
QTest::newRow("insert after current")
|
|
|
|
<< int(QQuickPathView::StrictlyEnforceRange) << 6 << 1 << 5.;
|
|
|
|
QTest::newRow("insert before current")
|
|
|
|
<< int(QQuickPathView::StrictlyEnforceRange) << 2 << 1 << 4.;
|
|
|
|
QTest::newRow("insert multiple after current")
|
|
|
|
<< int(QQuickPathView::StrictlyEnforceRange) << 5 << 2 << 6.;
|
|
|
|
QTest::newRow("insert multiple before current")
|
|
|
|
<< int(QQuickPathView::StrictlyEnforceRange) << 1 << 2 << 4.;
|
|
|
|
QTest::newRow("insert at end")
|
|
|
|
<< int(QQuickPathView::StrictlyEnforceRange) << 8 << 1 << 5.;
|
|
|
|
QTest::newRow("insert at beginning")
|
|
|
|
<< int(QQuickPathView::StrictlyEnforceRange) << 0 << 1 << 4.;
|
|
|
|
QTest::newRow("insert at current")
|
|
|
|
<< int(QQuickPathView::StrictlyEnforceRange) << 4 << 1 << 4.;
|
|
|
|
|
|
|
|
QTest::newRow("no range - insert after current")
|
|
|
|
<< int(QQuickPathView::NoHighlightRange) << 6 << 1 << 5.;
|
|
|
|
QTest::newRow("no range - insert before current")
|
|
|
|
<< int(QQuickPathView::NoHighlightRange) << 2 << 1 << 4.;
|
|
|
|
QTest::newRow("no range - insert multiple after current")
|
|
|
|
<< int(QQuickPathView::NoHighlightRange) << 5 << 2 << 6.;
|
|
|
|
QTest::newRow("no range - insert multiple before current")
|
|
|
|
<< int(QQuickPathView::NoHighlightRange) << 1 << 2 << 4.;
|
|
|
|
QTest::newRow("no range - insert at end")
|
|
|
|
<< int(QQuickPathView::NoHighlightRange) << 8 << 1 << 5.;
|
|
|
|
QTest::newRow("no range - insert at beginning")
|
|
|
|
<< int(QQuickPathView::NoHighlightRange) << 0 << 1 << 4.;
|
|
|
|
QTest::newRow("no range - insert at current")
|
|
|
|
<< int(QQuickPathView::NoHighlightRange) << 4 << 1 << 4.;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QQuickPathView::insertModel()
|
|
|
|
{
|
|
|
|
QFETCH(int, mode);
|
|
|
|
QFETCH(int, idx);
|
|
|
|
QFETCH(int, count);
|
|
|
|
QFETCH(qreal, offset);
|
|
|
|
|
|
|
|
QQuickView *canvas = createView();
|
|
|
|
canvas->show();
|
|
|
|
|
2012-01-31 07:15:00 +00:00
|
|
|
QaimModel model;
|
2011-11-22 07:26:49 +00:00
|
|
|
model.addItem("Ben", "12345");
|
|
|
|
model.addItem("Bohn", "2345");
|
|
|
|
model.addItem("Bob", "54321");
|
|
|
|
model.addItem("Bill", "4321");
|
|
|
|
model.addItem("Jinny", "679");
|
|
|
|
model.addItem("Milly", "73378");
|
|
|
|
model.addItem("Jimmy", "3535");
|
|
|
|
model.addItem("Barb", "9039");
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlContext *ctxt = canvas->rootContext();
|
2011-11-22 07:26:49 +00:00
|
|
|
ctxt->setContextProperty("testModel", &model);
|
|
|
|
|
2011-12-21 08:06:26 +00:00
|
|
|
canvas->setSource(testFileUrl("pathview0.qml"));
|
2011-11-22 07:26:49 +00:00
|
|
|
qApp->processEvents();
|
|
|
|
|
|
|
|
QQuickPathView *pathview = findItem<QQuickPathView>(canvas->rootObject(), "view");
|
|
|
|
QVERIFY(pathview != 0);
|
|
|
|
|
|
|
|
pathview->setHighlightRangeMode((QQuickPathView::HighlightRangeMode)mode);
|
|
|
|
|
|
|
|
pathview->setCurrentIndex(4);
|
|
|
|
if (mode == QQuickPathView::StrictlyEnforceRange)
|
|
|
|
QTRY_COMPARE(pathview->offset(), 4.0);
|
|
|
|
else
|
|
|
|
pathview->setOffset(4);
|
|
|
|
|
|
|
|
QList<QPair<QString, QString> > items;
|
|
|
|
for (int i = 0; i < count; ++i)
|
|
|
|
items.append(qMakePair(QString("New"), QString::number(i)));
|
|
|
|
|
|
|
|
model.insertItems(idx, items);
|
|
|
|
QTRY_COMPARE(pathview->offset(), offset);
|
|
|
|
|
|
|
|
delete canvas;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QQuickPathView::removeModel_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<int>("mode");
|
|
|
|
QTest::addColumn<int>("idx");
|
|
|
|
QTest::addColumn<int>("count");
|
|
|
|
QTest::addColumn<qreal>("offset");
|
|
|
|
|
|
|
|
// We have 8 items, with currentIndex == 4
|
|
|
|
QTest::newRow("remove after current")
|
|
|
|
<< int(QQuickPathView::StrictlyEnforceRange) << 6 << 1 << 3.;
|
|
|
|
QTest::newRow("remove before current")
|
|
|
|
<< int(QQuickPathView::StrictlyEnforceRange) << 2 << 1 << 4.;
|
|
|
|
QTest::newRow("remove multiple after current")
|
|
|
|
<< int(QQuickPathView::StrictlyEnforceRange) << 5 << 2 << 2.;
|
|
|
|
QTest::newRow("remove multiple before current")
|
|
|
|
<< int(QQuickPathView::StrictlyEnforceRange) << 1 << 2 << 4.;
|
|
|
|
QTest::newRow("remove last")
|
|
|
|
<< int(QQuickPathView::StrictlyEnforceRange) << 7 << 1 << 3.;
|
|
|
|
QTest::newRow("remove first")
|
|
|
|
<< int(QQuickPathView::StrictlyEnforceRange) << 0 << 1 << 4.;
|
|
|
|
QTest::newRow("remove current")
|
|
|
|
<< int(QQuickPathView::StrictlyEnforceRange) << 4 << 1 << 3.;
|
|
|
|
|
|
|
|
QTest::newRow("no range - remove after current")
|
|
|
|
<< int(QQuickPathView::NoHighlightRange) << 6 << 1 << 3.;
|
|
|
|
QTest::newRow("no range - remove before current")
|
|
|
|
<< int(QQuickPathView::NoHighlightRange) << 2 << 1 << 4.;
|
|
|
|
QTest::newRow("no range - remove multiple after current")
|
|
|
|
<< int(QQuickPathView::NoHighlightRange) << 5 << 2 << 2.;
|
|
|
|
QTest::newRow("no range - remove multiple before current")
|
|
|
|
<< int(QQuickPathView::NoHighlightRange) << 1 << 2 << 4.;
|
|
|
|
QTest::newRow("no range - remove last")
|
|
|
|
<< int(QQuickPathView::NoHighlightRange) << 7 << 1 << 3.;
|
|
|
|
QTest::newRow("no range - remove first")
|
|
|
|
<< int(QQuickPathView::NoHighlightRange) << 0 << 1 << 4.;
|
|
|
|
QTest::newRow("no range - remove current offset")
|
|
|
|
<< int(QQuickPathView::NoHighlightRange) << 4 << 1 << 4.;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QQuickPathView::removeModel()
|
|
|
|
{
|
|
|
|
QFETCH(int, mode);
|
|
|
|
QFETCH(int, idx);
|
|
|
|
QFETCH(int, count);
|
|
|
|
QFETCH(qreal, offset);
|
|
|
|
|
|
|
|
QQuickView *canvas = createView();
|
|
|
|
canvas->show();
|
|
|
|
|
2012-01-31 07:15:00 +00:00
|
|
|
QaimModel model;
|
2011-11-22 07:26:49 +00:00
|
|
|
model.addItem("Ben", "12345");
|
|
|
|
model.addItem("Bohn", "2345");
|
|
|
|
model.addItem("Bob", "54321");
|
|
|
|
model.addItem("Bill", "4321");
|
|
|
|
model.addItem("Jinny", "679");
|
|
|
|
model.addItem("Milly", "73378");
|
|
|
|
model.addItem("Jimmy", "3535");
|
|
|
|
model.addItem("Barb", "9039");
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlContext *ctxt = canvas->rootContext();
|
2011-11-22 07:26:49 +00:00
|
|
|
ctxt->setContextProperty("testModel", &model);
|
|
|
|
|
2011-12-21 08:06:26 +00:00
|
|
|
canvas->setSource(testFileUrl("pathview0.qml"));
|
2011-11-22 07:26:49 +00:00
|
|
|
qApp->processEvents();
|
|
|
|
|
|
|
|
QQuickPathView *pathview = findItem<QQuickPathView>(canvas->rootObject(), "view");
|
|
|
|
QVERIFY(pathview != 0);
|
|
|
|
|
|
|
|
pathview->setHighlightRangeMode((QQuickPathView::HighlightRangeMode)mode);
|
|
|
|
|
|
|
|
pathview->setCurrentIndex(4);
|
|
|
|
if (mode == QQuickPathView::StrictlyEnforceRange)
|
|
|
|
QTRY_COMPARE(pathview->offset(), 4.0);
|
|
|
|
else
|
|
|
|
pathview->setOffset(4);
|
|
|
|
|
|
|
|
model.removeItems(idx, count);
|
|
|
|
QTRY_COMPARE(pathview->offset(), offset);
|
|
|
|
|
|
|
|
delete canvas;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void tst_QQuickPathView::moveModel_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<int>("mode");
|
|
|
|
QTest::addColumn<int>("from");
|
|
|
|
QTest::addColumn<int>("to");
|
|
|
|
QTest::addColumn<int>("count");
|
|
|
|
QTest::addColumn<qreal>("offset");
|
|
|
|
|
|
|
|
// We have 8 items, with currentIndex == 4
|
|
|
|
QTest::newRow("move after current")
|
|
|
|
<< int(QQuickPathView::StrictlyEnforceRange) << 5 << 6 << 1 << 4.;
|
|
|
|
QTest::newRow("move before current")
|
|
|
|
<< int(QQuickPathView::StrictlyEnforceRange) << 2 << 3 << 1 << 4.;
|
|
|
|
QTest::newRow("move before current to after")
|
|
|
|
<< int(QQuickPathView::StrictlyEnforceRange) << 2 << 6 << 1 << 5.;
|
|
|
|
QTest::newRow("move multiple after current")
|
|
|
|
<< int(QQuickPathView::StrictlyEnforceRange) << 5 << 6 << 2 << 4.;
|
|
|
|
QTest::newRow("move multiple before current")
|
|
|
|
<< int(QQuickPathView::StrictlyEnforceRange) << 0 << 1 << 2 << 4.;
|
|
|
|
QTest::newRow("move before current to end")
|
|
|
|
<< int(QQuickPathView::StrictlyEnforceRange) << 2 << 7 << 1 << 5.;
|
|
|
|
QTest::newRow("move last to beginning")
|
|
|
|
<< int(QQuickPathView::StrictlyEnforceRange) << 7 << 0 << 1 << 3.;
|
|
|
|
QTest::newRow("move current")
|
|
|
|
<< int(QQuickPathView::StrictlyEnforceRange) << 4 << 6 << 1 << 2.;
|
|
|
|
|
|
|
|
QTest::newRow("no range - move after current")
|
|
|
|
<< int(QQuickPathView::NoHighlightRange) << 5 << 6 << 1 << 4.;
|
|
|
|
QTest::newRow("no range - move before current")
|
|
|
|
<< int(QQuickPathView::NoHighlightRange) << 2 << 3 << 1 << 4.;
|
|
|
|
QTest::newRow("no range - move before current to after")
|
|
|
|
<< int(QQuickPathView::NoHighlightRange) << 2 << 6 << 1 << 5.;
|
|
|
|
QTest::newRow("no range - move multiple after current")
|
|
|
|
<< int(QQuickPathView::NoHighlightRange) << 5 << 6 << 2 << 4.;
|
|
|
|
QTest::newRow("no range - move multiple before current")
|
|
|
|
<< int(QQuickPathView::NoHighlightRange) << 0 << 1 << 2 << 4.;
|
|
|
|
QTest::newRow("no range - move before current to end")
|
|
|
|
<< int(QQuickPathView::NoHighlightRange) << 2 << 7 << 1 << 5.;
|
|
|
|
QTest::newRow("no range - move last to beginning")
|
|
|
|
<< int(QQuickPathView::NoHighlightRange) << 7 << 0 << 1 << 3.;
|
|
|
|
QTest::newRow("no range - move current")
|
|
|
|
<< int(QQuickPathView::NoHighlightRange) << 4 << 6 << 1 << 4.;
|
|
|
|
QTest::newRow("no range - move multiple incl. current")
|
|
|
|
<< int(QQuickPathView::NoHighlightRange) << 0 << 1 << 5 << 4.;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QQuickPathView::moveModel()
|
|
|
|
{
|
|
|
|
QFETCH(int, mode);
|
|
|
|
QFETCH(int, from);
|
|
|
|
QFETCH(int, to);
|
|
|
|
QFETCH(int, count);
|
|
|
|
QFETCH(qreal, offset);
|
|
|
|
|
|
|
|
QQuickView *canvas = createView();
|
|
|
|
canvas->show();
|
|
|
|
|
2012-01-31 07:15:00 +00:00
|
|
|
QaimModel model;
|
2011-11-22 07:26:49 +00:00
|
|
|
model.addItem("Ben", "12345");
|
|
|
|
model.addItem("Bohn", "2345");
|
|
|
|
model.addItem("Bob", "54321");
|
|
|
|
model.addItem("Bill", "4321");
|
|
|
|
model.addItem("Jinny", "679");
|
|
|
|
model.addItem("Milly", "73378");
|
|
|
|
model.addItem("Jimmy", "3535");
|
|
|
|
model.addItem("Barb", "9039");
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlContext *ctxt = canvas->rootContext();
|
2011-11-22 07:26:49 +00:00
|
|
|
ctxt->setContextProperty("testModel", &model);
|
|
|
|
|
2011-12-21 08:06:26 +00:00
|
|
|
canvas->setSource(testFileUrl("pathview0.qml"));
|
2011-11-22 07:26:49 +00:00
|
|
|
qApp->processEvents();
|
|
|
|
|
|
|
|
QQuickPathView *pathview = findItem<QQuickPathView>(canvas->rootObject(), "view");
|
|
|
|
QVERIFY(pathview != 0);
|
|
|
|
|
|
|
|
pathview->setHighlightRangeMode((QQuickPathView::HighlightRangeMode)mode);
|
|
|
|
|
|
|
|
pathview->setCurrentIndex(4);
|
|
|
|
if (mode == QQuickPathView::StrictlyEnforceRange)
|
|
|
|
QTRY_COMPARE(pathview->offset(), 4.0);
|
|
|
|
else
|
|
|
|
pathview->setOffset(4);
|
|
|
|
|
|
|
|
model.moveItems(from, to, count);
|
|
|
|
QTRY_COMPARE(pathview->offset(), offset);
|
|
|
|
|
|
|
|
delete canvas;
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickPathView::path()
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlEngine engine;
|
|
|
|
QQmlComponent c(&engine, testFileUrl("pathtest.qml"));
|
|
|
|
QQuickPath *obj = qobject_cast<QQuickPath*>(c.create());
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
QVERIFY(obj != 0);
|
|
|
|
QCOMPARE(obj->startX(), 120.);
|
|
|
|
QCOMPARE(obj->startY(), 100.);
|
|
|
|
QVERIFY(obj->path() != QPainterPath());
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlListReference list(obj, "pathElements");
|
2011-04-27 12:13:26 +00:00
|
|
|
QCOMPARE(list.count(), 5);
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickPathAttribute* attr = qobject_cast<QQuickPathAttribute*>(list.at(0));
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(attr != 0);
|
|
|
|
QCOMPARE(attr->name(), QString("scale"));
|
|
|
|
QCOMPARE(attr->value(), 1.0);
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickPathQuad* quad = qobject_cast<QQuickPathQuad*>(list.at(1));
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(quad != 0);
|
|
|
|
QCOMPARE(quad->x(), 120.);
|
|
|
|
QCOMPARE(quad->y(), 25.);
|
|
|
|
QCOMPARE(quad->controlX(), 260.);
|
|
|
|
QCOMPARE(quad->controlY(), 75.);
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickPathPercent* perc = qobject_cast<QQuickPathPercent*>(list.at(2));
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(perc != 0);
|
|
|
|
QCOMPARE(perc->value(), 0.3);
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickPathLine* line = qobject_cast<QQuickPathLine*>(list.at(3));
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(line != 0);
|
|
|
|
QCOMPARE(line->x(), 120.);
|
|
|
|
QCOMPARE(line->y(), 100.);
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickPathCubic* cubic = qobject_cast<QQuickPathCubic*>(list.at(4));
|
2011-04-27 12:13:26 +00:00
|
|
|
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();
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlContext *ctxt = canvas->rootContext();
|
2011-04-27 12:13:26 +00:00
|
|
|
TestObject *testObject = new TestObject;
|
|
|
|
ctxt->setContextProperty("testObject", testObject);
|
|
|
|
|
2012-01-31 07:15:00 +00:00
|
|
|
QaimModel model;
|
2011-04-27 12:13:26 +00:00
|
|
|
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-12-21 08:06:26 +00:00
|
|
|
canvas->setSource(testFileUrl("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();
|
|
|
|
|
2012-01-31 07:15:00 +00:00
|
|
|
QaimModel model;
|
2011-04-27 12:13:26 +00:00
|
|
|
model.addItem("Ben", "12345");
|
|
|
|
model.addItem("Bohn", "2345");
|
|
|
|
model.addItem("Bob", "54321");
|
|
|
|
model.addItem("Bill", "4321");
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlContext *ctxt = canvas->rootContext();
|
2011-04-27 12:13:26 +00:00
|
|
|
ctxt->setContextProperty("testModel", &model);
|
|
|
|
|
2011-12-21 08:06:26 +00:00
|
|
|
canvas->setSource(testFileUrl("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);
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickPath *path = qobject_cast<QQuickPath*>(pathview->path());
|
2011-04-27 12:13:26 +00:00
|
|
|
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);
|
2011-11-03 05:52:13 +00:00
|
|
|
QTRY_COMPARE(firstItem->pos() + offset, start);
|
2011-04-27 12:13:26 +00:00
|
|
|
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));
|
2012-02-16 05:54:09 +00:00
|
|
|
QCOMPARE(curItem->pos() + offset, QPointF(itemPos.x(), itemPos.y()));
|
2011-04-27 12:13:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
2012-01-31 07:15:00 +00:00
|
|
|
QaimModel model;
|
2011-04-27 12:13:26 +00:00
|
|
|
model.addItem("Ben", "12345");
|
|
|
|
model.addItem("Bohn", "2345");
|
|
|
|
model.addItem("Bob", "54321");
|
|
|
|
model.addItem("Bill", "4321");
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlContext *ctxt = canvas->rootContext();
|
2011-04-27 12:13:26 +00:00
|
|
|
ctxt->setContextProperty("testModel", &model);
|
|
|
|
|
2011-12-21 08:06:26 +00:00
|
|
|
canvas->setSource(testFileUrl("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);
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickPath *path = qobject_cast<QQuickPath*>(pathview->path());
|
2011-04-27 12:13:26 +00:00
|
|
|
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));
|
|
|
|
|
2011-11-21 23:28:40 +00:00
|
|
|
// move an item, set move duration to 0, and change currentIndex to moved item. QTBUG-22786
|
|
|
|
model.moveItem(0, 3);
|
|
|
|
pathview->setHighlightMoveDuration(0);
|
|
|
|
pathview->setCurrentIndex(3);
|
|
|
|
QCOMPARE(pathview->currentIndex(), 3);
|
|
|
|
firstItem = findItem<QQuickRectangle>(pathview, "wrapper", 3);
|
|
|
|
QVERIFY(firstItem);
|
|
|
|
QCOMPARE(pathview->currentItem(), firstItem);
|
|
|
|
QTRY_COMPARE(firstItem->pos() + offset, start);
|
|
|
|
model.moveItem(3, 0);
|
|
|
|
pathview->setCurrentIndex(0);
|
|
|
|
pathview->setHighlightMoveDuration(300);
|
|
|
|
|
2011-08-01 03:09:10 +00:00
|
|
|
// 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);
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlContext *ctxt = canvas->rootContext();
|
2011-04-27 12:13:26 +00:00
|
|
|
ctxt->setContextProperty("testModel", &model);
|
|
|
|
|
2011-12-21 08:06:26 +00:00
|
|
|
canvas->setSource(testFileUrl("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-12-21 08:06:26 +00:00
|
|
|
canvas->setSource(testFileUrl("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-12-21 08:06:26 +00:00
|
|
|
canvas->setSource(testFileUrl("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);
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickPath *path = canvas->rootObject()->findChild<QQuickPath*>("path");
|
2011-04-27 12:13:26 +00:00
|
|
|
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);
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickPath *alternatePath = canvas->rootObject()->findChild<QQuickPath*>("alternatePath");
|
2011-04-27 12:13:26 +00:00
|
|
|
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);
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickPathAttribute *pathAttribute = canvas->rootObject()->findChild<QQuickPathAttribute*>("pathAttribute");
|
2011-04-27 12:13:26 +00:00
|
|
|
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-12-21 08:06:26 +00:00
|
|
|
canvas->setSource(testFileUrl("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);
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlComponent delegateComponent(canvas->engine());
|
2011-04-27 12:13:26 +00:00
|
|
|
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-12-21 08:06:26 +00:00
|
|
|
canvas->setSource(testFileUrl("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);
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickListModel *alternateModel = canvas->rootObject()->findChild<QQuickListModel*>("alternateModel");
|
2011-04-27 12:13:26 +00:00
|
|
|
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-12-21 08:06:26 +00:00
|
|
|
canvas->setSource(testFileUrl("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);
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickPath *path = canvas->rootObject()->findChild<QQuickPath*>("path");
|
2011-04-27 12:13:26 +00:00
|
|
|
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-12-21 08:06:26 +00:00
|
|
|
canvas->setSource(testFileUrl("pathview_package.qml"));
|
2011-11-08 02:09:39 +00:00
|
|
|
canvas->show();
|
|
|
|
QTest::qWaitForWindowShown(canvas);
|
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);
|
|
|
|
|
2012-01-06 04:02:10 +00:00
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
QSKIP("QTBUG-21590 view does not reliably receive polish without a running animation");
|
|
|
|
#endif
|
|
|
|
|
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;
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlContext *ctxt = canvas->rootContext();
|
2011-04-27 12:13:26 +00:00
|
|
|
ctxt->setContextProperty("emptyModel", &model);
|
|
|
|
|
2011-12-21 08:06:26 +00:00
|
|
|
canvas->setSource(testFileUrl("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
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlEngine engine;
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlComponent c(&engine, testFileUrl("openPath.qml"));
|
|
|
|
QQuickPath *obj = qobject_cast<QQuickPath*>(c.create());
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(obj);
|
|
|
|
QCOMPARE(obj->isClosed(), false);
|
|
|
|
delete obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlComponent c(&engine, testFileUrl("closedPath.qml"));
|
|
|
|
QQuickPath *obj = qobject_cast<QQuickPath*>(c.create());
|
2011-04-27 12:13:26 +00:00
|
|
|
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-12-21 08:06:26 +00:00
|
|
|
canvas->setSource(testFileUrl("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
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlEngine engine;
|
|
|
|
QQmlComponent c(&engine, testFileUrl("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
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlEngine engine;
|
2011-12-06 02:29:09 +00:00
|
|
|
|
2012-01-09 02:55:52 +00:00
|
|
|
// QPainterPath warnings are only received if QT_NO_DEBUG is not defined
|
|
|
|
if (QLibraryInfo::isDebugBuild()) {
|
|
|
|
QString warning1("QPainterPath::moveTo: Adding point where x or y is NaN or Inf, ignoring call");
|
|
|
|
QTest::ignoreMessage(QtWarningMsg,qPrintable(warning1));
|
2011-12-06 02:29:09 +00:00
|
|
|
|
2012-01-09 02:55:52 +00:00
|
|
|
QString warning2("QPainterPath::lineTo: Adding point where x or y is NaN or Inf, ignoring call");
|
|
|
|
QTest::ignoreMessage(QtWarningMsg,qPrintable(warning2));
|
|
|
|
}
|
2011-12-06 02:29:09 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlComponent c(&engine, testFileUrl("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-12-21 08:06:26 +00:00
|
|
|
canvas->setSource(testFileUrl("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);
|
2012-01-13 02:08:20 +00:00
|
|
|
QGuiApplication::sendEvent(canvas, &mv);
|
2011-04-27 12:13:26 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
QMouseEvent mv(QEvent::MouseMove, QPoint(90,100), Qt::LeftButton, Qt::LeftButton,Qt::NoModifier);
|
2012-01-13 02:08:20 +00:00
|
|
|
QGuiApplication::sendEvent(canvas, &mv);
|
2011-04-27 12:13:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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-12-21 08:06:26 +00:00
|
|
|
canvas->setSource(testFileUrl("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-12-21 08:06:26 +00:00
|
|
|
canvas->setSource(testFileUrl("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);
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickPath *path = qobject_cast<QQuickPath*>(pathview->path());
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(path);
|
|
|
|
QPointF start = path->pointAt(0.5);
|
|
|
|
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);
|
|
|
|
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-12-21 08:06:26 +00:00
|
|
|
canvas.setSource(testFileUrl("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();
|
|
|
|
|
2012-01-31 07:15:00 +00:00
|
|
|
QaimModel model;
|
2011-11-09 05:34:01 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlContext *ctxt = canvas->rootContext();
|
2011-11-09 05:34:01 +00:00
|
|
|
ctxt->setContextProperty("testModel", &model);
|
|
|
|
|
2011-12-21 08:06:26 +00:00
|
|
|
canvas->setSource(testFileUrl("pathline.qml"));
|
2011-11-09 05:34:01 +00:00
|
|
|
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));
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickPath *path = qobject_cast<QQuickPath*>(pathview->path());
|
2011-11-09 05:34:01 +00:00
|
|
|
QVERIFY(path);
|
|
|
|
|
|
|
|
QPointF start = path->pointAt(0.5);
|
|
|
|
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-11-03 05:52:13 +00:00
|
|
|
void tst_QQuickPathView::asynchronous()
|
|
|
|
{
|
|
|
|
QQuickView *canvas = createView();
|
|
|
|
canvas->show();
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlIncubationController controller;
|
2011-11-03 05:52:13 +00:00
|
|
|
canvas->engine()->setIncubationController(&controller);
|
|
|
|
|
2011-12-21 08:06:26 +00:00
|
|
|
canvas->setSource(testFileUrl("asyncloader.qml"));
|
2011-11-03 05:52:13 +00:00
|
|
|
|
|
|
|
QQuickItem *rootObject = qobject_cast<QQuickItem*>(canvas->rootObject());
|
|
|
|
QVERIFY(rootObject);
|
|
|
|
|
|
|
|
QQuickPathView *pathview = 0;
|
|
|
|
while (!pathview) {
|
|
|
|
bool b = false;
|
|
|
|
controller.incubateWhile(&b);
|
|
|
|
pathview = rootObject->findChild<QQuickPathView*>("view");
|
|
|
|
}
|
|
|
|
|
|
|
|
// items will be created one at a time
|
|
|
|
for (int i = 0; i < 5; ++i) {
|
|
|
|
QVERIFY(findItem<QQuickItem>(pathview, "wrapper", i) == 0);
|
|
|
|
QQuickItem *item = 0;
|
|
|
|
while (!item) {
|
|
|
|
bool b = false;
|
|
|
|
controller.incubateWhile(&b);
|
|
|
|
item = findItem<QQuickItem>(pathview, "wrapper", i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
bool b = true;
|
|
|
|
controller.incubateWhile(&b);
|
|
|
|
}
|
|
|
|
|
|
|
|
// verify positioning
|
|
|
|
QQuickRectangle *firstItem = findItem<QQuickRectangle>(pathview, "wrapper", 0);
|
|
|
|
QVERIFY(firstItem);
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickPath *path = qobject_cast<QQuickPath*>(pathview->path());
|
2011-11-03 05:52:13 +00:00
|
|
|
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);
|
|
|
|
QTRY_COMPARE(firstItem->pos() + offset, start);
|
|
|
|
pathview->setOffset(1.0);
|
|
|
|
|
|
|
|
for (int i=0; i<5; i++) {
|
|
|
|
QQuickItem *curItem = findItem<QQuickItem>(pathview, "wrapper", i);
|
|
|
|
QPointF itemPos(path->pointAt(0.2 + i*0.2));
|
2012-02-16 05:54:09 +00:00
|
|
|
QCOMPARE(curItem->pos() + offset, itemPos);
|
2011-11-03 05:52:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
delete canvas;
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickPathView::missingPercent()
|
2011-07-29 00:41:47 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlEngine engine;
|
|
|
|
QQmlComponent c(&engine, testFileUrl("missingPercent.qml"));
|
|
|
|
QQuickPath *obj = qobject_cast<QQuickPath*>(c.create());
|
2011-07-29 00:41:47 +00:00
|
|
|
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"
|