• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KDECore

KGenericFactory< Product, ParentType > Class Template Reference

This template provides a generic implementation of a KLibFactory , for use with shared library components. More...

#include <KGenericFactory>

Inheritance diagram for KGenericFactory< Product, ParentType >:

Inheritance graph
[legend]

List of all members.


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)

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 );
The args QStringList passed to the constructor is the args string list that the caller passed to KLibFactory's create method.

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 );
The args QStringList passed to the constructor is the args string list that the caller passed to KLibFactory's create method.

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 );
The args QStringList passed to the constructor is the args string list that the caller passed to KLibFactory's create method.

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.


Constructor & Destructor Documentation

template<class Product , class ParentType = QObject>
KGenericFactory< Product, ParentType >::KGenericFactory ( const char *  componentName = 0,
const char *  catalogName = 0 
) [inline, explicit]

Definition at line 151 of file kgenericfactory.h.

template<class Product , class ParentType = QObject>
KGenericFactory< Product, ParentType >::KGenericFactory ( const KAboutData *  data  )  [inline, explicit]

Definition at line 155 of file kgenericfactory.h.


Member Function Documentation

template<class Product , class ParentType = QObject>
virtual QObject* KGenericFactory< Product, ParentType >::createObject ( QObject *  parent,
const char *  className,
const QStringList &  args 
) [inline, protected, virtual]

Deprecated:

Reimplemented from KPluginFactory.

Definition at line 160 of file kgenericfactory.h.


The documentation for this class was generated from the following file:
  • kgenericfactory.h

KDECore

Skip menu "KDECore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal