pgLab/pglab/plugin_support/PluginRegister.cpp
eelke dc8a052544 Basic concept of MenuAction is working
Module can register action
Window adds this action to its menu
Clicking the menu item for the action has the expected result
But menu structure still needs work (everything is now put into one dropdown menu)
2019-01-01 11:15:16 +01:00

44 lines
1 KiB
C++

#include "PluginRegister.h"
#include "plugin_support/PluginModule.h"
#include <QDebug>
PluginRegister* PluginRegister::s_pluginRegister;
PluginRegister* PluginRegister::getInstance()
{
static std::mutex m;
// check if set without locking first (in most cases it will be set and it will never be unset) so locking the mutex everytime
// is a waist of time.
if (!s_pluginRegister) {
// not set then lock
std::lock_guard<std::mutex> guard(m);
// recheck in case someone else just set it
if (!s_pluginRegister) {
s_pluginRegister = new PluginRegister;
}
}
return s_pluginRegister;
}
PluginRegister::PluginRegister() = default;
void PluginRegister::initModules()
{
for (auto && mod : m_moduleMap) {
mod.second->init();
}
}
void PluginRegister::registerModule(PluginModuleSPtr module)
{
m_moduleMap.emplace(module->identifier(), module);
}
const PluginModule* PluginRegister::findModule(const QString &module_ident) const
{
auto res = m_moduleMap.find(module_ident);
if (res == m_moduleMap.end())
return nullptr;
return res->second.get();
}