OpenCoverage

qquicktranslate.cpp

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/items/qquicktranslate.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
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 "qquicktranslate_p.h"-
41#include "qquickitem_p.h"-
42-
43QT_BEGIN_NAMESPACE-
44-
45class QQuickTranslatePrivate : public QQuickTransformPrivate-
46{-
47public:-
48 QQuickTranslatePrivate()-
49 : x(0), y(0) {}
executed 6 times by 2 tests: end of block
Executed by:
  • tst_examples
  • tst_qquickitem2
6
50-
51 qreal x;-
52 qreal y;-
53};-
54-
55-
56/*!-
57 \qmltype Translate-
58 \instantiates QQuickTranslate-
59 \inqmlmodule QtQuick-
60 \ingroup qtquick-visual-transforms-
61 \brief Provides a way to move an Item without changing its x or y properties.-
62-
63 The Translate type provides independent control over position in addition-
64 to the Item's x and y properties.-
65-
66 The following example moves the Y axis of the \l Rectangle items while-
67 still allowing the \l Row to lay the items out as if they had not been-
68 transformed:-
69-
70 \qml-
71 import QtQuick 2.0-
72-
73 Row {-
74 Rectangle {-
75 width: 100; height: 100-
76 color: "blue"-
77 transform: Translate { y: 20 }-
78 }-
79 Rectangle {-
80 width: 100; height: 100-
81 color: "red"-
82 transform: Translate { y: -20 }-
83 }-
84 }-
85 \endqml-
86-
87 \image translate.png-
88*/-
89QQuickTranslate::QQuickTranslate(QObject *parent)-
90: QQuickTransform(*new QQuickTranslatePrivate, parent)-
91{-
92}
executed 6 times by 2 tests: end of block
Executed by:
  • tst_examples
  • tst_qquickitem2
6
93-
94-
95QQuickTranslate::~QQuickTranslate()-
96{-
97}-
98/*!-
99 \qmlproperty real QtQuick::Translate::x-
100-
101 The translation along the X axis.-
102-
103 The default value is 0.0.-
104*/-
105qreal QQuickTranslate::x() const-
106{-
107 Q_D(const QQuickTranslate);-
108 return d->x;
never executed: return d->x;
0
109}-
110-
111void QQuickTranslate::setX(qreal x)-
112{-
113 Q_D(QQuickTranslate);-
114 if (d->x == x)
d->x == xDescription
TRUEnever evaluated
FALSEevaluated 6 times by 2 tests
Evaluated by:
  • tst_examples
  • tst_qquickitem2
0-6
115 return;
never executed: return;
0
116 d->x = x;-
117 update();-
118 emit xChanged();-
119}
executed 6 times by 2 tests: end of block
Executed by:
  • tst_examples
  • tst_qquickitem2
6
120-
121/*!-
122 \qmlproperty real QtQuick::Translate::y-
123-
124 The translation along the Y axis.-
125-
126 The default value is 0.0.-
127*/-
128qreal QQuickTranslate::y() const-
129{-
130 Q_D(const QQuickTranslate);-
131 return d->y;
never executed: return d->y;
0
132}-
133void QQuickTranslate::setY(qreal y)-
134{-
135 Q_D(QQuickTranslate);-
136 if (d->y == y)
d->y == yDescription
TRUEnever evaluated
FALSEevaluated 6 times by 2 tests
Evaluated by:
  • tst_examples
  • tst_qquickitem2
0-6
137 return;
never executed: return;
0
138 d->y = y;-
139 update();-
140 emit yChanged();-
141}
executed 6 times by 2 tests: end of block
Executed by:
  • tst_examples
  • tst_qquickitem2
6
142-
143void QQuickTranslate::applyTo(QMatrix4x4 *matrix) const-
144{-
145 Q_D(const QQuickTranslate);-
146 matrix->translate(d->x, d->y, 0);-
147}
executed 6 times by 2 tests: end of block
Executed by:
  • tst_examples
  • tst_qquickitem2
6
148-
149class QQuickScalePrivate : public QQuickTransformPrivate-
150{-
151public:-
152 QQuickScalePrivate()-
153 : xScale(1), yScale(1), zScale(1) {}
executed 8 times by 3 tests: end of block
Executed by:
  • tst_qquickitem
  • tst_qquickitem2
  • tst_qquickstates
8
154 QVector3D origin;-
155 qreal xScale;-
156 qreal yScale;-
157 qreal zScale;-
158};-
159-
160/*!-
161 \qmltype Scale-
162 \instantiates QQuickScale-
163 \inqmlmodule QtQuick-
164 \ingroup qtquick-visual-transforms-
165 \brief Provides a way to scale an Item.-
166-
167 The Scale type provides a way to scale an \l Item through a scale-type-
168 transform.-
169-
170 It allows different scaling values for the x and y axes, and allows the-
171 scale to be relative to an arbitrary point. This gives more control over-
172 item scaling than the \l{Item::}{scale} property.-
173-
174 The following example scales the X axis of the Rectangle, relative to-
175 its interior point (25, 25):-
176-
177 \qml-
178 Rectangle {-
179 width: 100; height: 100-
180 color: "blue"-
181 transform: Scale { origin.x: 25; origin.y: 25; xScale: 3}-
182 }-
183 \endqml-
184-
185 \sa Rotation, Translate-
186*/-
187QQuickScale::QQuickScale(QObject *parent)-
188 : QQuickTransform(*new QQuickScalePrivate, parent)-
189{-
190}
executed 8 times by 3 tests: end of block
Executed by:
  • tst_qquickitem
  • tst_qquickitem2
  • tst_qquickstates
8
191-
192QQuickScale::~QQuickScale()-
193{-
194}-
195-
196/*!-
197 \qmlpropertygroup QtQuick::Scale::origin-
198 \qmlproperty real QtQuick::Scale::origin.x-
199 \qmlproperty real QtQuick::Scale::origin.y-
200-
201 This property holds the point that the item is scaled from (that is,-
202 the point that stays fixed relative to the parent as the rest of the-
203 item grows).-
204-
205 The default value of the origin is (0, 0).-
206*/-
207QVector3D QQuickScale::origin() const-
208{-
209 Q_D(const QQuickScale);-
210 return d->origin;
never executed: return d->origin;
0
211}-
212void QQuickScale::setOrigin(const QVector3D &point)-
213{-
214 Q_D(QQuickScale);-
215 if (d->origin == point)
d->origin == pointDescription
TRUEnever evaluated
FALSEnever evaluated
0
216 return;
never executed: return;
0
217 d->origin = point;-
218 update();-
219 emit originChanged();-
220}
never executed: end of block
0
221-
222/*!-
223 \qmlproperty real QtQuick::Scale::xScale-
224-
225 The scaling factor for the X axis.-
226-
227 The default value is 1.0.-
228*/-
229qreal QQuickScale::xScale() const-
230{-
231 Q_D(const QQuickScale);-
232 return d->xScale;
never executed: return d->xScale;
0
233}-
234void QQuickScale::setXScale(qreal scale)-
235{-
236 Q_D(QQuickScale);-
237 if (d->xScale == scale)
d->xScale == scaleDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_qquickitem
FALSEevaluated 6 times by 2 tests
Evaluated by:
  • tst_qquickitem2
  • tst_qquickstates
2-6
238 return;
executed 2 times by 1 test: return;
Executed by:
  • tst_qquickitem
2
239 d->xScale = scale;-
240 update();-
241 emit xScaleChanged();-
242 emit scaleChanged();-
243}
executed 6 times by 2 tests: end of block
Executed by:
  • tst_qquickitem2
  • tst_qquickstates
6
244-
245/*!-
246 \qmlproperty real QtQuick::Scale::yScale-
247-
248 The scaling factor for the Y axis.-
249-
250 The default value is 1.0.-
251*/-
252qreal QQuickScale::yScale() const-
253{-
254 Q_D(const QQuickScale);-
255 return d->yScale;
never executed: return d->yScale;
0
256}-
257void QQuickScale::setYScale(qreal scale)-
258{-
259 Q_D(QQuickScale);-
260 if (d->yScale == scale)
d->yScale == scaleDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_qquickitem
FALSEevaluated 6 times by 2 tests
Evaluated by:
  • tst_qquickitem2
  • tst_qquickstates
2-6
261 return;
executed 2 times by 1 test: return;
Executed by:
  • tst_qquickitem
2
262 d->yScale = scale;-
263 update();-
264 emit yScaleChanged();-
265 emit scaleChanged();-
266}
executed 6 times by 2 tests: end of block
Executed by:
  • tst_qquickitem2
  • tst_qquickstates
6
267-
268qreal QQuickScale::zScale() const-
269{-
270 Q_D(const QQuickScale);-
271 return d->zScale;
never executed: return d->zScale;
0
272}-
273void QQuickScale::setZScale(qreal scale)-
274{-
275 Q_D(QQuickScale);-
276 if (d->zScale == scale)
d->zScale == scaleDescription
TRUEnever evaluated
FALSEnever evaluated
0
277 return;
never executed: return;
0
278 d->zScale = scale;-
279 update();-
280 emit zScaleChanged();-
281 emit scaleChanged();-
282}
never executed: end of block
0
283-
284void QQuickScale::applyTo(QMatrix4x4 *matrix) const-
285{-
286 Q_D(const QQuickScale);-
287 matrix->translate(d->origin);-
288 matrix->scale(d->xScale, d->yScale, d->zScale);-
289 matrix->translate(-d->origin);-
290}
executed 6 times by 2 tests: end of block
Executed by:
  • tst_qquickitem2
  • tst_qquickstates
6
291-
292class QQuickRotationPrivate : public QQuickTransformPrivate-
293{-
294public:-
295 QQuickRotationPrivate()-
296 : angle(0), axis(0, 0, 1) {}
executed 838 times by 5 tests: end of block
Executed by:
  • tst_examples
  • tst_qquickflipable
  • tst_qquickitem2
  • tst_qquickpathview
  • tst_qquickstates
838
297 QVector3D origin;-
298 qreal angle;-
299 QVector3D axis;-
300};-
301-
302/*!-
303 \qmltype Rotation-
304 \instantiates QQuickRotation-
305 \inqmlmodule QtQuick-
306 \ingroup qtquick-visual-transforms-
307 \brief Provides a way to rotate an Item.-
308-
309 The Rotation type provides a way to rotate an \l Item through a-
310 rotation-type transform.-
311-
312 It allows (z axis) rotation to be relative to an arbitrary point, and also-
313 provides a way to specify 3D-like rotations for Items. This gives more-
314 control over item rotation than the \l{Item::}{rotation} property.-
315-
316 The following example rotates a Rectangle around its interior point-
317 (25, 25):-
318-
319 \qml-
320 Rectangle {-
321 width: 100; height: 100-
322 color: "blue"-
323 transform: Rotation { origin.x: 25; origin.y: 25; angle: 45}-
324 }-
325 \endqml-
326-
327 For 3D-like item rotations, you must specify the axis of rotation in-
328 addition to the origin point. The following example shows various 3D-like-
329 rotations applied to an \l Image.-
330-
331 \snippet qml/rotation.qml 0-
332-
333 \image axisrotation.png-
334-
335 \sa {customitems/dialcontrol}{Dial Control example}, {Qt Quick Demo - Clocks}-
336*/-
337QQuickRotation::QQuickRotation(QObject *parent)-
338 : QQuickTransform(*new QQuickRotationPrivate, parent)-
339{-
340}
executed 838 times by 5 tests: end of block
Executed by:
  • tst_examples
  • tst_qquickflipable
  • tst_qquickitem2
  • tst_qquickpathview
  • tst_qquickstates
838
341-
342QQuickRotation::~QQuickRotation()-
343{-
344}-
345-
346/*!-
347 \qmlpropertygroup QtQuick::Rotation::origin-
348 \qmlproperty real QtQuick::Rotation::origin.x-
349 \qmlproperty real QtQuick::Rotation::origin.y-
350-
351 The origin point of the rotation (i.e., the point that stays fixed-
352 relative to the parent as the rest of the item rotates). By default-
353 the origin is (0, 0).-
354*/-
355QVector3D QQuickRotation::origin() const-
356{-
357 Q_D(const QQuickRotation);-
358 return d->origin;
executed 2468 times by 3 tests: return d->origin;
Executed by:
  • tst_examples
  • tst_qquickflipable
  • tst_qquickpathview
2468
359}-
360-
361void QQuickRotation::setOrigin(const QVector3D &point)-
362{-
363 Q_D(QQuickRotation);-
364 if (d->origin == point)
d->origin == pointDescription
TRUEevaluated 822 times by 3 tests
Evaluated by:
  • tst_examples
  • tst_qquickflipable
  • tst_qquickpathview
FALSEevaluated 1646 times by 3 tests
Evaluated by:
  • tst_examples
  • tst_qquickflipable
  • tst_qquickpathview
822-1646
365 return;
executed 822 times by 3 tests: return;
Executed by:
  • tst_examples
  • tst_qquickflipable
  • tst_qquickpathview
822
366 d->origin = point;-
367 update();-
368 emit originChanged();-
369}
executed 1646 times by 3 tests: end of block
Executed by:
  • tst_examples
  • tst_qquickflipable
  • tst_qquickpathview
1646
370-
371/*!-
372 \qmlproperty real QtQuick::Rotation::angle-
373-
374 The angle to rotate, in degrees clockwise.-
375*/-
376qreal QQuickRotation::angle() const-
377{-
378 Q_D(const QQuickRotation);-
379 return d->angle;
executed 8 times by 2 tests: return d->angle;
Executed by:
  • tst_examples
  • tst_qquickflipable
8
380}-
381void QQuickRotation::setAngle(qreal angle)-
382{-
383 Q_D(QQuickRotation);-
384 if (d->angle == angle)
d->angle == angleDescription
TRUEevaluated 18 times by 3 tests
Evaluated by:
  • tst_examples
  • tst_qquickflipable
  • tst_qquickpathview
FALSEevaluated 88 times by 5 tests
Evaluated by:
  • tst_examples
  • tst_qquickflipable
  • tst_qquickitem2
  • tst_qquickpathview
  • tst_qquickstates
18-88
385 return;
executed 18 times by 3 tests: return;
Executed by:
  • tst_examples
  • tst_qquickflipable
  • tst_qquickpathview
18
386 d->angle = angle;-
387 update();-
388 emit angleChanged();-
389}
executed 88 times by 5 tests: end of block
Executed by:
  • tst_examples
  • tst_qquickflipable
  • tst_qquickitem2
  • tst_qquickpathview
  • tst_qquickstates
88
390-
391/*!-
392 \qmlpropertygroup QtQuick::Rotation::axis-
393 \qmlproperty real QtQuick::Rotation::axis.x-
394 \qmlproperty real QtQuick::Rotation::axis.y-
395 \qmlproperty real QtQuick::Rotation::axis.z-
396-
397 The axis to rotate around. For simple (2D) rotation around a point, you-
398 do not need to specify an axis, as the default axis is the z axis-
399 (\c{ axis { x: 0; y: 0; z: 1 } }).-
400-
401 For a typical 3D-like rotation you will usually specify both the origin-
402 and the axis.-
403-
404 \image 3d-rotation-axis.png-
405*/-
406QVector3D QQuickRotation::axis() const-
407{-
408 Q_D(const QQuickRotation);-
409 return d->axis;
executed 838 times by 4 tests: return d->axis;
Executed by:
  • tst_examples
  • tst_qquickflipable
  • tst_qquickpathview
  • tst_qquickstates
838
410}-
411void QQuickRotation::setAxis(const QVector3D &axis)-
412{-
413 Q_D(QQuickRotation);-
414 if (d->axis == axis)
d->axis == axisDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_examples
FALSEevaluated 834 times by 4 tests
Evaluated by:
  • tst_examples
  • tst_qquickflipable
  • tst_qquickpathview
  • tst_qquickstates
4-834
415 return;
executed 4 times by 1 test: return;
Executed by:
  • tst_examples
4
416 d->axis = axis;-
417 update();-
418 emit axisChanged();-
419}
executed 834 times by 4 tests: end of block
Executed by:
  • tst_examples
  • tst_qquickflipable
  • tst_qquickpathview
  • tst_qquickstates
834
420-
421void QQuickRotation::setAxis(Qt::Axis axis)-
422{-
423 switch (axis)-
424 {-
425 case Qt::XAxis:
never executed: case Qt::XAxis:
0
426 setAxis(QVector3D(1, 0, 0));-
427 break;
never executed: break;
0
428 case Qt::YAxis:
never executed: case Qt::YAxis:
0
429 setAxis(QVector3D(0, 1, 0));-
430 break;
never executed: break;
0
431 case Qt::ZAxis:
never executed: case Qt::ZAxis:
0
432 setAxis(QVector3D(0, 0, 1));-
433 break;
never executed: break;
0
434 }-
435}
never executed: end of block
0
436-
437class QGraphicsRotation {-
438public:-
439 static inline void projectedRotate(QMatrix4x4 *matrix, qreal angle, qreal x, qreal y, qreal z)-
440 {-
441 matrix->projectedRotate(angle, x, y, z);-
442 }
executed 41 times by 4 tests: end of block
Executed by:
  • tst_examples
  • tst_qquickflipable
  • tst_qquickitem2
  • tst_qquickstates
41
443};-
444-
445void QQuickRotation::applyTo(QMatrix4x4 *matrix) const-
446{-
447 Q_D(const QQuickRotation);-
448-
449 if (d->angle == 0. || d->axis.isNull())
d->angle == 0.Description
TRUEevaluated 338 times by 3 tests
Evaluated by:
  • tst_examples
  • tst_qquickflipable
  • tst_qquickpathview
FALSEevaluated 41 times by 4 tests
Evaluated by:
  • tst_examples
  • tst_qquickflipable
  • tst_qquickitem2
  • tst_qquickstates
d->axis.isNull()Description
TRUEnever evaluated
FALSEevaluated 41 times by 4 tests
Evaluated by:
  • tst_examples
  • tst_qquickflipable
  • tst_qquickitem2
  • tst_qquickstates
0-338
450 return;
executed 338 times by 3 tests: return;
Executed by:
  • tst_examples
  • tst_qquickflipable
  • tst_qquickpathview
338
451-
452 matrix->translate(d->origin);-
453 QGraphicsRotation::projectedRotate(matrix, d->angle, d->axis.x(), d->axis.y(), d->axis.z());-
454 matrix->translate(-d->origin);-
455}
executed 41 times by 4 tests: end of block
Executed by:
  • tst_examples
  • tst_qquickflipable
  • tst_qquickitem2
  • tst_qquickstates
41
456-
457class QQuickMatrix4x4Private : public QQuickTransformPrivate-
458{-
459public:-
460 QQuickMatrix4x4Private()-
461 : matrix() {}
executed 6 times by 2 tests: end of block
Executed by:
  • tst_multipointtoucharea_interop
  • tst_qquickitem2
6
462 QMatrix4x4 matrix;-
463};-
464-
465/*!-
466 \qmltype Matrix4x4-
467 \instantiates QQuickMatrix4x4-
468 \inqmlmodule QtQuick-
469 \ingroup qtquick-visual-transforms-
470 \since 5.3-
471 \brief Provides a way to apply a 4x4 tranformation matrix to an \l Item.-
472-
473 The Matrix4x4 type provides a way to apply a transformation to an-
474 \l Item through a 4x4 matrix.-
475-
476 It allows for a combination of rotation, scale, translatation and shearing-
477 by using just one tranformation provided in a 4x4-matrix.-
478-
479 The following example rotates a Rectangle 45 degress (PI/4):-
480-
481 \qml-
482 Rectangle {-
483 width: 100-
484 height: 100-
485 color: "red"-
486-
487 transform: Matrix4x4 {-
488 property real a: Math.PI / 4-
489 matrix: Qt.matrix4x4(Math.cos(a), -Math.sin(a), 0, 0,-
490 Math.sin(a), Math.cos(a), 0, 0,-
491 0, 0, 1, 0,-
492 0, 0, 0, 1)-
493 }-
494 }-
495 \endqml-
496*/-
497QQuickMatrix4x4::QQuickMatrix4x4(QObject *parent)-
498 : QQuickTransform(*new QQuickMatrix4x4Private, parent)-
499{-
500}
executed 6 times by 2 tests: end of block
Executed by:
  • tst_multipointtoucharea_interop
  • tst_qquickitem2
6
501-
502QQuickMatrix4x4::~QQuickMatrix4x4()-
503{-
504}-
505-
506/*!-
507 \qmlproperty QMatrix4x4 QtQuick::Matrix4x4::matrix-
508-
509 4x4-matrix which will be used in the tranformation of an \l Item-
510*/-
511QMatrix4x4 QQuickMatrix4x4::matrix() const-
512{-
513 Q_D(const QQuickMatrix4x4);-
514 return d->matrix;
never executed: return d->matrix;
0
515}-
516-
517void QQuickMatrix4x4::setMatrix(const QMatrix4x4 &matrix)-
518{-
519 Q_D(QQuickMatrix4x4);-
520 if (d->matrix == matrix)
d->matrix == matrixDescription
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_qquickitem2
0-2
521 return;
never executed: return;
0
522 d->matrix = matrix;-
523 update();-
524 emit matrixChanged();-
525}
executed 2 times by 1 test: end of block
Executed by:
  • tst_qquickitem2
2
526-
527void QQuickMatrix4x4::applyTo(QMatrix4x4 *matrix) const-
528{-
529 Q_D(const QQuickMatrix4x4);-
530 *matrix *= d->matrix;-
531}
executed 2 times by 1 test: end of block
Executed by:
  • tst_qquickitem2
2
532-
533QT_END_NAMESPACE-
534-
535#include "moc_qquicktranslate_p.cpp"-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.0