From 478923fa291949af2ce1f307f9dd592f451508df Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 1 Jan 2014 12:13:25 +0100 Subject: fix qvariant saying invalid when they're not --- facetracknoir/options.h | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'facetracknoir') diff --git a/facetracknoir/options.h b/facetracknoir/options.h index e77988c7..7ecf6280 100644 --- a/facetracknoir/options.h +++ b/facetracknoir/options.h @@ -32,6 +32,8 @@ # define ov #endif +#include + namespace options { template inline T qcruft_to_t (const QVariant& t); @@ -193,8 +195,8 @@ namespace options { base_value(pbundle b, const QString& name) : b(b), self_name(name) { connect(b.get(), SIGNAL(reloaded()), this, SLOT(reread_value())); } - virtual QVariant operator=(const QVariant& datum) = 0; protected: + virtual QVariant operator=(const QVariant& datum) = 0; pbundle b; QString self_name; public slots: @@ -203,7 +205,7 @@ namespace options { this->operator=(b->get(self_name)); } public slots: -#define DEFINE_SLOT(t) void setValue(t datum) { this->operator=(datum); } +#define DEFINE_SLOT(t) void setValue(t datum) { this->operator=(qVariantFromValue(datum)); } DEFINE_SLOT(double) DEFINE_SLOT(int) DEFINE_SLOT(QString) @@ -218,24 +220,29 @@ namespace options { template class value : public base_value { - private: T def; + private: + T def; + protected: + QVariant operator=(const QVariant& datum) { + auto foo = qcruft_to_t(datum); + b->store(self_name, qVariantFromValue(foo)); + emit valueChanged(foo); + return datum; + } public: static constexpr const Qt::ConnectionType CONNTYPE = Qt::QueuedConnection; value(pbundle b, const QString& name, T def) : base_value(b, name), def(def) { - if (!b->contains(name)) + if (!b->contains(name) || b->get(name).type() == QVariant::Invalid) { - QVariant cruft(def); - b->store(self_name, cruft); + this->operator=(qVariantFromValue(def)); } } operator T() { return b->get(self_name); } - QVariant operator=(const QVariant& datum) { - b->store(self_name, datum); - auto foo = qcruft_to_t(datum); - emit valueChanged(foo); - return datum; + QVariant operator=(const T& datum) + { + return this->operator =(qVariantFromValue(datum)); } }; -- cgit v1.2.3