diff options
author | Bjoern Michaelsen <bjoern.michaelsen@canonical.com> | 2016-01-02 01:12:51 +0100 |
---|---|---|
committer | Bjoern Michaelsen <bjoern.michaelsen@canonical.com> | 2016-01-02 01:27:38 +0100 |
commit | b4082bed2de12cd576a06a9f456a71101809f3ed (patch) | |
tree | 726c5e2bc94d24705ecf0afc65ca4fed1c134755 /sw | |
parent | 952f41ed0806cd8bfbd568a7c87df7f6368fdca9 (diff) |
make this temp override of ItemSet more explicit and scoped
Change-Id: I8a02be2772b8f7c0d1b13556d0c49f1b00bcc1aa
Diffstat (limited to 'sw')
-rw-r--r-- | sw/source/core/unocore/unostyle.cxx | 50 |
1 files changed, 30 insertions, 20 deletions
diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index 42a8f110946b..8caa0dd905f1 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -1320,7 +1320,6 @@ private: std::unique_ptr<SfxItemSet> m_pMyItemSet; OUString m_rStyleName; const SwAttrSet* m_pParentStyle; - public: SwStyleBase_Impl(SwDoc& rSwDoc, const OUString& rName, const SwAttrSet* pParentStyle) : m_rDoc(rSwDoc) @@ -1346,13 +1345,6 @@ public: return m_xNewBase.is(); } - SfxItemSet* replaceItemSet(SfxItemSet* pNew) - { - SfxItemSet* pRetval = m_pItemSet; - m_pItemSet = pNew; - return pRetval; - } - SfxItemSet& GetItemSet() { assert(m_xNewBase.is()); @@ -1369,6 +1361,19 @@ public: } const SwPageDesc* GetOldPageDesc(); + + // still a hack, but a bit more explicit and with a proper scope + struct ItemSetOverrider + { + SwStyleBase_Impl& m_rStyleBase; + SfxItemSet* m_pOldSet; + ItemSetOverrider(SwStyleBase_Impl& rStyleBase, SfxItemSet* pTemp) + : m_rStyleBase(rStyleBase) + , m_pOldSet(m_rStyleBase.m_pItemSet) + { m_rStyleBase.m_pItemSet = pTemp; } + ~ItemSetOverrider() + { m_rStyleBase.m_pItemSet = m_pOldSet; }; + }; }; const SwPageDesc* SwStyleBase_Impl::GetOldPageDesc() @@ -1394,6 +1399,7 @@ const SwPageDesc* SwStyleBase_Impl::GetOldPageDesc() return m_pOldPageDesc; } + static void lcl_SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, @@ -3058,9 +3064,10 @@ static void lcl_putItemToSet(const SvxSetItem* pSetItem, const SfxItemPropertySe // replace the used SfxItemSet at the SwStyleBase_Impl temporarily and use the // default method to set the property - SfxItemSet* pRememberItemSet = rBaseImpl.replaceItemSet(&rSetSet); - lcl_SetStyleProperty(rEntry, rPropSet, rVal, rBaseImpl, pPool, pDoc, eFamily); - rBaseImpl.replaceItemSet(pRememberItemSet); + { + SwStyleBase_Impl::ItemSetOverrider o(rBaseImpl, &rSetSet); + lcl_SetStyleProperty(rEntry, rPropSet, rVal, rBaseImpl, pPool, pDoc, eFamily); + } // reset paret at ItemSet from SetItem rSetSet.SetParent(nullptr); @@ -3261,9 +3268,10 @@ void SAL_CALL SwXPageStyle::SetPropertyValues_Impl( // replace the used SfxItemSet at the SwStyleBase_Impl temporarily and use the // default method to set the property - SfxItemSet* pRememberItemSet = aBaseImpl.replaceItemSet(&rSetSet); - lcl_SetStyleProperty(*pEntry, *pPropSet, pValues[nProp], aBaseImpl, m_pBasePool, GetDoc(), GetFamily()); - aBaseImpl.replaceItemSet(pRememberItemSet); + { + SwStyleBase_Impl::ItemSetOverrider o(aBaseImpl, &rSetSet); + lcl_SetStyleProperty(*pEntry, *pPropSet, pValues[nProp], aBaseImpl, m_pBasePool, GetDoc(), GetFamily()); + } // reset paret at ItemSet from SetItem rSetSet.SetParent(nullptr); @@ -3452,9 +3460,10 @@ uno::Sequence< uno::Any > SAL_CALL SwXPageStyle::GetPropertyValues_Impl( { // get from SfxItemSet of the corresponding SfxSetItem const SfxItemSet& rSetSet = pSetItem->GetItemSet(); - SfxItemSet* pRememberItemSet = aBase.replaceItemSet(&const_cast< SfxItemSet& >(rSetSet)); - pRet[nProp] = lcl_GetStyleProperty(*pEntry, *pPropSet, aBase, pBase, GetFamily(), GetDoc() ); - aBase.replaceItemSet(pRememberItemSet); + { + SwStyleBase_Impl::ItemSetOverrider o(aBase, &const_cast< SfxItemSet& >(rSetSet)); + pRet[nProp] = lcl_GetStyleProperty(*pEntry, *pPropSet, aBase, pBase, GetFamily(), GetDoc()); + } } else if(pEntry->nWID == SID_ATTR_PAGE_ON) { @@ -3522,9 +3531,10 @@ uno::Sequence< uno::Any > SAL_CALL SwXPageStyle::GetPropertyValues_Impl( { // set at SfxItemSet of the corresponding SfxSetItem const SfxItemSet& rSetSet = pSetItem->GetItemSet(); - SfxItemSet* pRememberItemSet = aBase.replaceItemSet(&const_cast< SfxItemSet& >(rSetSet)); - pRet[nProp] = lcl_GetStyleProperty(*pEntry, *pPropSet, aBase, pBase, GetFamily(), GetDoc() ); - aBase.replaceItemSet(pRememberItemSet); + { + SwStyleBase_Impl::ItemSetOverrider o(aBase, &const_cast<SfxItemSet&>(rSetSet)); + pRet[nProp] = lcl_GetStyleProperty(*pEntry, *pPropSet, aBase, pBase, GetFamily(), GetDoc()); + } } } else |