summaryrefslogtreecommitdiffhomepage
path: root/options/connector.hpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2017-03-21 08:22:36 +0100
committerStanislaw Halik <sthalik@misaki.pl>2017-03-21 08:22:36 +0100
commitca847749c03b88d8e482396a9c4311ef02b054b9 (patch)
treec8237b2d8385f922acdb5563e417737feba3adfb /options/connector.hpp
parentfd0305aeecfad05f855b7d0e09a1eb9a70f4b2e5 (diff)
options/{bundle,connector,value}: allow setting to default values
This is complicated by Qt's rejection of template classes. Also move some stuff to slots where makes sense.
Diffstat (limited to 'options/connector.hpp')
-rw-r--r--options/connector.hpp27
1 files changed, 21 insertions, 6 deletions
diff --git a/options/connector.hpp b/options/connector.hpp
index dec98016..abe72154 100644
--- a/options/connector.hpp
+++ b/options/connector.hpp
@@ -30,20 +30,35 @@ class connector
{
friend class ::options::base_value;
- using value_vec = std::vector<const base_value*>;
+ using value_type = base_value*;
+ using value_vec = std::vector<value_type>;
using comparator = bool(*)(const QVariant&, const QVariant&);
using tt = std::tuple<value_vec, comparator, std::type_index>;
std::map<QString, tt> connected_values;
- void on_value_destructed(const QString& name, const base_value* val);
- void on_value_created(const QString& name, const base_value* val);
- bool on_value_destructed_impl(const QString& name, const base_value* val);
+ void on_value_destructed(const QString& name, value_type val);
+ void on_value_created(const QString& name, value_type val);
+ bool on_value_destructed_impl(const QString& name, value_type val);
protected:
void notify_values(const QString& name) const;
void notify_all_values() const;
virtual QMutex* get_mtx() const = 0;
+ template<typename F>
+ void forall(F&& fun)
+ {
+ QMutexLocker l(get_mtx());
+
+ for (auto& pair : connected_values)
+ {
+ for (auto& val : std::get<0>(pair.second))
+ {
+ fun(pair.first, val);
+ }
+ }
+ }
+
public:
connector();
virtual ~connector();
@@ -56,5 +71,5 @@ public:
connector& operator=(connector&&) = default;
};
-}
-}
+} // ns detail
+} // ns options