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

The base class for value objects. More...

#include <Valuable/Attribute.hpp>

Inheritance diagram for Valuable::Attribute:
Valuable::Serializable Valuable::AttributeContainerT< std::list< MultiWidgets::OperatorPtr > > Valuable::AttributeContainerT< std::map< float, KeyFrame< T > > > Valuable::AttributeContainerT< std::map< Key, T, Compare, Allocator > > Valuable::AttributeFlagsT< EdgeFlags > Valuable::AttributeFlagsT< Flags > Valuable::AttributeFlagsT< LimitBehaviorFlags > Valuable::AttributeFlagsT< MultiTouch::TrackedObjectType > Valuable::AttributeT< Align > Valuable::AttributeT< AlignContent > Valuable::AttributeT< bool > Valuable::AttributeT< FlexDirection > Valuable::AttributeT< FlexWrap > Valuable::AttributeT< IncludeMode > Valuable::AttributeT< JustifyContent > Valuable::AttributeT< MatrixType > Valuable::AttributeT< Mode > Valuable::AttributeT< MultiWidgets::LimitScaleOperator::Mode > Valuable::AttributeT< Nimble::RectT< T > > Valuable::AttributeT< Nimble::Vector2f > Valuable::AttributeT< Orientation > Valuable::AttributeT< QMap< QString, QString > > Valuable::AttributeT< QString > Valuable::AttributeT< QStringList > Valuable::AttributeT< Radiant::Color > Valuable::AttributeT< Radiant::TimeStamp > Valuable::AttributeT< ResizeToContent > Valuable::AttributeT< StyleValue > Valuable::AttributeT< Uuid > Valuable::AttributeT< VectorT< T > > Valuable::AttributeT< VectorType > Stylish::AttributeBackground Stylish::AttributeBorder Stylish::AttributeFont Valuable::AttributeAlias Valuable::AttributeContainerT< T > Valuable::AttributeFlagsT< T > Valuable::AttributeFrame Valuable::AttributeSizeT< ElementType, SizeClass, ElementAttribute > Valuable::AttributeT< T > Valuable::FlagAlias Valuable::Node

Public Types

enum  Layer {
  DEFAULT = 0, STYLE, USER, STYLE_IMPORTANT,
  LAYER_COUNT, LAYER_CURRENT
}
 Attribute has multiple independent attribute values on LAYER_COUNT different layers. More...
 
typedef std::function< void()> ListenerFunc
 Callback function type in the listener API.
 
enum  ListenerRole { DELETE_ROLE = 1 << 0, CHANGE_ROLE = 1 << 1, ALL_ROLES = (CHANGE_ROLE << 1) -1 }
 Different listener roles, used when adding a new listener.
 
enum  ValueUnit {
  VU_UNKNOWN, VU_PXS, VU_PERCENTAGE, VU_EMS,
  VU_EXS
}
 Units of a value. More...
 

Public Member Functions

long addListener (ListenerFunc func, int role=CHANGE_ROLE)
 Adds a listener that is invoked whenever the value is changed. More...
 
long addListener (Node *listener, ListenerFunc func, int role=CHANGE_ROLE)
 Adds a listener that is invoked whenever the value is changed. More...
 
long addListener (v8::Persistent< v8::Function > func, int role=CHANGE_ROLE)
 Adds a JavaScript listener that is invoked whenever the value is changed. More...
 
virtual float asFloat (bool *const ok=0, Layer layer=LAYER_CURRENT) const
 Converts the value object in a floating point number. More...
 
virtual int asInt (bool *const ok=0, Layer layer=LAYER_CURRENT) const
 Converts the value object in an integer. More...
 
virtual QString asString (bool *const ok=0, Layer layer=LAYER_CURRENT) const
 Converts the value object to a string. More...
 
 Attribute (const Attribute &o)
 Create a copy of the given Attribute WITHOUT the link to host, listeners, or the attribute name. More...
 
 Attribute (Node *host, const QByteArray &name, bool transit=false)
 Constructs a new value object and attaches it to its host. More...
 
virtual Attributeattribute (const QByteArray &name) const
 Gets an Attribute with the given name. More...
 
virtual void clearValue (Layer layer)
 Unsets the value from a specific layer. More...
 
virtual void emitChange ()
 Invokes the change valueChanged function of all listeners.
 
virtual void eventProcess (const QByteArray &id, Radiant::BinaryData &data)
 Process a message. More...
 
void eventProcessFloat (const char *id, float v)
 Utility function for sending a float message to the object.
 
void eventProcessInt (const char *id, int v)
 Utility function for sending an int message to the object.
 
void eventProcessString (const char *id, const QString &str)
 Utility function for sending string message to the object.
 
void eventProcessString (const char *id, const char *str)
 Utility function for sending string message to the object.
 
void eventProcessVector2 (const char *id, Nimble::Vector2)
 Utility function for sending a Nimble::Vector2f message to the object.
 
void eventProcessVector3 (const char *id, Nimble::Vector3)
 Utility function for sending a Vector3 message to the object.
 
void eventProcessVector4 (const char *id, Nimble::Vector4)
 Utility function for sending a Vector4 message to the object.
 
virtual bool handleShorthand (const Valuable::StyleValue &value, Radiant::ArrayMap< Valuable::Attribute *, Valuable::StyleValue > &expanded)
 If attribute supports shorthand properties, this should be used to parse those. More...
 
Nodehost () const
 The host object of the value object (is any). More...
 
virtual bool isChanged () const
 
virtual bool isValueDefinedOnLayer (Layer layer) const
 Check if the given layer defines a value. More...
 
bool layerForSerialization (SerializationOptions flags, Layer &layer) const
 
const QByteArray & name () const
 Returns the name of the object.
 
const Attributeoperator= (const Attribute &)
 Create a copy of the given Attribute WITHOUT the link to host, listeners, or the attribute name. More...
 
AttributeownerShorthand () const
 
QByteArray path () const
 Returns the path (separated by '/'s) from the root.
 
void removeHost ()
 Sets the host pointer to zero and removes this object from the host. More...
 
bool removeListener (Node *listener, int role=ALL_ROLES)
 Removes a listener from the listener list. More...
 
bool removeListener (long id)
 Removes a listener from the listener list. More...
 
void removeListeners (int role=ALL_ROLES)
 Removes listeners from the listener list.
 
virtual ArchiveElement serialize (Archive &archive) const
 The object is serialized using its name as a tag name. More...
 
virtual bool set (float v, Layer layer=USER, ValueUnit unit=VU_UNKNOWN)
 Sets the value of the object.
 
virtual bool set (int v, Layer layer=USER, ValueUnit unit=VU_UNKNOWN)
 Sets the value of the object.
 
virtual bool set (const QString &v, Layer layer=USER, ValueUnit unit=VU_UNKNOWN)
 Sets the value of the object.
 
virtual bool set (const Nimble::Vector2f &v, Layer layer=USER, QList< ValueUnit > units=QList< ValueUnit >())
 Sets the value of the object.
 
virtual bool set (const Nimble::Vector3f &v, Layer layer=USER, QList< ValueUnit > units=QList< ValueUnit >())
 Sets the value of the object.
 
virtual bool set (const Nimble::Vector4f &v, Layer layer=USER, QList< ValueUnit > units=QList< ValueUnit >())
 Sets the value of the object.
 
virtual bool set (const StyleValue &value, Layer layer=USER)
 Sets the value of the object.
 
virtual void setAsDefaults ()
 Sets the current USER attribute value as the default value and clears the USER value. More...
 
void setName (const QByteArray &s)
 Sets the name of the object.
 
void setOwnerShorthand (Attribute *owner)
 
virtual QByteArray type () const
 Get the type id of the attribute. More...
 
- Public Member Functions inherited from Valuable::Serializable
virtual bool deserialize (const ArchiveElement &element)=0
 Deserializes (reads) this object from serializer element. More...
 
virtual bool deserializeXML (const DOMElement &element)
 Deserializes (reads) this object from an XML element. More...
 
bool isSerializable () const
 
void setSerializable (bool v)
 

Protected Member Functions

virtual void emitDelete ()
 Invokes the change valueDeleted function of all listeners.
 

Friends

class Node
 

Detailed Description

The base class for value objects.

Typical child classes include some POD (plain old data) elements (floats, ints, vector2) etc, that can be accessed through the API. The Attributes have names (QString), that can be used to access Attributes that are stored inside Node objects.

It is also possible to add listeners to values, so that if a value is changed, then a call-back to some other object is followed. The listener-API is a bit hard-core, but it has plenty of power when you need to track the state of other objects.

See Also
Node
Examples:
AttributesExample.cpp.

Member Enumeration Documentation

Attribute has multiple independent attribute values on LAYER_COUNT different layers.

The real effective value of the attribute comes from an active layer that has the highest priority. By default only DEFAULT layer has value (is enabled). Layer numerical value also means the layer priority, DEFAULT layer has the lowest priority, while STYLE_IMPORTANT has the highest priority.

Enumerator
DEFAULT 

Default, usually set in the constructor.

STYLE 

Set from a CSS file.

USER 

Set from a C++/JS code or by interaction / animators.

STYLE_IMPORTANT 

!important rules from CSS file

Units of a value.

Enumerator
VU_PXS 

Value defined in pixels.

VU_PERCENTAGE 

Value defined in percentage (100% == 1.0f)

VU_EMS 

Length value defined by font-size.

VU_EXS 

Length value defined by x-height of the current font.

Constructor & Destructor Documentation

Valuable::Attribute::Attribute ( const Attribute o)

Create a copy of the given Attribute WITHOUT the link to host, listeners, or the attribute name.

So only the values and transit parameter are copied.

Valuable::Attribute::Attribute ( Node host,
const QByteArray &  name,
bool  transit = false 
)

Constructs a new value object and attaches it to its host.

Parameters
hostThe host object. This object is automatically added to the host.
nameThe name (or id) of this attribute. Names are typically human-readable. The names should not contain white-spaces as they may be used in XML files etc.
transitShould value changes be transmitted forward. This is related to future uses, and can be largely ignored at the moment.

Member Function Documentation

long Valuable::Attribute::addListener ( ListenerFunc  func,
int  role = CHANGE_ROLE 
)

Adds a listener that is invoked whenever the value is changed.

Returns an id that can be used to remove the listener later.

Parameters
funclistener function
rolewhen should the listener function be called
Returns
listener id
See Also
removeListener
Examples:
AttributesExample.cpp.
long Valuable::Attribute::addListener ( Node listener,
ListenerFunc  func,
int  role = CHANGE_ROLE 
)

Adds a listener that is invoked whenever the value is changed.

Returns an id that can be used to remove the listener later. The listener is removed when the listener object is deleted. This function can fail and return -1 if the target listener is being destroyed when this function is called.

Parameters
listenerlistener that owns the callback
funclistener function
rolewhen should the listener function be called
Returns
listener id or -1 on failure
See Also
removeListener
long Valuable::Attribute::addListener ( v8::Persistent< v8::Function >  func,
int  role = CHANGE_ROLE 
)

Adds a JavaScript listener that is invoked whenever the value is changed.

Parameters
funclistener function
rolewhen should the listener function be called
Returns
listener id that can be used to remove the listener with removeListener
See Also
removeListener
virtual QString Valuable::Attribute::asString ( bool *const  ok = 0,
Layer  layer = LAYER_CURRENT 
) const
virtual

Converts the value object to a string.

Parameters
okIf non-null, *ok is set to true/false on success/error
Returns
Object as a string, the default implementation returns an empty string

Reimplemented in Valuable::AttributeFlagsT< T >, Valuable::AttributeFlagsT< EdgeFlags >, Valuable::AttributeFlagsT< Flags >, Valuable::AttributeFlagsT< MultiTouch::TrackedObjectType >, Valuable::AttributeFlagsT< LimitBehaviorFlags >, Valuable::AttributeEnumT< T >, Valuable::AttributeEnumT< Mode >, Valuable::AttributeEnumT< FlexDirection >, Valuable::AttributeEnumT< FlexWrap >, Valuable::AttributeEnumT< ResizeToContent >, Valuable::AttributeEnumT< MultiWidgets::LimitScaleOperator::Mode >, Valuable::AttributeEnumT< AlignContent >, Valuable::AttributeEnumT< JustifyContent >, Valuable::AttributeEnumT< Align >, Valuable::AttributeEnumT< IncludeMode >, Valuable::AttributeEnumT< Orientation >, Stylish::AttributeFont, Valuable::AttributeSizeT< ElementType, SizeClass, ElementAttribute >, Valuable::AttributeVector< VectorType >, Valuable::AttributeVector< Nimble::Vector2f >, Valuable::AttributeVector< Radiant::Color >, Valuable::AttributeVector< VectorT< T > >, Valuable::AttributeFrame, Valuable::AttributeNumericT< T >, Valuable::AttributeNumericT< Mode >, Valuable::AttributeNumericT< FlexDirection >, Valuable::AttributeNumericT< FlexWrap >, Valuable::AttributeNumericT< ResizeToContent >, Valuable::AttributeNumericT< MultiWidgets::LimitScaleOperator::Mode >, Valuable::AttributeNumericT< AlignContent >, Valuable::AttributeNumericT< JustifyContent >, Valuable::AttributeNumericT< Align >, Valuable::AttributeNumericT< IncludeMode >, Valuable::AttributeNumericT< Uuid >, Valuable::AttributeNumericT< Orientation >, Valuable::AttributeMatrix< MatrixType, ElementType, N >, Valuable::AttributeStringMap, Valuable::AttributeAlias, Valuable::AttributeRectT< T >, and Valuable::AttributeStringList.

virtual Attribute* Valuable::Attribute::attribute ( const QByteArray &  name) const
virtual

Gets an Attribute with the given name.

Parameters
nameAttribute name to search for
Returns
Null if no object can be found

Reimplemented in Valuable::Node, Valuable::Node, and Valuable::AttributeAlias.

Examples:
AttributesExample.cpp.
virtual void Valuable::Attribute::eventProcess ( const QByteArray &  id,
Radiant::BinaryData data 
)
virtual

Process a message.

This method is a key element in the event-passing system. It is used to deliver information between objects. The information contains two parts:

  1. Identifier: A character string that gives the address for the adjustment
  2. Data: A binary blob that contains information for the message

This function is overridden in number of classes that need to receive and process events. In a typical case, when overriding this function, you should either process the message, or call the function of the parent class.

void MyClass::eventProcess(const QByteArray & type, Radiant::BinaryData & data)
{
if(type == "jump")
doJump();
else if(type == "crawl") {
bool ok;
int speed = data.readInt32(&ok);
if(ok)
doCrawl(speed);
}
else
Parent::eventProcess(type, data);
}
Parameters
idThe indentifier for the message. Typically this is quite human-readable
dataBinary blob that contains the argument data in easily parseable format.

Reimplemented in MultiWidgets::Widget, Luminous::MultiHead, MultiWidgets::KeyboardWidget, Valuable::AttributeFlagsT< T >, Valuable::AttributeFlagsT< EdgeFlags >, Valuable::AttributeFlagsT< Flags >, Valuable::AttributeFlagsT< MultiTouch::TrackedObjectType >, Valuable::AttributeFlagsT< LimitBehaviorFlags >, MultiWidgets::Application, Resonant::ModuleSamplePlayer, MultiWidgets::CloudWidget, Valuable::AttributeEnumT< T >, Valuable::AttributeEnumT< Mode >, Valuable::AttributeEnumT< FlexDirection >, Valuable::AttributeEnumT< FlexWrap >, Valuable::AttributeEnumT< ResizeToContent >, Valuable::AttributeEnumT< MultiWidgets::LimitScaleOperator::Mode >, Valuable::AttributeEnumT< AlignContent >, Valuable::AttributeEnumT< JustifyContent >, Valuable::AttributeEnumT< Align >, Valuable::AttributeEnumT< IncludeMode >, Valuable::AttributeEnumT< Orientation >, Valuable::AttributeSizeT< ElementType, SizeClass, ElementAttribute >, MultiWidgets::VideoWidget, MultiWidgets::ItemFlowWidget, Valuable::AttributeIntT< T >, Valuable::AttributeIntT< Uuid >, MultiWidgets::ListWidget, Valuable::AttributeFloatT< T >, MultiWidgets::ImageWidget, MultiWidgets::TextEditWidget, MultiWidgets::ImageMovieWidget, MultiWidgets::TimerDialWidget, Valuable::AttributeVector< VectorType >, Valuable::AttributeVector< Nimble::Vector2f >, Valuable::AttributeVector< Radiant::Color >, Valuable::AttributeVector< VectorT< T > >, MultiWidgets::FlippingWidget, Resonant::Module, Resonant::ModulePanner, MultiWidgets::BrowserFrameWidget, MultiWidgets::JavaScriptWidget, Valuable::AttributeTimeStamp, Resonant::ModuleOutCollect, MultiWidgets::BookWidget, MultiWidgets::RotateTowardsHandsOperator, Valuable::AttributeString, MultiWidgets::LayoutEngine, Valuable::AttributeAlias, and WebBrowserCef::BrowserVirtualKeyboardOperator.

virtual bool Valuable::Attribute::handleShorthand ( const Valuable::StyleValue value,
Radiant::ArrayMap< Valuable::Attribute *, Valuable::StyleValue > &  expanded 
)
virtual

If attribute supports shorthand properties, this should be used to parse those.

For example "background: url('image.png') repeat" is a shorhand for setting background-image to "url('image.png')" and background-repeat to "repeat".

Parameters
[in]valueshorthand value
[out]expandedshorthand property split to parts. With the previous background-example map should have two values.
Returns
true if shorthand was successfully handled
See Also
http://www.w3.org/TR/CSS21/about.html#shorthand

Reimplemented in Valuable::AttributeFlagsT< T >, Valuable::AttributeFlagsT< EdgeFlags >, Valuable::AttributeFlagsT< Flags >, Valuable::AttributeFlagsT< MultiTouch::TrackedObjectType >, Valuable::AttributeFlagsT< LimitBehaviorFlags >, Valuable::AttributeFrame, Valuable::AttributeSizeT< ElementType, SizeClass, ElementAttribute >, Valuable::FlagAliasT< T >, Stylish::AttributeFont, Valuable::AttributeAlias, Stylish::AttributeBorder, and Stylish::AttributeBackground.

Node* Valuable::Attribute::host ( ) const
inline

The host object of the value object (is any).

Returns
Pointer to the host
const Attribute& Valuable::Attribute::operator= ( const Attribute )

Create a copy of the given Attribute WITHOUT the link to host, listeners, or the attribute name.

So only the values and transit parameter are copied.

void Valuable::Attribute::removeHost ( )

Sets the host pointer to zero and removes this object from the host.

bool Valuable::Attribute::removeListener ( Node listener,
int  role = ALL_ROLES 
)

Removes a listener from the listener list.

Returns
True if any items from the list were removed, otherwise false
bool Valuable::Attribute::removeListener ( long  id)

Removes a listener from the listener list.

Parameters
idlistener id, same as the return value in addListener
Returns
True if any items from the list were removed, otherwise false
virtual ArchiveElement Valuable::Attribute::serialize ( Archive archive) const
virtual
virtual void Valuable::Attribute::setAsDefaults ( )
inlinevirtual
virtual QByteArray Valuable::Attribute::type ( ) const
inlinevirtual

Get the type id of the attribute.

Returns
type of the attribute

Reimplemented in MultiWidgets::Widget, Luminous::MultiHead::Window, Luminous::MultiHead::Area, MultiWidgets::Operator, and Valuable::AttributeAlias.