diff options
author | Serge Krot <Serge.Krot@cib.de> | 2018-10-24 15:38:17 +0200 |
---|---|---|
committer | Thorsten Behrens <Thorsten.Behrens@CIB.de> | 2018-10-29 17:53:31 +0100 |
commit | 9c5f3baa657290cca801767f9e5886f6287e2f08 (patch) | |
tree | 13b5ab6d4bf55d6b35a7a663d15195b0d582ffc2 /sc | |
parent | 65d727548740afae7175fb04a12f50e119514497 (diff) |
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.Behrens@CIB.de>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/column.hxx | 3 | ||||
-rw-r--r-- | sc/inc/table.hxx | 1 | ||||
-rw-r--r-- | sc/source/core/data/column2.cxx | 61 | ||||
-rw-r--r-- | sc/source/core/data/dociter.cxx | 14 | ||||
-rw-r--r-- | sc/source/core/data/table1.cxx | 21 | ||||
-rw-r--r-- | sc/source/core/data/table3.cxx | 13 |
6 files changed, 88 insertions, 25 deletions
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx index 915b1aa22644..ffa43e12ea94 100644 --- a/sc/inc/column.hxx +++ b/sc/inc/column.hxx @@ -369,7 +369,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 FormulaError GetErrCode( SCROW nRow ) const; diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index 50dd96be4a3b..0e5b62837b92 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -290,6 +290,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 07653661e13a..e6cbf36a2ce5 100644 --- a/sc/source/core/data/column2.cxx +++ b/sc/source/core/data/column2.cxx @@ -3471,48 +3471,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 3ceaf83c8048..7e1630258430 100644 --- a/sc/source/core/data/dociter.cxx +++ b/sc/source/core/data/dociter.cxx @@ -2537,10 +2537,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)) @@ -2548,7 +2552,7 @@ void ScDocRowHeightUpdater::update() if (!aData.mbValue) continue; - nCellCount += aData.mnRow2 - aData.mnRow1 + 1; + nCellCount += mrDoc.maTabs[nTab]->GetWeightedCount(aData.mnRow1, aData.mnRow2); } } @@ -2556,10 +2560,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; @@ -2574,7 +2578,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 32e2b5329716..7941f3178629 100644 --- a/sc/source/core/data/table1.cxx +++ b/sc/source/core/data/table1.cxx @@ -52,6 +52,7 @@ #include <refupdatecontext.hxx> #include <rowheightcontext.hxx> #include <compressedarray.hxx> +#include <vcl/svapp.hxx> #include <formula/vectortoken.hxx> #include <token.hxx> @@ -86,7 +87,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); @@ -111,20 +112,24 @@ void GetOptimalHeightsInColumn( break; } - SCROW nMinStart = nPos; + const SCROW nMinStart = nPos; - sal_uLong nWeightedCount = 0; - for (SCCOL nCol=0; nCol<(rCol.size()-1); nCol++) // last col done already above + sal_uLong nWeightedCount = nProgressStart + rCol.back().GetWeightedCount(nStartRow, nEndRow); + const SCCOL maxCol = (rCol.size() - 1); // last col done already above + const SCCOL progressUpdateStep = rCol.size() / 10; + for (SCCOL nCol=0; nCol<maxCol; nCol++) { 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 13b0228ca703..bb3f1cab4e4e 100644 --- a/sc/source/core/data/table3.cxx +++ b/sc/source/core/data/table3.cxx @@ -3540,8 +3540,17 @@ sal_uLong ScTable::GetWeightedCount() const sal_uLong nCellCount = 0; for ( SCCOL nCol=0; nCol < aCol.size(); nCol++ ) - if ( aCol[nCol].GetCellCount() ) - nCellCount += aCol[nCol].GetWeightedCount(); + 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; } |