Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qgraphicstransform.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
53#include "qgraphicstransform.h"
54#include "qgraphicsitem_p.h"
56#include <QDebug>
57#include <QtCore/qmath.h>
58#include <QtCore/qnumeric.h>
59
61
65
67{
68 if (item == i)
69 return;
70
71 if (item) {
74
76 Q_ASSERT(d_ptr->transformData);
78 d_ptr->dirtySceneTransform = 1;
79 item = nullptr;
80 }
81
82 item = i;
83}
84
90
98
103{
105 d->setItem(nullptr);
106}
107
115
137{
139 if (d->item)
140 d->updateItem(d->item);
141}
142
176
184
191
202{
203 Q_D(const QGraphicsScale);
204 return d->origin;
205}
207{
208 Q_D(QGraphicsScale);
209 if (d->origin == point)
210 return;
211 d->origin = point;
212 update();
214}
215
228{
229 Q_D(const QGraphicsScale);
230 return d->xScale;
231}
233{
234 Q_D(QGraphicsScale);
235 if (d->xScale == scale)
236 return;
237 d->xScale = scale;
238 update();
241}
242
255{
256 Q_D(const QGraphicsScale);
257 return d->yScale;
258}
260{
261 Q_D(QGraphicsScale);
262 if (d->yScale == scale)
263 return;
264 d->yScale = scale;
265 update();
268}
269
282{
283 Q_D(const QGraphicsScale);
284 return d->zScale;
285}
287{
288 Q_D(QGraphicsScale);
289 if (d->zScale == scale)
290 return;
291 d->zScale = scale;
292 update();
295}
296
301{
302 Q_D(const QGraphicsScale);
303 matrix->translate(d->origin);
304 matrix->scale(d->xScale, d->yScale, d->zScale);
305 matrix->translate(-d->origin);
306}
307
391
399
406
417{
418 Q_D(const QGraphicsRotation);
419 return d->origin;
420}
422{
424 if (d->origin == point)
425 return;
426 d->origin = point;
427 update();
429}
430
445{
446 Q_D(const QGraphicsRotation);
447 return d->angle;
448}
450{
452 if (d->angle == angle)
453 return;
454 d->angle = angle;
455 update();
457}
458
488{
489 Q_D(const QGraphicsRotation);
490 return d->axis;
491}
493{
495 if (d->axis == axis)
496 return;
497 d->axis = axis;
498 update();
500}
501
522{
523 switch (axis)
524 {
525 case Qt::XAxis:
526 setAxis(QVector3D(1, 0, 0));
527 break;
528 case Qt::YAxis:
529 setAxis(QVector3D(0, 1, 0));
530 break;
531 case Qt::ZAxis:
532 setAxis(QVector3D(0, 0, 1));
533 break;
534 }
535}
536
541{
542 Q_D(const QGraphicsRotation);
543
544 if (d->angle == 0. || d->axis.isNull() || qIsNaN(d->angle))
545 return;
546
547 matrix->translate(d->origin);
548 matrix->projectedRotate(d->angle, d->axis.x(), d->axis.y(), d->axis.z());
549 matrix->translate(-d->origin);
550}
551
561
562#include "moc_qgraphicstransform.cpp"
TransformData * transformData
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
QScopedPointer< QGraphicsItemPrivate > d_ptr
void prepareGeometryChange()
Prepares the item for a geometry change.
The QGraphicsRotation class provides a rotation transformation around a given axis.
QVector3D axis
a rotation axis, specified by a vector in 3D space.
void originChanged()
This signal is emitted whenever the origin has changed.
void setAxis(const QVector3D &axis)
QGraphicsRotation(QObject *parent=nullptr)
Constructs a new QGraphicsRotation with the given parent.
~QGraphicsRotation()
Destroys the graphics rotation.
void axisChanged()
This signal is emitted whenever the axis of the object changes.
void setOrigin(const QVector3D &point)
QVector3D origin
the origin of the rotation in 3D space.
void angleChanged()
This signal is emitted whenever the angle has changed.
void applyTo(QMatrix4x4 *matrix) const override
\reimp
qreal angle
the angle for clockwise rotation, in degrees.
The QGraphicsScale class provides a scale transformation.
void applyTo(QMatrix4x4 *matrix) const override
\reimp
void setOrigin(const QVector3D &point)
void yScaleChanged()
qreal xScale
the horizontal scale factor.
~QGraphicsScale()
Destroys the graphics scale.
void zScaleChanged()
void xScaleChanged()
void originChanged()
QGraphicsScale emits this signal when its origin changes.
QGraphicsScale(QObject *parent=nullptr)
Constructs an empty QGraphicsScale object with the given parent.
void scaleChanged()
This signal is emitted whenever the xScale, yScale, or zScale of the object changes.
qreal zScale
the depth scale factor.
qreal yScale
the vertical scale factor.
QVector3D origin
the origin of the scale in 3D space.
void setItem(QGraphicsItem *item)
static void updateItem(QGraphicsItem *item)
The QGraphicsTransform class is an abstract base class for building advanced transformations on QGrap...
~QGraphicsTransform()
Destroys the graphics transform.
QGraphicsTransform(QObject *parent=nullptr)
Constructs a new QGraphicsTransform with the given parent.
void update()
Notifies that this transform operation has changed its parameters in such a way that applyTo() will r...
qsizetype removeAll(const AT &t)
Definition qlist.h:592
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition qmatrix4x4.h:25
\inmodule QtCore
Definition qobject.h:103
T * data() const noexcept
Returns the value of the pointer referenced by this object.
The QVector3D class represents a vector or vertex in 3D space.
Definition qvectornd.h:171
Combined button and popup list for selecting options.
@ ZAxis
@ XAxis
@ YAxis
bool qIsNaN(qfloat16 f) noexcept
Definition qfloat16.h:284
GLfloat angle
GLuint GLenum matrix
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLfloat GLfloat p
[1]
GLenum GLenum GLenum GLenum GLenum scale
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define emit
double qreal
Definition qtypes.h:187
QGraphicsItem * item
QList< QGraphicsTransform * > graphicsTransforms