Kaydet (Commit) 1b95eb30 authored tarafından Noel Grandin's avatar Noel Grandin

loplugin:useuniqueptr in ScColumnRowStylesBase

Change-Id: I44e9cb38f57684930a94bd1f185e87a9605b65c2
Reviewed-on: https://gerrit.libreoffice.org/59225
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 7125c679
......@@ -982,18 +982,11 @@ ScColumnRowStylesBase::ScColumnRowStylesBase()
ScColumnRowStylesBase::~ScColumnRowStylesBase()
{
auto i(aStyleNames.begin());
auto endi(aStyleNames.end());
while (i != endi)
{
delete *i;
++i;
}
}
sal_Int32 ScColumnRowStylesBase::AddStyleName(OUString* pString)
sal_Int32 ScColumnRowStylesBase::AddStyleName(const OUString & rString)
{
aStyleNames.push_back(pString);
aStyleNames.push_back(rString);
return aStyleNames.size() - 1;
}
......@@ -1002,7 +995,7 @@ sal_Int32 ScColumnRowStylesBase::GetIndexOfStyleName(const OUString& rString, co
sal_Int32 nPrefixLength(rPrefix.getLength());
OUString sTemp(rString.copy(nPrefixLength));
sal_Int32 nIndex(sTemp.toInt32());
if (nIndex > 0 && static_cast<size_t>(nIndex-1) < aStyleNames.size() && *aStyleNames.at(nIndex - 1) == rString)
if (nIndex > 0 && static_cast<size_t>(nIndex-1) < aStyleNames.size() && aStyleNames.at(nIndex - 1) == rString)
return nIndex - 1;
else
{
......@@ -1010,7 +1003,7 @@ sal_Int32 ScColumnRowStylesBase::GetIndexOfStyleName(const OUString& rString, co
bool bFound(false);
while (!bFound && static_cast<size_t>(i) < aStyleNames.size())
{
if (*aStyleNames.at(i) == rString)
if (aStyleNames.at(i) == rString)
bFound = true;
else
++i;
......@@ -1022,15 +1015,8 @@ sal_Int32 ScColumnRowStylesBase::GetIndexOfStyleName(const OUString& rString, co
}
}
OUString* ScColumnRowStylesBase::GetStyleNameByIndex(const sal_Int32 nIndex)
OUString& ScColumnRowStylesBase::GetStyleNameByIndex(const sal_Int32 nIndex)
{
if ( nIndex < 0 || nIndex >= sal::static_int_cast<sal_Int32>( aStyleNames.size() ) )
{
// should no longer happen, use first style then
OSL_FAIL("GetStyleNameByIndex: invalid index");
return aStyleNames[0];
}
return aStyleNames[nIndex];
}
......
......@@ -205,16 +205,16 @@ public:
class ScColumnRowStylesBase
{
std::vector<OUString*> aStyleNames;
std::vector<OUString> aStyleNames;
public:
ScColumnRowStylesBase();
virtual ~ScColumnRowStylesBase();
virtual void AddNewTable(const sal_Int32 nTable, const sal_Int32 nFields) = 0;
sal_Int32 AddStyleName(OUString* pString);
sal_Int32 AddStyleName(const OUString & rString);
sal_Int32 GetIndexOfStyleName(const OUString& rString, const OUString& rPrefix);
OUString* GetStyleNameByIndex(const sal_Int32 nIndex);
OUString& GetStyleNameByIndex(const sal_Int32 nIndex);
};
struct ScColumnStyle
......
......@@ -747,7 +747,7 @@ void ScXMLExport::WriteSingleColumn(const sal_Int32 nRepeatColumns, const sal_In
const sal_Int32 nIndex, const bool bIsAutoStyle, const bool bIsVisible)
{
CheckAttrList();
AddAttribute(sAttrStyleName, *pColumnStyles->GetStyleNameByIndex(nStyleIndex));
AddAttribute(sAttrStyleName, pColumnStyles->GetStyleNameByIndex(nStyleIndex));
if (!bIsVisible)
AddAttribute(XML_NAMESPACE_TABLE, XML_VISIBILITY, XML_COLLAPSE);
if (nRepeatColumns > 1)
......@@ -1365,7 +1365,7 @@ void ScXMLExport::WriteRowStartTag(
const sal_Int32 nIndex, const sal_Int32 nEqualRows,
bool bHidden, bool bFiltered)
{
AddAttribute(sAttrStyleName, *pRowStyles->GetStyleNameByIndex(nIndex));
AddAttribute(sAttrStyleName, pRowStyles->GetStyleNameByIndex(nIndex));
if (bHidden)
{
if (bFiltered)
......@@ -2202,8 +2202,7 @@ void ScXMLExport::AddStyleFromColumn(const uno::Reference<beans::XPropertySet>&
{
GetAutoStylePool()->RegisterName(XML_STYLE_FAMILY_TABLE_COLUMN, *pOldName);
// add to pColumnStyles, so the name is found for normal sheets
OUString* pTemp(new OUString(*pOldName));
rIndex = pColumnStyles->AddStyleName(pTemp);
rIndex = pColumnStyles->AddStyleName(*pOldName);
}
}
else
......@@ -2211,8 +2210,7 @@ void ScXMLExport::AddStyleFromColumn(const uno::Reference<beans::XPropertySet>&
OUString sName;
if (GetAutoStylePool()->Add(sName, XML_STYLE_FAMILY_TABLE_COLUMN, sParent, aPropStates))
{
OUString* pTemp(new OUString(sName));
rIndex = pColumnStyles->AddStyleName(pTemp);
rIndex = pColumnStyles->AddStyleName(sName);
}
else
rIndex = pColumnStyles->GetIndexOfStyleName(sName, XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_PREFIX);
......@@ -2233,8 +2231,7 @@ void ScXMLExport::AddStyleFromRow(const uno::Reference<beans::XPropertySet>& xRo
{
GetAutoStylePool()->RegisterName(XML_STYLE_FAMILY_TABLE_ROW, *pOldName);
// add to pRowStyles, so the name is found for normal sheets
OUString* pTemp(new OUString(*pOldName));
rIndex = pRowStyles->AddStyleName(pTemp);
rIndex = pRowStyles->AddStyleName(*pOldName);
}
}
else
......@@ -2242,8 +2239,7 @@ void ScXMLExport::AddStyleFromRow(const uno::Reference<beans::XPropertySet>& xRo
OUString sName;
if (GetAutoStylePool()->Add(sName, XML_STYLE_FAMILY_TABLE_ROW, sParent, aPropStates))
{
OUString* pTemp(new OUString(sName));
rIndex = pRowStyles->AddStyleName(pTemp);
rIndex = pRowStyles->AddStyleName(sName);
}
else
rIndex = pRowStyles->GetIndexOfStyleName(sName, XML_STYLE_FAMILY_TABLE_ROW_STYLES_PREFIX);
......
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