diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,7 +29,7 @@ set(REQUIRED_QT_VERSION 5.7.0) find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Core) -set(KCoreAddons_AUTOMOC_MACRO_NAMES "K_PLUGIN_FACTORY_WITH_JSON" "K_PLUGIN_FACTORY") +set(KCoreAddons_AUTOMOC_MACRO_NAMES "K_PLUGIN_FACTORY_WITH_JSON" "K_PLUGIN_FACTORY" "K_PLUGIN_CLASS_WITH_JSON") if(NOT CMAKE_VERSION VERSION_LESS "3.10.0") # CMake 3.9+ warns about automoc on files without Q_OBJECT, and doesn't know about other macros. # 3.10+ lets us provide more macro names that require automoc. diff --git a/src/lib/plugin/kpluginfactory.h b/src/lib/plugin/kpluginfactory.h --- a/src/lib/plugin/kpluginfactory.h +++ b/src/lib/plugin/kpluginfactory.h @@ -172,6 +172,44 @@ */ #define K_PLUGIN_FACTORY_WITH_JSON(name, jsonFile, pluginRegistrations) K_PLUGIN_FACTORY_WITH_BASEFACTORY_JSON(name, KPluginFactory, jsonFile, pluginRegistrations) +/** + * \relates KPluginFactory + * + * Create a KPluginFactory subclass and export it as the root plugin object with + * JSON metadata. + * + * This macro does the same as K_PLUGIN_FACTORY_WITH_JSON, but you only have to pass the class name and the json file. + * The factory name and registerPlugin call are deduced from the class name. + * + * @code + * #include + * @endcode + * in the same source file when that one has the name "myplugin.cpp". + * + * Example: + * \code + * #include + * #include + * + * class MyPlugin : public PluginInterface + * { + * public: + * MyPlugin(QObject *parent, const QVariantList &args) + * : PluginInterface(parent) + * {} + * }; + * + * K_PLUGIN_CLASS_WITH_JSON(MyPlugin, "metadata.json") + * + * #include + * \endcode + * + * \see K_PLUGIN_FACTORY_WITH_JSON + * + * @since 5.44 + */ +#define K_PLUGIN_CLASS_WITH_JSON(classname, jsonFile) K_PLUGIN_FACTORY_WITH_JSON(classname ## Factory, jsonFile, registerPlugin();) + /** * \relates KPluginFactory *