1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-16 14:08:35 +08:00
Files
CMake/Tests/CMakeGUI/CatchShow.h
Kitware Robot 1772622772 LICENSE: Replace references to Copyright.txt with LICENSE.rst
```
git grep -lz 'Copyright.txt or https://cmake.org/licensing ' |
  while IFS= read -r -d $'\0' f ; do
    sed -i '/Copyright.txt or https:\/\/cmake.org\/licensing / {
              s/Copyright.txt/LICENSE.rst/
            }' "$f" ; done
```
2025-03-03 10:43:35 -05:00

43 lines
910 B
C++

/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file LICENSE.rst or https://cmake.org/licensing for details. */
#pragma once
#include <functional>
#include <memory>
#include <QObject>
#include <QWidget>
class CatchShow : public QObject
{
Q_OBJECT
public:
CatchShow(QObject* parent = nullptr);
template <typename T, typename F>
void setCallback(F&& func);
bool eventFilter(QObject* obj, QEvent* event) override;
int count() const;
private:
std::function<void(QObject* obj)> m_callback;
int m_count = 0;
};
template <typename T, typename F>
void CatchShow::setCallback(F&& func)
{
this->m_callback = [this, func](QObject* obj) {
auto* d = qobject_cast<T*>(obj);
if (d) {
QMetaObject::invokeMethod(
obj,
[this, func, d]() {
++this->m_count;
func(d);
},
Qt::QueuedConnection);
}
};
}