From c8a5a82994e513acb00ba0e1f0b882ccbb18a6db Mon Sep 17 00:00:00 2001 From: Sine Striker <trueful@163.com> Date: 周二, 26 12月 2023 05:15:47 +0800 Subject: [PATCH] clean code --- src/core/contexts/abstractwindowcontext.cpp | 56 +++++++++++++++++++++++++++++++------------------------- 1 files changed, 31 insertions(+), 25 deletions(-) diff --git a/src/core/contexts/abstractwindowcontext.cpp b/src/core/contexts/abstractwindowcontext.cpp index 8672faf..dc0dc38 100644 --- a/src/core/contexts/abstractwindowcontext.cpp +++ b/src/core/contexts/abstractwindowcontext.cpp @@ -71,32 +71,7 @@ } } - bool AbstractWindowContext::setWindowAttribute(const QString &key, const QVariant &attribute) { - auto it = m_windowAttributes.find(key); - if (it == m_windowAttributes.end()) { - if (!attribute.isValid()) { - return true; - } - if (!m_windowHandle || !windowAttributeChanged(key, attribute, {})) { - return false; - } - m_windowAttributes.insert(key, attribute); - return true; - } - if (it.value() == attribute) - return true; - if (!m_windowHandle || !windowAttributeChanged(key, attribute, it.value())) { - return false; - } - - if (attribute.isValid()) { - it.value() = attribute; - } else { - m_windowAttributes.erase(it); - } - return true; - } bool AbstractWindowContext::setHitTestVisible(const QObject *obj, bool visible) { Q_ASSERT(obj); @@ -285,6 +260,37 @@ } } + QVariant AbstractWindowContext::windowAttribute(const QString &key) const { + return m_windowAttributes.value(key); + } + + bool AbstractWindowContext::setWindowAttribute(const QString &key, const QVariant &attribute) { + auto it = m_windowAttributes.find(key); + if (it == m_windowAttributes.end()) { + if (!attribute.isValid()) { + return true; + } + if (!m_windowHandle || !windowAttributeChanged(key, attribute, {})) { + return false; + } + m_windowAttributes.insert(key, attribute); + return true; + } + + if (it.value() == attribute) + return true; + if (!m_windowHandle || !windowAttributeChanged(key, attribute, it.value())) { + return false; + } + + if (attribute.isValid()) { + it.value() = attribute; + } else { + m_windowAttributes.erase(it); + } + return true; + } + bool AbstractWindowContext::windowAttributeChanged(const QString &key, const QVariant &attribute, const QVariant &oldAttribute) { -- Gitblit v1.9.1