diff options
author | Kohei Yoshida <kohei.yoshida@suse.com> | 2012-03-05 13:49:05 -0500 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2012-03-09 11:13:29 -0500 |
commit | db60d94fc2ec8624653dddace5a934778fc2c7b4 (patch) | |
tree | 92d853aa4ac3bb4ff856d8b99296aa1541415d0d /sc | |
parent | At least pass all unit tests. (diff) | |
download | core-db60d94fc2ec8624653dddace5a934778fc2c7b4.tar.gz core-db60d94fc2ec8624653dddace5a934778fc2c7b4.zip |
Fix the result hierarchy construction. Still lots of places remain broken.
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/dpitemdata.hxx | 7 | ||||
-rw-r--r-- | sc/inc/dptablecache.hxx | 2 | ||||
-rw-r--r-- | sc/source/core/data/dpgroup.cxx | 96 | ||||
-rw-r--r-- | sc/source/core/data/dpitemdata.cxx | 35 | ||||
-rw-r--r-- | sc/source/core/data/dptablecache.cxx | 40 | ||||
-rw-r--r-- | sc/source/core/data/dptabres.cxx | 3 | ||||
-rw-r--r-- | sc/source/core/data/dptabsrc.cxx | 2 |
7 files changed, 137 insertions, 48 deletions
diff --git a/sc/inc/dpitemdata.hxx b/sc/inc/dpitemdata.hxx index 01bb425f78b3..2fa8cba62ebf 100644 --- a/sc/inc/dpitemdata.hxx +++ b/sc/inc/dpitemdata.hxx @@ -40,6 +40,8 @@ #include <boost/unordered_map.hpp> +#define DEBUG_DP_ITEM_DATA 1 + class ScDocument; class SC_DLLPUBLIC ScDPItemData @@ -76,6 +78,7 @@ public: ScDPItemData(sal_Int32 nGroupType, sal_Int32 nValue); ~ScDPItemData(); + Type GetType() const; void SetString(const rtl::OUString& rS); void SetValue(double fVal); void SetGroupValue(sal_Int32 nGroupType, sal_Int32 nValue); @@ -97,6 +100,10 @@ public: bool HasStringData() const ; sal_uInt8 GetCellType() const; + +#if DEBUG_DP_ITEM_DATA + void Dump(const char* msg) const; +#endif }; #endif diff --git a/sc/inc/dptablecache.hxx b/sc/inc/dptablecache.hxx index c8f7816d661a..13efb3bfe4e9 100644 --- a/sc/inc/dptablecache.hxx +++ b/sc/inc/dptablecache.hxx @@ -129,7 +129,7 @@ public: const ObjectSetType& GetAllReferences() const; SCROW GetIdByItemData(long nDim, const rtl::OUString& sItemData) const; - SCROW GetIdByItemData(long nDim, const ScDPItemData& rData) const; + SCROW GetIdByItemData(long nDim, const ScDPItemData& rItem) const; rtl::OUString GetFormattedString(long nDim, const ScDPItemData& rItem) const; void AppendGroupField(); void ResetGroupItems(long nDim); diff --git a/sc/source/core/data/dpgroup.cxx b/sc/source/core/data/dpgroup.cxx index e3024b0229fb..fde7759d5149 100644 --- a/sc/source/core/data/dpgroup.cxx +++ b/sc/source/core/data/dpgroup.cxx @@ -448,6 +448,8 @@ ScDPDateGroupHelper::~ScDPDateGroupHelper() { } +namespace { + sal_Int32 lcl_GetDatePartValue( double fValue, sal_Int32 nDatePart, SvNumberFormatter* pFormatter, const ScDPNumGroupInfo* pNumInfo ) { @@ -586,6 +588,58 @@ String lcl_GetSpecialDateName( double fValue, bool bFirst, SvNumberFormatter* pF return aBuffer.makeStringAndClear(); } +bool isDateInGroup(const ScDPItemData& rGroupItem, const ScDPItemData& rChildItem) +{ + stack_printer __stack_printer__("::isDateInGroup"); + if (rGroupItem.GetType() != ScDPItemData::GroupValue || rChildItem.GetType() != ScDPItemData::GroupValue) + return false; + + sal_Int32 nGroupPart = rGroupItem.GetGroupValue().mnGroupType; + sal_Int32 nGroupValue = rGroupItem.GetGroupValue().mnValue; + sal_Int32 nChildPart = rChildItem.GetGroupValue().mnGroupType; + sal_Int32 nChildValue = rChildItem.GetGroupValue().mnValue; + + fprintf(stdout, "isDateInGroup: group part = %d group values = %d child part = %d child value = %d\n", + nGroupPart, nGroupValue, nChildPart, nChildValue); + + if (nGroupValue == SC_DP_DATE_FIRST || nGroupValue == SC_DP_DATE_LAST || + nChildValue == SC_DP_DATE_FIRST || nChildValue == SC_DP_DATE_LAST) + { + // first/last entry matches only itself + return nGroupValue == nChildValue; + } + + switch (nChildPart) // 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 + return (nGroupValue - 1 == (nChildValue - 1) / 3); + + 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 += (nChildValue - 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 + + return nGroupValue == nCompare; + } + break; + default: + ; + } + + return true; +} + +} + void ScDPDateGroupHelper::SetGroupDim(long nDim) { mnGroupDim = nDim; @@ -665,7 +719,7 @@ void ScDPDateGroupHelper::FillColumnEntries( rtl::OUString aName = ScDPUtil::getDateGroupName( nDatePart, nValue, pFormatter ); fprintf(stdout, "ScDPDateGroupHelper::FillColumnEntries: name = '%s'\n", rtl::OUStringToOString(aName, RTL_TEXTENCODING_UTF8).getStr()); - SCROW nId = pCache->SetGroupItem(mnGroupDim, ScDPItemData(aName)); + SCROW nId = pCache->SetGroupItem(mnGroupDim, ScDPItemData(nDatePart, nValue)); rEntries.push_back(nId); } @@ -673,13 +727,13 @@ void ScDPDateGroupHelper::FillColumnEntries( rtl::OUString aFirstName = lcl_GetSpecialDateName( aNumInfo.mfStart, true, pFormatter ); fprintf(stdout, "ScDPDateGroupHelper::FillColumnEntries: first = '%s'\n", rtl::OUStringToOString(aFirstName, RTL_TEXTENCODING_UTF8).getStr()); - SCROW nId = pCache->SetGroupItem(mnGroupDim, ScDPItemData(aFirstName)); + SCROW nId = pCache->SetGroupItem(mnGroupDim, ScDPItemData(nDatePart, SC_DP_DATE_LAST)); rEntries.push_back(nId); rtl::OUString aLastName = lcl_GetSpecialDateName( aNumInfo.mfEnd, false, pFormatter ); fprintf(stdout, "ScDPDateGroupHelper::FillColumnEntries: last = '%s'\n", rtl::OUStringToOString(aLastName, RTL_TEXTENCODING_UTF8).getStr()); - nId = pCache->SetGroupItem(mnGroupDim, ScDPItemData(aLastName)); + nId = pCache->SetGroupItem(mnGroupDim, ScDPItemData(nDatePart, SC_DP_DATE_LAST)); rEntries.push_back(nId); std::vector<SCROW>::const_iterator it = rEntries.begin(), itEnd = rEntries.end(); @@ -1123,18 +1177,6 @@ const std::vector< SCROW >& ScDPGroupTableData::GetColumnEntries( long nColumn const ScDPItemData* ScDPGroupTableData::GetMemberById( long nDim, long nId ) { -// stack_printer __stack_printer__("ScDPGroupTableData::GetMemberById"); -// fprintf(stdout, "ScDPGroupTableData::GetMemberById: dim = %d id = %d\n", nDim, nId); - if ( nDim >= nSourceCount ) - { - if ( getIsDataLayoutDimension( nDim) ) - nDim = nSourceCount; - else - { - const ScDPGroupDimension& rGroupDim = aGroups[nDim - nSourceCount]; - nDim = rGroupDim.GetSourceDim(); - } - } return pSourceData->GetMemberById( nDim, nId ); } @@ -1482,9 +1524,7 @@ sal_Bool ScDPGroupTableData::IsInGroup( const ScDPItemData& rGroupData, long nGr const ScDPItemData& rBaseData, long nBaseIndex ) const { stack_printer __stack_printer__("ScDPGroupTableData::IsInGroup"); - fprintf(stdout, "ScDPGroupTableData::IsInGroup: group = '%s' base = '%s' group id = %d base id = %d\n", - rtl::OUStringToOString(rGroupData.GetString(), RTL_TEXTENCODING_UTF8).getStr(), - rtl::OUStringToOString(rBaseData.GetString(), RTL_TEXTENCODING_UTF8).getStr(), nGroupIndex, nBaseIndex); + fprintf(stdout, "ScDPGroupTableData::IsInGroup: group dim = %d base dim = %d\n", nGroupIndex, nBaseIndex); for ( ScDPGroupDimensionVec::const_iterator aIter(aGroups.begin()); aIter != aGroups.end(); aIter++ ) { const ScDPGroupDimension& rDim = *aIter; @@ -1493,25 +1533,7 @@ sal_Bool ScDPGroupTableData::IsInGroup( const ScDPItemData& rGroupData, long nGr const ScDPDateGroupHelper* pGroupDateHelper = rDim.GetDateHelper(); if ( pGroupDateHelper ) { - //! transform rBaseData (innermost date part) - //! -> always do "HasCommonElement" style comparison - //! (only Quarter, Month, Day affected) - - const ScDPDateGroupHelper* pBaseDateHelper = NULL; - if ( nBaseIndex < nSourceCount ) - pBaseDateHelper = pNumGroups[nBaseIndex].GetDateHelper(); - - // If there's a date group dimension, the base dimension must have - // date group information, too. - if ( !pBaseDateHelper ) - { - OSL_FAIL( "mix of date and non-date groups" ); - return true; - } - - sal_Int32 nGroupPart = pGroupDateHelper->GetDatePart(); - sal_Int32 nBasePart = pBaseDateHelper->GetDatePart(); - return lcl_DateContained( nGroupPart, rGroupData, nBasePart, rBaseData ); + return isDateInGroup(rGroupData, rBaseData); } else { diff --git a/sc/source/core/data/dpitemdata.cxx b/sc/source/core/data/dpitemdata.cxx index b74eb85d9f1c..b710ed3b304c 100644 --- a/sc/source/core/data/dpitemdata.cxx +++ b/sc/source/core/data/dpitemdata.cxx @@ -93,6 +93,11 @@ ScDPItemData::~ScDPItemData() delete mpString; } +ScDPItemData::Type ScDPItemData::GetType() const +{ + return meType; +} + void ScDPItemData::SetString(const rtl::OUString& rS) { if (meType == String) @@ -201,6 +206,35 @@ sal_uInt8 ScDPItemData::GetCellType() const return SC_VALTYPE_STRING; } +#if DEBUG_DP_ITEM_DATA +void ScDPItemData::Dump(const char* msg) const +{ + printf("--- (%s)\n", msg); + switch (meType) + { + case Empty: + printf("empty\n"); + break; + case Error: + printf("error\n"); + break; + case GroupValue: + printf("group value: group type = %d value = %d\n", + maGroupValue.mnGroupType, maGroupValue.mnValue); + break; + case String: + printf("string\n"); + break; + case Value: + printf("value: %g\n", mfValue); + break; + default: + printf("unknown type\n"); + } + printf("---\n"); +} +#endif + bool ScDPItemData::IsEmpty() const { return meType == Empty; @@ -216,6 +250,7 @@ rtl::OUString ScDPItemData::GetString() const switch (meType) { case String: + case Error: return *mpString; case Value: return rtl::OUString::valueOf(mfValue); diff --git a/sc/source/core/data/dptablecache.cxx b/sc/source/core/data/dptablecache.cxx index 5cd984c654ee..9afaed8e3b77 100644 --- a/sc/source/core/data/dptablecache.cxx +++ b/sc/source/core/data/dptablecache.cxx @@ -770,9 +770,9 @@ const ScDPItemData* ScDPCache::GetItemDataById(long nDim, SCROW nId) const { // stack_printer __stack_printer__("ScDPCache::GetItemDataById"); // fprintf(stdout, "ScDPCache::GetItemDataById: dim = %d id = %d\n", nDim, nId); - if (nDim < 0) + if (nDim < 0 || nId < 0) { - fprintf(stdout, "ScDPCache::GetItemDataById: fail (%d)\n", __LINE__); + fprintf(stdout, "ScDPCache::GetItemDataById: negative ID\n"); return NULL; } @@ -965,18 +965,46 @@ SCROW ScDPCache::GetIdByItemData(long nDim, const rtl::OUString& sItemData) cons return -1; } -SCROW ScDPCache::GetIdByItemData(long nDim, const ScDPItemData& rData) const +SCROW ScDPCache::GetIdByItemData(long nDim, const ScDPItemData& rItem) const { - fprintf(stdout, "ScDPCache::GetIdByItemData: FIXME\n"); - if ( nDim < mnColumnCount && nDim >=0 ) + if (nDim < 0) + return -1; + + if (nDim < mnColumnCount) { + // source field. const DataListType& rItems = maFields[nDim].maItems; for (size_t i = 0, n = rItems.size(); i < n; ++i) { - if (rItems[i] == rData) + if (rItems[i] == rItem) + return i; + } + + if (!maFields[nDim].mpGroup) + return -1; + + // grouped source field. + const DataListType& rGI = maFields[nDim].mpGroup->maItems; + for (size_t i = 0, n = rGI.size(); i < n; ++i) + { + if (rGI[i] == rItem) + return rItems.size() + i; + } + return -1; + } + + // group field. + nDim -= mnColumnCount; + if (nDim < maGroupFields.size()) + { + const DataListType& rGI = maGroupFields[nDim].maItems; + for (size_t i = 0, n = rGI.size(); i < n; ++i) + { + if (rGI[i] == rItem) return i; } } + return -1; } diff --git a/sc/source/core/data/dptabres.cxx b/sc/source/core/data/dptabres.cxx index a282f8fb7f52..9749bd55b768 100644 --- a/sc/source/core/data/dptabres.cxx +++ b/sc/source/core/data/dptabres.cxx @@ -974,7 +974,7 @@ bool ScDPResultData::IsInGroup( const ScDPItemData& rGroupData, long nGroupIndex bool ScDPResultData::IsInGroup( SCROW nGroupDataId, long nGroupIndex, const ScDPItemData& rBaseData, long nBaseIndex ) const { - fprintf(stdout, "ScDPResultData::IsInGroup: dim = %d id = %d\n", nGroupIndex, nGroupDataId); + fprintf(stdout, "ScDPResultData::IsInGroup: group dim = %d group item id = %d\n", nGroupIndex, nGroupDataId); const ScDPItemData* pGroupData = pSource->GetItemDataById( nGroupIndex , nGroupDataId); if ( pGroupData ) return pSource->GetData()->IsInGroup( *pGroupData, nGroupIndex, rBaseData , nBaseIndex ); @@ -2753,7 +2753,6 @@ sal_Bool ScDPGroupCompare::TestIncluded( const ScDPMember& rMember ) //! get array of groups (or indexes) before loop? ScDPItemData aMemberData; rMember.FillItemData( aMemberData ); - fprintf(stdout, "ScDPGroupCompare::TestIncluded: s = '%s'\n", rtl::OUStringToOString(aMemberData.GetString(), RTL_TEXTENCODING_UTF8).getStr()); long nInitCount = rInitState.GetCount(); const long* pInitSource = rInitState.GetSource(); const SCROW* pInitNames = rInitState.GetNameIds(); diff --git a/sc/source/core/data/dptabsrc.cxx b/sc/source/core/data/dptabsrc.cxx index e37654169919..4087c42af6ba 100644 --- a/sc/source/core/data/dptabsrc.cxx +++ b/sc/source/core/data/dptabsrc.cxx @@ -2572,7 +2572,6 @@ ScDPMember::~ScDPMember() bool ScDPMember::IsNamedItem(SCROW nIndex) const { long nSrcDim = pSource->GetSourceDim( nDim ); - fprintf(stdout, "ScDPMember::IsNamedItem: dim = %d src dim = %d\n", nDim, nSrcDim); if ( nHier != SC_DAPI_HIERARCHY_FLAT && pSource->IsDateDimension( nSrcDim ) ) { const ScDPItemData* pData = pSource->GetCache()->GetItemDataById(nDim, nIndex); @@ -2586,7 +2585,6 @@ bool ScDPMember::IsNamedItem(SCROW nIndex) const } } - fprintf(stdout, "ScDPMember::IsNamedItem: result = %d\n", nIndex == mnDataId); return nIndex == mnDataId; } |