From 0287f19b3eabf6b6632d51c0288e6cf0be2c5e69 Mon Sep 17 00:00:00 2001 From: Yuhang Zhao <zhaoyuhang@rankyee.com> Date: 周三, 06 12月 2023 18:04:31 +0800 Subject: [PATCH] update pointer usage --- src/core/corewindowagent.cpp | 36 ++++++++++++++++++++---------------- 1 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/core/corewindowagent.cpp b/src/core/corewindowagent.cpp index b705937..5d1f74e 100644 --- a/src/core/corewindowagent.cpp +++ b/src/core/corewindowagent.cpp @@ -1,6 +1,8 @@ #include "corewindowagent.h" #include "corewindowagent_p.h" +#include "qwkcoreglobal_p.h" + #ifdef Q_OS_WINDOWS # include "win32windowcontext_p.h" #else @@ -11,31 +13,33 @@ namespace QWK { - CoreWindowAgentPrivate::CoreWindowAgentPrivate() : q_ptr(nullptr), eventHandler(nullptr) { + CoreWindowAgentPrivate::CoreWindowAgentPrivate() : q_ptr(nullptr), context(nullptr) { } - CoreWindowAgentPrivate::~CoreWindowAgentPrivate() = default; + CoreWindowAgentPrivate::~CoreWindowAgentPrivate() { + if (context) { + delete context; + context = nullptr; + } + } void CoreWindowAgentPrivate::init() { } - bool CoreWindowAgentPrivate::setup(QWindow *window, const WindowItemDelegatePtr &delegate) { - Q_ASSERT(window); - if (!window) { - return false; - } - auto handler = + bool CoreWindowAgentPrivate::setup(const QObject *host, const WindowItemDelegate *delegate) { + auto ctx = #ifdef Q_OS_WINDOWS - std::make_shared<Win32WindowContext>(window, delegate) + new Win32WindowContext(host, delegate) #else - std::make_shared<QtWindowContext>(window, delegate) + new QtWindowContext(host, window, delegate) #endif ; - - if (!handler->setup()) { + if (!ctx->setup()) { + delete ctx; + ctx = nullptr; return false; } - eventHandler = handler; + context = ctx; return true; } @@ -43,12 +47,12 @@ void CoreWindowAgent::showSystemMenu(const QPoint &pos) { Q_D(CoreWindowAgent); - d->eventHandler->showSystemMenu(pos); + d->context->showSystemMenu(pos); } void CoreWindowAgent::startSystemMove(const QPoint &pos) { Q_D(CoreWindowAgent); - auto win = d->eventHandler->window(); + auto win = d->context->window(); if (!win) { return; } @@ -59,7 +63,7 @@ void CoreWindowAgent::startSystemResize(Qt::Edges edges, const QPoint &pos) { Q_D(CoreWindowAgent); - auto win = d->eventHandler->window(); + auto win = d->context->window(); if (!win) { return; } -- Gitblit v1.9.1