Coverage Report

Created: 2026-01-25 07:18

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