summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--options/bundle.cpp15
-rw-r--r--options/bundle.hpp17
2 files changed, 19 insertions, 13 deletions
diff --git a/options/bundle.cpp b/options/bundle.cpp
index 644fe4c6..aa7d0ea8 100644
--- a/options/bundle.cpp
+++ b/options/bundle.cpp
@@ -49,7 +49,7 @@ void bundle::store_kv(const QString& name, const QVariant& datum)
bool bundle::contains(const QString &name) const
{
- QMutexLocker l(const_cast<QMutex*>(&mtx));
+ QMutexLocker l(mtx);
return transient.contains(name);
}
@@ -80,9 +80,9 @@ void bundle::save()
save_deferred(*group::ini_file());
}
-bool bundle::modifiedp() const // XXX unused
+bool bundle::is_modified() const // XXX unused
{
- QMutexLocker l(const_cast<QMutex*>(&mtx));
+ QMutexLocker l(mtx);
return transient != saved;
}
@@ -155,11 +155,9 @@ OPENTRACK_OPTIONS_EXPORT bundler& singleton()
return ret;
}
-}
-
-// end options::detail
+} // end options::detail
-OPENTRACK_OPTIONS_EXPORT bundle make_bundle(const QString& name)
+OPENTRACK_OPTIONS_EXPORT std::shared_ptr<bundle_type> make_bundle(const QString& name)
{
if (name.size())
return detail::singleton().make_bundle(name);
@@ -167,5 +165,6 @@ OPENTRACK_OPTIONS_EXPORT bundle make_bundle(const QString& name)
return std::make_shared<bundle_type>(QStringLiteral(""));
}
-} // end options
+QMutex* options::detail::bundle::get_mtx() const { return mtx; }
+} // end options
diff --git a/options/bundle.hpp b/options/bundle.hpp
index f83e6800..78c40ea2 100644
--- a/options/bundle.hpp
+++ b/options/bundle.hpp
@@ -26,16 +26,23 @@ namespace detail {
class OPENTRACK_OPTIONS_EXPORT bundle final : public QObject, public virtual connector
{
+ class OPENTRACK_OPTIONS_EXPORT mutex final : public QMutex
+ {
+ public:
+ mutex(QMutex::RecursionMode mode) : QMutex(mode) {}
+ operator QMutex*() const { return const_cast<QMutex*>(static_cast<const QMutex*>(this)); }
+ };
+
Q_OBJECT
private:
- QMutex mtx;
+ mutex mtx;
const QString group_name;
group saved;
group transient;
bundle(const bundle&) = delete;
bundle& operator=(const bundle&) = delete;
- QMutex* get_mtx() override { return &mtx; }
+ QMutex* get_mtx() const override;
signals:
void reloading();
@@ -50,12 +57,12 @@ public:
bool contains(const QString& name) const;
void save();
void save_deferred(QSettings& s);
- bool modifiedp() const;
+ bool is_modified() const;
template<typename t>
t get(const QString& name) const
{
- QMutexLocker l(const_cast<QMutex*>(&mtx));
+ QMutexLocker l(mtx);
return transient.get<t>(name);
}
};
@@ -85,6 +92,6 @@ OPENTRACK_OPTIONS_EXPORT bundler& singleton();
using bundle_type = detail::bundle;
using bundle = std::shared_ptr<bundle_type>;
-OPENTRACK_OPTIONS_EXPORT bundle make_bundle(const QString& name);
+OPENTRACK_OPTIONS_EXPORT std::shared_ptr<bundle_type> make_bundle(const QString& name);
}