83 lines
2.4 KiB
C++
83 lines
2.4 KiB
C++
#ifndef PLUGIN_SUPPORTPLUGINMODULE_H
|
|
#define PLUGIN_SUPPORTPLUGINMODULE_H
|
|
|
|
#include "ModuleActionParameters.h"
|
|
#include "MenuAction.h"
|
|
#include "LWidgetAction.h"
|
|
#include "PluginRegister.h"
|
|
#include <QObject>
|
|
#include <functional>
|
|
#include <map>
|
|
#include <vector>
|
|
|
|
class QAction;
|
|
class IPluginContentWidgetContext;
|
|
|
|
class PluginModule: public QObject {
|
|
Q_OBJECT
|
|
public:
|
|
using MenuActionList = std::vector<MenuAction>;
|
|
using LWidgetActionList = std::vector<LWidgetAction>;
|
|
using ModuleAction = std::function<void(IPluginContentWidgetContext*, const ModuleActionParameters &)>;
|
|
using ModuleActionMap = std::map<QString, ModuleAction>;
|
|
|
|
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 registerMenuAction(MenuAction action);
|
|
const MenuActionList& menuActions() const;
|
|
|
|
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 registerWidgetAction(const LWidgetAction &action)
|
|
{
|
|
m_widgetActions.push_back(action);
|
|
}
|
|
const LWidgetActionList& widgetActions() const { return m_widgetActions; }
|
|
private:
|
|
/// Name shown to end users
|
|
QString m_name;
|
|
/// Unique identifier
|
|
QString m_ident;
|
|
QString m_displayCategory;
|
|
|
|
MenuActionList m_menuActions;
|
|
ModuleActionMap m_moduleActions;
|
|
LWidgetActionList m_widgetActions;
|
|
};
|
|
|
|
|
|
template <typename T>
|
|
std::shared_ptr<PluginModule> createPluginModule(QString name, QString ident, QString category={})
|
|
{
|
|
auto module = std::make_shared<T>(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<PluginModule> register_variable = createPluginModule<module>\
|
|
(name, ident);}
|
|
|
|
#define REGISTER_PLUGIN_MODULE_CAT(module, name, ident, category) \
|
|
namespace {\
|
|
std::weak_ptr<PluginModule> register_variable = createPluginModule<module>\
|
|
(name, ident, category);}
|
|
|
|
|
|
#endif // PLUGIN_SUPPORTPLUGINMODULE_H
|