diff options
author | scito <info@scito.ch> | 2021-11-28 16:53:49 +0100 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2021-12-01 17:35:01 +0100 |
commit | 6382f51d2a4d9a3ec8eef2471467ab0dbf7a8294 (patch) | |
tree | adf676e910e26beeebccae1bcfdb2ee06bd0500a /sc/source/ui | |
parent | 42e56a3b4fd8372fae2bc6d768383ba1edf69918 (diff) |
tdf#124103 count non-sequentially selected rows or columns in statusbar
Count non-sequential cells if either rows or columns remain the same and are
sequential.
Examples:
A1, A2, A4 -> 3 rows, 1 column
A1, A2, A4, B4 -> do not show any count (as before)
A1, B1, D1 -> 1 row, 3 columns
A1, B1, D1, D2 -> do not show any count (as before)
Change-Id: Ib8f20d560e4dc4a2b673c6e0962397563d803519
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125979
Tested-by: Jenkins
Reviewed-by: Eike Rathke <erack@redhat.com>
Diffstat (limited to 'sc/source/ui')
-rw-r--r-- | sc/source/ui/view/cellsh.cxx | 76 |
1 files changed, 57 insertions, 19 deletions
diff --git a/sc/source/ui/view/cellsh.cxx b/sc/source/ui/view/cellsh.cxx index a1ee1bbb3289..4f542fec392e 100644 --- a/sc/source/ui/view/cellsh.cxx +++ b/sc/source/ui/view/cellsh.cxx @@ -765,26 +765,64 @@ void ScCellShell::GetState(SfxItemSet &rSet) case SID_ROWCOL_SELCOUNT: { - ScRange aMarkRange; - GetViewData().GetSimpleArea( aMarkRange ); - SCCOL nCol1, nCol2; - SCROW nRow1, nRow2; - nCol1 = aMarkRange.aStart.Col(); - nRow1 = aMarkRange.aStart.Row(); - nCol2 = aMarkRange.aEnd.Col(); - nRow2 = aMarkRange.aEnd.Row(); - if( nCol2 != nCol1 || nRow1 != nRow2 ) + 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(); + + if ((nRanges == 1 && (nCol2 != nCol1 || nRow1 != nRow2)) || nRanges > 1) { - const auto nRows - = rDoc.CountNonFilteredRows(nRow1, nRow2, aMarkRange.aStart.Tab()); - const auto nCols = nCol2 - nCol1 + 1; - const LocaleDataWrapper& rLocaleData = Application::GetSettings().GetUILocaleDataWrapper(); - OUString aRowArg = ScResId(STR_SELCOUNT_ROWARG, nRows).replaceAll("$1", rLocaleData.getNum(nRows, 0)); - OUString aColArg = ScResId(STR_SELCOUNT_COLARG, nCols).replaceAll("$1", rLocaleData.getNum(nCols, 0)); - OUString aStr = ScResId(STR_SELCOUNT); - aStr = aStr.replaceAll("$1", aRowArg); - aStr = aStr.replaceAll("$2", aColArg); - rSet.Put( SfxStringItem( nWhich, aStr ) ); + bool bSameRows = true; + bool bSameCols = true; + SCROW nRowsSum = 0; + 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; + 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) + { + nRowsSum = nRows; + nColsSum += nCols; + } + else if (bSameCols) + { + nRowsSum += nRows; + nColsSum = nCols; + } + else + break; + } + // Either the rows or columns are the same among selections + if (bSameRows || bSameCols) + { + const LocaleDataWrapper& rLocaleData + = Application::GetSettings().GetUILocaleDataWrapper(); + OUString aRowArg + = ScResId(STR_SELCOUNT_ROWARG, nRowsSum) + .replaceAll("$1", rLocaleData.getNum(nRowsSum, 0)); + OUString aColArg + = ScResId(STR_SELCOUNT_COLARG, nColsSum) + .replaceAll("$1", rLocaleData.getNum(nColsSum, 0)); + OUString aStr = ScResId(STR_SELCOUNT); + aStr = aStr.replaceAll("$1", aRowArg); + aStr = aStr.replaceAll("$2", aColArg); + rSet.Put(SfxStringItem(nWhich, aStr)); + } } else { |