diff options
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/dpobject.hxx | 2 | ||||
-rw-r--r-- | sc/inc/dpoutput.hxx | 6 | ||||
-rw-r--r-- | sc/source/core/data/dpobject.cxx | 11 | ||||
-rw-r--r-- | sc/source/core/data/dpoutput.cxx | 435 | ||||
-rw-r--r-- | sc/source/core/tool/interpr2.cxx | 90 |
5 files changed, 0 insertions, 544 deletions
diff --git a/sc/inc/dpobject.hxx b/sc/inc/dpobject.hxx index c217f1ed40ba..735b0334d8dc 100644 --- a/sc/inc/dpobject.hxx +++ b/sc/inc/dpobject.hxx @@ -183,8 +183,6 @@ public: const OUString& rDataFieldName, std::vector<com::sun::star::sheet::DataPilotFieldFilter>& rFilters); - bool GetPivotData( ScDPGetPivotDataField& rTarget, /* returns result */ - const std::vector< ScDPGetPivotDataField >& rFilters ); bool ParseFilters( ScDPGetPivotDataField& rTarget, std::vector< ScDPGetPivotDataField >& rFilters, const OUString& rFilterList ); diff --git a/sc/inc/dpoutput.hxx b/sc/inc/dpoutput.hxx index 49b9643c131b..293d93767356 100644 --- a/sc/inc/dpoutput.hxx +++ b/sc/inc/dpoutput.hxx @@ -143,12 +143,6 @@ public: field region. */ bool GetDataResultPositionData(::std::vector< ::com::sun::star::sheet::DataPilotFieldFilter >& rFilters, const ScAddress& rPos); - /** - * @return true on success and stores the result in rTarget, or false if - * rFilters or rTarget describe something that is not visible. - */ - bool GetPivotData( ScDPGetPivotDataField& rTarget, - const std::vector< ScDPGetPivotDataField >& rFilters ); long GetHeaderDim( const ScAddress& rPos, sal_uInt16& rOrient ); bool GetHeaderDrag( const ScAddress& rPos, bool bMouseLeft, bool bMouseTop, long nDragDim, diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx index 04273c8dd23b..dff56a52cd14 100644 --- a/sc/source/core/data/dpobject.cxx +++ b/sc/source/core/data/dpobject.cxx @@ -1363,17 +1363,6 @@ double ScDPObject::GetPivotData(const OUString& rDataFieldName, std::vector<shee return aRes[nDataIndex]; } -// Returns sal_True on success and stores the result in rTarget -bool ScDPObject::GetPivotData( ScDPGetPivotDataField& rTarget, - const std::vector< ScDPGetPivotDataField >& rFilters ) -{ - if (!mbEnableGetPivotData) - return false; - - CreateOutput(); // create xSource and pOutput if not already done - return pOutput->GetPivotData( rTarget, rFilters ); -} - bool ScDPObject::IsFilterButton( const ScAddress& rPos ) { CreateOutput(); // create xSource and pOutput if not already done 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(); diff --git a/sc/source/core/tool/interpr2.cxx b/sc/source/core/tool/interpr2.cxx index 67328043e71a..91d791f6e0f0 100644 --- a/sc/source/core/tool/interpr2.cxx +++ b/sc/source/core/tool/interpr2.cxx @@ -3082,7 +3082,6 @@ void ScInterpreter::ScGetPivotData() RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "sc", "er", "ScInterpreter::ScGetPivotData" ); sal_uInt8 nParamCount = GetByte(); -#if 1 if (!MustHaveParamCount(nParamCount, 2, 30) || (nParamCount % 2) == 1) { PushError(errNoRef); @@ -3155,95 +3154,6 @@ void ScInterpreter::ScGetPivotData() return; } PushDouble(fVal); - -#else - if ( MustHaveParamCount( nParamCount, 2, 30 ) ) - { - // there must be an even number of args - // target, ref, then field/item pairs - if( (nParamCount % 2) == 1) - goto failed; - - bool bOldSyntax = false; - if ( nParamCount == 2 ) - { - // if the first parameter is a ref, assume old syntax - StackVar eFirstType = GetStackType( 2 ); - if ( eFirstType == svSingleRef || eFirstType == svDoubleRef ) - bOldSyntax = true; - } - - ScDPGetPivotDataField aTarget; // target field, and returns result - std::vector< ScDPGetPivotDataField > aFilters; - String aFilterList; - if ( bOldSyntax ) - aFilterList = GetString(); // old syntax: second parameter is list of constraints - else - { - // new syntax: separate name/value pairs - - sal_uInt16 nFilterCount = nParamCount / 2 - 1; - aFilters.resize( nFilterCount ); - - sal_uInt16 i = nFilterCount; - while( i-- > 0 ) - { - //! should allow numeric constraint values - aFilters[i].mbValIsStr = true; - aFilters[i].maValStr = GetString(); - - aFilters[i].maFieldName = GetString(); - } - } - - // common to both syntaxes: a reference to the data pilot table - - ScRange aBlock; - switch ( GetStackType() ) - { - case svDoubleRef : - PopDoubleRef( aBlock ); - break; - - case svSingleRef : - { - ScAddress aAddr; - PopSingleRef( aAddr ); - aBlock = aAddr; - break; - } - default: - goto failed; - } - // NOTE : MS Excel docs claim to use the 'most recent' which is not - // exactly the same as what we do in ScDocument::GetDPAtBlock - // However we do need to use GetDPABlock - ScDPObject* pDPObj = pDok->GetDPAtBlock ( aBlock ); - if( NULL == pDPObj) - goto failed; - - if ( bOldSyntax ) - { - // fill aFilters / aTarget from aFilterList string - if ( !pDPObj->ParseFilters( aTarget, aFilters, aFilterList ) ) - goto failed; - } - else - aTarget.maFieldName = GetString(); // new syntax: first parameter is data field name - - if( pDPObj->GetPivotData( aTarget, aFilters ) ) - { - if( aTarget.mbValIsStr ) - PushString( aTarget.maValStr ); - else - PushDouble( aTarget.mnValNum ); - return; - } - } - -failed : - PushError( errNoRef ); -#endif } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |