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 | 35 ++++++++++++++++++----------------- 1 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/core/corewindowagent.cpp b/src/core/corewindowagent.cpp index abcd6fb..5d1f74e 100644 --- a/src/core/corewindowagent.cpp +++ b/src/core/corewindowagent.cpp @@ -13,32 +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, WindowItemDelegate *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 - new Win32WindowContext(window, delegate) + new Win32WindowContext(host, delegate) #else - new QtWindowContext(window, delegate) + new QtWindowContext(host, window, delegate) #endif ; - if (!handler->setup()) { - delete handler; + if (!ctx->setup()) { + delete ctx; + ctx = nullptr; return false; } - eventHandler.reset(handler); + context = ctx; return true; } @@ -46,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; } @@ -62,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