File indexing completed on 2025-02-09 04:28:39
0001 /* 0002 This file is part of the KTextTemplate library 0003 0004 SPDX-FileCopyrightText: 2010 Stephen Kelly <steveire@gmail.com> 0005 0006 SPDX-License-Identifier: LGPL-2.1-or-later 0007 0008 */ 0009 0010 #include "rendercontext.h" 0011 0012 #include "node.h" 0013 0014 using namespace KTextTemplate; 0015 0016 namespace KTextTemplate 0017 { 0018 0019 class RenderContextPrivate 0020 { 0021 RenderContextPrivate(RenderContext *qq) 0022 : q_ptr(qq) 0023 { 0024 } 0025 0026 Q_DECLARE_PUBLIC(RenderContext) 0027 RenderContext *const q_ptr; 0028 0029 QList<QHash<const Node *, QVariant>> m_variantHashStack; 0030 }; 0031 } 0032 0033 RenderContext::RenderContext() 0034 : d_ptr(new RenderContextPrivate(this)) 0035 { 0036 } 0037 0038 RenderContext::~RenderContext() 0039 { 0040 delete d_ptr; 0041 } 0042 0043 void RenderContext::push() 0044 { 0045 Q_D(RenderContext); 0046 d->m_variantHashStack.prepend({}); 0047 } 0048 0049 bool RenderContext::contains(Node *const scopeNode) const 0050 { 0051 Q_D(const RenderContext); 0052 Q_ASSERT(!d->m_variantHashStack.isEmpty()); 0053 return d->m_variantHashStack.last().contains(scopeNode); 0054 } 0055 0056 QVariant &RenderContext::data(const Node *const scopeNode) 0057 { 0058 Q_D(RenderContext); 0059 Q_ASSERT(!d->m_variantHashStack.isEmpty()); 0060 return d->m_variantHashStack.last()[scopeNode]; 0061 } 0062 0063 void RenderContext::pop() 0064 { 0065 Q_D(RenderContext); 0066 d->m_variantHashStack.removeFirst(); 0067 }