diff --git a/src/input/gestures.cpp b/src/input/gestures.cpp index 3a1aa3e98..031e0b106 100644 --- a/src/input/gestures.cpp +++ b/src/input/gestures.cpp @@ -179,22 +179,16 @@ GestureRecognizer::GestureRecognizer(QObject *parent) void GestureRecognizer::registerSwipeGesture(SwipeGesture *gesture) { Q_ASSERT(!m_swipeGestures.contains(gesture)); - auto connection = connect(gesture, - &QObject::destroyed, - this, - std::bind(&GestureRecognizer::unregisterSwipeGesture, this, gesture)); - m_destroyConnections.insert(gesture, connection); + connect(gesture, &QObject::destroyed, this, [this, gesture] { + m_swipeGestures.removeOne(gesture); + m_activeSwipeGestures.removeOne(gesture); + }); m_swipeGestures << gesture; } void GestureRecognizer::unregisterSwipeGesture(SwipeGesture *gesture) { - auto it = m_destroyConnections.find(gesture); - if (it != m_destroyConnections.end()) { - disconnect(it.value()); - m_destroyConnections.erase(it); - } - m_swipeGestures.removeAll(gesture); + m_swipeGestures.removeOne(gesture); if (m_activeSwipeGestures.removeOne(gesture)) { Q_EMIT gesture->cancelled(); } @@ -371,7 +365,6 @@ HoldGesture::~HoldGesture() { if (m_holdTimer != nullptr) { m_holdTimer->stop(); - m_holdTimer->deleteLater(); } } @@ -398,22 +391,17 @@ bool HoldGesture::isActive() const void GestureRecognizer::registerHoldGesture(HoldGesture *gesture) { Q_ASSERT(!m_holdGestures.contains(gesture)); - auto connection = connect(gesture, - &QObject::destroyed, - this, - std::bind(&GestureRecognizer::unregisterHoldGesture, this, gesture)); - m_destroyConnections.insert(gesture, connection); + connect(gesture, &QObject::destroyed, this, [this, gesture] { + m_holdGestures.removeOne(gesture); + m_activeHoldGestures.removeOne(gesture); + }); m_holdGestures << gesture; } void GestureRecognizer::unregisterHoldGesture(HoldGesture *gesture) { - auto it = m_destroyConnections.find(gesture); - if (it != m_destroyConnections.end()) { - disconnect(it.value()); - m_destroyConnections.erase(it); - } - if (m_holdGestures.removeOne(gesture)) { + m_holdGestures.removeOne(gesture); + if (m_activeHoldGestures.removeOne(gesture)) { Q_EMIT gesture->cancelled(); } gesture->deleteLater(); diff --git a/src/input/gestures.h b/src/input/gestures.h index 35de72130..3a0d1ab5b 100644 --- a/src/input/gestures.h +++ b/src/input/gestures.h @@ -1,5 +1,5 @@ -// Copyright (C) 2024-2025 UnionTech Software Technology Co., Ltd. +// Copyright (C) 2024-2026 UnionTech Software Technology Co., Ltd. // SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #pragma once @@ -158,7 +158,6 @@ class GestureRecognizer : public QObject QList m_activeSwipeGestures; QList m_holdGestures; QList m_activeHoldGestures; - QMap m_destroyConnections; QPointF m_currentDelta = QPointF(0, 0); uint m_currentFingerCount = 0;