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)
This commit is contained in:
parent
f130c426a1
commit
dc8a052544
12 changed files with 220 additions and 28 deletions
|
|
@ -1,6 +1,62 @@
|
|||
#include "MenuAction.h"
|
||||
#include "MenuAction.h"
|
||||
|
||||
MenuAction::MenuAction()
|
||||
MenuAction::MenuAction(QString text, Func func)
|
||||
: m_text(std::move(text))
|
||||
, m_func(std::move(func))
|
||||
{}
|
||||
|
||||
const QIcon& MenuAction::icon() const
|
||||
{
|
||||
|
||||
return m_icon;
|
||||
}
|
||||
|
||||
const MenuLocation& MenuAction::menuLocation() const
|
||||
{
|
||||
return m_menuLocation;
|
||||
}
|
||||
|
||||
void MenuAction::setIcon(QIcon icon)
|
||||
{
|
||||
m_icon = std::move(icon);
|
||||
}
|
||||
|
||||
void MenuAction::setMenuLocation(MenuLocation menu_location)
|
||||
{
|
||||
m_menuLocation = std::move(menu_location);
|
||||
}
|
||||
|
||||
void MenuAction::setShortCut(QKeySequence shortcut)
|
||||
{
|
||||
m_shortCut = std::move(shortcut);
|
||||
}
|
||||
|
||||
void MenuAction::setText(QString text)
|
||||
{
|
||||
m_text = std::move(text);
|
||||
}
|
||||
|
||||
void MenuAction::setToolTip(QString tooltip)
|
||||
{
|
||||
m_toolTip = std::move(tooltip);
|
||||
}
|
||||
|
||||
const QKeySequence& MenuAction::shortCut() const
|
||||
{
|
||||
return m_shortCut;
|
||||
}
|
||||
|
||||
const QString& MenuAction::text() const
|
||||
{
|
||||
return m_text;
|
||||
}
|
||||
|
||||
const QString& MenuAction::toolTip() const
|
||||
{
|
||||
return m_toolTip;
|
||||
}
|
||||
|
||||
void MenuAction::perform(IPluginContentWidgetContext *context) const
|
||||
{
|
||||
if (m_func)
|
||||
m_func(context);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,49 @@
|
|||
#ifndef MENUACTION_H
|
||||
#ifndef MENUACTION_H
|
||||
#define MENUACTION_H
|
||||
|
||||
#include "MenuLocation.h"
|
||||
#include "ToolbarLocation.h"
|
||||
|
||||
class MenuAction
|
||||
{
|
||||
#include <QIcon>
|
||||
#include <QKeySequence>
|
||||
#include <QString>
|
||||
#include <functional>
|
||||
|
||||
class QAction;
|
||||
class IPluginContentWidgetContext;
|
||||
|
||||
/** An action for in a menu or toolbar that does not pertain to a specific
|
||||
* widget. It often will create a widget for instance a New or Open action.
|
||||
* It does need a context.
|
||||
*
|
||||
*/
|
||||
class MenuAction {
|
||||
public:
|
||||
MenuAction();
|
||||
using Func = std::function<void(IPluginContentWidgetContext *context)>;
|
||||
|
||||
MenuAction(QString text, Func func);
|
||||
|
||||
const QIcon& icon() const;
|
||||
const MenuLocation& menuLocation() const;
|
||||
void setIcon(QIcon icon);
|
||||
void setMenuLocation(MenuLocation menu_location);
|
||||
void setShortCut(QKeySequence shortcut);
|
||||
void setText(QString text);
|
||||
void setToolTip(QString tooltip);
|
||||
const QKeySequence& shortCut() const;
|
||||
const QString& text() const;
|
||||
const QString& toolTip() const;
|
||||
|
||||
void perform(IPluginContentWidgetContext *context) const;
|
||||
private:
|
||||
QString m_text;
|
||||
QString m_toolTip;
|
||||
QIcon m_icon;
|
||||
QKeySequence m_shortCut;
|
||||
MenuLocation m_menuLocation;
|
||||
|
||||
Func m_func;
|
||||
};
|
||||
|
||||
#endif // MENUACTION_H
|
||||
|
||||
#endif // MENUACTION_H
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include "plugin_support/PluginModule.h"
|
||||
#include <QDebug>
|
||||
|
||||
PluginModule::PluginModule(QString name, QString ident)
|
||||
: m_name(std::move(name))
|
||||
|
|
@ -11,9 +12,15 @@ void PluginModule::setDisplayCategory(QString category)
|
|||
m_displayCategory = std::move(category);
|
||||
}
|
||||
|
||||
void PluginModule::registerAction(QAction *action, MenuLocation menu_location, ToolbarLocation toolbar_location)
|
||||
void PluginModule::registerMenuAction(MenuAction action)
|
||||
{
|
||||
qDebug() << "registerMenuAction " << action.text();
|
||||
m_menuActions.emplace_back(std::move(action));
|
||||
}
|
||||
|
||||
const PluginModule::MenuActionList& PluginModule::menuActions() const
|
||||
{
|
||||
return m_menuActions;
|
||||
}
|
||||
|
||||
void PluginModule::registerModuleAction(QString module_action, ModuleAction action)
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
#ifndef PLUGIN_SUPPORTPLUGINMODULE_H
|
||||
#define PLUGIN_SUPPORTPLUGINMODULE_H
|
||||
|
||||
#include "MenuLocation.h"
|
||||
#include "ToolbarLocation.h"
|
||||
#include "ModuleActionParameters.h"
|
||||
#include "MenuAction.h"
|
||||
#include "PluginRegister.h"
|
||||
#include <QObject>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
class QAction;
|
||||
class IPluginContentWidgetContext;
|
||||
|
|
@ -15,17 +15,23 @@ class IPluginContentWidgetContext;
|
|||
class PluginModule: public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
using MenuActionList = std::vector<MenuAction>;
|
||||
using ModuleAction = std::function<void(IPluginContentWidgetContext*, const ModuleActionParameters &)>;
|
||||
using ModuleActionMap = std::map<QString, ModuleAction>;
|
||||
|
||||
PluginModule(QString name, QString ident);
|
||||
|
||||
virtual void init() {};
|
||||
|
||||
const QString& name() const { return m_name; }
|
||||
const QString& identifier() const { return m_ident; }
|
||||
const QString& displayCategory() const { return m_displayCategory; }
|
||||
|
||||
void setDisplayCategory(QString category);
|
||||
void registerAction(QAction *action, MenuLocation menu_location, ToolbarLocation toolbar_location);
|
||||
|
||||
/// registers an action that should always be accessible from the menu
|
||||
void registerMenuAction(MenuAction action);
|
||||
const MenuActionList& menuActions() const;
|
||||
|
||||
void registerModuleAction(QString module_action, ModuleAction action);
|
||||
|
||||
|
|
@ -39,6 +45,7 @@ private:
|
|||
QString m_ident;
|
||||
QString m_displayCategory;
|
||||
|
||||
MenuActionList m_menuActions;
|
||||
ModuleActionMap m_moduleActions;
|
||||
};
|
||||
|
||||
|
|
@ -47,7 +54,6 @@ template <typename T>
|
|||
std::shared_ptr<PluginModule> createPluginModule(QString name, QString ident)
|
||||
{
|
||||
auto module = std::make_shared<T>(std::move(name), std::move(ident));
|
||||
module->init();
|
||||
|
||||
PluginRegister::getInstance()->registerModule(module);
|
||||
return std::move(module);
|
||||
|
|
|
|||
|
|
@ -23,6 +23,13 @@ PluginRegister* PluginRegister::getInstance()
|
|||
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -18,7 +18,9 @@ public:
|
|||
|
||||
PluginRegister();
|
||||
void registerModule(PluginModuleSPtr module);
|
||||
const ModuleMap& modules() const { return m_moduleMap; }
|
||||
|
||||
void initModules();
|
||||
const ModuleMap& modules() const{ return m_moduleMap; }
|
||||
|
||||
const PluginModule* findModule(const QString &module_ident) const;
|
||||
private:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue