summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2018-02-05 10:25:15 +0100
committerLiang Qi <liang.qi@qt.io>2018-02-05 10:25:15 +0100
commit6fe4c1f2803abac74da152b9a5656eff2d71dceb (patch)
tree7d90d1a71d8cfb938f9a8fad33b8fbeeb66019f7
parent2e65f6c2a5d84f4369245cabdc03eca4c19851f0 (diff)
parentc2bd33af9fb548ff20bf34323271baa89cbc8a55 (diff)
Merge remote-tracking branch 'origin/5.9' into 5.10
Conflicts: tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp Change-Id: I64f7c1d776fab3cad4530f291b93afd2a8fb8533
-rw-r--r--tests/auto/quick/qquickwindow/tst_qquickwindow.cpp105
-rw-r--r--tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp119
-rw-r--r--tools/qmlprofiler/qmlprofilerapplication.cpp18
-rw-r--r--tools/qmlprofiler/qmlprofilerapplication.h1
4 files changed, 242 insertions, 1 deletions
diff --git a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp
index f20a1a7e1a..5c87daaed6 100644
--- a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp
+++ b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp
@@ -292,6 +292,70 @@ protected:
}
};
+class MouseRecordingWindow : public QQuickWindow
+{
+public:
+ explicit MouseRecordingWindow(QWindow *parent = nullptr) : QQuickWindow(parent) { }
+
+protected:
+ void mousePressEvent(QMouseEvent *event) override {
+ qCDebug(lcTests) << event;
+ m_mouseEvents << *event;
+ QQuickWindow::mousePressEvent(event);
+ }
+ void mouseMoveEvent(QMouseEvent *event) override {
+ qCDebug(lcTests) << event;
+ m_mouseEvents << *event;
+ QQuickWindow::mouseMoveEvent(event);
+ }
+ void mouseReleaseEvent(QMouseEvent *event) override {
+ qCDebug(lcTests) << event;
+ m_mouseEvents << *event;
+ QQuickWindow::mouseReleaseEvent(event);
+ }
+
+public:
+ QList<QMouseEvent> m_mouseEvents;
+};
+
+class MouseRecordingItem : public QQuickItem
+{
+public:
+ MouseRecordingItem(bool acceptTouch, QQuickItem *parent = nullptr)
+ : QQuickItem(parent)
+ , m_acceptTouch(acceptTouch)
+ {
+ setSize(QSizeF(300, 300));
+ setAcceptedMouseButtons(Qt::LeftButton);
+ }
+
+protected:
+ void touchEvent(QTouchEvent* event) override {
+ event->setAccepted(m_acceptTouch);
+ m_touchEvents << *event;
+ qCDebug(lcTests) << "accepted?" << event->isAccepted() << event;
+ }
+ void mousePressEvent(QMouseEvent *event) override {
+ qCDebug(lcTests) << event;
+ m_mouseEvents << *event;
+ }
+ void mouseMoveEvent(QMouseEvent *event) override {
+ qCDebug(lcTests) << event;
+ m_mouseEvents << *event;
+ }
+ void mouseReleaseEvent(QMouseEvent *event) override {
+ qCDebug(lcTests) << event;
+ m_mouseEvents << *event;
+ }
+
+public:
+ QList<QMouseEvent> m_mouseEvents;
+ QList<QTouchEvent> m_touchEvents;
+
+private:
+ bool m_acceptTouch;
+};
+
class tst_qquickwindow : public QQmlDataTest
{
Q_OBJECT
@@ -330,6 +394,8 @@ private slots:
void mergeTouchPointLists();
void mouseFromTouch_basic();
+ void synthMouseFromTouch_data();
+ void synthMouseFromTouch();
void clearWindow();
@@ -1132,6 +1198,45 @@ void tst_qquickwindow::mouseFromTouch_basic()
delete item;
}
+void tst_qquickwindow::synthMouseFromTouch_data()
+{
+ QTest::addColumn<bool>("synthMouse"); // AA_SynthesizeMouseForUnhandledTouchEvents
+ QTest::addColumn<bool>("acceptTouch"); // QQuickItem::touchEvent: setAccepted()
+
+ QTest::newRow("no synth, accept") << false << true; // suitable for touch-capable UIs
+ QTest::newRow("no synth, don't accept") << false << false;
+ QTest::newRow("synth and accept") << true << true;
+ QTest::newRow("synth, don't accept") << true << false; // the default
+}
+
+void tst_qquickwindow::synthMouseFromTouch()
+{
+ QFETCH(bool, synthMouse);
+ QFETCH(bool, acceptTouch);
+
+ QCoreApplication::setAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents, synthMouse);
+ QScopedPointer<MouseRecordingWindow> window(new MouseRecordingWindow);
+ QScopedPointer<MouseRecordingItem> item(new MouseRecordingItem(acceptTouch, nullptr));
+ item->setParentItem(window->contentItem());
+ window->resize(250, 250);
+ window->setPosition(100, 100);
+ window->setTitle(QTest::currentTestFunction());
+ window->show();
+ QVERIFY(QTest::qWaitForWindowActive(window.data()));
+
+ QPoint p1 = QPoint(20, 20);
+ QPoint p2 = QPoint(30, 30);
+ QTest::touchEvent(window.data(), touchDevice).press(0, p1, window.data());
+ QTest::touchEvent(window.data(), touchDevice).move(0, p2, window.data());
+ QTest::touchEvent(window.data(), touchDevice).release(0, p2, window.data());
+
+ QCOMPARE(item->m_touchEvents.count(), 3);
+ QCOMPARE(item->m_mouseEvents.count(), acceptTouch ? 0 : 3);
+ QCOMPARE(window->m_mouseEvents.count(), 0);
+ for (const QMouseEvent &ev : item->m_mouseEvents)
+ QCOMPARE(ev.source(), Qt::MouseEventSynthesizedByQt);
+}
+
void tst_qquickwindow::clearWindow()
{
QQuickWindow *window = new QQuickWindow;
diff --git a/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp b/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp
index 61673996aa..bb9f1d192d 100644
--- a/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp
+++ b/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp
@@ -27,6 +27,7 @@
****************************************************************************/
#include <qtest.h>
+#include <qtesttouch.h>
#include <QtTest/QSignalSpy>
#include <QtQml/qqmlcomponent.h>
#include <QtQml/qqmlcontext.h>
@@ -38,11 +39,81 @@
#include <QtCore/QDebug>
#include <QtQml/qqmlengine.h>
+#include <QtCore/QLoggingCategory>
+
#include <QtWidgets/QBoxLayout>
#include <QtWidgets/QLabel>
#include <QtQuickWidgets/QQuickWidget>
+Q_LOGGING_CATEGORY(lcTests, "qt.quick.tests")
+
+class MouseRecordingQQWidget : public QQuickWidget
+{
+public:
+ explicit MouseRecordingQQWidget(QWidget *parent = nullptr) : QQuickWidget(parent) {
+ setAttribute(Qt::WA_AcceptTouchEvents);
+ }
+
+protected:
+ void mousePressEvent(QMouseEvent *event) override {
+ qCDebug(lcTests) << event;
+ m_mouseEvents << *event;
+ QQuickWidget::mousePressEvent(event);
+ }
+ void mouseMoveEvent(QMouseEvent *event) override {
+ qCDebug(lcTests) << event;
+ m_mouseEvents << *event;
+ QQuickWidget::mouseMoveEvent(event);
+ }
+ void mouseReleaseEvent(QMouseEvent *event) override {
+ qCDebug(lcTests) << event;
+ m_mouseEvents << *event;
+ QQuickWidget::mouseReleaseEvent(event);
+ }
+
+public:
+ QList<QMouseEvent> m_mouseEvents;
+};
+
+class MouseRecordingItem : public QQuickItem
+{
+public:
+ MouseRecordingItem(bool acceptTouch, QQuickItem *parent = nullptr)
+ : QQuickItem(parent)
+ , m_acceptTouch(acceptTouch)
+ {
+ setSize(QSizeF(300, 300));
+ setAcceptedMouseButtons(Qt::LeftButton);
+ }
+
+protected:
+ void touchEvent(QTouchEvent* event) override {
+ event->setAccepted(m_acceptTouch);
+ m_touchEvents << *event;
+ qCDebug(lcTests) << "accepted?" << event->isAccepted() << event;
+ }
+ void mousePressEvent(QMouseEvent *event) override {
+ qCDebug(lcTests) << event;
+ m_mouseEvents << *event;
+ }
+ void mouseMoveEvent(QMouseEvent *event) override {
+ qCDebug(lcTests) << event;
+ m_mouseEvents << *event;
+ }
+ void mouseReleaseEvent(QMouseEvent *event) override {
+ qCDebug(lcTests) << event;
+ m_mouseEvents << *event;
+ }
+
+public:
+ QList<QMouseEvent> m_mouseEvents;
+ QList<QTouchEvent> m_touchEvents;
+
+private:
+ bool m_acceptTouch;
+};
+
class tst_qquickwidget : public QQmlDataTest
{
Q_OBJECT
@@ -67,8 +138,12 @@ private slots:
void shortcuts();
void enterLeave();
void mouseEventWindowPos();
-};
+ void synthMouseFromTouch_data();
+ void synthMouseFromTouch();
+private:
+ QTouchDevice *device = QTest::createTouchDevice();
+};
tst_qquickwidget::tst_qquickwidget()
{
@@ -499,6 +574,48 @@ void tst_qquickwidget::mouseEventWindowPos()
QTRY_VERIFY(rootItem->property("wasMoved").toBool());
}
+void tst_qquickwidget::synthMouseFromTouch_data()
+{
+ QTest::addColumn<bool>("synthMouse"); // AA_SynthesizeMouseForUnhandledTouchEvents
+ QTest::addColumn<bool>("acceptTouch"); // QQuickItem::touchEvent: setAccepted()
+
+ QTest::newRow("no synth, accept") << false << true; // suitable for touch-capable UIs
+ QTest::newRow("no synth, don't accept") << false << false;
+ QTest::newRow("synth and accept") << true << true;
+ QTest::newRow("synth, don't accept") << true << false; // the default
+}
+
+void tst_qquickwidget::synthMouseFromTouch()
+{
+ QFETCH(bool, synthMouse);
+ QFETCH(bool, acceptTouch);
+
+ QCoreApplication::setAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents, synthMouse);
+ QWidget window;
+ window.setAttribute(Qt::WA_AcceptTouchEvents);
+ QScopedPointer<MouseRecordingQQWidget> childView(new MouseRecordingQQWidget(&window));
+ MouseRecordingItem *item = new MouseRecordingItem(acceptTouch, nullptr);
+ childView->setContent(QUrl(), nullptr, item);
+ window.resize(300, 300);
+ childView->resize(300, 300);
+ window.show();
+ QVERIFY(QTest::qWaitForWindowActive(&window));
+ QVERIFY(childView->quickWindow()->isVisible());
+ QVERIFY(item->isVisible());
+
+ QPoint p1 = QPoint(20, 20);
+ QPoint p2 = QPoint(30, 30);
+ QTest::touchEvent(&window, device).press(0, p1, &window);
+ QTest::touchEvent(&window, device).move(0, p2, &window);
+ QTest::touchEvent(&window, device).release(0, p2, &window);
+
+ QCOMPARE(item->m_touchEvents.count(), 3);
+ QCOMPARE(item->m_mouseEvents.count(), acceptTouch ? 0 : 3);
+ QCOMPARE(childView->m_mouseEvents.count(), 0);
+ for (const QMouseEvent &ev : item->m_mouseEvents)
+ QCOMPARE(ev.source(), Qt::MouseEventSynthesizedByQt);
+}
+
QTEST_MAIN(tst_qquickwidget)
#include "tst_qquickwidget.moc"
diff --git a/tools/qmlprofiler/qmlprofilerapplication.cpp b/tools/qmlprofiler/qmlprofilerapplication.cpp
index 033492b516..33be8722c0 100644
--- a/tools/qmlprofiler/qmlprofilerapplication.cpp
+++ b/tools/qmlprofiler/qmlprofilerapplication.cpp
@@ -91,6 +91,8 @@ QmlProfilerApplication::QmlProfilerApplication(int &argc, char **argv) :
connect(&m_connection, &QQmlDebugConnection::connected,
this, &QmlProfilerApplication::connected);
+ connect(&m_connection, &QQmlDebugConnection::disconnected,
+ this, &QmlProfilerApplication::disconnected);
connect(&m_qmlProfilerClient, &QmlProfilerClient::enabledChanged,
this, &QmlProfilerApplication::traceClientEnabledChanged);
@@ -512,6 +514,22 @@ void QmlProfilerApplication::connected()
.arg(endpoint).arg(m_recording ? tr("on") : tr("off")));
}
+void QmlProfilerApplication::disconnected()
+{
+ if (m_runMode == AttachMode) {
+ int exitCode = 0;
+ if (m_recording) {
+ logError("Connection dropped while recording, last trace is damaged!");
+ exitCode = 2;
+ }
+
+ if (!m_interactive )
+ exit(exitCode);
+ else
+ m_qmlProfilerClient.clearPendingData();
+ }
+}
+
void QmlProfilerApplication::processHasOutput()
{
Q_ASSERT(m_process);
diff --git a/tools/qmlprofiler/qmlprofilerapplication.h b/tools/qmlprofiler/qmlprofilerapplication.h
index 13f0f041f0..4946622902 100644
--- a/tools/qmlprofiler/qmlprofilerapplication.h
+++ b/tools/qmlprofiler/qmlprofilerapplication.h
@@ -69,6 +69,7 @@ private:
void run();
void tryToConnect();
void connected();
+ void disconnected();
void processHasOutput();
void processFinished();