diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2021-12-17 20:57:48 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2021-12-17 20:57:58 +0100 |
commit | cc9ef300857255d84efef60868448c6765d3ccff (patch) | |
tree | 7cc470b3dc4cc6094a22c8deefcf8af0e0fbda9f | |
parent | face7439282c844897568e7a17d3094102580d38 (diff) |
compat/qt-sig: progress on beating options::value<t> into shape
-rw-r--r-- | compat/qt-signal.cpp | 12 | ||||
-rw-r--r-- | compat/qt-signal.hpp | 67 | ||||
-rw-r--r-- | opentrack/main-window.hpp | 8 |
3 files changed, 64 insertions, 23 deletions
diff --git a/compat/qt-signal.cpp b/compat/qt-signal.cpp index 08aac663..8c23866b 100644 --- a/compat/qt-signal.cpp +++ b/compat/qt-signal.cpp @@ -1,13 +1,7 @@ +#define OTR_GENERATE_SIGNAL3(type) void sig_##type::operator()(const type& x) const { notify(x); } #include "qt-signal.hpp" +namespace _qt_sig_impl { -namespace qt_sig { +sig_void::sig_void(QObject* parent) : QObject(parent) {} -nullary::nullary(QObject* parent) : QObject(parent) {} -nullary::~nullary() = default; - -void nullary::operator()() const -{ - notify(); } - -} // ns qt_sig diff --git a/compat/qt-signal.hpp b/compat/qt-signal.hpp index 119e063c..1b4e94d2 100644 --- a/compat/qt-signal.hpp +++ b/compat/qt-signal.hpp @@ -3,28 +3,75 @@ // 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 { +namespace _qt_sig_impl { -class OTR_COMPAT_EXPORT nullary : public QObject +template<typename t> struct sig; + +class OTR_COMPAT_EXPORT sig_void final : public QObject { Q_OBJECT public: template<typename t, typename F> - nullary(t* datum, F&& f, Qt::ConnectionType conntype = Qt::AutoConnection) : QObject(datum) + sig_void(t* datum, F&& f, Qt::ConnectionType conntype = Qt::AutoConnection) : QObject(datum) { - connect(this, &nullary::notify, datum, f, conntype); + connect(this, &sig_void::notify, datum, f, conntype); } - - nullary(QObject* parent = nullptr); - ~nullary() override; - - void operator()() const; + sig_void(QObject* parent = nullptr); + void operator()() const { notify(); } signals: void notify() const; }; -} // ns qt_sig +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: \ + template<typename t, typename F> \ + sig_##type(t* datum, F&& f, Qt::ConnectionType conntype = Qt::AutoConnection) : QObject(datum) \ + { \ + connect(this, &sig_##type::notify, datum, f, conntype); \ + } \ + 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; + diff --git a/opentrack/main-window.hpp b/opentrack/main-window.hpp index 33398d20..0314c582 100644 --- a/opentrack/main-window.hpp +++ b/opentrack/main-window.hpp @@ -78,10 +78,10 @@ class main_window final : public QMainWindow, private State bool exiting_already { false }; - qt_sig::nullary start_tracker { this, &main_window::start_tracker_, Qt::QueuedConnection }; - qt_sig::nullary stop_tracker { this, &main_window::stop_tracker_, Qt::QueuedConnection }; - qt_sig::nullary toggle_tracker { this, &main_window::toggle_tracker_, Qt::QueuedConnection }; - qt_sig::nullary restart_tracker { this, &main_window::restart_tracker_, Qt::QueuedConnection }; + qt_signal<void> start_tracker { this, &main_window::start_tracker_, Qt::QueuedConnection }; + qt_signal<void> stop_tracker { this, &main_window::stop_tracker_, Qt::QueuedConnection }; + qt_signal<void> toggle_tracker { this, &main_window::toggle_tracker_, Qt::QueuedConnection }; + qt_signal<void> restart_tracker { this, &main_window::restart_tracker_, Qt::QueuedConnection }; public: void init_dylibs(); |