All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Valuable::StyleValue Class Reference

CSS attribute value is a list of variant components. More...

#include <Valuable/StyleValue.hpp>

Classes

class  Component
 One part of StyleValue list, variant / tagged union type with some convertions. More...
 

Public Types

typedef QList< ComponentComponentList
 
enum  Separator { SEPARATOR_WHITE_SPACE, SEPARATOR_COMMA, SEPARATOR_SLASH }
 A separator between components. More...
 
enum  ValueType {
  TYPE_NONE, TYPE_FLOAT, TYPE_INT, TYPE_COLOR,
  TYPE_STRING, TYPE_KEYWORD
}
 Component variant type. More...
 

Public Member Functions

void append (const StyleValue &v)
 Concatenates another StyleValue to this object. More...
 
void append (const StyleValue &v, Separator separator)
 Concatenates another StyleValue to this object with given separator. More...
 
void append (const Component &c)
 Appends one component to end of this StyleValue. More...
 
void append (const Component &c, Separator separator)
 Appends one component to end of this StyleValue with given separator. More...
 
Radiant::Color asColor (int idx=0) const
 
float asFloat (int idx=0) const
 
int asInt (int idx=0) const
 
QByteArray asKeyword (int idx=0) const
 
QMap< QString, QString > asMap () const
 CSS value "aaa bbb, ccc ddd eee, fff" will be converted to map: "aaa" => "bbb", "ccc" => "ddd eee", "fff" => "". More...
 
QString asString (int idx=0) const
 
const ComponentList & components () const
 
bool isEmpty () const
 
bool isNumber (int idx=0) const
 
bool isUniform () const
 In uniform StyleValue all components have same separators and types that can be converted to each other. More...
 
bool operator!= (const StyleValue &v) const
 Checks if StyleValue objects are different. More...
 
bool operator== (const StyleValue &v) const
 Checks if StyleValue objects are identical. More...
 
const Componentoperator[] (int idx) const
 Access one component in the StyleValue. More...
 
int size () const
 
QList< StyleValuesplit (Separator sep) const
 Splits StyleValue to parts with a separator. More...
 
QString stringify () const
 
 StyleValue ()
 Creates an empty StyleValue.
 
 StyleValue (float v, Attribute::ValueUnit unit=Attribute::VU_UNKNOWN)
 Creates a new StyleValue with one float component. More...
 
 StyleValue (int v)
 Creates a new StyleValue with one int component. More...
 
 StyleValue (const Radiant::Color &color)
 Creates a new StyleValue with one color component. More...
 
 StyleValue (const QString &string)
 Creates a new StyleValue with one string component. More...
 
 StyleValue (const QByteArray &keyword)
 Creates a new StyleValue with one keyword component. More...
 
 StyleValue (const Component &component)
 Creates a new StyleValue with one component. More...
 
 StyleValue (const QMap< QString, QString > &map)
 Shorthand constructor for creating a StyleValue from a map. More...
 
ValueType type (int idx=0) const
 
Attribute::ValueUnit unit (int idx=0) const
 
 ~StyleValue ()
 Deletes StyleValue and its components.
 

Detailed Description

CSS attribute value is a list of variant components.

StyleValue is the part between ':' and ';' in CSS, example: background: "image.png" top left; This value is a list of three components, one string and two keywords. CSS parser will generate a StyleValue instance from a value in CSS declaration.

See Also
http://www.w3.org/TR/CSS21/syndata.html#values

Member Enumeration Documentation

A separator between components.

Enumerator
SEPARATOR_WHITE_SPACE 

Components are separated by white space (newline, tab, space)

SEPARATOR_COMMA 

Components are separated by comma (,)

SEPARATOR_SLASH 

Components are separated by slash (/)

Component variant type.

Enumerator
TYPE_NONE 

Null type.

TYPE_FLOAT 

Floating point value, example: 10.0.

TYPE_INT 

Integer value, example: 10.

TYPE_COLOR 

Color value, example: #fff.

TYPE_STRING 

Quoted string, example: "image.png".

TYPE_KEYWORD 

Unquoted string, example: transparent.

Constructor & Destructor Documentation

Valuable::StyleValue::StyleValue ( float  v,
Attribute::ValueUnit  unit = Attribute::VU_UNKNOWN 
)

Creates a new StyleValue with one float component.

Parameters
vfloat value
unitunit of v
Valuable::StyleValue::StyleValue ( int  v)

Creates a new StyleValue with one int component.

Parameters
vint value
Valuable::StyleValue::StyleValue ( const Radiant::Color color)

Creates a new StyleValue with one color component.

Parameters
colorcolor value
Valuable::StyleValue::StyleValue ( const QString &  string)

Creates a new StyleValue with one string component.

Parameters
stringstring value
Valuable::StyleValue::StyleValue ( const QByteArray &  keyword)

Creates a new StyleValue with one keyword component.

Parameters
keywordkeyword value
Valuable::StyleValue::StyleValue ( const Component component)

Creates a new StyleValue with one component.

Parameters
componentcomponent to add to the new StyleValue
Valuable::StyleValue::StyleValue ( const QMap< QString, QString > &  map)

Shorthand constructor for creating a StyleValue from a map.

Parameters
mapmap that is converted to StyleValue, see asMap() for exact format

Member Function Documentation

void Valuable::StyleValue::append ( const StyleValue v)

Concatenates another StyleValue to this object.

Parameters
vStyleValue to append
void Valuable::StyleValue::append ( const StyleValue v,
Separator  separator 
)

Concatenates another StyleValue to this object with given separator.

Parameters
vStyleValue to append
separatorseparator to use between this and v
void Valuable::StyleValue::append ( const Component c)

Appends one component to end of this StyleValue.

Parameters
ccomponent to append
void Valuable::StyleValue::append ( const Component c,
Separator  separator 
)

Appends one component to end of this StyleValue with given separator.

Parameters
ccomponent to append
separatorseparator to use between this and c
int Valuable::StyleValue::asInt ( int  idx = 0) const
QMap<QString, QString> Valuable::StyleValue::asMap ( ) const

CSS value "aaa bbb, ccc ddd eee, fff" will be converted to map: "aaa" => "bbb", "ccc" => "ddd eee", "fff" => "".

Returns
StyleValue converted to map
const ComponentList& Valuable::StyleValue::components ( ) const
inline
Returns
const references to component list
bool Valuable::StyleValue::isEmpty ( ) const
Returns
true if size() == 0
bool Valuable::StyleValue::isNumber ( int  idx = 0) const
Parameters
idxindex of the value in the list
Returns
true if value is integer or floating point number
bool Valuable::StyleValue::isUniform ( ) const

In uniform StyleValue all components have same separators and types that can be converted to each other.

Empty StyleValue is also uniform type.

Returns
true if StyleValue is uniform
bool Valuable::StyleValue::operator!= ( const StyleValue v) const
inline

Checks if StyleValue objects are different.

Parameters
vother StyleValue object
Returns
true if objects differ
bool Valuable::StyleValue::operator== ( const StyleValue v) const

Checks if StyleValue objects are identical.

Parameters
vother StyleValue object
Returns
true if objects are identical
const Component& Valuable::StyleValue::operator[] ( int  idx) const

Access one component in the StyleValue.

Parameters
idx0 <= idx < size()
Returns
const reference to component at index idx
int Valuable::StyleValue::size ( ) const
Returns
the number of components
QList<StyleValue> Valuable::StyleValue::split ( Separator  sep) const

Splits StyleValue to parts with a separator.

Parameters
sepseparator that marks the points where to split
Returns
this StyleValue splitted to smaller parts
QString Valuable::StyleValue::stringify ( ) const
Returns
String representation that can be used in a CSS