blob: f74de6422cd3695e282ed1f430098c58c9ca80f8 (
plain)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
#pragma once
// this is to avoid dealing with QMetaObject for the time being -sh 20190203
#include "export.hpp"
namespace options { class slider_value; }
#include <QObject>
#include <QList>
namespace _qt_sig_impl {
template<typename t> struct sig;
class OTR_COMPAT_EXPORT sig_void final : public QObject
{
Q_OBJECT
public:
template<typename t, typename F>
sig_void(t* datum, F&& f, Qt::ConnectionType conntype = Qt::AutoConnection) : QObject(datum)
{
connect(this, &sig_void::notify, datum, f, conntype);
}
explicit sig_void(QObject* parent = nullptr);
void operator()() const { notify(); }
signals:
void notify() const;
};
template<> struct sig<void> { using t = sig_void; };
#ifndef OTR_GENERATE_SIGNAL3
# define OTR_GENERATE_SIGNAL3(x)
#endif
#define OTR_GENERATE_SIGNAL2(type) \
class OTR_COMPAT_EXPORT sig_##type final : public QObject \
{ \
Q_OBJECT \
public: \
explicit sig_##type(QObject* parent = nullptr) : QObject(parent) {} \
void operator()(const type& x) const; \
Q_SIGNALS: \
void notify(const type& x) const; \
}; \
OTR_GENERATE_SIGNAL3(type)
# define OTR_GENERATE_SIGNAL(type) \
OTR_GENERATE_SIGNAL2(type); \
using qlist##type = QList<type>; \
OTR_GENERATE_SIGNAL2(qlist##type); \
template<> struct sig<type> { using t = sig_##type; }; \
template<> struct sig<qlist##type> { using t = qlist##type; }
using slider_value = options::slider_value;
OTR_GENERATE_SIGNAL(int);
OTR_GENERATE_SIGNAL(double);
OTR_GENERATE_SIGNAL(float);
OTR_GENERATE_SIGNAL(bool);
OTR_GENERATE_SIGNAL(QString);
OTR_GENERATE_SIGNAL(slider_value);
OTR_GENERATE_SIGNAL(QPointF);
OTR_GENERATE_SIGNAL(QVariant);
} // namespace _qt_sig_impl
#undef OTR_GENERATE_SIGNAL2
#undef OTR_GENERATE_SIGNAL
template<typename t> using qt_signal = typename _qt_sig_impl::sig<t>::t;
|