From 8c403d5dd03418febd67d50c6d9094a61c036f9b Mon Sep 17 00:00:00 2001
From: Sine Striker <trueful@163.com>
Date: 周一, 11 12月 2023 14:43:40 +0800
Subject: [PATCH] Add virtual hook

---
 src/core/kernel/nativeeventfilter.cpp |   25 ++++++-------------------
 1 files changed, 6 insertions(+), 19 deletions(-)

diff --git a/src/core/kernel/nativeeventfilter.cpp b/src/core/kernel/nativeeventfilter.cpp
index a3b8c1b..44a1337 100644
--- a/src/core/kernel/nativeeventfilter.cpp
+++ b/src/core/kernel/nativeeventfilter.cpp
@@ -1,7 +1,7 @@
 #include "nativeeventfilter.h"
 
 #include <QtCore/QAbstractNativeEventFilter>
-#include <QtGui/QGuiApplication>
+#include <QtCore/QCoreApplication>
 
 namespace QWK {
 
@@ -19,7 +19,7 @@
 
         bool nativeEventFilter(const QByteArray &eventType, void *message,
                                QT_NATIVE_EVENT_RESULT_TYPE *result) override {
-            for (const auto &child : qAsConst(m_children)) {
+            for (const auto &child : qAsConst(children)) {
                 if (child->nativeEventFilter(eventType, message, result)) {
                     return true;
                 }
@@ -27,22 +27,9 @@
             return false;
         }
 
-        inline int count() const {
-            return m_children.size();
-        }
-
-        inline void addChild(NativeEventFilter *child) {
-            m_children.append(child);
-        }
-
-        inline void removeChild(NativeEventFilter *child) {
-            m_children.removeOne(child);
-        }
+        QVector<NativeEventFilter *> children;
 
         static MasterNativeEventFilter *instance;
-
-    protected:
-        QVector<NativeEventFilter *> m_children;
     };
 
     MasterNativeEventFilter *MasterNativeEventFilter::instance = nullptr;
@@ -51,12 +38,12 @@
         if (!MasterNativeEventFilter::instance) {
             MasterNativeEventFilter::instance = new MasterNativeEventFilter();
         }
-        MasterNativeEventFilter::instance->addChild(this);
+        MasterNativeEventFilter::instance->children.append(this);
     }
 
     NativeEventFilter::~NativeEventFilter() {
-        MasterNativeEventFilter::instance->removeChild(this);
-        if (MasterNativeEventFilter::instance->count() == 0) {
+        MasterNativeEventFilter::instance->children.removeOne(this);
+        if (MasterNativeEventFilter::instance->children.isEmpty()) {
             delete MasterNativeEventFilter::instance;
             MasterNativeEventFilter::instance = nullptr;
         }

--
Gitblit v1.9.1