2018-12-30 15:46:15 +01:00
|
|
|
|
#ifndef PLUGIN_SUPPORTPLUGINMODULE_H
|
|
|
|
|
|
#define PLUGIN_SUPPORTPLUGINMODULE_H
|
|
|
|
|
|
|
2018-12-31 15:20:55 +01:00
|
|
|
|
#include "ModuleActionParameters.h"
|
2019-01-31 19:31:17 +01:00
|
|
|
|
#include "StaticAction.h"
|
|
|
|
|
|
#include "LContextAction.h"
|
2018-12-31 15:20:55 +01:00
|
|
|
|
#include "PluginRegister.h"
|
2018-12-30 15:46:15 +01:00
|
|
|
|
#include <QObject>
|
2018-12-31 15:20:55 +01:00
|
|
|
|
#include <functional>
|
|
|
|
|
|
#include <map>
|
2019-01-01 11:15:16 +01:00
|
|
|
|
#include <vector>
|
2018-12-30 15:46:15 +01:00
|
|
|
|
|
|
|
|
|
|
class QAction;
|
2018-12-31 15:20:55 +01:00
|
|
|
|
class IPluginContentWidgetContext;
|
2018-12-30 15:46:15 +01:00
|
|
|
|
|
|
|
|
|
|
class PluginModule: public QObject {
|
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
public:
|
2019-01-31 19:31:17 +01:00
|
|
|
|
using StaticActionList = std::vector<StaticAction>;
|
|
|
|
|
|
using ContextActionList = std::vector<LContextAction>;
|
2018-12-31 15:20:55 +01:00
|
|
|
|
using ModuleAction = std::function<void(IPluginContentWidgetContext*, const ModuleActionParameters &)>;
|
|
|
|
|
|
using ModuleActionMap = std::map<QString, ModuleAction>;
|
|
|
|
|
|
|
2018-12-30 15:46:15 +01:00
|
|
|
|
PluginModule(QString name, QString ident);
|
|
|
|
|
|
|
2019-01-05 19:58:23 +01:00
|
|
|
|
virtual void init() {}
|
2019-01-01 11:15:16 +01:00
|
|
|
|
|
2018-12-30 15:46:15 +01:00
|
|
|
|
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);
|
2019-01-01 11:15:16 +01:00
|
|
|
|
|
|
|
|
|
|
/// registers an action that should always be accessible from the menu
|
2019-01-31 19:31:17 +01:00
|
|
|
|
void registerStaticAction(StaticAction action);
|
|
|
|
|
|
const StaticActionList& staticActions() const;
|
2018-12-31 15:20:55 +01:00
|
|
|
|
|
2019-01-31 19:25:54 +01:00
|
|
|
|
/// "API" action that other modules can trigger by name without being linked to
|
|
|
|
|
|
/// this module. Allows for loose coupling.
|
2018-12-31 15:20:55 +01:00
|
|
|
|
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;
|
2019-01-05 19:58:23 +01:00
|
|
|
|
|
2019-01-31 19:31:17 +01:00
|
|
|
|
void registerContextAction(const LContextAction &action)
|
2019-01-05 19:58:23 +01:00
|
|
|
|
{
|
|
|
|
|
|
m_widgetActions.push_back(action);
|
|
|
|
|
|
}
|
2019-01-31 19:31:17 +01:00
|
|
|
|
const ContextActionList& contextActions() const { return m_widgetActions; }
|
2018-12-30 15:46:15 +01:00
|
|
|
|
private:
|
|
|
|
|
|
/// Name shown to end users
|
|
|
|
|
|
QString m_name;
|
|
|
|
|
|
/// Unique identifier
|
|
|
|
|
|
QString m_ident;
|
|
|
|
|
|
QString m_displayCategory;
|
2018-12-31 15:20:55 +01:00
|
|
|
|
|
2019-01-31 19:31:17 +01:00
|
|
|
|
StaticActionList m_menuActions;
|
2018-12-31 15:20:55 +01:00
|
|
|
|
ModuleActionMap m_moduleActions;
|
2019-01-31 19:31:17 +01:00
|
|
|
|
ContextActionList m_widgetActions;
|
2018-12-30 15:46:15 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-12-31 15:20:55 +01:00
|
|
|
|
template <typename T>
|
2019-01-06 10:11:48 +01:00
|
|
|
|
std::shared_ptr<PluginModule> createPluginModule(QString name, QString ident, QString category={})
|
2018-12-31 15:20:55 +01:00
|
|
|
|
{
|
|
|
|
|
|
auto module = std::make_shared<T>(std::move(name), std::move(ident));
|
2019-01-06 10:11:48 +01:00
|
|
|
|
module->setDisplayCategory(category);
|
2018-12-31 15:20:55 +01:00
|
|
|
|
|
|
|
|
|
|
PluginRegister::getInstance()->registerModule(module);
|
|
|
|
|
|
return std::move(module);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-01-01 08:26:20 +01:00
|
|
|
|
#define REGISTER_PLUGIN_MODULE(module, name, ident) \
|
|
|
|
|
|
namespace {\
|
|
|
|
|
|
std::weak_ptr<PluginModule> register_variable = createPluginModule<module>\
|
2019-01-01 14:35:22 +01:00
|
|
|
|
(name, ident);}
|
2019-01-01 08:26:20 +01:00
|
|
|
|
|
2019-01-06 10:11:48 +01:00
|
|
|
|
#define REGISTER_PLUGIN_MODULE_CAT(module, name, ident, category) \
|
|
|
|
|
|
namespace {\
|
|
|
|
|
|
std::weak_ptr<PluginModule> register_variable = createPluginModule<module>\
|
|
|
|
|
|
(name, ident, category);}
|
|
|
|
|
|
|
2018-12-31 15:20:55 +01:00
|
|
|
|
|
2018-12-30 15:46:15 +01:00
|
|
|
|
#endif // PLUGIN_SUPPORTPLUGINMODULE_H
|