Coverage Report

Created: 2026-10-28 07:09

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/qtsvg/src/svg/css/qsvgstyleselector.cpp
Line
Count
Source
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
6
#include "qsvgstyleselector_p.h"
7
#include <QtSvg/private/qsvgnode_p.h>
8
#include <QtSvg/private/qsvgstructure_p.h>
9
10
QT_BEGIN_NAMESPACE
11
12
QSvgStyleSelector::QSvgStyleSelector()
13
96.8k
{
14
96.8k
    nameCaseSensitivity = Qt::CaseInsensitive;
15
96.8k
}
16
17
QSvgStyleSelector::~QSvgStyleSelector()
18
96.8k
{
19
96.8k
}
20
21
QSvgNode *QSvgStyleSelector::svgNode(NodePtr node) const
22
295k
{
23
295k
    return (QSvgNode*)node.ptr;
24
295k
}
25
26
QSvgStructureNode *QSvgStyleSelector::nodeToStructure(QSvgNode *n) const
27
80
{
28
80
    if (n &&
29
76
        (n->type() == QSvgNode::Doc ||
30
6
         n->type() == QSvgNode::Group ||
31
6
         n->type() == QSvgNode::Defs ||
32
76
         n->type() == QSvgNode::Switch)) {
33
76
        return (QSvgStructureNode*)n;
34
76
    }
35
4
    return 0;
36
80
}
37
38
QSvgStructureNode *QSvgStyleSelector::svgStructure(NodePtr node) const
39
0
{
40
0
    QSvgNode *n = svgNode(node);
41
0
    QSvgStructureNode *st = nodeToStructure(n);
42
0
    return st;
43
0
}
44
45
bool QSvgStyleSelector::nodeNameEquals(NodePtr node, const QString &nodeName) const
46
55.3k
{
47
55.3k
    QSvgNode *n = svgNode(node);
48
55.3k
    if (!n)
49
0
        return false;
50
55.3k
    return QString::compare(n->typeName(), nodeName, Qt::CaseInsensitive) == 0;
51
55.3k
}
52
53
QString QSvgStyleSelector::attributeValue(NodePtr node, const QCss::AttributeSelector &asel) const
54
90.9k
{
55
90.9k
    const QString &name = asel.name;
56
90.9k
    QSvgNode *n = svgNode(node);
57
90.9k
    if ((!n->nodeId().isEmpty() && (name == QLatin1String("id") ||
58
70.9k
                                    name == QLatin1String("xml:id"))))
59
0
        return n->nodeId();
60
90.9k
    if (!n->xmlClass().isEmpty() && name == QLatin1String("class"))
61
61.8k
        return n->xmlClass();
62
29.0k
    return QString();
63
90.9k
}
64
65
bool QSvgStyleSelector::hasAttributes(NodePtr node) const
66
112k
{
67
112k
    QSvgNode *n = svgNode(node);
68
112k
    return (n &&
69
112k
            (!n->nodeId().isEmpty() || !n->xmlClass().isEmpty()));
70
112k
}
71
72
QStringList QSvgStyleSelector::nodeIds(NodePtr node) const
73
1.55k
{
74
1.55k
    QSvgNode *n = svgNode(node);
75
1.55k
    QString nid;
76
1.55k
    if (n)
77
1.55k
        nid = n->nodeId();
78
1.55k
    QStringList lst; lst.append(nid);
79
1.55k
    return lst;
80
1.55k
}
81
82
QStringList QSvgStyleSelector::nodeNames(NodePtr node) const
83
12.6k
{
84
12.6k
    QSvgNode *n = svgNode(node);
85
12.6k
    if (n)
86
12.6k
        return QStringList(n->typeName());
87
0
    return QStringList();
88
12.6k
}
89
90
bool QSvgStyleSelector::isNullNode(NodePtr node) const
91
22.2k
{
92
22.2k
    return !node.ptr;
93
22.2k
}
94
95
QCss::StyleSelector::NodePtr QSvgStyleSelector::parentNode(NodePtr node) const
96
22.2k
{
97
22.2k
    QSvgNode *n = svgNode(node);
98
22.2k
    NodePtr newNode;
99
22.2k
    newNode.ptr = 0;
100
22.2k
    newNode.id = 0;
101
22.2k
    if (n) {
102
22.2k
        QSvgNode *svgParent = n->parent();
103
22.2k
        if (svgParent) {
104
18.9k
            newNode.ptr = svgParent;
105
18.9k
        }
106
22.2k
    }
107
22.2k
    return newNode;
108
22.2k
}
109
110
QCss::StyleSelector::NodePtr QSvgStyleSelector::previousSiblingNode(NodePtr node) const
111
80
{
112
80
    NodePtr newNode;
113
80
    newNode.ptr = 0;
114
80
    newNode.id = 0;
115
116
80
    QSvgNode *n = svgNode(node);
117
80
    if (!n)
118
0
        return newNode;
119
80
    QSvgStructureNode *svgParent = nodeToStructure(n->parent());
120
121
80
    if (svgParent) {
122
76
        newNode.ptr = svgParent->previousSiblingNode(n);
123
76
    }
124
80
    return newNode;
125
80
}
126
127
QCss::StyleSelector::NodePtr QSvgStyleSelector::duplicateNode(NodePtr node) const
128
16.5k
{
129
16.5k
    NodePtr n;
130
16.5k
    n.ptr = node.ptr;
131
16.5k
    n.id  = node.id;
132
16.5k
    return n;
133
16.5k
}
134
135
void QSvgStyleSelector::freeNode(NodePtr node) const
136
38.8k
{
137
    Q_UNUSED(node);
138
38.8k
}
139
140
QT_END_NAMESPACE