TablreRef: always use SetTableColumnName() to prevent duplicates

Change-Id: Ifbdd9b0c3d8e6f41c4d1eb4d0e62053a8788e05d
This commit is contained in:
Eike Rathke
2015-09-04 20:44:10 +02:00
parent bc77f2c67c
commit f8c14e81cb

View File

@@ -738,12 +738,21 @@ private:
}; };
/** Set a numbered table column name at given nIndex, preventing duplicates, /** Set a numbered table column name at given nIndex, preventing duplicates,
numbering starting at nCount. No check whether nIndex is valid. */ numbering starting at nCount. If nCount==0 then the first attempt is made
void SetTableColumnName( ::std::vector<OUString>& rVec, size_t nIndex, const OUString& rName, sal_Int32 nCount ) with an unnumbered name and if already present the next attempt with
nCount=2, so "Original" and "Original2". No check whether nIndex is valid. */
void SetTableColumnName( ::std::vector<OUString>& rVec, size_t nIndex, const OUString& rName, size_t nCount )
{ {
OUString aStr;
do do
{ {
OUString aStr( rName + OUString::number( nCount)); if (nCount)
aStr = rName + OUString::number( nCount);
else
{
aStr = rName;
++nCount;
}
auto it( ::std::find_if( rVec.begin(), rVec.end(), TableColumnNameSearch( aStr))); auto it( ::std::find_if( rVec.begin(), rVec.end(), TableColumnNameSearch( aStr)));
if (it == rVec.end()) if (it == rVec.end())
{ {
@@ -773,11 +782,14 @@ void ScDBData::RefreshTableColumnNames( ScDocument* pDoc )
if (pCell->hasString()) if (pCell->hasString())
{ {
const OUString& rStr = pCell->getString( pDoc); const OUString& rStr = pCell->getString( pDoc);
aNewNames[nCol-nStartCol] = rStr;
if (rStr.isEmpty()) if (rStr.isEmpty())
bHaveEmpty = true; bHaveEmpty = true;
else if (nLastColFilled < nCol-1) else
bHaveEmpty = true; {
SetTableColumnName( aNewNames, nCol-nStartCol, rStr, 0);
if (nLastColFilled < nCol-1)
bHaveEmpty = true;
}
nLastColFilled = nCol; nLastColFilled = nCol;
} }
else else
@@ -799,13 +811,7 @@ void ScDBData::RefreshTableColumnNames( ScDocument* pDoc )
if (rStr.isEmpty()) if (rStr.isEmpty())
bHaveEmpty = true; bHaveEmpty = true;
else else
{ SetTableColumnName( aNewNames, i, rStr, 0);
auto it( ::std::find_if( aNewNames.begin(), aNewNames.end(), TableColumnNameSearch( rStr)));
if (it == aNewNames.end())
aNewNames[i] = rStr;
else
bHaveEmpty = true;
}
} }
} }
} }