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

#include <SvgCssHelper.h>

Classes

class  Private
 

Public Member Functions

QStringList matchStyles (const QDomElement &element) const
 
void parseStylesheet (const QDomElement &)
 Parses css style sheet in given xml element.
 
 SvgCssHelper ()
 
 ~SvgCssHelper ()
 

Private Attributes

Private *const d
 

Detailed Description

Definition at line 14 of file SvgCssHelper.h.

Constructor & Destructor Documentation

◆ SvgCssHelper()

SvgCssHelper::SvgCssHelper ( )

Definition at line 599 of file SvgCssHelper.cpp.

600: d(new Private())
601{
602}
Private *const d

◆ ~SvgCssHelper()

SvgCssHelper::~SvgCssHelper ( )

Definition at line 604 of file SvgCssHelper.cpp.

605{
606 delete d;
607}

References d.

Member Function Documentation

◆ matchStyles()

QStringList SvgCssHelper::matchStyles ( const QDomElement & element) const

Matches css styles to given xml element and returns them

Parameters
elementthe element to match styles for
Returns
list of matching css styles sorted by priority

Definition at line 656 of file SvgCssHelper.cpp.

657{
658 QMap<int, QString> prioritizedRules;
659 // match rules to element
660 Q_FOREACH (const CssRule &rule, d->cssRules) {
661 Q_FOREACH (CssSelectorBase *s, rule.first) {
662 bool matched = s->match(element);
663 if (matched)
664 prioritizedRules[s->priority()] = rule.second;
665 }
666 }
667
668 // css style attribute has the priority of 100
669 QString styleAttribute = element.attribute("style").simplified();
670 if (!styleAttribute.isEmpty())
671 prioritizedRules[100] = styleAttribute;
672
673 QStringList cssStyles;
674 // add matching styles in correct order to style list
675 QMapIterator<int, QString> it(prioritizedRules);
676 while (it.hasNext()) {
677 it.next();
678 cssStyles.append(it.value());
679 }
680
681 return cssStyles;
682}
QPair< SelectorGroup, QString > CssRule
A css rule consisting of group of selectors corresponding to a style.
Selector base class, merely an interface.
virtual bool match(const QDomElement &)=0
Matches the given element.
virtual int priority()
QList< CssRule > cssRules

References SvgCssHelper::Private::cssRules, d, CssSelectorBase::match(), and CssSelectorBase::priority().

◆ parseStylesheet()

void SvgCssHelper::parseStylesheet ( const QDomElement & e)

Parses css style sheet in given xml element.

Definition at line 609 of file SvgCssHelper.cpp.

610{
611 QString data;
612
613 if (e.hasChildNodes()) {
614 QDomNode c = e.firstChild();
615 if (c.isCDATASection()) {
616 QDomCDATASection cdata = c.toCDATASection();
617 data = cdata.data().simplified();
618 } else if (c.isText()) {
619 QDomText text = c.toText();
620 data = text.data().simplified();
621 }
622 }
623 if (data.isEmpty())
624 return;
625
626 // remove comments
627 QRegExp commentExp("\\/\\*.*\\*\\/");
628 commentExp.setMinimal(true); // do not match greedy
629#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
630 data.remove(commentExp);
631#else
632 commentExp.removeIn(data);
633#endif
634
635 QStringList defs = data.split('}', Qt::SkipEmptyParts);
636 for (int i = 0; i < defs.count(); ++i) {
637 QStringList def = defs[i].split('{');
638 if( def.count() != 2 )
639 continue;
640 QString pattern = def[0].simplified();
641 if (pattern.isEmpty())
642 break;
643 QString style = def[1].simplified();
644 if (style.isEmpty())
645 break;
646 QStringList selectors = pattern.split(',', Qt::SkipEmptyParts);
647 for (int i = 0; i < selectors.count(); ++i ) {
648 QString selector = selectors[i].simplified();
649 d->cssStyles[selector] = style;
650 }
651 SelectorGroup group = d->parsePattern(pattern);
652 d->cssRules.append(CssRule(group, style));
653 }
654}
QMap< QString, QString > cssStyles
SelectorGroup parsePattern(const QString &pattern)

References SvgCssHelper::Private::cssRules, SvgCssHelper::Private::cssStyles, d, and SvgCssHelper::Private::parsePattern().

Member Data Documentation

◆ d

Private* const SvgCssHelper::d
private

Definition at line 32 of file SvgCssHelper.h.


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