summaryrefslogtreecommitdiffhomepage
path: root/options/base-value.hpp
blob: 6a4709ee17c0d4786449a4a6ed61d937d34d1144 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#pragma once

#include "bundle.hpp"
#include "slider.hpp"
#include "connector.hpp"
#include "metatype.hpp"

#include "export.hpp"
#include "compat/macros.hpp"
#include "value-traits.hpp"

#include <QObject>
#include <QString>
#include <QList>
#include <QPointF>
#include <QVariant>

#include <utility>

#define OTR_OPTIONS_SLOT(t) void setValue(t datum) { store_(datum); }
#define OTR_OPTIONS_SIGNAL(t) void valueChanged(t) const

namespace options {

class OTR_OPTIONS_EXPORT value_ : public QObject
{
    Q_OBJECT

    friend class detail::connector;

    template<typename t>
    using signal_sig = void(value_::*)(cv_qualified<t>) const;

public:
    QString name() const { return self_name; }
    value_(bundle const& b, const QString& name);
    ~value_() override;

    // no C++17 "constexpr inline" for data declarations in MSVC
    template<typename t>
    static constexpr auto value_changed()
    {
        return static_cast<signal_sig<t>>(&value_::valueChanged);
    }

    void notify() const;

signals:
    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;
    QString self_name;

    virtual void store_variant(const QVariant& x) = 0;

    template<typename t>
    void store_(const t& datum)
    {
        using traits = detail::value_traits<t>;
        store_variant(traits::qvariant_from_value(datum));
    }

public slots:
    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 bundle_value_changed() const = 0;
    virtual void set_to_default() = 0;

    friend void ::options::detail::set_value_to_default(value_* val);
};

} //ns options