summaryrefslogtreecommitdiff
path: root/sc/source/core/data/dpoutput.cxx
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2013-04-18 22:23:54 -0400
committerKohei Yoshida <kohei.yoshida@gmail.com>2013-04-19 00:30:12 -0400
commita012bc60f2b3933d9148c2dd595df691a7834ad4 (patch)
treef18913f17e65ced1229d4f47e463a9c2ebb1d1ae /sc/source/core/data/dpoutput.cxx
parentf6412b5bd5c8b6421d8bb3939c142cb4a9f68068 (diff)
We can remove all this code now.
This code is the old GETPIVOTDATA implementation, which actually parses the pivot table output on the sheet (ugh!) to get the right value. It was susceptible to the table output being configurable. Change-Id: Iefbefa06b91fc6cfa7a21f9a8031bf6841c1d936
Diffstat (limited to 'sc/source/core/data/dpoutput.cxx')
-rw-r--r--sc/source/core/data/dpoutput.cxx435
1 files changed, 0 insertions, 435 deletions
diff --git a/sc/source/core/data/dpoutput.cxx b/sc/source/core/data/dpoutput.cxx
index b12edc57279c..e774f8e18119 100644
--- a/sc/source/core/data/dpoutput.cxx
+++ b/sc/source/core/data/dpoutput.cxx
@@ -1516,340 +1516,6 @@ bool ScDPOutput::GetDataResultPositionData(vector<sheet::DataPilotFieldFilter>&
namespace {
-//
-// helper functions for ScDPOutput::GetPivotData
-//
-
-bool lcl_IsNamedDataField( const ScDPGetPivotDataField& rTarget, const OUString& rSourceName, const OUString& rGivenName )
-{
- // match one of the names, ignoring case
- return ScGlobal::GetpTransliteration()->isEqual( rTarget.maFieldName, rSourceName ) ||
- ScGlobal::GetpTransliteration()->isEqual( rTarget.maFieldName, rGivenName );
-}
-
-bool lcl_IsNamedCategoryField( const ScDPGetPivotDataField& rFilter, const ScDPOutLevelData& rField )
-{
- return ScGlobal::GetpTransliteration()->isEqual( rFilter.maFieldName, rField.maName );
-}
-
-bool lcl_IsCondition( const sheet::MemberResult& rResultEntry, const ScDPGetPivotDataField& rFilter )
-{
- //! handle numeric conditions?
- return ScGlobal::GetpTransliteration()->isEqual( rResultEntry.Name, rFilter.maValStr );
-}
-
-bool lcl_CheckPageField( const ScDPOutLevelData& rField,
- const std::vector< ScDPGetPivotDataField >& rFilters,
- std::vector<bool>& rFilterUsed )
-{
- for (SCSIZE nFilterPos = 0; nFilterPos < rFilters.size(); ++nFilterPos)
- {
- if ( lcl_IsNamedCategoryField( rFilters[nFilterPos], rField ) )
- {
- rFilterUsed[nFilterPos] = true;
-
- // page field result is empty or the selection as single entry (see lcl_GetSelectedPageAsResult)
- if ( rField.aResult.getLength() == 1 &&
- lcl_IsCondition( rField.aResult[0], rFilters[nFilterPos] ) )
- {
- return true; // condition matches page selection
- }
- else
- {
- return false; // no page selection or different entry
- }
- }
- }
-
- return true; // valid if the page field doesn't have a filter
-}
-
-uno::Sequence<sheet::GeneralFunction> lcl_GetSubTotals(
- const uno::Reference<sheet::XDimensionsSupplier>& xSource, const ScDPOutLevelData& rField )
-{
- uno::Sequence<sheet::GeneralFunction> aSubTotals;
-
- uno::Reference<sheet::XHierarchiesSupplier> xHierSupp;
- uno::Reference<container::XNameAccess> xDimsName = xSource->getDimensions();
- uno::Reference<container::XIndexAccess> xIntDims = new ScNameToIndexAccess( xDimsName );
- sal_Int32 nIntCount = xIntDims->getCount();
- if ( rField.nDim < nIntCount )
- {
- uno::Reference<uno::XInterface> xIntDim = ScUnoHelpFunctions::AnyToInterface(
- xIntDims->getByIndex( rField.nDim ) );
- xHierSupp = uno::Reference<sheet::XHierarchiesSupplier>( xIntDim, uno::UNO_QUERY );
- }
- OSL_ENSURE( xHierSupp.is(), "dimension not found" );
-
- sal_Int32 nHierCount = 0;
- uno::Reference<container::XIndexAccess> xHiers;
- if ( xHierSupp.is() )
- {
- uno::Reference<container::XNameAccess> xHiersName = xHierSupp->getHierarchies();
- xHiers = new ScNameToIndexAccess( xHiersName );
- nHierCount = xHiers->getCount();
- }
- uno::Reference<uno::XInterface> xHier;
- if ( rField.nHier < nHierCount )
- xHier = ScUnoHelpFunctions::AnyToInterface( xHiers->getByIndex( rField.nHier ) );
- OSL_ENSURE( xHier.is(), "hierarchy not found" );
-
- sal_Int32 nLevCount = 0;
- uno::Reference<container::XIndexAccess> xLevels;
- uno::Reference<sheet::XLevelsSupplier> xLevSupp( xHier, uno::UNO_QUERY );
- if ( xLevSupp.is() )
- {
- uno::Reference<container::XNameAccess> xLevsName = xLevSupp->getLevels();
- xLevels = new ScNameToIndexAccess( xLevsName );
- nLevCount = xLevels->getCount();
- }
- uno::Reference<uno::XInterface> xLevel;
- if ( rField.nLevel < nLevCount )
- xLevel = ScUnoHelpFunctions::AnyToInterface( xLevels->getByIndex( rField.nLevel ) );
- OSL_ENSURE( xLevel.is(), "level not found" );
-
- uno::Reference<beans::XPropertySet> xLevelProp( xLevel, uno::UNO_QUERY );
- if ( xLevelProp.is() )
- {
- try
- {
- uno::Any aValue = xLevelProp->getPropertyValue( OUString(SC_UNO_DP_SUBTOTAL) );
- aValue >>= aSubTotals;
- }
- catch(const uno::Exception&)
- {
- }
- }
-
- return aSubTotals;
-}
-
-void lcl_FilterInclude( std::vector<bool>& rResult, std::vector< sal_Int32 >& rSubtotal,
- const ScDPOutLevelData& rField,
- const std::vector< ScDPGetPivotDataField >& rFilters,
- std::vector<bool>& rFilterUsed,
- bool& rBeforeDataLayout,
- sal_Int32 nGrandTotals, sal_Int32 nDataLayoutIndex,
- const std::vector<OUString>& rDataNames, const std::vector<OUString>& rGivenNames,
- const ScDPGetPivotDataField& rTarget, const uno::Reference<sheet::XDimensionsSupplier>& xSource )
-{
- // returns true if a filter was given for the field
-
- OSL_ENSURE( rFilters.size() == rFilterUsed.size(), "wrong size" );
-
- const bool bIsDataLayout = ( rField.nDim == nDataLayoutIndex );
- if (bIsDataLayout)
- rBeforeDataLayout = false;
-
- bool bHasFilter = false;
- ScDPGetPivotDataField aFilter;
- if ( !bIsDataLayout ) // selection of data field is handled separately
- {
- for (SCSIZE nFilterPos = 0; nFilterPos < rFilters.size() && !bHasFilter; ++nFilterPos)
- {
- if ( lcl_IsNamedCategoryField( rFilters[nFilterPos], rField ) )
- {
- aFilter = rFilters[nFilterPos];
- rFilterUsed[nFilterPos] = true;
- bHasFilter = true;
- }
- }
- }
-
- bool bHasFunc = bHasFilter && aFilter.meFunction != sheet::GeneralFunction_NONE;
-
- uno::Sequence<sheet::GeneralFunction> aSubTotals;
- if ( !bIsDataLayout )
- aSubTotals = lcl_GetSubTotals( xSource, rField );
- bool bManualSub = ( aSubTotals.getLength() > 0 && aSubTotals[0] != sheet::GeneralFunction_AUTO );
-
- const uno::Sequence<sheet::MemberResult>& rSequence = rField.aResult;
- const sheet::MemberResult* pArray = rSequence.getConstArray();
- sal_Int32 nSize = rSequence.getLength();
-
- OSL_ENSURE( (sal_Int32)rResult.size() == nSize, "Number of fields do not match result count" );
-
- sal_Int32 nContCount = 0;
- sal_Int32 nSubTotalCount = 0;
- sheet::MemberResult aPrevious;
- for( sal_Int32 j=0; j < nSize; j++ )
- {
- sheet::MemberResult aResultEntry = pArray[j];
- if ( aResultEntry.Flags & sheet::MemberResultFlags::CONTINUE )
- {
- aResultEntry = aPrevious;
- ++nContCount;
- }
- else if ( ( aResultEntry.Flags & sheet::MemberResultFlags::SUBTOTAL ) == 0 )
- {
- // count the CONTINUE entries before a SUBTOTAL
- nContCount = 0;
- }
-
- if ( j >= nSize - nGrandTotals )
- {
- // mark as subtotal for the preceding data
- if ( ( aResultEntry.Flags & sheet::MemberResultFlags::SUBTOTAL ) != 0 )
- {
- rSubtotal[j] = nSize - nGrandTotals;
-
- if ( rResult[j] && nGrandTotals > 1 )
- {
- // grand total is always automatic
- sal_Int32 nDataPos = j - ( nSize - nGrandTotals );
- if (nDataPos >= 0 && nDataPos < (sal_Int32)rDataNames.size() &&
- nDataPos < (sal_Int32)rGivenNames.size())
- {
- OUString aSourceName( rDataNames[nDataPos] ); // vector contains source names
- OUString aGivenName( rGivenNames[nDataPos] );
-
- rResult[j] = lcl_IsNamedDataField( rTarget, aSourceName, aGivenName );
- }
- else
- {
- OSL_FAIL( "wrong data count for grand total" );
- rResult[j] = false;
- }
- }
- }
-
- // treat "grand total" columns/rows as empty description, as if they were marked
- // in a previous field
-
- OSL_ENSURE( ( aResultEntry.Flags &
- ( sheet::MemberResultFlags::HASMEMBER | sheet::MemberResultFlags::SUBTOTAL ) ) == 0 ||
- ( aResultEntry.Flags &
- ( sheet::MemberResultFlags::HASMEMBER | sheet::MemberResultFlags::SUBTOTAL ) ) ==
- ( sheet::MemberResultFlags::HASMEMBER | sheet::MemberResultFlags::SUBTOTAL ),
- "non-subtotal member found in grand total result" );
- aResultEntry.Flags = 0;
- }
-
- // mark subtotals (not grand total) for preceding data (assume CONTINUE is set)
- if ( ( aResultEntry.Flags & sheet::MemberResultFlags::SUBTOTAL ) != 0 )
- {
- rSubtotal[j] = nContCount + 1 + nSubTotalCount;
-
- if ( rResult[j] )
- {
- if ( bManualSub )
- {
- if ( rBeforeDataLayout )
- {
- // manual subtotals and several data fields
-
- sal_Int32 nDataCount = rDataNames.size();
- sal_Int32 nFuncPos = nSubTotalCount / nDataCount; // outer order: subtotal functions
- sal_Int32 nDataPos = nSubTotalCount % nDataCount; // inner order: data fields
-
- OUString aSourceName( rDataNames[nDataPos] ); // vector contains source names
- OUString aGivenName( rGivenNames[nDataPos] );
-
- if (nFuncPos < aSubTotals.getLength())
- {
- rResult[j] = lcl_IsNamedDataField( rTarget, aSourceName, aGivenName ) &&
- aSubTotals[nFuncPos] == aFilter.meFunction;
- }
- else
- {
- OSL_FAIL( "wrong subtotal count for manual subtotals and several data fields" );
- rResult[j] = false;
- }
- }
- else
- {
- // manual subtotals for a single data field
-
- if (nSubTotalCount < aSubTotals.getLength())
- {
- rResult[j] = ( aSubTotals[nSubTotalCount] == aFilter.meFunction );
- }
- else
- {
- OSL_FAIL( "wrong subtotal count for manual subtotals for a single data field" );
- rResult[j] = false;
- }
- }
- }
- else // automatic subtotals
- {
- if ( rBeforeDataLayout )
- {
- if (nSubTotalCount < (sal_Int32)rDataNames.size() &&
- nSubTotalCount < (sal_Int32)rGivenNames.size())
- {
- OUString aSourceName( rDataNames[nSubTotalCount] ); // vector contains source names
- OUString aGivenName( rGivenNames[nSubTotalCount] );
-
- rResult[j] = lcl_IsNamedDataField( rTarget, aSourceName, aGivenName );
- }
- else
- {
- OSL_FAIL( "wrong data count for automatic subtotals" );
- rResult[j] = false;
- }
- }
-
- // if a function was specified, automatic subtotals never match
- if ( bHasFunc )
- rResult[j] = false;
- }
- }
-
- ++nSubTotalCount;
- }
- else
- nSubTotalCount = 0;
-
- if( rResult[j] )
- {
- if ( bIsDataLayout )
- {
- if ( ( aResultEntry.Flags & sheet::MemberResultFlags::HASMEMBER ) != 0 )
- {
- // Asterisks are added in ScDPSaveData::WriteToSource to create unique names.
- //! preserve original name there?
- OUString aSourceName = ScDPUtil::getSourceDimensionName(aResultEntry.Name);
-
- rResult[j] = lcl_IsNamedDataField(
- rTarget, aSourceName, aResultEntry.Caption);
- }
- }
- else if ( bHasFilter )
- {
- // name must match (simple value or subtotal)
- rResult[j] = ( ( aResultEntry.Flags & sheet::MemberResultFlags::HASMEMBER ) != 0 ) &&
- lcl_IsCondition( aResultEntry, aFilter );
-
- // if a function was specified, simple (non-subtotal) values never match
- if ( bHasFunc && nSubTotalCount == 0 )
- rResult[j] = false;
- }
- // if no condition is given, keep the columns/rows included
- }
- aPrevious = aResultEntry;
- }
-}
-
-void lcl_StripSubTotals( std::vector<bool>& rResult, const std::vector<sal_Int32>& rSubtotal )
-{
- sal_Int32 nSize = rResult.size();
- OSL_ENSURE( (sal_Int32)rSubtotal.size() == nSize, "sizes don't match" );
-
- for (sal_Int32 nPos=0; nPos<nSize; nPos++)
- if ( rResult[nPos] && rSubtotal[nPos] )
- {
- // if a subtotal is included, clear the result flag for the columns/rows that the subtotal includes
- sal_Int32 nStart = nPos - rSubtotal[nPos];
- OSL_ENSURE( nStart >= 0, "invalid subtotal count" );
- if (nStart < 0)
- nStart = 0;
-
- for (sal_Int32 nPrev = nStart; nPrev < nPos; nPrev++)
- rResult[nPrev] = false;
- }
-}
-
OUString lcl_GetDataFieldName( const OUString& rSourceName, sheet::GeneralFunction eFunc )
{
sal_uInt16 nStrId = 0;
@@ -1905,107 +1571,6 @@ void ScDPOutput::GetDataDimensionNames(
}
}
-bool ScDPOutput::GetPivotData( ScDPGetPivotDataField& rTarget,
- const std::vector< ScDPGetPivotDataField >& rFilters )
-{
- CalcSizes();
-
- // need to know about grand total columns/rows:
- sal_Int32 nGrandTotalCols;
- sal_Int32 nGrandTotalRows;
- sal_Int32 nDataLayoutIndex;
- std::vector<OUString> aDataNames;
- std::vector<OUString> aGivenNames;
- sheet::DataPilotFieldOrientation eDataOrient;
- lcl_GetTableVars( nGrandTotalCols, nGrandTotalRows, nDataLayoutIndex, aDataNames, aGivenNames, eDataOrient, xSource );
-
- if ( aDataNames.empty() )
- return false; // incomplete table without data fields -> no result
-
- if ( eDataOrient == sheet::DataPilotFieldOrientation_HIDDEN )
- {
- // no data layout field -> single data field -> must match the selected field in rTarget
-
- OSL_ENSURE( aDataNames.size() == 1, "several data fields but no data layout field" );
- if ( !lcl_IsNamedDataField( rTarget, aDataNames[0], aGivenNames[0] ) )
- return false;
- }
-
- std::vector<bool> aIncludeCol(nColCount, true);
- std::vector< sal_Int32 > aSubtotalCol( nColCount, 0 );
- std::vector<bool> aIncludeRow(nRowCount, true);
- std::vector< sal_Int32 > aSubtotalRow( nRowCount, 0 );
-
- std::vector<bool> aFilterUsed(rFilters.size(), false);
-
- long nField;
- long nCol;
- long nRow;
- bool bBeforeDataLayout;
-
- // look in column fields
-
- bBeforeDataLayout = ( eDataOrient == sheet::DataPilotFieldOrientation_COLUMN );
- for (nField=0; nField<nColFieldCount; nField++)
- lcl_FilterInclude( aIncludeCol, aSubtotalCol, pColFields[nField], rFilters, aFilterUsed, bBeforeDataLayout,
- nGrandTotalCols, nDataLayoutIndex, aDataNames, aGivenNames, rTarget, xSource );
-
- // look in row fields
-
- bBeforeDataLayout = ( eDataOrient == sheet::DataPilotFieldOrientation_ROW );
- for (nField=0; nField<nRowFieldCount; nField++)
- lcl_FilterInclude( aIncludeRow, aSubtotalRow, pRowFields[nField], rFilters, aFilterUsed, bBeforeDataLayout,
- nGrandTotalRows, nDataLayoutIndex, aDataNames, aGivenNames, rTarget, xSource );
-
- // page fields
-
- for (nField=0; nField<nPageFieldCount; nField++)
- if ( !lcl_CheckPageField( pPageFields[nField], rFilters, aFilterUsed ) )
- return false;
-
- // all filter fields must be used
- for (SCSIZE nFilter=0; nFilter<aFilterUsed.size(); nFilter++)
- if (!aFilterUsed[nFilter])
- return false;
-
- lcl_StripSubTotals( aIncludeCol, aSubtotalCol );
- lcl_StripSubTotals( aIncludeRow, aSubtotalRow );
-
- long nColPos = 0;
- long nColIncluded = 0;
- for (nCol=0; nCol<nColCount; nCol++)
- if (aIncludeCol[nCol])
- {
- nColPos = nCol;
- ++nColIncluded;
- }
-
- long nRowPos = 0;
- long nRowIncluded = 0;
- for (nRow=0; nRow<nRowCount; nRow++)
- if (aIncludeRow[nRow])
- {
- nRowPos = nRow;
- ++nRowIncluded;
- }
-
- if ( nColIncluded != 1 || nRowIncluded != 1 )
- return false;
-
- const uno::Sequence<sheet::DataResult>& rDataRow = aData[nRowPos];
- if ( nColPos >= rDataRow.getLength() )
- return false;
-
- const sheet::DataResult& rResult = rDataRow[nColPos];
- if ( rResult.Flags & sheet::DataResultFlags::ERROR )
- return false; //! different error?
-
- rTarget.mbValIsStr = false;
- rTarget.mnValNum = rResult.Value;
-
- return true;
-}
-
bool ScDPOutput::IsFilterButton( const ScAddress& rPos )
{
SCCOL nCol = rPos.Col();