summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2021-12-01 18:35:14 +0100
committerEike Rathke <erack@redhat.com>2021-12-02 17:46:53 +0100
commit8a82417383fa29bfe3cdeaf8f4ca35f5170994de (patch)
tree1d4f097bff35fa82c876ce0a0ec0bc3ca52d1974
parent4f448fdfbce44237161a035bbeadb4e723c18c68 (diff)
Call CountNonFilteredRows() only if necessary, tdf#124103 follow-up
i.e. only for different row selections or the first time. Also const as const can and reference rRange vs aRange naming. Change-Id: Iee926eeefa7ae5db1e6b8cff768a0c7c106c3476 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126189 Reviewed-by: Eike Rathke <erack@redhat.com> Tested-by: Jenkins (cherry picked from commit 31d038966de5db78bd31dfd1008ee02c050d510a) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126228
-rw-r--r--sc/source/ui/view/cellsh.cxx46
1 files changed, 25 insertions, 21 deletions
diff --git a/sc/source/ui/view/cellsh.cxx b/sc/source/ui/view/cellsh.cxx
index 4f542fec392e..db9523332f67 100644
--- a/sc/source/ui/view/cellsh.cxx
+++ b/sc/source/ui/view/cellsh.cxx
@@ -767,11 +767,11 @@ void ScCellShell::GetState(SfxItemSet &rSet)
{
ScRangeListRef aMarkRanges;
GetViewData().GetMultiArea(aMarkRanges);
- SCCOL nCol1 = aMarkRanges->front().aStart.Col();
- SCROW nRow1 = aMarkRanges->front().aStart.Row();
- SCCOL nCol2 = aMarkRanges->front().aEnd.Col();
- SCROW nRow2 = aMarkRanges->front().aEnd.Row();
- size_t nRanges = aMarkRanges->size();
+ const SCCOL nCol1 = aMarkRanges->front().aStart.Col();
+ const SCROW nRow1 = aMarkRanges->front().aStart.Row();
+ const SCCOL nCol2 = aMarkRanges->front().aEnd.Col();
+ const SCROW nRow2 = aMarkRanges->front().aEnd.Row();
+ const size_t nRanges = aMarkRanges->size();
if ((nRanges == 1 && (nCol2 != nCol1 || nRow1 != nRow2)) || nRanges > 1)
{
@@ -781,28 +781,32 @@ void ScCellShell::GetState(SfxItemSet &rSet)
SCCOL nColsSum = 0;
for (size_t i = 0; i < nRanges; ++i)
{
- const ScRange& aRange = (*aMarkRanges)[i];
- SCCOL nRangeCol1 = aRange.aStart.Col();
- SCROW nRangeRow1 = aRange.aStart.Row();
- SCCOL nRangeCol2 = aRange.aEnd.Col();
- SCROW nRangeRow2 = aRange.aEnd.Row();
- const auto nRows = rDoc.CountNonFilteredRows(nRangeRow1, nRangeRow2,
- aRange.aStart.Tab());
- const auto nCols = nRangeCol2 - nRangeCol1 + 1;
+ const ScRange& rRange = (*aMarkRanges)[i];
+ const SCCOL nRangeCol1 = rRange.aStart.Col();
+ const SCROW nRangeRow1 = rRange.aStart.Row();
+ const SCCOL nRangeCol2 = rRange.aEnd.Col();
+ const SCROW nRangeRow2 = rRange.aEnd.Row();
bSameRows &= (nRow1 == nRangeRow1 && nRow2 == nRangeRow2);
bSameCols &= (nCol1 == nRangeCol1 && nCol2 == nRangeCol2);
// Sum rows if the number of cols is the same or
// sum columns if the number of rows is the same,
// otherwise do not show any count of selected cells.
- if (bSameRows)
+ if (bSameRows || bSameCols)
{
- nRowsSum = nRows;
- nColsSum += nCols;
- }
- else if (bSameCols)
- {
- nRowsSum += nRows;
- nColsSum = nCols;
+ const auto nCols = nRangeCol2 - nRangeCol1 + 1;
+ const auto nRows = (bSameCols || nRowsSum == 0) ?
+ rDoc.CountNonFilteredRows( nRangeRow1, nRangeRow2, rRange.aStart.Tab()) :
+ nRowsSum;
+ if (bSameRows)
+ {
+ nRowsSum = nRows;
+ nColsSum += nCols;
+ }
+ else if (bSameCols)
+ {
+ nRowsSum += nRows;
+ nColsSum = nCols;
+ }
}
else
break;