Documents > BPS V2 C++ API

This class is a generic editable object. More...

#include <bpspropertyobject.h>

+ Inheritance diagram for BpsPropertyObject:

List of all members.

Public Slots

void setModified (bool aModified=true)
 Set or clear the modification status.
virtual bool setProperty (const char *aName, const QVariant &aValue)
 Set the value of a property.
bool setPropertyAsString (const char *aName, const QString &aValue)
 Set the value of a property by converting from a string.

Signals

void childInserted (int aIndex, BpsPropertyObject *aChild)
 This signal is emitted when a new child is inserted.
void childMoved (int aOldIndex, int aNewIndex)
 This signal is emitted when a child is moved.
void childRemoved (int aIndex, BpsPropertyObject *aChild)
 This signal is emitted when a child is removed.
void modifiedChanged (bool aModified)
 This signal is emitted when the modification status is changed.
void objectChanged ()
 This signal is emitted whenever anything in the object or any of its descendants (children, grandchildren, ...) is changed.
void propertyChanged (const QByteArray &aName, const QVariant &aNewValue, const QVariant &aOldValue)
 This signal is emitted whenever a property changes, or after emitValues().

Public Member Functions

void addAttribute (const char *aProperty, const char *aAttribute, const QVariant &aValue=true)
 Adds or remove an attribute to/from an existing property.
void addProperty (const char *aName, const QVariant &aValue)
 Add or remove a property.
void appendChild (BpsPropertyObject *aChild)
 Appends a child to the end of the children list.
QVariant attribute (const char *aProperty, const char *aAttribute) const
 Get the attributes value.
QList< QByteArray > attributeNames (const char *aProperty) const
 Get a list of all attributes defined for a certain property.
 BpsPropertyObject (QObject *aParent=0)
 Constructor for BpsPropertyObject.
 BpsPropertyObject (const QString &aName, QObject *aParent=0)
 Constructor for BpsPropertyObject.
 BpsPropertyObject (const BpsPropertyObject &aOther)
 Copy-constructor for BpsPropertyObject.
BpsPropertyObjectchildAt (int aIndex) const
 Get pointer to indexed child element.
int childCount () const
int childIndex (BpsPropertyObject *aChild) const
 Get index of a child.
QList< BpsPropertyObject * > children () const
void clear ()
 Removes all dynamic properties and deletes all children.
void emitValues ()
 Emits valueChanged() for all properties.
void insertChild (int aIndex, BpsPropertyObject *aChild)
 Insert a child at the specified position in the children list.
bool isModified () const
bool isValid (BpsPropertyObject *aObject) const
void loadXml (const QString &aDocType, const QString &aXml)
 Load the object from XML.
QString makeXml (const QString &aDocType, bool aFormat=false) const
 Creates XML to save the object and its children.
void moveChild (int aOldIndex, int aNewIndex)
 Move a child in the list.
BpsPropertyObjectoperator= (const BpsPropertyObject &aOther)
 Assignment operator.
BpsPropertyObjectparent () const
 Get the parent of this object.
QString propertyAsString (const char *aName) const
 Gets a string representation of the value.
BpsPropertyObjectremoveChild (int aIndex)
 Remove a child.

Protected Member Functions

virtual BpsPropertyObjectxmlCreateObject (const QString &aTagName, int aLevel) const
 Create a new object while processing loadXml().
virtual QString xmlTagName (int aLevel) const
 Define a XML tag for the element of the level.

Detailed Description

This class is a generic editable object.

Query the property value with QObject::property(const char* name). If the property does not exist, an invalid value will be returned.

A list of all existing properties can be fetched with QObject::dynamicPropertyNames().


Constructor & Destructor Documentation

BpsPropertyObject::BpsPropertyObject ( QObject *  aParent = 0)

Constructor for BpsPropertyObject.

Parameters:
[in]aParentThe parent widget.
BpsPropertyObject::BpsPropertyObject ( const QString &  aName,
QObject *  aParent = 0 
)

Constructor for BpsPropertyObject.

Parameters:
[in]aNameThe object name to set.
[in]aParentThe parent widget.
BpsPropertyObject::BpsPropertyObject ( const BpsPropertyObject aOther)

Copy-constructor for BpsPropertyObject.

Parameters:
[in]aOtherThe source property to clone.

Member Function Documentation

void BpsPropertyObject::addAttribute ( const char *  aProperty,
const char *  aAttribute,
const QVariant &  aValue = true 
)

Adds or remove an attribute to/from an existing property.

In case the attribute for this property did already exist, it's value is overwritten. Passing an invalid value will remove the attribute.

The currently supported attributes are:

Attribute Name Remark Attribute Type Property Types
readOnly setValue() does not change the value QVariant::Bool any
noExport Do not export this property to XML QVariant::Bool any
noImport Do not import this property from XML QVariant::Bool any
xmlElement Save as separate XML element instead of as attibute. QVariant::Bool any
Parameters:
[in]aPropertyName of the property.
[in]aAttributeThe attribute name.
[in]aValueThe attribute value.
void BpsPropertyObject::addProperty ( const char *  aName,
const QVariant &  aValue 
)

Add or remove a property.

Make sure to pass an initial value of the desired type. Remove a property by passing an invalid value.

Parameters:
[in]aNameName of the property.
[in]aValueThe attribute value.
void BpsPropertyObject::appendChild ( BpsPropertyObject aChild)

Appends a child to the end of the children list.

Parameters:
[in]aChildPointer to the child to be inserted.
QVariant BpsPropertyObject::attribute ( const char *  aProperty,
const char *  aAttribute 
) const

Get the attributes value.

In case there is no such attribute, QVariant() is returned.

Parameters:
[in]aPropertyName of the property.
[in]aAttributeThe attribute name.
Returns:
A QVariant is returned.
QList<QByteArray> BpsPropertyObject::attributeNames ( const char *  aProperty) const

Get a list of all attributes defined for a certain property.

Parameters:
[in]aPropertyName of the property.
Returns:
A list of attribute names.
BpsPropertyObject* BpsPropertyObject::childAt ( int  aIndex) const

Get pointer to indexed child element.

Parameters:
[in]aIndexThe index of the requested child.
Returns:
Pointer to child.
int BpsPropertyObject::childCount ( ) const
Returns:
The number of children of this element.
int BpsPropertyObject::childIndex ( BpsPropertyObject aChild) const

Get index of a child.

Parameters:
[in]aChildThis is a parameter.
Returns:
Child index, or -1 if no such child found.
void BpsPropertyObject::childInserted ( int  aIndex,
BpsPropertyObject aChild 
) [signal]

This signal is emitted when a new child is inserted.

Parameters:
[in]aIndexIndex of the new child.
[in]aChildPointer to the new child.
void BpsPropertyObject::childMoved ( int  aOldIndex,
int  aNewIndex 
) [signal]

This signal is emitted when a child is moved.

Parameters:
[in]aOldIndexThe former index of the child.
[in]aNewIndexThe new index of the child.
void BpsPropertyObject::childRemoved ( int  aIndex,
BpsPropertyObject aChild 
) [signal]

This signal is emitted when a child is removed.

ATTENTION! Both, index and child pointer are now invalid!

Parameters:
[in]aIndexFormer index of the removed child.
[in]aChildFormer pointer to the new child.
QList<BpsPropertyObject*> BpsPropertyObject::children ( ) const
Returns:
The list of children.
void BpsPropertyObject::clear ( )

Removes all dynamic properties and deletes all children.

The object name stays.

void BpsPropertyObject::insertChild ( int  aIndex,
BpsPropertyObject aChild 
)

Insert a child at the specified position in the children list.

Parameters:
[in]aIndexThe position to insert at.
[in]aChildPointer to the child to be inserted.
bool BpsPropertyObject::isModified ( ) const
Returns:
True if the item has been modified.
bool BpsPropertyObject::isValid ( BpsPropertyObject aObject) const
Parameters:
[in]aObjectObject to check.
Returns:
True if the object belongs to this item (is this item itself or any descendant).
void BpsPropertyObject::loadXml ( const QString &  aDocType,
const QString &  aXml 
)

Load the object from XML.

Parameters:
[in]aDocTypeDOCTYPE to check. No check when empty string.
[in]aXmlString with the XML representation of the object to be loaded.
QString BpsPropertyObject::makeXml ( const QString &  aDocType,
bool  aFormat = false 
) const

Creates XML to save the object and its children.

Parameters:
[in]aDocTypeDOCTYPE to use.
[in]aFormatFormat the XML with newlines and indentions.
Returns:
A QString with the XML representation of the object and it's children.
void BpsPropertyObject::modifiedChanged ( bool  aModified) [signal]

This signal is emitted when the modification status is changed.

Parameters:
[in]aModifiedThe new modification status.
void BpsPropertyObject::moveChild ( int  aOldIndex,
int  aNewIndex 
)

Move a child in the list.

Parameters:
[in]aOldIndexIndex of the old position.
[in]aNewIndexIndex of the new position.
void BpsPropertyObject::objectChanged ( ) [signal]

This signal is emitted whenever anything in the object or any of its descendants (children, grandchildren, ...) is changed.

It may be any property add/remove/change, attribute add/remove/change, child add/remove/move. This signal is not be emitted by emitValues() or setModified().

BpsPropertyObject& BpsPropertyObject::operator= ( const BpsPropertyObject aOther)

Assignment operator.

Parameters:
[in]aOtherThe source property to clone.
Returns:
Reference to the current object.
BpsPropertyObject* BpsPropertyObject::parent ( ) const

Get the parent of this object.

Returns:
The parent of this element, or 0 if this is a top level element.
QString BpsPropertyObject::propertyAsString ( const char *  aName) const

Gets a string representation of the value.

This representation is also used for XML file generation.

Special conversions are made for types listed in the table below:

Type Representation
QVariant::PointF x,y
QVariant::SizeF width,height
QVariant::Color #AARRGGBB where RR,GG,BB are the red green and blue values in hex, and AA is the alpha-channel (transparency) in hex

Any other types are returned as by QVariant::toString().

Parameters:
[in]aNameName of the property.
Returns:
The value of the named property represented as string.
void BpsPropertyObject::propertyChanged ( const QByteArray &  aName,
const QVariant &  aNewValue,
const QVariant &  aOldValue 
) [signal]

This signal is emitted whenever a property changes, or after emitValues().

Parameters:
[in]aNameThe name of the property.
[in]aNewValueThe new value.
[in]aOldValueThe previous value. Note that this is equal to aNewValue when emit was done by emitValues().
BpsPropertyObject* BpsPropertyObject::removeChild ( int  aIndex)

Remove a child.

The child itself is not deleted, but it's parent is set to 0.

Parameters:
[in]aIndexIndex of the child to be removed.
Returns:
Pointer to removed child.
void BpsPropertyObject::setModified ( bool  aModified = true) [slot]

Set or clear the modification status.

Parameters:
[in]aModifiedThe new status to set.
virtual bool BpsPropertyObject::setProperty ( const char *  aName,
const QVariant &  aValue 
) [virtual, slot]

Set the value of a property.

Attempts to set the value of a not existing property, or a property with the attribute readOnly are ignored.

Parameters:
[in]aNameName of the property.
[in]aValueThe new value.
Returns:
True if the value was modified.

Reimplemented in BpsReportElement.

bool BpsPropertyObject::setPropertyAsString ( const char *  aName,
const QString &  aValue 
) [slot]

Set the value of a property by converting from a string.

See propertyAsString(const char* aName) for string format information.

After string conversion, setValue(const QString& aName, const QVariant& aValue) is called to effectively save the value.

Parameters:
[in]aNameName of the property.
[in]aValueThe new value.
Returns:
True if the value was modified.
virtual BpsPropertyObject* BpsPropertyObject::xmlCreateObject ( const QString &  aTagName,
int  aLevel 
) const [protected, virtual]

Create a new object while processing loadXml().

The default implementation returns a new BpsPropertyObject.

Parameters:
[in]aTagNameTag name of the element to be created.
[in]aLevelElement level. The top level is 0, but this method will only be called for children of level 1 and up.
Returns:
A BpsPropertyObject*, or a thereof derived object. Return 0 if no object can be created for the given name and level.

Reimplemented in BpsReportElement.

virtual QString BpsPropertyObject::xmlTagName ( int  aLevel) const [protected, virtual]

Define a XML tag for the element of the level.

Parameters:
[in]aLevelElement level. The top level is 0.
Returns:
Tag name. The default implementation returns object{level}.

Reimplemented in BpsReportElement.


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