KGenericFactory

Search for usage in LXR

KGenericFactory< Product, ParentType > Class Template Reference

#include <KGenericFactory>

Inherits KGenericFactoryBase< T >.

Public Member Functions

 KGenericFactory (const char *componentName=nullptr)
 
 KGenericFactory (const KAboutData *data)
 

Protected Member Functions

virtual QObjectcreateObject (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:

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 argument of the KGenericFactory constructor is 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> )
Deprecated:
use KPluginFactory

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 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:

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 argument of the KGenericFactory constructor is 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 153 of file kgenericfactory.h.


The documentation for this class was generated from the following file:
This template provides a generic implementation of a KLibFactory , for use with shared library compon...
A dialog base class with standard buttons and predefined layouts.
Definition: kdialog.h:128
Per component data.
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon May 8 2023 03:56:01 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.