Krita Source Code Documentation
Loading...
Searching...
No Matches
AttributeSelector Class Reference

Attribute selector, matching existence or content of attributes. More...

+ Inheritance diagram for AttributeSelector:

Public Member Functions

 AttributeSelector (const QString &attribute)
 
bool match (const QDomElement &e) override
 Matches the given element.
 
int priority () override
 
QString toString () const override
 Returns string representation of selector.
 
- Public Member Functions inherited from CssSelectorBase
virtual ~CssSelectorBase ()
 

Private Types

enum  MatchType {
  Unknown , Exists , Equals , InList ,
  StartsWith
}
 

Private Attributes

QString m_attribute
 
MatchType m_type
 
QString m_value
 

Detailed Description

Attribute selector, matching existence or content of attributes.

Definition at line 104 of file SvgCssHelper.cpp.

Member Enumeration Documentation

◆ MatchType

Enumerator
Unknown 

unknown -> error state

Exists 

[att] -> attribute exists

Equals 

[att=val] -> attribute value matches exactly val

InList 

[att~=val] -> attribute is whitespace separated list where one is val

StartsWith 

[att|=val] -> attribute starts with val-

Definition at line 181 of file SvgCssHelper.cpp.

181 {
182 Unknown,
183 Exists,
184 Equals,
185 InList,
187 };
@ Unknown
unknown -> error state
@ StartsWith
[att|=val] -> attribute starts with val-
@ Exists
[att] -> attribute exists
@ InList
[att~=val] -> attribute is whitespace separated list where one is val
@ Equals
[att=val] -> attribute value matches exactly val

Constructor & Destructor Documentation

◆ AttributeSelector()

AttributeSelector::AttributeSelector ( const QString & attribute)
inline

Definition at line 107 of file SvgCssHelper.cpp.

108 : m_type(Unknown)
109 {
110 QString pattern = attribute;
111 if (pattern.startsWith('['))
112 pattern.remove(0,1);
113 if (pattern.endsWith(']'))
114 pattern.remove(pattern.length()-1,1);
115 int equalPos = pattern.indexOf('=');
116 if (equalPos == -1) {
117 m_type = Exists;
118 m_attribute = pattern;
119 } else if (equalPos > 0){
120 if (pattern[equalPos-1] == '~') {
121 m_attribute = pattern.left(equalPos-1);
122 m_type = InList;
123 } else if(pattern[equalPos-1] == '|') {
124 m_attribute = pattern.left(equalPos-1) + '-';
126 } else {
127 m_attribute = pattern.left(equalPos);
128 m_type = Equals;
129 }
130 m_value = pattern.mid(equalPos+1);
131 if (m_value.startsWith(QLatin1Char('"')))
132 m_value.remove(0,1);
133 if (m_value.endsWith(QLatin1Char('"')))
134 m_value.chop(1);
135 }
136 }

References Equals, Exists, InList, m_attribute, m_type, m_value, and StartsWith.

Member Function Documentation

◆ match()

bool AttributeSelector::match ( const QDomElement & )
inlineoverridevirtual

Matches the given element.

Implements CssSelectorBase.

Definition at line 138 of file SvgCssHelper.cpp.

139 {
140 switch(m_type) {
141 case Exists:
142 return e.hasAttribute(m_attribute);
143 break;
144 case Equals:
145 return e.attribute(m_attribute) == m_value;
146 break;
147 case InList:
148 {
149 QStringList tokens = e.attribute(m_attribute).split(' ', Qt::SkipEmptyParts);
150 return tokens.contains(m_value);
151 }
152 break;
153 case StartsWith:
154 return e.attribute(m_attribute).startsWith(m_value);
155 break;
156 default:
157 return false;
158 }
159 }

References Equals, Exists, InList, m_attribute, m_type, m_value, and StartsWith.

◆ priority()

int AttributeSelector::priority ( )
inlineoverridevirtual

Returns priority of selector see http://www.w3.org/TR/1998/REC-CSS2-19980512/cascade.html#specificity

Reimplemented from CssSelectorBase.

Definition at line 175 of file SvgCssHelper.cpp.

176 {
177 return 10;
178 }

◆ toString()

QString AttributeSelector::toString ( ) const
inlineoverridevirtual

Returns string representation of selector.

Reimplemented from CssSelectorBase.

Definition at line 160 of file SvgCssHelper.cpp.

161 {
162 QString str('[');
163 str += m_attribute;
164 if (m_type == Equals) {
165 str += '=';
166 } else if (m_type == InList) {
167 str += "~=";
168 } else if (m_type == StartsWith) {
169 str += "|=";
170 }
171 str += m_value;
172 str += ']';
173 return str;
174 }

References Equals, InList, m_attribute, m_type, m_value, and StartsWith.

Member Data Documentation

◆ m_attribute

QString AttributeSelector::m_attribute
private

Definition at line 188 of file SvgCssHelper.cpp.

◆ m_type

MatchType AttributeSelector::m_type
private

Definition at line 190 of file SvgCssHelper.cpp.

◆ m_value

QString AttributeSelector::m_value
private

Definition at line 189 of file SvgCssHelper.cpp.


The documentation for this class was generated from the following file: