OpenCoverage

qquickdraghandler.cpp

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/handlers/qquickdraghandler.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2017 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtQuick module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include "qquickdraghandler_p.h"-
41#include <private/qquickwindow_p.h>-
42#include <QDebug>-
43-
44QT_BEGIN_NAMESPACE-
45-
46/*!-
47 \qmltype DragHandler-
48 \instantiates QQuickDragHandler-
49 \inherits SinglePointHandler-
50 \inqmlmodule Qt.labs.handlers-
51 \ingroup qtquick-handlers-
52 \brief Handler for dragging.-
53-
54 DragHandler is a handler that is used to interactively move an Item.-
55 Like other Pointer Handlers, by default it is fully functional, and-
56 manipulates its \l {PointerHandler::target} {target}.-
57-
58 \snippet pointerHandlers/dragHandler.qml 0-
59-
60 It has properties to restrict the range of dragging.-
61-
62 If it is declared within one Item but is assigned a different-
63 \l {PointerHandler::target} {target}, then it handles events within the-
64 bounds of the \l {PointerHandler::parent} {parent} Item but-
65 manipulates the \c target Item instead:-
66-
67 \snippet pointerHandlers/dragHandlerDifferentTarget.qml 0-
68-
69 A third way to use it is to set \l {PointerHandler::target} {target} to-
70 \c null and react to property changes in some other way:-
71-
72 \snippet pointerHandlers/dragHandlerNullTarget.qml 0-
73-
74 At this time, drag-and-drop is not yet supported.-
75-
76 \sa Drag, MouseArea-
77*/-
78-
79QQuickDragHandler::QQuickDragHandler(QObject *parent)-
80 : QQuickSinglePointHandler(parent)-
81{-
82}
executed 396 times by 3 tests: end of block
Executed by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
396
83-
84QQuickDragHandler::~QQuickDragHandler()-
85{-
86}-
87-
88bool QQuickDragHandler::wantsEventPoint(QQuickEventPoint *point)-
89{-
90 // If we've already been interested in a point, stay interested, even if it has strayed outside bounds.-
91 return ((point->state() != QQuickEventPoint::Pressed && this->point().id() == point->pointId())
executed 4376 times by 3 tests: return ((point->state() != QQuickEventPoint::Pressed && this->point().id() == point->pointId()) || QQuickSinglePointHandler::wantsEventPoint(point));
Executed by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
4376
92 || QQuickSinglePointHandler::wantsEventPoint(point));
executed 4376 times by 3 tests: return ((point->state() != QQuickEventPoint::Pressed && this->point().id() == point->pointId()) || QQuickSinglePointHandler::wantsEventPoint(point));
Executed by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
4376
93}-
94-
95bool QQuickDragHandler::targetContains(QQuickEventPoint *point)-
96{-
97 Q_ASSERT(parentItem() && target());-
98 return target()->contains(localTargetPosition(point));
executed 78 times by 3 tests: return target()->contains(localTargetPosition(point));
Executed by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
78
99}-
100-
101QPointF QQuickDragHandler::localTargetPosition(QQuickEventPoint *point)-
102{-
103 QPointF pos = point->position();-
104 if (target() != parentItem())
target() != parentItem()Description
TRUEevaluated 210 times by 2 tests
Evaluated by:
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
FALSEevaluated 318 times by 2 tests
Evaluated by:
  • tst_flickableinterop
  • tst_qquickdraghandler
210-318
105 pos = parentItem()->mapToItem(target(), pos);
executed 210 times by 2 tests: pos = parentItem()->mapToItem(target(), pos);
Executed by:
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
210
106 return pos;
executed 528 times by 3 tests: return pos;
Executed by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
528
107}-
108-
109void QQuickDragHandler::onGrabChanged(QQuickPointerHandler *grabber, QQuickEventPoint::GrabState stateChange, QQuickEventPoint *point)-
110{-
111 if (grabber == this && stateChange == QQuickEventPoint::GrabExclusive) {
grabber == thisDescription
TRUEevaluated 244 times by 3 tests
Evaluated by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
FALSEnever evaluated
stateChange ==...:GrabExclusiveDescription
TRUEevaluated 74 times by 3 tests
Evaluated by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
FALSEevaluated 170 times by 3 tests
Evaluated by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
0-244
112 // In case the grab got handed over from another grabber, we might not get the Press.-
113 if (!m_pressedInsideTarget) {
!m_pressedInsideTargetDescription
TRUEevaluated 12 times by 1 test
Evaluated by:
  • tst_qquickdraghandler
FALSEevaluated 62 times by 3 tests
Evaluated by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
12-62
114 if (target())
target()Description
TRUEevaluated 12 times by 1 test
Evaluated by:
  • tst_qquickdraghandler
FALSEnever evaluated
0-12
115 m_pressTargetPos = QPointF(target()->width(), target()->height()) / 2;
executed 12 times by 1 test: m_pressTargetPos = QPointF(target()->width(), target()->height()) / 2;
Executed by:
  • tst_qquickdraghandler
12
116 m_pressScenePos = point->scenePosition();-
117 } else if (m_pressTargetPos.isNull()) {
executed 12 times by 1 test: end of block
Executed by:
  • tst_qquickdraghandler
m_pressTargetPos.isNull()Description
TRUEnever evaluated
FALSEevaluated 62 times by 3 tests
Evaluated by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
0-62
118 if (target())
target()Description
TRUEnever evaluated
FALSEnever evaluated
0
119 m_pressTargetPos = localTargetPosition(point);
never executed: m_pressTargetPos = localTargetPosition(point);
0
120 m_pressScenePos = point->scenePosition();-
121 }
never executed: end of block
0
122 }
executed 74 times by 3 tests: end of block
Executed by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
74
123 QQuickSinglePointHandler::onGrabChanged(grabber, stateChange, point);-
124}
executed 244 times by 3 tests: end of block
Executed by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
244
125-
126void QQuickDragHandler::onActiveChanged()-
127{-
128 if (!active()) {
!active()Description
TRUEevaluated 74 times by 3 tests
Evaluated by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
FALSEevaluated 74 times by 3 tests
Evaluated by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
74
129 m_pressTargetPos = QPointF();-
130 m_pressScenePos = m_pressTargetPos;-
131 m_pressedInsideTarget = false;-
132 }
executed 74 times by 3 tests: end of block
Executed by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
74
133}
executed 148 times by 3 tests: end of block
Executed by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
148
134-
135void QQuickDragHandler::handleEventPoint(QQuickEventPoint *point)-
136{-
137 point->setAccepted();-
138 switch (point->state()) {-
139 case QQuickEventPoint::Pressed:
executed 78 times by 3 tests: case QQuickEventPoint::Pressed:
Executed by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
78
140 if (target()) {
target()Description
TRUEevaluated 78 times by 3 tests
Evaluated by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
FALSEnever evaluated
0-78
141 m_pressedInsideTarget = targetContains(point);-
142 m_pressTargetPos = localTargetPosition(point);-
143 }
executed 78 times by 3 tests: end of block
Executed by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
78
144 m_pressScenePos = point->scenePosition();-
145 setPassiveGrab(point);-
146 break;
executed 78 times by 3 tests: break;
Executed by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
78
147 case QQuickEventPoint::Updated: {
executed 586 times by 3 tests: case QQuickEventPoint::Updated:
Executed by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
586
148 QVector2D accumulatedDragDelta = QVector2D(point->scenePosition() - m_pressScenePos);-
149 if (active()) {
active()Description
TRUEevaluated 372 times by 3 tests
Evaluated by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
FALSEevaluated 214 times by 3 tests
Evaluated by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
214-372
150 // update translation property. Make sure axis is respected for it.-
151 if (!m_xAxis.enabled())
!m_xAxis.enabled()Description
TRUEevaluated 228 times by 2 tests
Evaluated by:
  • tst_flickableinterop
  • tst_qquickdraghandler
FALSEevaluated 144 times by 3 tests
Evaluated by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
144-228
152 accumulatedDragDelta.setX(0);
executed 228 times by 2 tests: accumulatedDragDelta.setX(0);
Executed by:
  • tst_flickableinterop
  • tst_qquickdraghandler
228
153 if (!m_yAxis.enabled())
!m_yAxis.enabled()Description
TRUEnever evaluated
FALSEevaluated 372 times by 3 tests
Evaluated by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
0-372
154 accumulatedDragDelta.setY(0);
never executed: accumulatedDragDelta.setY(0);
0
155 setTranslation(accumulatedDragDelta);-
156-
157 if (target() && target()->parentItem()) {
target()Description
TRUEevaluated 372 times by 3 tests
Evaluated by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
FALSEnever evaluated
target()->parentItem()Description
TRUEevaluated 372 times by 3 tests
Evaluated by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
FALSEnever evaluated
0-372
158 const QPointF newTargetTopLeft = localTargetPosition(point) - m_pressTargetPos;-
159 const QPointF xformOrigin = target()->transformOriginPoint();-
160 const QPointF targetXformOrigin = newTargetTopLeft + xformOrigin;-
161 QPointF pos = target()->parentItem()->mapFromItem(target(), targetXformOrigin);-
162 pos -= xformOrigin;-
163 QPointF targetItemPos = target()->position();-
164 if (!m_xAxis.enabled())
!m_xAxis.enabled()Description
TRUEevaluated 228 times by 2 tests
Evaluated by:
  • tst_flickableinterop
  • tst_qquickdraghandler
FALSEevaluated 144 times by 3 tests
Evaluated by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
144-228
165 pos.setX(targetItemPos.x());
executed 228 times by 2 tests: pos.setX(targetItemPos.x());
Executed by:
  • tst_flickableinterop
  • tst_qquickdraghandler
228
166 if (!m_yAxis.enabled())
!m_yAxis.enabled()Description
TRUEnever evaluated
FALSEevaluated 372 times by 3 tests
Evaluated by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
0-372
167 pos.setY(targetItemPos.y());
never executed: pos.setY(targetItemPos.y());
0
168 enforceAxisConstraints(&pos);-
169 moveTarget(pos, point);-
170 }
executed 372 times by 3 tests: end of block
Executed by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
372
171 } else if (!point->exclusiveGrabber() &&
executed 372 times by 3 tests: end of block
Executed by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
!point->exclusiveGrabber()Description
TRUEevaluated 214 times by 3 tests
Evaluated by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
FALSEnever evaluated
0-372
172 ((m_xAxis.enabled() && QQuickWindowPrivate::dragOverThreshold(accumulatedDragDelta.x(), Qt::XAxis, point)) ||
m_xAxis.enabled()Description
TRUEevaluated 116 times by 3 tests
Evaluated by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
FALSEevaluated 98 times by 2 tests
Evaluated by:
  • tst_flickableinterop
  • tst_qquickdraghandler
QQuickWindowPr...:XAxis, point)Description
TRUEevaluated 30 times by 3 tests
Evaluated by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
FALSEevaluated 86 times by 3 tests
Evaluated by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
30-116
173 (m_yAxis.enabled() && QQuickWindowPrivate::dragOverThreshold(accumulatedDragDelta.y(), Qt::YAxis, point)))) {
m_yAxis.enabled()Description
TRUEevaluated 184 times by 3 tests
Evaluated by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
FALSEnever evaluated
QQuickWindowPr...:YAxis, point)Description
TRUEevaluated 44 times by 2 tests
Evaluated by:
  • tst_flickableinterop
  • tst_qquickdraghandler
FALSEevaluated 140 times by 3 tests
Evaluated by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
0-184
174 setExclusiveGrab(point);-
175 if (auto parent = parentItem()) {
auto parent = parentItem()Description
TRUEevaluated 74 times by 3 tests
Evaluated by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
FALSEnever evaluated
0-74
176 if (point->pointerEvent()->asPointerTouchEvent())
point->pointer...erTouchEvent()Description
TRUEevaluated 64 times by 3 tests
Evaluated by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
FALSEevaluated 10 times by 2 tests
Evaluated by:
  • tst_flickableinterop
  • tst_qquickdraghandler
10-64
177 parent->setKeepTouchGrab(true);
executed 64 times by 3 tests: parent->setKeepTouchGrab(true);
Executed by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
64
178 // tablet and mouse are treated the same by Item's legacy event handling, and-
179 // touch becomes synth-mouse for Flickable, so we need to prevent stealing-
180 // mouse grab too, whenever dragging occurs in an enabled direction-
181 parent->setKeepMouseGrab(true);-
182 }
executed 74 times by 3 tests: end of block
Executed by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
74
183 }
executed 74 times by 3 tests: end of block
Executed by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
74
184 } break;
executed 586 times by 3 tests: break;
Executed by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
586
185 default:
executed 92 times by 3 tests: default:
Executed by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
92
186 break;
executed 92 times by 3 tests: break;
Executed by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
92
187 }-
188}-
189-
190void QQuickDragHandler::enforceConstraints()-
191{-
192 if (!target() || !target()->parentItem())
!target()Description
TRUEnever evaluated
FALSEnever evaluated
!target()->parentItem()Description
TRUEnever evaluated
FALSEnever evaluated
0
193 return;
never executed: return;
0
194 QPointF pos = target()->position();-
195 QPointF copy(pos);-
196 enforceAxisConstraints(&pos);-
197 if (pos != copy)
pos != copyDescription
TRUEnever evaluated
FALSEnever evaluated
0
198 target()->setPosition(pos);
never executed: target()->setPosition(pos);
0
199}
never executed: end of block
0
200-
201void QQuickDragHandler::enforceAxisConstraints(QPointF *localPos)-
202{-
203 if (m_xAxis.enabled())
m_xAxis.enabled()Description
TRUEevaluated 144 times by 3 tests
Evaluated by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
FALSEevaluated 228 times by 2 tests
Evaluated by:
  • tst_flickableinterop
  • tst_qquickdraghandler
144-228
204 localPos->setX(qBound(m_xAxis.minimum(), localPos->x(), m_xAxis.maximum()));
executed 144 times by 3 tests: localPos->setX(qBound(m_xAxis.minimum(), localPos->x(), m_xAxis.maximum()));
Executed by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
144
205 if (m_yAxis.enabled())
m_yAxis.enabled()Description
TRUEevaluated 372 times by 3 tests
Evaluated by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
FALSEnever evaluated
0-372
206 localPos->setY(qBound(m_yAxis.minimum(), localPos->y(), m_yAxis.maximum()));
executed 372 times by 3 tests: localPos->setY(qBound(m_yAxis.minimum(), localPos->y(), m_yAxis.maximum()));
Executed by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
372
207}
executed 372 times by 3 tests: end of block
Executed by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
372
208-
209void QQuickDragHandler::setTranslation(const QVector2D &trans)-
210{-
211 if (trans == m_translation) // fuzzy compare?
trans == m_translationDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_flickableinterop
FALSEevaluated 368 times by 3 tests
Evaluated by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
4-368
212 return;
executed 4 times by 1 test: return;
Executed by:
  • tst_flickableinterop
4
213 m_translation = trans;-
214 emit translationChanged();-
215}
executed 368 times by 3 tests: end of block
Executed by:
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_qquickdraghandler
368
216-
217/*!-
218 \qmlpropertygroup QtQuick::DragHandler::xAxis-
219 \qmlproperty real QtQuick::DragHandler::xAxis.minimum-
220 \qmlproperty real QtQuick::DragHandler::xAxis.maximum-
221 \qmlproperty bool QtQuick::DragHandler::xAxis.enabled-
222-
223 \c xAxis controls the constraints for horizontal dragging.-
224-
225 \c minimum is the minimum acceptable value of \l {Item::x}{x} to be-
226 applied to the \l {PointerHandler::target} {target}.-
227 \c maximum is the maximum acceptable value of \l {Item::x}{x} to be-
228 applied to the \l {PointerHandler::target} {target}.-
229 If \c enabled is true, horizontal dragging is allowed.-
230 */-
231-
232/*!-
233 \qmlpropertygroup QtQuick::DragHandler::yAxis-
234 \qmlproperty real QtQuick::DragHandler::yAxis.minimum-
235 \qmlproperty real QtQuick::DragHandler::yAxis.maximum-
236 \qmlproperty bool QtQuick::DragHandler::yAxis.enabled-
237-
238 \c yAxis controls the constraints for vertical dragging.-
239-
240 \c minimum is the minimum acceptable value of \l {Item::y}{y} to be-
241 applied to the \l {PointerHandler::target} {target}.-
242 \c maximum is the maximum acceptable value of \l {Item::y}{y} to be-
243 applied to the \l {PointerHandler::target} {target}.-
244 If \c enabled is true, vertical dragging is allowed.-
245 */-
246-
247/*!-
248 \readonly-
249 \qmlproperty QVector2D QtQuick::DragHandler::translation-
250-
251 The translation since the gesture began.-
252*/-
253-
254QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.0