Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Kitware
GitHub Repository: Kitware/CMake
Path: blob/master/Tests/CMakeGUI/CatchShow.h
3148 views
1
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2
file LICENSE.rst or https://cmake.org/licensing for details. */
3
#pragma once
4
5
#include <functional>
6
#include <memory>
7
8
#include <QObject>
9
#include <QWidget>
10
11
class CatchShow : public QObject
12
{
13
Q_OBJECT
14
public:
15
CatchShow(QObject* parent = nullptr);
16
17
template <typename T, typename F>
18
void setCallback(F&& func);
19
bool eventFilter(QObject* obj, QEvent* event) override;
20
int count() const;
21
22
private:
23
std::function<void(QObject* obj)> m_callback;
24
int m_count = 0;
25
};
26
27
template <typename T, typename F>
28
void CatchShow::setCallback(F&& func)
29
{
30
this->m_callback = [this, func](QObject* obj) {
31
auto* d = qobject_cast<T*>(obj);
32
if (d) {
33
QMetaObject::invokeMethod(
34
obj,
35
[this, func, d]() {
36
++this->m_count;
37
func(d);
38
},
39
Qt::QueuedConnection);
40
}
41
};
42
}
43
44