Loading...
Searching...
No Matches
LayerContextMenu.hpp
1#pragma once
2#include <score/plugins/StringFactoryKey.hpp>
3#include <score/tools/Debug.hpp>
4#include <score/tools/std/HashMap.hpp>
5
6#include <QPoint>
7#include <QPointF>
8
9#include <score_lib_process_export.h>
10
11#include <functional>
12class QMenu;
13
14namespace Process
15{
16template <typename T>
18struct LayerContext;
19
20using ContextMenuFun
21 = std::function<void(QMenu&, QPoint, QPointF, const Process::LayerContext&)>;
22class SCORE_LIB_PROCESS_EXPORT LayerContextMenu
23{
24public:
26
27 StringKey<LayerContextMenu> key() const { return m_key; }
28
29 std::vector<ContextMenuFun> functions;
30
31 void build(QMenu& m, QPoint pt, QPointF ptf, const Process::LayerContext& proc) const;
32
33private:
35};
36
37class SCORE_LIB_PROCESS_EXPORT LayerContextMenuManager
38{
39public:
40 void insert(LayerContextMenu val)
41 {
42 SCORE_ASSERT(m_container.find(val.key()) == m_container.end());
43 m_container.insert(std::make_pair(val.key(), std::move(val)));
44 }
45
46 template <typename T>
47 LayerContextMenu& menu()
48 {
49 using meta_t = MetaContextMenu<T>;
50 SCORE_ASSERT(m_container.find(meta_t::static_key()) != m_container.end());
51 return m_container.find(meta_t::static_key())->second;
52 }
53
54 template <typename T>
55 const LayerContextMenu& menu() const
56 {
57 using meta_t = MetaContextMenu<T>;
58 SCORE_ASSERT(m_container.find(meta_t::static_key()) != m_container.end());
59 return m_container.find(meta_t::static_key())->second;
60 }
61
62 auto& get() { return m_container; }
63 auto& get() const { return m_container; }
64
65private:
66 score::hash_map<StringKey<LayerContextMenu>, LayerContextMenu> m_container;
67};
68}
69
70#define SCORE_PROCESS_DECLARE_CONTEXT_MENU(Export, Type) \
71 namespace ContextMenus \
72 { \
73 class Type; \
74 } \
75 namespace Process \
76 { \
77 template <> \
78 class Export MetaContextMenu<ContextMenus::Type> \
79 { \
80 public: \
81 static LayerContextMenu make() \
82 { \
83 return LayerContextMenu{static_key()}; \
84 } \
85 \
86 static StringKey<Process::LayerContextMenu> static_key() \
87 { \
88 return StringKey<Process::LayerContextMenu>{#Type}; \
89 } \
90 }; \
91 }
Definition LayerContextMenu.hpp:23
Definition LayerContextMenu.hpp:38
Definition LayerContextMenu.hpp:17
Definition StringFactoryKey.hpp:8
Base classes and tools to implement processes and layers.
Definition JSONVisitor.hpp:1324
Definition ProcessContext.hpp:21