#ifndef PLUGIN_SUPPORTPLUGINMODULE_H #define PLUGIN_SUPPORTPLUGINMODULE_H #include "ModuleActionParameters.h" #include "StaticAction.h" #include "PluginRegister.h" #include #include #include #include #include #include #include class QAction; class IPluginContentWidgetContext; class PluginContentWidget; /** Defines available actions for the application framework. * * There are static and context actions. * There can be multiple contexts which are seperated by there typeid/type_index. */ class PluginModule: public QObject { Q_OBJECT public: using StaticActionList = std::vector; using ModuleAction = std::function; using ModuleActionMap = std::map; using ContextActionContainer = std::vector>; PluginModule(QString name, QString ident); virtual void init() {} const QString& name() const { return m_name; } const QString& identifier() const { return m_ident; } const QString& displayCategory() const { return m_displayCategory; } void setDisplayCategory(QString category); /// registers an action that should always be accessible from the menu void registerStaticAction(StaticAction action); const StaticActionList& staticActions() const; /// "API" action that other modules can trigger by name without being linked to /// this module. Allows for loose coupling. void registerModuleAction(QString module_action, ModuleAction action); /// Searches for and returns a pointer to the requested module action. /// When the action is not found nullptr is returned. const ModuleAction* findModuleAction(const QString &module_action) const; void registerContextAction(std::shared_ptr action); std::set contextTypeIndexes(); const ContextActionContainer& actionsForContext(std::type_index ti); const ContextActionContainer& actionsForContext(PluginContentWidget *widget); private: using ContextMap = std::unordered_map; /// Name shown to end users QString m_name; /// Unique identifier QString m_ident; QString m_displayCategory; StaticActionList m_menuActions; ModuleActionMap m_moduleActions; ContextMap m_contextMap; }; template std::shared_ptr createPluginModule(QString name, QString ident, QString category={}) { auto module = std::make_shared(std::move(name), std::move(ident)); module->setDisplayCategory(category); PluginRegister::getInstance()->registerModule(module); return std::move(module); } #define REGISTER_PLUGIN_MODULE(module, name, ident) \ namespace {\ std::weak_ptr register_variable = createPluginModule\ (name, ident);} #define REGISTER_PLUGIN_MODULE_CAT(module, name, ident, category) \ namespace {\ std::weak_ptr register_variable = createPluginModule\ (name, ident, category);} #endif // PLUGIN_SUPPORTPLUGINMODULE_H