KCoreAddons
kpluginfactory.h
91#define K_PLUGIN_FACTORY(name, pluginRegistrations) __K_PLUGIN_FACTORY_DEFINITION(name, pluginRegistrations, IID KPluginFactory_iid)
154 * This macro does the same as K_PLUGIN_FACTORY_WITH_JSON, but you only have to pass the class name and the json file.
186 K_PLUGIN_FACTORY_WITH_JSON(KPLUGINFACTORY_PLUGIN_CLASS_INTERNAL_NAME, jsonFile, registerPlugin<classname>();)
188#define K_PLUGIN_CLASS_WITH_JSON(classname, jsonFile) K_PLUGIN_FACTORY_WITH_JSON(classname##Factory, jsonFile, registerPlugin<classname>();)
199 * This is also useful if you want to use static plugins, see the kcoreaddons_add_plugin CMake method.
203#define K_PLUGIN_CLASS(classname) K_PLUGIN_FACTORY(KPLUGINFACTORY_PLUGIN_CLASS_INTERNAL_NAME, registerPlugin<classname>();)
205#define K_PLUGIN_CLASS(classname) K_PLUGIN_FACTORY(classname##Factory, registerPlugin<classname>();)
228 * T(QWidget *parentWidget, QObject *parent, const KPluginMetaData &metaData, const QVariantList &args)
282 * virtual QObject *create(const char *iface, QWidget *parentWidget, QObject *parent, const QVariantList &args)
322 * Holds the result of a plugin load operation, i.e. the loaded plugin on success or information about the error on failure
362 * If there is no extra error handling needed the plugin can be directly accessed and checked if it is a nullptr
373 static Result<T> instantiatePlugin(const KPluginMetaData &data, QObject *parent = nullptr, const QVariantList &args = {})
386 result.errorString = tr("KPluginFactory could not create a %1 instance from %2").arg(className, data.fileName());
398 * @p T. If it has multiple choices it's not defined which object will be returned, so be careful
412 * This overload has an additional @p parentWidget argument, which is used by some plugins (e.g. Parts).
418 * @param args additional arguments which will be passed to the object. Since 5.93 this has a default arg.
446 using CreateInstanceWithMetaDataFunction = QObject *(*)(QWidget *, QObject *, const KPluginMetaData &, const QVariantList &);
449 * This is used to detect the arguments need for the constructor of metadata-taking plugin classes.
455 static constexpr bool enabled = std::is_constructible<impl, QWidget *, QObject *, KPluginMetaData, QVariantList>::value // KParts
477 * This is used to detect the arguments need for the constructor of metadata-less plugin classes.
483 static constexpr bool _canConstruct = std::is_constructible<impl, QWidget *, QVariantList>::value // QWidget plugin
487 static constexpr bool enabled = _canConstruct && !InheritanceWithMetaDataChecker<impl>::enabled; // Avoid ambiguity in case of default arguments
524 CreateInstanceWithMetaDataFunction instanceFunction = InheritanceChecker<T>().createInstanceFunction(static_cast<T *>(nullptr));
533 * new T(QWidget *parentWidget, QObject *parent, const KPluginMetaData &metaData, const QVariantList &args)
549 CreateInstanceWithMetaDataFunction instanceFunction = InheritanceWithMetaDataChecker<T>().createInstanceFunction(static_cast<T *>(nullptr));
559 * @param instanceFunction A function pointer to a function that creates an instance of the plugin.
580 virtual QObject *create(const char *iface, QWidget *parentWidget, QObject *parent, const QVariantList &args);
583 static QObject *createInstance(QWidget * /*parentWidget*/, QObject *parent, const KPluginMetaData & /*metaData*/, const QVariantList &args)
598 static QObject *createWithMetaDataInstance(QWidget * /*parentWidget*/, QObject *parent, const KPluginMetaData &metaData, const QVariantList &args)
605 if constexpr (std::is_constructible<impl, ParentType *, KPluginMetaData, QVariantList>::value) {
613 static QObject *createPartWithMetaDataInstance(QWidget *parentWidget, QObject *parent, const KPluginMetaData &metaData, const QVariantList &args)
615 if constexpr (std::is_constructible<impl, QWidget *, QObject *, KPluginMetaData, QVariantList>::value) {
625 void registerPlugin(const QMetaObject *metaObject, CreateInstanceWithMetaDataFunction instanceFunction);
644inline T *KPluginFactory::create(QWidget *parentWidget, QObject *parent, const QVariantList &args)
Holds the result of a plugin load operation, i.e.
Definition kpluginfactory.h:327
KPluginFactory provides a convenient way to provide factory-style plugins.
Definition kpluginfactory.h:300
T * create(QObject *parent=nullptr, const QVariantList &args={})
Use this method to create an object.
Definition kpluginfactory.h:632
void registerPlugin()
Uses a default instance creation function depending on the type of interface.
Definition kpluginfactory.h:522
static Result< T > instantiatePlugin(const KPluginMetaData &data, QObject *parent=nullptr, const QVariantList &args={})
Attempts to load the KPluginFactory and create a T instance from the given metadata KCoreAddons will ...
Definition kpluginfactory.h:373
void registerPlugin(CreateInstanceWithMetaDataFunction instanceFunction)
Registers a plugin with the factory.
Definition kpluginfactory.h:563
QObject *(*)(QWidget *, QObject *, const KPluginMetaData &, const QVariantList &) CreateInstanceWithMetaDataFunction
Function pointer type to a function that instantiates a plugin For plugins that don't support a KPlug...
Definition kpluginfactory.h:446
This class allows easily accessing some standardized values from the JSON metadata that can be embedd...
Definition kpluginmetadata.h:82
QAction * create(StandardAction id, const Receiver *recvr, Func slot, QObject *parent, std::optional< Qt::ConnectionType > connectionType=std::nullopt)
KCOREADDONS_EXPORT void setMetaData(const MetaDataMap &metaData, QMimeData *mimeData)
Definition kurlmimedata.cpp:58
bool isWidgetType() const const
QObject * parent() const const
T qobject_cast(QObject *object)
QString tr(const char *sourceText, const char *disambiguation, int n)
QString arg(Args &&... args) const const
This is used to detect the arguments need for the constructor of metadata-less plugin classes.
Definition kpluginfactory.h:481
This is used to detect the arguments need for the constructor of metadata-taking plugin classes.
Definition kpluginfactory.h:453
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:08:22 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:08:22 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.