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

The ObjectManager provides object management features to the developer. More...

#include <ObjectManager.h>

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

List of all members.

Public Member Functions

QStringList allFactoryNames () const
 Provides a list with the names of all the factories registered in the object manager.
QtilitiesCategory categoryForTag (const QString &factory_name, const QString &factory_tag, bool *ok=0) const
 Provides the category of the specified tag.
QObject * createInstance (const InstanceFactoryInfo &ifactory_data)
 Constructs an instance in a specified factory and return it.
QList< QPointer< QObject > > metaTypeActiveObjects (const QString &meta_type) const
 Returns the active object(s) for a specific meta type. If the meta type does not exist, an empty list is returned.
bool moveSubjects (QList< QObject * > objects, int source_observer_id, int destination_observer_id, QString *error_msg, bool silent=false)
 A function which moves a list of objects from one observer to another observer.
bool moveSubjects (QList< QPointer< QObject > > objects, int source_observer_id, int destination_observer_id, QString *error_msg, bool silent=false)
 Move subjects by providing the objects as a list with smart pointers.
QObject * objectBase ()
 Returns the QObject* base of the interface.
const QObject * objectBase () const
 Returns a const QObject* base of the interface.
ObserverobjectPool ()
 Function which returns a reference to the global object pool.
ObserverobserverReference (int id) const
 Gets the reference to an observer.
QStringList providedFactories () const
 Provides the names of all the factories exposed through this interface.
QStringList providedFactoryTags (const QString &factory_name, const QtilitiesCategory &category_filter=QtilitiesCategory(), bool *ok=0) const
 Provides the tags in a specific factory.
IFactoryProviderreferenceIFactoryProvider (const QString &factory_name) const
 Provides a reference to the factory interface for a specific factory.
QList< QObject * > registeredInterfaces (const QString &iface) const
 Returns all objects in the global object pool which implements the specified interface.
void registerFactoryInterface (FactoryInterface< QObject > *factory_interface, FactoryItemID iface_tag)
 Registers a factory interface inside the Qtilities factory.
bool registerIFactoryProvider (IFactoryProvider *factory_iface)
 Registers a factory interface in the object manager.
void registerObject (QObject *obj, QtilitiesCategory category=QtilitiesCategory())
 Registers an object to be included in the global object pool.
int registerObserver (Observer *observer)
 Registers an observer in the observer manager.
void removeObject (QObject *obj)
 Removes an object to from the global object pool.
void setMetaTypeActiveObjects (QList< QObject * > objects, const QString &meta_type)
 Updates the active object(s) for a specific meta type.
void setMetaTypeActiveObjects (QList< QPointer< QObject > > objects, const QString &meta_type)
 Update the active object(s) for a specific meta type by providing a list of smart pointers to the objects.
QMap< QString, QtilitiesCategorytagCategoryMap (const QString &factory_name, bool *ok=0) const
 Provides the full tag and category map for the given factory.
QStringList tagsForFactory (const QString &factory_name) const
 Provides a list of all the tags registered in a specific factory.

Static Public Member Functions

static bool cloneObjectProperties (const QObject *source_obj, QObject *target_obj, PropertyTypeFlags property_types=AllPropertyTypes)
 Streams exportable dynamic properties from the given QDomDocument and QDomElement and then add them to the QObject.
static bool compareDynamicProperties (const QObject *obj1, const QObject *obj2, PropertyTypeFlags property_types=AllPropertyTypes, PropertyDiffInfo *property_diff_info=0, QStringList ignore_list=QStringList())
 Convenience function to compare all properties that match the PropertyTypeFlags on two objects.
static bool constructDefaultPropertiesOnObject (QObject *obj, QString *errorMsg=0)
 Convenience function to allow construction of all properties specified by IAvailablePropertyProvider interfaces in the global object pool on the given object.
static SharedPropertyconstructPropertyFromSpecification (PropertySpecification specification)
 Convenience function to construct a property from a given PropertySpecification.
static QList< QPointer< QObject > > convNormalObjectsToSafe (QList< QObject * > normal_list)
 Converts a QList<QObject*> object list to a QList<QPointer<QObject> > list.
static QList< QObject * > convSafeObjectsToNormal (QList< QPointer< QObject > > safe_list)
 Converts a QList<QPointer<QObject> > object list to a QList<QObject*> list.
static
IExportable::ExportResultFlags 
exportObjectPropertiesBinary (const QObject *obj, QDataStream &stream, PropertyTypeFlags property_types=AllPropertyTypes, Qtilities::ExportVersion version=Qtilities::Qtilities_Latest)
 Streams exportable dynamic properties about the object to the given QDataStream.
static
IExportable::ExportResultFlags 
exportObjectPropertiesXml (const QObject *obj, QDomDocument *doc, QDomElement *object_node, PropertyTypeFlags property_types=AllPropertyTypes, Qtilities::ExportVersion version=Qtilities::Qtilities_Latest)
 Exports all exportable dynamic properties about the object to the given QDomDocument and QDomElement.
static MultiContextProperty getMultiContextProperty (const QObject *obj, const char *property_name)
 Convenience function which will get the specified MultiContextProperty of the specified object.
static SharedProperty getSharedProperty (const QObject *obj, const char *property_name)
 Convenience function which will get the specified SharedProperty of the specified object.
static
IExportable::ExportResultFlags 
importObjectPropertiesBinary (QObject *obj, QDataStream &stream)
 Streams exportable dynamic properties from the given data stream and add them to the QObject.
static
IExportable::ExportResultFlags 
importObjectPropertiesXml (QObject *obj, QDomDocument *doc, QDomElement *object_node)
 Streams exportable dynamic properties from the given QDomDocument and QDomElement and then add them to the QObject.
static bool propertyExists (const QObject *obj, const char *property_name)
 Convenience function to check if a dynamic property exists on a object.
static bool removeDynamicProperties (QObject *obj, PropertyTypeFlags property_types=AllPropertyTypes)
 Convenience function to remove all properties that match the PropertyTypeFlags from an object.
static bool setMultiContextProperty (QObject *obj, MultiContextProperty multi_context_property)
 Convenience function which will set the specified MultiContextProperty on the specified object.
static bool setSharedProperty (QObject *obj, SharedProperty shared_property)
 Convenience function which will set the specified SharedProperty on the specified object.
static bool setSharedProperty (QObject *obj, const char *property_name, QVariant property_value)
 Convenience function which will create and set a SharedProperty with the given name and value on the object.
static bool setSharedProperty (QObject *obj, PropertySpecification property_specification)
 Convenience function which will create and set a SharedProperty from the given PropertySpecification.

Additional Inherited Members

- Public Types inherited from Qtilities::Core::Interfaces::IObjectManager
enum  PropertyTypes {
  NoProperties = 0, MultiContextProperties = 1, SharedProperties = 2, QtilitiesInternalProperties = 4,
  NonQtilitiesProperties = 8
}
 Possible property types. More...
- Signals inherited from Qtilities::Core::Interfaces::IObjectManager
void metaTypeActiveObjectsChanged (QList< QPointer< QObject > > objects, const QString &meta_type)
 Signal which is emitted when the setMetaTypeActiveObjects() is finished.
void newObjectAdded (QObject *obj)
 Signal which is emitted when a new object is added to the global object pool.
void objectRemoved (QObject *obj)
 Signal which is emitted when an object is removed from the global object pool.

Detailed Description

The ObjectManager provides object management features to the developer.

For more information about object management in Qtilities, see the Object Management article.


Member Function Documentation

QtilitiesCategory ObjectManager::categoryForTag ( const QString &  factory_name,
const QString &  factory_tag,
bool *  ok = 0 
) const
virtual

Provides the category of the specified tag.

Parameters:
factory_nameThe factory in which the tag is located.
factory_tagThe tag for which the category must is requested.
okSet to true if the parameters matches a factory in this provider, false otherwise.
Returns:
The QtilitiesCategory for the found tag. If the tag and factory_name combination is not found by this provider, QtilitiesCategory() is returned.

This function was added in Qtilities v1.2.

Implements Qtilities::Core::Interfaces::IFactoryProvider.

bool Qtilities::Core::ObjectManager::cloneObjectProperties ( const QObject *  source_obj,
QObject *  target_obj,
PropertyTypeFlags  property_types = AllPropertyTypes 
)
static

Streams exportable dynamic properties from the given QDomDocument and QDomElement and then add them to the QObject.

Note:
Conflicting properties will be replaced.
See also:
removeDynamicProperties().
bool Qtilities::Core::ObjectManager::compareDynamicProperties ( const QObject *  obj1,
const QObject *  obj2,
PropertyTypeFlags  property_types = AllPropertyTypes,
PropertyDiffInfo property_diff_info = 0,
QStringList  ignore_list = QStringList() 
)
static

Convenience function to compare all properties that match the PropertyTypeFlags on two objects.

This function checks each property using the == overload of the QVariant property type and returns true if they match exactly, false otherwise.

Parameters:
obj1The first object to use in the comparison. The results will be relative to this object, for example if a property exists on obj1 and not on obj2, the diff result will show that the property was added. Also, when a property exists on both objects and the value changed, the old value will be the value on obj2 and the new value the value on obj1.
obj2The second object to use in the comparison.
property_typesThe property types which must be compared.
property_diff_infoInformation about property changes on obj1 compared to obj2. By default the differences will not be calculated, it will only be done when the property_diff_info parameter is passed a valid reference.
ignore_listA list of property names which should be ignored in the comparison.
bool ObjectManager::constructDefaultPropertiesOnObject ( QObject *  obj,
QString *  errorMsg = 0 
)
static

Convenience function to allow construction of all properties specified by IAvailablePropertyProvider interfaces in the global object pool on the given object.

*This function can be used to do automatic dynamic property construction on objects. This is usefull in *extendible applications where you use dynamic properties in order to extend objects at runtime. For example, *if you have an application and plugins can add dynamic properties on specific type of objects, you can do it by *having some sort of mechanism where the plugin is notified of new objects that it is interested in. One way to do it *is to register the new objects in the global object pool and listen to the new object added signal on the object pool. *When the plugin gets this notification it adds the needed dynamic properties on the object.

*This function provides a more efficient way to do this. When called, the function looks for all implementations of *IAvailablePropertyProvider registered in the global object pool and gets all PropertySpecification specifications for *for which the given object inherits the d_class_name specification of the property specification.

*It will check all these properties and if their d_add_during_construction parameter is set *it will add these properties with the parameters specified by the matching PropertySpecification.

*The intended use of this function is to call it in the constructor of your object.

Parameters:
objThe object on which the properties must be constructed.ad.
errorMsgWhen the function returns false due to any issues, the reason for the failure can be found through this parameter.
Returns:
True when successfull, false otherwise.

*This function was added in Qtilities v1.2.

SharedProperty * ObjectManager::constructPropertyFromSpecification ( PropertySpecification  specification)
static

Convenience function to construct a property from a given PropertySpecification.

Constructs a SharedProperty from the given PropertySpecification.

Parameters:
specificationThe property specification
Returns:
A reference to the constructed property.

*This function was added in Qtilities v1.2.

QList< QPointer< QObject > > Qtilities::Core::ObjectManager::convNormalObjectsToSafe ( QList< QObject * >  normal_list)
static

Converts a QList<QObject*> object list to a QList<QPointer<QObject> > list.

This function was added in Qtilities v1.1.

QList< QObject * > Qtilities::Core::ObjectManager::convSafeObjectsToNormal ( QList< QPointer< QObject > >  safe_list)
static

Converts a QList<QPointer<QObject> > object list to a QList<QObject*> list.

This function was added in Qtilities v1.1.

IExportable::ExportResultFlags Qtilities::Core::ObjectManager::exportObjectPropertiesBinary ( const QObject *  obj,
QDataStream &  stream,
PropertyTypeFlags  property_types = AllPropertyTypes,
Qtilities::ExportVersion  version = Qtilities::Qtilities_Latest 
)
static

Streams exportable dynamic properties about the object to the given QDataStream.

To use this function make sure that all the QVariant properties have the streaming << / >> operators overloaded. This is the case for all properties used in Qtilities.

IExportable::ExportResultFlags Qtilities::Core::ObjectManager::exportObjectPropertiesXml ( const QObject *  obj,
QDomDocument *  doc,
QDomElement *  object_node,
PropertyTypeFlags  property_types = AllPropertyTypes,
Qtilities::ExportVersion  version = Qtilities::Qtilities_Latest 
)
static

Exports all exportable dynamic properties about the object to the given QDomDocument and QDomElement.

To use this function make sure that all the QVariants are exportable. See QtilitiesProperty::isExportableVariant() for more information.

Qtilities::Core::MultiContextProperty Qtilities::Core::ObjectManager::getMultiContextProperty ( const QObject *  obj,
const char *  property_name 
)
static

Convenience function which will get the specified MultiContextProperty of the specified object.

See also:
setMultiContextProperty(), setSharedProperty(), getSharedProperty(), propertyExists()
Qtilities::Core::SharedProperty Qtilities::Core::ObjectManager::getSharedProperty ( const QObject *  obj,
const char *  property_name 
)
static

Convenience function which will get the specified SharedProperty of the specified object.

See also:
setMultiContextProperty(), setSharedProperty(), getMultiContextProperty(), propertyExists()
IExportable::ExportResultFlags Qtilities::Core::ObjectManager::importObjectPropertiesBinary ( QObject *  obj,
QDataStream &  stream 
)
static

Streams exportable dynamic properties from the given data stream and add them to the QObject.

Note:
Conflicting properties will be replaced.
IExportable::ExportResultFlags Qtilities::Core::ObjectManager::importObjectPropertiesXml ( QObject *  obj,
QDomDocument *  doc,
QDomElement *  object_node 
)
static

Streams exportable dynamic properties from the given QDomDocument and QDomElement and then add them to the QObject.

Note:
Conflicting properties will be replaced.
QList< QPointer< QObject > > Qtilities::Core::ObjectManager::metaTypeActiveObjects ( const QString &  meta_type) const
virtual

Returns the active object(s) for a specific meta type. If the meta type does not exist, an empty list is returned.

For more information about see the Global object activity management section of the Object Management article.

See also:
setMetaTypeActiveObjects(), metaTypeActiveObjectsChanged()

Implements Qtilities::Core::Interfaces::IObjectManager.

bool Qtilities::Core::ObjectManager::moveSubjects ( QList< QObject * >  objects,
int  source_observer_id,
int  destination_observer_id,
QString *  error_msg,
bool  silent = false 
)
virtual

A function which moves a list of objects from one observer to another observer.

This function will attempt to move subjects from one observer context to another. If any of the subjects cannot be attached, it will be skipped and attempt to move the next subject in the list. If any of the subjects could not be attached, the function will return false. If all subjects was moved successfully the function will return true.

Parameters:
objectsThe objects which must be moved.
source_observer_idThe source observer ID.
destination_observer_idThe destination observer ID.
error_msgWhen valid it will be populated with any error messages produced during the move operation.
silentWhen true the subjects must be moved without showing any dialogs.
Returns:
True if all objects were moved successfully, false if some of the objects failed.

Implements Qtilities::Core::Interfaces::IObjectManager.

bool Qtilities::Core::ObjectManager::moveSubjects ( QList< QPointer< QObject > >  objects,
int  source_observer_id,
int  destination_observer_i,
QString *  error_msg,
bool  silent = false 
)
virtual

Move subjects by providing the objects as a list with smart pointers.

This function will attempt to move subjects from one observer context to another. If any of the subjects cannot be attached, it will be skipped and attempt to move the next subject in the list. If any of the subjects could not be attached, the function will return false. If all subjects was moved successfully the function will return true.

Parameters:
objectsThe objects which must be moved.
source_observer_idThe source observer ID.
destination_observer_idThe destination observer ID.
error_msgWhen valid it will be populated with any error messages produced during the move operation.
silentWhen true the subjects must be moved without showing any dialogs.
Returns:
True if all objects were moved successfully, false if some of the objects failed.

Implements Qtilities::Core::Interfaces::IObjectManager.

const QObject* Qtilities::Core::ObjectManager::objectBase ( ) const
inlinevirtual

Returns a const QObject* base of the interface.

This function can be used in const methods, but make sure that you don't modify things that should stay const. An example where this is used is when we want to get a property on an object in a const method. This is a const operation.

Implements Qtilities::Core::Interfaces::IObjectBase.

Qtilities::Core::Observer * Qtilities::Core::ObjectManager::objectPool ( )
virtual

Function which returns a reference to the global object pool.

Care should be taken when using the object pool observer. You should for example not delete all the subjects in the pool unless you know what you are doing.

It is recommended to use registerObject() and registeredInterfaces() instead of the object pool directly, unless you require the use of additional functions on the object pool, like displaying it using an ObserverWidget.

Note:
The global object pool is in a processing cycle by default. Thus if you want to display it, you need to call endProcessingCycle() on it and refreshViewsLayout().

Implements Qtilities::Core::Interfaces::IObjectManager.

Qtilities::Core::Observer * Qtilities::Core::ObjectManager::observerReference ( int  id) const
virtual

Gets the reference to an observer.

Parameters:
idThe observer id of the observer for which the reference must be fetched.
Returns:
The observer with the specified id. If the id is invalid 0 is returned.

Implements Qtilities::Core::Interfaces::IObjectManager.

QStringList Qtilities::Core::ObjectManager::providedFactoryTags ( const QString &  factory_name,
const QtilitiesCategory category_filter = QtilitiesCategory(),
bool *  ok = 0 
) const
virtual

Provides the tags in a specific factory.

Parameters:
factory_nameThe factory in which the tag is located.
category_filterAllows you to get tag for a specific category. When empty, all categories are returned.
okSet to true if the parameters matches a factory in this provider, false otherwise.
Returns:
The QtilitiesCategory for the found tag. If the tag and factory_name combination is not found by this provider, QtilitiesCategory() is returned.

Implements Qtilities::Core::Interfaces::IFactoryProvider.

Qtilities::Core::Interfaces::IFactoryProvider * Qtilities::Core::ObjectManager::referenceIFactoryProvider ( const QString &  factory_name) const
virtual

Provides a reference to the factory interface for a specific factory.

This function returns the IFactoryProvider interface which contains the specified factory.

Implements Qtilities::Core::Interfaces::IObjectManager.

QList< QObject * > Qtilities::Core::ObjectManager::registeredInterfaces ( const QString &  iface) const
virtual

Returns all objects in the global object pool which implements the specified interface.

For example:

// Get a list of all the project items in the object pool, that is objects
// implementing the IProjectItem interface:
QList<QObject*> projectItemObjects = OBJECT_MANAGER->registeredInterfaces("com.Qtilities.ProjectManagement.IProjectItem/1.0");
QList<IProjectItem*> projectItems;
// Cast all items:
for (int i = 0; i < projectItemObjects.count(); i++) {
IProjectItem* part = qobject_cast<IProjectItem*> (projectItemObjects.at(i));
if (part)
projectItems.append(part);
}

Implements Qtilities::Core::Interfaces::IObjectManager.

bool Qtilities::Core::ObjectManager::registerIFactoryProvider ( IFactoryProvider obj)
virtual

Registers a factory interface in the object manager.

The object manager keeps track of all IFactoryProvider interfaces registered using this function. It is then possible to access the IFactoryProvider interface for a specific factory using the referenceIFactoryProvider() function.

The way that the object manager keeps track of factories and their respective IFactoryProvider interfaces is done in such a way that factory names exposed by IFactoryProvider must be unique for all IFactoryProvider interfaces registered using this function.

If a duplicate factory name is found, an error is printed and this function returns false.

Implements Qtilities::Core::Interfaces::IObjectManager.

void Qtilities::Core::ObjectManager::registerObject ( QObject *  obj,
QtilitiesCategory  category = QtilitiesCategory() 
)
virtual

Registers an object to be included in the global object pool.

Parameters:
categoryThe category under which the object must be registered. This parameter can be left out in most cases, however it is usefull when visualizing the global object pool using the Qtilities::Plugins::Debug plugin for example.
Returns:
The integer value returned will be the object's unique ID in the global object pool.

Implements Qtilities::Core::Interfaces::IObjectManager.

void Qtilities::Core::ObjectManager::removeObject ( QObject *  obj)
virtual

Removes an object to from the global object pool.

This function will detach the object from the global object pool observer. It will not however delete the object, it will just detach it.

Implements Qtilities::Core::Interfaces::IObjectManager.

void Qtilities::Core::ObjectManager::setMetaTypeActiveObjects ( QList< QObject * >  objects,
const QString &  meta_type 
)
virtual

Updates the active object(s) for a specific meta type.

For more information about see the Global object activity management section of the Object Management article.

See also:
metaTypeActiveObjects(), metaTypeActiveObjectsChanged()

Implements Qtilities::Core::Interfaces::IObjectManager.

bool Qtilities::Core::ObjectManager::setMultiContextProperty ( QObject *  obj,
MultiContextProperty  multi_context_property 
)
static

Convenience function which will set the specified MultiContextProperty on the specified object.

Caution should be taken when using this function because you can easily overwrite property values for other contexts since the property has different values for different contexts.

Therefore you must always check if an observer property exist before setting as shown in the example below:

QtilitiesCategory category("Test Category");
// Check if the property exists:
// If it does we MUST append the value for our context:
MultiContextProperty category_property = ObjectManager::getMultiContextProperty(iface->objectBase(),qti_prop_CATEGORY_MAP);
category_property.setValue(qVariantFromValue(category),observerID());
ObjectManager::setMultiContextProperty(iface->objectBase(),category_property);
} else {
// If not we create a new property with the value for our context:
MultiContextProperty category_property(qti_prop_CATEGORY_MAP);
category_property.setValue(qVariantFromValue(category),observerID());
ObjectManager::setMultiContextProperty(iface->objectBase(),category_property);
}
See also:
getMultiContextProperty(), setSharedProperty(), getSharedProperty(), propertyExists()
bool Qtilities::Core::ObjectManager::setSharedProperty ( QObject *  obj,
SharedProperty  shared_property 
)
static

Convenience function which will set the specified SharedProperty on the specified object.

See also:
setMultiContextProperty(), getMultiContextProperty(), getSharedProperty(), propertyExists()
bool Qtilities::Core::ObjectManager::setSharedProperty ( QObject *  obj,
const char *  property_name,
QVariant  property_value 
)
static

Convenience function which will create and set a SharedProperty with the given name and value on the object.

See also:
setMultiContextProperty(), getMultiContextProperty(), getSharedProperty(), propertyExists()
bool ObjectManager::setSharedProperty ( QObject *  obj,
PropertySpecification  property_specification 
)
static

Convenience function which will create and set a SharedProperty from the given PropertySpecification.

See also:
setMultiContextProperty(), getMultiContextProperty(), getSharedProperty(), propertyExists()

This function was added in Qtilities v1.2.

QMap< QString, QtilitiesCategory > ObjectManager::tagCategoryMap ( const QString &  factory_name,
bool *  ok = 0 
) const
virtual

Provides the full tag and category map for the given factory.

Parameters:
factory_nameThe factory for which the map is requested.
okSet to true if the parameters matches a factory in this provider, false otherwise.
Returns:
A QMap with the keys being the tags and the values their corresponding categories. If the factory_name is not a factory provided by this provider, an empty map is returned.

This function was added in Qtilities v1.2.

Implements Qtilities::Core::Interfaces::IFactoryProvider.



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