All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
Object Management

Overview

Qtilities provides an object manager which provides many object management features. The object manager is also responsible to provide a global object pool to the developer. This allows the registration of objects in the global object pool where other objects can access them or the interfaces they implement. This article will provide information on the different features of the object manager and the global object pool.

Table of contents:

First Steps

Overviews

The Object Manager

The object manager implements the Qtilities::Core::Interfaces::IObjectManager interface and can be accessed directly through the thread safe OBJECT_MANAGER macro or directly using Qtilities::Core::QtilitiesCoreApplication::objectManager()

For example:

QObject* my_object = new QObject();
OBJECT_MANAGER->registerObject(my_object);
// Internally the global object pool is an observer which can be accessed like this:
OBJECT_MANAGER->objectPool();

Object Management Features

The global object pool

A global object pool is a powerful object management feature in an application, especially when the application is extensible through plugins. It allows objects to be registered in the pool and can then be searched and used in other parts of the application. The example below shows some example usages of the global object pool.

#include <IMyIFace.h>
// Register an object in the global object pool
// This will emit the newObjectAdded(QObject*) signal on the object manager
QObject* my_object = new QObject();
OBJECT_MANAGER->registerObject(my_object);
// Check which objects in the global object pool implements a specific interface (called "IMyIFace" in this example)
QList<QObject *> iface_list;
iface_list = OBJECT_MANAGER->registeredInterfaces("IMyIFace");
foreach (QObject* obj, iface_list) {
IMyIFace* my_iface = qobject_cast<IMyIFace*> (obj);
if (my_iface) {
// Now you can access your interface.
}
}

A good example of using the global object pool is the methodology behind how plugins are used in the Qtilities extension system. Plugins register objects in which the rest of the application might be interested during plugin initialization. Once all plugins were initialized, plugins initializes their dependencies where it will inspect the global object pool for registered objects in which it is interested in.

The Qtilities::Plugins::Debug plugin provides a visual overview of the global object pool state during runtime which simplifies debugging. This is shown in the image below:

debugging_object_pool_tab.jpg
Global Object Pool View In Debug Plugin

Observer object management features

When attaching objects to observers, it is possible to specify the way the object should be managed in the observer context. The possible management options are defined in the Qtilities::Core::Observer::ObjectOwnership enumeration. See the Object lifetimes: Managing object lifetimes using observers section of the Observers article for more information.

Global object activity management

The object manager provides functionality to manage global active objects in an application. Active objects can be set on a meta-type basis where the meta type is a simple QString used to identify the set of active objects. Active objects for a meta-type can be set using the Qtilities::Core::Interfaces::IObjectManager::setMetaTypeActiveObjects() function. When this function is called the Qtilities::Core::Interfaces::IObjectManager::metaTypeActiveObjectsChanged() signal is emitted with the new set of active objects for the specified meta-type. The active objects for a meta-type can be accessed at any time using the Qtilities::Core::Interfaces::IObjectManager::metaTypeActiveObjects() function.

Object Property Management

Qtilities provided various features related to QObject property management. The sections that follow will provide highlights of these features.

Working with object properties

To make working with object properties easier, Qtilities comes with its own property classes which all inherit from Qtilities::Core::QtilitiesProperty. This approach provides many advantages allowing you to control many aspects of the property. For example:

The object manager provides many functions which helps you to work with properties on QObjects. QtilitiesProperty based classes are meant to compliment normal QVariant properties which can be set on QObjects and all the property functions provided by the object manager supports normal QVariant properties as well as property classes inheriting from QtilitiesProperty.

Property related functionality on object manager includes:

See the static functions on Qtilities::Core::ObjectManager for more information.

Displaying object properties

When Qtilities is built using the QTILITIES_PROPERTY_BROWSER define enabled, the following widgets allows you to inspect properties on objects at runtime.

Displaying Q_PROPERTY properties

The Qtilities::CoreGui::ObjectPropertyBrowser allows you to inspect Q_PROPERTY properties on objects at runtime. The widget embedded in the debug plugin is shown below for an example object.

debugging_static_properties.jpg
Static Properties Browser

Displaying dynamic properties

The Qtilities::CoreGui::DynamicObjectPropertyBrowser allows you to inspect dynamic properties on QObjects at runtime. This widget allows you to display the following type of properties:

The widget embedded in the debug plugin is shown below for an example object.

debugging_dynamic_properties.jpg
Dynamic Properties Browser


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