The base class for value objects. More...
#include <Valuable/Attribute.hpp>
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 Attribute * | attribute (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... | |
| Node * | host () 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 Attribute & | operator= (const Attribute &) |
| Create a copy of the given Attribute WITHOUT the link to host, listeners, or the attribute name. More... | |
| Attribute * | ownerShorthand () 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 |
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.
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 |
| 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.
| host | The host object. This object is automatically added to the host. |
| name | The 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. |
| transit | Should value changes be transmitted forward. This is related to future uses, and can be largely ignored at the moment. |
| 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.
| func | listener function |
| role | when should the listener function be called |
| 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.
| listener | listener that owns the callback |
| func | listener function |
| role | when should the listener function be called |
| 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.
| func | listener function |
| role | when should the listener function be called |
|
virtual |
Converts the value object in a floating point number.
| ok | If non-null, *ok is set to true/false on success/error |
Reimplemented in 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 >, and Valuable::AttributeAlias.
|
virtual |
Converts the value object in an integer.
| ok | If non-null, *ok is set to true/false on success/error |
Reimplemented in Valuable::AttributeFlagsT< T >, Valuable::AttributeFlagsT< EdgeFlags >, Valuable::AttributeFlagsT< Flags >, Valuable::AttributeFlagsT< MultiTouch::TrackedObjectType >, Valuable::AttributeFlagsT< LimitBehaviorFlags >, Valuable::FlagAliasT< T >, 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 >, and Valuable::AttributeAlias.
|
virtual |
Converts the value object to a string.
| ok | If non-null, *ok is set to true/false on success/error |
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 |
Gets an Attribute with the given name.
| name | Attribute name to search for |
Reimplemented in Valuable::Node, Valuable::Node, and Valuable::AttributeAlias.
|
virtual |
Unsets the value from a specific layer.
| layer | layer to clear, must not be DEFAULT, since DEFAULT layer should always be set |
Reimplemented in Valuable::AttributeT< Mode >, Valuable::AttributeT< FlexDirection >, Valuable::AttributeT< FlexWrap >, Valuable::AttributeT< ResizeToContent >, Valuable::AttributeT< Nimble::Vector2f >, Valuable::AttributeT< QString >, Valuable::AttributeT< JustifyContent >, Valuable::AttributeT< VectorType >, Valuable::AttributeT< Align >, Valuable::AttributeT< Radiant::TimeStamp >, Valuable::AttributeT< bool >, Valuable::AttributeT< StyleValue >, Valuable::AttributeFlagsT< T >, Valuable::AttributeFlagsT< EdgeFlags >, Valuable::AttributeFlagsT< Flags >, Valuable::AttributeFlagsT< MultiTouch::TrackedObjectType >, Valuable::AttributeFlagsT< LimitBehaviorFlags >, Valuable::AttributeSizeT< ElementType, SizeClass, ElementAttribute >, Valuable::AttributeFrame, Valuable::AttributeLocation2f, Valuable::AttributeFloatT< T >, Valuable::FlagAliasT< T >, and Valuable::AttributeAlias.
|
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:
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.
| id | The indentifier for the message. Typically this is quite human-readable |
| data | Binary 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 |
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".
| [in] | value | shorthand value |
| [out] | expanded | shorthand property split to parts. With the previous background-example map should have two values. |
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.
|
inline |
The host object of the value object (is any).
|
virtual |
Reimplemented in Valuable::AttributeT< T >, Valuable::AttributeT< Mode >, Valuable::AttributeT< FlexDirection >, Valuable::AttributeT< FlexWrap >, Valuable::AttributeT< ResizeToContent >, Valuable::AttributeT< Nimble::Vector2f >, Valuable::AttributeT< QString >, Valuable::AttributeT< Radiant::Color >, Valuable::AttributeT< Nimble::RectT< T > >, Valuable::AttributeT< MultiWidgets::LimitScaleOperator::Mode >, Valuable::AttributeT< MatrixType >, Valuable::AttributeT< AlignContent >, Valuable::AttributeT< JustifyContent >, Valuable::AttributeT< VectorType >, Valuable::AttributeT< Align >, Valuable::AttributeT< IncludeMode >, Valuable::AttributeT< Radiant::TimeStamp >, Valuable::AttributeT< Uuid >, Valuable::AttributeT< bool >, Valuable::AttributeT< StyleValue >, Valuable::AttributeT< Orientation >, Valuable::AttributeT< QMap< QString, QString > >, Valuable::AttributeT< QStringList >, Valuable::AttributeT< VectorT< T > >, Valuable::AttributeSizeT< ElementType, SizeClass, ElementAttribute >, Valuable::AttributeFrame, Valuable::AttributeContainerT< T >, Valuable::AttributeContainerT< std::map< float, KeyFrame< T > > >, Valuable::AttributeContainerT< std::map< Key, T, Compare, Allocator > >, Valuable::AttributeContainerT< std::list< MultiWidgets::OperatorPtr > >, and Valuable::AttributeAlias.
|
virtual |
Check if the given layer defines a value.
| layer | layer to check |
Reimplemented in Valuable::AttributeT< Mode >, Valuable::AttributeT< FlexDirection >, Valuable::AttributeT< FlexWrap >, Valuable::AttributeT< ResizeToContent >, Valuable::AttributeT< Nimble::Vector2f >, Valuable::AttributeT< QString >, Valuable::AttributeT< JustifyContent >, Valuable::AttributeT< VectorType >, Valuable::AttributeT< Align >, Valuable::AttributeT< Radiant::TimeStamp >, Valuable::AttributeT< bool >, Valuable::AttributeT< StyleValue >, Valuable::FlagAliasT< T >, Valuable::AttributeSizeT< ElementType, SizeClass, ElementAttribute >, and Valuable::AttributeAlias.
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.
| bool Valuable::Attribute::removeListener | ( | long | id | ) |
Removes a listener from the listener list.
| id | listener id, same as the return value in addListener |
|
virtual |
The object is serialized using its name as a tag name.
| archive | Serialization archive that is used to create new elements. |
Implements Valuable::Serializable.
Reimplemented in Valuable::AttributeT< T >, Valuable::AttributeT< Mode >, Valuable::AttributeT< FlexDirection >, Valuable::AttributeT< FlexWrap >, Valuable::AttributeT< ResizeToContent >, Valuable::AttributeT< Nimble::Vector2f >, Valuable::AttributeT< QString >, Valuable::AttributeT< Radiant::Color >, Valuable::AttributeT< Nimble::RectT< T > >, Valuable::AttributeT< MultiWidgets::LimitScaleOperator::Mode >, Valuable::AttributeT< MatrixType >, Valuable::AttributeT< AlignContent >, Valuable::AttributeT< JustifyContent >, Valuable::AttributeT< VectorType >, Valuable::AttributeT< Align >, Valuable::AttributeT< IncludeMode >, Valuable::AttributeT< Radiant::TimeStamp >, Valuable::AttributeT< Uuid >, Valuable::AttributeT< bool >, Valuable::AttributeT< StyleValue >, Valuable::AttributeT< Orientation >, Valuable::AttributeT< QMap< QString, QString > >, Valuable::AttributeT< QStringList >, Valuable::AttributeT< VectorT< T > >, Valuable::Node, Valuable::AttributeContainerT< T >, Valuable::AttributeContainerT< std::map< float, KeyFrame< T > > >, Valuable::AttributeContainerT< std::map< Key, T, Compare, Allocator > >, Valuable::AttributeContainerT< std::list< MultiWidgets::OperatorPtr > >, Valuable::FlagAliasT< T >, and Valuable::AttributeAlias.
|
inlinevirtual |
Sets the current USER attribute value as the default value and clears the USER value.
Reimplemented in Valuable::AttributeT< T >, Valuable::AttributeT< Mode >, Valuable::AttributeT< FlexDirection >, Valuable::AttributeT< FlexWrap >, Valuable::AttributeT< ResizeToContent >, Valuable::AttributeT< Nimble::Vector2f >, Valuable::AttributeT< QString >, Valuable::AttributeT< Radiant::Color >, Valuable::AttributeT< Nimble::RectT< T > >, Valuable::AttributeT< MultiWidgets::LimitScaleOperator::Mode >, Valuable::AttributeT< MatrixType >, Valuable::AttributeT< AlignContent >, Valuable::AttributeT< JustifyContent >, Valuable::AttributeT< VectorType >, Valuable::AttributeT< Align >, Valuable::AttributeT< IncludeMode >, Valuable::AttributeT< Radiant::TimeStamp >, Valuable::AttributeT< Uuid >, Valuable::AttributeT< bool >, Valuable::AttributeT< StyleValue >, Valuable::AttributeT< Orientation >, Valuable::AttributeT< QMap< QString, QString > >, Valuable::AttributeT< QStringList >, Valuable::AttributeT< VectorT< T > >, Valuable::Node, Valuable::AttributeFlagsT< T >, Valuable::AttributeFlagsT< EdgeFlags >, Valuable::AttributeFlagsT< Flags >, Valuable::AttributeFlagsT< MultiTouch::TrackedObjectType >, Valuable::AttributeFlagsT< LimitBehaviorFlags >, Valuable::AttributeSizeT< ElementType, SizeClass, ElementAttribute >, Valuable::AttributeFrame, Valuable::AttributeLocation2f, Valuable::AttributeFloatT< T >, and Valuable::AttributeAlias.
|
inlinevirtual |
Get the type id of the attribute.
Reimplemented in MultiWidgets::Widget, Luminous::MultiHead::Window, Luminous::MultiHead::Area, MultiWidgets::Operator, and Valuable::AttributeAlias.