summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvo Hinkelmann <ihi@openoffice.org>2011-03-29 13:19:46 +0200
committerIvo Hinkelmann <ihi@openoffice.org>2011-03-29 13:19:46 +0200
commitaed5d1b0747fb20a84b7090aece52cc545a3f6bc (patch)
tree1841840dc7048a34e33ad1fba1755741dea7755a
parentfae7a5819bfdbec837b7eec7c0db2685bc1648e9 (diff)
parent65f59ac78860cc018a8b554e6a9d38a3d937fb1e (diff)
CWS-TOOLING: integrate CWS obo56ooo/DEV300_m105
-rw-r--r--sc/inc/dpsave.hxx2
-rw-r--r--sc/source/core/data/dpobject.cxx5
-rw-r--r--sc/source/core/data/dpsave.cxx63
3 files changed, 69 insertions, 1 deletions
diff --git a/sc/inc/dpsave.hxx b/sc/inc/dpsave.hxx
index a361d8f99..570cb3280 100644
--- a/sc/inc/dpsave.hxx
+++ b/sc/inc/dpsave.hxx
@@ -46,6 +46,7 @@ namespace com { namespace sun { namespace star { namespace sheet {
class ScDPDimensionSaveData;
class ScDPTableData;
+class ScDPObject;
// --------------------------------------------------------------------
//
@@ -272,6 +273,7 @@ public:
SC_DLLPUBLIC ScDPDimensionSaveData* GetDimensionData(); // create if not there
void SetDimensionData( const ScDPDimensionSaveData* pNew ); // copied
void BuildAllDimensionMembers(ScDPTableData* pData);
+ void BuildAllDimensionMembersFromSource(ScDPObject* pDPObj);
/**
* Check whether a dimension has one or more invisible members.
diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx
index f2598c9e7..5579056f1 100644
--- a/sc/source/core/data/dpobject.cxx
+++ b/sc/source/core/data/dpobject.cxx
@@ -644,9 +644,12 @@ void ScDPObject::BuildAllDimensionMembers()
return;
// #i111857# don't always create empty mpTableData for external service.
- // Ideally, xSource should be used instead of mpTableData.
+ // #163781# Initialize all members from xSource instead.
if (pServDesc)
+ {
+ pSaveData->BuildAllDimensionMembersFromSource( this );
return;
+ }
pSaveData->BuildAllDimensionMembers(GetTableData());
}
diff --git a/sc/source/core/data/dpsave.cxx b/sc/source/core/data/dpsave.cxx
index 85fed0e19..af6616f0b 100644
--- a/sc/source/core/data/dpsave.cxx
+++ b/sc/source/core/data/dpsave.cxx
@@ -34,6 +34,7 @@
#include "dpsave.hxx"
#include "dpdimsave.hxx"
+#include "dpobject.hxx" // GetMemberNames used in BuildAllDimensionMembersFromSource
#include "miscuno.hxx"
#include "scerrors.hxx"
#include "unonames.hxx"
@@ -874,6 +875,7 @@ ScDPSaveDimension* ScDPSaveData::GetDimensionByName(const String& rName)
}
ScDPSaveDimension* pNew = new ScDPSaveDimension( rName, sal_False );
aDimList.Insert( pNew, LIST_APPEND );
+ mbDimensionMembersBuilt = false; // BuildAllDimensionMembers only handles existing entries in aDimList
return pNew;
}
@@ -900,6 +902,7 @@ ScDPSaveDimension* ScDPSaveData::GetNewDimensionByName(const String& rName)
}
ScDPSaveDimension* pNew = new ScDPSaveDimension( rName, sal_False );
aDimList.Insert( pNew, LIST_APPEND );
+ mbDimensionMembersBuilt = false; // BuildAllDimensionMembers only handles existing entries in aDimList
return pNew;
}
@@ -911,6 +914,7 @@ ScDPSaveDimension* ScDPSaveData::GetDataLayoutDimension()
ScDPSaveDimension* pNew = new ScDPSaveDimension( String(), sal_True );
aDimList.Insert( pNew, LIST_APPEND );
+ mbDimensionMembersBuilt = false; // BuildAllDimensionMembers only handles existing entries in aDimList
return pNew;
}
@@ -935,6 +939,7 @@ ScDPSaveDimension* ScDPSaveData::DuplicateDimension(const String& rName)
ScDPSaveDimension* pNew = new ScDPSaveDimension( *pOld );
pNew->SetDupFlag( sal_True );
aDimList.Insert( pNew, LIST_APPEND );
+ mbDimensionMembersBuilt = false; // BuildAllDimensionMembers only handles existing entries in aDimList
return pNew;
}
@@ -958,6 +963,7 @@ ScDPSaveDimension& ScDPSaveData::DuplicateDimension( const ScDPSaveDimension& rD
ScDPSaveDimension* pNew = new ScDPSaveDimension( rDim );
pNew->SetDupFlag( sal_True );
aDimList.Insert( pNew, LIST_APPEND );
+ mbDimensionMembersBuilt = false; // BuildAllDimensionMembers only handles existing entries in aDimList
return *pNew;
}
@@ -1275,6 +1281,63 @@ void ScDPSaveData::BuildAllDimensionMembers(ScDPTableData* pData)
mbDimensionMembersBuilt = true;
}
+void ScDPSaveData::BuildAllDimensionMembersFromSource( ScDPObject* pDPObj )
+{
+ // Initialize all members like BuildAllDimensionMembers, but access only the DataPilotSource, not the table data.
+ // This could also replace BuildAllDimensionMembers, but the performance implications still have to be checked.
+ // ScDPObject is used for the helper method GetMemberNames.
+
+ if (mbDimensionMembersBuilt)
+ return;
+
+ uno::Reference<sheet::XDimensionsSupplier> xSource = pDPObj->GetSource();
+ uno::Reference<container::XNameAccess> xDimsName = xSource->getDimensions();
+ // GetMemberNames uses the dimension index from getElementNames
+ uno::Sequence<OUString> aDimNames = xDimsName->getElementNames();
+
+ // First, build a dimension name-to-index map.
+ typedef hash_map<OUString, long, ::rtl::OUStringHash> NameIndexMap;
+ NameIndexMap aMap;
+ long nColCount = aDimNames.getLength();
+ for (long i = 0; i < nColCount; ++i)
+ aMap.insert( NameIndexMap::value_type(aDimNames[i], i) );
+
+ NameIndexMap::const_iterator itrEnd = aMap.end();
+
+ sal_uInt32 n = aDimList.Count();
+ for (sal_uInt32 i = 0; i < n; ++i)
+ {
+ ScDPSaveDimension* pDim = static_cast<ScDPSaveDimension*>(aDimList.GetObject(i));
+ const String& rDimName = pDim->GetName();
+ if (!rDimName.Len())
+ // empty dimension name. It must be data layout.
+ continue;
+
+ NameIndexMap::const_iterator itr = aMap.find(rDimName);
+ if (itr == itrEnd)
+ // dimension name not in the data. This should never happen!
+ continue;
+
+ long nDimIndex = itr->second;
+ uno::Sequence<OUString> aMemberNames;
+ pDPObj->GetMemberNames( nDimIndex, aMemberNames );
+ sal_Int32 nMemberCount = aMemberNames.getLength();
+ for (sal_Int32 j = 0; j < nMemberCount; ++j)
+ {
+ String aMemName = aMemberNames[j];
+ if (pDim->GetExistingMemberByName(aMemName))
+ // this member instance already exists. nothing to do.
+ continue;
+
+ auto_ptr<ScDPSaveMember> pNewMember(new ScDPSaveMember(aMemName));
+ pNewMember->SetIsVisible(true);
+ pDim->AddMember(pNewMember.release());
+ }
+ }
+
+ mbDimensionMembersBuilt = true;
+}
+
bool ScDPSaveData::HasInvisibleMember(const OUString& rDimName) const
{
ScDPSaveDimension* pDim = GetExistingDimensionByName(rDimName);