diff options
author | Kohei Yoshida <kohei.yoshida@suse.com> | 2012-03-05 14:49:21 -0500 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2012-03-09 11:13:29 -0500 |
commit | b814c1749aa9c233f7eabf605be663068d47de13 (patch) | |
tree | cb9071f19cc6fa5259531485cb63bfb26c1c2b39 /sc | |
parent | Fix the result hierarchy construction. Still lots of places remain broken. (diff) | |
download | core-b814c1749aa9c233f7eabf605be663068d47de13.tar.gz core-b814c1749aa9c233f7eabf605be663068d47de13.zip |
Display date group values correctly.
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/dpitemdata.hxx | 2 | ||||
-rw-r--r-- | sc/source/core/data/dpgroup.cxx | 62 | ||||
-rw-r--r-- | sc/source/core/data/dpitemdata.cxx | 50 | ||||
-rw-r--r-- | sc/source/core/data/dptablecache.cxx | 8 | ||||
-rw-r--r-- | sc/source/core/data/dptabres.cxx | 3 |
5 files changed, 48 insertions, 77 deletions
diff --git a/sc/inc/dpitemdata.hxx b/sc/inc/dpitemdata.hxx index 2fa8cba62ebf..0323b91cae74 100644 --- a/sc/inc/dpitemdata.hxx +++ b/sc/inc/dpitemdata.hxx @@ -49,7 +49,7 @@ class SC_DLLPUBLIC ScDPItemData friend class ScDPCache; public: - enum Type { String, Value, Error, Empty, GroupValue }; + enum Type { GroupValue = 0, Value = 1, String = 2, Error = 3, Empty = 4 }; struct GroupValueAttr { diff --git a/sc/source/core/data/dpgroup.cxx b/sc/source/core/data/dpgroup.cxx index fde7759d5149..3f628e7ee798 100644 --- a/sc/source/core/data/dpgroup.cxx +++ b/sc/source/core/data/dpgroup.cxx @@ -522,64 +522,6 @@ sal_Int32 lcl_GetDatePartValue( double fValue, sal_Int32 nDatePart, SvNumberForm return nResult; } -sal_Bool lcl_DateContained( sal_Int32 nGroupPart, const ScDPItemData& rGroupData, - sal_Int32 nBasePart, const ScDPItemData& rBaseData ) -{ - if ( !rGroupData.IsValue() || !rBaseData.IsValue() ) - { - // non-numeric entries involved: only match equal entries - return rGroupData.IsCaseInsEqual( rBaseData ); - } - - // no approxFloor needed, values were created from integers - sal_Int32 nGroupValue = (sal_Int32) rGroupData.GetValue(); - sal_Int32 nBaseValue = (sal_Int32) rBaseData.GetValue(); - if ( nBasePart > nGroupPart ) - { - // switch, so the base part is the smaller (inner) part - - ::std::swap( nGroupPart, nBasePart ); - ::std::swap( nGroupValue, nBaseValue ); - } - - if ( nGroupValue == SC_DP_DATE_FIRST || nGroupValue == SC_DP_DATE_LAST || - nBaseValue == SC_DP_DATE_FIRST || nBaseValue == SC_DP_DATE_LAST ) - { - // first/last entry matches only itself - return ( nGroupValue == nBaseValue ); - } - - sal_Bool bContained = sal_True; - switch ( nBasePart ) // inner part - { - case com::sun::star::sheet::DataPilotFieldGroupBy::MONTHS: - // a month is only contained in its quarter - if ( nGroupPart == com::sun::star::sheet::DataPilotFieldGroupBy::QUARTERS ) - { - // months and quarters are both 1-based - bContained = ( nGroupValue - 1 == ( nBaseValue - 1 ) / 3 ); - } - break; - case com::sun::star::sheet::DataPilotFieldGroupBy::DAYS: - // a day is only contained in its quarter or month - if ( nGroupPart == com::sun::star::sheet::DataPilotFieldGroupBy::MONTHS || nGroupPart == com::sun::star::sheet::DataPilotFieldGroupBy::QUARTERS ) - { - Date aDate( 1, 1, SC_DP_LEAPYEAR ); - aDate += ( nBaseValue - 1 ); // days are 1-based - sal_Int32 nCompare = aDate.GetMonth(); - if ( nGroupPart == com::sun::star::sheet::DataPilotFieldGroupBy::QUARTERS ) - nCompare = ( ( nCompare - 1 ) / 3 ) + 1; // get quarter from date - - bContained = ( nGroupValue == nCompare ); - } - break; - - // other parts: everything is contained - } - - return bContained; -} - String lcl_GetSpecialDateName( double fValue, bool bFirst, SvNumberFormatter* pFormatter ) { rtl::OUStringBuffer aBuffer; @@ -1577,9 +1519,7 @@ sal_Bool ScDPGroupTableData::HasCommonElement( const ScDPItemData& rFirstData, l return true; } - sal_Int32 nFirstPart = pFirstDateHelper->GetDatePart(); - sal_Int32 nSecondPart = pSecondDateHelper->GetDatePart(); - return lcl_DateContained( nFirstPart, rFirstData, nSecondPart, rSecondData ); + return isDateInGroup(rFirstData, rSecondData); } const ScDPGroupItem* pFirstItem = pFirstDim->GetGroupForName( rFirstData ); diff --git a/sc/source/core/data/dpitemdata.cxx b/sc/source/core/data/dpitemdata.cxx index b710ed3b304c..92cbab55602b 100644 --- a/sc/source/core/data/dpitemdata.cxx +++ b/sc/source/core/data/dpitemdata.cxx @@ -36,17 +36,40 @@ sal_Int32 ScDPItemData::Compare(const ScDPItemData& rA, const ScDPItemData& rB) { - if ( rA.IsValue() ) + if (rA.meType != rB.meType) { - if ( rB.IsValue() ) + // group value, value and string in this order. + return rA.meType < rB.meType; + } + + switch (rA.meType) + { + case GroupValue: + { + if (rA.maGroupValue.mnGroupType == rB.maGroupValue.mnGroupType) + { + if (rA.maGroupValue.mnValue == rB.maGroupValue.mnValue) + return 0; + + return rA.maGroupValue.mnValue < rB.maGroupValue.mnValue; + } + + return rA.maGroupValue.mnGroupType < rB.maGroupValue.mnGroupType; + } + case Value: + { + if (rA.mfValue == rB.mfValue) + return 0; + return rA.mfValue < rB.mfValue ? -1 : 1; - else - return -1; // values first + } + case String: + case Error: + return ScGlobal::GetCollator()->compareString(rA.GetString(), rB.GetString()); + default: + ; } - else if ( rB.IsValue() ) - return 1; // values first - else - return ScGlobal::GetCollator()->compareString(rA.GetString(), rB.GetString()); + return 0; } ScDPItemData::ScDPItemData() : @@ -216,14 +239,16 @@ void ScDPItemData::Dump(const char* msg) const printf("empty\n"); break; case Error: - printf("error\n"); + printf("error: %s\n", + rtl::OUStringToOString(*mpString, RTL_TEXTENCODING_UTF8).getStr()); break; case GroupValue: printf("group value: group type = %d value = %d\n", maGroupValue.mnGroupType, maGroupValue.mnValue); break; case String: - printf("string\n"); + printf("string: %s\n", + rtl::OUStringToOString(*mpString, RTL_TEXTENCODING_UTF8).getStr()); break; case Value: printf("value: %g\n", mfValue); @@ -242,7 +267,7 @@ bool ScDPItemData::IsEmpty() const bool ScDPItemData::IsValue() const { - return meType == Value || meType == GroupValue; + return meType == Value; } rtl::OUString ScDPItemData::GetString() const @@ -267,9 +292,6 @@ double ScDPItemData::GetValue() const if (meType == Value) return mfValue; - if (meType == GroupValue) - return maGroupValue.mnValue; - return 0.0; } diff --git a/sc/source/core/data/dptablecache.cxx b/sc/source/core/data/dptablecache.cxx index 9afaed8e3b77..5b2af50d02e1 100644 --- a/sc/source/core/data/dptablecache.cxx +++ b/sc/source/core/data/dptablecache.cxx @@ -37,6 +37,7 @@ #include "globstr.hrc" #include "docoptio.hxx" #include "dpitemdata.hxx" +#include "dputil.hxx" #include <rtl/math.hxx> #include <unotools/textsearch.hxx> @@ -1010,6 +1011,13 @@ SCROW ScDPCache::GetIdByItemData(long nDim, const ScDPItemData& rItem) const rtl::OUString ScDPCache::GetFormattedString(long nDim, const ScDPItemData& rItem) const { + if (rItem.GetType() == ScDPItemData::GroupValue) + { + ScDPItemData::GroupValueAttr aAttr = rItem.GetGroupValue(); + return ScDPUtil::getDateGroupName( + aAttr.mnGroupType, aAttr.mnValue, mpDoc->GetFormatTable()); + } + if (!rItem.IsValue()) return rItem.GetString(); diff --git a/sc/source/core/data/dptabres.cxx b/sc/source/core/data/dptabres.cxx index 9749bd55b768..38cc7e958599 100644 --- a/sc/source/core/data/dptabres.cxx +++ b/sc/source/core/data/dptabres.cxx @@ -1441,7 +1441,8 @@ void ScDPResultMember::FillMemberResults( uno::Sequence<sheet::MemberResult>* pS else aName = aItemData.GetString(); - bIsNumeric = aItemData.IsValue(); + ScDPItemData::Type eType = aItemData.GetType(); + bIsNumeric = eType == ScDPItemData::Value || ScDPItemData::GroupValue; } fprintf(stdout, "ScDPResultMember::FillMemberResults: name = '%s' numeric = %d\n", |