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"
|
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-08-14 09:06:48 +02:00
|
|
|
|
#include <unordered_map>
|
|
|
|
|
|
#include <set>
|
2019-01-01 11:15:16 +01:00
|
|
|
|
#include <vector>
|
2019-08-14 09:06:48 +02:00
|
|
|
|
#include <typeindex>
|
2018-12-30 15:46:15 +01:00
|
|
|
|
|
|
|
|
|
|
class QAction;
|
2018-12-31 15:20:55 +01:00
|
|
|
|
class IPluginContentWidgetContext;
|
2019-08-14 09:06:48 +02:00
|
|
|
|
class PluginContentWidget;
|
2018-12-30 15:46:15 +01:00
|
|
|
|
|
2019-08-14 09:06:48 +02:00
|
|
|
|
/** 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.
|
|
|
|
|
|
*/
|
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>;
|
2018-12-31 15:20:55 +01:00
|
|
|
|
using ModuleAction = std::function<void(IPluginContentWidgetContext*, const ModuleActionParameters &)>;
|
|
|
|
|
|
using ModuleActionMap = std::map<QString, ModuleAction>;
|
|
|
|
|
|
|
2019-08-14 09:06:48 +02:00
|
|
|
|
using ContextActionContainer = std::vector<std::shared_ptr<ContextBaseAction>>;
|
|
|
|
|
|
|
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-08-14 09:06:48 +02:00
|
|
|
|
void registerContextAction(std::shared_ptr<ContextBaseAction> action);
|
|
|
|
|
|
|
|
|
|
|
|
std::set<std::type_index> contextTypeIndexes();
|
|
|
|
|
|
const ContextActionContainer& actionsForContext(std::type_index ti);
|
|
|
|
|
|
const ContextActionContainer& actionsForContext(PluginContentWidget *widget);
|
|
|
|
|
|
|
2018-12-30 15:46:15 +01:00
|
|
|
|
private:
|
2019-08-14 09:06:48 +02:00
|
|
|
|
using ContextMap = std::unordered_map<std::type_index, ContextActionContainer>;
|
|
|
|
|
|
|
2018-12-30 15:46:15 +01:00
|
|
|
|
/// 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-08-14 09:06:48 +02:00
|
|
|
|
ContextMap m_contextMap;
|
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
|