Kaydet (Commit) f0306eee authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl Kaydeden (comit) Tomaž Vajngerl

TSCP: extract some functions, simplify code

Change-Id: I993b272b0976e857506041794f5c00183e5854a9
Reviewed-on: https://gerrit.libreoffice.org/44017Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarTomaž Vajngerl <quikee@gmail.com>
üst 7ca48ce4
......@@ -34,6 +34,7 @@
#include <com/sun/star/beans/PropertyAttribute.hpp>
#include <comphelper/processfactory.hxx>
#include <comphelper/scopeguard.hxx>
#include <editeng/editdata.hxx>
#include <editeng/eeitem.hxx>
......@@ -258,95 +259,62 @@ bool hasCustomPropertyField(std::vector<editeng::Section> const & aSections, OUS
return false;
}
OUString getWeightString(SfxItemSet const & rItemSet)
{
OUString sWeightString = "NORMAL";
if (const SfxPoolItem* pItem = rItemSet.GetItem(EE_CHAR_WEIGHT, false))
{
const SvxWeightItem* pWeightItem = dynamic_cast<const SvxWeightItem*>(pItem);
if (pWeightItem && pWeightItem->GetWeight() == WEIGHT_BOLD)
sWeightString = "BOLD";
}
return sWeightString;
}
} // end anonymous namespace
class ClassificationCollector
class ClassificationCommon
{
private:
protected:
sd::DrawViewShell& m_rDrawViewShell;
std::vector<svx::ClassificationResult> m_aResults;
public:
ClassificationCollector(sd::DrawViewShell & rDrawViewShell)
ClassificationCommon(sd::DrawViewShell & rDrawViewShell)
: m_rDrawViewShell(rDrawViewShell)
{}
};
std::vector<svx::ClassificationResult> getResults()
{
return m_aResults;
}
class ClassificationCollector : public ClassificationCommon
{
private:
std::vector<svx::ClassificationResult> m_aResults;
bool collect()
void iterateSectionsAndCollect(std::vector<editeng::Section> const & rSections, EditTextObject const & rEditText)
{
OUString sPolicy = SfxClassificationHelper::policyTypeToString(SfxClassificationHelper::getPolicyType());
OUString sKey = sPolicy + "BusinessAuthorizationCategory:Name";
uno::Reference<document::XDocumentProperties> xDocumentProperties = SfxObjectShell::Current()->getDocProperties();
// Properties
uno::Reference<beans::XPropertyContainer> xPropertyContainer = xDocumentProperties->getUserDefinedProperties();
// Set to MASTER mode
EditMode eOldMode = m_rDrawViewShell.GetEditMode();
if (eOldMode != EditMode::MasterPage)
m_rDrawViewShell.ChangeEditMode(EditMode::MasterPage, false);
const sal_uInt16 nCount = m_rDrawViewShell.GetDoc()->GetMasterSdPageCount(PageKind::Standard);
bool bFound = false;
for (sal_uInt16 nPageIndex = 0; nPageIndex < nCount; ++nPageIndex)
{
SdPage* pMasterPage = m_rDrawViewShell.GetDoc()->GetMasterSdPage(nPageIndex, PageKind::Standard);
for (size_t nObject = 0; nObject < pMasterPage->GetObjCount(); ++nObject)
{
SdrObject* pObject = pMasterPage->GetObj(nObject);
SdrRectObj* pRectObject = dynamic_cast<SdrRectObj*>(pObject);
if (pRectObject && pRectObject->GetTextKind() == OBJ_TEXT)
{
OutlinerParaObject* pOutlinerParagraphObject = pRectObject->GetOutlinerParaObject();
if (pOutlinerParagraphObject)
{
const EditTextObject& rEditText = pOutlinerParagraphObject->GetTextObject();
std::vector<editeng::Section> aSections;
rEditText.GetAllSections(aSections);
if (hasCustomPropertyField(aSections, sKey))
{
bFound = true;
const OUString sBlank("");
sal_Int32 nCurrentParagraph = -1;
OUString sBlank;
for (editeng::Section const & rSection : aSections)
for (editeng::Section const & rSection : rSections)
{
// Insert new paragraph if needed
while (nCurrentParagraph < rSection.mnParagraph)
{
nCurrentParagraph++;
// Get Weight of current paragraph
FontWeight eFontWeight = WEIGHT_NORMAL;
SfxItemSet aItemSet(rEditText.GetParaAttribs(nCurrentParagraph));
if (const SfxPoolItem* pItem = aItemSet.GetItem(EE_CHAR_WEIGHT, false))
{
const SvxWeightItem* pWeightItem = dynamic_cast<const SvxWeightItem*>(pItem);
if (pWeightItem && pWeightItem->GetWeight() == WEIGHT_BOLD)
eFontWeight = WEIGHT_BOLD;
}
// Font weight to string
OUString sWeightProperty = "NORMAL";
if (eFontWeight == WEIGHT_BOLD)
sWeightProperty = "BOLD";
// Insert into collection
OUString sWeightProperty = getWeightString(rEditText.GetParaAttribs(nCurrentParagraph));
// Insert new paragraph into collection
m_aResults.push_back({ svx::ClassificationType::PARAGRAPH, sWeightProperty, sBlank });
}
const SvxFieldItem* pFieldItem = findField(rSection);
const editeng::CustomPropertyField* pCustomPropertyField = pFieldItem ? dynamic_cast<const editeng::CustomPropertyField*>(pFieldItem->GetField()) : nullptr;
if (pCustomPropertyField)
if (pFieldItem)
{
const auto* pCustomPropertyField = dynamic_cast<const editeng::CustomPropertyField*>(pFieldItem->GetField());
OUString aKey = pCustomPropertyField->GetKey();
if (aKey.startsWith(sPolicy + "Marking:Text:"))
{
......@@ -371,6 +339,52 @@ public:
}
}
}
public:
ClassificationCollector(sd::DrawViewShell & rDrawViewShell)
: ClassificationCommon(rDrawViewShell)
{}
std::vector<svx::ClassificationResult> getResults()
{
return m_aResults;
}
bool collect()
{
OUString sPolicy = SfxClassificationHelper::policyTypeToString(SfxClassificationHelper::getPolicyType());
OUString sKey = sPolicy + "BusinessAuthorizationCategory:Name";
// Set to MASTER mode
EditMode eOldMode = m_rDrawViewShell.GetEditMode();
if (eOldMode != EditMode::MasterPage)
m_rDrawViewShell.ChangeEditMode(EditMode::MasterPage, false);
const sal_uInt16 nCount = m_rDrawViewShell.GetDoc()->GetMasterSdPageCount(PageKind::Standard);
bool bFound = false;
for (sal_uInt16 nPageIndex = 0; nPageIndex < nCount; ++nPageIndex)
{
SdPage* pMasterPage = m_rDrawViewShell.GetDoc()->GetMasterSdPage(nPageIndex, PageKind::Standard);
for (size_t nObject = 0; nObject < pMasterPage->GetObjCount(); ++nObject)
{
SdrObject* pObject = pMasterPage->GetObj(nObject);
SdrRectObj* pRectObject = dynamic_cast<SdrRectObj*>(pObject);
if (pRectObject && pRectObject->GetTextKind() == OBJ_TEXT)
{
OutlinerParaObject* pOutlinerParagraphObject = pRectObject->GetOutlinerParaObject();
if (pOutlinerParagraphObject)
{
const EditTextObject& rEditText = pOutlinerParagraphObject->GetTextObject();
std::vector<editeng::Section> aSections;
rEditText.GetAllSections(aSections);
if (hasCustomPropertyField(aSections, sKey))
{
bFound = true;
iterateSectionsAndCollect(aSections, rEditText);
}
}
}
}
......@@ -383,11 +397,9 @@ public:
}
};
class ClassificationInserter
class ClassificationInserter : public ClassificationCommon
{
private:
sd::DrawViewShell& m_rDrawViewShell;
/// Delete the previous existing classification object(s) - if they exists
void deleteExistingObjects()
{
......@@ -424,7 +436,7 @@ private:
public:
ClassificationInserter(sd::DrawViewShell & rDrawViewShell)
: m_rDrawViewShell(rDrawViewShell)
: ClassificationCommon(rDrawViewShell)
{}
......@@ -435,14 +447,19 @@ public:
if (eOldMode != EditMode::MasterPage)
m_rDrawViewShell.ChangeEditMode(EditMode::MasterPage, false);
// Scoped guard to revert the mode
comphelper::ScopeGuard const aGuard([this, eOldMode] () {
m_rDrawViewShell.ChangeEditMode(eOldMode, false);
});
// Delete the previous existing object - if exists
deleteExistingObjects();
// Document properties
uno::Reference<document::XDocumentProperties> xDocumentProperties = SfxObjectShell::Current()->getDocProperties();
// Clear properties
uno::Reference<beans::XPropertyContainer> xPropertyContainer = xDocumentProperties->getUserDefinedProperties();
// Clear properties
lcl_removeAllProperties(xPropertyContainer);
SfxClassificationHelper aHelper(xDocumentProperties);
......@@ -545,9 +562,6 @@ public:
m_rDrawViewShell.GetDrawView()->InsertObjectAtView(pRectObj, *m_rDrawViewShell.GetDrawView()->GetSdrPageView());
pOutliner->Init(eOutlinerMode);
// Revert edit mode
m_rDrawViewShell.ChangeEditMode(eOldMode, false);
return true;
}
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment