From 324d87a130d929fe59379ed8c15e33f7c74e38dd Mon Sep 17 00:00:00 2001 From: Kohei Yoshida Date: Thu, 11 Jul 2013 22:00:54 -0400 Subject: fdo#66655: Get GETPIVOTDATA to work again. 1) Compare data field name as it is displayed in the table output. 2) In the result tree, store field member names as strings as displayed in the table output, instead of as ScDPItemData. GETPIVOTDATA operates on displayed cell values and do textural comparison. There is no use storing ScDPItemData which screws up value lookup in the result tree. Change-Id: I31bc03a6800f4fadf2ba1180d1958354d43e8a07 --- sc/inc/datauno.hxx | 1 - sc/inc/dpresfilter.hxx | 4 +-- sc/inc/dptabres.hxx | 2 ++ sc/inc/dputil.hxx | 11 ++++++-- sc/source/core/data/dpobject.cxx | 10 ++++++- sc/source/core/data/dptabres.cxx | 45 ++++++++++++++++------------- sc/source/core/data/dptabsrc.cxx | 2 +- sc/source/core/data/dputil.cxx | 59 ++++++++++++++++++++++++++++++++++++++- sc/source/filter/xml/xmldrani.cxx | 4 +-- sc/source/ui/unoobj/cellsuno.cxx | 55 ++---------------------------------- sc/source/ui/unoobj/datauno.cxx | 37 +++--------------------- 11 files changed, 114 insertions(+), 116 deletions(-) (limited to 'sc') diff --git a/sc/inc/datauno.hxx b/sc/inc/datauno.hxx index 2acde1871cb9..a2562c21f7bf 100644 --- a/sc/inc/datauno.hxx +++ b/sc/inc/datauno.hxx @@ -68,7 +68,6 @@ typedef boost::ptr_vector XDBRefreshListenerArr_Impl; class ScDataUnoConversion { public: - static ScSubTotalFunc GeneralToSubTotal( com::sun::star::sheet::GeneralFunction eSummary ); static com::sun::star::sheet::GeneralFunction SubTotalToGeneral( ScSubTotalFunc eSubTotal ); }; diff --git a/sc/inc/dpresfilter.hxx b/sc/inc/dpresfilter.hxx index bde3c02cb55e..be84b8c83c2d 100644 --- a/sc/inc/dpresfilter.hxx +++ b/sc/inc/dpresfilter.hxx @@ -24,7 +24,7 @@ namespace com { namespace sun { namespace star { namespace sheet { struct ScDPResultFilter { OUString maDimName; - ScDPItemData maValue; + OUString maValue; bool mbHasValue:1; bool mbDataLayout:1; @@ -55,7 +55,7 @@ private: struct MemberNode; struct DimensionNode; - typedef std::map MembersType; + typedef std::map MembersType; typedef std::map DimensionsType; struct DimensionNode : boost::noncopyable diff --git a/sc/inc/dptabres.hxx b/sc/inc/dptabres.hxx index cab2da82d9f7..30fc21224dfe 100644 --- a/sc/inc/dptabres.hxx +++ b/sc/inc/dptabres.hxx @@ -380,6 +380,8 @@ public: ScDPInitState& rInitState); void CheckShowEmpty( bool bShow = false ); OUString GetName() const; + OUString GetDisplayName() const; + void FillItemData( ScDPItemData& rData ) const; bool IsValid() const; bool IsVisible() const; diff --git a/sc/inc/dputil.hxx b/sc/inc/dputil.hxx index 425d33301ed2..294ca97b6339 100644 --- a/sc/inc/dputil.hxx +++ b/sc/inc/dputil.hxx @@ -7,11 +7,14 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef __SC_DPUTIL_HXX__ -#define __SC_DPUTIL_HXX__ +#ifndef SC_DPUTIL_HXX +#define SC_DPUTIL_HXX #include "rtl/ustring.hxx" #include "scdllapi.h" +#include "global.hxx" + +#include class SvNumberFormatter; struct ScDPNumGroupInfo; @@ -38,6 +41,10 @@ public: static sal_Int32 getDatePartValue( double fValue, const ScDPNumGroupInfo& rInfo, sal_Int32 nDatePart, SvNumberFormatter* pFormatter); + + static OUString getDisplayedMeasureName(const OUString& rName, ScSubTotalFunc eFunc); + + static ScSubTotalFunc toSubTotalFunc(com::sun::star::sheet::GeneralFunction eGenFunc); }; #endif diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx index 5b1017bd8272..eca69a93e447 100644 --- a/sc/source/core/data/dpobject.cxx +++ b/sc/source/core/data/dpobject.cxx @@ -1289,11 +1289,19 @@ public: FindByName(const OUString& rName) : maName(rName) {} bool operator() (const ScDPSaveDimension* pDim) const { + // Layout name takes precedence. const OUString* pLayoutName = pDim->GetLayoutName(); if (pLayoutName) return *pLayoutName == maName; - return maName == pDim->GetName(); + sheet::GeneralFunction eGenFunc = static_cast(pDim->GetFunction()); + ScSubTotalFunc eFunc = ScDPUtil::toSubTotalFunc(eGenFunc); + OUString aSrcName = ScDPUtil::getSourceDimensionName(pDim->GetName()); + OUString aFuncName = ScDPUtil::getDisplayedMeasureName(aSrcName, eFunc); + if (maName == aFuncName) + return true; + + return maName == aSrcName; } }; diff --git a/sc/source/core/data/dptabres.cxx b/sc/source/core/data/dptabres.cxx index 21e1486bf55c..3a2ea7c945cb 100644 --- a/sc/source/core/data/dptabres.cxx +++ b/sc/source/core/data/dptabres.cxx @@ -24,12 +24,12 @@ #include "global.hxx" #include "subtotal.hxx" #include "globstr.hrc" -#include "datauno.hxx" // ScDataUnoConversion #include "dpitemdata.hxx" #include "document.hxx" // for DumpState only! #include "stlalgorithm.hxx" #include "dpresfilter.hxx" +#include "dputil.hxx" #include #include @@ -110,7 +110,7 @@ public: mrFilters.push_back(ScDPResultFilter(rName, bDataLayout)); } - void pushDimValue(const ScDPItemData& rValue) + void pushDimValue(const OUString& rValue) { ScDPResultFilter& rFilter = mrFilters.back(); rFilter.maValue = rValue; @@ -749,7 +749,7 @@ static ScSubTotalFunc lcl_GetForceFunc( const ScDPLevel* pLevel, long nFuncNo ) { sheet::GeneralFunction eUser = aSeq.getConstArray()[nFuncNo]; if (eUser != sheet::GeneralFunction_AUTO) - eRet = ScDataUnoConversion::GeneralToSubTotal( eUser ); + eRet = ScDPUtil::toSubTotalFunc(eUser); } } return eRet; @@ -863,18 +863,11 @@ OUString ScDPResultData::GetMeasureString(long nMeasure, bool bForce, ScSubTotal if (pLayoutName) return *pLayoutName; } - OUStringBuffer aRet; + ScSubTotalFunc eFunc = ( eForceFunc == SUBTOTAL_FUNC_NONE ) ? GetMeasureFunction(nMeasure) : eForceFunc; - sal_uInt16 nId = nFuncStrIds[eFunc]; - if (nId) - { - aRet.append(ScGlobal::GetRscString(nId)); // function name - aRet.appendAscii(RTL_CONSTASCII_STRINGPARAM(" - ")); - } - aRet.append(maMeasureNames[nMeasure]); // field name - return aRet.makeStringAndClear(); + return ScDPUtil::getDisplayedMeasureName(maMeasureNames[nMeasure], eFunc); } } @@ -1004,6 +997,23 @@ OUString ScDPResultMember::GetName() const return ScGlobal::GetRscString(STR_PIVOT_TOTAL); // root member } +OUString ScDPResultMember::GetDisplayName() const +{ + const ScDPMember* pDPMember = GetDPMember(); + if (!pDPMember) + return OUString(); + + ScDPItemData aItem; + pDPMember->FillItemData(aItem); + if (aParentDimData.mpParentDim) + { + long nDim = aParentDimData.mpParentDim->GetDimension(); + return pResultData->GetSource().GetData()->GetFormattedString(nDim, aItem); + } + + return aItem.GetString(); +} + void ScDPResultMember::FillItemData( ScDPItemData& rData ) const { const ScDPMember* pMemberDesc = GetDPMember(); @@ -1536,10 +1546,9 @@ void ScDPResultMember::FillDataResults( if (pDPMember) { // Root result has no corresponding DP member. Only take the non-root results. - ScDPItemData aItem; - pDPMember->FillItemData(aItem); + OUString aMemStr = GetDisplayName(); pFilterStack.reset(new FilterStack(rFilterCxt.maFilters)); - pFilterStack->pushDimValue(aItem); + pFilterStack->pushDimValue(aMemStr); } // IsVisible() test is in ScDPResultDimension::FillDataResults @@ -2044,12 +2053,8 @@ void ScDPDataMember::FillDataRow( // Topmost data member (pResultMember=NULL) doesn't need to be handled // since its immediate parent result member is linked to the same // dimension member. - ScDPItemData aItem; - const ScDPMember* pDPMember = pResultMember->GetDPMember(); - if (pDPMember) - pDPMember->FillItemData(aItem); pFilterStack.reset(new FilterStack(rFilterCxt.maFilters)); - pFilterStack->pushDimValue(aItem); + pFilterStack->pushDimValue(pResultMember->GetDisplayName()); } OSL_ENSURE( pRefMember == pResultMember || !pResultMember, "bla" ); diff --git a/sc/source/core/data/dptabsrc.cxx b/sc/source/core/data/dptabsrc.cxx index d21590a10c8c..17b0fab6ac33 100644 --- a/sc/source/core/data/dptabsrc.cxx +++ b/sc/source/core/data/dptabsrc.cxx @@ -823,7 +823,7 @@ void ScDPSource::CreateRes_Impl() } // Map UNO's enum to internal enum ScSubTotalFunc. - aDataFunctions.push_back(ScDataUnoConversion::GeneralToSubTotal(eUser)); + aDataFunctions.push_back(ScDPUtil::toSubTotalFunc(eUser)); // Get reference field/item information. aDataRefValues.push_back(pDim->GetReferenceValue()); diff --git a/sc/source/core/data/dputil.cxx b/sc/source/core/data/dputil.cxx index e4240ba60769..8eb836aa1458 100644 --- a/sc/source/core/data/dputil.cxx +++ b/sc/source/core/data/dputil.cxx @@ -11,10 +11,10 @@ */ #include "dputil.hxx" -#include "global.hxx" #include "dpitemdata.hxx" #include "dpnumgroupinfo.hxx" #include "globalnames.hxx" +#include "globstr.hrc" #include "comphelper/string.hxx" #include "unotools/localedatawrapper.hxx" @@ -347,4 +347,61 @@ sal_Int32 ScDPUtil::getDatePartValue( return nResult; } +namespace { + +sal_uInt16 nFuncStrIds[12] = { + 0, // SUBTOTAL_FUNC_NONE + STR_FUN_TEXT_AVG, // SUBTOTAL_FUNC_AVE + STR_FUN_TEXT_COUNT, // SUBTOTAL_FUNC_CNT + STR_FUN_TEXT_COUNT, // SUBTOTAL_FUNC_CNT2 + STR_FUN_TEXT_MAX, // SUBTOTAL_FUNC_MAX + STR_FUN_TEXT_MIN, // SUBTOTAL_FUNC_MIN + STR_FUN_TEXT_PRODUCT, // SUBTOTAL_FUNC_PROD + STR_FUN_TEXT_STDDEV, // SUBTOTAL_FUNC_STD + STR_FUN_TEXT_STDDEV, // SUBTOTAL_FUNC_STDP + STR_FUN_TEXT_SUM, // SUBTOTAL_FUNC_SUM + STR_FUN_TEXT_VAR, // SUBTOTAL_FUNC_VAR + STR_FUN_TEXT_VAR // SUBTOTAL_FUNC_VARP +}; + +} + +OUString ScDPUtil::getDisplayedMeasureName(const OUString& rName, ScSubTotalFunc eFunc) +{ + OUStringBuffer aRet; + sal_uInt16 nId = nFuncStrIds[eFunc]; + if (nId) + { + aRet.append(ScGlobal::GetRscString(nId)); // function name + aRet.appendAscii(RTL_CONSTASCII_STRINGPARAM(" - ")); + } + aRet.append(rName); // field name + + return aRet.makeStringAndClear(); +} + +ScSubTotalFunc ScDPUtil::toSubTotalFunc(com::sun::star::sheet::GeneralFunction eGenFunc) +{ + ScSubTotalFunc eSubTotal; + switch (eGenFunc) + { + case sheet::GeneralFunction_NONE: eSubTotal = SUBTOTAL_FUNC_NONE; break; + case sheet::GeneralFunction_SUM: eSubTotal = SUBTOTAL_FUNC_SUM; break; + case sheet::GeneralFunction_COUNT: eSubTotal = SUBTOTAL_FUNC_CNT2; break; + case sheet::GeneralFunction_AVERAGE: eSubTotal = SUBTOTAL_FUNC_AVE; break; + case sheet::GeneralFunction_MAX: eSubTotal = SUBTOTAL_FUNC_MAX; break; + case sheet::GeneralFunction_MIN: eSubTotal = SUBTOTAL_FUNC_MIN; break; + case sheet::GeneralFunction_PRODUCT: eSubTotal = SUBTOTAL_FUNC_PROD; break; + case sheet::GeneralFunction_COUNTNUMS: eSubTotal = SUBTOTAL_FUNC_CNT; break; + case sheet::GeneralFunction_STDEV: eSubTotal = SUBTOTAL_FUNC_STD; break; + case sheet::GeneralFunction_STDEVP: eSubTotal = SUBTOTAL_FUNC_STDP; break; + case sheet::GeneralFunction_VAR: eSubTotal = SUBTOTAL_FUNC_VAR; break; + case sheet::GeneralFunction_VARP: eSubTotal = SUBTOTAL_FUNC_VARP; break; + case sheet::GeneralFunction_AUTO: + default: + eSubTotal = SUBTOTAL_FUNC_NONE; + } + return eSubTotal; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/filter/xml/xmldrani.cxx b/sc/source/filter/xml/xmldrani.cxx index 9e98d38a6c4d..97483e3d6433 100644 --- a/sc/source/filter/xml/xmldrani.cxx +++ b/sc/source/filter/xml/xmldrani.cxx @@ -33,6 +33,7 @@ #include "XMLConverter.hxx" #include "rangeutl.hxx" #include "queryentry.hxx" +#include "dputil.hxx" #include #include @@ -398,8 +399,7 @@ ScDBData* ScXMLDatabaseRangeContext::ConvertToDBData(const OUString& rName) for (SCCOL i = 0; i < nCount; ++i) { aParam.pSubTotals[nPos][i] = static_cast(pAry[i].Column); - aParam.pFunctions[nPos][i] = - ScDataUnoConversion::GeneralToSubTotal( pAry[i].Function ); + aParam.pFunctions[nPos][i] = ScDPUtil::toSubTotalFunc(pAry[i].Function); } } else diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx index d60140312156..f1c288f2dcaf 100644 --- a/sc/source/ui/unoobj/cellsuno.cxx +++ b/sc/source/ui/unoobj/cellsuno.cxx @@ -122,6 +122,7 @@ #include "formulaiter.hxx" #include "tokenarray.hxx" #include "stylehelper.hxx" +#include "dputil.hxx" #include #include @@ -933,58 +934,6 @@ static sal_Bool lcl_WholeSheet( const ScRangeList& rRanges ) return false; } -//------------------------------------------------------------------------ - -static ScSubTotalFunc lcl_SummaryToSubTotal( sheet::GeneralFunction eSummary ) -{ - ScSubTotalFunc eSubTotal; - switch (eSummary) - { - case sheet::GeneralFunction_SUM: - eSubTotal = SUBTOTAL_FUNC_SUM; - break; - case sheet::GeneralFunction_COUNT: - eSubTotal = SUBTOTAL_FUNC_CNT2; - break; - case sheet::GeneralFunction_AVERAGE: - eSubTotal = SUBTOTAL_FUNC_AVE; - break; - case sheet::GeneralFunction_MAX: - eSubTotal = SUBTOTAL_FUNC_MAX; - break; - case sheet::GeneralFunction_MIN: - eSubTotal = SUBTOTAL_FUNC_MIN; - break; - case sheet::GeneralFunction_PRODUCT: - eSubTotal = SUBTOTAL_FUNC_PROD; - break; - case sheet::GeneralFunction_COUNTNUMS: - eSubTotal = SUBTOTAL_FUNC_CNT; - break; - case sheet::GeneralFunction_STDEV: - eSubTotal = SUBTOTAL_FUNC_STD; - break; - case sheet::GeneralFunction_STDEVP: - eSubTotal = SUBTOTAL_FUNC_STDP; - break; - case sheet::GeneralFunction_VAR: - eSubTotal = SUBTOTAL_FUNC_VAR; - break; - case sheet::GeneralFunction_VARP: - eSubTotal = SUBTOTAL_FUNC_VARP; - break; - - case sheet::GeneralFunction_NONE: - case sheet::GeneralFunction_AUTO: - default: - eSubTotal = SUBTOTAL_FUNC_NONE; - break; - } - return eSubTotal; -} - -//------------------------------------------------------------------------ - namespace { template const ::editeng::SvxBorderLine* lcl_getBorderLine( @@ -1877,7 +1826,7 @@ double SAL_CALL ScCellRangesBase::computeFunction( sheet::GeneralFunction nFunct ScAddress aDummy; // wenn nicht Marked, ignoriert wegen Negative double fVal; - ScSubTotalFunc eFunc = lcl_SummaryToSubTotal( nFunction ); + ScSubTotalFunc eFunc = ScDPUtil::toSubTotalFunc(nFunction); ScDocument* pDoc = pDocShell->GetDocument(); if ( !pDoc->GetSelectionFunction( eFunc, aDummy, aMark, fVal ) ) { diff --git a/sc/source/ui/unoobj/datauno.cxx b/sc/source/ui/unoobj/datauno.cxx index df93ca452569..23cf3da9c0b6 100644 --- a/sc/source/ui/unoobj/datauno.cxx +++ b/sc/source/ui/unoobj/datauno.cxx @@ -48,6 +48,7 @@ #include "attrib.hxx" #include "dpshttab.hxx" #include "queryentry.hxx" +#include "dputil.hxx" #include #include @@ -134,34 +135,6 @@ SC_SIMPLE_SERVICE_INFO( ScFilterDescriptorBase, "ScFilterDescriptorBase", "com.s SC_SIMPLE_SERVICE_INFO( ScSubTotalDescriptorBase, "ScSubTotalDescriptorBase", "com.sun.star.sheet.SubTotalDescriptor" ) SC_SIMPLE_SERVICE_INFO( ScSubTotalFieldObj, "ScSubTotalFieldObj", "com.sun.star.sheet.SubTotalField" ) - -//------------------------------------------------------------------------ - -ScSubTotalFunc ScDataUnoConversion::GeneralToSubTotal( sheet::GeneralFunction eSummary ) -{ - ScSubTotalFunc eSubTotal; - switch (eSummary) - { - case sheet::GeneralFunction_NONE: eSubTotal = SUBTOTAL_FUNC_NONE; break; - case sheet::GeneralFunction_SUM: eSubTotal = SUBTOTAL_FUNC_SUM; break; - case sheet::GeneralFunction_COUNT: eSubTotal = SUBTOTAL_FUNC_CNT2; break; - case sheet::GeneralFunction_AVERAGE: eSubTotal = SUBTOTAL_FUNC_AVE; break; - case sheet::GeneralFunction_MAX: eSubTotal = SUBTOTAL_FUNC_MAX; break; - case sheet::GeneralFunction_MIN: eSubTotal = SUBTOTAL_FUNC_MIN; break; - case sheet::GeneralFunction_PRODUCT: eSubTotal = SUBTOTAL_FUNC_PROD; break; - case sheet::GeneralFunction_COUNTNUMS: eSubTotal = SUBTOTAL_FUNC_CNT; break; - case sheet::GeneralFunction_STDEV: eSubTotal = SUBTOTAL_FUNC_STD; break; - case sheet::GeneralFunction_STDEVP: eSubTotal = SUBTOTAL_FUNC_STDP; break; - case sheet::GeneralFunction_VAR: eSubTotal = SUBTOTAL_FUNC_VAR; break; - case sheet::GeneralFunction_VARP: eSubTotal = SUBTOTAL_FUNC_VARP; break; - case sheet::GeneralFunction_AUTO: - default: - OSL_FAIL("GeneralToSubTotal: falscher enum"); - eSubTotal = SUBTOTAL_FUNC_NONE; - } - return eSubTotal; -} - sheet::GeneralFunction ScDataUnoConversion::SubTotalToGeneral( ScSubTotalFunc eSubTotal ) { sheet::GeneralFunction eGeneral; @@ -569,8 +542,7 @@ void SAL_CALL ScSubTotalFieldObj::setSubTotalColumns( for (SCCOL i=0; i(pAry[i].Column); - aParam.pFunctions[nPos][i] = - ScDataUnoConversion::GeneralToSubTotal( pAry[i].Function ); + aParam.pFunctions[nPos][i] = ScDPUtil::toSubTotalFunc(pAry[i].Function); } } else @@ -651,8 +623,7 @@ void SAL_CALL ScSubTotalDescriptorBase::addNew( for (SCCOL i=0; i(pAry[i].Column); - aParam.pFunctions[nPos][i] = - ScDataUnoConversion::GeneralToSubTotal( pAry[i].Function ); + aParam.pFunctions[nPos][i] = ScDPUtil::toSubTotalFunc(pAry[i].Function); } } else @@ -919,7 +890,7 @@ void SAL_CALL ScConsolidationDescriptor::setFunction( sheet::GeneralFunction nFu throw(uno::RuntimeException) { SolarMutexGuard aGuard; - aParam.eFunction = ScDataUnoConversion::GeneralToSubTotal(nFunction); + aParam.eFunction = ScDPUtil::toSubTotalFunc(nFunction); } uno::Sequence SAL_CALL ScConsolidationDescriptor::getSources() -- cgit