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
|
|
@ -7,11 +7,20 @@
|
|||
#include <QObject>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#include <typeindex>
|
||||
|
||||
class QAction;
|
||||
class IPluginContentWidgetContext;
|
||||
class PluginContentWidget;
|
||||
|
||||
/** Defines available actions for the application framework.
|
||||
*
|
||||
* There are static and context actions.
|
||||
* There can be multiple contexts which are seperated by there typeid/type_index.
|
||||
*/
|
||||
class PluginModule: public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
|
@ -19,6 +28,8 @@ public:
|
|||
using ModuleAction = std::function<void(IPluginContentWidgetContext*, const ModuleActionParameters &)>;
|
||||
using ModuleActionMap = std::map<QString, ModuleAction>;
|
||||
|
||||
using ContextActionContainer = std::vector<std::shared_ptr<ContextBaseAction>>;
|
||||
|
||||
PluginModule(QString name, QString ident);
|
||||
|
||||
virtual void init() {}
|
||||
|
|
@ -41,7 +52,15 @@ public:
|
|||
/// When the action is not found nullptr is returned.
|
||||
const ModuleAction* findModuleAction(const QString &module_action) const;
|
||||
|
||||
void registerContextAction(std::shared_ptr<ContextBaseAction> action);
|
||||
|
||||
std::set<std::type_index> contextTypeIndexes();
|
||||
const ContextActionContainer& actionsForContext(std::type_index ti);
|
||||
const ContextActionContainer& actionsForContext(PluginContentWidget *widget);
|
||||
|
||||
private:
|
||||
using ContextMap = std::unordered_map<std::type_index, ContextActionContainer>;
|
||||
|
||||
/// Name shown to end users
|
||||
QString m_name;
|
||||
/// Unique identifier
|
||||
|
|
@ -50,6 +69,7 @@ private:
|
|||
|
||||
StaticActionList m_menuActions;
|
||||
ModuleActionMap m_moduleActions;
|
||||
ContextMap m_contextMap;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue