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
21QString QSvgStyleSelector::nodeToName(QSvgNode *node) const
22{
23 return node->typeName();
24}
25
26QSvgNode *QSvgStyleSelector::svgNode(NodePtr node) const
27{
28 return (QSvgNode*)node.ptr;
29}
30
31QSvgStructureNode *QSvgStyleSelector::nodeToStructure(QSvgNode *n) const
32{
33 if (n &&
34 (n->type() == QSvgNode::Doc ||
35 n->type() == QSvgNode::Group ||
36 n->type() == QSvgNode::Defs ||
37 n->type() == QSvgNode::Switch)) {
38 return (QSvgStructureNode*)n;
39 }
40 return 0;
41}
42
43QSvgStructureNode *QSvgStyleSelector::svgStructure(NodePtr node) const
44{
45 QSvgNode *n = svgNode(node);
46 QSvgStructureNode *st = nodeToStructure(n);
47 return st;
48}
49
50bool QSvgStyleSelector::nodeNameEquals(NodePtr node, const QString &nodeName) const
51{
52 QSvgNode *n = svgNode(node);
53 if (!n)
54 return false;
55 QString name = nodeToName(n);
56 return QString::compare(name, nodeName, Qt::CaseInsensitive) == 0;
57}
58
59QString QSvgStyleSelector::attributeValue(NodePtr node, const QCss::AttributeSelector &asel) const
60{
61 const QString &name = asel.name;
62 QSvgNode *n = svgNode(node);
63 if ((!n->nodeId().isEmpty() && (name == QLatin1String("id") ||
64 name == QLatin1String("xml:id"))))
65 return n->nodeId();
66 if (!n->xmlClass().isEmpty() && name == QLatin1String("class"))
67 return n->xmlClass();
68 return QString();
69}
70
71bool QSvgStyleSelector::hasAttributes(NodePtr node) const
72{
73 QSvgNode *n = svgNode(node);
74 return (n &&
75 (!n->nodeId().isEmpty() || !n->xmlClass().isEmpty()));
76}
77
79{
80 QSvgNode *n = svgNode(node);
81 QString nid;
82 if (n)
83 nid = n->nodeId();
84 QStringList lst; lst.append(nid);
85 return lst;
86}
87
89{
90 QSvgNode *n = svgNode(node);
91 if (n)
92 return QStringList(nodeToName(n));
93 return QStringList();
94}
95
96bool QSvgStyleSelector::isNullNode(NodePtr node) const
97{
98 return !node.ptr;
99}
100
102{
103 QSvgNode *n = svgNode(node);
104 NodePtr newNode;
105 newNode.ptr = 0;
106 newNode.id = 0;
107 if (n) {
108 QSvgNode *svgParent = n->parent();
109 if (svgParent) {
110 newNode.ptr = svgParent;
111 }
112 }
113 return newNode;
114}
115
117{
118 NodePtr newNode;
119 newNode.ptr = 0;
120 newNode.id = 0;
121
122 QSvgNode *n = svgNode(node);
123 if (!n)
124 return newNode;
125 QSvgStructureNode *svgParent = nodeToStructure(n->parent());
126
127 if (svgParent) {
128 newNode.ptr = svgParent->previousSiblingNode(n);
129 }
130 return newNode;
131}
132
134{
135 NodePtr n;
136 n.ptr = node.ptr;
137 n.id = node.id;
138 return n;
139}
140
141void QSvgStyleSelector::freeNode(NodePtr node) const
142{
143 Q_UNUSED(node);
144}
145
146QT_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
QString nodeToName(QSvgNode *node) const
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.