From 13ff773a47552e9dac2d57ba810e01ebcaa64b53 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 28 Apr 2018 00:28:18 +0200 Subject: options/qt: cleanup metatype definition Also note Koenig lookup works --- options/defs.hpp | 38 ++++++++++++++++++++++++++++++++++++++ options/metatype.cpp | 30 +++++++++--------------------- options/metatype.hpp | 20 -------------------- options/slider.cpp | 6 +----- options/slider.hpp | 15 +++++---------- options/tie.hpp | 2 +- 6 files changed, 54 insertions(+), 57 deletions(-) (limited to 'options') diff --git a/options/defs.hpp b/options/defs.hpp index f093a22a..feaad005 100644 --- a/options/defs.hpp +++ b/options/defs.hpp @@ -1,7 +1,45 @@ #pragma once #include +#include #define OPENTRACK_CONFIG_FILENAME_KEY "settings-filename" #define OPENTRACK_DEFAULT_CONFIG "default.ini" #define OPENTRACK_DEFAULT_CONFIG_Q QStringLiteral("default.ini") +#define OTR_OPTIONS_EXPAND2(x) x +#define OTR_OPTIONS_EXPAND1(x) OTR_OPTIONS_EXPAND2(x) + +#define OPENTRACK_REGISTER_METATYPE2(t, ctr) \ + OPENTRACK_REGISTER_METATYPE3(t, ctr) + +#define OPENTRACK_REGISTER_METATYPE3(t, sym) \ + OPENTRACK_REGISTER_METATYPE4(t, init_metatype_ ## sym) + +#define OPENTRACK_REGISTER_METATYPE4(t, sym) \ + class sym { \ + static const int dribble; \ + } sym ## _singleton; \ + const int sym :: dribble = ::options::detail::custom_type_initializer::declare_for_type(#t) + +#if defined Q_CREATOR_RUN +# define OPENTRACK_DEFINE_METATYPE(t) +#else +# define OPENTRACK_DEFINE_METATYPE(t) OPENTRACK_REGISTER_METATYPE2(t, OTR_OPTIONS_EXPAND1(__COUNTER__)) +#endif + +namespace options { +namespace detail { + +struct custom_type_initializer final +{ + template static int declare_for_type(const char* str) + { + qRegisterMetaType(str); + qRegisterMetaTypeStreamOperators(); + + return -1; + } +}; + +} // ns options::detail +} // ns options diff --git a/options/metatype.cpp b/options/metatype.cpp index ed12821b..ddfdcef9 100644 --- a/options/metatype.cpp +++ b/options/metatype.cpp @@ -1,22 +1,10 @@ #include "metatype.hpp" - -#define OPENTRACK_REGISTER_METATYPE(t) ::options::detail::custom_type_initializer::declare_for_type(#t) - -namespace options { -namespace detail { - -custom_type_initializer::custom_type_initializer() -{ - OPENTRACK_REGISTER_METATYPE(options::slider_value); - OPENTRACK_REGISTER_METATYPE(QList); - OPENTRACK_REGISTER_METATYPE(QList); - OPENTRACK_REGISTER_METATYPE(QList); - OPENTRACK_REGISTER_METATYPE(QList); - OPENTRACK_REGISTER_METATYPE(QList); - OPENTRACK_REGISTER_METATYPE(QList); -} - -const custom_type_initializer custom_type_initializer::singleton; - -} -} +#include "defs.hpp" + +OPENTRACK_DEFINE_METATYPE(::options::slider_value); +OPENTRACK_DEFINE_METATYPE(QList); +OPENTRACK_DEFINE_METATYPE(QList); +OPENTRACK_DEFINE_METATYPE(QList); +OPENTRACK_DEFINE_METATYPE(QList); +OPENTRACK_DEFINE_METATYPE(QList); +OPENTRACK_DEFINE_METATYPE(QList); diff --git a/options/metatype.hpp b/options/metatype.hpp index c889766a..0c78f556 100644 --- a/options/metatype.hpp +++ b/options/metatype.hpp @@ -1,13 +1,10 @@ #pragma once -#include #include #include #include -#include #include -#include "export.hpp" #include "slider.hpp" Q_DECLARE_METATYPE(QList) @@ -18,21 +15,4 @@ Q_DECLARE_METATYPE(QList) Q_DECLARE_METATYPE(QList) Q_DECLARE_METATYPE(::options::slider_value) -namespace options { -namespace detail { -struct custom_type_initializer final -{ - static const custom_type_initializer singleton; - - custom_type_initializer(); - - template static void declare_for_type(const char* str) - { - qRegisterMetaType(str); - qRegisterMetaTypeStreamOperators(); - } -}; - -} -} diff --git a/options/slider.cpp b/options/slider.cpp index 33000ee9..5c73d867 100644 --- a/options/slider.cpp +++ b/options/slider.cpp @@ -86,10 +86,6 @@ int slider_value::to_slider_pos(int q_min, int q_max) const return int(std::round(((cur() - min()) * q_diff / div) + q_min)); } -} // end ns options - -QT_BEGIN_NAMESPACE - QDataStream& operator << (QDataStream& out, const options::slider_value& v) { out << v.cur() @@ -111,4 +107,4 @@ QDataStream& operator >> (QDataStream& in, options::slider_value& v) return in; } -QT_END_NAMESPACE +} // end ns options diff --git a/options/slider.hpp b/options/slider.hpp index f3ba44f8..7570ace0 100644 --- a/options/slider.hpp +++ b/options/slider.hpp @@ -10,8 +10,8 @@ #include "export.hpp" #include "compat/macros.hpp" -#include #include +#include #include namespace options @@ -49,13 +49,8 @@ namespace options slider_value update_from_slider(int pos, int q_min, int q_max) const; int to_slider_pos(int q_min, int q_max) const; }; -} - -QT_BEGIN_NAMESPACE - -QDebug operator << (QDebug dbg, const options::slider_value& val); -QDataStream& operator << (QDataStream& out, const options::slider_value& v); -QDataStream& operator >> (QDataStream& in, options::slider_value& v); - -QT_END_NAMESPACE + QDebug operator << (QDebug dbg, const options::slider_value& val); + QDataStream& operator << (QDataStream& out, const options::slider_value& v); + QDataStream& operator >> (QDataStream& in, options::slider_value& v); +} diff --git a/options/tie.hpp b/options/tie.hpp index 014dc84d..307f5930 100644 --- a/options/tie.hpp +++ b/options/tie.hpp @@ -67,7 +67,7 @@ struct tie_setting_traits>> : tie_setting_ } }; -} // ns options::details +} // ns options::detail template> std::enable_if_t -- cgit v1.2.3