LeechCraft 0.6.70-14794-g33744ae6ce
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
lambdaeventfilter.h
Go to the documentation of this file.
1/**********************************************************************
2 * LeechCraft - modular cross-platform feature rich internet client.
3 * Copyright (C) 2006-2014 Georg Rudoy
4 *
5 * Distributed under the Boost Software License, Version 1.0.
6 * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7 **********************************************************************/
8
9#pragma once
10
11#include <type_traits>
12#include <QObject>
13#include "typegetter.h"
14
15namespace LC
16{
17namespace Util
18{
19 namespace detail
20 {
21 template<typename F>
22 class LambdaEventFilter : public QObject
23 {
24 const F F_;
25
26 using EventType_t = std::remove_pointer_t<std::decay_t<ArgType_t<F, 0>>>;
27 public:
28 LambdaEventFilter (F&& f, QObject *parent = nullptr)
29 : QObject { parent }
30 , F_ { std::move (f) }
31 {
32 }
33
34 bool eventFilter (QObject*, QEvent *srcEv) override
35 {
36 const auto ev = dynamic_cast<EventType_t*> (srcEv);
37 if (!ev)
38 return false;
39
40 return F_ (ev);
41 }
42 };
43 }
44
45 template<typename F>
46 auto MakeLambdaEventFilter (F&& f, QObject *parent = nullptr)
47 {
48 return new detail::LambdaEventFilter<std::decay_t<F>> { std::forward<F> (f), parent };
49 }
50}
51}
LambdaEventFilter(F &&f, QObject *parent=nullptr)
bool eventFilter(QObject *, QEvent *srcEv) override
auto MakeLambdaEventFilter(F &&f, QObject *parent=nullptr)
Definition: constants.h:15
STL namespace.