on xenial help sign in
The GenericApp approach doesn't work
commitdff962bb5326a4ad629f61b5c95aad7f42934e9a authorDaniel d'Andrada <daniel.dandrada@canonical.com> dateThu 19 Mar 2015, 12:18 (12 years ago) parente0c46f5
6 files changed+31−124
tests/mocks/Unity/Application/CMakeLists.txt−1 tests/mocks/Unity/Application/GenericApp.cpp−51 tests/mocks/Unity/Application/GenericApp.h−67 tests/mocks/Unity/Application/MirSurfaceItem.cpp+13 tests/mocks/Unity/Application/MirSurfaceItem.h+17 tests/mocks/Unity/Application/SurfaceManager.cpp+1−5
tests/mocks/Unity/Application/CMakeLists.txt−1
@@ -6,7 +6,6 @@ set(FakeUnityApplicationQml_SOURCES
66 ApplicationManager.cpp
77 ApplicationScreenshotProvider.cpp
88 ApplicationTestInterface.cpp
9− GenericApp.cpp
109 MirSurfaceItem.cpp
1110 MirSurfaceItemModel.h
1211 ObjectListModel.h
tests/mocks/Unity/Application/GenericApp.cppdeleted−51
@@ -1,51 +0,0 @@
1−/*
2− * Copyright (C) 2014-2015 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−#include "GenericApp.h"
18−#include "Session.h"
19−
20−#include <paths.h>
21−
22−#include <QString>
23−
24−#include <QDebug>
25−
26−GenericApp::GenericApp(const QString& name,
27− GenericApp::Type type,
28− GenericApp::State state,
29− const QUrl& screenshot,
30− const QString &qmlFilePath,
31− QQuickItem *parent)
32− : MirSurfaceItem(name, type, state, screenshot, qmlFilePath, parent)
33− , m_touchPressCount(0)
34− , m_touchReleaseCount(0)
35−{
36−}
37−
38−GenericApp::~GenericApp()
39−{
40−}
41−
42−void GenericApp::touchEvent(QTouchEvent * event)
43−{
44− if (event->touchPointStates() & Qt::TouchPointPressed) {
45− ++m_touchPressCount;
46− Q_EMIT touchPressCountChanged(m_touchPressCount);
47− } else if (event->touchPointStates() & Qt::TouchPointReleased) {
48− ++m_touchReleaseCount;
49− Q_EMIT touchReleaseCountChanged(m_touchReleaseCount);
50− }
51−}
tests/mocks/Unity/Application/GenericApp.hdeleted−67
@@ -1,67 +0,0 @@
1−/*
2− * Copyright (C) 2014-2015 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−#ifndef GENERICAPP_H
18−#define GENERICAPP_H
19−
20−#include "MirSurfaceItemModel.h"
21−#include "MirSurfaceItem.h"
22−
23−#include <QUrl>
24−
25−class GenericApp : public MirSurfaceItem
26−{
27− Q_OBJECT
28−
29− Q_PROPERTY(int touchPressCount READ touchPressCount WRITE setTouchPressCount NOTIFY touchPressCountChanged
30− DESIGNABLE false)
31− Q_PROPERTY(int touchReleaseCount READ touchReleaseCount WRITE setTouchReleaseCount NOTIFY touchReleaseCountChanged
32− DESIGNABLE false)
33−
34−public:
35− ~GenericApp();
36−
37− int touchPressCount() const { return m_touchPressCount; }
38− void setTouchPressCount(int count) { m_touchPressCount = count; Q_EMIT touchPressCountChanged(count); }
39−
40− int touchReleaseCount() const { return m_touchReleaseCount; }
41− void setTouchReleaseCount(int count) { m_touchReleaseCount = count; Q_EMIT touchReleaseCountChanged(count); }
42−
43−Q_SIGNALS:
44− void touchPressCountChanged(int count);
45− void touchReleaseCountChanged(int count);
46−
47−protected:
48− void touchEvent(QTouchEvent * event) override;
49−
50−private:
51− explicit GenericApp(const QString& name,
52− Type type,
53− State state,
54− const QUrl& screenshot,
55− const QString &qmlFilePath = QString(),
56− QQuickItem *parent = 0);
57−
58− int m_touchPressCount;
59− int m_touchReleaseCount;
60−
61− friend class SurfaceManager;
62−};
63−
64−Q_DECLARE_METATYPE(GenericApp*)
65−Q_DECLARE_METATYPE(QList<GenericApp*>)
66−
67−#endif // GENERICAPP_H
tests/mocks/Unity/Application/MirSurfaceItem.cpp+13
@@ -42,6 +42,8 @@ MirSurfaceItem::MirSurfaceItem(const QString& name,
4242 , m_orientationAngle(Angle0)
4343 , m_qmlItem(nullptr)
4444 , m_screenshotUrl(screenshot)
45+ , m_touchPressCount(0)
46+ , m_touchReleaseCount(0)
4547{
4648 QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
4749
@@ -169,3 +171,14 @@ void MirSurfaceItem::createQmlContentItem()
169171 screenshotSource.write(QVariant::fromValue(m_screenshotUrl));
170172 }
171173}
174+
175+void MirSurfaceItem::touchEvent(QTouchEvent * event)
176+{
177+ if (event->touchPointStates() & Qt::TouchPointPressed) {
178+ ++m_touchPressCount;
179+ Q_EMIT touchPressCountChanged(m_touchPressCount);
180+ } else if (event->touchPointStates() & Qt::TouchPointReleased) {
181+ ++m_touchReleaseCount;
182+ Q_EMIT touchReleaseCountChanged(m_touchReleaseCount);
183+ }
184+}
tests/mocks/Unity/Application/MirSurfaceItem.h+17
@@ -37,6 +37,10 @@ class MirSurfaceItem : public QQuickItem
3737 Q_PROPERTY(bool live READ live NOTIFY liveChanged)
3838 Q_PROPERTY(OrientationAngle orientationAngle READ orientationAngle WRITE setOrientationAngle
3939 NOTIFY orientationAngleChanged DESIGNABLE false)
40+ Q_PROPERTY(int touchPressCount READ touchPressCount WRITE setTouchPressCount
41+ NOTIFY touchPressCountChanged DESIGNABLE false)
42+ Q_PROPERTY(int touchReleaseCount READ touchReleaseCount WRITE setTouchReleaseCount
43+ NOTIFY touchReleaseCountChanged DESIGNABLE false)
4044
4145public:
4246 enum Type {
@@ -85,11 +89,19 @@ public:
8589 Q_INVOKABLE void setState(State newState);
8690 Q_INVOKABLE void release();
8791
92+ int touchPressCount() const { return m_touchPressCount; }
93+ void setTouchPressCount(int count) { m_touchPressCount = count; Q_EMIT touchPressCountChanged(count); }
94+
95+ int touchReleaseCount() const { return m_touchReleaseCount; }
96+ void setTouchReleaseCount(int count) { m_touchReleaseCount = count; Q_EMIT touchReleaseCountChanged(count); }
97+
8898Q_SIGNALS:
8999 void typeChanged(Type);
90100 void stateChanged(State);
91101 void liveChanged(bool live);
92102 void orientationAngleChanged(OrientationAngle angle);
103+ void touchPressCountChanged(int count);
104+ void touchReleaseCountChanged(int count);
93105
94106 // internal mock use
95107 void deregister();
@@ -102,6 +114,8 @@ protected:
102114 const QString &qmlFilePath = QString(),
103115 QQuickItem *parent = 0);
104116
117+ void touchEvent(QTouchEvent * event) override;
118+
105119private Q_SLOTS:
106120 void onComponentStatusChanged(QQmlComponent::Status status);
107121
@@ -120,6 +134,9 @@ private:
120134 QQuickItem *m_qmlItem;
121135 QUrl m_screenshotUrl;
122136
137+ int m_touchPressCount;
138+ int m_touchReleaseCount;
139+
123140 friend class SurfaceManager;
124141};
125142
tests/mocks/Unity/Application/SurfaceManager.cpp+1−5
@@ -16,7 +16,6 @@
1616
1717#include "SurfaceManager.h"
1818
19−#include "GenericApp.h"
2019#include "VirtualKeyboard.h"
2120
2221#include <paths.h>
@@ -42,10 +41,7 @@ MirSurfaceItem *SurfaceManager::createSurface(const QString& name,
4241 MirSurfaceItem::State state,
4342 const QUrl& screenshot)
4443{
45− MirSurfaceItem* surface = new GenericApp(name,
46− type,
47− state,
48− screenshot);
44+ MirSurfaceItem* surface = new MirSurfaceItem(name, type, state, screenshot);
4945 Q_EMIT surfaceCreated(surface);
5046 return surface;
5147}