From ef643fb1d6b53db3a9c5345c14437c5281159634 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Tue, 16 Jan 2024 13:45:28 +0100 Subject: Add clear() function to QSGTextNode interface This was omitted from the API by accident, which makes the class a lot less convenient to use. Pick-to: 6.7 Change-Id: I648d5088725a8a5c1f1ec603c466656e4f318b0f Reviewed-by: Andy Nichols --- src/quick/items/qquicktext.cpp | 2 +- src/quick/items/qquicktextinput.cpp | 2 +- src/quick/items/qsginternaltextnode.cpp | 2 +- src/quick/items/qsginternaltextnode_p.h | 2 +- src/quick/scenegraph/util/qsgtextnode.cpp | 13 +++++++++++++ src/quick/scenegraph/util/qsgtextnode.h | 2 ++ 6 files changed, 19 insertions(+), 4 deletions(-) (limited to 'src/quick') diff --git a/src/quick/items/qquicktext.cpp b/src/quick/items/qquicktext.cpp index f739fcecc8..8a8b36bea3 100644 --- a/src/quick/items/qquicktext.cpp +++ b/src/quick/items/qquicktext.cpp @@ -2720,7 +2720,7 @@ QSGNode *QQuickText::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data node->setTextStyle(QSGTextNode::TextStyle(d->style)); node->setRenderType(QSGTextNode::RenderType(d->renderType)); node->setRenderTypeQuality(d->renderTypeQuality()); - node->deleteContent(); + node->clear(); node->setMatrix(QMatrix4x4()); node->setColor(QColor::fromRgba(d->color)); diff --git a/src/quick/items/qquicktextinput.cpp b/src/quick/items/qquicktextinput.cpp index d0939d70d2..363fa1cbd3 100644 --- a/src/quick/items/qquicktextinput.cpp +++ b/src/quick/items/qquicktextinput.cpp @@ -1988,7 +1988,7 @@ QSGNode *QQuickTextInput::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData node->clearCursor(); } else { node->setRenderType(QSGTextNode::RenderType(d->renderType)); - node->deleteContent(); + node->clear(); node->setMatrix(QMatrix4x4()); node->setTextStyle(QSGInternalTextNode::Normal); node->setColor(d->color); diff --git a/src/quick/items/qsginternaltextnode.cpp b/src/quick/items/qsginternaltextnode.cpp index 2f55835a22..b7b70db880 100644 --- a/src/quick/items/qsginternaltextnode.cpp +++ b/src/quick/items/qsginternaltextnode.cpp @@ -255,7 +255,7 @@ void QSGInternalTextNode::addTextLayout(const QPointF &position, QTextLayout *te engine.addToSceneGraph(this, QQuickText::TextStyle(m_textStyle), m_styleColor); } -void QSGInternalTextNode::deleteContent() +void QSGInternalTextNode::clear() { while (firstChild() != nullptr) delete firstChild(); diff --git a/src/quick/items/qsginternaltextnode_p.h b/src/quick/items/qsginternaltextnode_p.h index 0585f78339..c16d71aaa4 100644 --- a/src/quick/items/qsginternaltextnode_p.h +++ b/src/quick/items/qsginternaltextnode_p.h @@ -158,7 +158,7 @@ public: void addRectangleNode(const QRectF &rect, const QColor &color); virtual void addDecorationNode(const QRectF &rect, const QColor &color); void addImage(const QRectF &rect, const QImage &image); - void deleteContent(); + void clear() override; QSGGlyphNode *addGlyphs(const QPointF &position, const QGlyphRun &glyphs, const QColor &color, QQuickText::TextStyle style = QQuickText::Normal, const QColor &styleColor = QColor(), QSGNode *parentNode = 0); diff --git a/src/quick/scenegraph/util/qsgtextnode.cpp b/src/quick/scenegraph/util/qsgtextnode.cpp index 27f9e3edae..7f98664ed7 100644 --- a/src/quick/scenegraph/util/qsgtextnode.cpp +++ b/src/quick/scenegraph/util/qsgtextnode.cpp @@ -243,6 +243,8 @@ QT_BEGIN_NAMESPACE objects to include from the layout. This can be useful, for instance, when creating elided layouts. If \a lineCount is < 0, then the the node will include the lines from \a lineStart to the end of the layout. + + \sa clear() */ /*! @@ -252,6 +254,17 @@ QT_BEGIN_NAMESPACE then this marks the first character in a selected area of \a selectionCount number of characters. The selection is represented as a background fill with the \l selectionColor() and the selected text is rendered in the \l selectionTextColor(). + + \sa clear() +*/ + +/*! + \fn QSGTextNode::clear() + + Clears the contents of the node, deleting nodes and other data that represents the layouts + and documents that have been added to it. + + \sa addTextLayout(), addTextDocument() */ QT_END_NAMESPACE diff --git a/src/quick/scenegraph/util/qsgtextnode.h b/src/quick/scenegraph/util/qsgtextnode.h index ee6c5cff6e..db91dc01ae 100644 --- a/src/quick/scenegraph/util/qsgtextnode.h +++ b/src/quick/scenegraph/util/qsgtextnode.h @@ -58,6 +58,8 @@ public: virtual void setSmooth(bool smooth) = 0; virtual bool smooth() const = 0; + virtual void clear() = 0; + virtual void setViewport(const QRectF &viewport) = 0; virtual QRectF viewport() const = 0; -- cgit v1.2.3