Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/handlers/qquickmultipointhandler.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||
2 | - | |||||||||||||
3 | QQuickMultiPointHandler::QQuickMultiPointHandler(QObject *parent, int minimumPointCount) | - | ||||||||||||
4 | : QQuickPointerDeviceHandler(parent) | - | ||||||||||||
5 | , m_minimumPointCount(minimumPointCount) | - | ||||||||||||
6 | , m_maximumPointCount(-1) | - | ||||||||||||
7 | { | - | ||||||||||||
8 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||
9 | - | |||||||||||||
10 | QQuickMultiPointHandler::~QQuickMultiPointHandler() | - | ||||||||||||
11 | { | - | ||||||||||||
12 | } | - | ||||||||||||
13 | - | |||||||||||||
14 | bool QQuickMultiPointHandler::wantsPointerEvent(QQuickPointerEvent *event) | - | ||||||||||||
15 | { | - | ||||||||||||
16 | if (!QQuickPointerDeviceHandler::wantsPointerEvent(event)
| 0-83 | ||||||||||||
17 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||
18 | - | |||||||||||||
19 | - | |||||||||||||
20 | if (event->asPointerNativeGestureEvent()
| 0-83 | ||||||||||||
21 | return never executed: true;return true; never executed: return true; | 0 | ||||||||||||
22 | - | |||||||||||||
23 | - | |||||||||||||
24 | if (hasCurrentPoints(event)
| 27-56 | ||||||||||||
25 | return executed 27 times by 1 test: true;return true; Executed by:
executed 27 times by 1 test: return true; Executed by:
| 27 | ||||||||||||
26 | - | |||||||||||||
27 | const QVector<QQuickEventPoint *> candidatePoints = eligiblePoints(event); | - | ||||||||||||
28 | const bool ret = (candidatePoints.size() >= minimumPointCount()
| 2-50 | ||||||||||||
29 | if (ret
| 4-52 | ||||||||||||
30 | m_currentPoints = candidatePoints; executed 4 times by 1 test: m_currentPoints = candidatePoints; Executed by:
| 4 | ||||||||||||
31 | return executed 56 times by 1 test: ret;return ret; Executed by:
executed 56 times by 1 test: return ret; Executed by:
| 56 | ||||||||||||
32 | } | - | ||||||||||||
33 | - | |||||||||||||
34 | void QQuickMultiPointHandler::handlePointerEventImpl(QQuickPointerEvent *event) | - | ||||||||||||
35 | { | - | ||||||||||||
36 | QQuickPointerHandler::handlePointerEventImpl(event); | - | ||||||||||||
37 | m_centroid.reset(m_currentPoints); | - | ||||||||||||
38 | centroidChanged(); | - | ||||||||||||
39 | } executed 31 times by 1 test: end of block Executed by:
| 31 | ||||||||||||
40 | - | |||||||||||||
41 | void QQuickMultiPointHandler::onActiveChanged() | - | ||||||||||||
42 | { | - | ||||||||||||
43 | if (active()
| 4 | ||||||||||||
44 | m_centroid.m_sceneGrabPosition = m_centroid.m_scenePosition; | - | ||||||||||||
45 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||
46 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||
47 | - | |||||||||||||
48 | QVector<QQuickEventPoint *> QQuickMultiPointHandler::eligiblePoints(QQuickPointerEvent *event) | - | ||||||||||||
49 | { | - | ||||||||||||
50 | QVector<QQuickEventPoint *> ret; | - | ||||||||||||
51 | int c = event->pointCount(); | - | ||||||||||||
52 | - | |||||||||||||
53 | - | |||||||||||||
54 | - | |||||||||||||
55 | bool stealingAllowed = event->isPressEvent()
| 10-46 | ||||||||||||
56 | for (int i = 0; i < c
| 56-96 | ||||||||||||
57 | QQuickEventPoint *p = event->point(i); | - | ||||||||||||
58 | if (!stealingAllowed
| 44-52 | ||||||||||||
59 | QObject *exclusiveGrabber = p->exclusiveGrabber(); | - | ||||||||||||
60 | if (exclusiveGrabber
| 4-34 | ||||||||||||
61 | continue; executed 14 times by 1 test: continue; Executed by:
| 14 | ||||||||||||
62 | } executed 38 times by 1 test: end of block Executed by:
| 38 | ||||||||||||
63 | if (p->state() != QQuickEventPoint::Released
| 0-72 | ||||||||||||
64 | ret << p; executed 72 times by 1 test: ret << p; Executed by:
| 72 | ||||||||||||
65 | } executed 82 times by 1 test: end of block Executed by:
| 82 | ||||||||||||
66 | return executed 56 times by 1 test: ret;return ret; Executed by:
executed 56 times by 1 test: return ret; Executed by:
| 56 | ||||||||||||
67 | } | - | ||||||||||||
68 | void QQuickMultiPointHandler::setMinimumPointCount(int c) | - | ||||||||||||
69 | { | - | ||||||||||||
70 | if (m_minimumPointCount == c
| 0-4 | ||||||||||||
71 | return; never executed: return; | 0 | ||||||||||||
72 | - | |||||||||||||
73 | m_minimumPointCount = c; | - | ||||||||||||
74 | minimumPointCountChanged(); | - | ||||||||||||
75 | if (m_maximumPointCount < 0
| 0-4 | ||||||||||||
76 | maximumPointCountChanged(); executed 4 times by 1 test: maximumPointCountChanged(); Executed by:
| 4 | ||||||||||||
77 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||
78 | void QQuickMultiPointHandler::setMaximumPointCount(int maximumPointCount) | - | ||||||||||||
79 | { | - | ||||||||||||
80 | if (m_maximumPointCount == maximumPointCount
| 0 | ||||||||||||
81 | return; never executed: return; | 0 | ||||||||||||
82 | - | |||||||||||||
83 | m_maximumPointCount = maximumPointCount; | - | ||||||||||||
84 | maximumPointCountChanged(); | - | ||||||||||||
85 | } never executed: end of block | 0 | ||||||||||||
86 | - | |||||||||||||
87 | bool QQuickMultiPointHandler::hasCurrentPoints(QQuickPointerEvent *event) | - | ||||||||||||
88 | { | - | ||||||||||||
89 | bool ret = true; | - | ||||||||||||
90 | int c = event->pointCount(); | - | ||||||||||||
91 | if (c < m_currentPoints.size()
| 34-49 | ||||||||||||
92 | return executed 34 times by 1 test: false;return false; Executed by:
executed 34 times by 1 test: return false; Executed by:
| 34 | ||||||||||||
93 | - | |||||||||||||
94 | - | |||||||||||||
95 | for (int i = 0; ret
| 16-142 | ||||||||||||
96 | if (event->point(i)->state() == QQuickEventPoint::Released
| 6-109 | ||||||||||||
97 | return executed 6 times by 1 test: false;return false; Executed by:
executed 6 times by 1 test: return false; Executed by:
| 6 | ||||||||||||
98 | bool found = false; | - | ||||||||||||
99 | int pointId = event->point(i)->pointId(); | - | ||||||||||||
100 | for (QQuickEventPoint *o : qAsConst(m_currentPoints)) | - | ||||||||||||
101 | if (o
| 0-285 | ||||||||||||
102 | found = true; executed 93 times by 1 test: found = true; Executed by:
| 93 | ||||||||||||
103 | if (!found
| 16-93 | ||||||||||||
104 | ret = false; executed 16 times by 1 test: ret = false; Executed by:
| 16 | ||||||||||||
105 | } executed 109 times by 1 test: end of block Executed by:
| 109 | ||||||||||||
106 | return executed 43 times by 1 test: ret;return ret; Executed by:
executed 43 times by 1 test: return ret; Executed by:
| 43 | ||||||||||||
107 | } | - | ||||||||||||
108 | - | |||||||||||||
109 | qreal QQuickMultiPointHandler::averageTouchPointDistance(const QPointF &ref) | - | ||||||||||||
110 | { | - | ||||||||||||
111 | qreal ret = 0; | - | ||||||||||||
112 | if (__builtin_expect(!!(m_currentPoints.size() == 0), false)
| 0-33 | ||||||||||||
113 | return never executed: ret;return ret; never executed: return ret; | 0 | ||||||||||||
114 | for (QQuickEventPoint *point : qAsConst(m_currentPoints)) | - | ||||||||||||
115 | ret += QVector2D(point->scenePosition() - ref).length(); executed 99 times by 1 test: ret += QVector2D(point->scenePosition() - ref).length(); Executed by:
| 99 | ||||||||||||
116 | return executed 33 times by 1 test: ret / m_currentPoints.size();return ret / m_currentPoints.size(); Executed by:
executed 33 times by 1 test: return ret / m_currentPoints.size(); Executed by:
| 33 | ||||||||||||
117 | } | - | ||||||||||||
118 | - | |||||||||||||
119 | qreal QQuickMultiPointHandler::averageStartingDistance(const QPointF &ref) | - | ||||||||||||
120 | { | - | ||||||||||||
121 | - | |||||||||||||
122 | qreal ret = 0; | - | ||||||||||||
123 | if (__builtin_expect(!!(m_currentPoints.size() == 0), false)
| 0 | ||||||||||||
124 | return never executed: ret;return ret; never executed: return ret; | 0 | ||||||||||||
125 | for (QQuickEventPoint *point : qAsConst(m_currentPoints)) | - | ||||||||||||
126 | ret += QVector2D(point->sceneGrabPosition() - ref).length(); never executed: ret += QVector2D(point->sceneGrabPosition() - ref).length(); | 0 | ||||||||||||
127 | return never executed: ret / m_currentPoints.size();return ret / m_currentPoints.size(); never executed: return ret / m_currentPoints.size(); | 0 | ||||||||||||
128 | } | - | ||||||||||||
129 | - | |||||||||||||
130 | QVector<QQuickMultiPointHandler::PointData> QQuickMultiPointHandler::angles(const QPointF &ref) const | - | ||||||||||||
131 | { | - | ||||||||||||
132 | QVector<PointData> angles; | - | ||||||||||||
133 | angles.reserve(m_currentPoints.count()); | - | ||||||||||||
134 | for (QQuickEventPoint *point : qAsConst(m_currentPoints)) { | - | ||||||||||||
135 | qreal angle = QLineF(ref, point->scenePosition()).angle(); | - | ||||||||||||
136 | angles.append(PointData(point->pointId(), -angle)); | - | ||||||||||||
137 | } executed 99 times by 1 test: end of block Executed by:
| 99 | ||||||||||||
138 | return executed 33 times by 1 test: angles;return angles; Executed by:
executed 33 times by 1 test: return angles; Executed by:
| 33 | ||||||||||||
139 | } | - | ||||||||||||
140 | - | |||||||||||||
141 | qreal QQuickMultiPointHandler::averageAngleDelta(const QVector<PointData> &old, const QVector<PointData> &newAngles) | - | ||||||||||||
142 | { | - | ||||||||||||
143 | qreal avgAngleDelta = 0; | - | ||||||||||||
144 | int numSamples = 0; | - | ||||||||||||
145 | - | |||||||||||||
146 | auto oldBegin = old.constBegin(); | - | ||||||||||||
147 | - | |||||||||||||
148 | for (PointData newData : newAngles) { | - | ||||||||||||
149 | quint64 id = newData.id; | - | ||||||||||||
150 | auto it = std::find_if(oldBegin, old.constEnd(), [id] (PointData pd) { return executed 87 times by 1 test: pd.id == id;return pd.id == id; Executed by:
executed 87 times by 1 test: });return pd.id == id; Executed by:
| 87 | ||||||||||||
151 | qreal angleD = 0; | - | ||||||||||||
152 | if (it != old.constEnd()
| 0-87 | ||||||||||||
153 | PointData oldData = *it; | - | ||||||||||||
154 | - | |||||||||||||
155 | - | |||||||||||||
156 | - | |||||||||||||
157 | - | |||||||||||||
158 | angleD = remainder(newData.angle - oldData.angle, qreal(360)); | - | ||||||||||||
159 | - | |||||||||||||
160 | - | |||||||||||||
161 | if (it == oldBegin
| 0-87 | ||||||||||||
162 | ++ executed 87 times by 1 test: oldBegin;++oldBegin; Executed by:
executed 87 times by 1 test: ++oldBegin; Executed by:
| 87 | ||||||||||||
163 | numSamples++; | - | ||||||||||||
164 | } executed 87 times by 1 test: end of block Executed by:
| 87 | ||||||||||||
165 | avgAngleDelta += angleD; | - | ||||||||||||
166 | } executed 87 times by 1 test: end of block Executed by:
| 87 | ||||||||||||
167 | if (numSamples > 1
| 0-29 | ||||||||||||
168 | avgAngleDelta /= numSamples; executed 29 times by 1 test: avgAngleDelta /= numSamples; Executed by:
| 29 | ||||||||||||
169 | - | |||||||||||||
170 | return executed 29 times by 1 test: avgAngleDelta;return avgAngleDelta; Executed by:
executed 29 times by 1 test: return avgAngleDelta; Executed by:
| 29 | ||||||||||||
171 | } | - | ||||||||||||
172 | - | |||||||||||||
173 | void QQuickMultiPointHandler::acceptPoints(const QVector<QQuickEventPoint *> &points) | - | ||||||||||||
174 | { | - | ||||||||||||
175 | for (QQuickEventPoint* point : points) | - | ||||||||||||
176 | point->setAccepted(); executed 87 times by 1 test: point->setAccepted(); Executed by:
| 87 | ||||||||||||
177 | } executed 29 times by 1 test: end of block Executed by:
| 29 | ||||||||||||
178 | - | |||||||||||||
179 | bool QQuickMultiPointHandler::grabPoints(QVector<QQuickEventPoint *> points) | - | ||||||||||||
180 | { | - | ||||||||||||
181 | bool allowed = true; | - | ||||||||||||
182 | for (QQuickEventPoint* point : points) { | - | ||||||||||||
183 | if (!canGrab(point)
| 0-12 | ||||||||||||
184 | allowed = false; | - | ||||||||||||
185 | break; never executed: break; | 0 | ||||||||||||
186 | } | - | ||||||||||||
187 | } executed 12 times by 1 test: end of block Executed by:
| 12 | ||||||||||||
188 | if (allowed
| 0-4 | ||||||||||||
189 | for (QQuickEventPoint* point : points) | - | ||||||||||||
190 | setExclusiveGrab(point); executed 12 times by 1 test: setExclusiveGrab(point); Executed by:
| 12 | ||||||||||||
191 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||
192 | return executed 4 times by 1 test: allowed;return allowed; Executed by:
executed 4 times by 1 test: return allowed; Executed by:
| 4 | ||||||||||||
193 | } | - | ||||||||||||
194 | - | |||||||||||||
195 | - | |||||||||||||
Switch to Source code | Preprocessed file |