2011-04-27 12:13:26 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2016-01-19 11:23:05 +00:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-04-27 12:13:26 +00:00
|
|
|
**
|
|
|
|
** This file is part of the test suite of the Qt Toolkit.
|
|
|
|
**
|
2016-01-19 11:23:05 +00:00
|
|
|
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
|
2012-09-20 05:21:40 +00:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2015-01-28 11:55:39 +00:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
2016-01-19 11:23:05 +00:00
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2012-09-20 05:21:40 +00:00
|
|
|
**
|
2016-01-19 11:23:05 +00:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
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>
|
2014-03-26 19:32:29 +00:00
|
|
|
#include <QtQuick/private/qquickflickable_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>
|
2018-10-24 08:06:18 +00:00
|
|
|
#include <QtQuickTest/QtQuickTest>
|
2019-04-03 13:22:22 +00:00
|
|
|
#include <QtQmlModels/private/qqmllistmodel_p.h>
|
2012-02-16 04:43:03 +00:00
|
|
|
#include <QtQml/private/qqmlvaluetype_p.h>
|
2012-07-18 00:36:17 +00:00
|
|
|
#include <QtGui/qstandarditemmodel.h>
|
2011-04-27 12:13:26 +00:00
|
|
|
#include <QStringListModel>
|
|
|
|
#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"
|
|
|
|
|
2017-09-08 05:20:14 +00:00
|
|
|
#include <math.h>
|
|
|
|
|
2017-05-02 06:25:37 +00:00
|
|
|
Q_LOGGING_CATEGORY(lcTests, "qt.quick.tests")
|
|
|
|
|
2012-01-31 07:15:00 +00:00
|
|
|
using namespace QQuickViewTestUtil;
|
|
|
|
using namespace QQuickVisualTestUtil;
|
|
|
|
|
2012-05-25 01:41:17 +00:00
|
|
|
Q_DECLARE_METATYPE(QQuickPathView::HighlightRangeMode)
|
2012-07-23 01:08:06 +00:00
|
|
|
Q_DECLARE_METATYPE(QQuickPathView::PositionMode)
|
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();
|
2012-07-18 00:36:17 +00:00
|
|
|
void initialCurrentIndex();
|
2014-09-30 12:23:56 +00:00
|
|
|
void initialCurrentItem();
|
2011-11-22 07:26:49 +00:00
|
|
|
void insertModel_data();
|
|
|
|
void insertModel();
|
|
|
|
void removeModel_data();
|
|
|
|
void removeModel();
|
|
|
|
void moveModel_data();
|
|
|
|
void moveModel();
|
2012-05-25 01:41:17 +00:00
|
|
|
void consecutiveModelChanges_data();
|
|
|
|
void consecutiveModelChanges();
|
2011-04-27 12:13:26 +00:00
|
|
|
void path();
|
|
|
|
void pathMoved();
|
2012-06-27 04:05:38 +00:00
|
|
|
void offset_data();
|
|
|
|
void offset();
|
2011-04-27 12:13:26 +00:00
|
|
|
void setCurrentIndex();
|
2019-03-21 13:36:57 +00:00
|
|
|
void setCurrentIndexWrap();
|
2011-04-27 12:13:26 +00:00
|
|
|
void resetModel();
|
|
|
|
void propertyChanges();
|
|
|
|
void pathChanges();
|
|
|
|
void componentChanges();
|
|
|
|
void modelChanges();
|
|
|
|
void pathUpdateOnStartChanged();
|
|
|
|
void package();
|
|
|
|
void emptyModel();
|
2013-01-17 09:46:45 +00:00
|
|
|
void emptyPath();
|
2011-04-27 12:13:26 +00:00
|
|
|
void closed();
|
|
|
|
void pathUpdate();
|
|
|
|
void visualDataModel();
|
|
|
|
void undefinedPath();
|
|
|
|
void mouseDrag();
|
2013-09-27 04:26:48 +00:00
|
|
|
void nestedMouseAreaDrag();
|
2019-09-05 11:57:19 +00:00
|
|
|
void flickNClick();
|
2011-04-27 12:13:26 +00:00
|
|
|
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();
|
2012-03-15 04:58:03 +00:00
|
|
|
void cancelDrag();
|
2012-03-25 02:37:08 +00:00
|
|
|
void maximumFlickVelocity();
|
2012-03-21 03:18:05 +00:00
|
|
|
void snapToItem();
|
|
|
|
void snapToItem_data();
|
|
|
|
void snapOneItem();
|
|
|
|
void snapOneItem_data();
|
2012-07-23 01:08:06 +00:00
|
|
|
void positionViewAtIndex();
|
|
|
|
void positionViewAtIndex_data();
|
|
|
|
void indexAt_itemAt();
|
|
|
|
void indexAt_itemAt_data();
|
2012-08-21 04:47:48 +00:00
|
|
|
void cacheItemCount();
|
2014-07-21 12:55:30 +00:00
|
|
|
void changePathDuringRefill();
|
2014-07-23 06:07:31 +00:00
|
|
|
void nestedinFlickable();
|
2019-11-14 07:16:39 +00:00
|
|
|
void ungrabNestedinFlickable();
|
2014-07-23 06:07:31 +00:00
|
|
|
void flickableDelegate();
|
2014-10-29 12:59:46 +00:00
|
|
|
void jsArrayChange();
|
2016-05-26 11:45:31 +00:00
|
|
|
void qtbug37815();
|
2015-05-07 05:56:03 +00:00
|
|
|
void qtbug42716();
|
2016-05-24 09:21:39 +00:00
|
|
|
void qtbug53464();
|
2015-05-21 07:52:49 +00:00
|
|
|
void addCustomAttribute();
|
2016-04-26 12:12:14 +00:00
|
|
|
void movementDirection_data();
|
|
|
|
void movementDirection();
|
2016-12-28 22:40:11 +00:00
|
|
|
void removePath();
|
2018-06-19 14:04:24 +00:00
|
|
|
void objectModelMove();
|
2019-08-15 08:03:57 +00:00
|
|
|
void requiredPropertiesInDelegate();
|
|
|
|
void requiredPropertiesInDelegatePreventUnrelated();
|
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
|
|
|
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(obj != nullptr);
|
2015-07-24 13:32:22 +00:00
|
|
|
QVERIFY(!obj->path());
|
|
|
|
QVERIFY(!obj->delegate());
|
2011-04-27 12:13:26 +00:00
|
|
|
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
|
|
|
{
|
2012-12-05 14:27:47 +00:00
|
|
|
QScopedPointer<QQuickView> window(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-07-11 07:32:16 +00:00
|
|
|
QQmlContext *ctxt = window->rootContext();
|
2011-04-27 12:13:26 +00:00
|
|
|
ctxt->setContextProperty("testModel", &model);
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
window->setSource(testFileUrl("pathview0.qml"));
|
2011-04-27 12:13:26 +00:00
|
|
|
qApp->processEvents();
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickPathView *pathview = findItem<QQuickPathView>(window->rootObject(), "view");
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(pathview != nullptr);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-05-30 06:35:52 +00:00
|
|
|
QCOMPARE(pathview->count(), model.count());
|
2012-07-11 07:32:16 +00:00
|
|
|
QCOMPARE(window->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);
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(name != nullptr);
|
2011-04-27 12:13:26 +00:00
|
|
|
QCOMPARE(name->text(), model.name(i));
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickText *number = findItem<QQuickText>(pathview, "textNumber", i);
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(number != nullptr);
|
2011-04-27 12:13:26 +00:00
|
|
|
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());
|
2019-05-27 21:36:31 +00:00
|
|
|
QPointF start = path->pointAtPercent(0.0);
|
2011-04-27 12:13:26 +00:00
|
|
|
QPointF offset;
|
|
|
|
offset.setX(pathview->highlightItem()->width()/2);
|
|
|
|
offset.setY(pathview->highlightItem()->height()/2);
|
2012-10-22 14:59:25 +00:00
|
|
|
QCOMPARE(pathview->highlightItem()->position() + offset, start);
|
2011-04-27 12:13:26 +00:00
|
|
|
}
|
|
|
|
|
2014-09-30 12:23:56 +00:00
|
|
|
void tst_QQuickPathView::initialCurrentItem()
|
|
|
|
{
|
|
|
|
QScopedPointer<QQuickView> window(createView());
|
|
|
|
|
|
|
|
QaimModel model;
|
|
|
|
model.addItem("Jules", "12345");
|
|
|
|
model.addItem("Vicent", "2345");
|
|
|
|
model.addItem("Marvin", "54321");
|
|
|
|
|
|
|
|
QQmlContext *ctxt = window->rootContext();
|
|
|
|
ctxt->setContextProperty("testModel", &model);
|
|
|
|
|
|
|
|
window->setSource(testFileUrl("pathview4.qml"));
|
|
|
|
qApp->processEvents();
|
|
|
|
|
|
|
|
QQuickPathView *pathview = findItem<QQuickPathView>(window->rootObject(), "view");
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(pathview != nullptr);
|
2014-09-30 12:23:56 +00:00
|
|
|
QVERIFY(pathview->currentIndex() != -1);
|
|
|
|
QVERIFY(!window->rootObject()->property("currentItemIsNull").toBool());
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(obj != nullptr);
|
|
|
|
QVERIFY(obj->path() != nullptr);
|
|
|
|
QVERIFY(obj->delegate() != nullptr);
|
2011-04-27 12:13:26 +00:00
|
|
|
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
|
|
|
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(obj != nullptr);
|
|
|
|
QVERIFY(obj->path() != nullptr);
|
|
|
|
QVERIFY(obj->delegate() != nullptr);
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(obj->model() != QVariant());
|
2012-06-27 04:05:38 +00:00
|
|
|
QCOMPARE(obj->currentIndex(), 7);
|
2011-04-27 12:13:26 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-07-18 00:36:17 +00:00
|
|
|
void tst_QQuickPathView::initialCurrentIndex()
|
|
|
|
{
|
|
|
|
QQmlEngine engine;
|
|
|
|
QQmlComponent c(&engine, testFileUrl("initialCurrentIndex.qml"));
|
|
|
|
QQuickPathView *obj = qobject_cast<QQuickPathView*>(c.create());
|
|
|
|
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(obj != nullptr);
|
|
|
|
QVERIFY(obj->path() != nullptr);
|
|
|
|
QVERIFY(obj->delegate() != nullptr);
|
2012-07-18 00:36:17 +00:00
|
|
|
QVERIFY(obj->model() != QVariant());
|
|
|
|
QCOMPARE(obj->currentIndex(), 3);
|
|
|
|
QCOMPARE(obj->offset(), 5.0);
|
|
|
|
QCOMPARE(obj->preferredHighlightBegin(), 0.5);
|
|
|
|
QCOMPARE(obj->dragMargin(), 24.);
|
|
|
|
QCOMPARE(obj->count(), 8);
|
|
|
|
QCOMPARE(obj->pathItemCount(), 4);
|
|
|
|
|
|
|
|
delete obj;
|
|
|
|
}
|
|
|
|
|
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");
|
2012-05-29 05:45:15 +00:00
|
|
|
QTest::addColumn<int>("currentIndex");
|
2011-11-22 07:26:49 +00:00
|
|
|
|
|
|
|
// We have 8 items, with currentIndex == 4
|
|
|
|
QTest::newRow("insert after current")
|
2013-03-07 15:07:35 +00:00
|
|
|
<< int(QQuickPathView::StrictlyEnforceRange) << 6 << 1 << qreal(5.) << 4;
|
2011-11-22 07:26:49 +00:00
|
|
|
QTest::newRow("insert before current")
|
2013-03-07 15:07:35 +00:00
|
|
|
<< int(QQuickPathView::StrictlyEnforceRange) << 2 << 1 << qreal(4.)<< 5;
|
2011-11-22 07:26:49 +00:00
|
|
|
QTest::newRow("insert multiple after current")
|
2013-03-07 15:07:35 +00:00
|
|
|
<< int(QQuickPathView::StrictlyEnforceRange) << 5 << 2 << qreal(6.) << 4;
|
2011-11-22 07:26:49 +00:00
|
|
|
QTest::newRow("insert multiple before current")
|
2013-03-07 15:07:35 +00:00
|
|
|
<< int(QQuickPathView::StrictlyEnforceRange) << 1 << 2 << qreal(4.) << 6;
|
2011-11-22 07:26:49 +00:00
|
|
|
QTest::newRow("insert at end")
|
2013-03-07 15:07:35 +00:00
|
|
|
<< int(QQuickPathView::StrictlyEnforceRange) << 8 << 1 << qreal(5.) << 4;
|
2011-11-22 07:26:49 +00:00
|
|
|
QTest::newRow("insert at beginning")
|
2013-03-07 15:07:35 +00:00
|
|
|
<< int(QQuickPathView::StrictlyEnforceRange) << 0 << 1 << qreal(4.) << 5;
|
2011-11-22 07:26:49 +00:00
|
|
|
QTest::newRow("insert at current")
|
2013-03-07 15:07:35 +00:00
|
|
|
<< int(QQuickPathView::StrictlyEnforceRange) << 4 << 1 << qreal(4.) << 5;
|
2011-11-22 07:26:49 +00:00
|
|
|
|
|
|
|
QTest::newRow("no range - insert after current")
|
2013-03-07 15:07:35 +00:00
|
|
|
<< int(QQuickPathView::NoHighlightRange) << 6 << 1 << qreal(5.) << 4;
|
2011-11-22 07:26:49 +00:00
|
|
|
QTest::newRow("no range - insert before current")
|
2013-03-07 15:07:35 +00:00
|
|
|
<< int(QQuickPathView::NoHighlightRange) << 2 << 1 << qreal(4.) << 5;
|
2011-11-22 07:26:49 +00:00
|
|
|
QTest::newRow("no range - insert multiple after current")
|
2013-03-07 15:07:35 +00:00
|
|
|
<< int(QQuickPathView::NoHighlightRange) << 5 << 2 << qreal(6.) << 4;
|
2011-11-22 07:26:49 +00:00
|
|
|
QTest::newRow("no range - insert multiple before current")
|
2013-03-07 15:07:35 +00:00
|
|
|
<< int(QQuickPathView::NoHighlightRange) << 1 << 2 << qreal(4.) << 6;
|
2011-11-22 07:26:49 +00:00
|
|
|
QTest::newRow("no range - insert at end")
|
2013-03-07 15:07:35 +00:00
|
|
|
<< int(QQuickPathView::NoHighlightRange) << 8 << 1 << qreal(5.) << 4;
|
2011-11-22 07:26:49 +00:00
|
|
|
QTest::newRow("no range - insert at beginning")
|
2013-03-07 15:07:35 +00:00
|
|
|
<< int(QQuickPathView::NoHighlightRange) << 0 << 1 << qreal(4.) << 5;
|
2011-11-22 07:26:49 +00:00
|
|
|
QTest::newRow("no range - insert at current")
|
2013-03-07 15:07:35 +00:00
|
|
|
<< int(QQuickPathView::NoHighlightRange) << 4 << 1 << qreal(4.) << 5;
|
2011-11-22 07:26:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QQuickPathView::insertModel()
|
|
|
|
{
|
2018-05-02 10:02:11 +00:00
|
|
|
#ifdef Q_OS_MACOS
|
|
|
|
QSKIP("this test currently crashes on MacOS. See QTBUG-68048");
|
|
|
|
#endif
|
|
|
|
|
2011-11-22 07:26:49 +00:00
|
|
|
QFETCH(int, mode);
|
|
|
|
QFETCH(int, idx);
|
|
|
|
QFETCH(int, count);
|
|
|
|
QFETCH(qreal, offset);
|
2012-05-29 05:45:15 +00:00
|
|
|
QFETCH(int, currentIndex);
|
2011-11-22 07:26:49 +00:00
|
|
|
|
2012-12-05 14:27:47 +00:00
|
|
|
QScopedPointer<QQuickView> window(createView());
|
2012-07-11 07:32:16 +00:00
|
|
|
window->show();
|
2011-11-22 07:26:49 +00:00
|
|
|
|
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-07-11 07:32:16 +00:00
|
|
|
QQmlContext *ctxt = window->rootContext();
|
2011-11-22 07:26:49 +00:00
|
|
|
ctxt->setContextProperty("testModel", &model);
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
window->setSource(testFileUrl("pathview0.qml"));
|
2011-11-22 07:26:49 +00:00
|
|
|
qApp->processEvents();
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickPathView *pathview = findItem<QQuickPathView>(window->rootObject(), "view");
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(pathview != nullptr);
|
2011-11-22 07:26:49 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2012-05-29 05:45:15 +00:00
|
|
|
QCOMPARE(pathview->currentIndex(), currentIndex);
|
2011-11-22 07:26:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QQuickPathView::removeModel_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<int>("mode");
|
|
|
|
QTest::addColumn<int>("idx");
|
|
|
|
QTest::addColumn<int>("count");
|
|
|
|
QTest::addColumn<qreal>("offset");
|
2012-05-29 05:45:15 +00:00
|
|
|
QTest::addColumn<int>("currentIndex");
|
2011-11-22 07:26:49 +00:00
|
|
|
|
|
|
|
// We have 8 items, with currentIndex == 4
|
|
|
|
QTest::newRow("remove after current")
|
2013-03-07 15:07:35 +00:00
|
|
|
<< int(QQuickPathView::StrictlyEnforceRange) << 6 << 1 << qreal(3.) << 4;
|
2011-11-22 07:26:49 +00:00
|
|
|
QTest::newRow("remove before current")
|
2013-03-07 15:07:35 +00:00
|
|
|
<< int(QQuickPathView::StrictlyEnforceRange) << 2 << 1 << qreal(4.) << 3;
|
2011-11-22 07:26:49 +00:00
|
|
|
QTest::newRow("remove multiple after current")
|
2013-03-07 15:07:35 +00:00
|
|
|
<< int(QQuickPathView::StrictlyEnforceRange) << 5 << 2 << qreal(2.) << 4;
|
2011-11-22 07:26:49 +00:00
|
|
|
QTest::newRow("remove multiple before current")
|
2013-03-07 15:07:35 +00:00
|
|
|
<< int(QQuickPathView::StrictlyEnforceRange) << 1 << 2 << qreal(4.) << 2;
|
2011-11-22 07:26:49 +00:00
|
|
|
QTest::newRow("remove last")
|
2013-03-07 15:07:35 +00:00
|
|
|
<< int(QQuickPathView::StrictlyEnforceRange) << 7 << 1 << qreal(3.) << 4;
|
2011-11-22 07:26:49 +00:00
|
|
|
QTest::newRow("remove first")
|
2013-03-07 15:07:35 +00:00
|
|
|
<< int(QQuickPathView::StrictlyEnforceRange) << 0 << 1 << qreal(4.) << 3;
|
2011-11-22 07:26:49 +00:00
|
|
|
QTest::newRow("remove current")
|
2013-03-07 15:07:35 +00:00
|
|
|
<< int(QQuickPathView::StrictlyEnforceRange) << 4 << 1 << qreal(3.) << 4;
|
2012-05-29 05:45:15 +00:00
|
|
|
QTest::newRow("remove all")
|
2013-03-07 15:07:35 +00:00
|
|
|
<< int(QQuickPathView::StrictlyEnforceRange) << 0 << 8 << qreal(0.) << 0;
|
2011-11-22 07:26:49 +00:00
|
|
|
|
|
|
|
QTest::newRow("no range - remove after current")
|
2013-03-07 15:07:35 +00:00
|
|
|
<< int(QQuickPathView::NoHighlightRange) << 6 << 1 << qreal(3.) << 4;
|
2011-11-22 07:26:49 +00:00
|
|
|
QTest::newRow("no range - remove before current")
|
2013-03-07 15:07:35 +00:00
|
|
|
<< int(QQuickPathView::NoHighlightRange) << 2 << 1 << qreal(4.) << 3;
|
2011-11-22 07:26:49 +00:00
|
|
|
QTest::newRow("no range - remove multiple after current")
|
2013-03-07 15:07:35 +00:00
|
|
|
<< int(QQuickPathView::NoHighlightRange) << 5 << 2 << qreal(2.) << 4;
|
2011-11-22 07:26:49 +00:00
|
|
|
QTest::newRow("no range - remove multiple before current")
|
2013-03-07 15:07:35 +00:00
|
|
|
<< int(QQuickPathView::NoHighlightRange) << 1 << 2 << qreal(4.) << 2;
|
2011-11-22 07:26:49 +00:00
|
|
|
QTest::newRow("no range - remove last")
|
2013-03-07 15:07:35 +00:00
|
|
|
<< int(QQuickPathView::NoHighlightRange) << 7 << 1 << qreal(3.) << 4;
|
2011-11-22 07:26:49 +00:00
|
|
|
QTest::newRow("no range - remove first")
|
2013-03-07 15:07:35 +00:00
|
|
|
<< int(QQuickPathView::NoHighlightRange) << 0 << 1 << qreal(4.) << 3;
|
2011-11-22 07:26:49 +00:00
|
|
|
QTest::newRow("no range - remove current offset")
|
2013-03-07 15:07:35 +00:00
|
|
|
<< int(QQuickPathView::NoHighlightRange) << 4 << 1 << qreal(4.) << 4;
|
2012-05-29 05:45:15 +00:00
|
|
|
QTest::newRow("no range - remove all")
|
2013-03-07 15:07:35 +00:00
|
|
|
<< int(QQuickPathView::NoHighlightRange) << 0 << 8 << qreal(0.) << 0;
|
2011-11-22 07:26:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QQuickPathView::removeModel()
|
|
|
|
{
|
|
|
|
QFETCH(int, mode);
|
|
|
|
QFETCH(int, idx);
|
|
|
|
QFETCH(int, count);
|
|
|
|
QFETCH(qreal, offset);
|
2012-05-29 05:45:15 +00:00
|
|
|
QFETCH(int, currentIndex);
|
2011-11-22 07:26:49 +00:00
|
|
|
|
2012-12-05 14:27:47 +00:00
|
|
|
QScopedPointer<QQuickView> window(createView());
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
window->show();
|
2011-11-22 07:26:49 +00:00
|
|
|
|
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-07-11 07:32:16 +00:00
|
|
|
QQmlContext *ctxt = window->rootContext();
|
2011-11-22 07:26:49 +00:00
|
|
|
ctxt->setContextProperty("testModel", &model);
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
window->setSource(testFileUrl("pathview0.qml"));
|
2011-11-22 07:26:49 +00:00
|
|
|
qApp->processEvents();
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickPathView *pathview = findItem<QQuickPathView>(window->rootObject(), "view");
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(pathview != nullptr);
|
2011-11-22 07:26:49 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2012-05-29 05:45:15 +00:00
|
|
|
QCOMPARE(pathview->currentIndex(), currentIndex);
|
2011-11-22 07:26:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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");
|
2012-05-29 05:45:15 +00:00
|
|
|
QTest::addColumn<int>("currentIndex");
|
2011-11-22 07:26:49 +00:00
|
|
|
|
|
|
|
// We have 8 items, with currentIndex == 4
|
|
|
|
QTest::newRow("move after current")
|
2013-03-07 15:07:35 +00:00
|
|
|
<< int(QQuickPathView::StrictlyEnforceRange) << 5 << 6 << 1 << qreal(4.) << 4;
|
2011-11-22 07:26:49 +00:00
|
|
|
QTest::newRow("move before current")
|
2013-03-07 15:07:35 +00:00
|
|
|
<< int(QQuickPathView::StrictlyEnforceRange) << 2 << 3 << 1 << qreal(4.) << 4;
|
2011-11-22 07:26:49 +00:00
|
|
|
QTest::newRow("move before current to after")
|
2013-03-07 15:07:35 +00:00
|
|
|
<< int(QQuickPathView::StrictlyEnforceRange) << 2 << 6 << 1 << qreal(5.) << 3;
|
2011-11-22 07:26:49 +00:00
|
|
|
QTest::newRow("move multiple after current")
|
2013-03-07 15:07:35 +00:00
|
|
|
<< int(QQuickPathView::StrictlyEnforceRange) << 5 << 6 << 2 << qreal(4.) << 4;
|
2011-11-22 07:26:49 +00:00
|
|
|
QTest::newRow("move multiple before current")
|
2013-03-07 15:07:35 +00:00
|
|
|
<< int(QQuickPathView::StrictlyEnforceRange) << 0 << 1 << 2 << qreal(4.) << 4;
|
2011-11-22 07:26:49 +00:00
|
|
|
QTest::newRow("move before current to end")
|
2013-03-07 15:07:35 +00:00
|
|
|
<< int(QQuickPathView::StrictlyEnforceRange) << 2 << 7 << 1 << qreal(5.) << 3;
|
2011-11-22 07:26:49 +00:00
|
|
|
QTest::newRow("move last to beginning")
|
2013-03-07 15:07:35 +00:00
|
|
|
<< int(QQuickPathView::StrictlyEnforceRange) << 7 << 0 << 1 << qreal(3.) << 5;
|
2011-11-22 07:26:49 +00:00
|
|
|
QTest::newRow("move current")
|
2013-03-07 15:07:35 +00:00
|
|
|
<< int(QQuickPathView::StrictlyEnforceRange) << 4 << 6 << 1 << qreal(2.) << 6;
|
2011-11-22 07:26:49 +00:00
|
|
|
|
|
|
|
QTest::newRow("no range - move after current")
|
2013-03-07 15:07:35 +00:00
|
|
|
<< int(QQuickPathView::NoHighlightRange) << 5 << 6 << 1 << qreal(4.) << 4;
|
2011-11-22 07:26:49 +00:00
|
|
|
QTest::newRow("no range - move before current")
|
2013-03-07 15:07:35 +00:00
|
|
|
<< int(QQuickPathView::NoHighlightRange) << 2 << 3 << 1 << qreal(4.) << 4;
|
2011-11-22 07:26:49 +00:00
|
|
|
QTest::newRow("no range - move before current to after")
|
2013-03-07 15:07:35 +00:00
|
|
|
<< int(QQuickPathView::NoHighlightRange) << 2 << 6 << 1 << qreal(5.) << 3;
|
2011-11-22 07:26:49 +00:00
|
|
|
QTest::newRow("no range - move multiple after current")
|
2013-03-07 15:07:35 +00:00
|
|
|
<< int(QQuickPathView::NoHighlightRange) << 5 << 6 << 2 << qreal(4.) << 4;
|
2011-11-22 07:26:49 +00:00
|
|
|
QTest::newRow("no range - move multiple before current")
|
2013-03-07 15:07:35 +00:00
|
|
|
<< int(QQuickPathView::NoHighlightRange) << 0 << 1 << 2 << qreal(4.) << 4;
|
2011-11-22 07:26:49 +00:00
|
|
|
QTest::newRow("no range - move before current to end")
|
2013-03-07 15:07:35 +00:00
|
|
|
<< int(QQuickPathView::NoHighlightRange) << 2 << 7 << 1 << qreal(5.) << 3;
|
2011-11-22 07:26:49 +00:00
|
|
|
QTest::newRow("no range - move last to beginning")
|
2013-03-07 15:07:35 +00:00
|
|
|
<< int(QQuickPathView::NoHighlightRange) << 7 << 0 << 1 << qreal(3.) << 5;
|
2011-11-22 07:26:49 +00:00
|
|
|
QTest::newRow("no range - move current")
|
2013-03-07 15:07:35 +00:00
|
|
|
<< int(QQuickPathView::NoHighlightRange) << 4 << 6 << 1 << qreal(4.) << 6;
|
2011-11-22 07:26:49 +00:00
|
|
|
QTest::newRow("no range - move multiple incl. current")
|
2013-03-07 15:07:35 +00:00
|
|
|
<< int(QQuickPathView::NoHighlightRange) << 0 << 1 << 5 << qreal(4.) << 5;
|
2011-11-22 07:26:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QQuickPathView::moveModel()
|
|
|
|
{
|
|
|
|
QFETCH(int, mode);
|
|
|
|
QFETCH(int, from);
|
|
|
|
QFETCH(int, to);
|
|
|
|
QFETCH(int, count);
|
|
|
|
QFETCH(qreal, offset);
|
2012-05-29 05:45:15 +00:00
|
|
|
QFETCH(int, currentIndex);
|
2011-11-22 07:26:49 +00:00
|
|
|
|
2012-12-05 14:27:47 +00:00
|
|
|
QScopedPointer<QQuickView> window(createView());
|
2012-07-11 07:32:16 +00:00
|
|
|
window->show();
|
2011-11-22 07:26:49 +00:00
|
|
|
|
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-07-11 07:32:16 +00:00
|
|
|
QQmlContext *ctxt = window->rootContext();
|
2011-11-22 07:26:49 +00:00
|
|
|
ctxt->setContextProperty("testModel", &model);
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
window->setSource(testFileUrl("pathview0.qml"));
|
2011-11-22 07:26:49 +00:00
|
|
|
qApp->processEvents();
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickPathView *pathview = findItem<QQuickPathView>(window->rootObject(), "view");
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(pathview != nullptr);
|
2011-11-22 07:26:49 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2012-05-29 05:45:15 +00:00
|
|
|
QCOMPARE(pathview->currentIndex(), currentIndex);
|
2011-11-22 07:26:49 +00:00
|
|
|
}
|
|
|
|
|
2012-05-25 01:41:17 +00:00
|
|
|
void tst_QQuickPathView::consecutiveModelChanges_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QQuickPathView::HighlightRangeMode>("mode");
|
|
|
|
QTest::addColumn<QList<ListChange> >("changes");
|
|
|
|
QTest::addColumn<int>("count");
|
|
|
|
QTest::addColumn<qreal>("offset");
|
2012-05-29 05:45:15 +00:00
|
|
|
QTest::addColumn<int>("currentIndex");
|
2012-05-25 01:41:17 +00:00
|
|
|
|
|
|
|
QTest::newRow("no range - insert after, insert before")
|
|
|
|
<< QQuickPathView::NoHighlightRange
|
|
|
|
<< (QList<ListChange>()
|
|
|
|
<< ListChange::insert(7, 2)
|
|
|
|
<< ListChange::insert(1, 3))
|
|
|
|
<< 13
|
2012-05-29 05:45:15 +00:00
|
|
|
<< 6.
|
|
|
|
<< 7;
|
2012-05-25 01:41:17 +00:00
|
|
|
QTest::newRow("no range - remove after, remove before")
|
|
|
|
<< QQuickPathView::NoHighlightRange
|
|
|
|
<< (QList<ListChange>()
|
|
|
|
<< ListChange::remove(6, 2)
|
|
|
|
<< ListChange::remove(1, 3))
|
|
|
|
<< 3
|
2012-05-29 05:45:15 +00:00
|
|
|
<< 2.
|
|
|
|
<< 1;
|
2012-05-25 01:41:17 +00:00
|
|
|
|
|
|
|
QTest::newRow("no range - remove after, insert before")
|
|
|
|
<< QQuickPathView::NoHighlightRange
|
|
|
|
<< (QList<ListChange>()
|
|
|
|
<< ListChange::remove(5, 2)
|
|
|
|
<< ListChange::insert(1, 3))
|
|
|
|
<< 9
|
2012-05-29 05:45:15 +00:00
|
|
|
<< 2.
|
|
|
|
<< 7;
|
2012-05-25 01:41:17 +00:00
|
|
|
|
|
|
|
QTest::newRow("no range - insert after, remove before")
|
|
|
|
<< QQuickPathView::NoHighlightRange
|
|
|
|
<< (QList<ListChange>()
|
|
|
|
<< ListChange::insert(6, 2)
|
|
|
|
<< ListChange::remove(1, 3))
|
|
|
|
<< 7
|
2012-05-29 05:45:15 +00:00
|
|
|
<< 6.
|
|
|
|
<< 1;
|
2012-05-25 01:41:17 +00:00
|
|
|
|
|
|
|
QTest::newRow("no range - insert, remove all, polish, insert")
|
|
|
|
<< QQuickPathView::NoHighlightRange
|
|
|
|
<< (QList<ListChange>()
|
|
|
|
<< ListChange::insert(3, 1)
|
|
|
|
<< ListChange::remove(0, 9)
|
|
|
|
<< ListChange::polish()
|
|
|
|
<< ListChange::insert(0, 3))
|
|
|
|
<< 3
|
2012-05-29 05:45:15 +00:00
|
|
|
<< 0.
|
|
|
|
<< 0;
|
2012-05-25 01:41:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QQuickPathView::consecutiveModelChanges()
|
|
|
|
{
|
|
|
|
QFETCH(QQuickPathView::HighlightRangeMode, mode);
|
|
|
|
QFETCH(QList<ListChange>, changes);
|
|
|
|
QFETCH(int, count);
|
|
|
|
QFETCH(qreal, offset);
|
2012-05-29 05:45:15 +00:00
|
|
|
QFETCH(int, currentIndex);
|
2012-05-25 01:41:17 +00:00
|
|
|
|
2012-12-05 14:27:47 +00:00
|
|
|
QScopedPointer<QQuickView> window(createView());
|
2012-07-11 07:32:16 +00:00
|
|
|
window->show();
|
2012-05-25 01:41:17 +00:00
|
|
|
|
|
|
|
QaimModel model;
|
|
|
|
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-07-11 07:32:16 +00:00
|
|
|
QQmlContext *ctxt = window->rootContext();
|
2012-05-25 01:41:17 +00:00
|
|
|
ctxt->setContextProperty("testModel", &model);
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
window->setSource(testFileUrl("pathview0.qml"));
|
2012-05-25 01:41:17 +00:00
|
|
|
qApp->processEvents();
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickPathView *pathview = findItem<QQuickPathView>(window->rootObject(), "view");
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(pathview != nullptr);
|
2012-05-25 01:41:17 +00:00
|
|
|
|
|
|
|
pathview->setHighlightRangeMode(mode);
|
|
|
|
|
|
|
|
pathview->setCurrentIndex(4);
|
|
|
|
if (mode == QQuickPathView::StrictlyEnforceRange)
|
|
|
|
QTRY_COMPARE(pathview->offset(), 4.0);
|
|
|
|
else
|
|
|
|
pathview->setOffset(4);
|
|
|
|
|
|
|
|
for (int i=0; i<changes.count(); i++) {
|
|
|
|
switch (changes[i].type) {
|
|
|
|
case ListChange::Inserted:
|
|
|
|
{
|
|
|
|
QList<QPair<QString, QString> > items;
|
|
|
|
for (int j=changes[i].index; j<changes[i].index + changes[i].count; ++j)
|
|
|
|
items << qMakePair(QString("new item %1").arg(j), QString::number(j));
|
|
|
|
model.insertItems(changes[i].index, items);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ListChange::Removed:
|
|
|
|
model.removeItems(changes[i].index, changes[i].count);
|
|
|
|
break;
|
|
|
|
case ListChange::Moved:
|
|
|
|
model.moveItems(changes[i].index, changes[i].to, changes[i].count);
|
|
|
|
break;
|
|
|
|
case ListChange::SetCurrent:
|
|
|
|
pathview->setCurrentIndex(changes[i].index);
|
|
|
|
break;
|
|
|
|
case ListChange::Polish:
|
2018-10-24 08:06:18 +00:00
|
|
|
QQuickTest::qWaitForItemPolished(pathview);
|
2012-05-25 01:41:17 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2018-10-24 08:06:18 +00:00
|
|
|
QQuickTest::qWaitForItemPolished(pathview);
|
2012-05-25 01:41:17 +00:00
|
|
|
|
|
|
|
QCOMPARE(findItems<QQuickItem>(pathview, "wrapper").count(), count);
|
|
|
|
QCOMPARE(pathview->count(), count);
|
|
|
|
QTRY_COMPARE(pathview->offset(), offset);
|
|
|
|
|
2012-05-29 05:45:15 +00:00
|
|
|
QCOMPARE(pathview->currentIndex(), currentIndex);
|
|
|
|
|
2012-05-25 01:41:17 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(obj != nullptr);
|
2011-04-27 12:13:26 +00:00
|
|
|
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));
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(attr != nullptr);
|
2011-04-27 12:13:26 +00:00
|
|
|
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));
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(quad != nullptr);
|
2011-04-27 12:13:26 +00:00
|
|
|
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));
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(perc != nullptr);
|
2011-04-27 12:13:26 +00:00
|
|
|
QCOMPARE(perc->value(), 0.3);
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickPathLine* line = qobject_cast<QQuickPathLine*>(list.at(3));
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(line != nullptr);
|
2011-04-27 12:13:26 +00:00
|
|
|
QCOMPARE(line->x(), 120.);
|
|
|
|
QCOMPARE(line->y(), 100.);
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickPathCubic* cubic = qobject_cast<QQuickPathCubic*>(list.at(4));
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(cubic != nullptr);
|
2011-04-27 12:13:26 +00:00
|
|
|
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
|
|
|
{
|
2018-05-02 09:41:37 +00:00
|
|
|
#ifdef Q_OS_MACOS
|
|
|
|
QSKIP("this test currently crashes on MacOS. See QTBUG-68047");
|
|
|
|
#endif
|
|
|
|
|
2012-12-05 14:27:47 +00:00
|
|
|
QScopedPointer<QQuickView> window(createView());
|
2012-07-11 07:32:16 +00:00
|
|
|
window->show();
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQmlContext *ctxt = window->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);
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
window->setSource(testFileUrl("datamodel.qml"));
|
2011-04-27 12:13:26 +00:00
|
|
|
qApp->processEvents();
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickPathView *pathview = qobject_cast<QQuickPathView*>(window->rootObject());
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(pathview != nullptr);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QMetaObject::invokeMethod(window->rootObject(), "checkProperties");
|
2015-07-24 11:39:05 +00:00
|
|
|
QVERIFY(!testObject->error());
|
2011-04-27 12:13:26 +00:00
|
|
|
|
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);
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QCOMPARE(window->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
|
|
|
|
2013-12-18 11:07:38 +00:00
|
|
|
QCOMPARE(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);
|
2012-07-11 07:32:16 +00:00
|
|
|
QCOMPARE(window->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);
|
2012-07-11 07:32:16 +00:00
|
|
|
QMetaObject::invokeMethod(window->rootObject(), "checkProperties");
|
2015-07-24 11:39:05 +00:00
|
|
|
QVERIFY(!testObject->error());
|
2011-04-27 12:13:26 +00:00
|
|
|
|
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);
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(testItem != nullptr);
|
2011-10-14 08:51:42 +00:00
|
|
|
testItem = findItem<QQuickRectangle>(pathview, "wrapper", 5);
|
2015-07-24 13:32:22 +00:00
|
|
|
QVERIFY(!testItem);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
pathview->setCurrentIndex(1);
|
2014-03-05 19:25:14 +00:00
|
|
|
QCOMPARE(pathview->currentIndex(), 1);
|
|
|
|
QCOMPARE(pathview->currentItem(), findItem<QQuickItem>(pathview, "wrapper", 1));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
model.insertItem(2, "pink", "2");
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QTRY_COMPARE(findItems<QQuickItem>(pathview, "wrapper").count(), 5);
|
2013-12-18 11:07:38 +00:00
|
|
|
QCOMPARE(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
|
|
|
|
2014-03-05 19:25:14 +00:00
|
|
|
QTRY_VERIFY(text = findItem<QQuickText>(pathview, "myText", 2));
|
2011-04-27 12:13:26 +00:00
|
|
|
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);
|
2012-06-27 04:05:38 +00:00
|
|
|
QTRY_COMPARE(pathview->offset(), 1.0);
|
2011-04-27 12:13:26 +00:00
|
|
|
model.removeItem(model.count()-1);
|
|
|
|
QCOMPARE(pathview->currentIndex(), model.count()-1);
|
|
|
|
|
|
|
|
delete testObject;
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickPathView::pathMoved()
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
2012-12-05 14:27:47 +00:00
|
|
|
QScopedPointer<QQuickView> window(createView());
|
2012-07-11 07:32:16 +00:00
|
|
|
window->show();
|
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("Ben", "12345");
|
|
|
|
model.addItem("Bohn", "2345");
|
|
|
|
model.addItem("Bob", "54321");
|
|
|
|
model.addItem("Bill", "4321");
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQmlContext *ctxt = window->rootContext();
|
2011-04-27 12:13:26 +00:00
|
|
|
ctxt->setContextProperty("testModel", &model);
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
window->setSource(testFileUrl("pathview0.qml"));
|
2011-04-27 12:13:26 +00:00
|
|
|
qApp->processEvents();
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickPathView *pathview = findItem<QQuickPathView>(window->rootObject(), "view");
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(pathview != nullptr);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
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);
|
2019-05-27 21:36:31 +00:00
|
|
|
QPointF start = path->pointAtPercent(0.0);
|
2011-04-27 12:13:26 +00:00
|
|
|
QPointF offset;//Center of item is at point, but pos is from corner
|
|
|
|
offset.setX(firstItem->width()/2);
|
|
|
|
offset.setY(firstItem->height()/2);
|
2012-10-22 14:59:25 +00:00
|
|
|
QTRY_COMPARE(firstItem->position() + 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);
|
2019-05-27 21:36:31 +00:00
|
|
|
QPointF itemPos(path->pointAtPercent(0.25 + i*0.25));
|
2012-10-22 14:59:25 +00:00
|
|
|
QCOMPARE(curItem->position() + offset, QPointF(itemPos.x(), itemPos.y()));
|
2011-04-27 12:13:26 +00:00
|
|
|
}
|
|
|
|
|
2012-06-27 04:05:38 +00:00
|
|
|
QCOMPARE(pathview->currentIndex(), 3);
|
|
|
|
|
2011-04-27 12:13:26 +00:00
|
|
|
pathview->setOffset(0.0);
|
2012-10-22 14:59:25 +00:00
|
|
|
QCOMPARE(firstItem->position() + offset, start);
|
2012-06-27 04:05:38 +00:00
|
|
|
QCOMPARE(pathview->currentIndex(), 0);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
// Change delegate size
|
|
|
|
pathview->setOffset(0.1);
|
|
|
|
pathview->setOffset(0.0);
|
2012-07-11 07:32:16 +00:00
|
|
|
window->rootObject()->setProperty("delegateWidth", 30);
|
2011-04-27 12:13:26 +00:00
|
|
|
QCOMPARE(firstItem->width(), 30.0);
|
|
|
|
offset.setX(firstItem->width()/2);
|
2012-10-22 14:59:25 +00:00
|
|
|
QTRY_COMPARE(firstItem->position() + offset, start);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
// Change delegate scale
|
|
|
|
pathview->setOffset(0.1);
|
|
|
|
pathview->setOffset(0.0);
|
2012-07-11 07:32:16 +00:00
|
|
|
window->rootObject()->setProperty("delegateScale", 1.2);
|
2012-10-22 14:59:25 +00:00
|
|
|
QTRY_COMPARE(firstItem->position() + offset, start);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-06-27 04:05:38 +00:00
|
|
|
void tst_QQuickPathView::offset_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<qreal>("offset");
|
|
|
|
QTest::addColumn<int>("currentIndex");
|
|
|
|
|
|
|
|
QTest::newRow("0.0") << 0.0 << 0;
|
|
|
|
QTest::newRow("1.0") << 7.0 << 1;
|
|
|
|
QTest::newRow("5.0") << 5.0 << 3;
|
|
|
|
QTest::newRow("4.6") << 4.6 << 3;
|
|
|
|
QTest::newRow("4.4") << 4.4 << 4;
|
|
|
|
QTest::newRow("5.4") << 5.4 << 3;
|
|
|
|
QTest::newRow("5.6") << 5.6 << 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QQuickPathView::offset()
|
|
|
|
{
|
|
|
|
QFETCH(qreal, offset);
|
|
|
|
QFETCH(int, currentIndex);
|
|
|
|
|
|
|
|
QQmlEngine engine;
|
|
|
|
QQmlComponent c(&engine, testFileUrl("pathview3.qml"));
|
|
|
|
QQuickPathView *view = qobject_cast<QQuickPathView*>(c.create());
|
|
|
|
|
|
|
|
view->setOffset(offset);
|
|
|
|
QCOMPARE(view->currentIndex(), currentIndex);
|
|
|
|
|
|
|
|
delete view;
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickPathView::setCurrentIndex()
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
2012-12-05 14:27:47 +00:00
|
|
|
QScopedPointer<QQuickView> window(createView());
|
2012-07-11 07:32:16 +00:00
|
|
|
window->show();
|
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("Ben", "12345");
|
|
|
|
model.addItem("Bohn", "2345");
|
|
|
|
model.addItem("Bob", "54321");
|
|
|
|
model.addItem("Bill", "4321");
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQmlContext *ctxt = window->rootContext();
|
2011-04-27 12:13:26 +00:00
|
|
|
ctxt->setContextProperty("testModel", &model);
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
window->setSource(testFileUrl("pathview0.qml"));
|
2011-04-27 12:13:26 +00:00
|
|
|
qApp->processEvents();
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickPathView *pathview = findItem<QQuickPathView>(window->rootObject(), "view");
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(pathview != nullptr);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
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);
|
2019-05-27 21:36:31 +00:00
|
|
|
QPointF start = path->pointAtPercent(0.0);
|
2011-04-27 12:13:26 +00:00
|
|
|
QPointF offset;//Center of item is at point, but pos is from corner
|
|
|
|
offset.setX(firstItem->width()/2);
|
|
|
|
offset.setY(firstItem->height()/2);
|
2012-10-22 14:59:25 +00:00
|
|
|
QCOMPARE(firstItem->position() + offset, start);
|
2012-07-11 07:32:16 +00:00
|
|
|
QCOMPARE(window->rootObject()->property("currentA").toInt(), 0);
|
|
|
|
QCOMPARE(window->rootObject()->property("currentB").toInt(), 0);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
pathview->setCurrentIndex(2);
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
firstItem = findItem<QQuickRectangle>(pathview, "wrapper", 2);
|
2012-10-22 14:59:25 +00:00
|
|
|
QTRY_COMPARE(firstItem->position() + offset, start);
|
2012-07-11 07:32:16 +00:00
|
|
|
QCOMPARE(window->rootObject()->property("currentA").toInt(), 2);
|
|
|
|
QCOMPARE(window->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);
|
2012-10-22 14:59:25 +00:00
|
|
|
QTRY_COMPARE(firstItem->position() + 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);
|
2012-10-22 14:59:25 +00:00
|
|
|
QTRY_COMPARE(firstItem->position() + 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);
|
2012-10-22 14:59:25 +00:00
|
|
|
QTRY_COMPARE(firstItem->position() + 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);
|
2012-10-22 14:59:25 +00:00
|
|
|
QTRY_COMPARE(firstItem->position() + offset, start);
|
2011-08-01 03:09:10 +00:00
|
|
|
QCOMPARE(pathview->currentItem(), firstItem);
|
|
|
|
QCOMPARE(firstItem->property("onPath"), QVariant(true));
|
|
|
|
|
2012-05-29 05:45:15 +00:00
|
|
|
// Test positive indexes are wrapped.
|
|
|
|
pathview->setCurrentIndex(6);
|
|
|
|
QTRY_COMPARE(pathview->currentIndex(), 2);
|
|
|
|
firstItem = findItem<QQuickRectangle>(pathview, "wrapper", 2);
|
|
|
|
QVERIFY(firstItem);
|
2012-10-22 14:59:25 +00:00
|
|
|
QTRY_COMPARE(firstItem->position() + offset, start);
|
2012-05-29 05:45:15 +00:00
|
|
|
QCOMPARE(pathview->currentItem(), firstItem);
|
|
|
|
QCOMPARE(firstItem->property("onPath"), QVariant(true));
|
|
|
|
|
|
|
|
// Test negative indexes are wrapped.
|
|
|
|
pathview->setCurrentIndex(-3);
|
|
|
|
QTRY_COMPARE(pathview->currentIndex(), 1);
|
|
|
|
firstItem = findItem<QQuickRectangle>(pathview, "wrapper", 1);
|
|
|
|
QVERIFY(firstItem);
|
2012-10-22 14:59:25 +00:00
|
|
|
QTRY_COMPARE(firstItem->position() + offset, start);
|
2012-05-29 05:45:15 +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);
|
2012-10-22 14:59:25 +00:00
|
|
|
QTRY_COMPARE(firstItem->position() + offset, start);
|
2011-11-21 23:28:40 +00:00
|
|
|
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
|
|
|
|
2015-10-21 15:04:16 +00:00
|
|
|
// check for bogus currentIndexChanged() signals
|
|
|
|
QSignalSpy currentIndexSpy(pathview, SIGNAL(currentIndexChanged()));
|
|
|
|
QVERIFY(currentIndexSpy.isValid());
|
|
|
|
pathview->setHighlightMoveDuration(100);
|
|
|
|
pathview->setHighlightRangeMode(QQuickPathView::StrictlyEnforceRange);
|
|
|
|
pathview->setSnapMode(QQuickPathView::SnapToItem);
|
|
|
|
pathview->setCurrentIndex(3);
|
|
|
|
QTRY_COMPARE(pathview->currentIndex(), 3);
|
|
|
|
QCOMPARE(currentIndexSpy.count(), 1);
|
2011-04-27 12:13:26 +00:00
|
|
|
}
|
|
|
|
|
2019-03-21 13:36:57 +00:00
|
|
|
void tst_QQuickPathView::setCurrentIndexWrap()
|
|
|
|
{
|
|
|
|
QScopedPointer<QQuickView> window(createView());
|
|
|
|
window->setSource(testFileUrl("pathview5.qml"));
|
|
|
|
window->show();
|
|
|
|
qApp->processEvents();
|
|
|
|
|
|
|
|
QQuickPathView *pathview = qobject_cast<QQuickPathView*>(window->rootObject());
|
|
|
|
QVERIFY(pathview);
|
|
|
|
|
|
|
|
// set current index to last item
|
|
|
|
pathview->setCurrentIndex(4);
|
|
|
|
// set currentIndex to first item, then quickly set it back (QTBUG-74508)
|
|
|
|
QSignalSpy currentIndexSpy(pathview, SIGNAL(currentIndexChanged()));
|
|
|
|
QSignalSpy movementStartedSpy(pathview, SIGNAL(movementStarted()));
|
|
|
|
pathview->setCurrentIndex(0);
|
|
|
|
pathview->setCurrentIndex(4);
|
|
|
|
QCOMPARE(pathview->currentIndex(), 4);
|
|
|
|
QCOMPARE(currentIndexSpy.count(), 2);
|
|
|
|
QCOMPARE(movementStartedSpy.count(), 0);
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickPathView::resetModel()
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
2012-12-05 14:27:47 +00:00
|
|
|
QScopedPointer<QQuickView> window(createView());
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
QStringList strings;
|
|
|
|
strings << "one" << "two" << "three";
|
|
|
|
QStringListModel model(strings);
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQmlContext *ctxt = window->rootContext();
|
2011-04-27 12:13:26 +00:00
|
|
|
ctxt->setContextProperty("testModel", &model);
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
window->setSource(testFileUrl("displaypath.qml"));
|
2011-04-27 12:13:26 +00:00
|
|
|
qApp->processEvents();
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickPathView *pathview = findItem<QQuickPathView>(window->rootObject(), "view");
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(pathview != nullptr);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
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);
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(display != nullptr);
|
2011-04-27 12:13:26 +00:00
|
|
|
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);
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(display != nullptr);
|
2011-04-27 12:13:26 +00:00
|
|
|
QCOMPARE(display->text(), strings.at(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickPathView::propertyChanges()
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
2012-12-05 14:27:47 +00:00
|
|
|
QScopedPointer<QQuickView> window(createView());
|
2012-07-11 07:32:16 +00:00
|
|
|
QVERIFY(window);
|
|
|
|
window->setSource(testFileUrl("propertychanges.qml"));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickPathView *pathView = window->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);
|
2012-03-25 02:37:08 +00:00
|
|
|
|
|
|
|
QSignalSpy maximumFlickVelocitySpy(pathView, SIGNAL(maximumFlickVelocityChanged()));
|
|
|
|
pathView->setMaximumFlickVelocity(1000);
|
|
|
|
QCOMPARE(maximumFlickVelocitySpy.count(), 1);
|
|
|
|
pathView->setMaximumFlickVelocity(1000);
|
|
|
|
QCOMPARE(maximumFlickVelocitySpy.count(), 1);
|
|
|
|
|
2011-04-27 12:13:26 +00:00
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickPathView::pathChanges()
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
2012-12-05 14:27:47 +00:00
|
|
|
QScopedPointer<QQuickView> window(createView());
|
2012-07-11 07:32:16 +00:00
|
|
|
QVERIFY(window);
|
|
|
|
window->setSource(testFileUrl("propertychanges.qml"));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickPathView *pathView = window->rootObject()->findChild<QQuickPathView*>("pathView");
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(pathView);
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickPath *path = window->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-07-11 07:32:16 +00:00
|
|
|
QQuickPath *alternatePath = window->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-07-11 07:32:16 +00:00
|
|
|
QQuickPathAttribute *pathAttribute = window->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);
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickPathView::componentChanges()
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
2012-12-05 14:27:47 +00:00
|
|
|
QScopedPointer<QQuickView> window(createView());
|
2012-07-11 07:32:16 +00:00
|
|
|
QVERIFY(window);
|
|
|
|
window->setSource(testFileUrl("propertychanges.qml"));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickPathView *pathView = window->rootObject()->findChild<QQuickPathView*>("pathView");
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(pathView);
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQmlComponent delegateComponent(window->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);
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickPathView::modelChanges()
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
2012-12-05 14:27:47 +00:00
|
|
|
QScopedPointer<QQuickView> window(createView());
|
2012-07-11 07:32:16 +00:00
|
|
|
QVERIFY(window);
|
|
|
|
window->setSource(testFileUrl("propertychanges.qml"));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickPathView *pathView = window->rootObject()->findChild<QQuickPathView*>("pathView");
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(pathView);
|
2012-07-18 00:36:17 +00:00
|
|
|
pathView->setCurrentIndex(3);
|
|
|
|
QTRY_COMPARE(pathView->offset(), 6.0);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2013-01-10 22:07:37 +00:00
|
|
|
QQmlListModel *alternateModel = window->rootObject()->findChild<QQmlListModel*>("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()));
|
2012-07-18 00:36:17 +00:00
|
|
|
QSignalSpy currentIndexSpy(pathView, SIGNAL(currentIndexChanged()));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2012-07-18 00:36:17 +00:00
|
|
|
QCOMPARE(pathView->currentIndex(), 3);
|
2011-04-27 12:13:26 +00:00
|
|
|
pathView->setModel(modelVariant);
|
|
|
|
QCOMPARE(pathView->model(), modelVariant);
|
|
|
|
QCOMPARE(modelSpy.count(),1);
|
2012-07-18 00:36:17 +00:00
|
|
|
QCOMPARE(pathView->currentIndex(), 0);
|
|
|
|
QCOMPARE(currentIndexSpy.count(), 1);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
pathView->setModel(modelVariant);
|
|
|
|
QCOMPARE(modelSpy.count(),1);
|
|
|
|
|
|
|
|
pathView->setModel(QVariant());
|
|
|
|
QCOMPARE(modelSpy.count(),2);
|
2012-07-18 00:36:17 +00:00
|
|
|
QCOMPARE(pathView->currentIndex(), 0);
|
|
|
|
QCOMPARE(currentIndexSpy.count(), 1);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickPathView::pathUpdateOnStartChanged()
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
2012-12-05 14:27:47 +00:00
|
|
|
QScopedPointer<QQuickView> window(createView());
|
2012-07-11 07:32:16 +00:00
|
|
|
QVERIFY(window);
|
|
|
|
window->setSource(testFileUrl("pathUpdateOnStartChanged.qml"));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickPathView *pathView = window->rootObject()->findChild<QQuickPathView*>("pathView");
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(pathView);
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickPath *path = window->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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickPathView::package()
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
2012-12-05 14:27:47 +00:00
|
|
|
QScopedPointer<QQuickView> window(createView());
|
2012-07-11 07:32:16 +00:00
|
|
|
QVERIFY(window);
|
|
|
|
window->setSource(testFileUrl("pathview_package.qml"));
|
|
|
|
window->show();
|
2012-10-19 16:05:01 +00:00
|
|
|
window->requestActivate();
|
2012-12-05 14:27:47 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowActive(window.data()));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickPathView *pathView = window->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
|
2012-09-06 12:55:54 +00:00
|
|
|
QSKIP("QTBUG-27170 view does not reliably receive polish without a running animation");
|
2012-01-06 04:02:10 +00:00
|
|
|
#endif
|
|
|
|
|
2019-01-22 09:35:09 +00:00
|
|
|
QQuickTest::qWaitForItemPolished(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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//QTBUG-13017
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickPathView::emptyModel()
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
2012-12-05 14:27:47 +00:00
|
|
|
QScopedPointer<QQuickView> window(createView());
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
QStringListModel model;
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQmlContext *ctxt = window->rootContext();
|
2011-04-27 12:13:26 +00:00
|
|
|
ctxt->setContextProperty("emptyModel", &model);
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
window->setSource(testFileUrl("emptymodel.qml"));
|
2011-04-27 12:13:26 +00:00
|
|
|
qApp->processEvents();
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickPathView *pathview = qobject_cast<QQuickPathView*>(window->rootObject());
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(pathview != nullptr);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
QCOMPARE(pathview->offset(), qreal(0.0));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-01-17 09:46:45 +00:00
|
|
|
void tst_QQuickPathView::emptyPath()
|
|
|
|
{
|
|
|
|
QQuickView *window = createView();
|
|
|
|
|
|
|
|
window->setSource(testFileUrl("emptypath.qml"));
|
|
|
|
qApp->processEvents();
|
|
|
|
|
|
|
|
QQuickPathView *pathview = qobject_cast<QQuickPathView*>(window->rootObject());
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(pathview != nullptr);
|
2013-01-17 09:46:45 +00:00
|
|
|
|
|
|
|
delete window;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2012-12-05 14:27:47 +00:00
|
|
|
QScopedPointer<QQuickView> window(createView());
|
2012-07-11 07:32:16 +00:00
|
|
|
QVERIFY(window);
|
|
|
|
window->setSource(testFileUrl("pathUpdate.qml"));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickPathView *pathView = window->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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
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());
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(obj != nullptr);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
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()) {
|
2019-06-03 08:01:26 +00:00
|
|
|
QRegularExpression warning1("^QPainterPath::moveTo:.*ignoring call$");
|
|
|
|
QTest::ignoreMessage(QtWarningMsg, warning1);
|
2011-12-06 02:29:09 +00:00
|
|
|
|
2019-06-03 08:01:26 +00:00
|
|
|
QRegularExpression warning2("^QPainterPath::lineTo:.*ignoring call$");
|
|
|
|
QTest::ignoreMessage(QtWarningMsg, warning2);
|
2012-01-09 02:55:52 +00:00
|
|
|
}
|
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());
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(obj != nullptr);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
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
|
|
|
{
|
2012-12-05 14:27:47 +00:00
|
|
|
QScopedPointer<QQuickView> window(createView());
|
2013-08-23 11:35:00 +00:00
|
|
|
QQuickViewTestUtil::moveMouseAway(window.data());
|
2012-07-11 07:32:16 +00:00
|
|
|
window->setSource(testFileUrl("dragpath.qml"));
|
|
|
|
window->show();
|
2012-10-19 16:05:01 +00:00
|
|
|
window->requestActivate();
|
2012-12-05 14:27:47 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowActive(window.data()));
|
|
|
|
QCOMPARE(window.data(), qGuiApp->focusWindow());
|
2012-07-11 07:32:16 +00:00
|
|
|
|
|
|
|
QQuickPathView *pathview = qobject_cast<QQuickPathView*>(window->rootObject());
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(pathview != nullptr);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2012-07-03 03:57:54 +00:00
|
|
|
QSignalSpy movingSpy(pathview, SIGNAL(movingChanged()));
|
|
|
|
QSignalSpy moveStartedSpy(pathview, SIGNAL(movementStarted()));
|
|
|
|
QSignalSpy moveEndedSpy(pathview, SIGNAL(movementEnded()));
|
|
|
|
QSignalSpy draggingSpy(pathview, SIGNAL(draggingChanged()));
|
|
|
|
QSignalSpy dragStartedSpy(pathview, SIGNAL(dragStarted()));
|
|
|
|
QSignalSpy dragEndedSpy(pathview, SIGNAL(dragEnded()));
|
|
|
|
|
2011-04-27 12:13:26 +00:00
|
|
|
int current = pathview->currentIndex();
|
|
|
|
|
2018-02-21 09:41:54 +00:00
|
|
|
QTest::mousePress(window.data(), Qt::LeftButton, Qt::NoModifier, QPoint(10,100));
|
2011-10-06 00:10:24 +00:00
|
|
|
QTest::qWait(100);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
{
|
2015-01-09 09:53:12 +00:00
|
|
|
QMouseEvent mv(QEvent::MouseMove, QPoint(50,100), Qt::LeftButton, Qt::LeftButton,Qt::NoModifier);
|
2012-12-05 14:27:47 +00:00
|
|
|
QGuiApplication::sendEvent(window.data(), &mv);
|
2011-04-27 12:13:26 +00:00
|
|
|
}
|
2012-05-14 02:49:52 +00:00
|
|
|
// first move beyond threshold does not trigger drag
|
|
|
|
QVERIFY(!pathview->isMoving());
|
2012-07-03 03:57:54 +00:00
|
|
|
QVERIFY(!pathview->isDragging());
|
|
|
|
QCOMPARE(movingSpy.count(), 0);
|
|
|
|
QCOMPARE(moveStartedSpy.count(), 0);
|
|
|
|
QCOMPARE(moveEndedSpy.count(), 0);
|
|
|
|
QCOMPARE(draggingSpy.count(), 0);
|
|
|
|
QCOMPARE(dragStartedSpy.count(), 0);
|
|
|
|
QCOMPARE(dragEndedSpy.count(), 0);
|
2012-05-14 02:49:52 +00:00
|
|
|
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
|
|
|
QMouseEvent mv(QEvent::MouseMove, QPoint(90,100), Qt::LeftButton, Qt::LeftButton,Qt::NoModifier);
|
2012-12-05 14:27:47 +00:00
|
|
|
QGuiApplication::sendEvent(window.data(), &mv);
|
2011-04-27 12:13:26 +00:00
|
|
|
}
|
2012-05-14 02:49:52 +00:00
|
|
|
// next move beyond threshold does trigger drag
|
2015-02-26 15:20:43 +00:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
if (!pathview->isMoving())
|
|
|
|
QSKIP("Skipping due to interference from external mouse move events.");
|
|
|
|
#endif // Q_OS_WIN
|
2012-05-14 02:49:52 +00:00
|
|
|
QVERIFY(pathview->isMoving());
|
2012-07-03 03:57:54 +00:00
|
|
|
QVERIFY(pathview->isDragging());
|
|
|
|
QCOMPARE(movingSpy.count(), 1);
|
|
|
|
QCOMPARE(moveStartedSpy.count(), 1);
|
|
|
|
QCOMPARE(moveEndedSpy.count(), 0);
|
|
|
|
QCOMPARE(draggingSpy.count(), 1);
|
|
|
|
QCOMPARE(dragStartedSpy.count(), 1);
|
|
|
|
QCOMPARE(dragEndedSpy.count(), 0);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
QVERIFY(pathview->currentIndex() != current);
|
|
|
|
|
2018-02-21 09:41:54 +00:00
|
|
|
QTest::mouseRelease(window.data(), Qt::LeftButton, Qt::NoModifier, QPoint(40,100));
|
2012-07-03 03:57:54 +00:00
|
|
|
QVERIFY(!pathview->isDragging());
|
|
|
|
QCOMPARE(draggingSpy.count(), 2);
|
|
|
|
QCOMPARE(dragStartedSpy.count(), 1);
|
|
|
|
QCOMPARE(dragEndedSpy.count(), 1);
|
|
|
|
QTRY_COMPARE(movingSpy.count(), 2);
|
|
|
|
QTRY_COMPARE(moveEndedSpy.count(), 1);
|
|
|
|
QCOMPARE(moveStartedSpy.count(), 1);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-09-27 04:26:48 +00:00
|
|
|
void tst_QQuickPathView::nestedMouseAreaDrag()
|
|
|
|
{
|
|
|
|
QScopedPointer<QQuickView> window(createView());
|
|
|
|
QQuickViewTestUtil::moveMouseAway(window.data());
|
|
|
|
window->setSource(testFileUrl("nestedmousearea.qml"));
|
|
|
|
window->show();
|
|
|
|
window->requestActivate();
|
|
|
|
QVERIFY(QTest::qWaitForWindowActive(window.data()));
|
|
|
|
QCOMPARE(window.data(), qGuiApp->focusWindow());
|
|
|
|
|
|
|
|
|
|
|
|
QQuickPathView *pathview = qobject_cast<QQuickPathView*>(window->rootObject());
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(pathview != nullptr);
|
2013-09-27 04:26:48 +00:00
|
|
|
|
|
|
|
// Dragging the child mouse area should move it and not animate the PathView
|
2015-01-09 09:53:12 +00:00
|
|
|
flick(window.data(), QPoint(200,200), QPoint(400,200), 200);
|
2013-09-27 04:26:48 +00:00
|
|
|
QVERIFY(!pathview->isMoving());
|
|
|
|
|
|
|
|
// Dragging outside the mouse are should animate the PathView.
|
|
|
|
flick(window.data(), QPoint(75,75), QPoint(175,75), 200);
|
|
|
|
QVERIFY(pathview->isMoving());
|
|
|
|
}
|
|
|
|
|
2019-09-05 11:57:19 +00:00
|
|
|
void tst_QQuickPathView::flickNClick() // QTBUG-77173
|
|
|
|
{
|
|
|
|
QScopedPointer<QQuickView> window(createView());
|
|
|
|
QQuickViewTestUtil::moveMouseAway(window.data());
|
|
|
|
window->setSource(testFileUrl("nestedmousearea2.qml"));
|
|
|
|
window->show();
|
|
|
|
window->requestActivate();
|
|
|
|
QVERIFY(QTest::qWaitForWindowActive(window.data()));
|
|
|
|
QCOMPARE(window.data(), qGuiApp->focusWindow());
|
|
|
|
|
|
|
|
QQuickPathView *pathview = qobject_cast<QQuickPathView*>(window->rootObject());
|
|
|
|
QVERIFY(pathview != nullptr);
|
2019-10-09 06:25:17 +00:00
|
|
|
QSignalSpy movingChangedSpy(pathview, SIGNAL(movingChanged()));
|
|
|
|
QSignalSpy draggingSpy(pathview, SIGNAL(draggingChanged()));
|
|
|
|
QSignalSpy dragStartedSpy(pathview, SIGNAL(dragStarted()));
|
|
|
|
QSignalSpy dragEndedSpy(pathview, SIGNAL(dragEnded()));
|
|
|
|
QSignalSpy currentIndexSpy(pathview, SIGNAL(currentIndexChanged()));
|
|
|
|
QSignalSpy moveStartedSpy(pathview, SIGNAL(movementStarted()));
|
|
|
|
QSignalSpy moveEndedSpy(pathview, SIGNAL(movementEnded()));
|
|
|
|
QSignalSpy flickingSpy(pathview, SIGNAL(flickingChanged()));
|
|
|
|
QSignalSpy flickStartedSpy(pathview, SIGNAL(flickStarted()));
|
|
|
|
QSignalSpy flickEndedSpy(pathview, SIGNAL(flickEnded()));
|
2019-09-05 11:57:19 +00:00
|
|
|
|
|
|
|
for (int duration = 100; duration > 0; duration -= 20) {
|
2019-10-09 06:25:17 +00:00
|
|
|
movingChangedSpy.clear();
|
|
|
|
draggingSpy.clear();
|
|
|
|
dragStartedSpy.clear();
|
|
|
|
dragEndedSpy.clear();
|
|
|
|
currentIndexSpy.clear();
|
|
|
|
moveStartedSpy.clear();
|
|
|
|
moveEndedSpy.clear();
|
|
|
|
flickingSpy.clear();
|
|
|
|
flickStartedSpy.clear();
|
|
|
|
flickEndedSpy.clear();
|
2019-09-05 11:57:19 +00:00
|
|
|
// Dragging the child mouse area should animate the PathView (MA has no drag target)
|
|
|
|
flick(window.data(), QPoint(200,200), QPoint(400,200), duration);
|
|
|
|
QVERIFY(pathview->isMoving());
|
2019-10-09 06:25:17 +00:00
|
|
|
QCOMPARE(movingChangedSpy.count(), 1);
|
|
|
|
QCOMPARE(draggingSpy.count(), 2);
|
|
|
|
QCOMPARE(dragStartedSpy.count(), 1);
|
|
|
|
QCOMPARE(dragEndedSpy.count(), 1);
|
|
|
|
QVERIFY(currentIndexSpy.count() > 0);
|
|
|
|
QCOMPARE(moveStartedSpy.count(), 1);
|
|
|
|
QCOMPARE(moveEndedSpy.count(), 0);
|
|
|
|
QCOMPARE(flickingSpy.count(), 1);
|
|
|
|
QCOMPARE(flickStartedSpy.count(), 1);
|
|
|
|
QCOMPARE(flickEndedSpy.count(), 0);
|
2019-09-05 11:57:19 +00:00
|
|
|
|
|
|
|
// Now while it's still moving, click it.
|
|
|
|
// The PathView should stop at a position such that offset is a whole number.
|
|
|
|
QTest::mouseClick(window.data(), Qt::LeftButton, Qt::NoModifier, QPoint(200, 200));
|
|
|
|
QTRY_VERIFY(!pathview->isMoving());
|
2019-10-09 06:25:17 +00:00
|
|
|
QCOMPARE(movingChangedSpy.count(), 2); // QTBUG-78926
|
|
|
|
QCOMPARE(draggingSpy.count(), 2);
|
|
|
|
QCOMPARE(dragStartedSpy.count(), 1);
|
|
|
|
QCOMPARE(dragEndedSpy.count(), 1);
|
|
|
|
QCOMPARE(moveStartedSpy.count(), 1);
|
|
|
|
QCOMPARE(moveEndedSpy.count(), 1);
|
|
|
|
QCOMPARE(flickingSpy.count(), 2);
|
|
|
|
QCOMPARE(flickStartedSpy.count(), 1);
|
|
|
|
QCOMPARE(flickEndedSpy.count(), 1);
|
2019-09-05 11:57:19 +00:00
|
|
|
QVERIFY(qFuzzyIsNull(pathview->offset() - int(pathview->offset())));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickPathView::treeModel()
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
|
|
|
QStandardItemModel model;
|
|
|
|
initStandardTreeModel(&model);
|
2020-06-10 11:10:16 +00:00
|
|
|
qmlRegisterSingletonInstance("Qt.treemodel", 1, 0, "TreeModelCpp", &model);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2020-06-10 11:10:16 +00:00
|
|
|
QScopedPointer<QQuickView> window(createView());
|
|
|
|
window->show();
|
2012-07-11 07:32:16 +00:00
|
|
|
window->setSource(testFileUrl("treemodel.qml"));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickPathView *pathview = qobject_cast<QQuickPathView*>(window->rootObject());
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(pathview != nullptr);
|
2011-04-27 12:13:26 +00:00
|
|
|
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"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickPathView::changePreferredHighlight()
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
2012-12-05 14:27:47 +00:00
|
|
|
QScopedPointer<QQuickView> window(createView());
|
2012-07-11 07:32:16 +00:00
|
|
|
window->setGeometry(0,0,400,200);
|
|
|
|
window->setSource(testFileUrl("dragpath.qml"));
|
|
|
|
window->show();
|
2012-10-19 16:05:01 +00:00
|
|
|
window->requestActivate();
|
2012-12-05 14:27:47 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowActive(window.data()));
|
|
|
|
QCOMPARE(window.data(), qGuiApp->focusWindow());
|
2012-07-11 07:32:16 +00:00
|
|
|
|
|
|
|
QQuickPathView *pathview = qobject_cast<QQuickPathView*>(window->rootObject());
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(pathview != nullptr);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
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);
|
2019-05-27 21:36:31 +00:00
|
|
|
QPointF start = path->pointAtPercent(0.5);
|
2011-04-27 12:13:26 +00:00
|
|
|
QPointF offset;//Center of item is at point, but pos is from corner
|
|
|
|
offset.setX(firstItem->width()/2);
|
|
|
|
offset.setY(firstItem->height()/2);
|
2012-10-22 14:59:25 +00:00
|
|
|
QTRY_COMPARE(firstItem->position() + offset, start);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
pathview->setPreferredHighlightBegin(0.8);
|
|
|
|
pathview->setPreferredHighlightEnd(0.8);
|
2019-05-27 21:36:31 +00:00
|
|
|
start = path->pointAtPercent(0.8);
|
2012-10-22 14:59:25 +00:00
|
|
|
QTRY_COMPARE(firstItem->position() + offset, start);
|
2011-04-27 12:13:26 +00:00
|
|
|
QCOMPARE(pathview->currentIndex(), 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickPathView::creationContext()
|
2011-10-07 03:06:26 +00:00
|
|
|
{
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickView window;
|
|
|
|
window.setGeometry(0,0,240,320);
|
|
|
|
window.setSource(testFileUrl("creationContext.qml"));
|
2011-10-07 03:06:26 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickItem *rootItem = qobject_cast<QQuickItem *>(window.rootObject());
|
2011-10-07 03:06:26 +00:00
|
|
|
QVERIFY(rootItem);
|
|
|
|
QVERIFY(rootItem->property("count").toInt() > 0);
|
|
|
|
|
2016-11-30 09:29:06 +00:00
|
|
|
QQuickItem *item = findItem<QQuickItem>(rootItem, "listItem", 0);
|
|
|
|
QVERIFY(item);
|
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()
|
|
|
|
{
|
2012-12-05 14:27:47 +00:00
|
|
|
QScopedPointer<QQuickView> window(createView());
|
2012-07-11 07:32:16 +00:00
|
|
|
window->show();
|
2011-11-09 05:34:01 +00:00
|
|
|
|
2012-01-31 07:15:00 +00:00
|
|
|
QaimModel model;
|
2011-11-09 05:34:01 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQmlContext *ctxt = window->rootContext();
|
2011-11-09 05:34:01 +00:00
|
|
|
ctxt->setContextProperty("testModel", &model);
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
window->setSource(testFileUrl("pathline.qml"));
|
2011-11-09 05:34:01 +00:00
|
|
|
qApp->processEvents();
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickPathView *pathview = findItem<QQuickPathView>(window->rootObject(), "view");
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(pathview != nullptr);
|
2011-11-09 05:34:01 +00:00
|
|
|
|
|
|
|
pathview->setPreferredHighlightBegin(0.5);
|
|
|
|
pathview->setPreferredHighlightEnd(0.5);
|
|
|
|
|
|
|
|
QCOMPARE(pathview->count(), model.count());
|
|
|
|
|
|
|
|
model.addItem("item0", "0");
|
|
|
|
|
|
|
|
QCOMPARE(pathview->count(), model.count());
|
|
|
|
|
2018-02-21 09:41:54 +00:00
|
|
|
QQuickRectangle *item = nullptr;
|
2011-11-09 05:34:01 +00:00
|
|
|
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);
|
|
|
|
|
2019-05-27 21:36:31 +00:00
|
|
|
QPointF start = path->pointAtPercent(0.5);
|
2011-11-09 05:34:01 +00:00
|
|
|
QPointF offset;//Center of item is at point, but pos is from corner
|
|
|
|
offset.setX(item->width()/2);
|
|
|
|
offset.setY(item->height()/2);
|
2012-10-22 14:59:25 +00:00
|
|
|
QCOMPARE(item->position() + offset, start);
|
2011-11-09 05:34:01 +00:00
|
|
|
|
|
|
|
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
|
2016-11-30 09:29:06 +00:00
|
|
|
item = findItem<QQuickRectangle>(pathview, "wrapper", 1);
|
|
|
|
QVERIFY(item);
|
2011-11-09 05:34:01 +00:00
|
|
|
|
|
|
|
// verify that current item (item 1) is still at offset 0.5
|
2012-10-22 14:59:25 +00:00
|
|
|
QCOMPARE(item->position() + offset, start);
|
2011-11-09 05:34:01 +00:00
|
|
|
|
|
|
|
// insert another item at the beginning
|
|
|
|
model.insertItem(0, "item2", "2");
|
|
|
|
qApp->processEvents();
|
|
|
|
|
|
|
|
QCOMPARE(currentIndexSpy.count(), 2);
|
|
|
|
|
|
|
|
// currentIndex is now 2
|
2016-11-30 09:29:06 +00:00
|
|
|
item = findItem<QQuickRectangle>(pathview, "wrapper", 2);
|
|
|
|
QVERIFY(item);
|
2011-11-09 05:34:01 +00:00
|
|
|
|
|
|
|
// verify that current item (item 2) is still at offset 0.5
|
2012-10-22 14:59:25 +00:00
|
|
|
QCOMPARE(item->position() + offset, start);
|
2011-11-09 05:34:01 +00:00
|
|
|
|
|
|
|
// verify that remove before current maintains current item
|
|
|
|
model.removeItem(0);
|
|
|
|
qApp->processEvents();
|
|
|
|
|
|
|
|
QCOMPARE(currentIndexSpy.count(), 3);
|
|
|
|
|
|
|
|
// currentIndex is now 1
|
2016-11-30 09:29:06 +00:00
|
|
|
item = findItem<QQuickRectangle>(pathview, "wrapper", 1);
|
|
|
|
QVERIFY(item);
|
2011-11-09 05:34:01 +00:00
|
|
|
|
|
|
|
// verify that current item (item 1) is still at offset 0.5
|
2012-10-22 14:59:25 +00:00
|
|
|
QCOMPARE(item->position() + offset, start);
|
2011-11-09 05:34:01 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-11-03 05:52:13 +00:00
|
|
|
void tst_QQuickPathView::asynchronous()
|
|
|
|
{
|
2012-12-05 14:27:47 +00:00
|
|
|
QScopedPointer<QQuickView> window(createView());
|
2012-07-11 07:32:16 +00:00
|
|
|
window->show();
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlIncubationController controller;
|
2012-07-11 07:32:16 +00:00
|
|
|
window->engine()->setIncubationController(&controller);
|
2011-11-03 05:52:13 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
window->setSource(testFileUrl("asyncloader.qml"));
|
2011-11-03 05:52:13 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickItem *rootObject = qobject_cast<QQuickItem*>(window->rootObject());
|
2011-11-03 05:52:13 +00:00
|
|
|
QVERIFY(rootObject);
|
|
|
|
|
2018-02-21 09:41:54 +00:00
|
|
|
QQuickPathView *pathview = nullptr;
|
2011-11-03 05:52:13 +00:00
|
|
|
while (!pathview) {
|
2020-05-13 09:11:23 +00:00
|
|
|
std::atomic<bool> b = false;
|
2011-11-03 05:52:13 +00:00
|
|
|
controller.incubateWhile(&b);
|
|
|
|
pathview = rootObject->findChild<QQuickPathView*>("view");
|
|
|
|
}
|
|
|
|
|
|
|
|
// items will be created one at a time
|
|
|
|
for (int i = 0; i < 5; ++i) {
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(findItem<QQuickItem>(pathview, "wrapper", i) == nullptr);
|
|
|
|
QQuickItem *item = nullptr;
|
2011-11-03 05:52:13 +00:00
|
|
|
while (!item) {
|
2020-05-13 09:11:23 +00:00
|
|
|
std::atomic<bool> b = false;
|
2011-11-03 05:52:13 +00:00
|
|
|
controller.incubateWhile(&b);
|
|
|
|
item = findItem<QQuickItem>(pathview, "wrapper", i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2020-05-13 09:11:23 +00:00
|
|
|
std::atomic<bool> b = true;
|
2011-11-03 05:52:13 +00:00
|
|
|
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);
|
2019-05-27 21:36:31 +00:00
|
|
|
QPointF start = path->pointAtPercent(0.0);
|
2011-11-03 05:52:13 +00:00
|
|
|
QPointF offset;//Center of item is at point, but pos is from corner
|
|
|
|
offset.setX(firstItem->width()/2);
|
|
|
|
offset.setY(firstItem->height()/2);
|
2012-10-22 14:59:25 +00:00
|
|
|
QTRY_COMPARE(firstItem->position() + offset, start);
|
2011-11-03 05:52:13 +00:00
|
|
|
pathview->setOffset(1.0);
|
|
|
|
|
|
|
|
for (int i=0; i<5; i++) {
|
|
|
|
QQuickItem *curItem = findItem<QQuickItem>(pathview, "wrapper", i);
|
2019-05-27 21:36:31 +00:00
|
|
|
QPointF itemPos(path->pointAtPercent(0.2 + i*0.2));
|
2012-10-22 14:59:25 +00:00
|
|
|
QCOMPARE(curItem->position() + offset, itemPos);
|
2011-11-03 05:52:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-07-29 12:46:37 +00:00
|
|
|
static inline bool hasFraction(qreal o)
|
|
|
|
{
|
|
|
|
const bool result = o != qFloor(o);
|
|
|
|
if (!result)
|
|
|
|
qDebug() << "o != qFloor(o)" << o;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-03-15 04:58:03 +00:00
|
|
|
void tst_QQuickPathView::cancelDrag()
|
|
|
|
{
|
2012-12-05 14:27:47 +00:00
|
|
|
QScopedPointer<QQuickView> window(createView());
|
2012-07-11 07:32:16 +00:00
|
|
|
window->setSource(testFileUrl("dragpath.qml"));
|
2013-08-30 08:01:15 +00:00
|
|
|
QQuickViewTestUtil::moveMouseAway(window.data());
|
2012-07-11 07:32:16 +00:00
|
|
|
window->show();
|
2012-10-19 16:05:01 +00:00
|
|
|
window->requestActivate();
|
2012-12-05 14:27:47 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowActive(window.data()));
|
|
|
|
QCOMPARE(window.data(), qGuiApp->focusWindow());
|
2012-07-11 07:32:16 +00:00
|
|
|
|
|
|
|
QQuickPathView *pathview = qobject_cast<QQuickPathView*>(window->rootObject());
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(pathview != nullptr);
|
2012-03-15 04:58:03 +00:00
|
|
|
|
2012-07-03 03:57:54 +00:00
|
|
|
QSignalSpy draggingSpy(pathview, SIGNAL(draggingChanged()));
|
|
|
|
QSignalSpy dragStartedSpy(pathview, SIGNAL(dragStarted()));
|
|
|
|
QSignalSpy dragEndedSpy(pathview, SIGNAL(dragEnded()));
|
|
|
|
|
2012-03-15 04:58:03 +00:00
|
|
|
// drag between snap points
|
2018-02-21 09:41:54 +00:00
|
|
|
QTest::mousePress(window.data(), Qt::LeftButton, Qt::NoModifier, QPoint(10,100));
|
2012-03-15 04:58:03 +00:00
|
|
|
QTest::qWait(100);
|
2015-01-09 09:53:12 +00:00
|
|
|
QTest::mouseMove(window.data(), QPoint(80, 100));
|
|
|
|
QTest::mouseMove(window.data(), QPoint(130, 100));
|
2012-03-15 04:58:03 +00:00
|
|
|
|
2013-07-29 12:46:37 +00:00
|
|
|
QTRY_VERIFY(hasFraction(pathview->offset()));
|
2012-03-15 04:58:03 +00:00
|
|
|
QTRY_VERIFY(pathview->isMoving());
|
2012-07-03 03:57:54 +00:00
|
|
|
QVERIFY(pathview->isDragging());
|
|
|
|
QCOMPARE(draggingSpy.count(), 1);
|
|
|
|
QCOMPARE(dragStartedSpy.count(), 1);
|
|
|
|
QCOMPARE(dragEndedSpy.count(), 0);
|
2012-03-15 04:58:03 +00:00
|
|
|
|
|
|
|
// steal mouse grab - cancels PathView dragging
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickItem *item = window->rootObject()->findChild<QQuickItem*>("text");
|
2012-03-15 04:58:03 +00:00
|
|
|
item->grabMouse();
|
|
|
|
|
|
|
|
// returns to a snap point.
|
2015-07-24 13:32:22 +00:00
|
|
|
QTRY_COMPARE(pathview->offset(), qreal(qFloor(pathview->offset())));
|
2012-03-15 04:58:03 +00:00
|
|
|
QTRY_VERIFY(!pathview->isMoving());
|
2012-07-03 03:57:54 +00:00
|
|
|
QVERIFY(!pathview->isDragging());
|
|
|
|
QCOMPARE(draggingSpy.count(), 2);
|
|
|
|
QCOMPARE(dragStartedSpy.count(), 1);
|
|
|
|
QCOMPARE(dragEndedSpy.count(), 1);
|
2012-03-15 04:58:03 +00:00
|
|
|
|
2018-02-21 09:41:54 +00:00
|
|
|
QTest::mouseRelease(window.data(), Qt::LeftButton, Qt::NoModifier, QPoint(40,100));
|
2012-03-15 04:58:03 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-03-25 02:37:08 +00:00
|
|
|
void tst_QQuickPathView::maximumFlickVelocity()
|
|
|
|
{
|
2012-12-05 14:27:47 +00:00
|
|
|
QScopedPointer<QQuickView> window(createView());
|
2012-07-11 07:32:16 +00:00
|
|
|
window->setSource(testFileUrl("dragpath.qml"));
|
2013-08-23 11:35:00 +00:00
|
|
|
QQuickViewTestUtil::moveMouseAway(window.data());
|
2012-07-11 07:32:16 +00:00
|
|
|
window->show();
|
2012-10-19 16:05:01 +00:00
|
|
|
window->requestActivate();
|
2012-12-05 14:27:47 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowActive(window.data()));
|
|
|
|
QCOMPARE(window.data(), qGuiApp->focusWindow());
|
2012-07-11 07:32:16 +00:00
|
|
|
|
|
|
|
QQuickPathView *pathview = qobject_cast<QQuickPathView*>(window->rootObject());
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(pathview != nullptr);
|
2012-03-25 02:37:08 +00:00
|
|
|
|
|
|
|
pathview->setMaximumFlickVelocity(700);
|
2012-12-05 14:27:47 +00:00
|
|
|
flick(window.data(), QPoint(200,10), QPoint(10,10), 180);
|
2012-03-25 02:37:08 +00:00
|
|
|
QVERIFY(pathview->isMoving());
|
|
|
|
QVERIFY(pathview->isFlicking());
|
2012-12-05 20:57:45 +00:00
|
|
|
QTRY_VERIFY_WITH_TIMEOUT(!pathview->isMoving(), 50000);
|
2012-03-25 02:37:08 +00:00
|
|
|
|
|
|
|
double dist1 = 100 - pathview->offset();
|
|
|
|
|
|
|
|
pathview->setOffset(0.);
|
|
|
|
pathview->setMaximumFlickVelocity(300);
|
2012-12-05 14:27:47 +00:00
|
|
|
flick(window.data(), QPoint(200,10), QPoint(10,10), 180);
|
2012-03-25 02:37:08 +00:00
|
|
|
QVERIFY(pathview->isMoving());
|
|
|
|
QVERIFY(pathview->isFlicking());
|
2012-12-05 20:57:45 +00:00
|
|
|
QTRY_VERIFY_WITH_TIMEOUT(!pathview->isMoving(), 50000);
|
2012-03-25 02:37:08 +00:00
|
|
|
|
|
|
|
double dist2 = 100 - pathview->offset();
|
|
|
|
|
|
|
|
pathview->setOffset(0.);
|
|
|
|
pathview->setMaximumFlickVelocity(500);
|
2012-12-05 14:27:47 +00:00
|
|
|
flick(window.data(), QPoint(200,10), QPoint(10,10), 180);
|
2012-03-25 02:37:08 +00:00
|
|
|
QVERIFY(pathview->isMoving());
|
|
|
|
QVERIFY(pathview->isFlicking());
|
2012-12-05 20:57:45 +00:00
|
|
|
QTRY_VERIFY_WITH_TIMEOUT(!pathview->isMoving(), 50000);
|
2012-03-25 02:37:08 +00:00
|
|
|
|
|
|
|
double dist3 = 100 - pathview->offset();
|
|
|
|
|
|
|
|
QVERIFY(dist1 > dist2);
|
|
|
|
QVERIFY(dist3 > dist2);
|
|
|
|
QVERIFY(dist2 < dist1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-03-21 03:18:05 +00:00
|
|
|
void tst_QQuickPathView::snapToItem()
|
|
|
|
{
|
|
|
|
QFETCH(bool, enforceRange);
|
|
|
|
|
2012-12-05 14:27:47 +00:00
|
|
|
QScopedPointer<QQuickView> window(createView());
|
2013-08-23 11:35:00 +00:00
|
|
|
QQuickViewTestUtil::moveMouseAway(window.data());
|
2012-07-11 07:32:16 +00:00
|
|
|
window->setSource(testFileUrl("panels.qml"));
|
2014-02-25 11:57:45 +00:00
|
|
|
window->show();
|
|
|
|
window->requestActivate();
|
|
|
|
QVERIFY(QTest::qWaitForWindowActive(window.data()));
|
|
|
|
QCOMPARE(window.data(), qGuiApp->focusWindow());
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickPathView *pathview = window->rootObject()->findChild<QQuickPathView*>("view");
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(pathview != nullptr);
|
2012-03-21 03:18:05 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
window->rootObject()->setProperty("enforceRange", enforceRange);
|
2012-03-21 03:18:05 +00:00
|
|
|
QTRY_VERIFY(!pathview->isMoving()); // ensure stable
|
|
|
|
|
|
|
|
int currentIndex = pathview->currentIndex();
|
|
|
|
|
|
|
|
QSignalSpy snapModeSpy(pathview, SIGNAL(snapModeChanged()));
|
|
|
|
|
2012-12-05 14:27:47 +00:00
|
|
|
flick(window.data(), QPoint(200,10), QPoint(10,10), 180);
|
2012-03-21 03:18:05 +00:00
|
|
|
|
|
|
|
QVERIFY(pathview->isMoving());
|
2013-03-19 12:11:27 +00:00
|
|
|
QTRY_VERIFY_WITH_TIMEOUT(!pathview->isMoving(), 50000);
|
2012-03-21 03:18:05 +00:00
|
|
|
|
2015-07-24 13:32:22 +00:00
|
|
|
QCOMPARE(pathview->offset(), qreal(qFloor(pathview->offset())));
|
2012-03-21 03:18:05 +00:00
|
|
|
|
|
|
|
if (enforceRange)
|
|
|
|
QVERIFY(pathview->currentIndex() != currentIndex);
|
|
|
|
else
|
2013-12-18 11:07:38 +00:00
|
|
|
QCOMPARE(pathview->currentIndex(), currentIndex);
|
2012-07-18 00:36:17 +00:00
|
|
|
|
2012-03-21 03:18:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QQuickPathView::snapToItem_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<bool>("enforceRange");
|
|
|
|
|
|
|
|
QTest::newRow("no enforce range") << false;
|
|
|
|
QTest::newRow("enforce range") << true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QQuickPathView::snapOneItem()
|
|
|
|
{
|
|
|
|
QFETCH(bool, enforceRange);
|
|
|
|
|
2012-12-05 14:27:47 +00:00
|
|
|
QScopedPointer<QQuickView> window(createView());
|
2013-08-23 11:35:00 +00:00
|
|
|
QQuickViewTestUtil::moveMouseAway(window.data());
|
2012-07-11 07:32:16 +00:00
|
|
|
window->setSource(testFileUrl("panels.qml"));
|
|
|
|
window->show();
|
2012-10-19 16:05:01 +00:00
|
|
|
window->requestActivate();
|
2012-12-05 14:27:47 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowActive(window.data()));
|
|
|
|
QCOMPARE(window.data(), qGuiApp->focusWindow());
|
2012-03-21 03:18:05 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickPathView *pathview = window->rootObject()->findChild<QQuickPathView*>("view");
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(pathview != nullptr);
|
2012-03-21 03:18:05 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
window->rootObject()->setProperty("enforceRange", enforceRange);
|
2012-03-21 03:18:05 +00:00
|
|
|
|
|
|
|
QSignalSpy snapModeSpy(pathview, SIGNAL(snapModeChanged()));
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
window->rootObject()->setProperty("snapOne", true);
|
2013-12-18 11:07:38 +00:00
|
|
|
QCOMPARE(snapModeSpy.count(), 1);
|
2012-03-21 03:18:05 +00:00
|
|
|
QTRY_VERIFY(!pathview->isMoving()); // ensure stable
|
|
|
|
|
|
|
|
int currentIndex = pathview->currentIndex();
|
|
|
|
|
|
|
|
double startOffset = pathview->offset();
|
2012-12-05 14:27:47 +00:00
|
|
|
flick(window.data(), QPoint(200,10), QPoint(10,10), 180);
|
2012-03-21 03:18:05 +00:00
|
|
|
|
|
|
|
QVERIFY(pathview->isMoving());
|
|
|
|
QTRY_VERIFY(!pathview->isMoving());
|
|
|
|
|
|
|
|
// must have moved only one item
|
|
|
|
QCOMPARE(pathview->offset(), fmodf(3.0 + startOffset - 1.0, 3.0));
|
|
|
|
|
|
|
|
if (enforceRange)
|
2013-12-18 11:07:38 +00:00
|
|
|
QCOMPARE(pathview->currentIndex(), currentIndex + 1);
|
2012-03-21 03:18:05 +00:00
|
|
|
else
|
2013-12-18 11:07:38 +00:00
|
|
|
QCOMPARE(pathview->currentIndex(), currentIndex);
|
2012-07-18 00:36:17 +00:00
|
|
|
|
2012-03-21 03:18:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QQuickPathView::snapOneItem_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<bool>("enforceRange");
|
|
|
|
|
|
|
|
QTest::newRow("no enforce range") << false;
|
|
|
|
QTest::newRow("enforce range") << true;
|
|
|
|
}
|
2012-03-25 02:37:08 +00:00
|
|
|
|
2012-07-23 01:08:06 +00:00
|
|
|
void tst_QQuickPathView::positionViewAtIndex()
|
|
|
|
{
|
|
|
|
QFETCH(bool, enforceRange);
|
|
|
|
QFETCH(int, pathItemCount);
|
|
|
|
QFETCH(qreal, initOffset);
|
|
|
|
QFETCH(int, index);
|
|
|
|
QFETCH(QQuickPathView::PositionMode, mode);
|
|
|
|
QFETCH(qreal, offset);
|
|
|
|
|
2012-12-05 14:27:47 +00:00
|
|
|
QScopedPointer<QQuickView> window(createView());
|
2012-07-23 01:08:06 +00:00
|
|
|
window->setSource(testFileUrl("pathview3.qml"));
|
|
|
|
window->show();
|
2012-10-19 16:05:01 +00:00
|
|
|
window->requestActivate();
|
2012-12-05 14:27:47 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowActive(window.data()));
|
|
|
|
QCOMPARE(window.data(), qGuiApp->focusWindow());
|
2012-07-23 01:08:06 +00:00
|
|
|
|
|
|
|
QQuickPathView *pathview = qobject_cast<QQuickPathView*>(window->rootObject());
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(pathview != nullptr);
|
2012-07-23 01:08:06 +00:00
|
|
|
|
|
|
|
window->rootObject()->setProperty("enforceRange", enforceRange);
|
|
|
|
if (pathItemCount == -1)
|
|
|
|
pathview->resetPathItemCount();
|
|
|
|
else
|
|
|
|
pathview->setPathItemCount(pathItemCount);
|
|
|
|
pathview->setOffset(initOffset);
|
|
|
|
|
|
|
|
pathview->positionViewAtIndex(index, mode);
|
|
|
|
|
|
|
|
QCOMPARE(pathview->offset(), offset);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QQuickPathView::positionViewAtIndex_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<bool>("enforceRange");
|
|
|
|
QTest::addColumn<int>("pathItemCount");
|
|
|
|
QTest::addColumn<qreal>("initOffset");
|
|
|
|
QTest::addColumn<int>("index");
|
|
|
|
QTest::addColumn<QQuickPathView::PositionMode>("mode");
|
|
|
|
QTest::addColumn<qreal>("offset");
|
|
|
|
|
|
|
|
QTest::newRow("no range, all items, Beginning") << false << -1 << 0.0 << 3 << QQuickPathView::Beginning << 5.0;
|
|
|
|
QTest::newRow("no range, all items, Center") << false << -1 << 0.0 << 3 << QQuickPathView::Center << 1.0;
|
|
|
|
QTest::newRow("no range, all items, End") << false << -1 << 0.0 << 3 << QQuickPathView::End << 5.0;
|
|
|
|
QTest::newRow("no range, 5 items, Beginning") << false << 5 << 0.0 << 3 << QQuickPathView::Beginning << 5.0;
|
|
|
|
QTest::newRow("no range, 5 items, Center") << false << 5 << 0.0 << 3 << QQuickPathView::Center << 7.5;
|
|
|
|
QTest::newRow("no range, 5 items, End") << false << 5 << 0.0 << 3 << QQuickPathView::End << 2.0;
|
|
|
|
QTest::newRow("no range, 5 items, Contain") << false << 5 << 0.0 << 3 << QQuickPathView::Contain << 0.0;
|
|
|
|
QTest::newRow("no range, 5 items, init offset 4.0, Contain") << false << 5 << 4.0 << 3 << QQuickPathView::Contain << 5.0;
|
|
|
|
QTest::newRow("no range, 5 items, init offset 3.0, Contain") << false << 5 << 3.0 << 3 << QQuickPathView::Contain << 2.0;
|
|
|
|
|
|
|
|
QTest::newRow("strict range, all items, Beginning") << true << -1 << 0.0 << 3 << QQuickPathView::Beginning << 1.0;
|
|
|
|
QTest::newRow("strict range, all items, Center") << true << -1 << 0.0 << 3 << QQuickPathView::Center << 5.0;
|
|
|
|
QTest::newRow("strict range, all items, End") << true << -1 << 0.0 << 3 << QQuickPathView::End << 0.0;
|
|
|
|
QTest::newRow("strict range, all items, Contain") << true << -1 << 0.0 << 3 << QQuickPathView::Contain << 0.0;
|
|
|
|
QTest::newRow("strict range, all items, init offset 1.0, Contain") << true << -1 << 1.0 << 3 << QQuickPathView::Contain << 1.0;
|
|
|
|
QTest::newRow("strict range, all items, SnapPosition") << true << -1 << 0.0 << 3 << QQuickPathView::SnapPosition << 5.0;
|
|
|
|
QTest::newRow("strict range, 5 items, Beginning") << true << 5 << 0.0 << 3 << QQuickPathView::Beginning << 3.0;
|
|
|
|
QTest::newRow("strict range, 5 items, Center") << true << 5 << 0.0 << 3 << QQuickPathView::Center << 5.0;
|
|
|
|
QTest::newRow("strict range, 5 items, End") << true << 5 << 0.0 << 3 << QQuickPathView::End << 7.0;
|
|
|
|
QTest::newRow("strict range, 5 items, Contain") << true << 5 << 0.0 << 3 << QQuickPathView::Contain << 7.0;
|
|
|
|
QTest::newRow("strict range, 5 items, init offset 1.0, Contain") << true << 5 << 1.0 << 3 << QQuickPathView::Contain << 7.0;
|
|
|
|
QTest::newRow("strict range, 5 items, init offset 2.0, Contain") << true << 5 << 2.0 << 3 << QQuickPathView::Contain << 3.0;
|
|
|
|
QTest::newRow("strict range, 5 items, SnapPosition") << true << 5 << 0.0 << 3 << QQuickPathView::SnapPosition << 5.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QQuickPathView::indexAt_itemAt()
|
|
|
|
{
|
|
|
|
QFETCH(qreal, x);
|
|
|
|
QFETCH(qreal, y);
|
|
|
|
QFETCH(int, index);
|
|
|
|
|
2012-12-05 14:27:47 +00:00
|
|
|
QScopedPointer<QQuickView> window(createView());
|
2012-07-23 01:08:06 +00:00
|
|
|
window->setSource(testFileUrl("pathview3.qml"));
|
|
|
|
window->show();
|
2012-10-19 16:05:01 +00:00
|
|
|
window->requestActivate();
|
2012-12-05 14:27:47 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowActive(window.data()));
|
|
|
|
QCOMPARE(window.data(), qGuiApp->focusWindow());
|
2012-07-23 01:08:06 +00:00
|
|
|
|
|
|
|
QQuickPathView *pathview = qobject_cast<QQuickPathView*>(window->rootObject());
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(pathview != nullptr);
|
2012-07-23 01:08:06 +00:00
|
|
|
|
2018-02-21 09:41:54 +00:00
|
|
|
QQuickItem *item = nullptr;
|
2012-07-23 01:08:06 +00:00
|
|
|
if (index >= 0) {
|
|
|
|
item = findItem<QQuickItem>(pathview, "wrapper", index);
|
|
|
|
QVERIFY(item);
|
|
|
|
}
|
|
|
|
QCOMPARE(pathview->indexAt(x,y), index);
|
2015-07-24 13:32:22 +00:00
|
|
|
QCOMPARE(pathview->itemAt(x,y), item);
|
2012-07-23 01:08:06 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QQuickPathView::indexAt_itemAt_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<qreal>("x");
|
|
|
|
QTest::addColumn<qreal>("y");
|
|
|
|
QTest::addColumn<int>("index");
|
|
|
|
|
2013-03-07 15:07:35 +00:00
|
|
|
QTest::newRow("Item 0 - 585, 95") << qreal(585.) << qreal(95.) << 0;
|
|
|
|
QTest::newRow("Item 0 - 660, 165") << qreal(660.) << qreal(165.) << 0;
|
|
|
|
QTest::newRow("No Item a - 580, 95") << qreal(580.) << qreal(95.) << -1;
|
|
|
|
QTest::newRow("No Item b - 585, 85") << qreal(585.) << qreal(85.) << -1;
|
|
|
|
QTest::newRow("Item 7 - 360, 200") << qreal(360.) << qreal(200.) << 7;
|
2012-07-23 01:08:06 +00:00
|
|
|
}
|
2012-03-15 04:58:03 +00:00
|
|
|
|
2012-08-21 04:47:48 +00:00
|
|
|
void tst_QQuickPathView::cacheItemCount()
|
|
|
|
{
|
2012-12-05 14:27:47 +00:00
|
|
|
QScopedPointer<QQuickView> window(createView());
|
2012-08-21 04:47:48 +00:00
|
|
|
|
|
|
|
window->setSource(testFileUrl("pathview3.qml"));
|
|
|
|
window->show();
|
|
|
|
qApp->processEvents();
|
|
|
|
|
|
|
|
QQuickPathView *pathview = qobject_cast<QQuickPathView*>(window->rootObject());
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(pathview != nullptr);
|
2012-08-21 04:47:48 +00:00
|
|
|
|
|
|
|
QMetaObject::invokeMethod(pathview, "addColor", Q_ARG(QVariant, QString("orange")));
|
|
|
|
QMetaObject::invokeMethod(pathview, "addColor", Q_ARG(QVariant, QString("lightsteelblue")));
|
|
|
|
QMetaObject::invokeMethod(pathview, "addColor", Q_ARG(QVariant, QString("teal")));
|
|
|
|
QMetaObject::invokeMethod(pathview, "addColor", Q_ARG(QVariant, QString("aqua")));
|
|
|
|
|
|
|
|
pathview->setOffset(0);
|
|
|
|
|
|
|
|
pathview->setCacheItemCount(3);
|
2013-12-18 11:07:38 +00:00
|
|
|
QCOMPARE(pathview->cacheItemCount(), 3);
|
2012-08-21 04:47:48 +00:00
|
|
|
|
|
|
|
QQmlIncubationController controller;
|
|
|
|
window->engine()->setIncubationController(&controller);
|
|
|
|
|
|
|
|
// Items on the path are created immediately
|
|
|
|
QVERIFY(findItem<QQuickItem>(pathview, "wrapper", 0));
|
|
|
|
QVERIFY(findItem<QQuickItem>(pathview, "wrapper", 1));
|
|
|
|
QVERIFY(findItem<QQuickItem>(pathview, "wrapper", 11));
|
|
|
|
QVERIFY(findItem<QQuickItem>(pathview, "wrapper", 10));
|
|
|
|
|
|
|
|
const int cached[] = { 2, 3, 9, -1 }; // two appended, one prepended
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
while (cached[i] >= 0) {
|
|
|
|
// items will be created one at a time
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(findItem<QQuickItem>(pathview, "wrapper", cached[i]) == nullptr);
|
|
|
|
QQuickItem *item = nullptr;
|
2012-08-21 04:47:48 +00:00
|
|
|
while (!item) {
|
2020-05-13 09:11:23 +00:00
|
|
|
std::atomic<bool> b = false;
|
2012-08-21 04:47:48 +00:00
|
|
|
controller.incubateWhile(&b);
|
|
|
|
item = findItem<QQuickItem>(pathview, "wrapper", cached[i]);
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2020-05-13 09:11:23 +00:00
|
|
|
std::atomic<bool> b = true;
|
2012-08-21 04:47:48 +00:00
|
|
|
controller.incubateWhile(&b);
|
|
|
|
}
|
|
|
|
|
|
|
|
// move view and confirm items in view are visible immediately and outside are created async
|
|
|
|
pathview->setOffset(4);
|
|
|
|
|
|
|
|
// Items on the path are created immediately
|
|
|
|
QVERIFY(findItem<QQuickItem>(pathview, "wrapper", 6));
|
|
|
|
QVERIFY(findItem<QQuickItem>(pathview, "wrapper", 7));
|
|
|
|
QVERIFY(findItem<QQuickItem>(pathview, "wrapper", 8));
|
|
|
|
QVERIFY(findItem<QQuickItem>(pathview, "wrapper", 9));
|
|
|
|
// already created items within cache stay created
|
|
|
|
QVERIFY(findItem<QQuickItem>(pathview, "wrapper", 10));
|
|
|
|
QVERIFY(findItem<QQuickItem>(pathview, "wrapper", 11));
|
|
|
|
|
|
|
|
// one item prepended async.
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(findItem<QQuickItem>(pathview, "wrapper", 5) == nullptr);
|
|
|
|
QQuickItem *item = nullptr;
|
2012-08-21 04:47:48 +00:00
|
|
|
while (!item) {
|
2020-05-13 09:11:23 +00:00
|
|
|
std::atomic<bool> b = false;
|
2012-08-21 04:47:48 +00:00
|
|
|
controller.incubateWhile(&b);
|
|
|
|
item = findItem<QQuickItem>(pathview, "wrapper", 5);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2020-05-13 09:11:23 +00:00
|
|
|
std::atomic<bool> b = true;
|
2012-08-21 04:47:48 +00:00
|
|
|
controller.incubateWhile(&b);
|
|
|
|
}
|
2014-07-21 12:55:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void testCurrentIndexChange(QQuickPathView *pathView, const QStringList &objectNamesInOrder)
|
|
|
|
{
|
|
|
|
for (int visualIndex = 0; visualIndex < objectNamesInOrder.size() - 1; ++visualIndex) {
|
|
|
|
QQuickRectangle *delegate = findItem<QQuickRectangle>(pathView, objectNamesInOrder.at(visualIndex));
|
|
|
|
QVERIFY(delegate);
|
|
|
|
|
|
|
|
QQuickRectangle *nextDelegate = findItem<QQuickRectangle>(pathView, objectNamesInOrder.at(visualIndex + 1));
|
|
|
|
QVERIFY(nextDelegate);
|
|
|
|
|
|
|
|
QVERIFY(delegate->y() < nextDelegate->y());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QQuickPathView::changePathDuringRefill()
|
|
|
|
{
|
|
|
|
QScopedPointer<QQuickView> window(createView());
|
|
|
|
|
|
|
|
window->setSource(testFileUrl("changePathDuringRefill.qml"));
|
|
|
|
window->show();
|
|
|
|
QVERIFY(QTest::qWaitForWindowActive(window.data()));
|
|
|
|
QCOMPARE(window.data(), qGuiApp->focusWindow());
|
|
|
|
|
|
|
|
QQuickPathView *pathView = qobject_cast<QQuickPathView*>(window->rootObject());
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(pathView != nullptr);
|
2014-07-21 12:55:30 +00:00
|
|
|
|
|
|
|
testCurrentIndexChange(pathView, QStringList() << "delegateC" << "delegateA" << "delegateB");
|
|
|
|
|
|
|
|
pathView->incrementCurrentIndex();
|
|
|
|
/*
|
|
|
|
Decrementing moves delegateA down, resulting in an offset of 1,
|
|
|
|
so incrementing will move it up, resulting in an offset of 2:
|
2012-08-21 04:47:48 +00:00
|
|
|
|
2014-07-21 12:55:30 +00:00
|
|
|
delegateC delegateA
|
|
|
|
delegateA => delegateB
|
|
|
|
delegateB delegateC
|
|
|
|
*/
|
|
|
|
QTRY_COMPARE(pathView->offset(), 2.0);
|
|
|
|
testCurrentIndexChange(pathView, QStringList() << "delegateA" << "delegateB" << "delegateC");
|
2012-08-21 04:47:48 +00:00
|
|
|
}
|
|
|
|
|
2014-07-23 06:07:31 +00:00
|
|
|
void tst_QQuickPathView::nestedinFlickable()
|
2014-03-26 19:32:29 +00:00
|
|
|
{
|
|
|
|
QScopedPointer<QQuickView> window(createView());
|
|
|
|
QQuickViewTestUtil::moveMouseAway(window.data());
|
2014-07-23 06:07:31 +00:00
|
|
|
window->setSource(testFileUrl("nestedInFlickable.qml"));
|
2014-03-26 19:32:29 +00:00
|
|
|
window->show();
|
|
|
|
window->requestActivate();
|
|
|
|
QVERIFY(QTest::qWaitForWindowActive(window.data()));
|
|
|
|
QCOMPARE(window.data(), qGuiApp->focusWindow());
|
|
|
|
|
|
|
|
QQuickPathView *pathview = findItem<QQuickPathView>(window->rootObject(), "pathView");
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(pathview != nullptr);
|
2014-03-26 19:32:29 +00:00
|
|
|
|
|
|
|
QQuickFlickable *flickable = qobject_cast<QQuickFlickable*>(window->rootObject());
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(flickable != nullptr);
|
2014-03-26 19:32:29 +00:00
|
|
|
|
|
|
|
QSignalSpy movingSpy(pathview, SIGNAL(movingChanged()));
|
|
|
|
QSignalSpy moveStartedSpy(pathview, SIGNAL(movementStarted()));
|
|
|
|
QSignalSpy moveEndedSpy(pathview, SIGNAL(movementEnded()));
|
|
|
|
|
|
|
|
QSignalSpy fflickingSpy(flickable, SIGNAL(flickingChanged()));
|
|
|
|
QSignalSpy fflickStartedSpy(flickable, SIGNAL(flickStarted()));
|
|
|
|
QSignalSpy fflickEndedSpy(flickable, SIGNAL(flickEnded()));
|
|
|
|
|
|
|
|
int waitInterval = 5;
|
|
|
|
|
2018-02-21 09:41:54 +00:00
|
|
|
QTest::mousePress(window.data(), Qt::LeftButton, Qt::NoModifier, QPoint(23,218));
|
2014-03-26 19:32:29 +00:00
|
|
|
|
|
|
|
QTest::mouseMove(window.data(), QPoint(25,218), waitInterval);
|
|
|
|
QTest::mouseMove(window.data(), QPoint(26,218), waitInterval);
|
|
|
|
QTest::mouseMove(window.data(), QPoint(28,219), waitInterval);
|
|
|
|
QTest::mouseMove(window.data(), QPoint(31,219), waitInterval);
|
2015-01-09 09:53:12 +00:00
|
|
|
QTest::mouseMove(window.data(), QPoint(53,219), waitInterval);
|
2014-03-26 19:32:29 +00:00
|
|
|
|
|
|
|
// first move beyond threshold does not trigger drag
|
|
|
|
QVERIFY(!pathview->isMoving());
|
|
|
|
QVERIFY(!pathview->isDragging());
|
|
|
|
QCOMPARE(movingSpy.count(), 0);
|
|
|
|
QCOMPARE(moveStartedSpy.count(), 0);
|
|
|
|
QCOMPARE(moveEndedSpy.count(), 0);
|
|
|
|
QCOMPARE(fflickingSpy.count(), 0);
|
|
|
|
QCOMPARE(fflickStartedSpy.count(), 0);
|
|
|
|
QCOMPARE(fflickEndedSpy.count(), 0);
|
|
|
|
|
|
|
|
// no further moves after the initial move beyond threshold
|
2018-02-21 09:41:54 +00:00
|
|
|
QTest::mouseRelease(window.data(), Qt::LeftButton, Qt::NoModifier, QPoint(73,219));
|
2014-03-26 19:32:29 +00:00
|
|
|
QTRY_COMPARE(movingSpy.count(), 2);
|
|
|
|
QTRY_COMPARE(moveEndedSpy.count(), 1);
|
|
|
|
QCOMPARE(moveStartedSpy.count(), 1);
|
|
|
|
// Flickable should not handle this
|
|
|
|
QCOMPARE(fflickingSpy.count(), 0);
|
|
|
|
QCOMPARE(fflickStartedSpy.count(), 0);
|
|
|
|
QCOMPARE(fflickEndedSpy.count(), 0);
|
2017-05-02 06:25:37 +00:00
|
|
|
|
|
|
|
// now test that two quick flicks are both handled by the pathview
|
|
|
|
movingSpy.clear();
|
|
|
|
moveStartedSpy.clear();
|
|
|
|
moveEndedSpy.clear();
|
|
|
|
fflickingSpy.clear();
|
|
|
|
fflickStartedSpy.clear();
|
|
|
|
fflickEndedSpy.clear();
|
|
|
|
int shortInterval = 2;
|
2020-06-10 10:50:44 +00:00
|
|
|
QTest::mousePress(window.data(), Qt::LeftButton, {}, QPoint(23,216));
|
2017-05-02 06:25:37 +00:00
|
|
|
QTest::mouseMove(window.data(), QPoint(48,216), shortInterval);
|
2020-06-10 10:50:44 +00:00
|
|
|
QTest::mouseRelease(window.data(), Qt::LeftButton, {}, QPoint(73,217));
|
2017-05-02 06:25:37 +00:00
|
|
|
QVERIFY(pathview->isMoving());
|
2020-06-10 10:50:44 +00:00
|
|
|
QTest::mousePress(window.data(), Qt::LeftButton, {}, QPoint(21,216));
|
2017-05-02 06:25:37 +00:00
|
|
|
QTest::mouseMove(window.data(), QPoint(46,216), shortInterval);
|
2020-06-10 10:50:44 +00:00
|
|
|
QTest::mouseRelease(window.data(), Qt::LeftButton, {}, QPoint(71,217));
|
2017-05-02 06:25:37 +00:00
|
|
|
QVERIFY(pathview->isMoving());
|
|
|
|
// moveEndedSpy.count() and moveStartedSpy.count() should be exactly 1
|
|
|
|
// but in CI we sometimes see a scheduling issue being hit which
|
|
|
|
// causes the main thread to be stalled while the animation thread
|
|
|
|
// continues, allowing the animation timer to finish after the first
|
|
|
|
// call to QVERIFY(pathview->isMoving()) in the code above, prior to
|
|
|
|
// the detected beginning of the second flick, which can cause both of
|
|
|
|
// those signal counts to be 2 rather than 1.
|
|
|
|
// Note that this is not a true problem (this scheduling quirk just
|
|
|
|
// means that the unit test is not testing the enforced behavior
|
|
|
|
// as strictly as it would otherwise); it is only a bug if it results
|
|
|
|
// in the Flickable handling one or more of the flicks, and that
|
|
|
|
// is unconditionally tested below.
|
|
|
|
// To avoid false positive test failure in the scheduling quirk case
|
|
|
|
// we allow the multiple signal count case, rather than simply:
|
|
|
|
// QTRY_COMPARE(moveEndedSpy.count(), 1);
|
|
|
|
// QCOMPARE(moveStartedSpy.count(), 1);
|
|
|
|
QTRY_VERIFY(moveEndedSpy.count() > 0);
|
|
|
|
qCDebug(lcTests) << "After receiving moveEnded signal:"
|
|
|
|
<< "moveEndedSpy.count():" << moveEndedSpy.count()
|
|
|
|
<< "moveStartedSpy.count():" << moveStartedSpy.count()
|
|
|
|
<< "fflickingSpy.count():" << fflickingSpy.count()
|
|
|
|
<< "fflickStartedSpy.count():" << fflickStartedSpy.count()
|
|
|
|
<< "fflickEndedSpy.count():" << fflickEndedSpy.count();
|
|
|
|
QTRY_COMPARE(moveStartedSpy.count(), moveEndedSpy.count());
|
|
|
|
qCDebug(lcTests) << "After receiving matched moveEnded signal(s):"
|
|
|
|
<< "moveEndedSpy.count():" << moveEndedSpy.count()
|
|
|
|
<< "moveStartedSpy.count():" << moveStartedSpy.count()
|
|
|
|
<< "fflickingSpy.count():" << fflickingSpy.count()
|
|
|
|
<< "fflickStartedSpy.count():" << fflickStartedSpy.count()
|
|
|
|
<< "fflickEndedSpy.count():" << fflickEndedSpy.count();
|
|
|
|
QVERIFY(moveStartedSpy.count() <= 2);
|
|
|
|
// Flickable should not handle this
|
|
|
|
QCOMPARE(fflickingSpy.count(), 0);
|
|
|
|
QCOMPARE(fflickStartedSpy.count(), 0);
|
|
|
|
QCOMPARE(fflickEndedSpy.count(), 0);
|
|
|
|
|
2014-03-26 19:32:29 +00:00
|
|
|
}
|
|
|
|
|
2019-11-14 07:16:39 +00:00
|
|
|
void tst_QQuickPathView::ungrabNestedinFlickable()
|
|
|
|
{
|
|
|
|
QScopedPointer<QQuickView> window(createView());
|
|
|
|
QQuickViewTestUtil::moveMouseAway(window.data());
|
|
|
|
window->setSource(testFileUrl("ungrabNestedinFlickable.qml"));
|
|
|
|
window->show();
|
|
|
|
window->requestActivate();
|
|
|
|
QVERIFY(QTest::qWaitForWindowActive(window.data()));
|
|
|
|
QCOMPARE(window.data(), qGuiApp->focusWindow());
|
|
|
|
|
|
|
|
QQuickPathView *pathview = findItem<QQuickPathView>(window->rootObject(), "pathView");
|
|
|
|
QVERIFY(pathview != nullptr);
|
|
|
|
|
|
|
|
double pathviewOffsetBefore = pathview->offset();
|
|
|
|
|
|
|
|
// Drag slowly upwards so that it does not flick, release, and let it start snapping back
|
2020-06-10 10:50:44 +00:00
|
|
|
QTest::mousePress(window.data(), Qt::LeftButton, {}, QPoint(200, 350));
|
2019-11-14 07:16:39 +00:00
|
|
|
for (int i = 0; i < 4; ++i)
|
|
|
|
QTest::mouseMove(window.data(), QPoint(200, 325 - i * 25), 500);
|
2020-06-10 10:50:44 +00:00
|
|
|
QTest::mouseRelease(window.data(), Qt::LeftButton, {}, QPoint(200, 250));
|
2019-11-14 07:16:39 +00:00
|
|
|
QCOMPARE(pathview->isMoving(), true);
|
|
|
|
|
|
|
|
// Press again to stop moving
|
2020-06-10 10:50:44 +00:00
|
|
|
QTest::mousePress(window.data(), Qt::LeftButton, {}, QPoint(200, 350));
|
2019-11-14 07:16:39 +00:00
|
|
|
QTRY_COMPARE(pathview->isMoving(), false);
|
|
|
|
|
|
|
|
// Cancel the grab, wait for movement to stop, and expect it to snap to
|
|
|
|
// the nearest delegate, which should be at the same offset as where we started
|
|
|
|
pathview->ungrabMouse();
|
|
|
|
QTRY_COMPARE(pathview->offset(), pathviewOffsetBefore);
|
|
|
|
QCOMPARE(pathview->isMoving(), false);
|
2020-06-10 10:50:44 +00:00
|
|
|
QTest::mouseRelease(window.data(), Qt::LeftButton, {}, QPoint(200, 350));
|
2019-11-14 07:16:39 +00:00
|
|
|
}
|
|
|
|
|
2014-07-23 06:07:31 +00:00
|
|
|
void tst_QQuickPathView::flickableDelegate()
|
|
|
|
{
|
|
|
|
QScopedPointer<QQuickView> window(createView());
|
|
|
|
QQuickViewTestUtil::moveMouseAway(window.data());
|
|
|
|
window->setSource(testFileUrl("flickableDelegate.qml"));
|
|
|
|
window->show();
|
|
|
|
window->requestActivate();
|
|
|
|
QVERIFY(QTest::qWaitForWindowActive(window.data()));
|
|
|
|
QCOMPARE(window.data(), qGuiApp->focusWindow());
|
|
|
|
|
|
|
|
QQuickPathView *pathview = qobject_cast<QQuickPathView*>(window->rootObject());
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(pathview != nullptr);
|
2014-07-23 06:07:31 +00:00
|
|
|
|
|
|
|
QQuickFlickable *flickable = qobject_cast<QQuickFlickable*>(pathview->currentItem());
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(flickable != nullptr);
|
2014-07-23 06:07:31 +00:00
|
|
|
|
|
|
|
QSignalSpy movingSpy(pathview, SIGNAL(movingChanged()));
|
|
|
|
QSignalSpy moveStartedSpy(pathview, SIGNAL(movementStarted()));
|
|
|
|
QSignalSpy moveEndedSpy(pathview, SIGNAL(movementEnded()));
|
|
|
|
|
|
|
|
QSignalSpy fflickingSpy(flickable, SIGNAL(flickingChanged()));
|
|
|
|
QSignalSpy fflickStartedSpy(flickable, SIGNAL(flickStarted()));
|
|
|
|
QSignalSpy fflickEndedSpy(flickable, SIGNAL(flickEnded()));
|
|
|
|
|
|
|
|
int waitInterval = 5;
|
|
|
|
|
2018-02-21 09:41:54 +00:00
|
|
|
QTest::mousePress(window.data(), Qt::LeftButton, Qt::NoModifier, QPoint(23,100));
|
2014-07-23 06:07:31 +00:00
|
|
|
|
|
|
|
QTest::mouseMove(window.data(), QPoint(25,100), waitInterval);
|
|
|
|
QTest::mouseMove(window.data(), QPoint(26,100), waitInterval);
|
|
|
|
QTest::mouseMove(window.data(), QPoint(28,100), waitInterval);
|
|
|
|
QTest::mouseMove(window.data(), QPoint(31,100), waitInterval);
|
|
|
|
QTest::mouseMove(window.data(), QPoint(39,100), waitInterval);
|
|
|
|
|
|
|
|
// first move beyond threshold does not trigger drag
|
|
|
|
QVERIFY(!flickable->isMoving());
|
|
|
|
QVERIFY(!flickable->isDragging());
|
|
|
|
QCOMPARE(movingSpy.count(), 0);
|
|
|
|
QCOMPARE(moveStartedSpy.count(), 0);
|
|
|
|
QCOMPARE(moveEndedSpy.count(), 0);
|
|
|
|
QCOMPARE(fflickingSpy.count(), 0);
|
|
|
|
QCOMPARE(fflickStartedSpy.count(), 0);
|
|
|
|
QCOMPARE(fflickEndedSpy.count(), 0);
|
|
|
|
|
|
|
|
// no further moves after the initial move beyond threshold
|
2018-02-21 09:41:54 +00:00
|
|
|
QTest::mouseRelease(window.data(), Qt::LeftButton, Qt::NoModifier, QPoint(53,100));
|
2014-07-23 06:07:31 +00:00
|
|
|
QTRY_COMPARE(fflickingSpy.count(), 2);
|
|
|
|
QTRY_COMPARE(fflickStartedSpy.count(), 1);
|
|
|
|
QCOMPARE(fflickEndedSpy.count(), 1);
|
|
|
|
// PathView should not handle this
|
|
|
|
QTRY_COMPARE(movingSpy.count(), 0);
|
|
|
|
QTRY_COMPARE(moveEndedSpy.count(), 0);
|
|
|
|
QCOMPARE(moveStartedSpy.count(), 0);
|
|
|
|
}
|
|
|
|
|
2014-10-29 12:59:46 +00:00
|
|
|
void tst_QQuickPathView::jsArrayChange()
|
|
|
|
{
|
|
|
|
QQmlEngine engine;
|
|
|
|
QQmlComponent component(&engine);
|
|
|
|
component.setData("import QtQuick 2.4; PathView {}", QUrl());
|
|
|
|
|
|
|
|
QScopedPointer<QQuickPathView> view(qobject_cast<QQuickPathView *>(component.create()));
|
|
|
|
QVERIFY(!view.isNull());
|
|
|
|
|
|
|
|
QSignalSpy spy(view.data(), SIGNAL(modelChanged()));
|
|
|
|
QVERIFY(spy.isValid());
|
|
|
|
|
|
|
|
QJSValue array1 = engine.newArray(3);
|
|
|
|
QJSValue array2 = engine.newArray(3);
|
|
|
|
for (int i = 0; i < 3; ++i) {
|
|
|
|
array1.setProperty(i, i);
|
|
|
|
array2.setProperty(i, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
view->setModel(QVariant::fromValue(array1));
|
|
|
|
QCOMPARE(spy.count(), 1);
|
|
|
|
|
|
|
|
// no change
|
|
|
|
view->setModel(QVariant::fromValue(array2));
|
|
|
|
QCOMPARE(spy.count(), 1);
|
|
|
|
}
|
|
|
|
|
2016-05-26 11:45:31 +00:00
|
|
|
void tst_QQuickPathView::qtbug37815()
|
|
|
|
{
|
|
|
|
QScopedPointer<QQuickView> window(createView());
|
|
|
|
|
|
|
|
window->setSource(testFileUrl("qtbug37815.qml"));
|
|
|
|
window->show();
|
|
|
|
window->requestActivate();
|
|
|
|
QVERIFY(QTest::qWaitForWindowActive(window.data()));
|
|
|
|
|
|
|
|
// cache items will be created async. Let's wait...
|
|
|
|
QTest::qWait(1000);
|
|
|
|
|
|
|
|
QQuickPathView *pathView = findItem<QQuickPathView>(window->rootObject(), "pathView");
|
2017-10-06 09:38:59 +00:00
|
|
|
QVERIFY(pathView != nullptr);
|
2016-05-26 11:45:31 +00:00
|
|
|
|
|
|
|
const int pathItemCount = pathView->pathItemCount();
|
|
|
|
const int cacheItemCount = pathView->cacheItemCount();
|
|
|
|
int totalCount = 0;
|
|
|
|
foreach (QQuickItem *item, pathView->childItems()) {
|
|
|
|
if (item->objectName().startsWith(QLatin1String("delegate")))
|
|
|
|
++totalCount;
|
|
|
|
}
|
|
|
|
QCOMPARE(pathItemCount + cacheItemCount, totalCount);
|
|
|
|
}
|
|
|
|
|
2015-05-07 05:56:03 +00:00
|
|
|
/* This bug was one where if you jump the list such that the sole missing item needed to be
|
|
|
|
* added in the middle of the list, it would instead move an item somewhere else in the list
|
|
|
|
* to the middle (messing it up very badly).
|
|
|
|
*
|
|
|
|
* The test checks correct visual order both before and after the jump.
|
|
|
|
*/
|
|
|
|
void tst_QQuickPathView::qtbug42716()
|
|
|
|
{
|
|
|
|
QScopedPointer<QQuickView> window(createView());
|
|
|
|
|
|
|
|
window->setSource(testFileUrl("qtbug42716.qml"));
|
|
|
|
window->show();
|
|
|
|
QVERIFY(QTest::qWaitForWindowActive(window.data()));
|
|
|
|
QCOMPARE(window.data(), qGuiApp->focusWindow());
|
|
|
|
|
|
|
|
QQuickPathView *pathView = findItem<QQuickPathView>(window->rootObject(), "pathView");
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(pathView != nullptr);
|
2015-05-07 05:56:03 +00:00
|
|
|
|
|
|
|
int order1[] = {5,6,7,0,1,2,3};
|
|
|
|
int missing1 = 4;
|
|
|
|
int order2[] = {0,1,2,3,4,5,6};
|
|
|
|
int missing2 = 7;
|
|
|
|
|
|
|
|
qreal lastY = 0.0;
|
|
|
|
for (int i = 0; i<7; i++) {
|
|
|
|
QQuickItem *item = findItem<QQuickItem>(pathView, QString("delegate%1").arg(order1[i]));
|
|
|
|
QVERIFY(item);
|
|
|
|
QVERIFY(item->y() > lastY);
|
|
|
|
lastY = item->y();
|
|
|
|
}
|
|
|
|
QQuickItem *itemMiss = findItem<QQuickItem>(pathView, QString("delegate%1").arg(missing1));
|
|
|
|
QVERIFY(!itemMiss);
|
|
|
|
|
|
|
|
pathView->setOffset(0.0882353);
|
|
|
|
//Note refill is delayed, needs time to take effect
|
|
|
|
QTest::qWait(100);
|
|
|
|
|
|
|
|
lastY = 0.0;
|
|
|
|
for (int i = 0; i<7; i++) {
|
|
|
|
QQuickItem *item = findItem<QQuickItem>(pathView, QString("delegate%1").arg(order2[i]));
|
|
|
|
QVERIFY(item);
|
|
|
|
QVERIFY(item->y() > lastY);
|
|
|
|
lastY = item->y();
|
|
|
|
}
|
|
|
|
itemMiss = findItem<QQuickItem>(pathView, QString("delegate%1").arg(missing2));
|
|
|
|
QVERIFY(!itemMiss);
|
|
|
|
}
|
|
|
|
|
2016-05-24 09:21:39 +00:00
|
|
|
void tst_QQuickPathView::qtbug53464()
|
|
|
|
{
|
|
|
|
QScopedPointer<QQuickView> window(createView());
|
|
|
|
|
|
|
|
window->setSource(testFileUrl("qtbug53464.qml"));
|
|
|
|
window->show();
|
|
|
|
window->requestActivate();
|
|
|
|
QVERIFY(QTest::qWaitForWindowActive(window.data()));
|
|
|
|
|
|
|
|
QQuickPathView *pathView = findItem<QQuickPathView>(window->rootObject(), "pathView");
|
2017-10-06 09:38:59 +00:00
|
|
|
QVERIFY(pathView != nullptr);
|
2016-05-24 09:21:39 +00:00
|
|
|
const int currentIndex = pathView->currentIndex();
|
|
|
|
QCOMPARE(currentIndex, 8);
|
|
|
|
|
|
|
|
const int pathItemCount = pathView->pathItemCount();
|
|
|
|
int totalCount = 0;
|
|
|
|
foreach (QQuickItem *item, pathView->childItems()) {
|
|
|
|
if (item->objectName().startsWith(QLatin1String("delegate")))
|
|
|
|
++totalCount;
|
|
|
|
}
|
|
|
|
QCOMPARE(pathItemCount, totalCount);
|
|
|
|
}
|
|
|
|
|
2015-05-21 07:52:49 +00:00
|
|
|
void tst_QQuickPathView::addCustomAttribute()
|
|
|
|
{
|
|
|
|
const QScopedPointer<QQuickView> window(createView());
|
|
|
|
window->setSource(testFileUrl("customAttribute.qml"));
|
|
|
|
window->show();
|
|
|
|
}
|
|
|
|
|
2016-04-26 12:12:14 +00:00
|
|
|
void tst_QQuickPathView::movementDirection_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QQuickPathView::MovementDirection>("movementdirection");
|
|
|
|
QTest::addColumn<int>("toidx");
|
|
|
|
QTest::addColumn<qreal>("fromoffset");
|
|
|
|
QTest::addColumn<qreal>("tooffset");
|
|
|
|
|
|
|
|
QTest::newRow("default-shortest") << QQuickPathView::Shortest << 3 << 8.0 << 5.0;
|
|
|
|
QTest::newRow("negative") << QQuickPathView::Negative << 2 << 0.0 << 6.0;
|
|
|
|
QTest::newRow("positive") << QQuickPathView::Positive << 3 << 8.0 << 5.0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void verify_offsets(QQuickPathView *pathview, int toidx, qreal fromoffset, qreal tooffset)
|
|
|
|
{
|
|
|
|
pathview->setCurrentIndex(toidx);
|
|
|
|
bool started = false;
|
|
|
|
qreal first, second;
|
|
|
|
QTest::qWait(100);
|
|
|
|
first = pathview->offset();
|
|
|
|
while (1) {
|
2018-04-26 12:08:52 +00:00
|
|
|
if (first == 0)
|
|
|
|
first = pathview->offset();
|
2016-04-26 12:12:14 +00:00
|
|
|
QTest::qWait(10); // highlightMoveDuration: 1000
|
|
|
|
second = pathview->offset();
|
2018-04-26 12:08:52 +00:00
|
|
|
if (!started && first != 0 && second != first) { // animation started
|
2016-04-26 12:12:14 +00:00
|
|
|
started = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tooffset > fromoffset) {
|
|
|
|
QVERIFY(fromoffset <= first);
|
|
|
|
QVERIFY(first <= second);
|
|
|
|
QVERIFY(second <= tooffset);
|
|
|
|
} else {
|
|
|
|
QVERIFY(fromoffset >= first);
|
|
|
|
QVERIFY(first >= second);
|
|
|
|
QVERIFY(second >= tooffset);
|
|
|
|
}
|
|
|
|
QTRY_COMPARE(pathview->offset(), tooffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QQuickPathView::movementDirection()
|
|
|
|
{
|
|
|
|
QFETCH(QQuickPathView::MovementDirection, movementdirection);
|
|
|
|
QFETCH(int, toidx);
|
|
|
|
QFETCH(qreal, fromoffset);
|
|
|
|
QFETCH(qreal, tooffset);
|
|
|
|
|
|
|
|
QScopedPointer<QQuickView> window(createView());
|
|
|
|
QQuickViewTestUtil::moveMouseAway(window.data());
|
|
|
|
window->setSource(testFileUrl("movementDirection.qml"));
|
|
|
|
window->show();
|
|
|
|
window->requestActivate();
|
|
|
|
QVERIFY(QTest::qWaitForWindowActive(window.data()));
|
|
|
|
QCOMPARE(window.data(), qGuiApp->focusWindow());
|
|
|
|
|
|
|
|
QQuickPathView *pathview = window->rootObject()->findChild<QQuickPathView*>("view");
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(pathview != nullptr);
|
2016-04-26 12:12:14 +00:00
|
|
|
QVERIFY(pathview->offset() == 0.0);
|
|
|
|
QVERIFY(pathview->currentIndex() == 0);
|
|
|
|
pathview->setMovementDirection(movementdirection);
|
|
|
|
QVERIFY(pathview->movementDirection() == movementdirection);
|
|
|
|
|
|
|
|
verify_offsets(pathview, toidx, fromoffset, tooffset);
|
|
|
|
}
|
|
|
|
|
2016-12-28 22:40:11 +00:00
|
|
|
void tst_QQuickPathView::removePath()
|
|
|
|
{
|
|
|
|
QScopedPointer<QQuickView> window(createView());
|
|
|
|
window->setSource(testFileUrl("removePath.qml"));
|
|
|
|
window->show();
|
|
|
|
|
|
|
|
QQuickPathView *pathview = qobject_cast<QQuickPathView*>(window->rootObject());
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(pathview != nullptr);
|
2016-12-28 22:40:11 +00:00
|
|
|
|
|
|
|
QVERIFY(QMetaObject::invokeMethod(pathview, "removePath"));
|
|
|
|
QVERIFY(QMetaObject::invokeMethod(pathview, "setPath"));
|
|
|
|
}
|
|
|
|
|
2018-06-19 14:04:24 +00:00
|
|
|
/*
|
|
|
|
Tests that moving items in an ObjectModel and then deleting the view
|
|
|
|
doesn't cause heap-use-after-free when run through ASAN.
|
|
|
|
|
|
|
|
The test case is based on a Qt Quick Controls 2 test where the issue was
|
|
|
|
discovered.
|
|
|
|
*/
|
|
|
|
void tst_QQuickPathView::objectModelMove()
|
|
|
|
{
|
|
|
|
QScopedPointer<QQuickView> window(createView());
|
|
|
|
window->setSource(testFileUrl("objectModelMove.qml"));
|
|
|
|
window->show();
|
|
|
|
|
|
|
|
// Create the view.
|
|
|
|
QVERIFY(QMetaObject::invokeMethod(window->rootObject(), "newView"));
|
|
|
|
QPointer<QQuickPathView> pathView = window->rootObject()->property("pathViewItem").value<QQuickPathView*>();
|
|
|
|
QVERIFY(pathView);
|
|
|
|
QCOMPARE(pathView->count(), 3);
|
|
|
|
pathView->highlightItem()->setObjectName("highlight");
|
|
|
|
|
|
|
|
// Move an item from index 0 to 1.
|
|
|
|
QVERIFY(QMetaObject::invokeMethod(window->rootObject(), "move"));
|
|
|
|
QCOMPARE(pathView->count(), 3);
|
|
|
|
|
|
|
|
// Keep track of the amount of listeners
|
|
|
|
QVector<QString> itemObjectNames;
|
|
|
|
itemObjectNames << QLatin1String("red") << QLatin1String("green") << QLatin1String("blue");
|
|
|
|
QVector<QQuickItem*> childItems;
|
2020-06-10 10:50:44 +00:00
|
|
|
for (const QString &itemObjectName : qAsConst(itemObjectNames)) {
|
2018-06-19 14:04:24 +00:00
|
|
|
QQuickItem *childItem = findItem<QQuickItem>(pathView, itemObjectName);
|
|
|
|
QVERIFY(childItem);
|
|
|
|
childItems.append(childItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Destroy the view (via destroy()).
|
|
|
|
QVERIFY(QMetaObject::invokeMethod(window->rootObject(), "destroyView"));
|
|
|
|
// Ensure that the view has been destroyed. This check is also necessary in order for
|
|
|
|
// ASAN to complain (it will complain after the test function has finished).
|
|
|
|
QTRY_VERIFY(pathView.isNull());
|
|
|
|
// By this point, all of its cached items should have been released,
|
|
|
|
// which means none of the items should have any listeners.
|
|
|
|
for (const auto childItem : qAsConst(childItems)) {
|
|
|
|
const QQuickItemPrivate *childItemPrivate = QQuickItemPrivate::get(childItem);
|
|
|
|
QCOMPARE(childItemPrivate->changeListeners.size(), 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-15 08:03:57 +00:00
|
|
|
void tst_QQuickPathView::requiredPropertiesInDelegate()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
QTest::ignoreMessage(QtMsgType::QtInfoMsg, "Bill JonesBerlin0");
|
|
|
|
QTest::ignoreMessage(QtMsgType::QtInfoMsg, "Jane DoeOslo1");
|
|
|
|
QTest::ignoreMessage(QtMsgType::QtInfoMsg, "John SmithOulo2");
|
|
|
|
QScopedPointer<QQuickView> window(createView());
|
|
|
|
window->setSource(testFileUrl("delegateWithRequiredProperties.qml"));
|
|
|
|
window->show();
|
|
|
|
}
|
|
|
|
{
|
|
|
|
QScopedPointer<QQuickView> window(createView());
|
|
|
|
window->setSource(testFileUrl("delegateWithRequiredProperties.2.qml"));
|
|
|
|
window->show();
|
|
|
|
QTRY_VERIFY(window->rootObject()->property("working").toBool());
|
|
|
|
}
|
2019-09-17 12:00:42 +00:00
|
|
|
{
|
|
|
|
QScopedPointer<QQuickView> window(createView());
|
|
|
|
QTest::ignoreMessage(QtMsgType::QtWarningMsg, QRegularExpression("Writing to \"name\" broke the binding to the underlying model"));
|
|
|
|
window->setSource(testFileUrl("delegateWithRequiredProperties.3.qml"));
|
|
|
|
window->show();
|
|
|
|
QTRY_VERIFY(window->rootObject()->property("working").toBool());
|
|
|
|
}
|
2019-08-15 08:03:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QQuickPathView::requiredPropertiesInDelegatePreventUnrelated()
|
|
|
|
{
|
|
|
|
QTest::ignoreMessage(QtMsgType::QtInfoMsg, "ReferenceError");
|
|
|
|
QTest::ignoreMessage(QtMsgType::QtInfoMsg, "ReferenceError");
|
|
|
|
QTest::ignoreMessage(QtMsgType::QtInfoMsg, "ReferenceError");
|
|
|
|
QScopedPointer<QQuickView> window(createView());
|
|
|
|
window->setSource(testFileUrl("delegatewithUnrelatedRequiredPreventsAccessToModel.qml"));
|
|
|
|
window->show();
|
|
|
|
}
|
|
|
|
|
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"
|