summaryrefslogtreecommitdiff
path: root/sw/source/uibase
diff options
context:
space:
mode:
authorMaxim Monastirsky <momonasmon@gmail.com>2023-06-21 09:07:20 +0300
committerMaxim Monastirsky <momonasmon@gmail.com>2023-06-23 17:26:42 +0200
commit759d414748bda99f29b04806f72d479e320c2f9f (patch)
treee3afed0b8f2ec77feabfc9f84118ff4b81cd851b /sw/source/uibase
parentdf29592493367bc03c9602c924711852eecf64c4 (diff)
tdf#103064 Simplify the code a bit
- Use SfxItemIter instead of manually iterating the ranges. While SwFormat::GetItemState does some extra stuff on top of SfxItemSet, it doesn't seem to be relevant for our use case. - Avoid searching for styles again and again. Change-Id: I397dd71a5ffb8cbf7d508b68abb3fc1b585938af Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153479 Tested-by: Jenkins Reviewed-by: Maxim Monastirsky <momonasmon@gmail.com>
Diffstat (limited to 'sw/source/uibase')
-rw-r--r--sw/source/uibase/app/docstyle.cxx109
1 files changed, 48 insertions, 61 deletions
diff --git a/sw/source/uibase/app/docstyle.cxx b/sw/source/uibase/app/docstyle.cxx
index e50c087d23fc..c78966a762e6 100644
--- a/sw/source/uibase/app/docstyle.cxx
+++ b/sw/source/uibase/app/docstyle.cxx
@@ -151,8 +151,7 @@ public:
if (nId == SfxHintId::StyleSheetModified)
{
pStyleSheet->SetName(pDocStyleSheet->GetName());
- pStyleSheet->GetItemSet().ClearItem();
- EnsureStyleHierarchy(pDocStyleSheet->GetName(), pDocStyleSheet->GetFamily());
+ UpdateStyleHierarchyFrom(pStyleSheet, pDocStyleSheet);
static_cast<SfxStyleSheet*>(pStyleSheet)->Broadcast(SfxHint(SfxHintId::DataChanged));
}
else if (nId == SfxHintId::StyleSheetErased)
@@ -162,21 +161,19 @@ public:
SfxStyleSheetBase* Find(const OUString& rName, SfxStyleFamily eFamily,
SfxStyleSearchBits = SfxStyleSearchBits::All) override
{
- if (eFamily != SfxStyleFamily::All)
- EnsureStyleHierarchy(rName, eFamily);
- return SfxStyleSheetPool::Find(rName, eFamily);
- }
+ auto pStyleSheet = SfxStyleSheetPool::Find(rName, eFamily);
- void EnsureStyleHierarchy(const OUString& rName, SfxStyleFamily eFamily)
- {
- auto pDocStyleSheet = m_pOwner->Find(rName, eFamily);
- if (!pDocStyleSheet)
- return;
+ if (auto pDocStyleSheet = pStyleSheet ? nullptr : m_pOwner->Find(rName, eFamily))
+ {
+ pStyleSheet = &Make(pDocStyleSheet->GetName(), pDocStyleSheet->GetFamily());
+ UpdateStyleHierarchyFrom(pStyleSheet, pDocStyleSheet);
+ }
- auto pStyleSheet = SfxStyleSheetPool::Find(rName, eFamily);
- if (!pStyleSheet)
- pStyleSheet = &Make(rName, eFamily);
+ return pStyleSheet;
+ }
+ void UpdateStyleHierarchyFrom(SfxStyleSheetBase* pStyleSheet, SfxStyleSheetBase* pDocStyleSheet)
+ {
FillItemSet(pStyleSheet, pDocStyleSheet);
// Remember now, as the next calls will invalidate pDocStyleSheet.
@@ -193,61 +190,50 @@ public:
void FillItemSet(SfxStyleSheetBase* pDestSheet, SfxStyleSheetBase* pSourceSheet)
{
auto& rItemSet = pDestSheet->GetItemSet();
- if (rItemSet.Count() > 0)
- return;
+ rItemSet.ClearItem();
auto pCol = static_cast<SwDocStyleSheet*>(pSourceSheet)->GetCollection();
- if (!pCol->GetAttrSet().Count())
- return;
-
- const WhichRangesContainer aRanges(svl::Items<RES_CHRATR_BEGIN, RES_CHRATR_END,
- RES_PARATR_BEGIN, RES_PARATR_END,
- RES_FRMATR_BEGIN, RES_FRMATR_END>);
+ SfxItemIter aIter(pCol->GetAttrSet());
+ std::optional<SvxLRSpaceItem> oLRSpaceItem;
- for (const auto& range : aRanges)
+ for (auto pItem = aIter.GetCurItem(); pItem; pItem = aIter.NextItem())
{
- std::optional<SvxLRSpaceItem> oLRSpaceItem;
+ if (aIter.GetItemState(false) != SfxItemState::SET)
+ continue;
- for (auto i = range.first; i < range.second; ++i)
+ auto nWhich = pItem->Which();
+ auto nSlotId = rPool.GetSlotId(nWhich);
+ auto nNewWhich = rPool.GetSecondaryPool()->GetWhich(nSlotId);
+ if (nNewWhich != nSlotId)
+ rItemSet.Put(pItem->CloneSetWhich(nNewWhich));
+ else if (nWhich == RES_MARGIN_FIRSTLINE)
{
- const SfxPoolItem* pItem;
- if (pCol->GetItemState(i, false, &pItem) != SfxItemState::SET)
- continue;
-
- auto nSlotId = rPool.GetSlotId(i);
- auto nNewWhich = rPool.GetSecondaryPool()->GetWhich(nSlotId);
- if (nNewWhich != nSlotId)
- rItemSet.Put(pItem->CloneSetWhich(nNewWhich));
- else if (i == RES_MARGIN_FIRSTLINE)
- {
- if (!oLRSpaceItem)
- oLRSpaceItem.emplace(EE_PARA_LRSPACE);
- auto pFirstLineItem = static_cast<const SvxFirstLineIndentItem*>(pItem);
- (*oLRSpaceItem).SetTextFirstLineOffsetValue(pFirstLineItem->GetTextFirstLineOffset());
- (*oLRSpaceItem).SetAutoFirst(pFirstLineItem->IsAutoFirst());
- }
- else if (i == RES_MARGIN_TEXTLEFT)
- {
- if (!oLRSpaceItem)
- oLRSpaceItem.emplace(EE_PARA_LRSPACE);
- (*oLRSpaceItem).SetTextLeft(static_cast<const SvxTextLeftMarginItem*>(pItem)->GetTextLeft());
- }
- else if (i == RES_MARGIN_RIGHT)
- {
- if (!oLRSpaceItem)
- oLRSpaceItem.emplace(EE_PARA_LRSPACE);
- (*oLRSpaceItem).SetRight(static_cast<const SvxRightMarginItem*>(pItem)->GetRight());
- }
- else if (i == RES_CHRATR_BACKGROUND)
- {
- auto pBrushItem = static_cast<const SvxBrushItem*>(pItem);
- rItemSet.Put(SvxColorItem(pBrushItem->GetColor(), EE_CHAR_BKGCOLOR));
- }
+ if (!oLRSpaceItem)
+ oLRSpaceItem.emplace(EE_PARA_LRSPACE);
+ auto pFirstLineItem = static_cast<const SvxFirstLineIndentItem*>(pItem);
+ (*oLRSpaceItem).SetTextFirstLineOffsetValue(pFirstLineItem->GetTextFirstLineOffset());
+ (*oLRSpaceItem).SetAutoFirst(pFirstLineItem->IsAutoFirst());
+ }
+ else if (nWhich == RES_MARGIN_TEXTLEFT)
+ {
+ if (!oLRSpaceItem)
+ oLRSpaceItem.emplace(EE_PARA_LRSPACE);
+ (*oLRSpaceItem).SetTextLeft(static_cast<const SvxTextLeftMarginItem*>(pItem)->GetTextLeft());
+ }
+ else if (nWhich == RES_MARGIN_RIGHT)
+ {
+ if (!oLRSpaceItem)
+ oLRSpaceItem.emplace(EE_PARA_LRSPACE);
+ (*oLRSpaceItem).SetRight(static_cast<const SvxRightMarginItem*>(pItem)->GetRight());
+ }
+ else if (nWhich == RES_CHRATR_BACKGROUND)
+ {
+ auto pBrushItem = static_cast<const SvxBrushItem*>(pItem);
+ rItemSet.Put(SvxColorItem(pBrushItem->GetColor(), EE_CHAR_BKGCOLOR));
}
-
- if (oLRSpaceItem)
- rItemSet.Put(*oLRSpaceItem);
}
+ if (oLRSpaceItem)
+ rItemSet.Put(*oLRSpaceItem);
}
};
@@ -2767,6 +2753,7 @@ bool SwDocStyleSheetPool::SetParent( SfxStyleFamily eFam,
if( bRet )
{
// only for Broadcasting
+ mxStyleSheet->SetPhysical( false );
mxStyleSheet->PresetName( rStyle );
mxStyleSheet->PresetParent( rParent );
if( SfxStyleFamily::Para == eFam )