QExtensionManager Class Reference

#include <qextensionmanager.h>

Inheritance diagram for QExtensionManager:

Inheritance graph
[legend]
Collaboration diagram for QExtensionManager:

Collaboration graph
[legend]
List of all members.

Detailed Description

The QExtensionManager class provides extension management facilities for Qt Designer.

QtDesigner

In the extensions are not created until they are required. For that reason, when implementing an extension, you must also create a QExtensionFactory, i.e a class that is able to make an instance of your extension, and register it using 's extension manager.

The registration of an extension factory is typically made in the QDesignerCustomWidgetInterface::initialize() function:

        void MyPlugin::initialize(QDesignerFormEditorInterface *formEditor)
        {
            if (initialized)
                return;

            QExtensionManager *manager = formEditor->extensionManager();
            Q_ASSERT(manager != 0);

            manager->registerExtensions(new MyExtensionFactory(manager),
                                        Q_TYPEID(QDesignerTaskMenuExtension));

            initialized = true;
        }

The QExtensionManager is not intended to be instantiated directly. You can retrieve an interface to 's extension manager using the QDesignerFormEditorInterface::extensionManager() function. A pointer to 's current QDesignerFormEditorInterface object (formEditor in the example above) is provided by the QDesignerCustomWidgetInterface::initialize() function's parameter. When implementing a custom widget plugin, you must subclass the QDesignerCustomWidgetInterface to expose your plugin to .

Then, when an extension is required, 's extension manager will run through all its registered factories calling QExtensionFactory::createExtension() for each until the first one that is able to create the requested extension for the selected object, is found. This factory will then make an instance of the extension.

There are four available types of extensions in : QDesignerContainerExtension , QDesignerMemberSheetExtension, QDesignerPropertySheetExtension and QDesignerTaskMenuExtension. 's behavior is the same whether the requested extension is associated with a container, a member sheet, a property sheet or a task menu.

For a complete example using the QExtensionManager class, see the {designer/taskmenuextension}{Task Menu Extension example}. The example shows how to create a custom widget plugin for Qt Designer, and how to to use the QDesignerTaskMenuExtension class to add custom items to 's task menu.

See also:
QExtensionFactory, QAbstractExtensionManager

Definition at line 33 of file qextensionmanager.h.

Public Member Functions

 QExtensionManager (QObject *parent=0)
 ~QExtensionManager ()
virtual void registerExtensions (QAbstractExtensionFactory *factory, const QString &iid=QString())
virtual void unregisterExtensions (QAbstractExtensionFactory *factory, const QString &iid=QString())
virtual QObjectextension (QObject *object, const QString &iid) const

Private Attributes

QHash< QString, QList< QAbstractExtensionFactory * > > m_extensions
QList< QAbstractExtensionFactory * > m_globalExtension

Related Functions

(Note that these are not member functions.)

qt_extension (QAbstractExtensionManager *manager, QObject *object)


Constructor & Destructor Documentation

QExtensionManager::QExtensionManager ( QObject parent = 0  ) 

Constructs an extension manager with the given parent.

Definition at line 94 of file qextensionmanager.cpp.

00095     : QObject(parent)
00096 {
00097 }

QExtensionManager::~QExtensionManager (  ) 

Destroys the extension manager

Definition at line 103 of file qextensionmanager.cpp.

00104 {
00105 }


Member Function Documentation

void QExtensionManager::registerExtensions ( QAbstractExtensionFactory factory,
const QString iid = QString() 
) [virtual]

Register the extension specified by the given factory and extension identifier iid.

Implements QAbstractExtensionManager.

Definition at line 111 of file qextensionmanager.cpp.

References QHash< Key, T >::contains(), QHash< Key, T >::insert(), QString::isEmpty(), m_extensions, m_globalExtension, and QList< T >::prepend().

Referenced by qdesigner_internal::FormEditor::FormEditor(), TicTacToePlugin::initialize(), Q3ListBoxPlugin::initialize(), Q3TablePlugin::initialize(), MultiPageWidgetPlugin::initialize(), Q3TextEditPlugin::initialize(), Q3MainWindowPlugin::initialize(), Q3WidgetStackPlugin::initialize(), Q3IconViewPlugin::initialize(), Q3ListViewPlugin::initialize(), Q3WizardPlugin::initialize(), Q3ToolBarPlugin::initialize(), qdesigner_internal::SignalSlotEditor::SignalSlotEditor(), and qdesigner_internal::TaskMenuComponent::TaskMenuComponent().

00112 {
00113     if (iid.isEmpty()) {
00114         m_globalExtension.prepend(factory);
00115         return;
00116     }
00117 
00118     if (!m_extensions.contains(iid))
00119         m_extensions.insert(iid, QList<QAbstractExtensionFactory*>());
00120 
00121     m_extensions[iid].prepend(factory);
00122 }

Here is the call graph for this function:

void QExtensionManager::unregisterExtensions ( QAbstractExtensionFactory factory,
const QString iid = QString() 
) [virtual]

Unregister the extension specified by the given factory and extension identifier iid.

Implements QAbstractExtensionManager.

Definition at line 128 of file qextensionmanager.cpp.

References QHash< Key, T >::contains(), QString::isEmpty(), m_extensions, m_globalExtension, QHash< Key, T >::remove(), and QList< T >::removeAll().

00129 {
00130     if (iid.isEmpty()) {
00131         m_globalExtension.removeAll(factory);
00132     } else if (m_extensions.contains(iid)) {
00133         QList<QAbstractExtensionFactory*> &factories = m_extensions[iid];
00134         factories.removeAll(factory);
00135 
00136         if (factories.isEmpty())
00137             m_extensions.remove(iid);
00138     }
00139 }

Here is the call graph for this function:

QObject * QExtensionManager::extension ( QObject object,
const QString iid 
) const [virtual]

Returns the extension specified by iid, for the given object.

Implements QAbstractExtensionManager.

Definition at line 145 of file qextensionmanager.cpp.

References QAbstractExtensionFactory::extension(), l, m_extensions, m_globalExtension, object, and QHash< Key, T >::value().

00146 {
00147     QList<QAbstractExtensionFactory*> l = m_extensions.value(iid);
00148     l += m_globalExtension;
00149 
00150     foreach (QAbstractExtensionFactory *factory, l) {
00151         if (QObject *ext = factory->extension(object, iid))
00152             return ext;
00153     }
00154 
00155     return 0;
00156 }

Here is the call graph for this function:


Friends And Related Function Documentation

T qt_extension ( QAbstractExtensionManager manager,
QObject object 
) [related]

Returns the extension of the given object cast to type T if the object is of type T (or of a subclass); otherwise returns 0. The extension is retrieved using the given extension manager.

       QDesignerPropertySheetExtension *propertySheet;
       QExtensionManager manager = formEditor->extensionManager();

       propertySheet = qt_extension<QDesignerPropertySheetExtension*>(manager, widget);

       if(propertySheet) {...}

When implementing a custom widget plugin, a pointer to 's current QDesignerFormEditorInterface object (formEditor) is provided by the QDesignerCustomWidgetInterface::initialize() function's parameter.

If the widget in the example above doesn't have a defined QDesignerPropertySheetExtension, propertySheet will be a null pointer.

Definition at line 74 of file extension.h.

00075 { return 0; }


Member Data Documentation

QHash<QString, QList<QAbstractExtensionFactory*> > QExtensionManager::m_extensions [private]

Definition at line 47 of file qextensionmanager.h.

Referenced by extension(), registerExtensions(), and unregisterExtensions().

QList<QAbstractExtensionFactory*> QExtensionManager::m_globalExtension [private]

Definition at line 48 of file qextensionmanager.h.

Referenced by extension(), registerExtensions(), and unregisterExtensions().


The documentation for this class was generated from the following files:
Generated on Thu Mar 15 17:31:39 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1