summaryrefslogtreecommitdiffhomepage
path: root/options/value.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'options/value.hpp')
-rw-r--r--options/value.hpp23
1 files changed, 21 insertions, 2 deletions
diff --git a/options/value.hpp b/options/value.hpp
index 090a7bdf..4476f8b7 100644
--- a/options/value.hpp
+++ b/options/value.hpp
@@ -27,10 +27,10 @@ namespace options::detail {
{
t x;
public:
- constexpr t const* operator->() const { return &x; }
constexpr t* operator->() { return &x; }
constexpr explicit dereference_wrapper(t&& x) : x(x) {}
};
+ template<typename t, typename...> /*MSVC workaround*/ static constexpr bool is_enum_v = std::is_enum_v<t>;
} // ns options::detail
namespace options {
@@ -38,7 +38,7 @@ namespace options {
template<typename t>
class value final : public value_
{
- static_assert(std::is_same_v<t, remove_cvref_t<t>>);
+ static_assert(std::is_same_v<t, std::remove_cvref_t<t>>);
mutable QMutex mtx;
const t def;
mutable t cached_value;
@@ -86,6 +86,9 @@ class value final : public value_
}
public:
+ using signal_sig = typename value_::signal_sig_<t>;
+ using slot_sig = typename value_::slot_sig_<t>;
+
QVariant get_variant() const noexcept override
{
if (QVariant ret{b->get_variant(self_name)}; ret.isValid() && !ret.isNull())
@@ -195,6 +198,22 @@ public:
{
return static_cast<u>(get());
}
+
+ template<typename Q, typename F>
+ QMetaObject::Connection
+ connect_to(Q* qobject, F&& writer, Qt::ConnectionType conn = Qt::QueuedConnection) {
+ return QObject::connect(this, static_cast<signal_sig>(&value<t>::valueChanged), qobject, std::forward<F>(writer), conn);
+ }
+ template<typename Q, typename F>
+ QMetaObject::Connection
+ connect_from(Q* qobject, F&& reader, Qt::ConnectionType conn = Qt::DirectConnection) {
+ return QObject::connect(qobject, std::forward<F>(reader), this, static_cast<slot_sig>(&value<t>::setValue), conn);
+ }
+ template<typename Q, typename F, typename G>
+ QMetaObject::Connection
+ connect_from(Q* qobject, F&& reader, G&& fn, Qt::ConnectionType conn = Qt::DirectConnection) {
+ return QObject::connect(qobject, std::forward<F>(reader), this, std::forward<G>(fn), conn);
+ }
};
#if !defined OTR_OPTIONS_INST_VALUE