sc/source/core/tool/dbdata.cxx | 119 +++++++++++++++++++++++++---------------- 1 file changed, 73 insertions(+), 46 deletions(-)
New commits: commit 8a7be690ced76c5bd790858226a2ff0747354676 Author: Eike Rathke <er...@redhat.com> Date: Tue Sep 1 18:07:04 2015 +0200 TableRef: ensure every column has a name after RefreshTableColumnNames() Change-Id: Ib080b5292e48ea0709217cd4e3e697ae1fa5d4cd diff --git a/sc/source/core/tool/dbdata.cxx b/sc/source/core/tool/dbdata.cxx index adc401a..9c607ba 100644 --- a/sc/source/core/tool/dbdata.cxx +++ b/sc/source/core/tool/dbdata.cxx @@ -643,45 +643,80 @@ private: void ScDBData::RefreshTableColumnNames( ScDocument* pDoc ) { - if (!HasHeader()) - return; // sorry, but.. - ::std::vector<OUString> aNewNames; aNewNames.resize( nEndCol - nStartCol + 1); - ScHorizontalCellIterator aIter( pDoc, nTable, nStartCol, nStartRow, nEndCol, nStartRow); // header row only - ScRefCellValue* pCell; - SCCOL nCol, nLastColFilled = nStartCol - 1; - SCROW nRow; bool bHaveEmpty = false; - for (size_t i=0; (pCell = aIter.GetNext( nCol, nRow)) != nullptr; ++i) + if (!HasHeader()) + bHaveEmpty = true; // Assume we have empty ones and fill below. + else { - if (pCell->hasString()) + ScHorizontalCellIterator aIter( pDoc, nTable, nStartCol, nStartRow, nEndCol, nStartRow); // header row only + ScRefCellValue* pCell; + SCCOL nCol, nLastColFilled = nStartCol - 1; + SCROW nRow; + for (size_t i=0; (pCell = aIter.GetNext( nCol, nRow)) != nullptr; ++i) { - const OUString& rStr = pCell->getString( pDoc); - aNewNames[nCol-nStartCol] = rStr; - if (rStr.isEmpty()) - bHaveEmpty = true; - else if (nLastColFilled < nCol-1) + 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; + nLastColFilled = nCol; + } + else bHaveEmpty = true; - nLastColFilled = nCol; } - else - bHaveEmpty = true; } - // Try to not have empty names and remember previous name that might had - // been used to compile formulas, but only if same number of columns and no - // duplicates. + // Never leave us with empty names, try to remember previous name that + // might had been used to compile formulas, but only if same number of + // columns and no duplicates. if (bHaveEmpty && aNewNames.size() == maTableColumnNames.size()) { + bHaveEmpty = false; for (size_t i=0, n=aNewNames.size(); i < n; ++i) { if (aNewNames[i].isEmpty()) { const OUString& rStr = maTableColumnNames[i]; - auto it( ::std::find_if( aNewNames.begin(), aNewNames.end(), TableColumnNameSearch( rStr))); - if (it == aNewNames.end()) - aNewNames[i] = rStr; + 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; + } + } + } + } + + // If we still have empty ones then fill those with "Column#" with # + // starting at the column offset number. Still no duplicates of course. + if (bHaveEmpty) + { + OUString aColumn( ScGlobal::GetRscString(STR_COLUMN)); + for (size_t i=0, n=aNewNames.size(); i < n; ++i) + { + if (aNewNames[i].isEmpty()) + { + size_t nCount = i+1; + do + { + OUString aStr( aColumn + OUString::number( nCount)); + auto it( ::std::find_if( aNewNames.begin(), aNewNames.end(), TableColumnNameSearch( aStr))); + if (it == aNewNames.end()) + { + aNewNames[i] = aStr; + break; // do while + } + ++nCount; + } while(1); } } } commit b0d6a8ea09148fce6f6c806086835a86eb8ff03d Author: Eike Rathke <er...@redhat.com> Date: Tue Sep 1 17:05:13 2015 +0200 TableRef: reuse TableColumnNameSearch in RefreshTableColumnNames() Change-Id: I354698d6959aeb9ce022ecc420f2e10b0155c184 diff --git a/sc/source/core/tool/dbdata.cxx b/sc/source/core/tool/dbdata.cxx index 46b9b2f..adc401a 100644 --- a/sc/source/core/tool/dbdata.cxx +++ b/sc/source/core/tool/dbdata.cxx @@ -622,6 +622,25 @@ void ScDBData::AdjustTableColumnNames( UpdateRefMode eUpdateRefMode, SCCOL nDx, aNewNames.swap( maTableColumnNames); } +namespace { +class TableColumnNameSearch : public unary_function<ScDBData, bool> +{ +public: + explicit TableColumnNameSearch( const OUString& rSearchName ) : + maSearchName( rSearchName ) + { + } + + bool operator()( const OUString& rName ) const + { + return ScGlobal::GetpTransliteration()->isEqual( maSearchName, rName); + } + +private: + OUString maSearchName; +}; +} + void ScDBData::RefreshTableColumnNames( ScDocument* pDoc ) { if (!HasHeader()) @@ -659,17 +678,9 @@ void ScDBData::RefreshTableColumnNames( ScDocument* pDoc ) { if (aNewNames[i].isEmpty()) { - bool bCopy = true; const OUString& rStr = maTableColumnNames[i]; - for (size_t j=0; j < n; ++j) - { - if (ScGlobal::GetpTransliteration()->isEqual( aNewNames[j], rStr)) - { - bCopy = false; - break; // for - } - } - if (bCopy) + auto it( ::std::find_if( aNewNames.begin(), aNewNames.end(), TableColumnNameSearch( rStr))); + if (it == aNewNames.end()) aNewNames[i] = rStr; } } @@ -678,25 +689,6 @@ void ScDBData::RefreshTableColumnNames( ScDocument* pDoc ) aNewNames.swap( maTableColumnNames); } -namespace { -class TableColumnNameSearch : public unary_function<ScDBData, bool> -{ -public: - explicit TableColumnNameSearch( const OUString& rSearchName ) : - maSearchName( rSearchName ) - { - } - - bool operator()( const OUString& rName ) const - { - return ScGlobal::GetpTransliteration()->isEqual( maSearchName, rName); - } - -private: - OUString maSearchName; -}; -} - sal_Int32 ScDBData::GetColumnNameOffset( const OUString& rName ) const { if (maTableColumnNames.empty()) _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits