diff options
Diffstat (limited to 'sc/source/core/data/dptabres.cxx')
-rw-r--r-- | sc/source/core/data/dptabres.cxx | 94 |
1 files changed, 82 insertions, 12 deletions
diff --git a/sc/source/core/data/dptabres.cxx b/sc/source/core/data/dptabres.cxx index 398d4d1c7e01..e548db56d7ff 100644 --- a/sc/source/core/data/dptabres.cxx +++ b/sc/source/core/data/dptabres.cxx @@ -67,6 +67,7 @@ using ::std::vector; using ::std::pair; using ::std::hash_map; using ::com::sun::star::uno::Sequence; +using ::rtl::OUString; // ----------------------------------------------------------------------- @@ -825,11 +826,11 @@ USHORT ScDPResultData::GetMeasureRefOrient(long nMeasure) const return pMeasRefOrient[nMeasure]; } -String ScDPResultData::GetMeasureString(long nMeasure, BOOL bForce, ScSubTotalFunc eForceFunc) const +String ScDPResultData::GetMeasureString(long nMeasure, BOOL bForce, ScSubTotalFunc eForceFunc, bool& rbTotalResult) const { // with bForce==TRUE, return function instead of "result" for single measure // with eForceFunc != SUBTOTAL_FUNC_NONE, always use eForceFunc - + rbTotalResult = false; if ( nMeasure < 0 || ( nMeasCount == 1 && !bForce && eForceFunc == SUBTOTAL_FUNC_NONE ) ) { // for user-specified subtotal function with all measures, @@ -837,12 +838,19 @@ String ScDPResultData::GetMeasureString(long nMeasure, BOOL bForce, ScSubTotalFu if ( eForceFunc != SUBTOTAL_FUNC_NONE ) return ScGlobal::GetRscString(nFuncStrIds[eForceFunc]); + rbTotalResult = true; return ScGlobal::GetRscString(STR_TABLE_ERGEBNIS); } else { DBG_ASSERT( pMeasNames && nMeasure < nMeasCount, "bumm" ); - + ScDPDimension* pDataDim = pSource->GetDataDimension(nMeasure); + if (pDataDim) + { + const OUString* pLayoutName = pDataDim->GetLayoutName(); + if (pLayoutName) + return *pLayoutName; + } String aRet; ScSubTotalFunc eFunc = ( eForceFunc == SUBTOTAL_FUNC_NONE ) ? GetMeasureFunction(nMeasure) : eForceFunc; @@ -896,6 +904,11 @@ BOOL ScDPResultData::HasCommonElement( const ScDPItemData& rFirstData, long nFir return pSource->GetData()->HasCommonElement( rFirstData, nFirstIndex, rSecondData, nSecondIndex ); } +const ScDPSource* ScDPResultData::GetSource() const +{ + return pSource; +} + // ----------------------------------------------------------------------- @@ -1172,6 +1185,33 @@ void ScDPResultMember::ProcessData( const vector<ScDPItemData>& aChildMembers, c } } +/** + * Parse subtotal string and replace all occurrences of '?' with the caption + * string. Do ensure that escaped characters are not translated. + */ +static String lcl_parseSubtotalName(const String& rSubStr, const String& rCaption) +{ + String aNewStr; + xub_StrLen n = rSubStr.Len(); + bool bEscaped = false; + for (xub_StrLen i = 0; i < n; ++i) + { + sal_Unicode c = rSubStr.GetChar(i); + if (!bEscaped && c == sal_Unicode('\\')) + { + bEscaped = true; + continue; + } + + if (!bEscaped && c == sal_Unicode('?')) + aNewStr.Append(rCaption); + else + aNewStr.Append(c); + bEscaped = false; + } + return aNewStr; +} + void ScDPResultMember::FillMemberResults( uno::Sequence<sheet::MemberResult>* pSequences, long& rPos, long nMeasure, BOOL bRoot, const String* pMemberName, @@ -1204,17 +1244,25 @@ void ScDPResultMember::FillMemberResults( uno::Sequence<sheet::MemberResult>* pS } String aCaption = aName; + if (pMemberDesc) + { + const OUString* pLayoutName = pMemberDesc->GetLayoutName(); + if (pLayoutName) + { + aCaption = *pLayoutName; + bIsNumeric = false; // layout name is always non-numeric. + } + } + if ( pMemberCaption ) // use pMemberCaption if != NULL aCaption = *pMemberCaption; if (!aCaption.Len()) aCaption = ScGlobal::GetRscString(STR_EMPTYDATA); - if ( !bIsNumeric ) - { - // add a "'" character so a string isn't parsed as value in the output cell - //! have a separate bit in Flags (MemberResultFlags) instead? - aCaption.Insert( (sal_Unicode) '\'', 0 ); - } + if (bIsNumeric) + pArray[rPos].Flags |= sheet::MemberResultFlags::NUMERIC; + else + pArray[rPos].Flags &= ~sheet::MemberResultFlags::NUMERIC; if ( nSize && !bRoot ) // root is overwritten by first dimension { @@ -1277,9 +1325,30 @@ void ScDPResultMember::FillMemberResults( uno::Sequence<sheet::MemberResult>* pS if (bHasChild) eForce = lcl_GetForceFunc( pParentLevel, nUserPos ); - String aSubStr = aName; //! caption? + bool bTotalResult = false; + String aSubStr = aCaption; aSubStr += ' '; - aSubStr += pResultData->GetMeasureString(nMemberMeasure, FALSE, eForce); + aSubStr += pResultData->GetMeasureString(nMemberMeasure, FALSE, eForce, bTotalResult); + + if (bTotalResult) + { + if (pMemberDesc) + { + // single data field layout. + const OUString* pSubtotalName = pParentDim->GetSubtotalName(); + if (pSubtotalName) + aSubStr = lcl_parseSubtotalName(*pSubtotalName, aCaption); + pArray[rPos].Flags &= ~sheet::MemberResultFlags::GRANDTOTAL; + } + else + { + // root member - subtotal (grand total?) for multi-data field layout. + const rtl::OUString* pGrandTotalName = pResultData->GetSource()->GetGrandTotalName(); + if (pGrandTotalName) + aSubStr = *pGrandTotalName; + pArray[rPos].Flags |= sheet::MemberResultFlags::GRANDTOTAL; + } + } pArray[rPos].Name = rtl::OUString(aName); pArray[rPos].Caption = rtl::OUString(aSubStr); @@ -2796,8 +2865,9 @@ void ScDPResultDimension::FillMemberResults( uno::Sequence<sheet::MemberResult>* // in data layout dimension, use first member with different measures/names if ( bIsDataLayout ) { + bool bTotalResult = false; String aMbrName = pResultData->GetMeasureDimensionName( nSorted ); - String aMbrCapt = pResultData->GetMeasureString( nSorted, FALSE, SUBTOTAL_FUNC_NONE ); + String aMbrCapt = pResultData->GetMeasureString( nSorted, FALSE, SUBTOTAL_FUNC_NONE, bTotalResult ); maMemberArray[0]->FillMemberResults( pSequences, nPos, nSorted, FALSE, &aMbrName, &aMbrCapt ); } else if ( pMember->IsVisible() ) |