summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2017-06-16 17:08:09 +0200
committerEike Rathke <erack@redhat.com>2017-06-16 17:08:40 +0200
commitf83d8ae84584c0967e2346566d21d65d6d7a432f (patch)
tree8400adf638519e4444628cdb7bc26ea5a281bcb8
parent3f405b1af38b810a6ae1089138637d7947ce4f82 (diff)
For AutoSum up to next sum mark/select the resulting range, tdf#71339
Change-Id: Ib543b4a84305467e8a9ce34bdc2c6a211f399cad
-rw-r--r--sc/source/ui/view/viewfun2.cxx24
1 files changed, 15 insertions, 9 deletions
diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx
index 2d5338dfa5c4..dec005d3561a 100644
--- a/sc/source/ui/view/viewfun2.cxx
+++ b/sc/source/ui/view/viewfun2.cxx
@@ -614,6 +614,7 @@ bool ScViewFunc::AutoSum( const ScRange& rRange, bool bSubTotal, bool bSetCursor
SCCOL nMarkEndCol = nEndCol;
SCROW nMarkEndRow = nEndRow;
ScAutoSum eSum = ScAutoSumNone;
+ ScRangeList aSumRangeList;
if ( bRow )
{
@@ -637,13 +638,12 @@ bool ScViewFunc::AutoSum( const ScRange& rRange, bool bSubTotal, bool bSetCursor
{
if ( !pDoc->IsBlockEmpty( nTab, nCol, nStartRow, nCol, nSumEndRow ) )
{
- ScRangeList aRangeList;
// Include the originally selected start row.
const ScRange aRange( nCol, rRange.aStart.Row(), nTab, nCol, nSumEndRow, nTab );
- if ( (eSum = lcl_GetAutoSumForColumnRange( pDoc, aRangeList, aRange )) != ScAutoSumNone )
+ if ( (eSum = lcl_GetAutoSumForColumnRange( pDoc, aSumRangeList, aRange )) != ScAutoSumNone )
{
const OUString aFormula = GetAutoSumFormula(
- aRangeList, bSubTotal, ScAddress(nCol, nInsRow, nTab));
+ aSumRangeList, bSubTotal, ScAddress(nCol, nInsRow, nTab));
EnterData( nCol, nInsRow, nTab, aFormula );
}
}
@@ -672,22 +672,28 @@ bool ScViewFunc::AutoSum( const ScRange& rRange, bool bSubTotal, bool bSetCursor
{
if ( !pDoc->IsBlockEmpty( nTab, nStartCol, nRow, nSumEndCol, nRow ) )
{
- ScRangeList aRangeList;
// Include the originally selected start column.
const ScRange aRange( rRange.aStart.Col(), nRow, nTab, nSumEndCol, nRow, nTab );
- if ( (eSum = lcl_GetAutoSumForRowRange( pDoc, aRangeList, aRange )) != ScAutoSumNone )
+ if ( (eSum = lcl_GetAutoSumForRowRange( pDoc, aSumRangeList, aRange )) != ScAutoSumNone )
{
- const OUString aFormula = GetAutoSumFormula( aRangeList, bSubTotal, ScAddress(nInsCol, nRow, nTab) );
+ const OUString aFormula = GetAutoSumFormula( aSumRangeList, bSubTotal, ScAddress(nInsCol, nRow, nTab) );
EnterData( nInsCol, nRow, nTab, aFormula );
}
}
}
}
- // set new mark range and cursor position
+ // Set new mark range and cursor position.
+ // For sum of sums (and data until sum) mark the actual resulting range if
+ // there is only one, or the data range if more than one. Otherwise use the
+ // original selection. All extended by end column/row where the sum is put.
const ScRange aMarkRange(
- (eSum == ScAutoSumSum ? nStartCol : rRange.aStart.Col()),
- (eSum == ScAutoSumSum ? nStartRow : rRange.aStart.Row()),
+ (eSum == ScAutoSumSum ?
+ (aSumRangeList.size() == 1 ? aSumRangeList[0]->aStart.Col() : nStartCol) :
+ rRange.aStart.Col()),
+ (eSum == ScAutoSumSum ?
+ (aSumRangeList.size() == 1 ? aSumRangeList[0]->aStart.Row() : nStartRow) :
+ rRange.aStart.Row()),
nTab, nMarkEndCol, nMarkEndRow, nTab );
MarkRange( aMarkRange, false, bContinue );
if ( bSetCursor )