Work on plugin mechanism
Context actions have become normal actions in the pluginwidget so the widget knows abot them and can easily do things like enable/disable.
This commit is contained in:
parent
eca8841427
commit
a704332342
24 changed files with 239 additions and 267 deletions
|
|
@ -2,7 +2,6 @@
|
|||
#include "PluginContentWidget.h"
|
||||
#include "PluginModule.h"
|
||||
#include "PluginRegister.h"
|
||||
#include "LContextAction.h"
|
||||
#include <QAction>
|
||||
#include <QDebug>
|
||||
#include <QToolBar>
|
||||
|
|
@ -16,28 +15,8 @@ LWidgetData::LWidgetData(PluginModule *module)
|
|||
|
||||
void LWidgetData::init(PluginContentWidget *widget)
|
||||
{
|
||||
auto&& widget_actions = m_module->contextActions();
|
||||
m_widgetActions.reserve(widget_actions.size());
|
||||
for (auto&& wa : widget_actions) {
|
||||
m_widgetActions.push_back(createAction(wa, widget));
|
||||
}
|
||||
}
|
||||
|
||||
QList<QAction *> LWidgetData::actions()
|
||||
{
|
||||
return m_widgetActions;
|
||||
}
|
||||
|
||||
QAction *LWidgetData::createAction(const LContextAction &wa, PluginContentWidget *widget)
|
||||
{
|
||||
auto ac = new QAction(wa.icon(), wa.text(), widget);
|
||||
ac->setShortcut(wa.shortcut());
|
||||
ac->setToolTip(wa.toolTip());
|
||||
QObject::connect(ac, SIGNAL(triggered()), widget, wa.slotName());
|
||||
return ac;
|
||||
}
|
||||
|
||||
|
||||
|
||||
PluginContentWidgetContextBase::PluginContentWidgetContextBase() = default;
|
||||
|
||||
|
|
@ -82,21 +61,13 @@ void PluginContentWidgetContextBase::removeContentWidget(PluginContentWidget *wi
|
|||
|
||||
void PluginContentWidgetContextBase::addWidgetActionsToToolbar(PluginContentWidget *widget, QToolBar *toolbar)
|
||||
{
|
||||
auto res = m_widgetLst.find(widget);
|
||||
if (res == m_widgetLst.end())
|
||||
return;
|
||||
|
||||
auto && actions = res->second.actions();
|
||||
auto && actions = widget->actions();
|
||||
toolbar->addActions(actions);
|
||||
}
|
||||
|
||||
void PluginContentWidgetContextBase::removeWidgetActionsFromToolbar(PluginContentWidget *widget, QToolBar *toolbar)
|
||||
{
|
||||
auto res = m_widgetLst.find(widget);
|
||||
if (res == m_widgetLst.end())
|
||||
return;
|
||||
|
||||
auto && actions = res->second.actions();
|
||||
auto && actions = widget->actions();
|
||||
for (auto && ac : actions)
|
||||
toolbar->removeAction(ac);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue