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 "MenuLocation.h"
|
|
|
|
|
|
#include "ToolbarLocation.h"
|
|
|
|
|
|
#include "ModuleActionParameters.h"
|
|
|
|
|
|
#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>
|
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:
|
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);
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
void registerAction(QAction *action, MenuLocation menu_location, ToolbarLocation toolbar_location);
|
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;
|
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
|
|
|
|
|
|
|
|
|
|
ModuleActionMap m_moduleActions;
|
2018-12-30 15:46:15 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-12-31 15:20:55 +01:00
|
|
|
|
template <typename T>
|
|
|
|
|
|
std::shared_ptr<PluginModule> createPluginModule(QString name, QString ident)
|
|
|
|
|
|
{
|
|
|
|
|
|
auto module = std::make_shared<T>(std::move(name), std::move(ident));
|
|
|
|
|
|
module->init();
|
|
|
|
|
|
|
|
|
|
|
|
PluginRegister::getInstance()->registerModule(module);
|
|
|
|
|
|
return std::move(module);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-12-30 15:46:15 +01:00
|
|
|
|
#endif // PLUGIN_SUPPORTPLUGINMODULE_H
|