Bind.hpp
1 #pragma once
2 #include <qobjectdefs.h>
3 
4 #include <utility>
5 
11 template <typename T, typename... Args>
12 QMetaObject::Connection con(const T& t, Args&&... args)
13 {
14  return T::connect(&t, std::forward<Args>(args)...);
15 }
16 
17 template <typename T, typename Property, typename U, typename Slot, typename... Args>
18 QMetaObject::Connection
19 bind(T& t, const Property&, const U* tgt, Slot&& slot, Args&&... args)
20 {
21  slot((t.*(Property::get))());
22 
23  return T::connect(
24  &t, Property::notify, tgt, std::forward<Slot>(slot), std::forward<Args>(args)...);
25 }
26 
27 template <typename Entities, typename Presenter>
28 void bind(const Entities& model, Presenter& presenter)
29 {
30  for(auto& entity : model)
31  presenter.on_created(entity);
32 
33  model.mutable_added.template connect<&Presenter::on_created>(presenter);
34  model.removed.template connect<&Presenter::on_removing>(presenter);
35 }