An error occurred while loading the file. Please try again.
-
Nico Vertriest authored
-modified \brief -checked QML modules -added qml directory to the qdocconf file -added particles directory to the qdocconf file Change-Id: I589e32d3106cda37c7fa4d55a941afd9876fc2b2 Reviewed-by:
Geir Vattekar <geir.vattekar@nokia.com>
6112c0f5
tst_qquickwindow.cpp 69.90 KiB
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** 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
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <qtest.h>
#include <QDebug>
#include <QTouchEvent>
#include <QtQuick/QQuickItem>
#include <QtQuick/QQuickView>
#include <QtQuick/QQuickWindow>
#include <QtQml/QQmlEngine>
#include <QtQml/QQmlComponent>
#include <QtQuick/private/qquickrectangle_p.h>
#include <QtQuick/private/qquickloader_p.h>
#include "../../shared/util.h"
#include "../shared/visualtestutil.h"
#include "../shared/viewtestutil.h"
#include <QSignalSpy>
#include <qpa/qwindowsysteminterface.h>
#include <private/qquickwindow_p.h>
#include <private/qguiapplication_p.h>
#include <QRunnable>
struct TouchEventData {
QEvent::Type type;
QWidget *widget;
QWindow *window;
Qt::TouchPointStates states;
QList<QTouchEvent::TouchPoint> touchPoints;
};
static QTouchEvent::TouchPoint makeTouchPoint(QQuickItem *item, const QPointF &p, const QPointF &lastPoint = QPointF())
{
QPointF last = lastPoint.isNull() ? p : lastPoint;
QTouchEvent::TouchPoint tp;
tp.setPos(p);
tp.setLastPos(last);
tp.setScenePos(item->mapToScene(p));
tp.setLastScenePos(item->mapToScene(last));
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
tp.setScreenPos(item->window()->mapToGlobal(tp.scenePos().toPoint()));
tp.setLastScreenPos(item->window()->mapToGlobal(tp.lastScenePos().toPoint()));
return tp;
}
static TouchEventData makeTouchData(QEvent::Type type, QWindow *w, Qt::TouchPointStates states = 0,
const QList<QTouchEvent::TouchPoint>& touchPoints = QList<QTouchEvent::TouchPoint>())
{
TouchEventData d = { type, 0, w, states, touchPoints };
return d;
}
static TouchEventData makeTouchData(QEvent::Type type, QWindow *w, Qt::TouchPointStates states, const QTouchEvent::TouchPoint &touchPoint)
{
QList<QTouchEvent::TouchPoint> points;
points << touchPoint;
return makeTouchData(type, w, states, points);
}
#define COMPARE_TOUCH_POINTS(tp1, tp2) \
{ \
QCOMPARE(tp1.pos(), tp2.pos()); \
QCOMPARE(tp1.lastPos(), tp2.lastPos()); \
QCOMPARE(tp1.scenePos(), tp2.scenePos()); \
QCOMPARE(tp1.lastScenePos(), tp2.lastScenePos()); \
QCOMPARE(tp1.screenPos(), tp2.screenPos()); \
QCOMPARE(tp1.lastScreenPos(), tp2.lastScreenPos()); \
}
#define COMPARE_TOUCH_DATA(d1, d2) \
{ \
QCOMPARE((int)d1.type, (int)d2.type); \
QCOMPARE(d1.widget, d2.widget); \
QCOMPARE((int)d1.states, (int)d2.states); \
QCOMPARE(d1.touchPoints.count(), d2.touchPoints.count()); \
for (int i=0; i<d1.touchPoints.count(); i++) { \
COMPARE_TOUCH_POINTS(d1.touchPoints[i], d2.touchPoints[i]); \
} \
}
class RootItemAccessor : public QQuickItem
{
Q_OBJECT
public:
RootItemAccessor()
: m_rootItemDestroyed(false)
, m_rootItem(0)
{
}
Q_INVOKABLE QQuickItem *contentItem()
{
if (!m_rootItem) {
QQuickWindowPrivate *c = QQuickWindowPrivate::get(window());
m_rootItem = c->contentItem;
QObject::connect(m_rootItem, SIGNAL(destroyed()), this, SLOT(rootItemDestroyed()));
}
return m_rootItem;
}
bool isRootItemDestroyed() {return m_rootItemDestroyed;}
public slots:
void rootItemDestroyed() {
m_rootItemDestroyed = true;
}
private:
bool m_rootItemDestroyed;
QQuickItem *m_rootItem;
};
class TestTouchItem : public QQuickRectangle
141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
{
Q_OBJECT
public:
TestTouchItem(QQuickItem *parent = 0)
: QQuickRectangle(parent), acceptTouchEvents(true), acceptMouseEvents(true),
mousePressId(0),
spinLoopWhenPressed(false), touchEventCount(0)
{
border()->setWidth(1);
setAcceptedMouseButtons(Qt::LeftButton);
setFiltersChildMouseEvents(true);
}
void reset() {
acceptTouchEvents = acceptMouseEvents = true;
setEnabled(true);
setVisible(true);
lastEvent = makeTouchData(QEvent::None, window(), 0, QList<QTouchEvent::TouchPoint>());//CHECK_VALID
lastVelocity = lastVelocityFromMouseMove = QVector2D();
lastMousePos = QPointF();
lastMouseCapabilityFlags = 0;
}
static void clearMousePressCounter()
{
mousePressNum = mouseMoveNum = mouseReleaseNum = 0;
}
void clearTouchEventCounter()
{
touchEventCount = 0;
}
bool acceptTouchEvents;
bool acceptMouseEvents;
TouchEventData lastEvent;
int mousePressId;
bool spinLoopWhenPressed;
int touchEventCount;
QVector2D lastVelocity;
QVector2D lastVelocityFromMouseMove;
QPointF lastMousePos;
int lastMouseCapabilityFlags;
void touchEvent(QTouchEvent *event) {
if (!acceptTouchEvents) {
event->ignore();
return;
}
++touchEventCount;
lastEvent = makeTouchData(event->type(), event->window(), event->touchPointStates(), event->touchPoints());
if (event->device()->capabilities().testFlag(QTouchDevice::Velocity) && !event->touchPoints().isEmpty()) {
lastVelocity = event->touchPoints().first().velocity();
} else {
lastVelocity = QVector2D();
}
if (spinLoopWhenPressed && event->touchPointStates().testFlag(Qt::TouchPointPressed)) {
QCoreApplication::processEvents();
}
}
void mousePressEvent(QMouseEvent *e) {
if (!acceptMouseEvents) {
e->ignore();
return;
}
mousePressId = ++mousePressNum;
lastMousePos = e->pos();
211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
lastMouseCapabilityFlags = QGuiApplicationPrivate::mouseEventCaps(e);
}
void mouseMoveEvent(QMouseEvent *e) {
if (!acceptMouseEvents) {
e->ignore();
return;
}
++mouseMoveNum;
lastVelocityFromMouseMove = QGuiApplicationPrivate::mouseEventVelocity(e);
lastMouseCapabilityFlags = QGuiApplicationPrivate::mouseEventCaps(e);
lastMousePos = e->pos();
}
void mouseReleaseEvent(QMouseEvent *e) {
if (!acceptMouseEvents) {
e->ignore();
return;
}
++mouseReleaseNum;
lastMousePos = e->pos();
lastMouseCapabilityFlags = QGuiApplicationPrivate::mouseEventCaps(e);
}
bool childMouseEventFilter(QQuickItem *, QEvent *event) {
// TODO Is it a bug if a QTouchEvent comes here?
if (event->type() == QEvent::MouseButtonPress)
mousePressId = ++mousePressNum;
return false;
}
static int mousePressNum, mouseMoveNum, mouseReleaseNum;
};
int TestTouchItem::mousePressNum = 0;
int TestTouchItem::mouseMoveNum = 0;
int TestTouchItem::mouseReleaseNum = 0;
class EventFilter : public QObject
{
public:
bool eventFilter(QObject *watched, QEvent *event) {
Q_UNUSED(watched);
events.append(event->type());
return false;
}
QList<int> events;
};
class ConstantUpdateItem : public QQuickItem
{
Q_OBJECT
public:
ConstantUpdateItem(QQuickItem *parent = 0) : QQuickItem(parent), iterations(0) {setFlag(ItemHasContents);}
int iterations;
protected:
QSGNode* updatePaintNode(QSGNode *, UpdatePaintNodeData *){
iterations++;
update();
return 0;
}
};
class tst_qquickwindow : public QQmlDataTest
{
Q_OBJECT
public:
281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
private slots:
void initTestCase()
{
QQmlDataTest::initTestCase();
touchDevice = new QTouchDevice;
touchDevice->setType(QTouchDevice::TouchScreen);
QWindowSystemInterface::registerTouchDevice(touchDevice);
touchDeviceWithVelocity = new QTouchDevice;
touchDeviceWithVelocity->setType(QTouchDevice::TouchScreen);
touchDeviceWithVelocity->setCapabilities(QTouchDevice::Position | QTouchDevice::Velocity);
QWindowSystemInterface::registerTouchDevice(touchDeviceWithVelocity);
}
void openglContextCreatedSignal();
void aboutToStopSignal();
void constantUpdates();
void constantUpdatesOnWindow_data();
void constantUpdatesOnWindow();
void mouseFiltering();
void headless();
void noUpdateWhenNothingChanges();
void touchEvent_basic();
void touchEvent_propagation();
void touchEvent_propagation_data();
void touchEvent_cancel();
void touchEvent_reentrant();
void touchEvent_velocity();
void mouseFromTouch_basic();
void clearWindow();
void qmlCreation();
void clearColor();
void defaultState();
void grab_data();
void grab();
void multipleWindows();
void animationsWhileHidden();
void focusObject();
void focusReason();
void ignoreUnhandledMouseEvents();
void ownershipRootItem();
void hideThenDelete_data();
void hideThenDelete();
void showHideAnimate();
void testExpose();
void requestActivate();
void testWindowVisibilityOrder();
void blockClosing();
void blockCloseMethod();
void crashWhenHoverItemDeleted();
void unloadSubWindow();
void qobjectEventFilter_touch();
351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
void qobjectEventFilter_key();
void qobjectEventFilter_mouse();
#ifndef QT_NO_CURSOR
void cursor();
#endif
void animatingSignal();
void contentItemSize();
void defaultSurfaceFormat();
void attachedProperty();
void testRenderJob();
private:
QTouchDevice *touchDevice;
QTouchDevice *touchDeviceWithVelocity;
};
Q_DECLARE_METATYPE(QOpenGLContext *);
void tst_qquickwindow::openglContextCreatedSignal()
{
qRegisterMetaType<QOpenGLContext *>();
QQuickWindow window;
QSignalSpy spy(&window, SIGNAL(openglContextCreated(QOpenGLContext*)));
window.show();
QTest::qWaitForWindowExposed(&window);
QVERIFY(spy.size() > 0);
QVariant ctx = spy.at(0).at(0);
QCOMPARE(qVariantValue<QOpenGLContext *>(ctx), window.openglContext());
}
void tst_qquickwindow::aboutToStopSignal()
{
QQuickWindow window;
window.show();
QTest::qWaitForWindowExposed(&window);
QSignalSpy spy(&window, SIGNAL(sceneGraphAboutToStop()));
window.hide();
QTRY_VERIFY(spy.count() > 0);
}
//If the item calls update inside updatePaintNode, it should schedule another sync pass
void tst_qquickwindow::constantUpdates()
{
QQuickWindow window;
window.resize(250, 250);
ConstantUpdateItem item(window.contentItem());
window.show();
QSignalSpy beforeSpy(&window, SIGNAL(beforeSynchronizing()));
QSignalSpy afterSpy(&window, SIGNAL(afterSynchronizing()));
QTRY_VERIFY(item.iterations > 10);
QTRY_VERIFY(beforeSpy.count() > 10);
QTRY_VERIFY(afterSpy.count() > 10);
}
void tst_qquickwindow::constantUpdatesOnWindow_data()