diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2012-03-08 15:49:31 -0500 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2012-03-09 11:13:35 -0500 |
commit | 593f6ac1064184f1faee60155c412b964f6f86a1 (patch) | |
tree | 1398b81fd493356ad21ca744cd325f4778c66bfc | |
parent | 32b61ed8931acd97e488bc73486244c385a3a974 (diff) |
Added hook to create group field data at cache creation time.
This is to avoid group data to be added multiple times in case of
multiple pivot tables referencing the same pivot cache.
-rw-r--r-- | sc/inc/dpdimsave.hxx | 3 | ||||
-rw-r--r-- | sc/inc/dpobject.hxx | 18 | ||||
-rw-r--r-- | sc/inc/dpsdbtab.hxx | 3 | ||||
-rw-r--r-- | sc/inc/dpshttab.hxx | 3 | ||||
-rw-r--r-- | sc/source/core/data/dpdimsave.cxx | 4 | ||||
-rw-r--r-- | sc/source/core/data/dpobject.cxx | 61 | ||||
-rw-r--r-- | sc/source/core/data/dpsdbtab.cxx | 4 | ||||
-rw-r--r-- | sc/source/core/data/dpshttab.cxx | 6 | ||||
-rw-r--r-- | sc/source/core/data/dptablecache.cxx | 1 | ||||
-rw-r--r-- | sc/source/filter/excel/xepivot.cxx | 7 | ||||
-rw-r--r-- | sc/source/ui/view/cellsh1.cxx | 7 |
11 files changed, 89 insertions, 28 deletions
diff --git a/sc/inc/dpdimsave.hxx b/sc/inc/dpdimsave.hxx index ea280a1b50fd..6858e8bf0f78 100644 --- a/sc/inc/dpdimsave.hxx +++ b/sc/inc/dpdimsave.hxx @@ -39,6 +39,7 @@ class ScDPGroupTableData; class ScDPGroupDimension; class ScDPObject; +class ScDPCache; class SvNumberFormatter; class ScDPSaveGroupDimension; @@ -163,6 +164,8 @@ public: void WriteToData( ScDPGroupTableData& rData ) const; + void WriteToCache(ScDPCache& rCache) const; + rtl::OUString CreateGroupDimName( const rtl::OUString& rSourceName, const ScDPObject& rObject, bool bAllowSource, const ::std::vector<rtl::OUString>* pDeletedNames ); diff --git a/sc/inc/dpobject.hxx b/sc/inc/dpobject.hxx index d77fbc13caa0..5f3963d95bd6 100644 --- a/sc/inc/dpobject.hxx +++ b/sc/inc/dpobject.hxx @@ -70,6 +70,7 @@ class ScSheetSourceDesc; struct PivotField; class ScDPCacheTable; class ScDPTableData; +class ScDPDimensionSaveData; struct ScDPServiceDesc { @@ -276,14 +277,14 @@ public: public: SheetCaches(ScDocument* pDoc); bool hasCache(const ScRange& rRange) const; - const ScDPCache* getCache(const ScRange& rRange); + const ScDPCache* getCache(const ScRange& rRange, const ScDPDimensionSaveData* pDimData); size_t size() const; void updateReference( UpdateRefMode eMode, const ScRange& r, SCsCOL nDx, SCsROW nDy, SCsTAB nDz); private: - void updateCache(const ScRange& rRange, std::set<ScDPObject*>& rRefs); + void updateCache(const ScRange& rRange, const ScDPDimensionSaveData* pDimData, std::set<ScDPObject*>& rRefs); bool remove(const ScDPCache* p); }; @@ -299,10 +300,13 @@ public: public: NameCaches(ScDocument* pDoc); bool hasCache(const rtl::OUString& rName) const; - const ScDPCache* getCache(const ::rtl::OUString& rName, const ScRange& rRange); + const ScDPCache* getCache( + const ::rtl::OUString& rName, const ScRange& rRange, const ScDPDimensionSaveData* pDimData); size_t size() const; private: - void updateCache(const rtl::OUString& rName, const ScRange& rRange, std::set<ScDPObject*>& rRefs); + void updateCache( + const rtl::OUString& rName, const ScRange& rRange, + const ScDPDimensionSaveData* pDimData, std::set<ScDPObject*>& rRefs); bool remove(const ScDPCache* p); }; @@ -335,14 +339,16 @@ public: public: DBCaches(ScDocument* pDoc); bool hasCache(sal_Int32 nSdbType, const rtl::OUString& rDBName, const rtl::OUString& rCommand) const; - const ScDPCache* getCache(sal_Int32 nSdbType, const ::rtl::OUString& rDBName, const ::rtl::OUString& rCommand); + const ScDPCache* getCache( + sal_Int32 nSdbType, const ::rtl::OUString& rDBName, const ::rtl::OUString& rCommand, + const ScDPDimensionSaveData* pDimData); private: com::sun::star::uno::Reference<com::sun::star::sdbc::XRowSet> createRowSet( sal_Int32 nSdbType, const ::rtl::OUString& rDBName, const ::rtl::OUString& rCommand); void updateCache(sal_Int32 nSdbType, const ::rtl::OUString& rDBName, const ::rtl::OUString& rCommand, - std::set<ScDPObject*>& rRefs); + const ScDPDimensionSaveData* pDimData, std::set<ScDPObject*>& rRefs); bool remove(const ScDPCache* p); }; diff --git a/sc/inc/dpsdbtab.hxx b/sc/inc/dpsdbtab.hxx index 81d198ce345a..eba6da20d52d 100644 --- a/sc/inc/dpsdbtab.hxx +++ b/sc/inc/dpsdbtab.hxx @@ -39,6 +39,7 @@ class ScDPCacheTable; class ScDocument; class ScDPCache; +class ScDPDimensionSaveData; struct ScImportSourceDesc { @@ -58,7 +59,7 @@ struct ScImportSourceDesc mpDoc == rOther.mpDoc; } sal_Int32 GetCommandType() const; - const ScDPCache* CreateCache() const; + const ScDPCache* CreateCache(const ScDPDimensionSaveData* pDimData) const; }; /** diff --git a/sc/inc/dpshttab.hxx b/sc/inc/dpshttab.hxx index 9df0d72e8f09..38a0d589e235 100644 --- a/sc/inc/dpshttab.hxx +++ b/sc/inc/dpshttab.hxx @@ -44,6 +44,7 @@ namespace com { namespace sun { namespace star { namespace sheet { class ScDPDimension; class ScDPItemData; +class ScDPDimensionSaveData; /** * This class contains authoritative information on the internal reference @@ -78,7 +79,7 @@ public: const ScQueryParam& GetQueryParam() const; bool operator== ( const ScSheetSourceDesc& rOther ) const; - SC_DLLPUBLIC const ScDPCache* CreateCache() const; + SC_DLLPUBLIC const ScDPCache* CreateCache(const ScDPDimensionSaveData* pDimData) const; /** * Check the sanity of the data source range. diff --git a/sc/source/core/data/dpdimsave.cxx b/sc/source/core/data/dpdimsave.cxx index c8ddaff2e624..34e87d5ee9c9 100644 --- a/sc/source/core/data/dpdimsave.cxx +++ b/sc/source/core/data/dpdimsave.cxx @@ -468,6 +468,10 @@ void ScDPDimensionSaveData::WriteToData( ScDPGroupTableData& rData ) const aIt->second.AddToData( rData ); } +void ScDPDimensionSaveData::WriteToCache(ScDPCache& rCache) const +{ +} + const ScDPSaveGroupDimension* ScDPDimensionSaveData::GetGroupDimForBase( const rtl::OUString& rBaseDimName ) const { return const_cast< ScDPDimensionSaveData* >( this )->GetGroupDimAccForBase( rBaseDimName ); diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx index 774a23b3eb1b..8e1eff832cea 100644 --- a/sc/source/core/data/dpobject.cxx +++ b/sc/source/core/data/dpobject.cxx @@ -429,10 +429,14 @@ ScDPTableData* ScDPObject::GetTableData() if (!mpTableData) { shared_ptr<ScDPTableData> pData; + const ScDPDimensionSaveData* pDimData = NULL; + if (pSaveData) + pDimData = pSaveData->GetExistingDimensionData(); + if ( pImpDesc ) { // database data - const ScDPCache* pCache = pImpDesc->CreateCache(); + const ScDPCache* pCache = pImpDesc->CreateCache(pDimData); if (pCache) { pCache->AddReference(this); @@ -453,7 +457,7 @@ ScDPTableData* ScDPObject::GetTableData() // GETPIVOTDATA called onto itself from within the source // range. DisableGetPivotData aSwitch(*this, mbEnableGetPivotData); - const ScDPCache* pCache = pSheetDesc->CreateCache(); + const ScDPCache* pCache = pSheetDesc->CreateCache(pDimData); if (pCache) { pCache->AddReference(this); @@ -463,10 +467,10 @@ ScDPTableData* ScDPObject::GetTableData() } // grouping (for cell or database data) - if (pData && pSaveData && pSaveData->GetExistingDimensionData()) + if (pData && pDimData) { shared_ptr<ScDPGroupTableData> pGroupData(new ScDPGroupTableData(pData, pDoc)); - pSaveData->GetExistingDimensionData()->WriteToData(*pGroupData); + pDimData->WriteToData(*pGroupData); pData = pGroupData; } @@ -2491,7 +2495,7 @@ bool ScDPCollection::SheetCaches::hasCache(const ScRange& rRange) const return itCache != maCaches.end(); } -const ScDPCache* ScDPCollection::SheetCaches::getCache(const ScRange& rRange) +const ScDPCache* ScDPCollection::SheetCaches::getCache(const ScRange& rRange, const ScDPDimensionSaveData* pDimData) { RangeIndexType::iterator it = std::find(maRanges.begin(), maRanges.end(), rRange); if (it != maRanges.end()) @@ -2513,6 +2517,8 @@ const ScDPCache* ScDPCollection::SheetCaches::getCache(const ScRange& rRange) ::std::auto_ptr<ScDPCache> pCache(new ScDPCache(mpDoc)); SAL_WNODEPRECATED_DECLARATIONS_POP pCache->InitFromDoc(mpDoc, rRange); + if (pDimData) + pDimData->WriteToCache(*pCache); // Get the smallest available range index. it = std::find_if(maRanges.begin(), maRanges.end(), FindInvalidRange()); @@ -2573,7 +2579,8 @@ void ScDPCollection::SheetCaches::updateReference( } } -void ScDPCollection::SheetCaches::updateCache(const ScRange& rRange, std::set<ScDPObject*>& rRefs) +void ScDPCollection::SheetCaches::updateCache( + const ScRange& rRange, const ScDPDimensionSaveData* pDimData, std::set<ScDPObject*>& rRefs) { RangeIndexType::iterator it = std::find(maRanges.begin(), maRanges.end(), rRange); if (it == maRanges.end()) @@ -2594,6 +2601,9 @@ void ScDPCollection::SheetCaches::updateCache(const ScRange& rRange, std::set<Sc ScDPCache& rCache = *itCache->second; rCache.InitFromDoc(mpDoc, rRange); + if (pDimData) + pDimData->WriteToCache(rCache); + std::set<ScDPObject*> aRefs(rCache.GetAllReferences()); rRefs.swap(aRefs); } @@ -2621,7 +2631,8 @@ bool ScDPCollection::NameCaches::hasCache(const OUString& rName) const return maCaches.count(rName) != 0; } -const ScDPCache* ScDPCollection::NameCaches::getCache(const OUString& rName, const ScRange& rRange) +const ScDPCache* ScDPCollection::NameCaches::getCache( + const OUString& rName, const ScRange& rRange, const ScDPDimensionSaveData* pDimData) { CachesType::const_iterator itr = maCaches.find(rName); if (itr != maCaches.end()) @@ -2632,6 +2643,9 @@ const ScDPCache* ScDPCollection::NameCaches::getCache(const OUString& rName, con ::std::auto_ptr<ScDPCache> pCache(new ScDPCache(mpDoc)); SAL_WNODEPRECATED_DECLARATIONS_POP pCache->InitFromDoc(mpDoc, rRange); + if (pDimData) + pDimData->WriteToCache(*pCache); + const ScDPCache* p = pCache.get(); maCaches.insert(rName, pCache); return p; @@ -2642,7 +2656,9 @@ size_t ScDPCollection::NameCaches::size() const return maCaches.size(); } -void ScDPCollection::NameCaches::updateCache(const OUString& rName, const ScRange& rRange, std::set<ScDPObject*>& rRefs) +void ScDPCollection::NameCaches::updateCache( + const OUString& rName, const ScRange& rRange, const ScDPDimensionSaveData* pDimData, + std::set<ScDPObject*>& rRefs) { CachesType::iterator itr = maCaches.find(rName); if (itr == maCaches.end()) @@ -2653,6 +2669,9 @@ void ScDPCollection::NameCaches::updateCache(const OUString& rName, const ScRang ScDPCache& rCache = *itr->second; rCache.InitFromDoc(mpDoc, rRange); + if (pDimData) + pDimData->WriteToCache(rCache); + std::set<ScDPObject*> aRefs(rCache.GetAllReferences()); rRefs.swap(aRefs); } @@ -2688,7 +2707,9 @@ bool ScDPCollection::DBCaches::hasCache(sal_Int32 nSdbType, const OUString& rDBN return itr != maCaches.end(); } -const ScDPCache* ScDPCollection::DBCaches::getCache(sal_Int32 nSdbType, const OUString& rDBName, const OUString& rCommand) +const ScDPCache* ScDPCollection::DBCaches::getCache( + sal_Int32 nSdbType, const OUString& rDBName, const OUString& rCommand, + const ScDPDimensionSaveData* pDimData) { DBType aType(nSdbType, rDBName, rCommand); CachesType::const_iterator itr = maCaches.find(aType); @@ -2705,6 +2726,9 @@ const ScDPCache* ScDPCollection::DBCaches::getCache(sal_Int32 nSdbType, const OU SAL_WNODEPRECATED_DECLARATIONS_POP SvNumberFormatter aFormat(mpDoc->GetServiceManager(), ScGlobal::eLnge); pCache->InitFromDataBase(xRowSet, *aFormat.GetNullDate()); + if (pDimData) + pDimData->WriteToCache(*pCache); + ::comphelper::disposeComponent(xRowSet); const ScDPCache* p = pCache.get(); maCaches.insert(aType, pCache); @@ -2776,7 +2800,8 @@ uno::Reference<sdbc::XRowSet> ScDPCollection::DBCaches::createRowSet( } void ScDPCollection::DBCaches::updateCache( - sal_Int32 nSdbType, const OUString& rDBName, const OUString& rCommand, std::set<ScDPObject*>& rRefs) + sal_Int32 nSdbType, const OUString& rDBName, const OUString& rCommand, + const ScDPDimensionSaveData* pDimData, std::set<ScDPObject*>& rRefs) { DBType aType(nSdbType, rDBName, rCommand); CachesType::iterator it = maCaches.find(aType); @@ -2803,6 +2828,8 @@ void ScDPCollection::DBCaches::updateCache( rRefs.clear(); return; } + if (pDimData) + pDimData->WriteToCache(rCache); comphelper::disposeComponent(xRowSet); std::set<ScDPObject*> aRefs(rCache.GetAllReferences()); @@ -2865,6 +2892,14 @@ public: sal_uLong ScDPCollection::ReloadCache(ScDPObject* pDPObj, std::set<ScDPObject*>& rRefs) { + if (!pDPObj) + return STR_ERR_DATAPILOTSOURCE; + + const ScDPSaveData* pSaveData = pDPObj->GetSaveData(); + const ScDPDimensionSaveData* pDimData = NULL; + if (pSaveData) + pDimData = pSaveData->GetExistingDimensionData(); + if (pDPObj->IsSheetData()) { // data source is internal sheet. @@ -2881,7 +2916,7 @@ sal_uLong ScDPCollection::ReloadCache(ScDPObject* pDPObj, std::set<ScDPObject*>& // cache by named range ScDPCollection::NameCaches& rCaches = GetNameCaches(); if (rCaches.hasCache(pDesc->GetRangeName())) - rCaches.updateCache(pDesc->GetRangeName(), pDesc->GetSourceRange(), rRefs); + rCaches.updateCache(pDesc->GetRangeName(), pDesc->GetSourceRange(), pDimData, rRefs); else { // Not cached yet. Collect all tables that use this named @@ -2894,7 +2929,7 @@ sal_uLong ScDPCollection::ReloadCache(ScDPObject* pDPObj, std::set<ScDPObject*>& // cache by cell range ScDPCollection::SheetCaches& rCaches = GetSheetCaches(); if (rCaches.hasCache(pDesc->GetSourceRange())) - rCaches.updateCache(pDesc->GetSourceRange(), rRefs); + rCaches.updateCache(pDesc->GetSourceRange(), pDimData, rRefs); else { // Not cached yet. Collect all tables that use this range as @@ -2913,7 +2948,7 @@ sal_uLong ScDPCollection::ReloadCache(ScDPObject* pDPObj, std::set<ScDPObject*>& ScDPCollection::DBCaches& rCaches = GetDBCaches(); if (rCaches.hasCache(pDesc->GetCommandType(), pDesc->aDBName, pDesc->aObject)) rCaches.updateCache( - pDesc->GetCommandType(), pDesc->aDBName, pDesc->aObject, rRefs); + pDesc->GetCommandType(), pDesc->aDBName, pDesc->aObject, pDimData, rRefs); else { // Not cached yet. Collect all tables that use this range as diff --git a/sc/source/core/data/dpsdbtab.cxx b/sc/source/core/data/dpsdbtab.cxx index a4e732bc9ea1..b085473b2408 100644 --- a/sc/source/core/data/dpsdbtab.cxx +++ b/sc/source/core/data/dpsdbtab.cxx @@ -63,7 +63,7 @@ sal_Int32 ScImportSourceDesc::GetCommandType() const return nSdbType; } -const ScDPCache* ScImportSourceDesc::CreateCache() const +const ScDPCache* ScImportSourceDesc::CreateCache(const ScDPDimensionSaveData* pDimData) const { if (!mpDoc) return NULL; @@ -73,7 +73,7 @@ const ScDPCache* ScImportSourceDesc::CreateCache() const return NULL; ScDPCollection::DBCaches& rCaches = mpDoc->GetDPCollection()->GetDBCaches(); - return rCaches.getCache(nSdbType, aDBName, aObject); + return rCaches.getCache(nSdbType, aDBName, aObject, pDimData); } ScDatabaseDPData::ScDatabaseDPData( diff --git a/sc/source/core/data/dpshttab.cxx b/sc/source/core/data/dpshttab.cxx index bde9ea0ca6f7..43911c8a5a9f 100644 --- a/sc/source/core/data/dpshttab.cxx +++ b/sc/source/core/data/dpshttab.cxx @@ -299,7 +299,7 @@ bool ScSheetSourceDesc::operator== (const ScSheetSourceDesc& rOther) const maQueryParam == rOther.maQueryParam; } -const ScDPCache* ScSheetSourceDesc::CreateCache() const +const ScDPCache* ScSheetSourceDesc::CreateCache(const ScDPDimensionSaveData* pDimData) const { if (!mpDoc) return NULL; @@ -317,11 +317,11 @@ const ScDPCache* ScSheetSourceDesc::CreateCache() const { // Name-based data source. ScDPCollection::NameCaches& rCaches = pDPs->GetNameCaches(); - return rCaches.getCache(GetRangeName(), GetSourceRange()); + return rCaches.getCache(GetRangeName(), GetSourceRange(), pDimData); } ScDPCollection::SheetCaches& rCaches = pDPs->GetSheetCaches(); - return rCaches.getCache(GetSourceRange()); + return rCaches.getCache(GetSourceRange(), pDimData); } sal_uLong ScSheetSourceDesc::CheckSourceRange() const diff --git a/sc/source/core/data/dptablecache.cxx b/sc/source/core/data/dptablecache.cxx index 730114672561..1c7f3a2a4db4 100644 --- a/sc/source/core/data/dptablecache.cxx +++ b/sc/source/core/data/dptablecache.cxx @@ -1058,6 +1058,7 @@ rtl::OUString ScDPCache::GetFormattedString(long nDim, const ScDPItemData& rItem void ScDPCache::AppendGroupField() { maGroupFields.push_back(new GroupItems); + fprintf(stdout, "ScDPCache::AppendGroupField: added; new count = %d\n", maGroupFields.size()); } void ScDPCache::ResetGroupItems(long nDim, const ScDPNumGroupInfo& rNumInfo) diff --git a/sc/source/filter/excel/xepivot.cxx b/sc/source/filter/excel/xepivot.cxx index 9ec7f5aac493..d1d5764744bf 100644 --- a/sc/source/filter/excel/xepivot.cxx +++ b/sc/source/filter/excel/xepivot.cxx @@ -538,7 +538,12 @@ void XclExpPCField::InsertNumDateGroupItems( const ScDPObject& rDPObj, const ScD if( const ScSheetSourceDesc* pSrcDesc = rDPObj.GetSheetDesc() ) { // get the string collection with original source elements - const ScDPCache* pCache = pSrcDesc->CreateCache(); + const ScDPSaveData* pSaveData = rDPObj.GetSaveData(); + const ScDPDimensionSaveData* pDimData = NULL; + if (pSaveData) + pDimData = pSaveData->GetExistingDimensionData(); + + const ScDPCache* pCache = pSrcDesc->CreateCache(pDimData); if (!pCache) return; diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx index 7fb77ed2f624..bdcf45678679 100644 --- a/sc/source/ui/view/cellsh1.cxx +++ b/sc/source/ui/view/cellsh1.cxx @@ -2156,7 +2156,12 @@ bool isDPSourceValid(const ScDPObject& rDPObj) if (!pDesc) return false; - const ScDPCache* pCache = pDesc->CreateCache(); + const ScDPSaveData* pSaveData = rDPObj.GetSaveData(); + const ScDPDimensionSaveData* pDimData = NULL; + if (pSaveData) + pDimData = pSaveData->GetExistingDimensionData(); + + const ScDPCache* pCache = pDesc->CreateCache(pDimData); if (!pCache) // cashe creation failed, probably due to invalid connection. return false; |