Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qsvgdebug.cpp
Go to the documentation of this file.
1// Copyright (C) 2023 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// Qt-Security score:significant reason:default
4
5
7
8#include <QDebug>
9
11
13{
14public:
15 SvgDebugVisitor(QDebug &stream) : debug(stream) {}
16 void write(const QSvgDocument *doc);
17
18protected:
19 void visitNode(const QSvgNode *) override;
20 bool visitStructureNodeStart(const QSvgStructureNode *node) override;
21 void visitStructureNodeEnd(const QSvgStructureNode *) override;
22 void visitAnimateNode(const QSvgAnimateNode *node) override;
23 void visitEllipseNode(const QSvgEllipse *node) override;
24 void visitImageNode(const QSvgImage *node) override;
25 void visitLineNode(const QSvgLine *node) override;
26 void visitPathNode(const QSvgPath *node) override;
27 void visitPolygonNode(const QSvgPolygon *node) override;
28 void visitPolylineNode(const QSvgPolyline *node) override;
29 void visitRectNode(const QSvgRect *node) override;
30 void visitTextNode(const QSvgText *node) override;
31 void visitUseNode(const QSvgUse *node) override;
32 void visitVideoNode(const QSvgVideo *node) override;
33
34private:
35 const char *indent() { m_indent.fill(' ', m_indentLevel * 2); return m_indent.constData();}
36 void handleBaseNode(const QSvgNode *node);
37 QDebug &debug;
38 int m_indentLevel = 0;
39 QByteArray m_indent;
40 int nodeCounter = 0;
41};
42
43void SvgDebugVisitor::handleBaseNode(const QSvgNode *node)
44{
45 debug << indent() << node->typeName() << "node, ID:" << node->nodeId();
46 nodeCounter++;
47}
48
49void SvgDebugVisitor::visitNode(const QSvgNode *node)
50{
51 handleBaseNode(node);
52 debug << Qt::endl;
53}
54
55bool SvgDebugVisitor::visitStructureNodeStart(const QSvgStructureNode *node)
56{
57 debug << indent() << "START node" << node->nodeId() << "type" << node->typeName() << node->type() << Qt::endl;
58 m_indentLevel++;
59 return true;
60}
61
62void SvgDebugVisitor::visitStructureNodeEnd(const QSvgStructureNode *node)
63{
64 m_indentLevel--;
65 debug << indent() << "END node" << node->nodeId() << Qt::endl;
66}
67
68void SvgDebugVisitor::visitAnimateNode(const QSvgAnimateNode *node)
69{
70 handleBaseNode(node);
71 debug << Qt::endl;
72}
73
74void SvgDebugVisitor::visitEllipseNode(const QSvgEllipse *node)
75{
76 handleBaseNode(node);
77 debug << "rect:" << node->rect() << Qt::endl;
78}
79
80void SvgDebugVisitor::visitImageNode(const QSvgImage *node)
81{
82 handleBaseNode(node);
83 debug << "image:" << node->image() << Qt::endl;
84}
85
86void SvgDebugVisitor::visitLineNode(const QSvgLine *node)
87{
88 handleBaseNode(node);
89 debug << "line:" << node->line() << Qt::endl;
90}
91
92void SvgDebugVisitor::visitPathNode(const QSvgPath *node)
93{
94 handleBaseNode(node);
95 debug << "path:" << node->path().elementCount() << "elements." << Qt::endl;
96}
97
98void SvgDebugVisitor::visitPolygonNode(const QSvgPolygon *node)
99{
100 handleBaseNode(node);
101 debug << "polygon:" << node->polygon().size() << "elements." << Qt::endl;
102}
103
104void SvgDebugVisitor::visitPolylineNode(const QSvgPolyline *node)
105{
106 handleBaseNode(node);
107 debug << "polygon:" << node->polygon().size() << "elements." << Qt::endl;
108}
109
110void SvgDebugVisitor::visitRectNode(const QSvgRect *node)
111{
112 handleBaseNode(node);
113 debug << "rect:" << node->rect() << "radius:" << node->radius() << Qt::endl;
114}
115
116void SvgDebugVisitor::visitTextNode(const QSvgText *node)
117{
118 handleBaseNode(node);
119 QString text;
120 for (const auto *tspan : node->tspans()) {
121 if (!tspan)
122 text += QStringLiteral("\\n");
123 else
124 text += tspan->text();
125 }
126 debug << "text:" << text << Qt::endl;
127}
128
129void SvgDebugVisitor::visitUseNode(const QSvgUse *node)
130{
131 handleBaseNode(node);
132 debug << "link ID:" << node->linkId() << Qt::endl;
133}
134
135void SvgDebugVisitor::visitVideoNode(const QSvgVideo *node)
136{
137 handleBaseNode(node);
138 debug << Qt::endl;
139}
140
141void SvgDebugVisitor::write(const QSvgDocument *doc)
142{
143 debug << "SVG" << doc->size() << "viewBox" << doc->viewBox() << Qt::endl;
144 traverse(doc);
145
146 debug << "END SVG" << nodeCounter << "nodes";
147}
148
149QDebug operator<<(QDebug debug, const QSvgDocument &doc)
150{
151 SvgDebugVisitor visitor(debug);
152 visitor.write(&doc);
153
154 return debug;
155}
156
157QT_END_NAMESPACE
bool visitStructureNodeStart(const QSvgStructureNode *node) override
Definition qsvgdebug.cpp:55
void visitLineNode(const QSvgLine *node) override
Definition qsvgdebug.cpp:86
void visitStructureNodeEnd(const QSvgStructureNode *) override
Definition qsvgdebug.cpp:62
void visitAnimateNode(const QSvgAnimateNode *node) override
Definition qsvgdebug.cpp:68
void visitPathNode(const QSvgPath *node) override
Definition qsvgdebug.cpp:92
void write(const QSvgDocument *doc)
void visitEllipseNode(const QSvgEllipse *node) override
Definition qsvgdebug.cpp:74
void visitRectNode(const QSvgRect *node) override
void visitVideoNode(const QSvgVideo *node) override
void visitTextNode(const QSvgText *node) override
SvgDebugVisitor(QDebug &stream)
Definition qsvgdebug.cpp:15
void visitPolygonNode(const QSvgPolygon *node) override
Definition qsvgdebug.cpp:98
void visitImageNode(const QSvgImage *node) override
Definition qsvgdebug.cpp:80
void visitPolylineNode(const QSvgPolyline *node) override
void visitNode(const QSvgNode *) override
Definition qsvgdebug.cpp:49
void visitUseNode(const QSvgUse *node) override
Combined button and popup list for selecting options.
QDebug operator<<(QDebug dbg, const QFileInfo &fi)