mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-16 18:35:35 +08:00
refactor: clang format line length
This commit is contained in:
@@ -23,12 +23,14 @@ namespace swift::misc
|
||||
* Wrapper around QObject::connect which disconnects after the signal has been emitted once.
|
||||
*/
|
||||
template <typename T, typename U, typename F, typename G>
|
||||
QMetaObject::Connection connectOnce(T *sender, F signal, U *receiver, G &&slot, Qt::ConnectionType type = Qt::AutoConnection)
|
||||
QMetaObject::Connection connectOnce(T *sender, F signal, U *receiver, G &&slot,
|
||||
Qt::ConnectionType type = Qt::AutoConnection)
|
||||
{
|
||||
std::promise<QMetaObject::Connection> promise;
|
||||
auto called = std::make_shared<std::atomic_flag>();
|
||||
called->clear();
|
||||
auto wrapper = [receiver, called, connection = promise.get_future().share(), slot = std::forward<G>(slot)](auto &&...args) {
|
||||
auto wrapper = [receiver, called, connection = promise.get_future().share(),
|
||||
slot = std::forward<G>(slot)](auto &&...args) {
|
||||
if (called->test_and_set()) { return; }
|
||||
QObject::disconnect(connection.get());
|
||||
private_ns::invokeSlot(slot, receiver, std::forward<decltype(args)>(args)...);
|
||||
@@ -45,7 +47,8 @@ namespace swift::misc
|
||||
template <typename T, typename F, typename G>
|
||||
QMetaObject::Connection connectOnce(T *sender, F signal, G &&slot)
|
||||
{
|
||||
static_assert(!std::is_member_pointer_v<std::decay_t<G>>, "If slot is a pointer to member, a receiver must be supplied");
|
||||
static_assert(!std::is_member_pointer_v<std::decay_t<G>>,
|
||||
"If slot is a pointer to member, a receiver must be supplied");
|
||||
return connectOnce(sender, signal, sender, std::forward<G>(slot));
|
||||
}
|
||||
|
||||
@@ -70,16 +73,15 @@ namespace swift::misc
|
||||
|
||||
//! Construct a slot from the given member function of the given object.
|
||||
template <typename T, typename U>
|
||||
CSlot(T *object, R (U::*function)(Args...)) : m_object(object),
|
||||
m_function([=](Args... args) { return (object->*function)(args...); })
|
||||
CSlot(T *object, R (U::*function)(Args...))
|
||||
: m_object(object), m_function([=](Args... args) { return (object->*function)(args...); })
|
||||
{
|
||||
Q_ASSERT_X(object, Q_FUNC_INFO, "Need object");
|
||||
}
|
||||
|
||||
//! Construct a slot from the given object passing a function and a object
|
||||
template <typename T>
|
||||
CSlot(T *object, std::function<R(Args...)> function) : m_object(object),
|
||||
m_function(function)
|
||||
CSlot(T *object, std::function<R(Args...)> function) : m_object(object), m_function(function)
|
||||
{}
|
||||
|
||||
//! Call the slot. The behaviour is undefined if the slot is empty.
|
||||
@@ -100,10 +102,7 @@ namespace swift::misc
|
||||
|
||||
//! Returns the object which the slot belongs to.
|
||||
//! Use this as the third argument to QObject::connect to ensure the slot is called in the correct thread.
|
||||
QObject *object() const
|
||||
{
|
||||
return m_object.data();
|
||||
}
|
||||
QObject *object() const { return m_object.data(); }
|
||||
|
||||
//! Set the object which the slot belongs to.
|
||||
//! Use this as the third argument to QObject::connect to ensure the slot is called in the correct thread.
|
||||
@@ -114,28 +113,16 @@ namespace swift::misc
|
||||
}
|
||||
|
||||
//! True if the slot can be called, false if it is empty.
|
||||
operator bool() const
|
||||
{
|
||||
return !this->isEmpty() && !this->hasNullObject();
|
||||
}
|
||||
operator bool() const { return !this->isEmpty() && !this->hasNullObject(); }
|
||||
|
||||
//! True if the slot is empty or object is null, false if it can be called.
|
||||
bool operator!() const
|
||||
{
|
||||
return this->isEmpty() || this->hasNullObject();
|
||||
}
|
||||
bool operator!() const { return this->isEmpty() || this->hasNullObject(); }
|
||||
|
||||
//! True if the slot is empty, false if it can be called.
|
||||
bool isEmpty() const
|
||||
{
|
||||
return !m_function;
|
||||
}
|
||||
bool isEmpty() const { return !m_function; }
|
||||
|
||||
//! True if the object is null
|
||||
bool hasNullObject() const
|
||||
{
|
||||
return m_object.isNull();
|
||||
}
|
||||
bool hasNullObject() const { return m_object.isNull(); }
|
||||
|
||||
private:
|
||||
QPointer<QObject> m_object;
|
||||
|
||||
Reference in New Issue
Block a user