diff options
author | Stanisław Halik <sthalik@misaki.pl> | 2017-05-14 16:22:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-14 16:22:09 +0200 |
commit | 5c23666b58bb1dd4aea15c0d62a2f716d5be7f52 (patch) | |
tree | e6497e9b55c073be209ec673ef05e62bf57a2c8f /options/base-value.hpp | |
parent | 4701dd3b0c8323a11cf7d5ad09c579a9864a41bd (diff) | |
parent | c392181211b245e74292424500265323c960c1aa (diff) |
Merge branch 'unstable' into unstable
Diffstat (limited to 'options/base-value.hpp')
-rw-r--r-- | options/base-value.hpp | 85 |
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 |