Kaydet (Commit) e7a5f5ef authored tarafından Prashant Pandey's avatar Prashant Pandey Kaydeden (comit) Eike Rathke

fdo#61541 : Count Number of selected Cells in calc

Change-Id: Ic9c911552f2b03bb496f47251917a3736494dce1
Reviewed-on: https://gerrit.libreoffice.org/3213Reviewed-by: 's avatarEike Rathke <erack@redhat.com>
Tested-by: 's avatarEike Rathke <erack@redhat.com>
üst 42960dcc
...@@ -741,7 +741,8 @@ enum ScSubTotalFunc ...@@ -741,7 +741,8 @@ enum ScSubTotalFunc
SUBTOTAL_FUNC_STDP = 8, SUBTOTAL_FUNC_STDP = 8,
SUBTOTAL_FUNC_SUM = 9, SUBTOTAL_FUNC_SUM = 9,
SUBTOTAL_FUNC_VAR = 10, SUBTOTAL_FUNC_VAR = 10,
SUBTOTAL_FUNC_VARP = 11 SUBTOTAL_FUNC_VARP = 11,
SUBTOTAL_FUNC_SELECTION_COUNT = 12
}; };
class ScArea; class ScArea;
......
...@@ -679,7 +679,9 @@ ...@@ -679,7 +679,9 @@
#define STR_UNDO_L2R 544 #define STR_UNDO_L2R 544
#define STR_UNDO_R2L 545 #define STR_UNDO_R2L 545
#define STR_COUNT 546 #define STR_FUN_TEXT_SELECTION_COUNT 546
#define STR_COUNT 547
#endif #endif
......
...@@ -1972,6 +1972,8 @@ void ScColumn::UpdateSelectionFunction( ...@@ -1972,6 +1972,8 @@ void ScColumn::UpdateSelectionFunction(
const ScMarkData& rMark, ScFunctionData& rData, ScFlatBoolRowSegments& rHiddenRows, const ScMarkData& rMark, ScFunctionData& rData, ScFlatBoolRowSegments& rHiddenRows,
bool bDoExclude, SCROW nExStartRow, SCROW nExEndRow) const bool bDoExclude, SCROW nExStartRow, SCROW nExEndRow) const
{ {
if ( rData.eFunc != SUBTOTAL_FUNC_SELECTION_COUNT )
{
SCSIZE nIndex; SCSIZE nIndex;
ScMarkedDataIter aDataIter(this, &rMark, false); ScMarkedDataIter aDataIter(this, &rMark, false);
while (aDataIter.Next( nIndex )) while (aDataIter.Next( nIndex ))
...@@ -1982,12 +1984,55 @@ void ScColumn::UpdateSelectionFunction( ...@@ -1982,12 +1984,55 @@ void ScColumn::UpdateSelectionFunction(
if ( !bDoExclude || nRow < nExStartRow || nRow > nExEndRow ) if ( !bDoExclude || nRow < nExStartRow || nRow > nExEndRow )
lcl_UpdateSubTotal( rData, maItems[nIndex].pCell ); lcl_UpdateSubTotal( rData, maItems[nIndex].pCell );
} }
}
else
{
SCROW nTop, nBottom;
// ScMarkData::GetArray() returns a valid array only if
// 'rMark.IsMultiMarked()' returns true.
// Since ScTable::UpdateSelectionFunction() already checked that first
// before calling this method it does not need to be repeated here.
ScMarkArrayIter aIter(rMark.GetArray() + nCol);
ScFlatBoolRowSegments::RangeData aData;
while (aIter.Next( nTop, nBottom ))
{
sal_Int32 nCellCount = 0; // to get the count of selected visible cells
SCROW nRow = nTop;
while ( nRow <= nBottom )
{
if (!rHiddenRows.getRangeData(nRow, aData)) // failed to get range data
break;
if (aData.mnRow2 > nBottom)
aData.mnRow2 = nBottom;
if (!aData.mbValue)
{
nCellCount += aData.mnRow2 - nRow + 1;
// Till this point, nCellCount also includes count of those cells which are excluded
// So, they should be decremented now.
if ( bDoExclude && nExStartRow >= nRow && nExEndRow <= aData.mnRow2 )
nCellCount -= nExEndRow - nExStartRow + 1;
}
nRow = aData.mnRow2 + 1;
}
rData.nCount += nCellCount;
}
}
} }
// with bNoMarked ignore the multiple selections // with bNoMarked ignore the multiple selections
void ScColumn::UpdateAreaFunction( void ScColumn::UpdateAreaFunction(
ScFunctionData& rData, ScFlatBoolRowSegments& rHiddenRows, SCROW nStartRow, SCROW nEndRow) const ScFunctionData& rData, ScFlatBoolRowSegments& rHiddenRows, SCROW nStartRow, SCROW nEndRow) const
{ {
if ( rData.eFunc != SUBTOTAL_FUNC_SELECTION_COUNT )
{
SCSIZE nIndex; SCSIZE nIndex;
Search( nStartRow, nIndex ); Search( nStartRow, nIndex );
while ( nIndex<maItems.size() && maItems[nIndex].nRow<=nEndRow ) while ( nIndex<maItems.size() && maItems[nIndex].nRow<=nEndRow )
...@@ -1995,9 +2040,29 @@ void ScColumn::UpdateAreaFunction( ...@@ -1995,9 +2040,29 @@ void ScColumn::UpdateAreaFunction(
SCROW nRow = maItems[nIndex].nRow; SCROW nRow = maItems[nIndex].nRow;
bool bRowHidden = rHiddenRows.getValue(nRow); bool bRowHidden = rHiddenRows.getValue(nRow);
if ( !bRowHidden ) if ( !bRowHidden )
if ( rData.eFunc != SUBTOTAL_FUNC_SELECTION_COUNT )
lcl_UpdateSubTotal( rData, maItems[nIndex].pCell ); lcl_UpdateSubTotal( rData, maItems[nIndex].pCell );
++nIndex; ++nIndex;
} }
}
else
{
sal_Int32 nCellCount = 0; // to get the count of selected visible cells
SCROW nRow = nStartRow;
ScFlatBoolRowSegments::RangeData aData;
while (nRow <= nEndRow)
{
if (!rHiddenRows.getRangeData(nRow, aData))
break;
if (!aData.mbValue)
nCellCount += (aData.mnRow2 <= nEndRow ? aData.mnRow2 : nEndRow) - nRow + 1;
nRow = aData.mnRow2 + 1;
}
rData.nCount += nCellCount;
}
} }
sal_uInt32 ScColumn::GetWeightedCount() const sal_uInt32 ScColumn::GetWeightedCount() const
......
...@@ -486,6 +486,7 @@ bool ScDocument::GetSelectionFunction( ScSubTotalFunc eFunc, ...@@ -486,6 +486,7 @@ bool ScDocument::GetSelectionFunction( ScSubTotalFunc eFunc,
SCTAB nMax = static_cast<SCTAB>(maTabs.size()); SCTAB nMax = static_cast<SCTAB>(maTabs.size());
ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end(); ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end();
for (; itr != itrEnd && *itr < nMax && !aData.bError; ++itr) for (; itr != itrEnd && *itr < nMax && !aData.bError; ++itr)
if (maTabs[*itr]) if (maTabs[*itr])
maTabs[*itr]->UpdateSelectionFunction( aData, maTabs[*itr]->UpdateSelectionFunction( aData,
...@@ -499,6 +500,9 @@ bool ScDocument::GetSelectionFunction( ScSubTotalFunc eFunc, ...@@ -499,6 +500,9 @@ bool ScDocument::GetSelectionFunction( ScSubTotalFunc eFunc,
case SUBTOTAL_FUNC_SUM: case SUBTOTAL_FUNC_SUM:
rResult = aData.nVal; rResult = aData.nVal;
break; break;
case SUBTOTAL_FUNC_SELECTION_COUNT:
rResult = aData.nCount;
break;
case SUBTOTAL_FUNC_CNT: case SUBTOTAL_FUNC_CNT:
case SUBTOTAL_FUNC_CNT2: case SUBTOTAL_FUNC_CNT2:
rResult = aData.nCount; rResult = aData.nCount;
......
...@@ -154,6 +154,9 @@ void ScXMLConverter::GetStringFromFunction( ...@@ -154,6 +154,9 @@ void ScXMLConverter::GetStringFromFunction(
case SUBTOTAL_FUNC_STD: sFuncStr = GetXMLToken( XML_STDEV ); break; case SUBTOTAL_FUNC_STD: sFuncStr = GetXMLToken( XML_STDEV ); break;
case SUBTOTAL_FUNC_STDP: sFuncStr = GetXMLToken( XML_STDEVP ); break; case SUBTOTAL_FUNC_STDP: sFuncStr = GetXMLToken( XML_STDEVP ); break;
case SUBTOTAL_FUNC_SUM: sFuncStr = GetXMLToken( XML_SUM ); break; case SUBTOTAL_FUNC_SUM: sFuncStr = GetXMLToken( XML_SUM ); break;
case SUBTOTAL_FUNC_SELECTION_COUNT: break;
// it is not needed as it is only a UI value and not document content
case SUBTOTAL_FUNC_VAR: sFuncStr = GetXMLToken( XML_VAR ); break; case SUBTOTAL_FUNC_VAR: sFuncStr = GetXMLToken( XML_VAR ); break;
case SUBTOTAL_FUNC_VARP: sFuncStr = GetXMLToken( XML_VARP ); break; case SUBTOTAL_FUNC_VARP: sFuncStr = GetXMLToken( XML_VARP ); break;
} }
......
...@@ -686,6 +686,10 @@ Resource RID_GLOBSTR ...@@ -686,6 +686,10 @@ Resource RID_GLOBSTR
{ {
Text [ en-US ] = "Sum" ; Text [ en-US ] = "Sum" ;
}; };
String STR_FUN_TEXT_SELECTION_COUNT
{
Text [ en-US ] = "Selection count" ;
};
String STR_FUN_TEXT_COUNT String STR_FUN_TEXT_COUNT
{ {
Text [ en-US ] = "Count" ; Text [ en-US ] = "Count" ;
......
...@@ -80,6 +80,8 @@ sal_Bool ScTabViewShell::GetFunction( String& rFuncStr, sal_uInt16 nErrCode ) ...@@ -80,6 +80,8 @@ sal_Bool ScTabViewShell::GetFunction( String& rFuncStr, sal_uInt16 nErrCode )
case SUBTOTAL_FUNC_MAX: nGlobStrId = STR_FUN_TEXT_MAX; break; case SUBTOTAL_FUNC_MAX: nGlobStrId = STR_FUN_TEXT_MAX; break;
case SUBTOTAL_FUNC_MIN: nGlobStrId = STR_FUN_TEXT_MIN; break; case SUBTOTAL_FUNC_MIN: nGlobStrId = STR_FUN_TEXT_MIN; break;
case SUBTOTAL_FUNC_SUM: nGlobStrId = STR_FUN_TEXT_SUM; break; case SUBTOTAL_FUNC_SUM: nGlobStrId = STR_FUN_TEXT_SUM; break;
case SUBTOTAL_FUNC_SELECTION_COUNT: nGlobStrId = STR_FUN_TEXT_SELECTION_COUNT; break;
default: default:
{ {
// added to avoid warnings // added to avoid warnings
...@@ -106,7 +108,7 @@ sal_Bool ScTabViewShell::GetFunction( String& rFuncStr, sal_uInt16 nErrCode ) ...@@ -106,7 +108,7 @@ sal_Bool ScTabViewShell::GetFunction( String& rFuncStr, sal_uInt16 nErrCode )
// Number in the standard format, the other on the cursor position // Number in the standard format, the other on the cursor position
SvNumberFormatter* pFormatter = pDoc->GetFormatTable(); SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
sal_uInt32 nNumFmt = 0; sal_uInt32 nNumFmt = 0;
if ( eFunc != SUBTOTAL_FUNC_CNT && eFunc != SUBTOTAL_FUNC_CNT2 ) if ( eFunc != SUBTOTAL_FUNC_CNT && eFunc != SUBTOTAL_FUNC_CNT2 && eFunc != SUBTOTAL_FUNC_SELECTION_COUNT)
{ {
// Zahlformat aus Attributen oder Formel // Zahlformat aus Attributen oder Formel
pDoc->GetNumberFormat( nPosX, nPosY, nTab, nNumFmt ); pDoc->GetNumberFormat( nPosX, nPosY, nTab, nNumFmt );
......
...@@ -134,6 +134,7 @@ ...@@ -134,6 +134,7 @@
#define HID_MNU_FUNC_MIN "SVX_HID_MNU_FUNC_MIN" #define HID_MNU_FUNC_MIN "SVX_HID_MNU_FUNC_MIN"
#define HID_MNU_FUNC_NONE "SVX_HID_MNU_FUNC_NONE" #define HID_MNU_FUNC_NONE "SVX_HID_MNU_FUNC_NONE"
#define HID_MNU_FUNC_SUM "SVX_HID_MNU_FUNC_SUM" #define HID_MNU_FUNC_SUM "SVX_HID_MNU_FUNC_SUM"
#define HID_MNU_FUNC_SELECTION_COUNT "SVX_HID_MNU_FUNC_SELECTION_COUNT"
#define HID_MNU_ZOOM_100 "SVX_HID_MNU_ZOOM_100" #define HID_MNU_ZOOM_100 "SVX_HID_MNU_ZOOM_100"
#define HID_MNU_ZOOM_150 "SVX_HID_MNU_ZOOM_150" #define HID_MNU_ZOOM_150 "SVX_HID_MNU_ZOOM_150"
#define HID_MNU_ZOOM_200 "SVX_HID_MNU_ZOOM_200" #define HID_MNU_ZOOM_200 "SVX_HID_MNU_ZOOM_200"
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
#define ZOOM_PAGE_WIDTH 7 #define ZOOM_PAGE_WIDTH 7
#define ZOOM_WHOLE_PAGE 8 #define ZOOM_WHOLE_PAGE 8
// IDs wie SUBTOTAL_FUNC im Calc // IDs as in SUBTOTAL_FUNC of Calc
#define PSZ_FUNC_AVG 1 #define PSZ_FUNC_AVG 1
#define PSZ_FUNC_COUNT2 3 #define PSZ_FUNC_COUNT2 3
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#define PSZ_FUNC_MAX 4 #define PSZ_FUNC_MAX 4
#define PSZ_FUNC_MIN 5 #define PSZ_FUNC_MIN 5
#define PSZ_FUNC_SUM 9 #define PSZ_FUNC_SUM 9
#define PSZ_FUNC_SELECTION_COUNT 12
#define PSZ_FUNC_NONE 16 #define PSZ_FUNC_NONE 16
#define XMLSEC_CALL 1 #define XMLSEC_CALL 1
......
...@@ -217,6 +217,12 @@ Menu RID_SVXMNU_PSZ_FUNC ...@@ -217,6 +217,12 @@ Menu RID_SVXMNU_PSZ_FUNC
Text [ en-US ] = "Sum" ; Text [ en-US ] = "Sum" ;
}; };
MenuItem MenuItem
{
Identifier = PSZ_FUNC_SELECTION_COUNT ;
HelpId = HID_MNU_FUNC_SELECTION_COUNT ;
Text [ en-US ] = "Selection count" ;
};
MenuItem
{ {
Identifier = PSZ_FUNC_NONE ; Identifier = PSZ_FUNC_NONE ;
HelpId = HID_MNU_FUNC_NONE ; HelpId = HID_MNU_FUNC_NONE ;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment