summaryrefslogtreecommitdiffhomepage
path: root/options/base-value.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'options/base-value.hpp')
-rw-r--r--options/base-value.hpp82
1 files changed, 42 insertions, 40 deletions
diff --git a/options/base-value.hpp b/options/base-value.hpp
index 5b924ab3..750f93f1 100644
--- a/options/base-value.hpp
+++ b/options/base-value.hpp
@@ -7,6 +7,7 @@
#include "export.hpp"
#include "compat/macros.hpp"
+#include "value-traits.hpp"
#include <QObject>
#include <QString>
@@ -15,9 +16,10 @@
#include <QVariant>
#include <typeindex>
+#include <utility>
-#define OPENTRACK_DEFINE_SLOT(t) void setValue(t datum) { store(datum); }
-#define OPENTRACK_DEFINE_SIGNAL(t) void valueChanged(t) const
+#define OTR_OPTIONS_SLOT(t) void setValue(t datum) { store_(datum); }
+#define OTR_OPTIONS_SIGNAL(t) void valueChanged(t) const
namespace options {
@@ -32,15 +34,13 @@ class OTR_OPTIONS_EXPORT value_ : public QObject
using signal_sig = void(value_::*)(cv_qualified<t>) const;
public:
- bundle get_bundle() { return b; }
QString name() const { return self_name; }
- value_(bundle b, const QString& name, comparator cmp, std::type_index type_idx);
+ value_(bundle const& b, const QString& name, comparator cmp, std::type_index type_idx);
~value_() override;
- // MSVC has ODR problems in 15.4
// no C++17 "constexpr inline" for data declarations in MSVC
template<typename t>
- constexpr static auto value_changed()
+ static constexpr auto value_changed()
{
return static_cast<signal_sig<t>>(&value_::valueChanged);
}
@@ -48,22 +48,22 @@ public:
void notify() const;
signals:
- OPENTRACK_DEFINE_SIGNAL(double);
- OPENTRACK_DEFINE_SIGNAL(float);
- OPENTRACK_DEFINE_SIGNAL(int);
- OPENTRACK_DEFINE_SIGNAL(bool);
- OPENTRACK_DEFINE_SIGNAL(const QString&);
- OPENTRACK_DEFINE_SIGNAL(const slider_value&);
- OPENTRACK_DEFINE_SIGNAL(const QPointF&);
- OPENTRACK_DEFINE_SIGNAL(const QVariant&);
-
- OPENTRACK_DEFINE_SIGNAL(const QList<double>&);
- OPENTRACK_DEFINE_SIGNAL(const QList<float>&);
- OPENTRACK_DEFINE_SIGNAL(const QList<int>&);
- OPENTRACK_DEFINE_SIGNAL(const QList<bool>&);
- OPENTRACK_DEFINE_SIGNAL(const QList<QString>&);
- OPENTRACK_DEFINE_SIGNAL(const QList<slider_value>&);
- OPENTRACK_DEFINE_SIGNAL(const QList<QPointF>&);
+ OTR_OPTIONS_SIGNAL(double);
+ OTR_OPTIONS_SIGNAL(float);
+ OTR_OPTIONS_SIGNAL(int);
+ OTR_OPTIONS_SIGNAL(bool);
+ OTR_OPTIONS_SIGNAL(const QString&);
+ OTR_OPTIONS_SIGNAL(const slider_value&);
+ OTR_OPTIONS_SIGNAL(const QPointF&);
+ OTR_OPTIONS_SIGNAL(const QVariant&);
+
+ OTR_OPTIONS_SIGNAL(const QList<double>&);
+ OTR_OPTIONS_SIGNAL(const QList<float>&);
+ OTR_OPTIONS_SIGNAL(const QList<int>&);
+ OTR_OPTIONS_SIGNAL(const QList<bool>&);
+ OTR_OPTIONS_SIGNAL(const QList<QString>&);
+ OTR_OPTIONS_SIGNAL(const QList<slider_value>&);
+ OTR_OPTIONS_SIGNAL(const QList<QPointF>&);
protected:
bundle b;
@@ -71,30 +71,32 @@ protected:
comparator cmp;
std::type_index type_index;
- void store(const QVariant& datum);
+ virtual void store_variant(const QVariant& x) = 0;
template<typename t>
- void store(const t& datum)
+ void store_(const t& datum)
{
- b->store_kv(self_name, QVariant::fromValue(datum));
+ using traits = detail::value_traits<t>;
+ using stored_type = typename traits::stored_type;
+ store_variant(QVariant::fromValue<stored_type>(datum));
}
public slots:
- OPENTRACK_DEFINE_SLOT(double)
- OPENTRACK_DEFINE_SLOT(int)
- OPENTRACK_DEFINE_SLOT(bool)
- OPENTRACK_DEFINE_SLOT(const QString&)
- OPENTRACK_DEFINE_SLOT(const slider_value&)
- OPENTRACK_DEFINE_SLOT(const QPointF&)
- OPENTRACK_DEFINE_SLOT(const QVariant&)
-
- OPENTRACK_DEFINE_SLOT(const QList<double>&)
- OPENTRACK_DEFINE_SLOT(const QList<float>&)
- OPENTRACK_DEFINE_SLOT(const QList<int>&)
- OPENTRACK_DEFINE_SLOT(const QList<bool>&)
- OPENTRACK_DEFINE_SLOT(const QList<QString>&)
- OPENTRACK_DEFINE_SLOT(const QList<slider_value>&)
- OPENTRACK_DEFINE_SLOT(const QList<QPointF>&)
+ OTR_OPTIONS_SLOT(double)
+ OTR_OPTIONS_SLOT(int)
+ OTR_OPTIONS_SLOT(bool)
+ OTR_OPTIONS_SLOT(const QString&)
+ OTR_OPTIONS_SLOT(const slider_value&)
+ OTR_OPTIONS_SLOT(const QPointF&)
+ OTR_OPTIONS_SLOT(const QVariant&)
+
+ OTR_OPTIONS_SLOT(const QList<double>&)
+ OTR_OPTIONS_SLOT(const QList<float>&)
+ OTR_OPTIONS_SLOT(const QList<int>&)
+ OTR_OPTIONS_SLOT(const QList<bool>&)
+ OTR_OPTIONS_SLOT(const QList<QString>&)
+ OTR_OPTIONS_SLOT(const QList<slider_value>&)
+ OTR_OPTIONS_SLOT(const QList<QPointF>&)
virtual void reload() = 0;
virtual void bundle_value_changed() const = 0;