Proof of concept for having the context actions statically defined in the module.
Needs work for correctly placing the items in menu and on toolbar. Old system still needs to be removed left in place to keep app useable.
This commit is contained in:
parent
7f09d5fe07
commit
601d071d0f
21 changed files with 303 additions and 70 deletions
|
|
@ -4,19 +4,43 @@
|
|||
#include "PluginRegister.h"
|
||||
#include <QAction>
|
||||
#include <QDebug>
|
||||
#include <QMenuBar>
|
||||
#include <QToolBar>
|
||||
#include <vector>
|
||||
|
||||
|
||||
|
||||
LWidgetData::LWidgetData(PluginModule *module)
|
||||
LWidgetData::LWidgetData(PluginModule *module, PluginContentWidget *widget)
|
||||
: m_module(module)
|
||||
, m_widget(widget)
|
||||
{}
|
||||
|
||||
void LWidgetData::init(PluginContentWidget *widget)
|
||||
void LWidgetData::init()
|
||||
{
|
||||
}
|
||||
|
||||
void LWidgetData::addToMenu(QMenuBar *menubar)
|
||||
{
|
||||
auto&& menu = menubar->actions().first()->menu();
|
||||
|
||||
auto ti = std::type_index(typeid(*m_widget));
|
||||
auto&& actions = m_module->actionsForContext(ti);
|
||||
m_menuActions.reserve(actions.size());
|
||||
for (auto&& actiondef : actions) {
|
||||
auto ac = actiondef->createAction(m_widget);
|
||||
menu->addAction(ac);
|
||||
m_menuActions.push_back(ac);
|
||||
}
|
||||
}
|
||||
|
||||
void LWidgetData::removeFromMenu(QMenuBar *menubar)
|
||||
{
|
||||
for (auto&& action : m_menuActions) {
|
||||
delete action;
|
||||
}
|
||||
m_menuActions.clear();
|
||||
}
|
||||
|
||||
|
||||
PluginContentWidgetContextBase::PluginContentWidgetContextBase() = default;
|
||||
|
||||
|
|
@ -41,13 +65,13 @@ void PluginContentWidgetContextBase::moduleAction(
|
|||
qWarning() << QString("module not found %1").arg(module_identifier);
|
||||
}
|
||||
|
||||
void PluginContentWidgetContextBase::addContentWidget(PluginModule *module, PluginContentWidget *widget)
|
||||
void PluginContentWidgetContextBase::addContentWidget(PluginContentWidget *widget)
|
||||
{
|
||||
auto res = m_widgetLst.emplace(widget, module);
|
||||
auto res = m_widgetLst.emplace(widget, LWidgetData{widget->pluginModule(), widget});
|
||||
if (!res.second)
|
||||
throw std::runtime_error("Unexpected conflicting key on insertiong PluginContentWidgetContextBase::addContentWidget");
|
||||
|
||||
res.first->second.init(widget);
|
||||
res.first->second.init();
|
||||
}
|
||||
|
||||
void PluginContentWidgetContextBase::removeContentWidget(PluginContentWidget *widget)
|
||||
|
|
@ -64,6 +88,7 @@ void PluginContentWidgetContextBase::addWidgetActionsToToolbar(PluginContentWidg
|
|||
{
|
||||
auto && actions = widget->actions();
|
||||
toolbar->addActions(actions);
|
||||
|
||||
}
|
||||
|
||||
void PluginContentWidgetContextBase::removeWidgetActionsFromToolbar(PluginContentWidget *widget, QToolBar *toolbar)
|
||||
|
|
@ -73,3 +98,20 @@ void PluginContentWidgetContextBase::removeWidgetActionsFromToolbar(PluginConten
|
|||
toolbar->removeAction(ac);
|
||||
|
||||
}
|
||||
|
||||
void PluginContentWidgetContextBase::addContextActionsToMenu(PluginContentWidget *widget, QMenuBar *menubar)
|
||||
{
|
||||
auto res = m_widgetLst.find(widget);
|
||||
if (res == m_widgetLst.end())
|
||||
return;
|
||||
res->second.addToMenu(menubar);
|
||||
}
|
||||
|
||||
void PluginContentWidgetContextBase::removeContextActionsFromMenu(PluginContentWidget *widget, QMenuBar *menubar)
|
||||
{
|
||||
auto res = m_widgetLst.find(widget);
|
||||
if (res == m_widgetLst.end())
|
||||
return;
|
||||
res->second.removeFromMenu(menubar);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue