diff options
author | Jim Raykowski <raykowj@gmail.com> | 2021-12-30 20:25:05 -0900 |
---|---|---|
committer | Jim Raykowski <raykowj@gmail.com> | 2022-01-16 22:15:34 +0100 |
commit | bf28e1df0a04cf6a06d9c4cf591e238a45a34ec1 (patch) | |
tree | a9120414d9e91e182ee6312bb10dce5abfb39a9b /sw/source/uibase/utlui | |
parent | 8728cebf75b127e5a0d6a043bbed40a1c9e34641 (diff) |
SwNavigator: use one loop instead of two to fill fields member list
Change-Id: I02f20e48606a34b2f9f4739f1777dd8aea8637ae
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127798
Tested-by: Jenkins
Reviewed-by: Jim Raykowski <raykowj@gmail.com>
Diffstat (limited to 'sw/source/uibase/utlui')
-rw-r--r-- | sw/source/uibase/utlui/content.cxx | 118 |
1 files changed, 54 insertions, 64 deletions
diff --git a/sw/source/uibase/utlui/content.cxx b/sw/source/uibase/utlui/content.cxx index 0a796d77711e..9f8cfca2e0a2 100644 --- a/sw/source/uibase/utlui/content.cxx +++ b/sw/source/uibase/utlui/content.cxx @@ -412,14 +412,11 @@ void SwContentType::Init(bool* pbInvalidateWindow) for (size_t i = 0; i < nSize; ++i) { const SwFieldType* pFieldType = rFieldTypes[i].get(); + if (pFieldType->Which() == SwFieldIds::Postit) + continue; std::vector<SwFormatField*> vFields; pFieldType->GatherFields(vFields); - for (SwFormatField* pFormatField: vFields) - { - SwField* pField = pFormatField->GetField(); - if (pField && pField->GetTypeId() != SwFieldTypesEnum::Postit) - m_nMemberCount++; - } + m_nMemberCount += vFields.size(); } } break; @@ -791,82 +788,75 @@ void SwContentType::FillMemberList(bool* pbLevelOrVisibilityChanged) break; case ContentTypeId::TEXTFIELD: { - // sorted list of all fields - meaning in the order they are in the document model - SetGetExpFields aSrtLst; const SwFieldTypes& rFieldTypes = *m_pWrtShell->GetDoc()->getIDocumentFieldsAccess().GetFieldTypes(); const size_t nSize = rFieldTypes.size(); for (size_t i = 0; i < nSize; ++i) { const SwFieldType* pFieldType = rFieldTypes[i].get(); + if (pFieldType->Which() == SwFieldIds::Postit) + continue; std::vector<SwFormatField*> vFields; pFieldType->GatherFields(vFields); - for (SwFormatField* pFormatField: vFields) + std::vector<OUString> aSubTypesList; + if (pFieldType->Which() == SwFieldIds::DocStat && !vFields.empty()) { - SwTextField* pTextField = pFormatField->GetTextField(); - SwField* pField = pFormatField->GetField(); - if (pTextField && pField && pField->GetTypeId() != SwFieldTypesEnum::Postit) - { - const SwTextNode& rTextNode = pTextField->GetTextNode(); - std::unique_ptr<SetGetExpField> - pNew(new SetGetExpField(SwNodeIndex(rTextNode), pTextField)); - aSrtLst.insert(std::move(pNew)); - } - } - } - for (size_t i = 0; i < aSrtLst.size(); ++i) - { - const SwTextField* pTextField = aSrtLst[i]->GetTextField(); - const SwFormatField& rFormatField = pTextField->GetFormatField(); - const SwField* pField = rFormatField.GetField(); - OUString sExpandedField(pField->ExpandField(true, m_pWrtShell->GetLayout())); - if (!sExpandedField.isEmpty()) - sExpandedField = u" - " + sExpandedField; - OUString sText = pField->GetDescription() + u" - " + pField->GetFieldName() - + sExpandedField; - if (pField->GetTypeId() == SwFieldTypesEnum::DocumentStatistics) - { - SwFieldMgr aFieldMgr(m_pWrtShell); - std::vector<OUString> aLst; - aFieldMgr.GetSubTypes(SwFieldTypesEnum::DocumentStatistics, aLst); - OUString sSubType; - if (pField->GetSubType() < aLst.size()) - sSubType = u" - " + aLst[pField->GetSubType()]; - sText = pField->GetDescription() + u" - " + pField->GetFieldName() + sSubType - + sExpandedField; + SwFieldMgr(m_pWrtShell).GetSubTypes(SwFieldTypesEnum::DocumentStatistics, + aSubTypesList); } - else if (pField->GetTypeId() == SwFieldTypesEnum::GetRef) + for (SwFormatField* pFormatField: vFields) { - OUString sExpandedTextOfReferencedTextNode; - if (const SwGetRefField* pRefField(dynamic_cast<const SwGetRefField*>(pField)); - pRefField) + if (SwTextField* pTextField = pFormatField->GetTextField()) { - if (pRefField->IsRefToHeadingCrossRefBookmark() || - pRefField->IsRefToNumItemCrossRefBookmark()) + const SwField* pField = pFormatField->GetField(); + OUString sExpandField(pField->ExpandField(true, m_pWrtShell->GetLayout())); + if (!sExpandField.isEmpty()) + sExpandField = u" - " + sExpandField; + OUString sText = pField->GetDescription() + u" - " + pField->GetFieldName() + + sExpandField; + if (pField->GetTypeId() == SwFieldTypesEnum::DocumentStatistics) { - sExpandedTextOfReferencedTextNode = u" - " + - pRefField->GetExpandedTextOfReferencedTextNode(*m_pWrtShell-> - GetLayout()); - if (sExpandedTextOfReferencedTextNode.getLength() > 80) - { - sExpandedTextOfReferencedTextNode = - OUString::Concat( - sExpandedTextOfReferencedTextNode.subView(0, 80)) + - u"..."; - } + OUString sSubType; + if (pField->GetSubType() < aSubTypesList.size()) + sSubType = u" - " + aSubTypesList[pField->GetSubType()]; + sText = pField->GetDescription() + u" - " + pField->GetFieldName() + + sSubType + sExpandField; } - else + else if (pField->GetTypeId() == SwFieldTypesEnum::GetRef) { - sExpandedTextOfReferencedTextNode = u" - " + pRefField->GetSetRefName(); + OUString sExpandedTextOfReferencedTextNode; + if (const SwGetRefField* pRefField( + dynamic_cast<const SwGetRefField*>(pField)); pRefField) + { + if (pRefField->IsRefToHeadingCrossRefBookmark() || + pRefField->IsRefToNumItemCrossRefBookmark()) + { + sExpandedTextOfReferencedTextNode = u" - " + + pRefField->GetExpandedTextOfReferencedTextNode( + *m_pWrtShell->GetLayout()); + if (sExpandedTextOfReferencedTextNode.getLength() > 80) + { + sExpandedTextOfReferencedTextNode = + OUString::Concat( + sExpandedTextOfReferencedTextNode.subView( + 0, 80)) + u"..."; + } + } + else + { + sExpandedTextOfReferencedTextNode = u" - " + + pRefField->GetSetRefName(); + } + } + sText = pField->GetDescription() + sExpandedTextOfReferencedTextNode; } + auto pCnt(std::make_unique<SwTextFieldContent>(this, sText, pFormatField, + pTextField->GetTextNode().GetIndex().get())); + if (!pTextField->GetTextNode().getLayoutFrame(m_pWrtShell->GetLayout())) + pCnt->SetInvisible(); + m_pMember->insert(std::move(pCnt)); } - sText = pField->GetDescription() + sExpandedTextOfReferencedTextNode; } - std::unique_ptr<SwTextFieldContent> pCnt(new SwTextFieldContent(this, sText, - &rFormatField, i)); - if (!pTextField->GetTextNode().getLayoutFrame(m_pWrtShell->GetLayout())) - pCnt->SetInvisible(); - m_pMember->insert(std::move(pCnt)); } m_nMemberCount = m_pMember->size(); } |