#pragma once #include #include #include template class SignalSpy : public QObject { // Simplify the storage if there's only one argument to the signal handler. using Call = std::conditional_t>, std::tuple>; public: SignalSpy(auto *sender, auto method) { auto conn = QObject::connect(sender, method, this, &SignalSpy::slot, Qt::DirectConnection); assert(conn && "Failed to connect"); } bool empty() const { return this->calls_.empty(); } size_t size() const { return this->calls_.size(); } const std::vector> &calls() const { return this->calls_; } void clear() { this->calls_.clear(); } const Call &last() const { assert(!this->calls_.empty()); return this->calls_.back(); } private: void slot(Args... args) { this->calls_.emplace_back(std::move(args)...); } std::vector calls_; };