KDECore
KGenericFactory< Product, ParentType > Class Template Reference
#include <KGenericFactory>

Detailed Description
template<class Product, class ParentType = QObject>
class KGenericFactory< Product, ParentType >
This template provides a generic implementation of a KLibFactory , for use with shared library components.
It implements the pure virtual createObject method of KLibFactory and instantiates objects of the specified class (template argument) when the class name argument of createObject matches a class name in the given hierarchy.
In case you are developing a KParts component, skip this file and go directly to KParts::GenericFactory .
Note that the class specified as template argument needs to provide a certain constructor:
-
If the class is derived from QObject then it needs to have a constructor like:
MyClass( QObject *parent, const QStringList &args );
-
If the class is derived from QWidget then it needs to have a constructor like:
MyWidget( QWidget *parent, const QStringList &args);
-
If the class is derived from KParts::Part then it needs to have a constructor like:
MyPart( QWidget *parentWidget, QObject *parent, const QStringList &args );
In addition upon instantiation this template provides a central KComponentData object for your component, accessible through the static componentData() method. The componentName and catalogName arguments of the KGenericFactory constructor are passed to the KComponentData object.
The creation of the KComponentData object can be customized by inheriting from this template class and re-implementing the virtual createComponentData method. For example it could look like this:
KComponentData *MyFactory::createComponentData() { return new KComponentData( myAboutData ); }
Example of usage of the whole template:
class MyPlugin : public KParts::Plugin { Q_ OBJECT public: MyPlugin( QObject *parent, const QStringList &args ); ... }; K_EXPORT_COMPONENT_FACTORY( libmyplugin, KGenericFactory<MyPlugin> )
It implements the pure virtual createObject method of KLibFactory and instantiates objects of the specified classes in the given typelist template argument when the class name argument of createObject matches a class names in the given hierarchy of classes.
Note that each class in the specified in the typelist template argument needs to provide a certain constructor:
-
If the class is derived from QObject then it needs to have a constructor like:
MyClass( QObject *parent, const QStringList &args );
-
If the class is derived from QWidget then it needs to have a constructor like:
MyWidget( QWidget *parent, const QStringList &args);
-
If the class is derived from KParts::Part then it needs to have a constructor like:
MyPart( QWidget *parentWidget, QObject *parent, const QStringList &args );
In addition upon instantiation this template provides a central KComponentData object for your component, accessible through the static componentData() method. The componentName and catalogName arguments of the KGenericFactory constructor are passed to the KComponentData object.
The creation of the KComponentData object can be customized by inheriting from this template class and re-implementing the virtual createComponentData method. For example it could look like this:
KComponentData *MyFactory::createComponentData() { return new KComponentData( myAboutData ); }
Example of usage of the whole template:
class MyPlugin : public KParts::Plugin { Q_ OBJECT public: MyPlugin( QObject *parent, const QStringList &args ); ... }; class MyDialogComponent : public KDialog { Q_ OBJECT public: MyDialogComponent( QWidget *parentWidget, const QStringList &args ); ... }; typedef K_TYPELIST_2( MyPlugin, MyDialogComponent ) Products; K_EXPORT_COMPONENT_FACTORY( libmyplugin, KGenericFactory<Products> )
It implements the pure virtual createObject method of KLibFactory and instantiates objects of the specified classes in the given typelist template argument when the class name argument of createObject matches a class names in the given hierarchy of classes.
Note that each class in the specified in the typelist template argument needs to provide a certain constructor:
-
If the class is derived from QObject then it needs to have a constructor like:
MyClass( QObject *parent, const QStringList &args );
-
If the class is derived from QWidget then it needs to have a constructor like:
MyWidget( QWidget *parent, const QStringList &args);
-
If the class is derived from KParts::Part then it needs to have a constructor like:
MyPart( QWidget *parentWidget, QObject *parent, const QStringList &args );
In addition upon instantiation this template provides a central KComponentData object for your component, accessible through the static componentData() method. The componentName and catalogNames arguments of the KGenericFactory constructor are passed to the KComponentData object.
The creation of the KComponentData object can be customized by inheriting from this template class and re-implementing the virtual createComponentData method. For example it could look like this:
KComponentData *MyFactory::createComponentData() { return new KComponentData( myAboutData ); }
Example of usage of the whole template:
class MyPlugin : public KParts::Plugin { Q_ OBJECT public: MyPlugin( QObject *parent, const QStringList &args ); ... }; class MyDialogComponent : public KDialog { Q_ OBJECT public: MyDialogComponent( QWidget *parentWidget, const QStringList &args ); ... }; typedef K_TYPELIST_2( MyPlugin, MyDialogComponent ) Products; K_EXPORT_COMPONENT_FACTORY( libmyplugin, KGenericFactory<Products> )
Definition at line 148 of file kgenericfactory.h.
Public Member Functions | |
KGenericFactory (const KAboutData *data) | |
KGenericFactory (const char *componentName=0, const char *catalogName=0) | |
Protected Member Functions | |
virtual QObject * | createObject (QObject *parent, const char *className, const QStringList &args) |
Constructor & Destructor Documentation
KGenericFactory< Product, ParentType >::KGenericFactory | ( | const char * | componentName = 0 , |
|
const char * | catalogName = 0 | |||
) | [inline, explicit] |
Definition at line 151 of file kgenericfactory.h.
KGenericFactory< Product, ParentType >::KGenericFactory | ( | const KAboutData * | data | ) | [inline, explicit] |
Definition at line 155 of file kgenericfactory.h.
Member Function Documentation
virtual QObject* KGenericFactory< Product, ParentType >::createObject | ( | QObject * | parent, | |
const char * | className, | |||
const QStringList & | args | |||
) | [inline, protected, virtual] |
The documentation for this class was generated from the following file: