All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Stylish::LazyAttributeManager Namespace Reference

Storage for factories that are used to create lazy attributes. More...

Classes

class  Registrant
 

Typedefs

typedef std::function
< Valuable::Attribute
*(Valuable::Node *, const
QByteArray &)> 
Func
 

Functions

STYLISH_API Valuable::Attributecreate (Valuable::Node *node, const QByteArray &name)
 

Detailed Description

Storage for factories that are used to create lazy attributes.

Lazy attributes are dynamically (on-demand) created Valuable::Attribute objects. These attributes are created by factory functions that are registered by using LAZY_ATTRIBUTE-macro. If there is a CSS rule that matches a Styleable object but fails to find the target attribute, LazyAttributeManager is invoked in order to create the missing attribute.

For example, see this CSS rule:

ImageWidget {
max-scale: 1.5;
}

This rule will match all ImageWidgets, but there is no such attribute in ImageWidget as 'max-scale', so this will trigger a warning.

However, we can add this attribute without modifying ImageWidget using LAZY_ATTRIBUTE-macro and custom factory:

static auto s_factory = [] (Widget & widget, const QByteArray & name) -> Valuable::Attribute *
{
auto limiter = std::make_shared<LimitScaleOperator>();
auto attr = new Valuable::AttributeAlias(&widget, name, limiter->attribute("maximum-value"));
return attr;
}
LAZY_ATTRIBUTE(ImageWidget, "max-scale", s_factory);

So when ever any ImageWidget is given any value for max-scale attribute in CSS, a new LimitScaleOperator is created and added to the widget. Any changes to the attribute change LimitScaleOperator::maximum-value attribute directly.