Krita Source Code Documentation
Loading...
Searching...
No Matches
SvgCssHelper::Private Class Reference

Public Member Functions

CssSelectorBasecompileSelector (const QString &selector)
 
SelectorGroup parsePattern (const QString &pattern)
 
QList< CssTokentokenize (const QString &selector)
 
 ~Private ()
 

Public Attributes

QList< CssRulecssRules
 
QMap< QString, QString > cssStyles
 

Detailed Description

Definition at line 487 of file SvgCssHelper.cpp.

Constructor & Destructor Documentation

◆ ~Private()

SvgCssHelper::Private::~Private ( )
inline

Definition at line 490 of file SvgCssHelper.cpp.

491 {
492 Q_FOREACH (const CssRule &rule, cssRules) {
493 qDeleteAll(rule.first);
494 }
495 }
QPair< SelectorGroup, QString > CssRule
A css rule consisting of group of selectors corresponding to a style.
QList< CssRule > cssRules

References cssRules.

Member Function Documentation

◆ compileSelector()

CssSelectorBase * SvgCssHelper::Private::compileSelector ( const QString & selector)
inline

Definition at line 579 of file SvgCssHelper.cpp.

580 {
581 QList<CssToken> tokenList = tokenize(selector);
582 if (tokenList.isEmpty())
583 return 0;
584
585 if (tokenList.count() == 1) {
586 // simple selector
587 return new CssSimpleSelector(tokenList.first().second);
588 } else if (tokenList.count() > 2) {
589 // complex selector
590 return new CssComplexSelector(tokenList);
591 }
592 return 0;
593 }
Complex selector, i.e. a combination of simple selectors.
A simple selector, i.e. a type/universal selector followed by attribute, id or pseudo-class selectors...
QList< CssToken > tokenize(const QString &selector)

References tokenize().

◆ parsePattern()

SelectorGroup SvgCssHelper::Private::parsePattern ( const QString & pattern)
inline

Definition at line 497 of file SvgCssHelper.cpp.

498 {
499 SelectorGroup group;
500
501 QStringList selectors = pattern.split(',', Qt::SkipEmptyParts);
502 for (int i = 0; i < selectors.count(); ++i ) {
503 CssSelectorBase * selector = compileSelector(selectors[i].simplified());
504 if (selector)
505 group.append(selector);
506 }
507 return group;
508 }
Selector base class, merely an interface.
CssSelectorBase * compileSelector(const QString &selector)

References compileSelector().

◆ tokenize()

QList< CssToken > SvgCssHelper::Private::tokenize ( const QString & selector)
inline

Definition at line 510 of file SvgCssHelper.cpp.

511 {
512 // add terminator to string
513 QString expr = selector + QChar();
514 enum {
515 Finish,
516 Bad,
517 InCombinator,
518 InSelector
519 } state;
520
521 QChar combinator;
522 int selectorStart = 0;
523
524 QList<CssToken> tokenList;
525
526 QChar ch = expr[0];
527 if (ch.isSpace() || ch == '>' || ch == '+') {
528 debugFlake << "selector starting with combinator is not allowed:" << selector;
529 return tokenList;
530 } else {
531 state = InSelector;
532 selectorStart = 0;
533 }
534 int i = 1;
535
536 // split into simple selectors and combinators
537 while((state != Finish) && (state != Bad) && (i < expr.length())) {
538 QChar ch = expr[i];
539 switch(state) {
540 case InCombinator:
541 // consume as long as there a combinator characters
542 if( ch == '>' || ch == '+') {
543 if( ! combinator.isSpace() ) {
544 // two non whitespace combinators in sequence are not allowed
545 state = Bad;
546 } else {
547 // switch combinator
548 combinator = ch;
549 }
550 } else if (!ch.isSpace()) {
551 tokenList.append(CssToken(CombinatorToken, combinator));
552 state = InSelector;
553 selectorStart = i;
554 combinator = QChar();
555 }
556 break;
557 case InSelector:
558 // consume as long as there a non combinator characters
559 if (ch.isSpace() || ch == '>' || ch == '+') {
560 state = InCombinator;
561 combinator = ch;
562 } else if (ch.isNull()) {
563 state = Finish;
564 }
565 if (state != InSelector) {
566 QString simpleSelector = selector.mid(selectorStart, i-selectorStart);
567 tokenList.append(CssToken(SelectorToken, simpleSelector));
568 }
569 break;
570 default:
571 break;
572 }
573 i++;
574 }
575
576 return tokenList;
577 }
#define debugFlake
Definition FlakeDebug.h:15
@ SelectorToken
a selector token
@ CombinatorToken
a combinator token
QPair< CssTokenType, QString > CssToken
A token used for tokenizing complex selectors.

References CombinatorToken, debugFlake, and SelectorToken.

Member Data Documentation

◆ cssRules

QList<CssRule> SvgCssHelper::Private::cssRules

Definition at line 596 of file SvgCssHelper.cpp.

◆ cssStyles

QMap<QString, QString> SvgCssHelper::Private::cssStyles

Definition at line 595 of file SvgCssHelper.cpp.


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