KDE 5.0 PyKDE API Reference
  • KDE's Python API
  • Overview
  • PyKDE Home
  • Sitemap
  • Contact Us
 

KPluginFactory Class Reference

from PyKDE5.kcoreaddons import *

Inherits: QObject

Detailed Description

\class KPluginFactory kpluginfactory.h <KPluginFactory>

KPluginFactory provides a convenient way to provide factory-style plugins. Qt plugins provide a singleton object, but a common pattern is for plugins to generate as many objects of a particular type as the application requires. By using KPluginFactory, you can avoid implementing the factory pattern yourself.

KPluginFactory also allows plugins to provide multiple different object types, indexed by keywords.

The objects created by KPluginFactory must inherit QObject, and must have a standard constructor pattern:

  • if the object is a KPart.Part, it must be of the form
  •  T(QWidget *parentWidget, QObject *parent, const QVariantList &args)
    
  • if it is a QWidget, it must be of the form
  •  T(QWidget *parent, const QVariantList &args)
    
  • otherwise it must be of the form
  •  T(QObject *parent, const QVariantList &args)
    

    You should typically use either K_PLUGIN_FACTORY() or K_PLUGIN_FACTORY_WITH_JSON() in your plugin code to create the factory. The typical pattern is

     #include <KPluginFactory>
     #include <plugininterface.h>
    
     class MyPlugin : public PluginInterface
     {
     public:
         MyPlugin(QObject *parent, const QVariantList &args)
             : PluginInterface(parent)
         {}
     };
    
     K_PLUGIN_FACTORY(MyPluginFactory,
                      registerPlugin<MyPlugin>();
                     )
     #include <myplugin.moc>
    

    If you want to write a custom KPluginFactory not using the standard macro(s) you can reimplement the create(const char *iface, QWidget *parentWidget, QObject *parent, const QVariantList &args, const QString &keyword) method.

    Example:

     class SomeScriptLanguageFactory : public KPluginFactory
     {
         Q_OBJECT
     public:
         SomeScriptLanguageFactory()
         {}
    
     protected:
         virtual QObject *create(const char *iface, QWidget *parentWidget, QObject *parent, const QVariantList &args, const QString &keyword)
         {
             const QString identifier = QLatin1String(iface) + QLatin1Char('_') + keyword;
             // load scripting language module from the information in identifier
             // and return it:
             return object;
         }
     };
    

    If you want to load a library use KPluginLoader. The application that wants to instantiate plugin classes can do the following:

     KPluginFactory *factory = KPluginLoader("libraryname").factory();
     if (factory) {
         PluginInterface *p1 = factory->create<PluginInterface>(parent);
         OtherInterface *p2  = factory->create<OtherInterface>(parent);
         NextInterface *p3   = factory->create<NextInterface>("keyword1", parent);
         NextInterface *p3   = factory->create<NextInterface>("keyword2", parent);
     }
    

    Author:
    Matthias Kretz <kretz@kde.org>
    Author:
    Bernhard Loos <nhuh.put@web.de>


    Signals

     objectCreated (QObject object)

    Methods

     __init__ (self)

    Static Methods

    [QVariant] stringListToVariantList (QStringList list)
    QStringList variantListToStringList ([QVariant] list)

    Signal Documentation

    objectCreated ( QObject  object
    )
    Signal syntax:
    QObject.connect(source, SIGNAL("objectCreated(QObject*)"), target_slot)

    Method Documentation

    __init__ (   self )

    This constructor creates a factory for a plugin.


    Static Method Documentation

    [QVariant] stringListToVariantList ( QStringList  list
    )

    Internal:
    Converts a QStringList to a QVariantList

    QStringList variantListToStringList ( [QVariant]  list
    )

    Internal:
    Converts a QVariantList of strings to a QStringList

    • Full Index

    Modules

    • karchive
    • kcoreaddons
    • kguiaddons
    • kitemmodels
    • kitemviews
    • kplotting
    • kwidgetsaddons
    • solid
    • sonnet
    This documentation is maintained by Simon Edwards.
    KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal