From dc6bf6c8ae94fd89f30e39d63dfe02fdb042e98d Mon Sep 17 00:00:00 2001 From: Eike Rathke Date: Fri, 17 Jun 2016 13:31:48 +0200 Subject: Resolves: tdf#91365 use underlying numeric value if available [API CHANGE] ... at least for setting the cell content. There are more places where the numeric value could be transported but all Data Pilot pivot stuff is based on text strings :-/ This appends a double Value member to com::sun::star::sheet::MemberResult Change-Id: Ia9e8ac47d0877bd4a59a69d5921ce4ea082e8a69 --- offapi/com/sun/star/sheet/MemberResult.idl | 9 +++++++ sc/source/core/data/dpoutput.cxx | 43 +++++++++++++++++++++++------- sc/source/core/data/dptabres.cxx | 11 ++++++++ 3 files changed, 53 insertions(+), 10 deletions(-) diff --git a/offapi/com/sun/star/sheet/MemberResult.idl b/offapi/com/sun/star/sheet/MemberResult.idl index 8cb4c2247702..7de14f3169c3 100644 --- a/offapi/com/sun/star/sheet/MemberResult.idl +++ b/offapi/com/sun/star/sheet/MemberResult.idl @@ -46,6 +46,15 @@ struct MemberResult */ long Flags; + + /** the underlying numeric value of the field if Flags + indicate so by having + com::sun::star::sheet::MemberResultFlags::NUMERIC set. + + May be NaN if value is not available or unknown. + */ + double Value; + }; diff --git a/sc/source/core/data/dpoutput.cxx b/sc/source/core/data/dpoutput.cxx index 6b32a8478202..5d4550df61e2 100644 --- a/sc/source/core/data/dpoutput.cxx +++ b/sc/source/core/data/dpoutput.cxx @@ -81,15 +81,19 @@ struct ScDPOutLevelData long nDimPos; sal_uInt32 mnSrcNumFmt; /// Prevailing number format used in the source data. uno::Sequence aResult; - OUString maName; /// Name is the internal field name. - OUString maCaption; /// Caption is the name visible in the output table. + OUString maName; /// Name is the internal field name. + OUString maCaption; /// Caption is the name visible in the output table. + double mfValue; /// Value is the underlying numeric value, if any, or NaN bool mbHasHiddenMember:1; bool mbDataLayout:1; bool mbPageDim:1; ScDPOutLevelData() : - nDim(-1), nHier(-1), nLevel(-1), nDimPos(-1), mnSrcNumFmt(0), mbHasHiddenMember(false), mbDataLayout(false), mbPageDim(false) - {} + nDim(-1), nHier(-1), nLevel(-1), nDimPos(-1), mnSrcNumFmt(0), mbHasHiddenMember(false), mbDataLayout(false), + mbPageDim(false) + { + rtl::math::setNan(&mfValue); + } bool operator<(const ScDPOutLevelData& r) const { return nDimPos getVisiblePageMembersAsResults( const uno::Re bool bVisible = ScUnoHelpFunctions::GetBoolProperty(xMemPS, SC_UNO_DP_ISVISIBLE); if (bVisible) - aRes.push_back(sheet::MemberResult(rName, aCaption, 0)); + { + /* TODO: any numeric value to obtain? */ + double fValue; + rtl::math::setNan(&fValue); + aRes.push_back(sheet::MemberResult(rName, aCaption, 0, fValue)); + } } if (aNames.getLength() == static_cast(aRes.size())) @@ -601,6 +610,10 @@ ScDPOutput::ScDPOutput( ScDocument* pD, const uno::ReferenceSetValue( nCol, nRow, nTab, rData.Value); + } else - aParam.setTextInput(); + { + ScSetStringParam aParam; + if (bNumeric) + aParam.setNumericInput(); + else + aParam.setTextInput(); - pDoc->SetString(nCol, nRow, nTab, rData.Caption, &aParam); + pDoc->SetString(nCol, nRow, nTab, rData.Caption, &aParam); + } } if ( nFlags & sheet::MemberResultFlags::SUBTOTAL ) diff --git a/sc/source/core/data/dptabres.cxx b/sc/source/core/data/dptabres.cxx index af5ad122efd8..12a40ccef9a7 100644 --- a/sc/source/core/data/dptabres.cxx +++ b/sc/source/core/data/dptabres.cxx @@ -1313,6 +1313,8 @@ void ScDPResultMember::FillMemberResults( OSL_ENSURE( rPos+nSize <= pSequences->getLength(), "bumm" ); bool bIsNumeric = false; + double fValue; + rtl::math::setNan(&fValue); OUString aName; if ( pMemberName ) // if pMemberName != NULL, use instead of real member name { @@ -1338,6 +1340,11 @@ void ScDPResultMember::FillMemberResults( ScDPItemData::Type eType = aItemData.GetType(); bIsNumeric = eType == ScDPItemData::Value || eType == ScDPItemData::GroupValue; + // IsValue() is not identical to bIsNumeric, i.e. + // ScDPItemData::GroupValue is excluded and not stored in the double, + // so even if the item is numeric the Value may be NaN. + if (aItemData.IsValue()) + fValue = aItemData.GetValue(); } const ScDPDimension* pParentDim = GetParentDim(); @@ -1376,6 +1383,7 @@ void ScDPResultMember::FillMemberResults( pArray[rPos].Name = aName; pArray[rPos].Caption = aCaption; pArray[rPos].Flags |= sheet::MemberResultFlags::HASMEMBER; + pArray[rPos].Value = fValue; // set "continue" flag (removed for subtotals later) for (long i=1; i