sc/inc/column.hxx | 3 + sc/inc/table.hxx | 1 sc/source/core/data/column2.cxx | 61 ++++++++++++++++++++++++++++++++++------ sc/source/core/data/dociter.cxx | 14 +++++---- sc/source/core/data/table1.cxx | 19 +++++++----- sc/source/core/data/table3.cxx | 15 +++++++-- 6 files changed, 88 insertions(+), 25 deletions(-)
New commits: commit e5a1a12af28e27173e2d0902d8d6bac3360fd419 Author: Serge Krot <serge.k...@cib.de> AuthorDate: Wed Oct 24 15:38:17 2018 +0200 Commit: Thorsten Behrens <thorsten.behr...@cib.de> CommitDate: Thu Nov 1 19:34:14 2018 +0100 sc: fix: range/step calculation for progress bar Change-Id: I733e4003b65b410d44d9a1132be4e9e10ac24c3e Reviewed-on: https://gerrit.libreoffice.org/62305 Tested-by: Jenkins Reviewed-by: Thorsten Behrens <thorsten.behr...@cib.de> Reviewed-on: https://gerrit.libreoffice.org/62751 Tested-by: Thorsten Behrens <thorsten.behr...@cib.de> diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx index d0b52f329db4..77d8a616e87c 100644 --- a/sc/inc/column.hxx +++ b/sc/inc/column.hxx @@ -370,7 +370,8 @@ public: ScFormulaCell * const * GetFormulaCellBlockAddress( SCROW nRow, size_t& rBlockSize ) const; CellType GetCellType( SCROW nRow ) const; SCSIZE GetCellCount() const; - sal_uInt32 GetWeightedCount() const; + sal_uLong GetWeightedCount() const; + sal_uLong GetWeightedCount(SCROW nStartRow, SCROW nEndRow) const; sal_uInt32 GetCodeCount() const; // RPN-Code in formulas sal_uInt16 GetErrCode( SCROW nRow ) const; diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index b78adcc78971..6665354c1b1e 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -238,6 +238,7 @@ public: sal_uLong GetCellCount() const; sal_uLong GetWeightedCount() const; + sal_uLong GetWeightedCount(SCROW nStartRow, SCROW nEndRow) const; sal_uLong GetCodeCount() const; // RPN code in formula sal_uInt16 GetTextWidth(SCCOL nCol, SCROW nRow) const; diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx index fd884b9b49b9..704593fa9f5e 100644 --- a/sc/source/core/data/column2.cxx +++ b/sc/source/core/data/column2.cxx @@ -3262,48 +3262,91 @@ namespace { class WeightedCounter { - size_t mnCount; + sal_uLong mnCount; public: WeightedCounter() : mnCount(0) {} void operator() (const sc::CellStoreType::value_type& node) { + mnCount += getWeight(node); + } + + static sal_uLong getWeight(const sc::CellStoreType::value_type& node) + { switch (node.type) { case sc::element_type_numeric: case sc::element_type_string: - mnCount += node.size; + return node.size; break; case sc::element_type_formula: { + size_t nCount = 0; // Each formula cell is worth its code length plus 5. sc::formula_block::const_iterator it = sc::formula_block::begin(*node.data); sc::formula_block::const_iterator itEnd = sc::formula_block::end(*node.data); for (; it != itEnd; ++it) { const ScFormulaCell* p = *it; - mnCount += 5 + p->GetCode()->GetCodeLen(); + nCount += 5 + p->GetCode()->GetCodeLen(); } + + return nCount; } break; case sc::element_type_edittext: // each edit-text cell is worth 50. - mnCount += node.size * 50; + return node.size * 50; break; default: - ; + return 0; } } - size_t getCount() const { return mnCount; } + sal_uLong getCount() const { return mnCount; } }; +class WeightedCounterWithRows +{ + const SCROW mnStartRow; + const SCROW mnEndRow; + sal_uLong mnCount; + +public: + WeightedCounterWithRows(SCROW nStartRow, SCROW nEndRow) + : mnStartRow(nStartRow) + , mnEndRow(nEndRow) + , mnCount(0) + { + } + + void operator() (const sc::CellStoreType::value_type& node) + { + const SCROW nRow1 = node.position; + const SCROW nRow2 = nRow1 + 1; + + if (! ((nRow2 < mnStartRow) || (nRow1 > mnEndRow))) + { + mnCount += WeightedCounter::getWeight(node); + } + } + + sal_uLong getCount() const { return mnCount; } +}; + +} + +sal_uLong ScColumn::GetWeightedCount() const +{ + const WeightedCounter aFunc = std::for_each(maCells.begin(), maCells.end(), + WeightedCounter()); + return aFunc.getCount(); } -sal_uInt32 ScColumn::GetWeightedCount() const +sal_uLong ScColumn::GetWeightedCount(SCROW nStartRow, SCROW nEndRow) const { - WeightedCounter aFunc; - std::for_each(maCells.begin(), maCells.end(), aFunc); + const WeightedCounterWithRows aFunc = std::for_each(maCells.begin(), maCells.end(), + WeightedCounterWithRows(nStartRow, nEndRow)); return aFunc.getCount(); } diff --git a/sc/source/core/data/dociter.cxx b/sc/source/core/data/dociter.cxx index c8dee787ef91..82efdb08aba1 100644 --- a/sc/source/core/data/dociter.cxx +++ b/sc/source/core/data/dociter.cxx @@ -2590,10 +2590,14 @@ void ScDocRowHeightUpdater::update() return; } - sal_uInt32 nCellCount = 0; + sal_uLong nCellCount = 0; vector<TabRanges>::const_iterator itr = mpTabRangesArray->begin(), itrEnd = mpTabRangesArray->end(); for (; itr != itrEnd; ++itr) { + const SCTAB nTab = itr->mnTab; + if (!ValidTab(nTab) || nTab >= mrDoc.GetTableCount() || !mrDoc.maTabs[nTab]) + continue; + ScFlatBoolRowSegments::RangeData aData; ScFlatBoolRowSegments::RangeIterator aRangeItr(*itr->mpRanges); for (bool bFound = aRangeItr.getFirst(aData); bFound; bFound = aRangeItr.getNext(aData)) @@ -2601,7 +2605,7 @@ void ScDocRowHeightUpdater::update() if (!aData.mbValue) continue; - nCellCount += aData.mnRow2 - aData.mnRow1 + 1; + nCellCount += mrDoc.maTabs[nTab]->GetWeightedCount(aData.mnRow1, aData.mnRow2); } } @@ -2609,10 +2613,10 @@ void ScDocRowHeightUpdater::update() Fraction aZoom(1, 1); itr = mpTabRangesArray->begin(); - sal_uInt32 nProgressStart = 0; + sal_uLong nProgressStart = 0; for (; itr != itrEnd; ++itr) { - SCTAB nTab = itr->mnTab; + const SCTAB nTab = itr->mnTab; if (!ValidTab(nTab) || nTab >= mrDoc.GetTableCount() || !mrDoc.maTabs[nTab]) continue; @@ -2627,7 +2631,7 @@ void ScDocRowHeightUpdater::update() mrDoc.maTabs[nTab]->SetOptimalHeight( aCxt, aData.mnRow1, aData.mnRow2, &aProgress, nProgressStart); - nProgressStart += aData.mnRow2 - aData.mnRow1 + 1; + nProgressStart += mrDoc.maTabs[nTab]->GetWeightedCount(aData.mnRow1, aData.mnRow2); } } } diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx index 00931e3cab35..bd4e779d0984 100644 --- a/sc/source/core/data/table1.cxx +++ b/sc/source/core/data/table1.cxx @@ -49,6 +49,7 @@ #include "scmatrix.hxx" #include "refupdatecontext.hxx" #include <rowheightcontext.hxx> +#include <vcl/svapp.hxx> #include <formula/vectortoken.hxx> @@ -82,7 +83,7 @@ ScProgress* GetProgressBar( void GetOptimalHeightsInColumn( sc::RowHeightContext& rCxt, ScColContainer& rCol, SCROW nStartRow, SCROW nEndRow, - ScProgress* pProgress, sal_uInt32 nProgressStart ) + ScProgress* pProgress, sal_uLong nProgressStart ) { assert(nStartRow <= nEndRow); @@ -102,20 +103,24 @@ void GetOptimalHeightsInColumn( SCSIZE nPos = nCount-1; while ( nPos && rHeights[nPos-1] >= nMinHeight ) --nPos; - SCROW nMinStart = nStartRow + nPos; - sal_uLong nWeightedCount = 0; + const SCROW nMinStart = nStartRow + nPos; + + sal_uLong nWeightedCount = nProgressStart + rCol[MAXCOL].GetWeightedCount(nStartRow, nEndRow); + const SCCOL progressUpdateStep = MAXCOL / 10; for (SCCOL nCol=0; nCol<MAXCOL; nCol++) // MAXCOL already above { rCol[nCol].GetOptimalHeight(rCxt, nStartRow, nEndRow, nMinHeight, nMinStart); if (pProgress) { - sal_uLong nWeight = rCol[nCol].GetWeightedCount(); - if (nWeight) // does not have to be the same Status + nWeightedCount += rCol[nCol].GetWeightedCount(nStartRow, nEndRow); + pProgress->SetState( nWeightedCount ); + + if ((nCol % progressUpdateStep) == 0) { - nWeightedCount += nWeight; - pProgress->SetState( nWeightedCount + nProgressStart ); + // try to make sure the progress dialog is painted before continuing + Application::Reschedule(true); } } } diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx index 56c85818015f..e5f663933e91 100644 --- a/sc/source/core/data/table3.cxx +++ b/sc/source/core/data/table3.cxx @@ -3394,9 +3394,18 @@ sal_uLong ScTable::GetWeightedCount() const { sal_uLong nCellCount = 0; - for ( SCCOL nCol=0; nCol<=MAXCOL; nCol++ ) - if ( aCol[nCol].GetCellCount() ) // GetCellCount ist inline - nCellCount += aCol[nCol].GetWeightedCount(); + for ( SCCOL nCol=0; nCol < aCol.size(); nCol++ ) + nCellCount += aCol[nCol].GetWeightedCount(); + + return nCellCount; +} + +sal_uLong ScTable::GetWeightedCount(SCROW nStartRow, SCROW nEndRow) const +{ + sal_uLong nCellCount = 0; + + for ( SCCOL nCol=0; nCol < aCol.size(); nCol++ ) + nCellCount += aCol[nCol].GetWeightedCount(nStartRow, nEndRow); return nCellCount; } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits