Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/util/qquickpathinterpolator.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||
---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||
2 | ** | - | ||||||
3 | ** Copyright (C) 2016 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 "qquickpathinterpolator_p.h" | - | ||||||
41 | - | |||||||
42 | #include "qquickpath_p.h" | - | ||||||
43 | - | |||||||
44 | QT_BEGIN_NAMESPACE | - | ||||||
45 | - | |||||||
46 | /*! | - | ||||||
47 | \qmltype PathInterpolator | - | ||||||
48 | \instantiates QQuickPathInterpolator | - | ||||||
49 | \inqmlmodule QtQuick | - | ||||||
50 | \ingroup qtquick-animation-control | - | ||||||
51 | \brief Specifies how to manually animate along a path. | - | ||||||
52 | - | |||||||
53 | PathInterpolator provides \c x, \c y, and \c angle information for a particular \c progress | - | ||||||
54 | along a path. | - | ||||||
55 | - | |||||||
56 | In the following example, we animate a green rectangle along a bezier path. | - | ||||||
57 | - | |||||||
58 | \snippet qml/pathinterpolator.qml 0 | - | ||||||
59 | */ | - | ||||||
60 | - | |||||||
61 | QQuickPathInterpolator::QQuickPathInterpolator(QObject *parent) : | - | ||||||
62 | QObject(parent), _path(nullptr), _x(0), _y(0), _angle(0), _progress(0) | - | ||||||
63 | { | - | ||||||
64 | } executed 10 times by 2 tests: end of block Executed by:
| 10 | ||||||
65 | - | |||||||
66 | /*! | - | ||||||
67 | \qmlproperty Path QtQuick::PathInterpolator::path | - | ||||||
68 | This property holds the path to interpolate. | - | ||||||
69 | - | |||||||
70 | For more information on defining a path see the \l Path documentation. | - | ||||||
71 | */ | - | ||||||
72 | QQuickPath *QQuickPathInterpolator::path() const | - | ||||||
73 | { | - | ||||||
74 | return _path; never executed: return _path; | 0 | ||||||
75 | } | - | ||||||
76 | - | |||||||
77 | void QQuickPathInterpolator::setPath(QQuickPath *path) | - | ||||||
78 | { | - | ||||||
79 | if (_path == path)
| 0-10 | ||||||
80 | return; never executed: return; | 0 | ||||||
81 | if (_path)
| 0-10 | ||||||
82 | disconnect(_path, SIGNAL(changed()), this, SLOT(_q_pathUpdated())); never executed: disconnect(_path, qFlagLocation("2""changed()" "\0" __FILE__ ":" "82"), this, qFlagLocation("1""_q_pathUpdated()" "\0" __FILE__ ":" "82")); | 0 | ||||||
83 | _path = path; | - | ||||||
84 | connect(_path, SIGNAL(changed()), this, SLOT(_q_pathUpdated())); | - | ||||||
85 | emit pathChanged(); | - | ||||||
86 | } executed 10 times by 2 tests: end of block Executed by:
| 10 | ||||||
87 | - | |||||||
88 | /*! | - | ||||||
89 | \qmlproperty real QtQuick::PathInterpolator::progress | - | ||||||
90 | This property holds the current progress along the path. | - | ||||||
91 | - | |||||||
92 | Typical usage of PathInterpolator is to set the progress | - | ||||||
93 | (often via a NumberAnimation), and read the corresponding | - | ||||||
94 | values for x, y, and angle (often via bindings to these values). | - | ||||||
95 | - | |||||||
96 | Progress ranges from 0.0 to 1.0. | - | ||||||
97 | */ | - | ||||||
98 | qreal QQuickPathInterpolator::progress() const | - | ||||||
99 | { | - | ||||||
100 | return _progress; executed 24 times by 1 test: return _progress; Executed by:
| 24 | ||||||
101 | } | - | ||||||
102 | - | |||||||
103 | void QQuickPathInterpolator::setProgress(qreal progress) | - | ||||||
104 | { | - | ||||||
105 | progress = qMin(qMax(progress, (qreal)0.0), (qreal)1.0); | - | ||||||
106 | - | |||||||
107 | if (progress == _progress)
| 4-16 | ||||||
108 | return; executed 4 times by 2 tests: return; Executed by:
| 4 | ||||||
109 | _progress = progress; | - | ||||||
110 | emit progressChanged(); | - | ||||||
111 | _q_pathUpdated(); | - | ||||||
112 | } executed 16 times by 1 test: end of block Executed by:
| 16 | ||||||
113 | - | |||||||
114 | /*! | - | ||||||
115 | \qmlproperty real QtQuick::PathInterpolator::x | - | ||||||
116 | \qmlproperty real QtQuick::PathInterpolator::y | - | ||||||
117 | - | |||||||
118 | These properties hold the position of the path at \l progress. | - | ||||||
119 | */ | - | ||||||
120 | qreal QQuickPathInterpolator::x() const | - | ||||||
121 | { | - | ||||||
122 | return _x; executed 26 times by 2 tests: return _x; Executed by:
| 26 | ||||||
123 | } | - | ||||||
124 | - | |||||||
125 | qreal QQuickPathInterpolator::y() const | - | ||||||
126 | { | - | ||||||
127 | return _y; executed 26 times by 2 tests: return _y; Executed by:
| 26 | ||||||
128 | } | - | ||||||
129 | - | |||||||
130 | /*! | - | ||||||
131 | \qmlproperty real QtQuick::PathInterpolator::angle | - | ||||||
132 | - | |||||||
133 | This property holds the angle of the path tangent at \l progress. | - | ||||||
134 | - | |||||||
135 | Angles are reported clockwise, with zero degrees at the 3 o'clock position. | - | ||||||
136 | */ | - | ||||||
137 | qreal QQuickPathInterpolator::angle() const | - | ||||||
138 | { | - | ||||||
139 | return _angle; executed 24 times by 2 tests: return _angle; Executed by:
| 24 | ||||||
140 | } | - | ||||||
141 | - | |||||||
142 | void QQuickPathInterpolator::_q_pathUpdated() | - | ||||||
143 | { | - | ||||||
144 | if (! _path)
| 0-26 | ||||||
145 | return; never executed: return; | 0 | ||||||
146 | - | |||||||
147 | qreal angle = 0; | - | ||||||
148 | const QPointF pt = _path->sequentialPointAt(_progress, &angle); | - | ||||||
149 | - | |||||||
150 | if (_x != pt.x()) {
| 2-24 | ||||||
151 | _x = pt.x(); | - | ||||||
152 | emit xChanged(); | - | ||||||
153 | } executed 24 times by 2 tests: end of block Executed by:
| 24 | ||||||
154 | - | |||||||
155 | if (_y != pt.y()) {
| 4-22 | ||||||
156 | _y = pt.y(); | - | ||||||
157 | emit yChanged(); | - | ||||||
158 | } executed 22 times by 2 tests: end of block Executed by:
| 22 | ||||||
159 | - | |||||||
160 | //convert to clockwise | - | ||||||
161 | angle = qreal(360) - angle; | - | ||||||
162 | if (qFuzzyCompare(angle, qreal(360)))
| 12-14 | ||||||
163 | angle = qreal(0); executed 12 times by 2 tests: angle = qreal(0); Executed by:
| 12 | ||||||
164 | - | |||||||
165 | if (angle != _angle) {
| 8-18 | ||||||
166 | _angle = angle; | - | ||||||
167 | emit angleChanged(); | - | ||||||
168 | } executed 18 times by 1 test: end of block Executed by:
| 18 | ||||||
169 | } executed 26 times by 2 tests: end of block Executed by:
| 26 | ||||||
170 | - | |||||||
171 | QT_END_NAMESPACE | - | ||||||
172 | - | |||||||
173 | #include "moc_qquickpathinterpolator_p.cpp" | - | ||||||
Source code | Switch to Preprocessed file |