summaryrefslogtreecommitdiffhomepage
path: root/options
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
parentd317b5caaf433ae12907663db3a7e60c5082a0d1 (diff)
options/qt: cleanup metatype definition
Also note Koenig lookup works
Diffstat (limited to 'options')
-rw-r--r--options/defs.hpp38
-rw-r--r--options/metatype.cpp30
-rw-r--r--options/metatype.hpp20
-rw-r--r--options/slider.cpp6
-rw-r--r--options/slider.hpp15
-rw-r--r--options/tie.hpp2
6 files changed, 54 insertions, 57 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
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>(#t)
-
-namespace options {
-namespace detail {
-
-custom_type_initializer::custom_type_initializer()
-{
- OPENTRACK_REGISTER_METATYPE(options::slider_value);
- OPENTRACK_REGISTER_METATYPE(QList<double>);
- OPENTRACK_REGISTER_METATYPE(QList<float>);
- OPENTRACK_REGISTER_METATYPE(QList<int>);
- OPENTRACK_REGISTER_METATYPE(QList<bool>);
- OPENTRACK_REGISTER_METATYPE(QList<QString>);
- OPENTRACK_REGISTER_METATYPE(QList<QPointF>);
-}
-
-const custom_type_initializer custom_type_initializer::singleton;
-
-}
-}
+#include "defs.hpp"
+
+OPENTRACK_DEFINE_METATYPE(::options::slider_value);
+OPENTRACK_DEFINE_METATYPE(QList<double>);
+OPENTRACK_DEFINE_METATYPE(QList<float>);
+OPENTRACK_DEFINE_METATYPE(QList<int>);
+OPENTRACK_DEFINE_METATYPE(QList<bool>);
+OPENTRACK_DEFINE_METATYPE(QList<QString>);
+OPENTRACK_DEFINE_METATYPE(QList<QPointF>);
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 <QMetaType>
#include <QList>
#include <QString>
#include <QPointF>
-#include <QDataStream>
#include <QDebug>
-#include "export.hpp"
#include "slider.hpp"
Q_DECLARE_METATYPE(QList<double>)
@@ -18,21 +15,4 @@ Q_DECLARE_METATYPE(QList<QString>)
Q_DECLARE_METATYPE(QList<QPointF>)
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<typename t> static void declare_for_type(const char* str)
- {
- qRegisterMetaType<t>(str);
- qRegisterMetaTypeStreamOperators<t>();
- }
-};
-
-}
-}
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 <QMetaType>
#include <QDataStream>
+#include <QMetaType>
#include <QDebug>
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<t, std::enable_if_t<std::is_enum_v<t>>> : tie_setting_
}
};
-} // ns options::details
+} // ns options::detail
template<typename t, typename traits_type = detail::tie_setting_traits<t>>
std::enable_if_t<traits_type::should_bind_to_itemdata()>