summaryrefslogtreecommitdiffhomepage
path: root/options/defs.hpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2018-04-28 00:28:18 +0200
committerStanislaw Halik <sthalik@misaki.pl>2018-04-28 00:28:18 +0200
commit13ff773a47552e9dac2d57ba810e01ebcaa64b53 (patch)
tree8f1a2d8d81fee884c5feba83ad6d14f57e20a387 /options/defs.hpp
parentd317b5caaf433ae12907663db3a7e60c5082a0d1 (diff)
options/qt: cleanup metatype definition
Also note Koenig lookup works
Diffstat (limited to 'options/defs.hpp')
-rw-r--r--options/defs.hpp38
1 files changed, 38 insertions, 0 deletions
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 <QString>
+#include <QMetaType>
#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>(#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<typename t> static int declare_for_type(const char* str)
+ {
+ qRegisterMetaType<t>(str);
+ qRegisterMetaTypeStreamOperators<t>();
+
+ return -1;
+ }
+};
+
+} // ns options::detail
+} // ns options