Context actions have become normal actions in the pluginwidget so the widget knows abot them and can easily do things like enable/disable.
74 lines
2 KiB
C++
74 lines
2 KiB
C++
#include "PluginContentWidgetContextBase.h"
|
|
#include "PluginContentWidget.h"
|
|
#include "PluginModule.h"
|
|
#include "PluginRegister.h"
|
|
#include <QAction>
|
|
#include <QDebug>
|
|
#include <QToolBar>
|
|
#include <vector>
|
|
|
|
|
|
|
|
LWidgetData::LWidgetData(PluginModule *module)
|
|
: m_module(module)
|
|
{}
|
|
|
|
void LWidgetData::init(PluginContentWidget *widget)
|
|
{
|
|
}
|
|
|
|
|
|
PluginContentWidgetContextBase::PluginContentWidgetContextBase() = default;
|
|
|
|
void PluginContentWidgetContextBase::moduleAction(
|
|
const QString &module_identifier,
|
|
QString module_action,
|
|
const ModuleActionParameters &action_params
|
|
)
|
|
{
|
|
auto reg = PluginRegister::getInstance();
|
|
auto mod = reg->findModule(module_identifier);
|
|
if (mod) {
|
|
auto action = mod->findModuleAction(module_action);
|
|
if (action) {
|
|
qDebug() << QString("module %1 action %2 called ").arg(module_identifier, module_action);
|
|
(*action)(this, action_params);
|
|
}
|
|
else
|
|
qWarning() << QString("module %1 has no action %2").arg(module_identifier, module_action);
|
|
}
|
|
else
|
|
qWarning() << QString("module not found %1").arg(module_identifier);
|
|
}
|
|
|
|
void PluginContentWidgetContextBase::addContentWidget(PluginModule *module, PluginContentWidget *widget)
|
|
{
|
|
auto res = m_widgetLst.emplace(widget, module);
|
|
if (!res.second)
|
|
throw std::runtime_error("Unexpected conflicting key on insertiong PluginContentWidgetContextBase::addContentWidget");
|
|
|
|
res.first->second.init(widget);
|
|
}
|
|
|
|
void PluginContentWidgetContextBase::removeContentWidget(PluginContentWidget *widget)
|
|
{
|
|
auto res = m_widgetLst.find(widget);
|
|
if (res == m_widgetLst.end())
|
|
return;
|
|
|
|
m_widgetLst.erase(res);
|
|
}
|
|
|
|
void PluginContentWidgetContextBase::addWidgetActionsToToolbar(PluginContentWidget *widget, QToolBar *toolbar)
|
|
{
|
|
auto && actions = widget->actions();
|
|
toolbar->addActions(actions);
|
|
}
|
|
|
|
void PluginContentWidgetContextBase::removeWidgetActionsFromToolbar(PluginContentWidget *widget, QToolBar *toolbar)
|
|
{
|
|
auto && actions = widget->actions();
|
|
for (auto && ac : actions)
|
|
toolbar->removeAction(ac);
|
|
|
|
}
|