From b0249aebbacf71eee27e77c766ccb3dc33693b11 Mon Sep 17 00:00:00 2001 From: Zhao Yuhang <2546789017@qq.com> Date: 周日, 10 12月 2023 13:54:14 +0800 Subject: [PATCH] a little simplify --- src/core/corewindowagent.cpp | 28 +++++++++++++--------------- 1 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/core/corewindowagent.cpp b/src/core/corewindowagent.cpp index 5d1f74e..d5dff5a 100644 --- a/src/core/corewindowagent.cpp +++ b/src/core/corewindowagent.cpp @@ -16,30 +16,28 @@ CoreWindowAgentPrivate::CoreWindowAgentPrivate() : q_ptr(nullptr), context(nullptr) { } - CoreWindowAgentPrivate::~CoreWindowAgentPrivate() { - if (context) { - delete context; - context = nullptr; - } - } + CoreWindowAgentPrivate::~CoreWindowAgentPrivate() = default; void CoreWindowAgentPrivate::init() { } - bool CoreWindowAgentPrivate::setup(const QObject *host, const WindowItemDelegate *delegate) { - auto ctx = + AbstractWindowContext *CoreWindowAgentPrivate::createContext() const { + return #ifdef Q_OS_WINDOWS - new Win32WindowContext(host, delegate) + new Win32WindowContext() #else - new QtWindowContext(host, window, delegate) + new QtWindowContext() #endif - ; - if (!ctx->setup()) { - delete ctx; - ctx = nullptr; + ; + } + + + bool CoreWindowAgentPrivate::setup(QObject *host, WindowItemDelegate *delegate) { + std::unique_ptr<AbstractWindowContext> ctx(createContext()); + if (!ctx->setup(host, delegate)) { return false; } - context = ctx; + context = std::move(ctx); return true; } -- Gitblit v1.9.1