diff options
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/dpcache.hxx | 12 | ||||
-rw-r--r-- | sc/inc/dpobject.hxx | 3 | ||||
-rw-r--r-- | sc/qa/unit/subsequent_filters-test.cxx | 43 | ||||
-rw-r--r-- | sc/source/core/data/dpcache.cxx | 10 |
4 files changed, 66 insertions, 2 deletions
diff --git a/sc/inc/dpcache.hxx b/sc/inc/dpcache.hxx index 707749cbb104..b35fa3b1d708 100644 --- a/sc/inc/dpcache.hxx +++ b/sc/inc/dpcache.hxx @@ -139,6 +139,15 @@ public: void GetGroupDimMemberIds(long nDim, std::vector<SCROW>& rIds) const; void ClearGroupFields(); const ScDPNumGroupInfo* GetNumGroupInfo(long nDim) const; + + /** + * Return a group type identifier. The values correspond with + * com::sun::star::sheet::DataPilotFieldGroupBy constant values. + * + * @param nDim 0-based dimension index. + * + * @return group type identifier, or 0 on failure. + */ sal_Int32 GetGroupType(long nDim) const; SCCOL GetDimensionIndex(const OUString& sName) const; @@ -163,6 +172,9 @@ public: const ScDPItemData* GetItemDataById( long nDim, SCROW nId ) const; + size_t GetFieldCount() const; + size_t GetGroupFieldCount() const; + ScDPCache(ScDocument* pDoc); ~ScDPCache(); diff --git a/sc/inc/dpobject.hxx b/sc/inc/dpobject.hxx index 6c0a64dd3b0e..05a063d375b5 100644 --- a/sc/inc/dpobject.hxx +++ b/sc/inc/dpobject.hxx @@ -287,8 +287,7 @@ public: void updateReference( UpdateRefMode eMode, const ScRange& r, SCsCOL nDx, SCsROW nDy, SCsTAB nDz); - private: - ScDPCache* getExistingCache(const ScRange& rRange); + SC_DLLPUBLIC ScDPCache* getExistingCache(const ScRange& rRange); void updateCache(const ScRange& rRange, std::set<ScDPObject*>& rRefs); bool remove(const ScDPCache* p); diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx index 2bb1dff9fac1..fd0ae767e238 100644 --- a/sc/qa/unit/subsequent_filters-test.cxx +++ b/sc/qa/unit/subsequent_filters-test.cxx @@ -46,11 +46,13 @@ #include "cellvalue.hxx" #include "attrib.hxx" #include "dpsave.hxx" +#include "dpshttab.hxx" #include <com/sun/star/drawing/XDrawPageSupplier.hpp> #include <com/sun/star/drawing/XControlShape.hpp> #include <com/sun/star/sheet/XSpreadsheetDocument.hpp> #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp> +#include <com/sun/star/sheet/DataPilotFieldGroupBy.hpp> #include <com/sun/star/sheet/GeneralFunction.hpp> #include <com/sun/star/container/XIndexAccess.hpp> #include <com/sun/star/frame/XModel.hpp> @@ -1718,6 +1720,47 @@ void ScFiltersTest::testPivotTableSharedCacheGroupODS() ScDPCollection::SheetCaches& rSheetCaches = pDPs->GetSheetCaches(); CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rSheetCaches.size()); + // Make sure that the cache contains all group field data upon load. + const ScSheetSourceDesc* pDesc = pDPObj->GetSheetDesc(); + CPPUNIT_ASSERT_MESSAGE("Failed to get the pivot source description instance.", pDesc); + const ScDPCache* pCache = rSheetCaches.getExistingCache(pDesc->GetSourceRange()); + CPPUNIT_ASSERT_MESSAGE("Pivot cache should exist for this range.", pCache); + + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(9), pCache->GetFieldCount()); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), pCache->GetGroupFieldCount()); + + SCCOL nDim = pCache->GetDimensionIndex("StartDate"); + CPPUNIT_ASSERT_MESSAGE("Dimension 'StartDate' doesn't exist in the cache.", nDim >= 0); + sal_Int32 nGrpType = pCache->GetGroupType(nDim); + CPPUNIT_ASSERT_EQUAL(sheet::DataPilotFieldGroupBy::DAYS, nGrpType); + const ScDPNumGroupInfo* pInfo = pCache->GetNumGroupInfo(nDim); + CPPUNIT_ASSERT_MESSAGE("Number group info doesn't exist in cache for 'StartDate'.", pInfo); + + // We should have two additional group fields and one should be years and + // the other should be month. The order is not guaranteed. + + bool bHasYears = false; + bool bHasMonths = false; + + for (long nGrpDim = 9; nGrpDim <= 10; ++nGrpDim) + { + nGrpType = pCache->GetGroupType(nGrpDim); + switch (nGrpType) + { + case sheet::DataPilotFieldGroupBy::MONTHS: + bHasMonths = true; + break; + case sheet::DataPilotFieldGroupBy::YEARS: + bHasYears = true; + break; + default: + ; + } + } + + CPPUNIT_ASSERT_MESSAGE("Pivot cache doesn't have an additional year group.", bHasYears); + CPPUNIT_ASSERT_MESSAGE("Pivot cache doesn't have an additional month group.", bHasMonths); + xDocSh->DoClose(); } diff --git a/sc/source/core/data/dpcache.cxx b/sc/source/core/data/dpcache.cxx index 49e5d8f164e0..1226878f4c73 100644 --- a/sc/source/core/data/dpcache.cxx +++ b/sc/source/core/data/dpcache.cxx @@ -821,6 +821,16 @@ const ScDPItemData* ScDPCache::GetItemDataById(long nDim, SCROW nId) const return &rGI[nItemId]; } +size_t ScDPCache::GetFieldCount() const +{ + return maFields.size(); +} + +size_t ScDPCache::GetGroupFieldCount() const +{ + return maGroupFields.size(); +} + SCROW ScDPCache::GetRowCount() const { return mnRowCount; |