KCoreAddons
kpluginfactory.h
75 K_PLUGIN_FACTORY_DECLARATION_WITH_BASEFACTORY_SKEL(name, baseFactory, Q_PLUGIN_METADATA(IID KPluginFactory_iid FILE json))
78 K_PLUGIN_FACTORY_DECLARATION_WITH_BASEFACTORY_SKEL(name, baseFactory, Q_PLUGIN_METADATA(IID KPluginFactory_iid))
89 #define K_PLUGIN_FACTORY_WITH_BASEFACTORY_JSON(name, baseFactory, jsonFile, pluginRegistrations) \
138 #define K_PLUGIN_FACTORY(name, pluginRegistrations) K_PLUGIN_FACTORY_WITH_BASEFACTORY(name, KPluginFactory, pluginRegistrations)
222 * This macro does the same as K_PLUGIN_FACTORY_WITH_JSON, but you only have to pass the class name and the json file.
272 K_PLUGIN_FACTORY_WITH_JSON(KPLUGINFACTORY_PLUGIN_CLASS_INTERNAL_NAME, jsonFile, registerPlugin<classname>();)
274 #define K_PLUGIN_CLASS_WITH_JSON(classname, jsonFile) K_PLUGIN_FACTORY_WITH_JSON(classname##Factory, jsonFile, registerPlugin<classname>();)
285 * This is also useful if you want to use static plugins, see the kcoreaddons_add_plugin CMake method.
289 #define K_PLUGIN_CLASS(classname) K_PLUGIN_FACTORY(KPLUGINFACTORY_PLUGIN_CLASS_INTERNAL_NAME, registerPlugin<classname>();)
291 #define K_PLUGIN_CLASS(classname) K_PLUGIN_FACTORY(classname##Factory, registerPlugin<classname>();)
305 #define K_PLUGIN_FACTORY_DECLARATION(name) K_PLUGIN_FACTORY_DECLARATION_WITH_BASEFACTORY(name, KPluginFactory)
320 #define K_PLUGIN_FACTORY_DEFINITION(name, pluginRegistrations) K_PLUGIN_FACTORY_DEFINITION_WITH_BASEFACTORY(name, KPluginFactory, pluginRegistrations)
342 * T(QWidget *parentWidget, QObject *parent, const KPluginMetaData &metaData, const QVariantList &args)
385 * create(const char *iface, QWidget *parentWidget, QObject *parent, const QVariantList &args, const QString &keyword)
398 * virtual QObject *create(const char *iface, QWidget *parentWidget, QObject *parent, const QVariantList &args, const QString &keyword)
450 * Holds the result of a plugin load operation, i.e. the loaded plugin on success or information about the error on failure
481 KPluginFactory::Result<MyClass> pluginResult = KPluginFactory::instantiatePlugin<MyClass>(metaData, parent, args);
488 * If there is no extra error handling needed the plugin can be directly accessed and checked if it is a nullptr
499 static Result<T> instantiatePlugin(const KPluginMetaData &data, QObject *parent = nullptr, const QVariantList &args = {})
512 result.errorString = tr("KPluginFactory could not create a %1 instance from %2").arg(className, data.fileName());
513 result.errorText = QStringLiteral("KPluginFactory could not create a %1 instance from %2").arg(className, data.fileName());
524 * @p T. If it has multiple choices it's not defined which object will be returned, so be careful
551 T *create(const QString &keyword, QObject *parent = nullptr, const QVariantList &args = QVariantList());
556 * This overload has an additional @p parentWidget argument, which is used by some plugins (e.g. Parts).
562 * @param args additional arguments which will be passed to the object. Since 5.93 this has a default arg.
576 T *create(QWidget *parentWidget, QObject *parent, const QString &keyword, const QVariantList &args = QVariantList());
584 KCOREADDONS_DEPRECATED_VERSION(4, 0, "Use KPluginFactory::create<T>(QObject *parent, const QVariantList &args)")
593 KCOREADDONS_DEPRECATED_VERSION(4, 0, "Use KPluginFactory::create<T>(QObject *parent, const QVariantList &args)")
594 QObject *create(QObject *parent = nullptr, const char *classname = "QObject", const QStringList &args = QStringList())
638 * This is used to detect the arguments need for the constructor of metadata-less plugin classes.
644 static constexpr bool enabled = std::is_constructible<impl, QWidget *, QObject *, const QVariantList &>::value
645 || std::is_constructible<impl, QWidget *, const QVariantList &>::value || std::is_constructible<impl, QObject *, const QVariantList &>::value;
662 * Function pointer type to a function that instantiates a plugin, also taking a plugin metadata argument.
665 using CreateInstanceWithMetaDataFunction = QObject *(*)(QWidget *, QObject *, const KPluginMetaData &, const QVariantList &);
668 * This is used to detect the arguments need for the constructor of metadata-taking plugin classes.
674 static constexpr bool enabled = std::is_constructible<impl, QWidget *, QObject *, const KPluginMetaData &, const QVariantList &>::value
676 || std::is_constructible<impl, QObject *, const KPluginMetaData &, const QVariantList &>::value;
700 * Registers a metadata-less plugin with the factory. Call this function from the constructor of the
716 * @deprecated Since 5.89, providing a custom CreateInstanceFunction is deprecated. Use registerPlugin<T>() instead
719 KCOREADDONS_DEPRECATED_VERSION_BELATED(5, 89, 5, 95, "Use registerPlugin(CreateInstanceWithMetaDataFunction) instead")
727 * Overload for registerPlugin<T>(const QString &keyword, CreateInstanceFunction instanceFunction)
749 CreateInstanceFunction instanceFunction = InheritanceChecker<T>().createInstanceFunction(static_cast<T *>(nullptr));
762 CreateInstanceFunction instanceFunction = InheritanceChecker<T>().createInstanceFunction(static_cast<T *>(nullptr));
769 * Registers a metadata-taking plugin with the factory. Call this function from the constructor of the
785 * @deprecated Since 5.89, providing a custom CreateInstanceWithMetaDataFunction is deprecated. Use registerPlugin<T>() instead
788 KCOREADDONS_DEPRECATED_VERSION(5, 89, "Providing a custom CreateInstanceWithMetaDataFunction is deprecated. Use registerPlugin<T>() instead")
789 void registerPlugin(const QString &keyword, CreateInstanceWithMetaDataFunction instanceFunction)
800 * new T(QWidget *parentWidget, QObject *parent, const KPluginMetaData &metaData, const QVariantList &args)
816 CreateInstanceWithMetaDataFunction instanceFunction = InheritanceWithMetaDataChecker<T>().createInstanceFunction(static_cast<T *>(nullptr));
826 * @param instanceFunction A function pointer to a function that creates an instance of the plugin.
844 CreateInstanceWithMetaDataFunction instanceFunction = InheritanceWithMetaDataChecker<T>().createInstanceFunction(static_cast<T *>(nullptr));
854 KCOREADDONS_DEPRECATED_VERSION(4, 0, "Use KPluginFactory::create<T>(QObject *parent, const QVariantList &args)")
858 * @deprecated since 4.0 use create<T>(QWidget *parentWidget, QObject *parent, const QString &keyword, const QVariantList &args)
862 "Use KPluginFactory::create<T>(QWidget *parentWidget, QObject *parent, const QString &keyword, const QVariantList &args)")
863 virtual KParts::Part *createPartObject(QWidget *parentWidget, QObject *parent, const char *classname, const QStringList &args);
880 virtual QObject *create(const char *iface, QWidget *parentWidget, QObject *parent, const QVariantList &args, const QString &keyword);
883 static QObject *createInstance(QWidget *parentWidget, QObject *parent, const QVariantList &args)
895 static QObject *createPartInstance(QWidget *parentWidget, QObject *parent, const QVariantList &args)
901 static QObject *createWithMetaDataInstance(QWidget *parentWidget, QObject *parent, const KPluginMetaData &metaData, const QVariantList &args)
913 static QObject *createPartWithMetaDataInstance(QWidget *parentWidget, QObject *parent, const KPluginMetaData &metaData, const QVariantList &args)
919 void registerPlugin(const QString &keyword, const QMetaObject *metaObject, CreateInstanceFunction instanceFunction);
920 void registerPlugin(const QString &keyword, const QMetaObject *metaObject, CreateInstanceWithMetaDataFunction instanceFunction);
921 // The logging categories are not part of the public API, consequently this needs to be a private function
939 create(T::staticMetaObject.className(), parent && parent->isWidgetType() ? reinterpret_cast<QWidget *>(parent) : nullptr, parent, args, QString());
950 inline T *KPluginFactory::create(const QString &keyword, QObject *parent, const QVariantList &args)
953 create(T::staticMetaObject.className(), parent && parent->isWidgetType() ? reinterpret_cast<QWidget *>(parent) : nullptr, parent, args, keyword);
964 inline T *KPluginFactory::create(QWidget *parentWidget, QObject *parent, const QVariantList &args)
977 inline T *KPluginFactory::create(QWidget *parentWidget, QObject *parent, const QString &keyword, const QVariantList &args)
KCOREADDONS_EXPORT KCOREADDONS_DEPRECATED_VERSION_BELATED(5, 75, 5, 0, "Use simpleBackupFile() or numberedBackupFile() directly") bool backupFile(const QString &filename
Function to create a backup file before saving.
void registerPlugin(CreateInstanceWithMetaDataFunction instanceFunction)
Registers a plugin with the factory.
Definition: kpluginfactory.h:830
void registerPlugin()
Overload for registerPlugin<T>(const QString &keyword, CreateInstanceFunction instanceFunction)
Definition: kpluginfactory.h:747
Definition: kpluginfactory.h:427
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.
Definition: kpluginfactory.h:499
QAction * create(GameStandardAction id, const QObject *recvr, const char *slot, QObject *parent)
T * create(QObject *parent=nullptr, const QVariantList &args=QVariantList())
Use this method to create an object.
Definition: kpluginfactory.h:936
This is used to detect the arguments need for the constructor of metadata-taking plugin classes.
Definition: kpluginfactory.h:672
Q_SIGNALSQ_SIGNALS
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
bool isWidgetType() const const
QObject *(*)(QWidget *, QObject *, const KPluginMetaData &, const QVariantList &) CreateInstanceWithMetaDataFunction
Function pointer type to a function that instantiates a plugin, also taking a plugin metadata argumen...
Definition: kpluginfactory.h:665
This is used to detect the arguments need for the constructor of metadata-less plugin classes.
Definition: kpluginfactory.h:642
Holds the result of a plugin load operation, i.e.
Definition: kpluginfactory.h:454
QString tr(const char *sourceText, const char *disambiguation, int n)
Definition: kpluginmetadata.h:87
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Nov 28 2023 04:05:52 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Nov 28 2023 04:05:52 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.