summaryrefslogtreecommitdiffhomepage
path: root/opentrack/options.hpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2014-11-04 18:44:02 +0100
committerStanislaw Halik <sthalik@misaki.pl>2014-11-04 19:20:13 +0100
commit790307a1ea1bad21d128872a53181a0b3e5ad3bd (patch)
treef9a2012db11d420fd8a085637c6053324468bf83 /opentrack/options.hpp
parent8574e7e62a9675eeed2de06d3f8af08044fe5176 (diff)
settings need fire when bundle reloads
Diffstat (limited to 'opentrack/options.hpp')
-rw-r--r--opentrack/options.hpp20
1 files changed, 15 insertions, 5 deletions
diff --git a/opentrack/options.hpp b/opentrack/options.hpp
index f7614b9c..daef7b1c 100644
--- a/opentrack/options.hpp
+++ b/opentrack/options.hpp
@@ -140,6 +140,7 @@ namespace options {
};
class impl_bundle : public QObject {
+ Q_OBJECT
protected:
QMutex mtx;
const string group_name;
@@ -148,6 +149,8 @@ namespace options {
bool modified;
impl_bundle(const impl_bundle&) = delete;
impl_bundle& operator=(const impl_bundle&) = delete;
+ signals:
+ void reloading();
public:
impl_bundle(const string& group_name) :
mtx(QMutex::Recursive),
@@ -165,9 +168,10 @@ namespace options {
saved = group(group_name);
transient = saved;
modified = false;
+ emit reloading();
}
- bool store_kv(const string& name, const QVariant& datum)
+ void store_kv(const string& name, const QVariant& datum)
{
QMutexLocker l(&mtx);
@@ -176,9 +180,7 @@ namespace options {
{
modified = true;
transient.put(name, datum);
- return true;
}
- return false;
}
bool contains(const string& name)
{
@@ -291,14 +293,16 @@ namespace options {
template<typename t>
void store(const t& datum)
{
- if (b->store_kv(self_name, datum))
- emit valueChanged(static_cast<t>(datum));
+ b->store_kv(self_name, datum);
+ emit valueChanged(static_cast<t>(datum));
}
public slots:
DEFINE_SLOT(double)
DEFINE_SLOT(int)
DEFINE_SLOT(QString)
DEFINE_SLOT(bool)
+ public slots:
+ virtual void reload() = 0;
};
static inline string string_from_qstring(const QString& datum)
@@ -319,6 +323,9 @@ namespace options {
static constexpr const Qt::ConnectionType SAFE_CONNTYPE = Qt::UniqueConnection;
value(pbundle b, const string& name, t def) : base_value(b, name)
{
+ QObject::connect(b.get(), SIGNAL(reloading()),
+ this, SLOT(reload()),
+ DIRECT_CONNTYPE);
if (!b->contains(name) || b->get<QVariant>(name).type() == QVariant::Invalid)
*this = def;
}
@@ -329,6 +336,9 @@ namespace options {
{
return b->get<t>(self_name);
}
+ void reload() override {
+ *this = static_cast<t>(*this);
+ }
};
template<typename t, typename q>