diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2012-03-07 15:27:17 -0500 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2012-03-09 11:13:33 -0500 |
commit | 7d53e6da1f9f36d8fc1040c823ba16723930012d (patch) | |
tree | 3b0cdc6e09eda10efb4aaab759404ee5aa74b2e3 | |
parent | f96c760bef74a2aa46d9b57b50356b8d28d72c7e (diff) |
Get number-grouping to work again.
Though I stil need to fix the sorting issue, which occurs because I
use string items to represent the range items.
-rw-r--r-- | sc/inc/dpgroup.hxx | 7 | ||||
-rw-r--r-- | sc/source/core/data/dpgroup.cxx | 121 | ||||
-rw-r--r-- | sc/source/filter/excel/xepivot.cxx | 3 |
3 files changed, 68 insertions, 63 deletions
diff --git a/sc/inc/dpgroup.hxx b/sc/inc/dpgroup.hxx index 6d66136a93eb..cff5c4bed390 100644 --- a/sc/inc/dpgroup.hxx +++ b/sc/inc/dpgroup.hxx @@ -127,9 +127,9 @@ typedef ::std::vector<ScDPGroupDimension> ScDPGroupDimensionVec; class SC_DLLPUBLIC ScDPNumGroupDimension { - ScDPNumGroupInfo aGroupInfo; // settings + mutable ScDPNumGroupInfo aGroupInfo; // settings ScDPDateGroupHelper* pDateHelper; - mutable ::std::vector< SCROW > maMemberEntries; + mutable std::vector<SCROW> maMemberEntries; mutable bool bHasNonInteger; // initialized in GetNumEntries mutable sal_Unicode cDecSeparator; // initialized in GetNumEntries @@ -148,8 +148,7 @@ public: const ScDPDateGroupHelper* GetDateHelper() const { return pDateHelper; } const std::vector<SCROW>& GetNumEntries( - SCCOL nSourceDim, const ScDPCache* pCache, - const std::vector< SCROW >& rOriginal) const; + SCCOL nSourceDim, ScDPCache* pCache, const std::vector<SCROW>& rOriginal) const; void MakeDateHelper( const ScDPNumGroupInfo& rInfo, long nDim, sal_Int32 nPart ); diff --git a/sc/source/core/data/dpgroup.cxx b/sc/source/core/data/dpgroup.cxx index 4fc5b6dae0b2..31db8c7bef44 100644 --- a/sc/source/core/data/dpgroup.cxx +++ b/sc/source/core/data/dpgroup.cxx @@ -865,11 +865,11 @@ void ScDPNumGroupDimension::MakeDateHelper( const ScDPNumGroupInfo& rInfo, long delete pDateHelper; pDateHelper = new ScDPDateGroupHelper(rInfo, nDim, nPart); - aGroupInfo.mbEnable = sal_True; //! or query both? + aGroupInfo.mbEnable = true; //! or query both? } const std::vector<SCROW>& ScDPNumGroupDimension::GetNumEntries( - SCCOL nSourceDim, const ScDPCache* pCache, const std::vector<SCROW>& rOriginal) const + SCCOL nSourceDim, ScDPCache* pCache, const std::vector<SCROW>& rOriginal) const { if (!maMemberEntries.empty()) return maMemberEntries; @@ -898,40 +898,34 @@ const std::vector<SCROW>& ScDPNumGroupDimension::GetNumEntries( double fSourceMax = 0.0; bool bFirst = true; - size_t nOriginalCount = rOriginal.size(); - for (size_t nOriginalPos=0; nOriginalPos<nOriginalCount; nOriginalPos++) + for (size_t i = 0, n = rOriginal.size(); i < n; ++i) { - const ScDPItemData* pItemData = pCache->GetItemDataById( nSourceDim , rOriginal[nOriginalPos] ); + const ScDPItemData* pItemData = pCache->GetItemDataById(nSourceDim, rOriginal[i]); + if (pItemData->GetType() != ScDPItemData::Value) + continue; - if ( pItemData && pItemData ->HasStringData() ) + double fSourceValue = pItemData->GetValue(); + if (bFirst) { - lcl_Insert( nSourceDim, pCache, maMemberEntries, rOriginal[nOriginalPos] ); + fSourceMin = fSourceMax = fSourceValue; + bFirst = false; + continue; } - else + + if (fSourceValue < fSourceMin) + fSourceMin = fSourceValue; + if (fSourceValue > fSourceMax) + fSourceMax = fSourceValue; + + if (!bHasNonInteger && !IsInteger(fSourceValue)) { - double fSourceValue = pItemData->GetValue(); - if ( bFirst ) - { - fSourceMin = fSourceMax = fSourceValue; - bFirst = false; - } - else - { - if ( fSourceValue < fSourceMin ) - fSourceMin = fSourceValue; - if ( fSourceValue > fSourceMax ) - fSourceMax = fSourceValue; - } - if ( !bHasNonInteger && !IsInteger( fSourceValue ) ) - { - // if any non-integer numbers are involved, the group labels are - // shown including their upper limit - bHasNonInteger = true; - } + // if any non-integer numbers are involved, the group labels are + // shown including their upper limit + bHasNonInteger = true; } } - if ( aGroupInfo.mbDateValues ) + if (aGroupInfo.mbDateValues) { // special handling for dates: always integer, round down limits bHasNonInteger = false; @@ -939,16 +933,19 @@ const std::vector<SCROW>& ScDPNumGroupDimension::GetNumEntries( fSourceMax = rtl::math::approxFloor( fSourceMax ) + 1; } - if ( aGroupInfo.mbAutoStart ) - const_cast<ScDPNumGroupDimension*>(this)->aGroupInfo.mfStart = fSourceMin; - if ( aGroupInfo.mbAutoEnd ) - const_cast<ScDPNumGroupDimension*>(this)->aGroupInfo.mfEnd = fSourceMax; + if (aGroupInfo.mbAutoStart) + aGroupInfo.mfStart = fSourceMin; + if (aGroupInfo.mbAutoEnd) + aGroupInfo.mfEnd = fSourceMax; //! limit number of entries? long nLoopCount = 0; double fLoop = aGroupInfo.mfStart; + // Num group always share the same dimension ID as the source dimension. + pCache->ResetGroupItems(nSourceDim, aGroupInfo); + // Use "less than" instead of "less or equal" for the loop - don't create a group // that consists only of the end value. Instead, the end value is then included // in the last group (last group is bigger than the others). @@ -956,12 +953,13 @@ const std::vector<SCROW>& ScDPNumGroupDimension::GetNumEntries( bool bFirstGroup = true; SvNumberFormatter* pFormatter = pCache->GetDoc()->GetFormatTable(); - while ( bFirstGroup || ( fLoop < aGroupInfo.mfEnd && !rtl::math::approxEqual( fLoop, aGroupInfo.mfEnd ) ) ) + while (bFirstGroup || (fLoop < aGroupInfo.mfEnd && !rtl::math::approxEqual(fLoop, aGroupInfo.mfEnd))) { - String aName = lcl_GetNumGroupName( fLoop, aGroupInfo, bHasNonInteger, cDecSeparator, pFormatter ); - // create a numerical entry to ensure proper sorting - // (in FillMemberResults this needs special handling) - lcl_InsertValue<true>( nSourceDim, pCache, maMemberEntries, aName, fLoop ); + rtl::OUString aName = lcl_GetNumGroupName( + fLoop, aGroupInfo, bHasNonInteger, cDecSeparator, pFormatter); + // TODO: create a numerical entry to ensure proper sorting + SCROW nId = pCache->SetGroupItem(nSourceDim, ScDPItemData(aName)); + maMemberEntries.push_back(nId); ++nLoopCount; fLoop = aGroupInfo.mfStart + nLoopCount * aGroupInfo.mfStep; bFirstGroup = false; @@ -969,13 +967,16 @@ const std::vector<SCROW>& ScDPNumGroupDimension::GetNumEntries( // ScDPItemData values are compared with approxEqual } - String aFirstName = lcl_GetSpecialNumGroupName( aGroupInfo.mfStart, true, cDecSeparator, aGroupInfo.mbDateValues, pFormatter ); - lcl_InsertValue<true>( nSourceDim, pCache, maMemberEntries, aFirstName, aGroupInfo.mfStart - aGroupInfo.mfStep ); + rtl::OUString aFirstName = lcl_GetSpecialNumGroupName( + aGroupInfo.mfStart, true, cDecSeparator, aGroupInfo.mbDateValues, pFormatter); + SCROW nId = pCache->SetGroupItem(nSourceDim, ScDPItemData(aFirstName)); + maMemberEntries.push_back(nId); - String aLastName = lcl_GetSpecialNumGroupName( aGroupInfo.mfEnd, false, cDecSeparator, aGroupInfo.mbDateValues, pFormatter ); - lcl_InsertValue<true>( nSourceDim, pCache, maMemberEntries, aLastName, aGroupInfo.mfEnd + aGroupInfo.mfStep ); + rtl::OUString aLastName = lcl_GetSpecialNumGroupName( + aGroupInfo.mfEnd, false, cDecSeparator, aGroupInfo.mbDateValues, pFormatter); + nId = pCache->SetGroupItem(nSourceDim, ScDPItemData(aLastName)); + maMemberEntries.push_back(nId); - fprintf(stdout, "ScDPNumGroupDimension::GetNumEntries: FIXME\n"); return maMemberEntries; } @@ -1069,7 +1070,9 @@ const std::vector< SCROW >& ScDPGroupTableData::GetColumnEntries( long nColumn { // dimension number is unchanged for numerical groups const std::vector< SCROW >& rOriginal = pSourceData->GetColumnEntries( nColumn ); - return pNumGroups[nColumn].GetNumEntries( (SCCOL)nColumn, GetCacheTable().getCache(), rOriginal ); + return pNumGroups[nColumn].GetNumEntries( + static_cast<SCCOL>(nColumn), + const_cast<ScDPCache*>(GetCacheTable().getCache()), rOriginal); } return pSourceData->GetColumnEntries( nColumn ); @@ -1303,11 +1306,10 @@ const ScDPCacheTable& ScDPGroupTableData::GetCacheTable() const void ScDPGroupTableData::FillGroupValues(SCROW* pItemDataIndex, long nCount, const long* pDims) { - stack_printer __stack_printer__("ScDPGroupTableData::FillGroupValues"); long nGroupedColumns = aGroups.size(); const ScDPCache* pCache = GetCacheTable().getCache(); - for (long nDim=0; nDim<nCount; nDim++) + for (long nDim = 0; nDim < nCount; ++nDim) { const ScDPDateGroupHelper* pDateHelper = NULL; @@ -1318,31 +1320,33 @@ void ScDPGroupTableData::FillGroupValues(SCROW* pItemDataIndex, long nCount, con const ScDPGroupDimension& rGroupDim = aGroups[nColumn - nSourceCount]; nSourceDim= rGroupDim.GetSourceDim(); pDateHelper = rGroupDim.GetDateHelper(); - if ( !pDateHelper ) // date is handled below + if (!pDateHelper) // date is handled below { - const ScDPGroupItem* pGroupItem = rGroupDim.GetGroupForData( *GetMemberById( nSourceDim, pItemDataIndex[nDim] )); - if ( pGroupItem ) - pItemDataIndex[nDim] = pCache->GetAdditionalItemID( pGroupItem->GetName() ); + const ScDPGroupItem* pGroupItem = + rGroupDim.GetGroupForData(*GetMemberById(nSourceDim, pItemDataIndex[nDim])); + + if (pGroupItem) + pItemDataIndex[nDim] = + pCache->GetIdByItemData(nColumn, ScDPItemData(pGroupItem->GetName())); } } else if ( IsNumGroupDimension( nColumn ) ) { pDateHelper = pNumGroups[nColumn].GetDateHelper(); - if ( !pDateHelper ) // date is handled below + if (!pDateHelper) // date is handled below { - const ScDPItemData* pData = pCache->GetItemDataById( (SCCOL)nSourceDim, pItemDataIndex[nDim]); - if ( pData ->IsValue() ) + const ScDPItemData* pData = pCache->GetItemDataById(nSourceDim, pItemDataIndex[nDim]); + if (pData->GetType() == ScDPItemData::Value) { - // TODO: This needs fixing. ScDPNumGroupInfo aNumInfo; bool bHasNonInteger = false; sal_Unicode cDecSeparator = 0; GetNumGroupInfo( nColumn, aNumInfo, bHasNonInteger, cDecSeparator ); double fGroupValue; - String aGroupName = lcl_GetNumGroupForValue( pData->GetValue(), - aNumInfo, bHasNonInteger, cDecSeparator, fGroupValue, pDoc ); + rtl::OUString aGroupName = lcl_GetNumGroupForValue( + pData->GetValue(), aNumInfo, bHasNonInteger, cDecSeparator, fGroupValue, pDoc); ScDPItemData aItemData(aGroupName); - pItemDataIndex[nDim] = pCache->GetAdditionalItemID(aItemData); + pItemDataIndex[nDim] = pCache->GetIdByItemData(nSourceDim, aItemData); } // else (textual) keep original value } @@ -1350,8 +1354,9 @@ void ScDPGroupTableData::FillGroupValues(SCROW* pItemDataIndex, long nCount, con if ( pDateHelper ) { - const ScDPItemData* pData = GetCacheTable().getCache()->GetItemDataById( (SCCOL)nSourceDim, pItemDataIndex[nDim]); - if ( pData ->IsValue() ) + const ScDPItemData* pData = + GetCacheTable().getCache()->GetItemDataById(nSourceDim, pItemDataIndex[nDim]); + if (pData->GetType() == ScDPItemData::Value) { SvNumberFormatter* pFormatter = pDoc->GetFormatTable(); const ScDPNumGroupInfo& rNumInfo = pDateHelper->GetNumInfo(); diff --git a/sc/source/filter/excel/xepivot.cxx b/sc/source/filter/excel/xepivot.cxx index 3a07b0e2d1a3..9ec7f5aac493 100644 --- a/sc/source/filter/excel/xepivot.cxx +++ b/sc/source/filter/excel/xepivot.cxx @@ -549,7 +549,8 @@ void XclExpPCField::InsertNumDateGroupItems( const ScDPObject& rDPObj, const ScD if( nDatePart != 0 ) aTmpDim.MakeDateHelper( rNumInfo, mnFieldIdx, nDatePart ); const std::vector<SCROW>& aMemberIds = aTmpDim.GetNumEntries( - static_cast<SCCOL>( GetBaseFieldIndex() ), aDPData.GetCacheTable().getCache(), aOrignial); + static_cast<SCCOL>(GetBaseFieldIndex()), + const_cast<ScDPCache*>(aDPData.GetCacheTable().getCache()), aOrignial); for ( size_t nIdx = 0 ; nIdx < aMemberIds.size(); nIdx++ ) { const ScDPItemData* pData = aDPData.GetMemberById( static_cast< long >( GetBaseFieldIndex() ) , aMemberIds[ nIdx] ); |