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
qsvgstyleselector.cpp
Go to the documentation of this file.
1// Copyright (C) 2025 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#include <QtSvg/private/qsvgnode_p.h>
8#include <QtSvg/private/qsvgstructure_p.h>
9
11
12QSvgStyleSelector::QSvgStyleSelector()
13{
14 nameCaseSensitivity = Qt::CaseInsensitive;
15}
16
20
21QSvgNode *QSvgStyleSelector::svgNode(NodePtr node) const
22{
23 return (QSvgNode*)node.ptr;
24}
25
26QSvgStructureNode *QSvgStyleSelector::nodeToStructure(QSvgNode *n) const
27{
28 if (n &&
29 (n->type() == QSvgNode::Doc ||
30 n->type() == QSvgNode::Group ||
31 n->type() == QSvgNode::Defs ||
32 n->type() == QSvgNode::Switch)) {
33 return (QSvgStructureNode*)n;
34 }
35 return 0;
36}
37
38QSvgStructureNode *QSvgStyleSelector::svgStructure(NodePtr node) const
39{
40 QSvgNode *n = svgNode(node);
41 QSvgStructureNode *st = nodeToStructure(n);
42 return st;
43}
44
45bool QSvgStyleSelector::nodeNameEquals(NodePtr node, const QString &nodeName) const
46{
47 QSvgNode *n = svgNode(node);
48 if (!n)
49 return false;
50 return QString::compare(n->typeName(), nodeName, Qt::CaseInsensitive) == 0;
51}
52
53QString QSvgStyleSelector::attributeValue(NodePtr node, const QCss::AttributeSelector &asel) const
54{
55 const QString &name = asel.name;
56 QSvgNode *n = svgNode(node);
57 if ((!n->nodeId().isEmpty() && (name == QLatin1String("id") ||
58 name == QLatin1String("xml:id"))))
59 return n->nodeId();
60 if (!n->xmlClass().isEmpty() && name == QLatin1String("class"))
61 return n->xmlClass();
62 return QString();
63}
64
65bool QSvgStyleSelector::hasAttributes(NodePtr node) const
66{
67 QSvgNode *n = svgNode(node);
68 return (n &&
69 (!n->nodeId().isEmpty() || !n->xmlClass().isEmpty()));
70}
71
73{
74 QSvgNode *n = svgNode(node);
75 QString nid;
76 if (n)
77 nid = n->nodeId();
78 QStringList lst; lst.append(nid);
79 return lst;
80}
81
83{
84 QSvgNode *n = svgNode(node);
85 if (n)
86 return QStringList(n->typeName());
87 return QStringList();
88}
89
90bool QSvgStyleSelector::isNullNode(NodePtr node) const
91{
92 return !node.ptr;
93}
94
96{
97 QSvgNode *n = svgNode(node);
98 NodePtr newNode;
99 newNode.ptr = 0;
100 newNode.id = 0;
101 if (n) {
102 QSvgNode *svgParent = n->parent();
103 if (svgParent) {
104 newNode.ptr = svgParent;
105 }
106 }
107 return newNode;
108}
109
111{
112 NodePtr newNode;
113 newNode.ptr = 0;
114 newNode.id = 0;
115
116 QSvgNode *n = svgNode(node);
117 if (!n)
118 return newNode;
119 QSvgStructureNode *svgParent = nodeToStructure(n->parent());
120
121 if (svgParent) {
122 newNode.ptr = svgParent->previousSiblingNode(n);
123 }
124 return newNode;
125}
126
128{
129 NodePtr n;
130 n.ptr = node.ptr;
131 n.id = node.id;
132 return n;
133}
134
135void QSvgStyleSelector::freeNode(NodePtr node) const
136{
137 Q_UNUSED(node);
138}
139
140QT_END_NAMESPACE
QStringList nodeNames(NodePtr node) const override
QSvgStructureNode * svgStructure(NodePtr node) const
bool hasAttributes(NodePtr node) const override
QString attributeValue(NodePtr node, const QCss::AttributeSelector &asel) const override
bool isNullNode(NodePtr node) const override
QSvgStructureNode * nodeToStructure(QSvgNode *n) const
void freeNode(NodePtr node) const override
NodePtr duplicateNode(NodePtr node) const override
QSvgNode * svgNode(NodePtr node) const
NodePtr parentNode(NodePtr node) const override
QStringList nodeIds(NodePtr node) const override
NodePtr previousSiblingNode(NodePtr node) const override
bool nodeNameEquals(NodePtr node, const QString &nodeName) const override
Combined button and popup list for selecting options.