summaryrefslogtreecommitdiffhomepage
path: root/options/base-value.hpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2017-05-12 15:44:05 +0200
committerStanislaw Halik <sthalik@misaki.pl>2017-05-12 15:48:16 +0200
commitf7ab2dc5a54c573cd7408a68cb1e93174827719e (patch)
tree683e3cda0a007f39ac97605850af94939d66bade /options/base-value.hpp
parent4c4c783d023cf1bb6a8d7d883bf8d3384f7b7da1 (diff)
options: split up value.hpp header
Also combine the traits classes and make them more useful.
Diffstat (limited to 'options/base-value.hpp')
-rw-r--r--options/base-value.hpp85
1 files changed, 85 insertions, 0 deletions
diff --git a/options/base-value.hpp b/options/base-value.hpp
new file mode 100644
index 00000000..4f90e3fc
--- /dev/null
+++ b/options/base-value.hpp
@@ -0,0 +1,85 @@
+#pragma once
+
+#include "bundle.hpp"
+#include "slider.hpp"
+#include "connector.hpp"
+
+#include "export.hpp"
+
+#include <QObject>
+#include <QString>
+#include <QList>
+#include <QPointF>
+#include <QVariant>
+
+#include <typeindex>
+
+#define OPENTRACK_DEFINE_SLOT(t) void setValue(t datum) { store(datum); }
+#define OPENTRACK_DEFINE_SIGNAL(t) void valueChanged(t) const
+
+namespace options {
+
+class OTR_OPTIONS_EXPORT base_value : public QObject
+{
+ Q_OBJECT
+ friend class detail::connector;
+
+ using comparator = bool(*)(const QVariant& val1, const QVariant& val2);
+public:
+ QString name() const { return self_name; }
+ base_value(bundle b, const QString& name, comparator cmp, std::type_index type_idx);
+ ~base_value() override;
+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>&);
+protected:
+ bundle b;
+ QString self_name;
+ comparator cmp;
+ std::type_index type_index;
+
+ void store(const QVariant& datum);
+
+ template<typename t>
+ void store(const t& datum)
+ {
+ b->store_kv(self_name, QVariant::fromValue(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>&)
+
+ virtual void reload() = 0;
+ virtual void bundle_value_changed() const = 0;
+ virtual void set_to_default() = 0;
+};
+
+} //ns options