2018-12-30 15:46:15 +01:00
|
|
|
|
#include "plugin_support/PluginModule.h"
|
2019-08-14 09:06:48 +02:00
|
|
|
|
#include "PluginContentWidget.h"
|
2019-01-01 11:15:16 +01:00
|
|
|
|
#include <QDebug>
|
2019-08-14 09:06:48 +02:00
|
|
|
|
#include <typeinfo>
|
|
|
|
|
|
#include <typeindex>
|
2018-12-30 15:46:15 +01:00
|
|
|
|
|
|
|
|
|
|
PluginModule::PluginModule(QString name, QString ident)
|
|
|
|
|
|
: m_name(std::move(name))
|
|
|
|
|
|
, m_ident(std::move(ident))
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PluginModule::setDisplayCategory(QString category)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_displayCategory = std::move(category);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-01-31 19:31:17 +01:00
|
|
|
|
void PluginModule::registerStaticAction(StaticAction action)
|
2018-12-30 15:46:15 +01:00
|
|
|
|
{
|
2019-01-01 11:15:16 +01:00
|
|
|
|
m_menuActions.emplace_back(std::move(action));
|
|
|
|
|
|
}
|
2018-12-30 15:46:15 +01:00
|
|
|
|
|
2019-01-31 19:31:17 +01:00
|
|
|
|
const PluginModule::StaticActionList& PluginModule::staticActions() const
|
2019-01-01 11:15:16 +01:00
|
|
|
|
{
|
|
|
|
|
|
return m_menuActions;
|
2018-12-30 15:46:15 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-31 15:20:55 +01:00
|
|
|
|
void PluginModule::registerModuleAction(QString module_action, ModuleAction action)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_moduleActions.emplace(
|
|
|
|
|
|
std::move(module_action),
|
|
|
|
|
|
std::move(action)
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
2018-12-30 15:46:15 +01:00
|
|
|
|
|
2018-12-31 15:20:55 +01:00
|
|
|
|
const PluginModule::ModuleAction* PluginModule::findModuleAction(const QString &module_action) const
|
|
|
|
|
|
{
|
|
|
|
|
|
auto res = m_moduleActions.find(module_action);
|
|
|
|
|
|
if (res == m_moduleActions.end())
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
return &res->second;
|
|
|
|
|
|
}
|
2019-01-05 19:58:23 +01:00
|
|
|
|
|
2019-08-14 09:06:48 +02:00
|
|
|
|
void PluginModule::registerContextAction(std::shared_ptr<ContextBaseAction> action)
|
|
|
|
|
|
{
|
|
|
|
|
|
auto find_result_iter = m_contextMap.find(action->contextTypeIndex());
|
|
|
|
|
|
if (find_result_iter != m_contextMap.end())
|
|
|
|
|
|
find_result_iter->second.push_back(action);
|
|
|
|
|
|
else
|
|
|
|
|
|
m_contextMap.emplace(action->contextTypeIndex(), ContextActionContainer({ action }));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const PluginModule::ContextActionContainer &PluginModule::actionsForContext(std::type_index ti)
|
|
|
|
|
|
{
|
|
|
|
|
|
static const ContextActionContainer empty_result;
|
|
|
|
|
|
|
|
|
|
|
|
auto find_result_iter = m_contextMap.find(ti);
|
|
|
|
|
|
if (find_result_iter != m_contextMap.end())
|
|
|
|
|
|
return find_result_iter->second;
|
|
|
|
|
|
|
|
|
|
|
|
return empty_result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const PluginModule::ContextActionContainer& PluginModule::actionsForContext(PluginContentWidget *widget)
|
|
|
|
|
|
{
|
|
|
|
|
|
return actionsForContext(std::type_index(typeid(*widget)));
|
|
|
|
|
|
}
|
|
|
|
|
|
|