summaryrefslogtreecommitdiff
path: root/qt/kzqproperty.cpp
blob: 4290e8cfc441fe4782a0ae67bb557fef8636e3c2 (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
#include "kzqproperty.h"
#include "kzqsettings.h"

namespace KaZoe {
class KzQPropertyPrivate
{
    Q_DISABLE_COPY(KzQPropertyPrivate)
    Q_DECLARE_PUBLIC(KaZoe::KzQProperty)

    KaZoe::KzQProperty * const q_ptr;
    QString m_key;
    QVariant m_value;
    KaZoe::KzQSettings m_settings;

    KzQPropertyPrivate(KaZoe::KzQProperty* systemprop): q_ptr(systemprop){}
};
};

KaZoe::KzQProperty::KzQProperty(QObject *parent)
    : QObject{parent}
    , d_ptr(new KaZoe::KzQPropertyPrivate(this))
{
    Q_D(KzQProperty);
    QObject::connect(&d->m_settings, &KaZoe::KzQSettings::valueChanged, [this](QString id, QVariant value){
        Q_D(KzQProperty);
        if(id == d->m_key)
        {
            setValue(value);
        }
    });
}

KaZoe::KzQProperty::~KzQProperty() = default;

QString KaZoe::KzQProperty::key() const
{
    Q_D(const KzQProperty);
    return d->m_key;
}

void KaZoe::KzQProperty::setKey(const QString &newKey)
{
    Q_D(KzQProperty);
    if (d->m_key == newKey)
        return;
    d->m_key = newKey;
    setValue(d->m_settings.get(d->m_key));
    emit keyChanged();
}

QVariant KaZoe::KzQProperty::value() const
{
    Q_D(const KzQProperty);
    return d->m_value;
}

void KaZoe::KzQProperty::setValue(const QVariant &newValue)
{
    Q_D(KzQProperty);
    if (d->m_value == newValue)
        return;
    d->m_value = newValue;
    emit valueChanged();
}