refactor: Turn link-info into its own element and class (#5178)

This commit is contained in:
nerix
2024-02-18 13:34:00 +01:00
committed by GitHub
parent 42e4559910
commit e130c48f76
22 changed files with 752 additions and 314 deletions
+60
View File
@@ -0,0 +1,60 @@
#pragma once
#include <QObject>
#include <tuple>
#include <vector>
template <typename... Args>
class SignalSpy : public QObject
{
// Simplify the storage if there's only one argument to the signal handler.
using Call =
std::conditional_t<sizeof...(Args) == 1,
std::tuple_element_t<0, std::tuple<Args...>>,
std::tuple<Args...>>;
public:
SignalSpy(auto *sender, auto method)
{
auto conn =
QObject::connect(sender, method, this, &SignalSpy<Args...>::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<std::tuple<Args...>> &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<Call> calls_;
};