-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenuEntry.h
More file actions
52 lines (40 loc) · 855 Bytes
/
MenuEntry.h
File metadata and controls
52 lines (40 loc) · 855 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#ifndef MENUENTRY_H
#define MENUENTRY_H
#include <QObject>
template<class TInstance>
using Callback = void (TInstance::*)();
class IMenuEntry : public QObject
{
Q_OBJECT
Q_PROPERTY(QString title READ title NOTIFY titleChanged)
public:
virtual QString title() const = 0;
public slots:
virtual void invoke() const = 0;
signals:
void titleChanged();
};
template<class TInstance>
class MenuEntry : public IMenuEntry
{
public:
MenuEntry(const QString &title, TInstance *instance, Callback<TInstance> callback)
{
m_title = title;
m_instance = instance;
m_callback = callback;
}
QString title() const override
{
return m_title;
}
void invoke() const override
{
(m_instance->*m_callback)();
}
private:
QString m_title;
TInstance *m_instance;
Callback<TInstance> m_callback;
};
#endif // MENUENTRY_H