From 5a01c9bd790fb6877534a9c0d613609ce397a14c Mon Sep 17 00:00:00 2001 From: Nodir Temirkhodjaev Date: Wed, 2 Jun 2021 14:38:44 +0300 Subject: [PATCH] UI: IocContainer: Only services are auto-deletable. --- src/ui/fortmanager.cpp | 4 ++-- src/ui/util/ioc/ioccontainer.cpp | 2 ++ src/ui/util/ioc/ioccontainer.h | 26 +++++++------------------- src/ui/util/nativeeventfilter.h | 3 ++- src/ui/util/net/hostinfocache.h | 3 ++- 5 files changed, 15 insertions(+), 23 deletions(-) diff --git a/src/ui/fortmanager.cpp b/src/ui/fortmanager.cpp index cbb8d80b..8517d417 100644 --- a/src/ui/fortmanager.cpp +++ b/src/ui/fortmanager.cpp @@ -179,9 +179,9 @@ void FortManager::createManagers() ioc->setService(taskManager); ioc->setService(new AppInfoCache()); - ioc->set(new HostInfoCache()); + ioc->setService(new HostInfoCache()); - ioc->set(new NativeEventFilter()); + ioc->setService(new NativeEventFilter()); ioc->setService(new HotKeyManager()); if (!settings->isService()) { diff --git a/src/ui/util/ioc/ioccontainer.cpp b/src/ui/util/ioc/ioccontainer.cpp index bcb36196..f1464cf4 100644 --- a/src/ui/util/ioc/ioccontainer.cpp +++ b/src/ui/util/ioc/ioccontainer.cpp @@ -18,6 +18,8 @@ IocContainer::IocContainer(QObject *parent) : QObject(parent) { } IocContainer::~IocContainer() { + autoDeleteAll(); + if (g_tlsIndex != -1) { TlsFree(g_tlsIndex); g_tlsIndex = -1; diff --git a/src/ui/util/ioc/ioccontainer.h b/src/ui/util/ioc/ioccontainer.h index bac46c7f..4bedd444 100644 --- a/src/ui/util/ioc/ioccontainer.h +++ b/src/ui/util/ioc/ioccontainer.h @@ -23,21 +23,21 @@ public: const int size() const { return m_size; } template - void set(T *obj, quint8 flags = AutoDelete) + void set(T *obj) { - setObject(getTypeId(), obj, flags); + setObject(getTypeId(), obj); } template void set(T &obj) { - set(&obj, 0); + set(&obj); } template void remove() { - set(nullptr, 0); + set(nullptr); } template @@ -55,27 +55,15 @@ public: } template - T *object() const + inline constexpr std::enable_if_t, T *> resolve() const { return static_cast(resolveObject(getTypeId())); } - template - T *service() const - { - return static_cast(resolveService(getTypeId())); - } - - template - inline constexpr std::enable_if_t, T *> resolve() const - { - return object(); - } - template inline constexpr std::enable_if_t, T *> resolve() const { - return service(); + return static_cast(resolveService(getTypeId())); } void setUpAll(); @@ -86,7 +74,7 @@ public: T *setUpDependency() { setUp(getTypeId()); - return service(); + return resolve(); } bool pinToThread(); diff --git a/src/ui/util/nativeeventfilter.h b/src/ui/util/nativeeventfilter.h index 0d0f4967..44689a0a 100644 --- a/src/ui/util/nativeeventfilter.h +++ b/src/ui/util/nativeeventfilter.h @@ -6,8 +6,9 @@ #include #include "classhelpers.h" +#include "ioc/iocservice.h" -class NativeEventFilter : public QObject, public QAbstractNativeEventFilter +class NativeEventFilter : public QObject, public QAbstractNativeEventFilter, public IocService { Q_OBJECT diff --git a/src/ui/util/net/hostinfocache.h b/src/ui/util/net/hostinfocache.h index a40c16b8..e3c11912 100644 --- a/src/ui/util/net/hostinfocache.h +++ b/src/ui/util/net/hostinfocache.h @@ -5,11 +5,12 @@ #include #include "../triggertimer.h" +#include "../util/ioc/iocservice.h" #include "hostinfo.h" class HostInfoManager; -class HostInfoCache : public QObject +class HostInfoCache : public QObject, public IocService { Q_OBJECT