diff options
Diffstat (limited to 'opentrack-compat/options.hpp')
-rw-r--r-- | opentrack-compat/options.hpp | 51 |
1 files changed, 21 insertions, 30 deletions
diff --git a/opentrack-compat/options.hpp b/opentrack-compat/options.hpp index 81a53067..d41c5cd1 100644 --- a/opentrack-compat/options.hpp +++ b/opentrack-compat/options.hpp @@ -10,7 +10,6 @@ #include <memory> #include <tuple> #include <map> -#include <string> #include <QObject> #include <QSettings> @@ -52,7 +51,6 @@ template<typename t> using mem = std::shared_ptr<t>; namespace options { template<typename k, typename v> using map = std::map<k, v>; - using std::string; template<typename t> // don't elide usages of the function, qvariant default implicit @@ -92,13 +90,13 @@ namespace options { // snapshot of qsettings group at given time class OPENTRACK_COMPAT_EXPORT group { private: - map<string, QVariant> kvs; - string name; + map<QString, QVariant> kvs; + QString name; public: - group(const string& name); + group(const QString& name); void save(); - void put(const string& s, const QVariant& d); - bool contains(const string& s); + void put(const QString& s, const QVariant& d); + bool contains(const QString& s); static QString ini_directory(); static QString ini_filename(); static QString ini_pathname(); @@ -106,7 +104,7 @@ namespace options { static const mem<QSettings> ini_file(); template<typename t> - t get(const string& k) + t get(const QString& k) { return qcruft_to_t<t>(kvs[k]); } @@ -116,7 +114,7 @@ namespace options { Q_OBJECT protected: QMutex mtx; - const string group_name; + const QString group_name; group saved; group transient; bool modified; @@ -126,16 +124,16 @@ namespace options { void reloading(); void saving(); public: - impl_bundle(const string& group_name); - string name() { return group_name; } + impl_bundle(const QString& group_name); + QString name() { return group_name; } void reload(); - void store_kv(const string& name, const QVariant& datum); - bool contains(const string& name); + void store_kv(const QString& name, const QVariant& datum); + bool contains(const QString& name); void save(); bool modifiedp(); template<typename t> - t get(const string& name) + t get(const QString& name) { QMutexLocker l(&mtx); return transient.get<t>(name); @@ -149,7 +147,7 @@ namespace options { struct OPENTRACK_COMPAT_EXPORT opt_singleton { public: - using k = std::string; + using k = QString; using v = opt_bundle; using cnt = int; using pbundle = std::shared_ptr<v>; @@ -168,13 +166,13 @@ namespace options { using pbundle = std::shared_ptr<opt_bundle>; - static inline pbundle bundle(const string name) { return detail::singleton().bundle(name); } + static inline pbundle bundle(const QString name) { return detail::singleton().bundle(name); } class OPENTRACK_COMPAT_EXPORT opt_bundle : public impl_bundle { public: opt_bundle() : impl_bundle("i-have-no-name") {} - opt_bundle(const string& group_name); + opt_bundle(const QString& group_name); ~opt_bundle(); }; @@ -184,8 +182,8 @@ namespace options { #define DEFINE_SLOT(t) void setValue(t datum) { store(datum); } #define DEFINE_SIGNAL(t) void valueChanged(t) public: - string name() { return self_name; } - base_value(pbundle b, const string& name); + QString name() { return self_name; } + base_value(pbundle b, const QString& name); signals: DEFINE_SIGNAL(double); DEFINE_SIGNAL(int); @@ -193,7 +191,7 @@ namespace options { DEFINE_SIGNAL(QString); protected: pbundle b; - string self_name; + QString self_name; template<typename t> void store(const t& datum) @@ -210,12 +208,6 @@ namespace options { virtual void reload() = 0; }; - static inline std::string string_from_qstring(const QString &datum) - { - auto tmp = datum.toUtf8(); - return string(tmp.constData()); - } - template<typename t> class value : public base_value { public: @@ -226,7 +218,7 @@ namespace options { } static constexpr const Qt::ConnectionType DIRECT_CONNTYPE = Qt::DirectConnection; static constexpr const Qt::ConnectionType SAFE_CONNTYPE = Qt::UniqueConnection; - value(pbundle b, const string& name, t def) : base_value(b, name), def(def) + value(pbundle b, const QString& name, t def) : base_value(b, name), def(def) { QObject::connect(b.get(), SIGNAL(reloading()), this, SLOT(reload()), @@ -234,8 +226,7 @@ namespace options { if (!b->contains(name) || b->get<QVariant>(name).type() == QVariant::Invalid) *this = def; } - value(pbundle b, const QString& name, t def) : value(b, string_from_qstring(name), def) {} - value(pbundle b, const char* name, t def) : value(b, string(name), def) {} + value(pbundle b, const char* name, t def) : value(b, QString(name), def) {} operator t() const { @@ -251,7 +242,7 @@ namespace options { struct OPENTRACK_COMPAT_EXPORT opts { pbundle b; - opts(const std::string& name); + opts(const QString& name); ~opts(); }; |