summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--opentrack-compat/options.cpp37
-rw-r--r--opentrack-compat/options.hpp51
2 files changed, 36 insertions, 52 deletions
diff --git a/opentrack-compat/options.cpp b/opentrack-compat/options.cpp
index 7938b075..550fec24 100644
--- a/opentrack-compat/options.cpp
+++ b/opentrack-compat/options.cpp
@@ -13,15 +13,14 @@ OPENTRACK_COMPAT_EXPORT opt_singleton& singleton()
}
-group::group(const string& name) : name(name)
+group::group(const QString& name) : name(name)
{
auto conf = ini_file();
- auto q_name = QString::fromStdString(name);
- conf->beginGroup(q_name);
+ conf->beginGroup(name);
for (auto& k_ : conf->childKeys())
{
auto tmp = k_.toUtf8();
- string k(tmp);
+ QString k(tmp);
kvs[k] = conf->value(k_);
}
conf->endGroup();
@@ -30,23 +29,19 @@ group::group(const string& name) : name(name)
void group::save()
{
auto s = ini_file();
- auto q_name = QString::fromStdString(name);
- s->beginGroup(q_name);
+ s->beginGroup(name);
for (auto& i : kvs)
- {
- auto k = QString::fromStdString(i.first);
- s->setValue(k, i.second);
- }
+ s->setValue(i.first, i.second);
s->endGroup();
s->sync();
}
-void group::put(const std::string &s, const QVariant &d)
+void group::put(const QString &s, const QVariant &d)
{
kvs[s] = d;
}
-bool group::contains(const std::string &s)
+bool group::contains(const QString &s)
{
return kvs.count(s) != 0;
}
@@ -93,7 +88,7 @@ const mem<QSettings> group::ini_file()
return std::make_shared<QSettings>();
}
-impl_bundle::impl_bundle(const std::string &group_name)
+impl_bundle::impl_bundle(const QString &group_name)
:
mtx(QMutex::Recursive),
group_name(group_name),
@@ -113,7 +108,7 @@ void impl_bundle::reload()
emit reloading();
}
-void impl_bundle::store_kv(const std::string &name, const QVariant &datum)
+void impl_bundle::store_kv(const QString &name, const QVariant &datum)
{
QMutexLocker l(&mtx);
@@ -125,7 +120,7 @@ void impl_bundle::store_kv(const std::string &name, const QVariant &datum)
}
}
-bool impl_bundle::contains(const std::string &name)
+bool impl_bundle::contains(const QString &name)
{
QMutexLocker l(&mtx);
return transient.contains(name);
@@ -162,7 +157,7 @@ pbundle opt_singleton::bundle(const opt_singleton::k &key)
return shared;
}
- qDebug() << "bundle +" << QString::fromStdString(key);
+ qDebug() << "bundle +" << key;
auto shr = std::make_shared<v>(key);
implsgl_data[key] = tt(cnt(1), shr);
@@ -181,26 +176,24 @@ opt_singleton::opt_singleton() : implsgl_mtx(QMutex::Recursive) {}
}
-opt_bundle::opt_bundle(const std::string &group_name)
+opt_bundle::opt_bundle(const QString &group_name)
: impl_bundle(group_name)
{
}
opt_bundle::~opt_bundle()
{
- qDebug() << "bundle -" << QString::fromStdString(group_name);
+ qDebug() << "bundle -" << group_name;
detail::singleton().bundle_decf(group_name);
}
-base_value::base_value(pbundle b, const std::string &name) : b(b), self_name(name) {}
+base_value::base_value(pbundle b, const QString &name) : b(b), self_name(name) {}
opts::~opts()
{
b->reload();
}
-opts::opts(const std::string &name) : b(bundle(name)) {}
-
-
+opts::opts(const QString &name) : b(bundle(name)) {}
}
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();
};