Loading...
Searching...
No Matches
Bind.hpp
1#pragma once
2#include <qobjectdefs.h>
3
4#include <utility>
5
11template <typename T, typename... Args>
12QMetaObject::Connection con(const T& t, Args&&... args)
13{
14 return T::connect(&t, std::forward<Args>(args)...);
15}
16
17template <typename T, typename Property, typename U, typename Slot, typename... Args>
18QMetaObject::Connection
19bind(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
27template <typename Entities, typename Presenter>
28void 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}