All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
Public Member Functions
Qtilities::Core::MultiContextProperty Class Reference

A MultiContextProperty provides a property which has different values in different contexts. More...

#include <QtilitiesProperty.h>

Inheritance diagram for Qtilities::Core::MultiContextProperty:
Inheritance graph
[legend]

List of all members.

Public Member Functions

void addContext (QVariant new_value, int context_id)
 Adds an context ID from the property.
QMap< quint32, QVariant > contextMap () const
 Returns a map with the contexts and their respective values for this property.
virtual
IExportable::ExportResultFlags 
exportBinary (QDataStream &stream) const
 Allows exporting to a QDataStream.
virtual
IExportable::ExportResultFlags 
exportXml (QDomDocument *doc, QDomElement *object_node) const
 Allows exporting to an XML document. A reference to the QDomElement to which the object's information must be added is provided, along with a reference to the QDomDocument.
bool hasContext (int context_id) const
 Checks if this property is defined within the context of the specified observer.
virtual
IExportable::ExportResultFlags 
importBinary (QDataStream &stream, QList< QPointer< QObject > > &import_list)
 Allows importing and reconstruction of the object state from information provided in a QDataStream.
virtual
IExportable::ExportResultFlags 
importXml (QDomDocument *doc, QDomElement *object_node, QList< QPointer< QObject > > &import_list)
int lastChangedContext () const
 Returns the context in which the last change took place.
QObject * objectBase ()
const QObject * objectBase () const
void removeContext (int context_id)
 Removes an context ID from the property.
virtual bool setValue (QVariant new_value, int context_id)
 Sets the value of the property.
virtual ExportModeFlags supportedFormats () const
 Provides information about the export format(s) supported by your implementation of IExportable.
virtual QVariant value (int context_id) const
 Returns the value of the property.
virtual QString valueString () const
 Returns a string representation of this property.
- Public Member Functions inherited from Qtilities::Core::QtilitiesProperty
bool isReadOnly () const
 Indicates if the property is read only.
bool isRemovable () const
 Indicates if the property is removable.
bool isReserved () const
 Indicates if the property is reserved.
bool isValid ()
 Function to check if an observer property is valid.
void makeNotRemovable ()
 Makes the property non removable. Properties can only be made not removable once, after that they always stay not removable.
void makeReadOnly ()
 Makes the property read only. Properties can only be made read only once, after that they always stay read only.
void makeReserved ()
 Makes the property reserved. Properties can only be made reserved once, after that they always stay reserved.
QString propertyNameString () const
 Gets the name of this property as a QString.
void setPropertyName (const char *new_name)
 Sets the name of this property.
void setPropertyName (const QString &new_name)
 Sets the name of this property.
bool supportsChangeNotifications () const
 Indicates if this property supports change notifications.
- Public Member Functions inherited from Qtilities::Core::Interfaces::IExportable
quint32 applicationExportVersion () const
 Returns the application export version currently used by all your application's classes.
virtual void clearExportTask ()
 Clears the export task.
IExportableduplicate (QString *error_msg=0, int properties_to_copy=0, ExportResultFlags *result_flags=0) const
 Function which will create a duplicate (copy) of this object.
virtual ITaskexportTask () const
 Gets the task which must be used to log import/export information to.
Qtilities::ExportVersion exportVersion () const
 Returns the export version currently used by all Qtilities classes.
virtual InstanceFactoryInfo instanceFactoryInfo () const
 The instance factory information which must be used when the exported object is reconstructed during an import.
bool isExportable () const
 Gets if this object must be part of it's parents' exports.
virtual void setApplicationExportVersion (quint32 version)
 Sets the application export version currently used by all your application's classes.
virtual void setExportTask (ITask *task)
 Sets the task which must be used to log import/export information to.
virtual void setExportVersion (Qtilities::ExportVersion version)
 Returns the export version currently used by all Qtilities classes.
virtual void setIsExportable (bool new_is_exportable)
 Sets if this object must be part of it's parents' exports.
- Public Member Functions inherited from Qtilities::Core::Interfaces::IObjectBase
QString objectOriginID () const
 Allows interfaces to provide some sort of source identification.
void setObjectOriginID (const QString &object_origin_id)
 Allows setting of the object source ID of this interface implementation.

Additional Inherited Members

- Static Public Member Functions inherited from Qtilities::Core::QtilitiesProperty
static QVariant constructVariant (const QString &type_string, const QString &value_string)
 Converts a QString type_string and QString value_string to a matching QVariant.
static QVariant constructVariant (QVariant::Type type, const QString &value_string)
 Converts a QVariant::Type and QString value_string to a matching QVariant.
static bool isExportableVariant (QVariant variant)
 Checks if a QVariant is exportable. Thus, if it can be converted to QString.
static bool propertyIsExportable (const char *property_name)
 Function to check if any Qtilities property is exportable.
static bool propertyIsRemovable (const char *property_name)
 Function to check if any Qtilities property is removable.
static bool propertyIsReserved (const char *property_name)
 Function to check if any Qtilities property is reserved.
static bool propertySupportsChangeNotifications (const char *property_name)
 Function to check if any Qtilities property supports change notifications.
- Static Public Member Functions inherited from Qtilities::Core::Interfaces::IExportable
template<typename T >
static T * duplicateInstance (IExportable *obj, QString *error_msg=0, int properties_to_copy=0, ExportResultFlags *result_flags=0)
 Provides an easy to use template based implementation of IExportable::duplicate().
static QString exportModeToString (ExportMode export_mode)
 Function which returns a string associated with a specific ExportMode.
static ExportMode stringToExportMode (const QString &export_mode_string)
 Function which returns the ExportMode associated with a string.
static Result validateQtilitiesExportVersion (Qtilities::ExportVersion export_version, ITask *task=0)
 Checks the exportVersion() against the supported Qtilities export versions for the current Qtilities version.
static Result validateQtilitiesImportVersion (Qtilities::ExportVersion import_version, ITask *task=0)
 Checks the exportVersion() against the supported Qtilities import versions for the current Qtilities version.

Detailed Description

A MultiContextProperty provides a property which has different values in different contexts.

A complete map of the property's contexts and their respective QVariant() values can be obtained using contextMap(). To get the last context ID for which the property changed use lastChangedContext(). You can check if an MultiContextProperty is valid using the isValid() call. Convenience functions for working with different contexts include hasContext(), addContext(),removeContext() and value().

Getting and setting shared properties are done by the Qtilities::Core::Observer class which provides easy to use functions to set and get properties and their values. For multi context properties we need to know the context to get a value since the value is different for different contexts.

The following example shows how to construct and work with Qtilities::Core::MultiContextProperty.

QObject* obj = new QObject();
Observer* observerA = new Observer("My Observer A","Example observer description");
int observerA_ID = observerA->observerID();
Observer* observerB = new Observer("My Observer B","Example observer description");
int observerB_ID = observerB->observerID();
// Create observer property
QString property_name = "Example Property Name";
MultiContextProperty observer_property(property_name);
observer_property.setIsExportable(false);
// Attach object to observers
observerA->attachSubject(obj);
observerB->attachSubject(obj);
// Now we can add values to our property for each context
observer_property.addContext(QVariant(true),observerA->observerID());
observer_property.addContext(QVariant(false),observerB->observerID());
// Now set the observer property on the object
// Now we can get the value of the property for each observer using the observer references
bool value_contextA = observerA->getMultiContextPropertyValue(obj,property_name).toBool();
bool value_contextB = observerB->getMultiContextPropertyValue(obj,property_name).toBool();
// Or get the value of the property without an observer reference: Option 1
MultiContextProperty observer_property1 = ObjectManager::getMultiContextProperty(property_name);
if (observer_property1.isValid()) {
bool value_contextA_1 = observer_property1->value(observerA_ID).toBool();
}
// Or get the value of the property without an observer reference: Option 2
QVariant prop = obj->property(property_name);
if (prop.isValid() && prop.canConvert<MultiContextProperty>()) {
bool value_contextA_2 = (prop.value<MultiContextProperty>()).value(observerA_ID).toBool();
}

For more information about how MultiContextProperty are used in the context of Qtilities::Core::Observer, please see Dynamic properties used and managed by Observers.

Note that you can inspect all MultiContextProperty properties on an object through the Qtilities::CoreGui::ObjectDynamicPropertyBrowser widget. See the qti.core.CategoryMap property as an example below:

debugging_dynamic_properties.jpg
Dynamic Properties Browser
See also:
Qtilities::Core::SharedProperty

Member Function Documentation

Qtilities::Core::Interfaces::IExportable::ExportResultFlags Qtilities::Core::MultiContextProperty::exportBinary ( QDataStream &  stream) const
virtual

Allows exporting to a QDataStream.

See Serializing Qtilities Data Types Overview for more information about the expected output format.

Parameters:
streamA reference to the QDataStream to which the object's information must be appended is provided.

Reimplemented from Qtilities::Core::QtilitiesProperty.

Qtilities::Core::Interfaces::IExportable::ExportResultFlags Qtilities::Core::MultiContextProperty::exportXml ( QDomDocument *  doc,
QDomElement *  object_node 
) const
virtual

Allows exporting to an XML document. A reference to the QDomElement to which the object's information must be added is provided, along with a reference to the QDomDocument.

See Serializing Qtilities Data Types Overview for more information about the expected output format.

Reimplemented from Qtilities::Core::QtilitiesProperty.

Qtilities::Core::Interfaces::IExportable::ExportResultFlags Qtilities::Core::MultiContextProperty::importBinary ( QDataStream &  stream,
QList< QPointer< QObject > > &  import_list 
)
virtual

Allows importing and reconstruction of the object state from information provided in a QDataStream.

See Serializing Qtilities Data Types Overview for more information about the expected output format.

Parameters:
streamThe QDataStream which contains the object's information.
import_listAll objects constructed during the import operation must be added to the import list. When the operation fails, all objects in this list will be deleted.

Reimplemented from Qtilities::Core::QtilitiesProperty.

Qtilities::Core::Interfaces::IExportable::ExportResultFlags Qtilities::Core::MultiContextProperty::importXml ( QDomDocument *  doc,
QDomElement *  object_node,
QList< QPointer< QObject > > &  import_list 
)
virtual

This function will add a set of attributes directly to the object_node passed to it.

Reimplemented from Qtilities::Core::QtilitiesProperty.

QObject* Qtilities::Core::MultiContextProperty::objectBase ( )
inlinevirtual
Note:
MultiContextProperty is not a QObject, thus it returns 0.

Reimplemented from Qtilities::Core::QtilitiesProperty.

const QObject* Qtilities::Core::MultiContextProperty::objectBase ( ) const
inlinevirtual
Note:
MultiContextProperty is not a QObject, thus it returns 0.

Reimplemented from Qtilities::Core::QtilitiesProperty.

bool Qtilities::Core::MultiContextProperty::setValue ( QVariant  new_value,
int  context_id 
)
virtual

Sets the value of the property.

Sets the value for a specific context ID. If the context ID does not exist, it is created with the specified value assigned to it.

Parameters:
new_valueThe new QVariant value which must be assigned to the property.
context_idIndicates the context ID for which the property value needs to be set.
Qtilities::Core::Interfaces::IExportable::ExportModeFlags Qtilities::Core::MultiContextProperty::supportedFormats ( ) const
virtual

Provides information about the export format(s) supported by your implementation of IExportable.

Note:
It is important to note that you need to check the exportVersion() when you return the supported formats.

Reimplemented from Qtilities::Core::QtilitiesProperty.

QVariant Qtilities::Core::MultiContextProperty::value ( int  context_id) const
virtual

Returns the value of the property.

Parameters:
context_idIndicates the context ID for which the property value is required.
QString Qtilities::Core::MultiContextProperty::valueString ( ) const
virtual

Returns a string representation of this property.

Returns:
A string representation which is basically a comma seperated context values list.


Qtilities : Reference Documentation Back to top Copyright © 2009-2013, Jaco Naudé