From 20befe6f00c84934a7ab9e9c27c8ac85cd0dac1d Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Fri, 10 Jan 2020 12:10:03 +0100 Subject: Don't use deprecated QMatrix class anymore Task-number: QTBUG-46653 Change-Id: I9944b62141d7054e3935000a819bebc5fd54df6c Reviewed-by: Volker Hilsheimer --- src/svg/qsvggenerator.cpp | 5 ++-- src/svg/qsvghandler.cpp | 23 +++++++++--------- src/svg/qsvgrenderer.cpp | 36 ++++++++++++++++++++++++---- src/svg/qsvgrenderer.h | 5 ++++ src/svg/qsvgstyle.cpp | 8 +++---- src/svg/qsvgstyle_p.h | 10 ++++---- src/svg/qsvgtinydocument.cpp | 7 +++--- src/svg/qsvgtinydocument_p.h | 3 ++- tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp | 10 ++++---- 9 files changed, 72 insertions(+), 35 deletions(-) diff --git a/src/svg/qsvggenerator.cpp b/src/svg/qsvggenerator.cpp index 360b02b..59dd7fc 100644 --- a/src/svg/qsvggenerator.cpp +++ b/src/svg/qsvggenerator.cpp @@ -53,6 +53,7 @@ #include "qbuffer.h" #include "qmath.h" #include "qbitmap.h" +#include "qtransform.h" #include "qdebug.h" @@ -117,7 +118,7 @@ public: QBrush brush; QPen pen; - QMatrix matrix; + QTransform matrix; QFont font; QString generateGradientName() { @@ -1009,7 +1010,7 @@ void QSvgPaintEngine::updateState(const QPaintEngineState &state) } if (flags & QPaintEngine::DirtyTransform) { - d->matrix = state.transform().toAffine(); + d->matrix = state.transform(); *d->stream << "transform=\"matrix(" << d->matrix.m11() << ',' << d->matrix.m12() << ',' << d->matrix.m21() << ',' << d->matrix.m22() << ',' diff --git a/src/svg/qsvghandler.cpp b/src/svg/qsvghandler.cpp index 86ca77e..64a2bdc 100644 --- a/src/svg/qsvghandler.cpp +++ b/src/svg/qsvghandler.cpp @@ -60,6 +60,7 @@ #include "qmath.h" #include "qnumeric.h" #include +#include "qtransform.h" #include "qvarlengtharray.h" #include "private/qmath_p.h" @@ -1068,12 +1069,12 @@ static void parseBrush(QSvgNode *node, -static QMatrix parseTransformationMatrix(const QStringRef &value) +static QTransform parseTransformationMatrix(const QStringRef &value) { if (value.isEmpty()) - return QMatrix(); + return QTransform(); - QMatrix matrix; + QTransform matrix; const QChar *str = value.constData(); const QChar *end = str + value.length(); @@ -1156,9 +1157,9 @@ static QMatrix parseTransformationMatrix(const QStringRef &value) if(state == Matrix) { if(points.count() != 6) goto error; - matrix = QMatrix(points[0], points[1], - points[2], points[3], - points[4], points[5]) * matrix; + matrix = QTransform(points[0], points[1], + points[2], points[3], + points[4], points[5]) * matrix; } else if (state == Translate) { if (points.count() == 1) matrix.translate(points[0], 0); @@ -1435,7 +1436,7 @@ static void parseTransform(QSvgNode *node, { if (attributes.transform.isEmpty()) return; - QMatrix matrix = parseTransformationMatrix(trimRef(attributes.transform)); + QTransform matrix = parseTransformationMatrix(trimRef(attributes.transform)); if (!matrix.isIdentity()) { node->appendStyleProperty(new QSvgTransformStyle(QTransform(matrix)), attributes.id); @@ -2846,7 +2847,7 @@ static void parseBaseGradient(QSvgNode *node, handler->pushColor(color); } - QMatrix matrix; + QTransform matrix; QGradient *grad = gradProp->qgradient(); if (!link.isEmpty()) { QSvgStyleProperty *prop = node->styleProperty(link); @@ -2861,7 +2862,7 @@ static void parseBaseGradient(QSvgNode *node, gradProp->setGradientStopsSet(inherited->gradientStopsSet()); } - matrix = inherited->qmatrix(); + matrix = inherited->qtransform(); } else { gradProp->setStopLink(link, handler->document()); } @@ -2869,9 +2870,9 @@ static void parseBaseGradient(QSvgNode *node, if (!trans.isEmpty()) { matrix = parseTransformationMatrix(trans); - gradProp->setMatrix(matrix); + gradProp->setTransform(matrix); } else if (!matrix.isIdentity()) { - gradProp->setMatrix(matrix); + gradProp->setTransform(matrix); } if (!spread.isEmpty()) { diff --git a/src/svg/qsvgrenderer.cpp b/src/svg/qsvgrenderer.cpp index da31a31..40ae6ab 100644 --- a/src/svg/qsvgrenderer.cpp +++ b/src/svg/qsvgrenderer.cpp @@ -45,6 +45,7 @@ #include "qbytearray.h" #include "qtimer.h" +#include "qtransform.h" #include "qdebug.h" #include "private/qobject_p.h" @@ -437,7 +438,7 @@ void QSvgRenderer::setViewBox(const QRectF &viewbox) The transformation matrix of parent elements is not affecting the bounds of the element. - \sa matrixForElement() + \sa transformForElement() */ QRectF QSvgRenderer::boundsOnElement(const QString &id) const { @@ -471,8 +472,15 @@ bool QSvgRenderer::elementExists(const QString &id) const return exists; } +#if QT_DEPRECATED_SINCE(5, 15) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED /*! \since 4.2 + \deprecated + + Use transformForElement() instead. + Returns the transformation matrix for the element with the given \a id. The matrix is a product of @@ -485,12 +493,32 @@ bool QSvgRenderer::elementExists(const QString &id) const \sa boundsOnElement() */ QMatrix QSvgRenderer::matrixForElement(const QString &id) const +{ + return transformForElement(id).toAffine(); +} +QT_WARNING_POP +#endif // QT_DEPRECATED_SINCE(5, 15) + +/*! + \since 5.15 + + Returns the transformation matrix for the element + with the given \a id. The matrix is a product of + the transformation of the element's parents. The transformation of + the element itself is not included. + + To find the bounding rectangle of the element in logical coordinates, + you can apply the matrix on the rectangle returned from boundsOnElement(). + + \sa boundsOnElement() +*/ +QTransform QSvgRenderer::transformForElement(const QString &id) const { Q_D(const QSvgRenderer); - QMatrix mat; + QTransform trans; if (d->render) - mat = d->render->matrixForElement(id); - return mat; + trans = d->render->transformForElement(id); + return trans; } QT_END_NAMESPACE diff --git a/src/svg/qsvgrenderer.h b/src/svg/qsvgrenderer.h index 4413509..c7da2fb 100644 --- a/src/svg/qsvgrenderer.h +++ b/src/svg/qsvgrenderer.h @@ -56,6 +56,7 @@ QT_BEGIN_NAMESPACE class QSvgRendererPrivate; class QPainter; class QByteArray; +class QTransform; class Q_SVG_EXPORT QSvgRenderer : public QObject { @@ -89,7 +90,11 @@ public: QRectF boundsOnElement(const QString &id) const; bool elementExists(const QString &id) const; +#if QT_DEPRECATED_SINCE(5, 15) + QT_DEPRECATED_X("Use transformForElement()") QMatrix matrixForElement(const QString &id) const; +#endif // QT_DEPRECATED_SINCE(5, 15) + QTransform transformForElement(const QString &id) const; public Q_SLOTS: bool load(const QString &filename); diff --git a/src/svg/qsvgstyle.cpp b/src/svg/qsvgstyle.cpp index c4edd25..f981931 100644 --- a/src/svg/qsvgstyle.cpp +++ b/src/svg/qsvgstyle.cpp @@ -421,16 +421,16 @@ QBrush QSvgGradientStyle::brush(QPainter *, QSvgExtraStates &) QBrush b(*m_gradient); - if (!m_matrix.isIdentity()) - b.setMatrix(m_matrix); + if (!m_transform.isIdentity()) + b.setTransform(m_transform); return b; } -void QSvgGradientStyle::setMatrix(const QMatrix &mat) +void QSvgGradientStyle::setTransform(const QTransform &transform) { - m_matrix = mat; + m_transform = transform; } QSvgTransformStyle::QSvgTransformStyle(const QTransform &trans) diff --git a/src/svg/qsvgstyle_p.h b/src/svg/qsvgstyle_p.h index 39aa690..9dd4f53 100644 --- a/src/svg/qsvgstyle_p.h +++ b/src/svg/qsvgstyle_p.h @@ -54,7 +54,7 @@ #include "QtGui/qpainter.h" #include "QtGui/qpen.h" #include "QtGui/qbrush.h" -#include "QtGui/qmatrix.h" +#include "QtGui/qtransform.h" #include "QtGui/qcolor.h" #include "QtGui/qfont.h" #include @@ -579,10 +579,10 @@ public: void resolveStops(); void resolveStops_helper(QStringList *visited); - void setMatrix(const QMatrix &matrix); - QMatrix qmatrix() const + void setTransform(const QTransform &transform); + QTransform qtransform() const { - return m_matrix; + return m_transform; } QGradient *qgradient() const @@ -603,7 +603,7 @@ public: QBrush brush(QPainter *, QSvgExtraStates &) override; private: QGradient *m_gradient; - QMatrix m_matrix; + QTransform m_transform; QSvgTinyDocument *m_doc; QString m_link; diff --git a/src/svg/qsvgtinydocument.cpp b/src/svg/qsvgtinydocument.cpp index 173baaa..eb6b6b0 100644 --- a/src/svg/qsvgtinydocument.cpp +++ b/src/svg/qsvgtinydocument.cpp @@ -48,6 +48,7 @@ #include "qbytearray.h" #include "qqueue.h" #include "qstack.h" +#include "qtransform.h" #include "qdebug.h" #ifndef QT_NO_COMPRESS @@ -469,13 +470,13 @@ bool QSvgTinyDocument::elementExists(const QString &id) const return (node!=0); } -QMatrix QSvgTinyDocument::matrixForElement(const QString &id) const +QTransform QSvgTinyDocument::transformForElement(const QString &id) const { QSvgNode *node = scopeNode(id); if (!node) { qCDebug(lcSvgHandler, "Couldn't find node %s. Skipping rendering.", qPrintable(id)); - return QMatrix(); + return QTransform(); } QTransform t; @@ -487,7 +488,7 @@ QMatrix QSvgTinyDocument::matrixForElement(const QString &id) const node = node->parent(); } - return t.toAffine(); + return t; } int QSvgTinyDocument::currentFrame() const diff --git a/src/svg/qsvgtinydocument_p.h b/src/svg/qsvgtinydocument_p.h index 404587d..d0c5cae 100644 --- a/src/svg/qsvgtinydocument_p.h +++ b/src/svg/qsvgtinydocument_p.h @@ -67,6 +67,7 @@ QT_BEGIN_NAMESPACE class QPainter; class QByteArray; class QSvgFont; +class QTransform; class Q_SVG_PRIVATE_EXPORT QSvgTinyDocument : public QSvgStructureNode { @@ -99,7 +100,7 @@ public: void draw(QPainter *p, const QString &id, const QRectF &bounds=QRectF()); - QMatrix matrixForElement(const QString &id) const; + QTransform transformForElement(const QString &id) const; QRectF boundsOnElement(const QString &id) const; bool elementExists(const QString &id) const; diff --git a/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp b/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp index 8ad74f2..4a4a287 100644 --- a/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp +++ b/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp @@ -561,15 +561,15 @@ void tst_QSvgRenderer::matrixForElement() const QPainter painter(&image); QSvgRenderer renderer(data); - compareTransforms(painter.worldTransform(), QTransform(renderer.matrixForElement(QLatin1String("ichi")))); + compareTransforms(painter.worldTransform(), renderer.transformForElement(QLatin1String("ichi"))); painter.translate(-3, 1); - compareTransforms(painter.worldTransform(), QTransform(renderer.matrixForElement(QLatin1String("ni")))); + compareTransforms(painter.worldTransform(), renderer.transformForElement(QLatin1String("ni"))); painter.rotate(45); - compareTransforms(painter.worldTransform(), QTransform(renderer.matrixForElement(QLatin1String("san")))); + compareTransforms(painter.worldTransform(), renderer.transformForElement(QLatin1String("san"))); painter.scale(4, 2); - compareTransforms(painter.worldTransform(), QTransform(renderer.matrixForElement(QLatin1String("yon")))); + compareTransforms(painter.worldTransform(), renderer.transformForElement(QLatin1String("yon"))); painter.setWorldTransform(QTransform(1, 2, 3, 4, 5, 6), true); - compareTransforms(painter.worldTransform(), QTransform(renderer.matrixForElement(QLatin1String("firkant")))); + compareTransforms(painter.worldTransform(), renderer.transformForElement(QLatin1String("firkant"))); } void tst_QSvgRenderer::boundsOnElement() const -- cgit v1.2.1