An abstract object characterized by properties. More...
#include <klfpobj.h>
Public Member Functions | |
KLFAbstractPropertizedObject () | |
virtual | ~KLFAbstractPropertizedObject () |
virtual QString | objectKind () const =0 |
A string representing this object type. | |
virtual QVariant | property (const QString &propName) const =0 |
get a property's value | |
virtual QStringList | propertyNameList () const =0 |
Queries what property are (or can be) set. | |
virtual bool | setProperty (const QString &pname, const QVariant &value)=0 |
Assign a value to a property. | |
virtual QMap< QString, QVariant > | allProperties () const |
Convenience function to retrieve all properties. | |
virtual bool | setAllProperties (const QMap< QString, QVariant > &data) |
Convenience function to load a set of property values. | |
virtual bool | hasFixedTypes () const |
virtual QByteArray | typeNameFor (const QString &property) const |
Corresonding type for the given property. | |
virtual QByteArray | typeSpecificationFor (const QString &property) const |
A type specification for the given property. |
An abstract object characterized by properties.
This class is an interface to get and set property values for objects like KLFPropertizedObject, QObject, QVariantMap-based, which store their information as logical properties.
Such objects should either inherit explicitely this class, or should provide an adapter class (eg. as for QObject).
This class was developed in the general idea of trying to avoid version issues in data formats, and storing everything as properties in a coherent form, eg. XML. See klfSave() and klfLoad().
QDataStream operators are implemented for this object.
Definition at line 32 of file klfpobj.cpp.
Definition at line 35 of file klfpobj.cpp.
QMap< QString, QVariant > KLFAbstractPropertizedObject::allProperties | ( | ) | const [virtual] |
Convenience function to retrieve all properties.
This function returns all the properties that have been set on this object with their corresponding values.
The default implementation uses propertyNameList() and property() to generate the required return value. It should be enough for most cases. If you really want to however, you can reimplement this function for your needs.
Reimplemented in KLFPropertizedObject.
Definition at line 51 of file klfpobj.cpp.
References property(), and propertyNameList().
Referenced by klfSaveVariantToText().
virtual bool KLFAbstractPropertizedObject::hasFixedTypes | ( | ) | const [inline, virtual] |
Definition at line 129 of file klfpobj.h.
Referenced by klfLoadVariantFromText(), and klfSaveVariantToText().
virtual QString KLFAbstractPropertizedObject::objectKind | ( | ) | const [pure virtual] |
A string representing this object type.
The string should be short, and contain only alphanumeric characters (a good idea is to give the class name here).
This is used for example as node name in XML exports.
Implemented in KLFPropertizedObject.
Referenced by klfLoadVariantFromText().
virtual QVariant KLFAbstractPropertizedObject::property | ( | const QString & | propName | ) | const [pure virtual] |
get a property's value
Implemented in KLFPropertizedObject.
Referenced by allProperties().
virtual QStringList KLFAbstractPropertizedObject::propertyNameList | ( | ) | const [pure virtual] |
Queries what property are (or can be) set.
This function should return a list of property names that have been explicitely set on this object.
Implemented in KLFPropertizedObject.
Referenced by allProperties().
bool KLFAbstractPropertizedObject::setAllProperties | ( | const QMap< QString, QVariant > & | data | ) | [virtual] |
Convenience function to load a set of property values.
This function tries to set all the properties given in data
. If one or more setProperty()
call failed, then this function returns FALSE. TRUE is returned when all properties were set successfully.
The default implementation uses propertyNameList() and setProperty() to set all the given properties.
Subclasses may be interested in reimplementing this function in order to garantee the the properties are set in a correct order. This might be necessary in some cases where you are allowed to set a given property depending on the value of another, for example a "Locked" property.
Reimplemented in KLFPropertizedObject.
Definition at line 61 of file klfpobj.cpp.
References QMap::begin(), QMap::end(), KLF_DEBUG_BLOCK, KLF_FUNC_NAME, klfDbg, and setProperty().
Referenced by klfLoadVariantFromText().
virtual bool KLFAbstractPropertizedObject::setProperty | ( | const QString & | pname, |
const QVariant & | value | ||
) | [pure virtual] |
Assign a value to a property.
It is up to the subclasse to implement this function.
This function checks that the given property pname
is allowed to be modified to the new value value
. If this is not the case, returns FALSE. Otherwise, this function tries to save the new value for the given property.
Implemented in KLFPropertizedObject.
Referenced by setAllProperties().
virtual QByteArray KLFAbstractPropertizedObject::typeNameFor | ( | const QString & | property | ) | const [inline, virtual] |
Corresonding type for the given property.
This function is only relevant if hasFixedTypes() returns TRUE.
Definition at line 135 of file klfpobj.h.
Referenced by klfLoadVariantFromText().
virtual QByteArray KLFAbstractPropertizedObject::typeSpecificationFor | ( | const QString & | property | ) | const [inline, virtual] |
A type specification for the given property.
A type specification is some additional data that specifies further the type. For example, a type KLFEnumType has to be specified to which enum values are allowed.
This is only used for types that derive KLFSpecifyableType.
Definition at line 144 of file klfpobj.h.
Referenced by klfLoadVariantFromText().