diff options
author | Eike Rathke <erack@redhat.com> | 2015-09-04 20:44:10 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2015-09-04 21:14:44 +0200 |
commit | f8c14e81cb63ea077109a4b0147e716cae41ab1b (patch) | |
tree | 73e9e38773ab7063a317008ecdf0b61cc7a87ca2 /sc/source | |
parent | bc77f2c67c747b89e2c661ed86b8b48acd8ce317 (diff) |
TablreRef: always use SetTableColumnName() to prevent duplicates
Change-Id: Ifbdd9b0c3d8e6f41c4d1eb4d0e62053a8788e05d
Diffstat (limited to 'sc/source')
-rw-r--r-- | sc/source/core/tool/dbdata.cxx | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/sc/source/core/tool/dbdata.cxx b/sc/source/core/tool/dbdata.cxx index 852c511796d8..d9bfcd26831e 100644 --- a/sc/source/core/tool/dbdata.cxx +++ b/sc/source/core/tool/dbdata.cxx @@ -738,12 +738,21 @@ private: }; /** Set a numbered table column name at given nIndex, preventing duplicates, - numbering starting at nCount. No check whether nIndex is valid. */ -void SetTableColumnName( ::std::vector<OUString>& rVec, size_t nIndex, const OUString& rName, sal_Int32 nCount ) + numbering starting at nCount. If nCount==0 then the first attempt is made + 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 { - 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))); if (it == rVec.end()) { @@ -773,11 +782,14 @@ void ScDBData::RefreshTableColumnNames( ScDocument* pDoc ) if (pCell->hasString()) { const OUString& rStr = pCell->getString( pDoc); - aNewNames[nCol-nStartCol] = rStr; if (rStr.isEmpty()) bHaveEmpty = true; - else if (nLastColFilled < nCol-1) - bHaveEmpty = true; + else + { + SetTableColumnName( aNewNames, nCol-nStartCol, rStr, 0); + if (nLastColFilled < nCol-1) + bHaveEmpty = true; + } nLastColFilled = nCol; } else @@ -799,13 +811,7 @@ void ScDBData::RefreshTableColumnNames( ScDocument* pDoc ) if (rStr.isEmpty()) bHaveEmpty = true; else - { - auto it( ::std::find_if( aNewNames.begin(), aNewNames.end(), TableColumnNameSearch( rStr))); - if (it == aNewNames.end()) - aNewNames[i] = rStr; - else - bHaveEmpty = true; - } + SetTableColumnName( aNewNames, i, rStr, 0); } } } |