pgLab/pglab/plugin_support/PluginContentWidgetContextBase.h
eelke 601d071d0f 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.
2019-08-14 09:06:48 +02:00

79 lines
2.1 KiB
C++

#ifndef PLUGINCONTENTWIDGETCONTEXTBASE_H
#define PLUGINCONTENTWIDGETCONTEXTBASE_H
#include "plugin_support/IPluginContentWidgetContext.h"
#include <QList>
#include <typeindex>
class LContextAction;
class QToolBar;
class QAction;
class QMenuBar;
/// Maintains the list of actions added to a toolbar for a specific widget
/// it facilitates the removal of all those actions.
class WidgetToolbarActionList {
public:
QToolBar *m_toolBar;
std::vector<QAction*> m_actions;
void removeAll()
{
// for (auto && a : m_actions)
// m_toolBar->removeAction(a);
}
};
class WidgetToolbarManager {
public:
void addAction(QAction *action, QString section);
private:
};
class LWidgetData {
public:
LWidgetData(PluginModule *module, PluginContentWidget *widget);
PluginModule* module() { return m_module; }
PluginContentWidget *widget() { return m_widget; }
void init();
void addToMenu(QMenuBar* menubar);
void removeFromMenu(QMenuBar* menubar);
private:
PluginModule *m_module;
PluginContentWidget *m_widget;
WidgetToolbarManager m_toolbarManager;
std::vector<QAction*> m_menuActions; ///< List of actions we put in the menu
};
/// Provides base implementation of IPluginContentWidgetContext
class PluginContentWidgetContextBase : public IPluginContentWidgetContext
{
public:
PluginContentWidgetContextBase();
void moduleAction(
const QString &module_identifier,
QString module_action,
const ModuleActionParameters &action_params
) override;
void addContentWidget(PluginContentWidget *widget) override;
void removeContentWidget(PluginContentWidget *widget) override;
void addWidgetActionsToToolbar(PluginContentWidget *widget, QToolBar *toolbar);
void removeWidgetActionsFromToolbar(PluginContentWidget *widget, QToolBar *toolbar);
void addContextActionsToMenu(PluginContentWidget *widget, QMenuBar *menubar);
void removeContextActionsFromMenu(PluginContentWidget *widget, QMenuBar *menubar);
private:
using WidgetLst = std::map<PluginContentWidget*, LWidgetData>;
WidgetLst m_widgetLst; /// Keeps track of which widget belongs to which module
};
#endif // PLUGINCONTENTWIDGETCONTEXTBASE_H