-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterpolationcurveobject.cpp
More file actions
57 lines (49 loc) · 1.94 KB
/
interpolationcurveobject.cpp
File metadata and controls
57 lines (49 loc) · 1.94 KB
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
#include "interpolationcurveobject.h"
InterpolationCurveObject::InterpolationCurveObject(Interpolation::Curve valueAndDefault,
QString const& settingsKey,
QObject *parent)
: QObject{parent}
, m_value(valueAndDefault)
, m_default(valueAndDefault)
, m_settingsKey(settingsKey)
{ }
Interpolation::Curve InterpolationCurveObject::value() const {
return m_value;
}
QString const& InterpolationCurveObject::settingsKey() const {
return m_settingsKey;
}
Interpolation::Curve InterpolationCurveObject::defaultValue() const {
return m_default;
}
void InterpolationCurveObject::setValue(Interpolation::Curve value) {
if (m_value != value) {
m_value = value;
emit valueChanged(m_value);
}
}
void InterpolationCurveObject::attachSettings(QSettings *settings) {
auto defaultValueName = Interpolation::getName(m_default);
auto loadedSetting = settings->value(m_settingsKey, defaultValueName).value<QString>();
auto loadedCurve = Interpolation::getByName(loadedSetting);
Interpolation::Curve curve;
if(!loadedCurve.has_value()) {
qDebug() << "Failed to load value from file for:"
<< m_settingsKey << "using default value"
<< Interpolation::getName(m_default)
<< "instead";
curve = m_default;
} else {
curve = loadedCurve.value();
}
connect(this, &InterpolationCurveObject::valueChanged,
[=](Interpolation::Curve newValue) {
qDebug() << "Updating " << m_settingsKey << ": " << Interpolation::getName(newValue);
settings->setValue(m_settingsKey, Interpolation::getName(newValue));
settings->sync();
});
// Updating local values
setValue(curve);
// Always write the setting back.
settings->setValue(m_settingsKey, Interpolation::getName(m_value));
}