|
Krita Source Code Documentation
|
#include <KoPluginLoader.h>
Inheritance diagram for KoPluginLoader:Classes | |
| struct | PluginsConfig |
Public Member Functions | |
| KoPluginLoader () | |
| DO NOT USE! Use instance() instead. | |
| void | load (const QString &serviceType, const PluginsConfig &config=PluginsConfig(), QObject *owner=0, bool cache=true) |
| KPluginFactory * | loadSinglePlugin (const QString &id, const QString &serviceType) |
| KPluginFactory * | loadSinglePlugin (const std::pair< QString, QString > &predicates, const QString &serviceType) |
| KPluginFactory * | loadSinglePlugin (const std::vector< std::pair< QString, QString > > &predicates, const QString &serviceType) |
| ~KoPluginLoader () override | |
Static Public Member Functions | |
| static KoPluginLoader * | instance () |
Public Attributes | |
| QStringList | loadedServiceTypes |
Private Member Functions | |
| KoPluginLoader (const KoPluginLoader &) | |
| KoPluginLoader | operator= (const KoPluginLoader &) |
Private Member Functions inherited from Private | |
| Private (KisCanvas2 *c) | |
Private Attributes | |
| Private *const | d |
Private Attributes inherited from Private | |
| KisCanvas2 * | canvas |
| int | displayedFrame |
| int | intendedFrame |
The pluginloader singleton is responsible for loading the plugins that it's asked to load. It keeps track of which servicetypes it has seen and doesn't reload them. The plugins need to inherit a QObject with a default constructor. Inside the default constructor you can create whatever object you want and add it to whatever registry you prefer. After having been constructed, your plugin will be deleted, so do all you need in the constructor. Things like adding a factory to a registry make sense there. Example header file;
Example cpp file;
Definition at line 60 of file KoPluginLoader.cpp.
|
override |
Definition at line 71 of file KoPluginLoader.cpp.
References d.
| KoPluginLoader::KoPluginLoader | ( | ) |
DO NOT USE! Use instance() instead.
Definition at line 66 of file KoPluginLoader.cpp.
|
private |
|
static |
Return an instance of the KoPluginLoader Creates an instance if that has never happened before and returns the singleton instance.
Definition at line 78 of file KoPluginLoader.cpp.
| void KoPluginLoader::load | ( | const QString & | serviceType, |
| const PluginsConfig & | config = PluginsConfig(), | ||
| QObject * | owner = 0, | ||
| bool | cache = true ) |
Load all plugins that conform to the versiontype, for instance: KoPluginLoader::instance()->load("Krita/Flake"); This method allows you to optionally limit the plugins that are loaded by version, but also using a user configurable set of config options. If you pass a PluginsConfig struct only those plugins are loaded that are specified in the application config file. New plugins found since last start will be automatically loaded.
| serviceType | The string used to identify the plugins. |
| config | when passing a valid config only the wanted plugins are actually loaded #param owner if 0, the plugin will be deleted after instantiation, if not, the given qobject will own the plugin in its qobject hierarchy |
| cache | if true, the plugin will only be loaded once |
First, remove all the duplicated plugins and keep only the ones with the highest version number
Erasing an element in QList in Qt5 may invalidate the existing iterator, so we should derive the new position from the iterator returned by erase() method
Then remove all the blacklisted plugins if necessary
Now "load" all the plugins. If "owner" object is not provided, we just create the plugin object and immediately destroy it. Usually the constructor of this plugin will just populate some registry, so the object is not necessary anymore.
Definition at line 83 of file KoPluginLoader.cpp.
References KoPluginLoader::PluginsConfig::blacklist, d, dbgPlugins, KoJsonTrader::Plugin::errorString(), KoJsonTrader::Plugin::fileName(), KoPluginLoader::PluginsConfig::group, KoJsonTrader::instance(), KoJsonTrader::Plugin::instance(), KoPluginLoader::PluginsConfig::isValid(), KoJsonTrader::query(), and warnPlugins.
| KPluginFactory * KoPluginLoader::loadSinglePlugin | ( | const QString & | id, |
| const QString & | serviceType ) |
Definition at line 189 of file KoPluginLoader.cpp.
References loadSinglePlugin().
| KPluginFactory * KoPluginLoader::loadSinglePlugin | ( | const std::pair< QString, QString > & | predicates, |
| const QString & | serviceType ) |
| KPluginFactory * KoPluginLoader::loadSinglePlugin | ( | const std::vector< std::pair< QString, QString > > & | predicates, |
| const QString & | serviceType ) |
Load a single plugin from the plugins directory
One can pass a set of predicates that should be satisfied for the plugin to be selected. The loader will compare metadata of the plugin against those predicates and choose only the one satisfying all of them.
If multiple plugins are found, then the one with highest version number is used. If two plugins with the same maximum version number exist, then a random one is selected.
Usage:
Definition at line 157 of file KoPluginLoader.cpp.
References KoJsonTrader::instance(), and KoJsonTrader::query().
|
private |
|
private |
Definition at line 152 of file KoPluginLoader.h.
| QStringList KoPluginLoader::loadedServiceTypes |
Definition at line 63 of file KoPluginLoader.cpp.