1b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3b3f79822SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4b3f79822SAndrew Rist * or more contributor license agreements. See the NOTICE file
5b3f79822SAndrew Rist * distributed with this work for additional information
6b3f79822SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7b3f79822SAndrew Rist * to you under the Apache License, Version 2.0 (the
8b3f79822SAndrew Rist * "License"); you may not use this file except in compliance
9b3f79822SAndrew Rist * with the License. You may obtain a copy of the License at
10b3f79822SAndrew Rist *
11b3f79822SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12b3f79822SAndrew Rist *
13b3f79822SAndrew Rist * Unless required by applicable law or agreed to in writing,
14b3f79822SAndrew Rist * software distributed under the License is distributed on an
15b3f79822SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b3f79822SAndrew Rist * KIND, either express or implied. See the License for the
17b3f79822SAndrew Rist * specific language governing permissions and limitations
18b3f79822SAndrew Rist * under the License.
19b3f79822SAndrew Rist *
20b3f79822SAndrew Rist *************************************************************/
21b3f79822SAndrew Rist
22b3f79822SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir
28cdf0e10cSrcweir
29cdf0e10cSrcweir // INCLUDE ---------------------------------------------------------------
30cdf0e10cSrcweir
31cdf0e10cSrcweir #include "dpsave.hxx"
32cdf0e10cSrcweir #include "dpdimsave.hxx"
33cdf0e10cSrcweir #include "dpobject.hxx" // GetMemberNames used in BuildAllDimensionMembersFromSource
34cdf0e10cSrcweir #include "miscuno.hxx"
35cdf0e10cSrcweir #include "scerrors.hxx"
36cdf0e10cSrcweir #include "unonames.hxx"
37cdf0e10cSrcweir #include "global.hxx"
38cdf0e10cSrcweir
39cdf0e10cSrcweir #include <tools/debug.hxx>
40cdf0e10cSrcweir
41cdf0e10cSrcweir #include <com/sun/star/sheet/GeneralFunction.hpp>
42cdf0e10cSrcweir #include <com/sun/star/sheet/DataPilotFieldAutoShowInfo.hpp>
43cdf0e10cSrcweir #include <com/sun/star/sheet/DataPilotFieldLayoutInfo.hpp>
44cdf0e10cSrcweir #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
45cdf0e10cSrcweir #include <com/sun/star/sheet/DataPilotFieldReference.hpp>
46cdf0e10cSrcweir #include <com/sun/star/sheet/DataPilotFieldSortInfo.hpp>
47cdf0e10cSrcweir #include <com/sun/star/sheet/DataPilotFieldSortMode.hpp>
48cdf0e10cSrcweir #include <com/sun/star/sheet/TableFilterField.hpp>
49cdf0e10cSrcweir #include <com/sun/star/sheet/XHierarchiesSupplier.hpp>
50cdf0e10cSrcweir #include <com/sun/star/sheet/XLevelsSupplier.hpp>
51cdf0e10cSrcweir #include <com/sun/star/sheet/XMembersSupplier.hpp>
52cdf0e10cSrcweir #include <com/sun/star/container/XNamed.hpp>
53cdf0e10cSrcweir #include <com/sun/star/util/XCloneable.hpp>
54cdf0e10cSrcweir // Wang Xu Ming -- 2009-8-17
55cdf0e10cSrcweir // DataPilot Migration - Cache&&Performance
56cdf0e10cSrcweir #include "dptabsrc.hxx"
57cdf0e10cSrcweir #include "dpglobal.hxx"
58cdf0e10cSrcweir using namespace ScDPGlobal;
59cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SHEET_DATAPILOTFIELDREFERENCETYPE_HPP_
60cdf0e10cSrcweir #include <com/sun/star/sheet/DataPilotFieldReferenceType.hpp>
61cdf0e10cSrcweir #endif
62cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SHEET_DATAPILOTFIELDREFERENCEITEMTYPE_HPP_
63cdf0e10cSrcweir #include <com/sun/star/sheet/DataPilotFieldReferenceItemType.hpp>
64cdf0e10cSrcweir #endif
65cdf0e10cSrcweir using namespace com::sun::star::sheet;
66cdf0e10cSrcweir // End Comments
67cdf0e10cSrcweir
68cdf0e10cSrcweir #include <hash_map>
69cdf0e10cSrcweir
70cdf0e10cSrcweir using namespace com::sun::star;
71cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
72cdf0e10cSrcweir using ::com::sun::star::uno::Any;
73cdf0e10cSrcweir using ::rtl::OUString;
74cdf0e10cSrcweir using ::rtl::OUStringHash;
75cdf0e10cSrcweir using ::std::hash_map;
76cdf0e10cSrcweir using ::std::auto_ptr;
77cdf0e10cSrcweir
78cdf0e10cSrcweir // -----------------------------------------------------------------------
79cdf0e10cSrcweir
80cdf0e10cSrcweir #define SC_DPSAVEMODE_NO 0
81cdf0e10cSrcweir #define SC_DPSAVEMODE_YES 1
82cdf0e10cSrcweir #define SC_DPSAVEMODE_DONTKNOW 2
83cdf0e10cSrcweir
84cdf0e10cSrcweir // -----------------------------------------------------------------------
85cdf0e10cSrcweir
lcl_SetBoolProperty(const uno::Reference<beans::XPropertySet> & xProp,const rtl::OUString & rName,sal_Bool bValue)86cdf0e10cSrcweir void lcl_SetBoolProperty( const uno::Reference<beans::XPropertySet>& xProp,
87cdf0e10cSrcweir const rtl::OUString& rName, sal_Bool bValue )
88cdf0e10cSrcweir {
89cdf0e10cSrcweir //! move to ScUnoHelpFunctions?
90cdf0e10cSrcweir
91cdf0e10cSrcweir xProp->setPropertyValue( rName, uno::Any( &bValue, getBooleanCppuType() ) );
92cdf0e10cSrcweir }
93cdf0e10cSrcweir
94cdf0e10cSrcweir // -----------------------------------------------------------------------
95cdf0e10cSrcweir
ScDPSaveMember(const String & rName)96cdf0e10cSrcweir ScDPSaveMember::ScDPSaveMember(const String& rName) :
97cdf0e10cSrcweir aName( rName ),
98cdf0e10cSrcweir mpLayoutName(NULL),
99cdf0e10cSrcweir nVisibleMode( SC_DPSAVEMODE_DONTKNOW ),
100cdf0e10cSrcweir nShowDetailsMode( SC_DPSAVEMODE_DONTKNOW )
101cdf0e10cSrcweir {
102cdf0e10cSrcweir }
103cdf0e10cSrcweir
ScDPSaveMember(const ScDPSaveMember & r)104cdf0e10cSrcweir ScDPSaveMember::ScDPSaveMember(const ScDPSaveMember& r) :
105cdf0e10cSrcweir aName( r.aName ),
106cdf0e10cSrcweir mpLayoutName(NULL),
107cdf0e10cSrcweir nVisibleMode( r.nVisibleMode ),
108cdf0e10cSrcweir nShowDetailsMode( r.nShowDetailsMode )
109cdf0e10cSrcweir {
110cdf0e10cSrcweir if (r.mpLayoutName.get())
111cdf0e10cSrcweir mpLayoutName.reset(new OUString(*r.mpLayoutName));
112cdf0e10cSrcweir }
113cdf0e10cSrcweir
~ScDPSaveMember()114cdf0e10cSrcweir ScDPSaveMember::~ScDPSaveMember()
115cdf0e10cSrcweir {
116cdf0e10cSrcweir }
117cdf0e10cSrcweir
operator ==(const ScDPSaveMember & r) const118cdf0e10cSrcweir sal_Bool ScDPSaveMember::operator== ( const ScDPSaveMember& r ) const
119cdf0e10cSrcweir {
120cdf0e10cSrcweir if ( aName != r.aName ||
121cdf0e10cSrcweir nVisibleMode != r.nVisibleMode ||
122cdf0e10cSrcweir nShowDetailsMode != r.nShowDetailsMode )
123cdf0e10cSrcweir return sal_False;
124cdf0e10cSrcweir
125cdf0e10cSrcweir return sal_True;
126cdf0e10cSrcweir }
127cdf0e10cSrcweir
HasIsVisible() const128cdf0e10cSrcweir sal_Bool ScDPSaveMember::HasIsVisible() const
129cdf0e10cSrcweir {
130cdf0e10cSrcweir return nVisibleMode != SC_DPSAVEMODE_DONTKNOW;
131cdf0e10cSrcweir }
132cdf0e10cSrcweir
SetIsVisible(sal_Bool bSet)133cdf0e10cSrcweir void ScDPSaveMember::SetIsVisible(sal_Bool bSet)
134cdf0e10cSrcweir {
135cdf0e10cSrcweir nVisibleMode = bSet;
136cdf0e10cSrcweir }
137cdf0e10cSrcweir
HasShowDetails() const138cdf0e10cSrcweir sal_Bool ScDPSaveMember::HasShowDetails() const
139cdf0e10cSrcweir {
140cdf0e10cSrcweir return nShowDetailsMode != SC_DPSAVEMODE_DONTKNOW;
141cdf0e10cSrcweir }
142cdf0e10cSrcweir
SetShowDetails(sal_Bool bSet)143cdf0e10cSrcweir void ScDPSaveMember::SetShowDetails(sal_Bool bSet)
144cdf0e10cSrcweir {
145cdf0e10cSrcweir nShowDetailsMode = bSet;
146cdf0e10cSrcweir }
147cdf0e10cSrcweir
SetName(const String & rNew)148cdf0e10cSrcweir void ScDPSaveMember::SetName( const String& rNew )
149cdf0e10cSrcweir {
150cdf0e10cSrcweir // Used only if the source member was renamed (groups).
151cdf0e10cSrcweir // For UI renaming of members, a layout name must be used.
152cdf0e10cSrcweir
153cdf0e10cSrcweir aName = rNew;
154cdf0e10cSrcweir }
155cdf0e10cSrcweir
SetLayoutName(const OUString & rName)156cdf0e10cSrcweir void ScDPSaveMember::SetLayoutName( const OUString& rName )
157cdf0e10cSrcweir {
158cdf0e10cSrcweir mpLayoutName.reset(new OUString(rName));
159cdf0e10cSrcweir }
160cdf0e10cSrcweir
GetLayoutName() const161cdf0e10cSrcweir const OUString* ScDPSaveMember::GetLayoutName() const
162cdf0e10cSrcweir {
163cdf0e10cSrcweir return mpLayoutName.get();
164cdf0e10cSrcweir }
165cdf0e10cSrcweir
RemoveLayoutName()166cdf0e10cSrcweir void ScDPSaveMember::RemoveLayoutName()
167cdf0e10cSrcweir {
168*3d762826SHerbert Dürr mpLayoutName.reset();
169cdf0e10cSrcweir }
170cdf0e10cSrcweir
WriteToSource(const uno::Reference<uno::XInterface> & xMember,sal_Int32 nPosition)171cdf0e10cSrcweir void ScDPSaveMember::WriteToSource( const uno::Reference<uno::XInterface>& xMember, sal_Int32 nPosition )
172cdf0e10cSrcweir {
173cdf0e10cSrcweir uno::Reference<beans::XPropertySet> xMembProp( xMember, uno::UNO_QUERY );
174cdf0e10cSrcweir DBG_ASSERT( xMembProp.is(), "no properties at member" );
175cdf0e10cSrcweir if ( xMembProp.is() )
176cdf0e10cSrcweir {
177cdf0e10cSrcweir // exceptions are caught at ScDPSaveData::WriteToSource
178cdf0e10cSrcweir
179cdf0e10cSrcweir if ( nVisibleMode != SC_DPSAVEMODE_DONTKNOW )
180cdf0e10cSrcweir lcl_SetBoolProperty( xMembProp,
181cdf0e10cSrcweir rtl::OUString::createFromAscii(DP_PROP_ISVISIBLE), (sal_Bool)nVisibleMode );
182cdf0e10cSrcweir
183cdf0e10cSrcweir if ( nShowDetailsMode != SC_DPSAVEMODE_DONTKNOW )
184cdf0e10cSrcweir lcl_SetBoolProperty( xMembProp,
185cdf0e10cSrcweir rtl::OUString::createFromAscii(DP_PROP_SHOWDETAILS), (sal_Bool)nShowDetailsMode );
186cdf0e10cSrcweir
187cdf0e10cSrcweir if (mpLayoutName.get())
188cdf0e10cSrcweir ScUnoHelpFunctions::SetOptionalPropertyValue(xMembProp, SC_UNO_LAYOUTNAME, *mpLayoutName);
189cdf0e10cSrcweir
190cdf0e10cSrcweir if ( nPosition >= 0 )
191cdf0e10cSrcweir ScUnoHelpFunctions::SetOptionalPropertyValue(xMembProp, DP_PROP_POSITION, nPosition);
192cdf0e10cSrcweir }
193cdf0e10cSrcweir }
194cdf0e10cSrcweir
195cdf0e10cSrcweir // -----------------------------------------------------------------------
196cdf0e10cSrcweir
ScDPSaveDimension(const String & rName,sal_Bool bDataLayout)197cdf0e10cSrcweir ScDPSaveDimension::ScDPSaveDimension(const String& rName, sal_Bool bDataLayout) :
198cdf0e10cSrcweir aName( rName ),
199cdf0e10cSrcweir pSelectedPage( NULL ),
200cdf0e10cSrcweir mpLayoutName(NULL),
201cdf0e10cSrcweir mpSubtotalName(NULL),
202cdf0e10cSrcweir bIsDataLayout( bDataLayout ),
203cdf0e10cSrcweir bDupFlag( sal_False ),
204cdf0e10cSrcweir nOrientation( sheet::DataPilotFieldOrientation_HIDDEN ),
205cdf0e10cSrcweir nFunction( sheet::GeneralFunction_AUTO ),
206cdf0e10cSrcweir nUsedHierarchy( -1 ),
207cdf0e10cSrcweir nShowEmptyMode( SC_DPSAVEMODE_DONTKNOW ),
208cdf0e10cSrcweir bSubTotalDefault( sal_True ),
209cdf0e10cSrcweir nSubTotalCount( 0 ),
210cdf0e10cSrcweir pSubTotalFuncs( NULL ),
211cdf0e10cSrcweir pReferenceValue( NULL ),
212cdf0e10cSrcweir pSortInfo( NULL ),
213cdf0e10cSrcweir pAutoShowInfo( NULL ),
214cdf0e10cSrcweir pLayoutInfo( NULL )
215cdf0e10cSrcweir {
216cdf0e10cSrcweir }
217cdf0e10cSrcweir
ScDPSaveDimension(const ScDPSaveDimension & r)218cdf0e10cSrcweir ScDPSaveDimension::ScDPSaveDimension(const ScDPSaveDimension& r) :
219cdf0e10cSrcweir aName( r.aName ),
220cdf0e10cSrcweir mpLayoutName(NULL),
221cdf0e10cSrcweir mpSubtotalName(NULL),
222cdf0e10cSrcweir bIsDataLayout( r.bIsDataLayout ),
223cdf0e10cSrcweir bDupFlag( r.bDupFlag ),
224cdf0e10cSrcweir nOrientation( r.nOrientation ),
225cdf0e10cSrcweir nFunction( r.nFunction ),
226cdf0e10cSrcweir nUsedHierarchy( r.nUsedHierarchy ),
227cdf0e10cSrcweir nShowEmptyMode( r.nShowEmptyMode ),
228cdf0e10cSrcweir bSubTotalDefault( r.bSubTotalDefault ),
229cdf0e10cSrcweir nSubTotalCount( r.nSubTotalCount ),
230cdf0e10cSrcweir pSubTotalFuncs( NULL )
231cdf0e10cSrcweir {
232cdf0e10cSrcweir if ( nSubTotalCount && r.pSubTotalFuncs )
233cdf0e10cSrcweir {
234cdf0e10cSrcweir pSubTotalFuncs = new sal_uInt16[nSubTotalCount];
235cdf0e10cSrcweir for (long nSub=0; nSub<nSubTotalCount; nSub++)
236cdf0e10cSrcweir pSubTotalFuncs[nSub] = r.pSubTotalFuncs[nSub];
237cdf0e10cSrcweir }
238cdf0e10cSrcweir
239cdf0e10cSrcweir for (MemberList::const_iterator i=r.maMemberList.begin(); i != r.maMemberList.end() ; i++)
240cdf0e10cSrcweir {
241cdf0e10cSrcweir const String& rName = (*i)->GetName();
242cdf0e10cSrcweir ScDPSaveMember* pNew = new ScDPSaveMember( **i );
243cdf0e10cSrcweir maMemberHash[rName] = pNew;
244cdf0e10cSrcweir maMemberList.push_back( pNew );
245cdf0e10cSrcweir }
246cdf0e10cSrcweir if (r.pReferenceValue)
247cdf0e10cSrcweir pReferenceValue = new sheet::DataPilotFieldReference( *(r.pReferenceValue) );
248cdf0e10cSrcweir else
249cdf0e10cSrcweir pReferenceValue = NULL;
250cdf0e10cSrcweir if (r.pSortInfo)
251cdf0e10cSrcweir pSortInfo = new sheet::DataPilotFieldSortInfo( *(r.pSortInfo) );
252cdf0e10cSrcweir else
253cdf0e10cSrcweir pSortInfo = NULL;
254cdf0e10cSrcweir if (r.pAutoShowInfo)
255cdf0e10cSrcweir pAutoShowInfo = new sheet::DataPilotFieldAutoShowInfo( *(r.pAutoShowInfo) );
256cdf0e10cSrcweir else
257cdf0e10cSrcweir pAutoShowInfo = NULL;
258cdf0e10cSrcweir if (r.pLayoutInfo)
259cdf0e10cSrcweir pLayoutInfo = new sheet::DataPilotFieldLayoutInfo( *(r.pLayoutInfo) );
260cdf0e10cSrcweir else
261cdf0e10cSrcweir pLayoutInfo = NULL;
262cdf0e10cSrcweir if (r.pSelectedPage)
263cdf0e10cSrcweir pSelectedPage = new String( *(r.pSelectedPage) );
264cdf0e10cSrcweir else
265cdf0e10cSrcweir pSelectedPage = NULL;
266cdf0e10cSrcweir if (r.mpLayoutName.get())
267cdf0e10cSrcweir mpLayoutName.reset(new OUString(*r.mpLayoutName));
268cdf0e10cSrcweir if (r.mpSubtotalName.get())
269cdf0e10cSrcweir mpSubtotalName.reset(new OUString(*r.mpSubtotalName));
270cdf0e10cSrcweir }
271cdf0e10cSrcweir
~ScDPSaveDimension()272cdf0e10cSrcweir ScDPSaveDimension::~ScDPSaveDimension()
273cdf0e10cSrcweir {
274cdf0e10cSrcweir for (MemberHash::const_iterator i=maMemberHash.begin(); i != maMemberHash.end() ; i++)
275cdf0e10cSrcweir delete i->second;
276cdf0e10cSrcweir delete pReferenceValue;
277cdf0e10cSrcweir delete pSortInfo;
278cdf0e10cSrcweir delete pAutoShowInfo;
279cdf0e10cSrcweir delete pLayoutInfo;
280cdf0e10cSrcweir delete pSelectedPage;
281cdf0e10cSrcweir delete [] pSubTotalFuncs;
282cdf0e10cSrcweir }
283cdf0e10cSrcweir
operator ==(const ScDPSaveDimension & r) const284cdf0e10cSrcweir sal_Bool ScDPSaveDimension::operator== ( const ScDPSaveDimension& r ) const
285cdf0e10cSrcweir {
286cdf0e10cSrcweir if ( aName != r.aName ||
287cdf0e10cSrcweir bIsDataLayout != r.bIsDataLayout ||
288cdf0e10cSrcweir bDupFlag != r.bDupFlag ||
289cdf0e10cSrcweir nOrientation != r.nOrientation ||
290cdf0e10cSrcweir nFunction != r.nFunction ||
291cdf0e10cSrcweir nUsedHierarchy != r.nUsedHierarchy ||
292cdf0e10cSrcweir nShowEmptyMode != r.nShowEmptyMode ||
293cdf0e10cSrcweir bSubTotalDefault != r.bSubTotalDefault ||
294cdf0e10cSrcweir nSubTotalCount != r.nSubTotalCount )
295cdf0e10cSrcweir return sal_False;
296cdf0e10cSrcweir
297cdf0e10cSrcweir if ( nSubTotalCount && ( !pSubTotalFuncs || !r.pSubTotalFuncs ) ) // should not happen
298cdf0e10cSrcweir return sal_False;
299cdf0e10cSrcweir
300cdf0e10cSrcweir long i;
301cdf0e10cSrcweir for (i=0; i<nSubTotalCount; i++)
302cdf0e10cSrcweir if ( pSubTotalFuncs[i] != r.pSubTotalFuncs[i] )
303cdf0e10cSrcweir return sal_False;
304cdf0e10cSrcweir
305cdf0e10cSrcweir if (maMemberHash.size() != r.maMemberHash.size() )
306cdf0e10cSrcweir return sal_False;
307cdf0e10cSrcweir
308cdf0e10cSrcweir MemberList::const_iterator a=maMemberList.begin();
309cdf0e10cSrcweir MemberList::const_iterator b=r.maMemberList.begin();
310cdf0e10cSrcweir for (; a != maMemberList.end() ; ++a, ++b)
311cdf0e10cSrcweir if (!(**a == **b))
312cdf0e10cSrcweir return sal_False;
313cdf0e10cSrcweir
314cdf0e10cSrcweir if ( this->HasCurrentPage() && r.HasCurrentPage() )
315cdf0e10cSrcweir {
316cdf0e10cSrcweir if ( this->GetCurrentPage() != r.GetCurrentPage() )
317cdf0e10cSrcweir {
318cdf0e10cSrcweir return sal_False;
319cdf0e10cSrcweir }
320cdf0e10cSrcweir }
321cdf0e10cSrcweir else if ( this->HasCurrentPage() || r.HasCurrentPage() )
322cdf0e10cSrcweir {
323cdf0e10cSrcweir return sal_False;
324cdf0e10cSrcweir }
325cdf0e10cSrcweir if( pReferenceValue && r.pReferenceValue )
326cdf0e10cSrcweir {
327cdf0e10cSrcweir if ( !(*pReferenceValue == *r.pReferenceValue) )
328cdf0e10cSrcweir {
329cdf0e10cSrcweir return sal_False;
330cdf0e10cSrcweir }
331cdf0e10cSrcweir }
332cdf0e10cSrcweir else if ( pReferenceValue || r.pReferenceValue )
333cdf0e10cSrcweir {
334cdf0e10cSrcweir return sal_False;
335cdf0e10cSrcweir }
336cdf0e10cSrcweir if( this->pSortInfo && r.pSortInfo )
337cdf0e10cSrcweir {
338cdf0e10cSrcweir if ( !(*this->pSortInfo == *r.pSortInfo) )
339cdf0e10cSrcweir {
340cdf0e10cSrcweir return sal_False;
341cdf0e10cSrcweir }
342cdf0e10cSrcweir }
343cdf0e10cSrcweir else if ( this->pSortInfo || r.pSortInfo )
344cdf0e10cSrcweir {
345cdf0e10cSrcweir return sal_False;
346cdf0e10cSrcweir }
347cdf0e10cSrcweir if( this->pAutoShowInfo && r.pAutoShowInfo )
348cdf0e10cSrcweir {
349cdf0e10cSrcweir if ( !(*this->pAutoShowInfo == *r.pAutoShowInfo) )
350cdf0e10cSrcweir {
351cdf0e10cSrcweir return sal_False;
352cdf0e10cSrcweir }
353cdf0e10cSrcweir }
354cdf0e10cSrcweir else if ( this->pAutoShowInfo || r.pAutoShowInfo )
355cdf0e10cSrcweir {
356cdf0e10cSrcweir return sal_False;
357cdf0e10cSrcweir }
358cdf0e10cSrcweir
359cdf0e10cSrcweir return sal_True;
360cdf0e10cSrcweir }
361cdf0e10cSrcweir
AddMember(ScDPSaveMember * pMember)362cdf0e10cSrcweir void ScDPSaveDimension::AddMember(ScDPSaveMember* pMember)
363cdf0e10cSrcweir {
364cdf0e10cSrcweir const String & rName = pMember->GetName();
365cdf0e10cSrcweir MemberHash::iterator aExisting = maMemberHash.find( rName );
366cdf0e10cSrcweir if ( aExisting == maMemberHash.end() )
367cdf0e10cSrcweir {
368cdf0e10cSrcweir std::pair< const String, ScDPSaveMember *> key( rName, pMember );
369cdf0e10cSrcweir maMemberHash.insert ( key );
370cdf0e10cSrcweir }
371cdf0e10cSrcweir else
372cdf0e10cSrcweir {
373cdf0e10cSrcweir maMemberList.remove( aExisting->second );
374cdf0e10cSrcweir delete aExisting->second;
375cdf0e10cSrcweir aExisting->second = pMember;
376cdf0e10cSrcweir }
377cdf0e10cSrcweir maMemberList.push_back( pMember );
378cdf0e10cSrcweir }
379cdf0e10cSrcweir
SetName(const String & rNew)380cdf0e10cSrcweir void ScDPSaveDimension::SetName( const String& rNew )
381cdf0e10cSrcweir {
382cdf0e10cSrcweir // Used only if the source dim was renamed (groups).
383cdf0e10cSrcweir // For UI renaming of dimensions, the layout name must be used.
384cdf0e10cSrcweir
385cdf0e10cSrcweir aName = rNew;
386cdf0e10cSrcweir }
387cdf0e10cSrcweir
SetOrientation(sal_uInt16 nNew)388cdf0e10cSrcweir void ScDPSaveDimension::SetOrientation(sal_uInt16 nNew)
389cdf0e10cSrcweir {
390cdf0e10cSrcweir nOrientation = nNew;
391cdf0e10cSrcweir }
392cdf0e10cSrcweir
SetSubTotals(long nCount,const sal_uInt16 * pFuncs)393cdf0e10cSrcweir void ScDPSaveDimension::SetSubTotals(long nCount, const sal_uInt16* pFuncs)
394cdf0e10cSrcweir {
395cdf0e10cSrcweir if (pSubTotalFuncs)
396cdf0e10cSrcweir delete [] pSubTotalFuncs;
397cdf0e10cSrcweir nSubTotalCount = nCount;
398cdf0e10cSrcweir if ( nCount && pFuncs )
399cdf0e10cSrcweir {
400cdf0e10cSrcweir pSubTotalFuncs = new sal_uInt16[nCount];
401cdf0e10cSrcweir for (long i=0; i<nCount; i++)
402cdf0e10cSrcweir pSubTotalFuncs[i] = pFuncs[i];
403cdf0e10cSrcweir }
404cdf0e10cSrcweir else
405cdf0e10cSrcweir pSubTotalFuncs = NULL;
406cdf0e10cSrcweir
407cdf0e10cSrcweir bSubTotalDefault = sal_False;
408cdf0e10cSrcweir }
409cdf0e10cSrcweir
HasShowEmpty() const410cdf0e10cSrcweir bool ScDPSaveDimension::HasShowEmpty() const
411cdf0e10cSrcweir {
412cdf0e10cSrcweir return nShowEmptyMode != SC_DPSAVEMODE_DONTKNOW;
413cdf0e10cSrcweir }
414cdf0e10cSrcweir
SetShowEmpty(sal_Bool bSet)415cdf0e10cSrcweir void ScDPSaveDimension::SetShowEmpty(sal_Bool bSet)
416cdf0e10cSrcweir {
417cdf0e10cSrcweir nShowEmptyMode = bSet;
418cdf0e10cSrcweir }
419cdf0e10cSrcweir
SetFunction(sal_uInt16 nNew)420cdf0e10cSrcweir void ScDPSaveDimension::SetFunction(sal_uInt16 nNew)
421cdf0e10cSrcweir {
422cdf0e10cSrcweir nFunction = nNew;
423cdf0e10cSrcweir }
424cdf0e10cSrcweir
SetUsedHierarchy(long nNew)425cdf0e10cSrcweir void ScDPSaveDimension::SetUsedHierarchy(long nNew)
426cdf0e10cSrcweir {
427cdf0e10cSrcweir nUsedHierarchy = nNew;
428cdf0e10cSrcweir }
429cdf0e10cSrcweir
SetSubtotalName(const OUString & rName)430cdf0e10cSrcweir void ScDPSaveDimension::SetSubtotalName(const OUString& rName)
431cdf0e10cSrcweir {
432cdf0e10cSrcweir mpSubtotalName.reset(new OUString(rName));
433cdf0e10cSrcweir }
434cdf0e10cSrcweir
GetSubtotalName() const435cdf0e10cSrcweir const OUString* ScDPSaveDimension::GetSubtotalName() const
436cdf0e10cSrcweir {
437cdf0e10cSrcweir return mpSubtotalName.get();
438cdf0e10cSrcweir }
439cdf0e10cSrcweir
IsMemberNameInUse(const OUString & rName) const440cdf0e10cSrcweir bool ScDPSaveDimension::IsMemberNameInUse(const OUString& rName) const
441cdf0e10cSrcweir {
442cdf0e10cSrcweir MemberList::const_iterator itr = maMemberList.begin(), itrEnd = maMemberList.end();
443cdf0e10cSrcweir for (; itr != itrEnd; ++itr)
444cdf0e10cSrcweir {
445cdf0e10cSrcweir const ScDPSaveMember* pMem = *itr;
446cdf0e10cSrcweir if (rName.equalsIgnoreAsciiCase(pMem->GetName()))
447cdf0e10cSrcweir return true;
448cdf0e10cSrcweir
449cdf0e10cSrcweir const OUString* pLayoutName = pMem->GetLayoutName();
450cdf0e10cSrcweir if (pLayoutName && rName.equalsIgnoreAsciiCase(*pLayoutName))
451cdf0e10cSrcweir return true;
452cdf0e10cSrcweir }
453cdf0e10cSrcweir return false;
454cdf0e10cSrcweir }
455cdf0e10cSrcweir
SetLayoutName(const OUString & rName)456cdf0e10cSrcweir void ScDPSaveDimension::SetLayoutName(const OUString& rName)
457cdf0e10cSrcweir {
458cdf0e10cSrcweir mpLayoutName.reset(new OUString(rName));
459cdf0e10cSrcweir }
460cdf0e10cSrcweir
GetLayoutName() const461cdf0e10cSrcweir const OUString* ScDPSaveDimension::GetLayoutName() const
462cdf0e10cSrcweir {
463cdf0e10cSrcweir return mpLayoutName.get();
464cdf0e10cSrcweir }
465cdf0e10cSrcweir
RemoveLayoutName()466cdf0e10cSrcweir void ScDPSaveDimension::RemoveLayoutName()
467cdf0e10cSrcweir {
468*3d762826SHerbert Dürr mpLayoutName.reset();
469cdf0e10cSrcweir }
470cdf0e10cSrcweir
SetReferenceValue(const sheet::DataPilotFieldReference * pNew)471cdf0e10cSrcweir void ScDPSaveDimension::SetReferenceValue(const sheet::DataPilotFieldReference* pNew)
472cdf0e10cSrcweir {
473cdf0e10cSrcweir delete pReferenceValue;
474cdf0e10cSrcweir if (pNew)
475cdf0e10cSrcweir pReferenceValue = new sheet::DataPilotFieldReference(*pNew);
476cdf0e10cSrcweir else
477cdf0e10cSrcweir pReferenceValue = NULL;
478cdf0e10cSrcweir }
479cdf0e10cSrcweir
SetSortInfo(const sheet::DataPilotFieldSortInfo * pNew)480cdf0e10cSrcweir void ScDPSaveDimension::SetSortInfo(const sheet::DataPilotFieldSortInfo* pNew)
481cdf0e10cSrcweir {
482cdf0e10cSrcweir delete pSortInfo;
483cdf0e10cSrcweir if (pNew)
484cdf0e10cSrcweir pSortInfo = new sheet::DataPilotFieldSortInfo(*pNew);
485cdf0e10cSrcweir else
486cdf0e10cSrcweir pSortInfo = NULL;
487cdf0e10cSrcweir }
488cdf0e10cSrcweir
SetAutoShowInfo(const sheet::DataPilotFieldAutoShowInfo * pNew)489cdf0e10cSrcweir void ScDPSaveDimension::SetAutoShowInfo(const sheet::DataPilotFieldAutoShowInfo* pNew)
490cdf0e10cSrcweir {
491cdf0e10cSrcweir delete pAutoShowInfo;
492cdf0e10cSrcweir if (pNew)
493cdf0e10cSrcweir pAutoShowInfo = new sheet::DataPilotFieldAutoShowInfo(*pNew);
494cdf0e10cSrcweir else
495cdf0e10cSrcweir pAutoShowInfo = NULL;
496cdf0e10cSrcweir }
497cdf0e10cSrcweir
SetLayoutInfo(const sheet::DataPilotFieldLayoutInfo * pNew)498cdf0e10cSrcweir void ScDPSaveDimension::SetLayoutInfo(const sheet::DataPilotFieldLayoutInfo* pNew)
499cdf0e10cSrcweir {
500cdf0e10cSrcweir delete pLayoutInfo;
501cdf0e10cSrcweir if (pNew)
502cdf0e10cSrcweir pLayoutInfo = new sheet::DataPilotFieldLayoutInfo(*pNew);
503cdf0e10cSrcweir else
504cdf0e10cSrcweir pLayoutInfo = NULL;
505cdf0e10cSrcweir }
506cdf0e10cSrcweir
SetCurrentPage(const String * pPage)507cdf0e10cSrcweir void ScDPSaveDimension::SetCurrentPage( const String* pPage )
508cdf0e10cSrcweir {
509cdf0e10cSrcweir delete pSelectedPage;
510cdf0e10cSrcweir if (pPage)
511cdf0e10cSrcweir pSelectedPage = new String( *pPage );
512cdf0e10cSrcweir else
513cdf0e10cSrcweir pSelectedPage = NULL;
514cdf0e10cSrcweir }
515cdf0e10cSrcweir
HasCurrentPage() const516cdf0e10cSrcweir sal_Bool ScDPSaveDimension::HasCurrentPage() const
517cdf0e10cSrcweir {
518cdf0e10cSrcweir return ( pSelectedPage != NULL );
519cdf0e10cSrcweir }
520cdf0e10cSrcweir
GetCurrentPage() const521cdf0e10cSrcweir const String& ScDPSaveDimension::GetCurrentPage() const
522cdf0e10cSrcweir {
523cdf0e10cSrcweir if (pSelectedPage)
524cdf0e10cSrcweir return *pSelectedPage;
525cdf0e10cSrcweir return EMPTY_STRING;
526cdf0e10cSrcweir }
527cdf0e10cSrcweir
GetExistingMemberByName(const String & rName)528cdf0e10cSrcweir ScDPSaveMember* ScDPSaveDimension::GetExistingMemberByName(const String& rName)
529cdf0e10cSrcweir {
530cdf0e10cSrcweir MemberHash::const_iterator res = maMemberHash.find (rName);
531cdf0e10cSrcweir if (res != maMemberHash.end())
532cdf0e10cSrcweir return res->second;
533cdf0e10cSrcweir return NULL;
534cdf0e10cSrcweir }
535cdf0e10cSrcweir
536cdf0e10cSrcweir
GetMemberByName(const String & rName)537cdf0e10cSrcweir ScDPSaveMember* ScDPSaveDimension::GetMemberByName(const String& rName)
538cdf0e10cSrcweir {
539cdf0e10cSrcweir MemberHash::const_iterator res = maMemberHash.find (rName);
540cdf0e10cSrcweir if (res != maMemberHash.end())
541cdf0e10cSrcweir return res->second;
542cdf0e10cSrcweir
543cdf0e10cSrcweir ScDPSaveMember* pNew = new ScDPSaveMember( rName );
544cdf0e10cSrcweir maMemberHash[rName] = pNew;
545cdf0e10cSrcweir maMemberList.push_back( pNew );
546cdf0e10cSrcweir return pNew;
547cdf0e10cSrcweir }
548cdf0e10cSrcweir
SetMemberPosition(const String & rName,sal_Int32 nNewPos)549cdf0e10cSrcweir void ScDPSaveDimension::SetMemberPosition( const String& rName, sal_Int32 nNewPos )
550cdf0e10cSrcweir {
551cdf0e10cSrcweir ScDPSaveMember* pMember = GetMemberByName( rName ); // make sure it exists and is in the hash
552cdf0e10cSrcweir
553cdf0e10cSrcweir maMemberList.remove( pMember );
554cdf0e10cSrcweir
555cdf0e10cSrcweir MemberList::iterator aIter = maMemberList.begin();
556cdf0e10cSrcweir for (sal_Int32 i=0; i<nNewPos && aIter != maMemberList.end(); i++)
557cdf0e10cSrcweir ++aIter;
558cdf0e10cSrcweir maMemberList.insert( aIter, pMember );
559cdf0e10cSrcweir }
560cdf0e10cSrcweir
WriteToSource(const uno::Reference<uno::XInterface> & xDim)561cdf0e10cSrcweir void ScDPSaveDimension::WriteToSource( const uno::Reference<uno::XInterface>& xDim )
562cdf0e10cSrcweir {
563cdf0e10cSrcweir uno::Reference<beans::XPropertySet> xDimProp( xDim, uno::UNO_QUERY );
564cdf0e10cSrcweir DBG_ASSERT( xDimProp.is(), "no properties at dimension" );
565cdf0e10cSrcweir if ( xDimProp.is() )
566cdf0e10cSrcweir {
567cdf0e10cSrcweir // exceptions are caught at ScDPSaveData::WriteToSource
568cdf0e10cSrcweir uno::Any aAny;
569cdf0e10cSrcweir
570cdf0e10cSrcweir sheet::DataPilotFieldOrientation eOrient = (sheet::DataPilotFieldOrientation)nOrientation;
571cdf0e10cSrcweir aAny <<= eOrient;
572cdf0e10cSrcweir xDimProp->setPropertyValue( rtl::OUString::createFromAscii(DP_PROP_ORIENTATION), aAny );
573cdf0e10cSrcweir
574cdf0e10cSrcweir sheet::GeneralFunction eFunc = (sheet::GeneralFunction)nFunction;
575cdf0e10cSrcweir aAny <<= eFunc;
576cdf0e10cSrcweir xDimProp->setPropertyValue( rtl::OUString::createFromAscii(DP_PROP_FUNCTION), aAny );
577cdf0e10cSrcweir
578cdf0e10cSrcweir if ( nUsedHierarchy >= 0 )
579cdf0e10cSrcweir {
580cdf0e10cSrcweir aAny <<= (sal_Int32)nUsedHierarchy;
581cdf0e10cSrcweir xDimProp->setPropertyValue( rtl::OUString::createFromAscii(DP_PROP_USEDHIERARCHY), aAny );
582cdf0e10cSrcweir }
583cdf0e10cSrcweir
584cdf0e10cSrcweir if ( pReferenceValue )
585cdf0e10cSrcweir {
586cdf0e10cSrcweir aAny <<= *pReferenceValue;
587cdf0e10cSrcweir xDimProp->setPropertyValue( rtl::OUString::createFromAscii(SC_UNO_REFVALUE), aAny );
588cdf0e10cSrcweir }
589cdf0e10cSrcweir
590cdf0e10cSrcweir uno::Sequence<sheet::TableFilterField> aFilter;
591cdf0e10cSrcweir // set the selected page field only if the dimension is used as page dimension
592cdf0e10cSrcweir if ( pSelectedPage && nOrientation == sheet::DataPilotFieldOrientation_PAGE )
593cdf0e10cSrcweir {
594cdf0e10cSrcweir // single filter field: first field equal to selected string
595cdf0e10cSrcweir sheet::TableFilterField aField( sheet::FilterConnection_AND, 0,
596cdf0e10cSrcweir sheet::FilterOperator_EQUAL, sal_False, 0.0, *pSelectedPage );
597cdf0e10cSrcweir aFilter = uno::Sequence<sheet::TableFilterField>( &aField, 1 );
598cdf0e10cSrcweir }
599cdf0e10cSrcweir // else keep empty sequence
600cdf0e10cSrcweir
601cdf0e10cSrcweir ScUnoHelpFunctions::SetOptionalPropertyValue(xDimProp, DP_PROP_FILTER, aFilter);
602cdf0e10cSrcweir if (mpLayoutName.get())
603cdf0e10cSrcweir ScUnoHelpFunctions::SetOptionalPropertyValue(xDimProp, SC_UNO_LAYOUTNAME, *mpLayoutName);
604cdf0e10cSrcweir
605cdf0e10cSrcweir const OUString* pSubTotalName = GetSubtotalName();
606cdf0e10cSrcweir if (pSubTotalName)
607cdf0e10cSrcweir // Custom subtotal name, with '?' being replaced by the visible field name later.
608cdf0e10cSrcweir ScUnoHelpFunctions::SetOptionalPropertyValue(xDimProp, SC_UNO_FIELD_SUBTOTALNAME, *pSubTotalName);
609cdf0e10cSrcweir }
610cdf0e10cSrcweir
611cdf0e10cSrcweir // Level loop outside of maMemberList loop
612cdf0e10cSrcweir // because SubTotals have to be set independently of known members
613cdf0e10cSrcweir
614cdf0e10cSrcweir long nCount = maMemberHash.size();
615cdf0e10cSrcweir
616cdf0e10cSrcweir long nHierCount = 0;
617cdf0e10cSrcweir uno::Reference<container::XIndexAccess> xHiers;
618cdf0e10cSrcweir uno::Reference<sheet::XHierarchiesSupplier> xHierSupp( xDim, uno::UNO_QUERY );
619cdf0e10cSrcweir if ( xHierSupp.is() )
620cdf0e10cSrcweir {
621cdf0e10cSrcweir uno::Reference<container::XNameAccess> xHiersName = xHierSupp->getHierarchies();
622cdf0e10cSrcweir xHiers = new ScNameToIndexAccess( xHiersName );
623cdf0e10cSrcweir nHierCount = xHiers->getCount();
624cdf0e10cSrcweir }
625cdf0e10cSrcweir
626cdf0e10cSrcweir sal_Bool bHasHiddenMember = false;
627cdf0e10cSrcweir
628cdf0e10cSrcweir for (long nHier=0; nHier<nHierCount; nHier++)
629cdf0e10cSrcweir {
630cdf0e10cSrcweir uno::Reference<uno::XInterface> xHierarchy = ScUnoHelpFunctions::AnyToInterface( xHiers->getByIndex(nHier) );
631cdf0e10cSrcweir
632cdf0e10cSrcweir long nLevCount = 0;
633cdf0e10cSrcweir uno::Reference<container::XIndexAccess> xLevels;
634cdf0e10cSrcweir uno::Reference<sheet::XLevelsSupplier> xLevSupp( xHierarchy, uno::UNO_QUERY );
635cdf0e10cSrcweir if ( xLevSupp.is() )
636cdf0e10cSrcweir {
637cdf0e10cSrcweir uno::Reference<container::XNameAccess> xLevelsName = xLevSupp->getLevels();
638cdf0e10cSrcweir xLevels = new ScNameToIndexAccess( xLevelsName );
639cdf0e10cSrcweir nLevCount = xLevels->getCount();
640cdf0e10cSrcweir }
641cdf0e10cSrcweir
642cdf0e10cSrcweir for (long nLev=0; nLev<nLevCount; nLev++)
643cdf0e10cSrcweir {
644cdf0e10cSrcweir uno::Reference<uno::XInterface> xLevel = ScUnoHelpFunctions::AnyToInterface( xLevels->getByIndex(nLev) );
645cdf0e10cSrcweir uno::Reference<beans::XPropertySet> xLevProp( xLevel, uno::UNO_QUERY );
646cdf0e10cSrcweir DBG_ASSERT( xLevProp.is(), "no properties at level" );
647cdf0e10cSrcweir if ( xLevProp.is() )
648cdf0e10cSrcweir {
649cdf0e10cSrcweir uno::Any aAny;
650cdf0e10cSrcweir if ( !bSubTotalDefault )
651cdf0e10cSrcweir {
652cdf0e10cSrcweir if ( !pSubTotalFuncs )
653cdf0e10cSrcweir nSubTotalCount = 0;
654cdf0e10cSrcweir
655cdf0e10cSrcweir uno::Sequence<sheet::GeneralFunction> aSeq(nSubTotalCount);
656cdf0e10cSrcweir sheet::GeneralFunction* pArray = aSeq.getArray();
657cdf0e10cSrcweir for (long i=0; i<nSubTotalCount; i++)
658cdf0e10cSrcweir pArray[i] = (sheet::GeneralFunction)pSubTotalFuncs[i];
659cdf0e10cSrcweir aAny <<= aSeq;
660cdf0e10cSrcweir xLevProp->setPropertyValue( rtl::OUString::createFromAscii(DP_PROP_SUBTOTALS), aAny );
661cdf0e10cSrcweir }
662cdf0e10cSrcweir if ( nShowEmptyMode != SC_DPSAVEMODE_DONTKNOW )
663cdf0e10cSrcweir lcl_SetBoolProperty( xLevProp,
664cdf0e10cSrcweir rtl::OUString::createFromAscii(DP_PROP_SHOWEMPTY), (sal_Bool)nShowEmptyMode );
665cdf0e10cSrcweir
666cdf0e10cSrcweir if ( pSortInfo )
667cdf0e10cSrcweir ScUnoHelpFunctions::SetOptionalPropertyValue(xLevProp, SC_UNO_SORTING, *pSortInfo);
668cdf0e10cSrcweir
669cdf0e10cSrcweir if ( pAutoShowInfo )
670cdf0e10cSrcweir ScUnoHelpFunctions::SetOptionalPropertyValue(xLevProp, SC_UNO_AUTOSHOW, *pAutoShowInfo);
671cdf0e10cSrcweir
672cdf0e10cSrcweir if ( pLayoutInfo )
673cdf0e10cSrcweir ScUnoHelpFunctions::SetOptionalPropertyValue(xLevProp, SC_UNO_LAYOUT, *pLayoutInfo);
674cdf0e10cSrcweir
675cdf0e10cSrcweir // exceptions are caught at ScDPSaveData::WriteToSource
676cdf0e10cSrcweir }
677cdf0e10cSrcweir
678cdf0e10cSrcweir if ( nCount > 0 )
679cdf0e10cSrcweir {
680cdf0e10cSrcweir uno::Reference<sheet::XMembersSupplier> xMembSupp( xLevel, uno::UNO_QUERY );
681cdf0e10cSrcweir if ( xMembSupp.is() )
682cdf0e10cSrcweir {
683cdf0e10cSrcweir uno::Reference<container::XNameAccess> xMembers = xMembSupp->getMembers();
684cdf0e10cSrcweir if ( xMembers.is() )
685cdf0e10cSrcweir {
686cdf0e10cSrcweir sal_Int32 nPosition = -1; // set position only in manual mode
687cdf0e10cSrcweir if ( !pSortInfo || pSortInfo->Mode == sheet::DataPilotFieldSortMode::MANUAL )
688cdf0e10cSrcweir nPosition = 0;
689cdf0e10cSrcweir
690cdf0e10cSrcweir for (MemberList::const_iterator i=maMemberList.begin(); i != maMemberList.end() ; i++)
691cdf0e10cSrcweir {
692cdf0e10cSrcweir ScDPSaveMember* pMember = *i;
693cdf0e10cSrcweir if (!pMember->GetIsVisible())
694cdf0e10cSrcweir bHasHiddenMember = true;
695cdf0e10cSrcweir rtl::OUString aMemberName = pMember->GetName();
696cdf0e10cSrcweir if ( xMembers->hasByName( aMemberName ) )
697cdf0e10cSrcweir {
698cdf0e10cSrcweir uno::Reference<uno::XInterface> xMemberInt = ScUnoHelpFunctions::AnyToInterface(
699cdf0e10cSrcweir xMembers->getByName( aMemberName ) );
700cdf0e10cSrcweir pMember->WriteToSource( xMemberInt, nPosition );
701cdf0e10cSrcweir
702cdf0e10cSrcweir if ( nPosition >= 0 )
703cdf0e10cSrcweir ++nPosition; // increase if initialized
704cdf0e10cSrcweir }
705cdf0e10cSrcweir // missing member is no error
706cdf0e10cSrcweir }
707cdf0e10cSrcweir }
708cdf0e10cSrcweir }
709cdf0e10cSrcweir }
710cdf0e10cSrcweir }
711cdf0e10cSrcweir }
712cdf0e10cSrcweir
713cdf0e10cSrcweir if (xDimProp.is())
714cdf0e10cSrcweir ScUnoHelpFunctions::SetOptionalPropertyValue(xDimProp, SC_UNO_HAS_HIDDEN_MEMBER, bHasHiddenMember);
715cdf0e10cSrcweir }
716cdf0e10cSrcweir
UpdateMemberVisibility(const hash_map<OUString,bool,OUStringHash> & rData)717cdf0e10cSrcweir void ScDPSaveDimension::UpdateMemberVisibility(const hash_map<OUString, bool, OUStringHash>& rData)
718cdf0e10cSrcweir {
719cdf0e10cSrcweir typedef hash_map<OUString, bool, OUStringHash> DataMap;
720cdf0e10cSrcweir MemberList::iterator itrMem = maMemberList.begin(), itrMemEnd = maMemberList.end();
721cdf0e10cSrcweir for (; itrMem != itrMemEnd; ++itrMem)
722cdf0e10cSrcweir {
723cdf0e10cSrcweir ScDPSaveMember* pMem = *itrMem;
724cdf0e10cSrcweir const String& rMemName = pMem->GetName();
725cdf0e10cSrcweir DataMap::const_iterator itr = rData.find(rMemName);
726cdf0e10cSrcweir if (itr != rData.end())
727cdf0e10cSrcweir pMem->SetIsVisible(itr->second);
728cdf0e10cSrcweir }
729cdf0e10cSrcweir }
730cdf0e10cSrcweir
HasInvisibleMember() const731cdf0e10cSrcweir bool ScDPSaveDimension::HasInvisibleMember() const
732cdf0e10cSrcweir {
733cdf0e10cSrcweir MemberList::const_iterator itrMem = maMemberList.begin(), itrMemEnd = maMemberList.end();
734cdf0e10cSrcweir for (; itrMem != itrMemEnd; ++itrMem)
735cdf0e10cSrcweir {
736cdf0e10cSrcweir const ScDPSaveMember* pMem = *itrMem;
737cdf0e10cSrcweir if (!pMem->GetIsVisible())
738cdf0e10cSrcweir return true;
739cdf0e10cSrcweir }
740cdf0e10cSrcweir return false;
741cdf0e10cSrcweir }
742cdf0e10cSrcweir
743cdf0e10cSrcweir // -----------------------------------------------------------------------
744cdf0e10cSrcweir
ScDPSaveData()745cdf0e10cSrcweir ScDPSaveData::ScDPSaveData() :
746cdf0e10cSrcweir pDimensionData( NULL ),
747cdf0e10cSrcweir nColumnGrandMode( SC_DPSAVEMODE_DONTKNOW ),
748cdf0e10cSrcweir nRowGrandMode( SC_DPSAVEMODE_DONTKNOW ),
749cdf0e10cSrcweir nIgnoreEmptyMode( SC_DPSAVEMODE_DONTKNOW ),
750cdf0e10cSrcweir nRepeatEmptyMode( SC_DPSAVEMODE_DONTKNOW ),
751cdf0e10cSrcweir bFilterButton( sal_True ),
752cdf0e10cSrcweir bDrillDown( sal_True ),
753cdf0e10cSrcweir // Wang Xu Ming -- 2009-8-17
754cdf0e10cSrcweir // DataPilot Migration - Cache&&Performance
755cdf0e10cSrcweir mnCacheId( -1),
756cdf0e10cSrcweir // End Comments
757cdf0e10cSrcweir mbDimensionMembersBuilt(false),
758cdf0e10cSrcweir mpGrandTotalName(NULL)
759cdf0e10cSrcweir {
760cdf0e10cSrcweir }
761cdf0e10cSrcweir
ScDPSaveData(const ScDPSaveData & r)762cdf0e10cSrcweir ScDPSaveData::ScDPSaveData(const ScDPSaveData& r) :
763cdf0e10cSrcweir nColumnGrandMode( r.nColumnGrandMode ),
764cdf0e10cSrcweir nRowGrandMode( r.nRowGrandMode ),
765cdf0e10cSrcweir nIgnoreEmptyMode( r.nIgnoreEmptyMode ),
766cdf0e10cSrcweir nRepeatEmptyMode( r.nRepeatEmptyMode ),
767cdf0e10cSrcweir bFilterButton( r.bFilterButton ),
768cdf0e10cSrcweir bDrillDown( r.bDrillDown ),
769cdf0e10cSrcweir // Wang Xu Ming -- 2009-8-17
770cdf0e10cSrcweir // DataPilot Migration - Cache&&Performance
771cdf0e10cSrcweir mnCacheId( r.mnCacheId ),
772cdf0e10cSrcweir // End Comments
773cdf0e10cSrcweir mbDimensionMembersBuilt(r.mbDimensionMembersBuilt),
774cdf0e10cSrcweir mpGrandTotalName(NULL)
775cdf0e10cSrcweir {
776cdf0e10cSrcweir if ( r.pDimensionData )
777cdf0e10cSrcweir pDimensionData = new ScDPDimensionSaveData( *r.pDimensionData );
778cdf0e10cSrcweir else
779cdf0e10cSrcweir pDimensionData = NULL;
780cdf0e10cSrcweir
781cdf0e10cSrcweir long nCount = r.aDimList.Count();
782cdf0e10cSrcweir for (long i=0; i<nCount; i++)
783cdf0e10cSrcweir {
784cdf0e10cSrcweir ScDPSaveDimension* pNew = new ScDPSaveDimension( *(ScDPSaveDimension*)r.aDimList.GetObject(i) );
785cdf0e10cSrcweir aDimList.Insert( pNew, LIST_APPEND );
786cdf0e10cSrcweir }
787cdf0e10cSrcweir
788cdf0e10cSrcweir if (r.mpGrandTotalName.get())
789cdf0e10cSrcweir mpGrandTotalName.reset(new OUString(*r.mpGrandTotalName));
790cdf0e10cSrcweir }
791cdf0e10cSrcweir
operator =(const ScDPSaveData & r)792cdf0e10cSrcweir ScDPSaveData& ScDPSaveData::operator= ( const ScDPSaveData& r )
793cdf0e10cSrcweir {
794cdf0e10cSrcweir if ( &r != this )
795cdf0e10cSrcweir {
796cdf0e10cSrcweir // Wang Xu Ming -- 2009-8-17
797cdf0e10cSrcweir // DataPilot Migration - Cache&&Performance
798cdf0e10cSrcweir this->~ScDPSaveData();
799cdf0e10cSrcweir new( this ) ScDPSaveData ( r );
800cdf0e10cSrcweir // End Comments
801cdf0e10cSrcweir }
802cdf0e10cSrcweir return *this;
803cdf0e10cSrcweir }
804cdf0e10cSrcweir
operator ==(const ScDPSaveData & r) const805cdf0e10cSrcweir sal_Bool ScDPSaveData::operator== ( const ScDPSaveData& r ) const
806cdf0e10cSrcweir {
807cdf0e10cSrcweir if ( nColumnGrandMode != r.nColumnGrandMode ||
808cdf0e10cSrcweir nRowGrandMode != r.nRowGrandMode ||
809cdf0e10cSrcweir nIgnoreEmptyMode != r.nIgnoreEmptyMode ||
810cdf0e10cSrcweir nRepeatEmptyMode != r.nRepeatEmptyMode ||
811cdf0e10cSrcweir bFilterButton != r.bFilterButton ||
812cdf0e10cSrcweir mnCacheId != r.mnCacheId ||/// Wang Xu Ming -- 2009-6-18 DataPilot Migration
813cdf0e10cSrcweir bDrillDown != r.bDrillDown ||
814cdf0e10cSrcweir mbDimensionMembersBuilt != r.mbDimensionMembersBuilt)
815cdf0e10cSrcweir return sal_False;
816cdf0e10cSrcweir
817cdf0e10cSrcweir if ( pDimensionData || r.pDimensionData )
818cdf0e10cSrcweir if ( !pDimensionData || !r.pDimensionData || !( *pDimensionData == *r.pDimensionData ) )
819cdf0e10cSrcweir return sal_False;
820cdf0e10cSrcweir
821cdf0e10cSrcweir sal_uLong nCount = aDimList.Count();
822cdf0e10cSrcweir if ( nCount != r.aDimList.Count() )
823cdf0e10cSrcweir return sal_False;
824cdf0e10cSrcweir
825cdf0e10cSrcweir for (sal_uLong i=0; i<nCount; i++)
826cdf0e10cSrcweir if ( !( *(ScDPSaveDimension*)aDimList.GetObject(i) ==
827cdf0e10cSrcweir *(ScDPSaveDimension*)r.aDimList.GetObject(i) ) )
828cdf0e10cSrcweir return sal_False;
829cdf0e10cSrcweir
830cdf0e10cSrcweir if (mpGrandTotalName.get())
831cdf0e10cSrcweir {
832cdf0e10cSrcweir if (!r.mpGrandTotalName.get())
833cdf0e10cSrcweir return false;
834cdf0e10cSrcweir if (!mpGrandTotalName->equals(*r.mpGrandTotalName))
835cdf0e10cSrcweir return false;
836cdf0e10cSrcweir }
837cdf0e10cSrcweir else if (r.mpGrandTotalName.get())
838cdf0e10cSrcweir return false;
839cdf0e10cSrcweir
840cdf0e10cSrcweir return sal_True;
841cdf0e10cSrcweir }
842cdf0e10cSrcweir
~ScDPSaveData()843cdf0e10cSrcweir ScDPSaveData::~ScDPSaveData()
844cdf0e10cSrcweir {
845cdf0e10cSrcweir long nCount = aDimList.Count();
846cdf0e10cSrcweir for (long i=0; i<nCount; i++)
847cdf0e10cSrcweir delete (ScDPSaveDimension*)aDimList.GetObject(i);
848cdf0e10cSrcweir aDimList.Clear();
849cdf0e10cSrcweir
850cdf0e10cSrcweir delete pDimensionData;
851cdf0e10cSrcweir }
852cdf0e10cSrcweir
SetGrandTotalName(const OUString & rName)853cdf0e10cSrcweir void ScDPSaveData::SetGrandTotalName(const OUString& rName)
854cdf0e10cSrcweir {
855cdf0e10cSrcweir mpGrandTotalName.reset(new OUString(rName));
856cdf0e10cSrcweir }
857cdf0e10cSrcweir
GetGrandTotalName() const858cdf0e10cSrcweir const OUString* ScDPSaveData::GetGrandTotalName() const
859cdf0e10cSrcweir {
860cdf0e10cSrcweir return mpGrandTotalName.get();
861cdf0e10cSrcweir }
862cdf0e10cSrcweir
GetDimensionByName(const String & rName)863cdf0e10cSrcweir ScDPSaveDimension* ScDPSaveData::GetDimensionByName(const String& rName)
864cdf0e10cSrcweir {
865cdf0e10cSrcweir long nCount = aDimList.Count();
866cdf0e10cSrcweir for (long i=0; i<nCount; i++)
867cdf0e10cSrcweir {
868cdf0e10cSrcweir ScDPSaveDimension* pDim = (ScDPSaveDimension*)aDimList.GetObject(i);
869cdf0e10cSrcweir if ( pDim->GetName() == rName && !pDim->IsDataLayout() )
870cdf0e10cSrcweir return pDim;
871cdf0e10cSrcweir }
872cdf0e10cSrcweir ScDPSaveDimension* pNew = new ScDPSaveDimension( rName, sal_False );
873cdf0e10cSrcweir aDimList.Insert( pNew, LIST_APPEND );
874cdf0e10cSrcweir mbDimensionMembersBuilt = false; // BuildAllDimensionMembers only handles existing entries in aDimList
875cdf0e10cSrcweir return pNew;
876cdf0e10cSrcweir }
877cdf0e10cSrcweir
GetExistingDimensionByName(const String & rName) const878cdf0e10cSrcweir ScDPSaveDimension* ScDPSaveData::GetExistingDimensionByName(const String& rName) const
879cdf0e10cSrcweir {
880cdf0e10cSrcweir long nCount = aDimList.Count();
881cdf0e10cSrcweir for (long i=0; i<nCount; i++)
882cdf0e10cSrcweir {
883cdf0e10cSrcweir ScDPSaveDimension* pDim = (ScDPSaveDimension*)aDimList.GetObject(i);
884cdf0e10cSrcweir if ( pDim->GetName() == rName && !pDim->IsDataLayout() )
885cdf0e10cSrcweir return pDim;
886cdf0e10cSrcweir }
887cdf0e10cSrcweir return NULL; // don't create new
888cdf0e10cSrcweir }
889cdf0e10cSrcweir
GetNewDimensionByName(const String & rName)890cdf0e10cSrcweir ScDPSaveDimension* ScDPSaveData::GetNewDimensionByName(const String& rName)
891cdf0e10cSrcweir {
892cdf0e10cSrcweir long nCount = aDimList.Count();
893cdf0e10cSrcweir for (long i=0; i<nCount; i++)
894cdf0e10cSrcweir {
895cdf0e10cSrcweir ScDPSaveDimension* pDim = (ScDPSaveDimension*)aDimList.GetObject(i);
896cdf0e10cSrcweir if ( pDim->GetName() == rName && !pDim->IsDataLayout() )
897cdf0e10cSrcweir return DuplicateDimension(rName);
898cdf0e10cSrcweir }
899cdf0e10cSrcweir ScDPSaveDimension* pNew = new ScDPSaveDimension( rName, sal_False );
900cdf0e10cSrcweir aDimList.Insert( pNew, LIST_APPEND );
901cdf0e10cSrcweir mbDimensionMembersBuilt = false; // BuildAllDimensionMembers only handles existing entries in aDimList
902cdf0e10cSrcweir return pNew;
903cdf0e10cSrcweir }
904cdf0e10cSrcweir
GetDataLayoutDimension()905cdf0e10cSrcweir ScDPSaveDimension* ScDPSaveData::GetDataLayoutDimension()
906cdf0e10cSrcweir {
907cdf0e10cSrcweir ScDPSaveDimension* pDim = GetExistingDataLayoutDimension();
908cdf0e10cSrcweir if (pDim)
909cdf0e10cSrcweir return pDim;
910cdf0e10cSrcweir
911cdf0e10cSrcweir ScDPSaveDimension* pNew = new ScDPSaveDimension( String(), sal_True );
912cdf0e10cSrcweir aDimList.Insert( pNew, LIST_APPEND );
913cdf0e10cSrcweir mbDimensionMembersBuilt = false; // BuildAllDimensionMembers only handles existing entries in aDimList
914cdf0e10cSrcweir return pNew;
915cdf0e10cSrcweir }
916cdf0e10cSrcweir
GetExistingDataLayoutDimension() const917cdf0e10cSrcweir ScDPSaveDimension* ScDPSaveData::GetExistingDataLayoutDimension() const
918cdf0e10cSrcweir {
919cdf0e10cSrcweir long nCount = aDimList.Count();
920cdf0e10cSrcweir for (long i=0; i<nCount; i++)
921cdf0e10cSrcweir {
922cdf0e10cSrcweir ScDPSaveDimension* pDim = (ScDPSaveDimension*)aDimList.GetObject(i);
923cdf0e10cSrcweir if ( pDim->IsDataLayout() )
924cdf0e10cSrcweir return pDim;
925cdf0e10cSrcweir }
926cdf0e10cSrcweir return NULL;
927cdf0e10cSrcweir }
928cdf0e10cSrcweir
DuplicateDimension(const String & rName)929cdf0e10cSrcweir ScDPSaveDimension* ScDPSaveData::DuplicateDimension(const String& rName)
930cdf0e10cSrcweir {
931cdf0e10cSrcweir // always insert new
932cdf0e10cSrcweir //! check if dimension is there?
933cdf0e10cSrcweir
934cdf0e10cSrcweir ScDPSaveDimension* pOld = GetDimensionByName( rName );
935cdf0e10cSrcweir ScDPSaveDimension* pNew = new ScDPSaveDimension( *pOld );
936cdf0e10cSrcweir pNew->SetDupFlag( sal_True );
937cdf0e10cSrcweir aDimList.Insert( pNew, LIST_APPEND );
938cdf0e10cSrcweir mbDimensionMembersBuilt = false; // BuildAllDimensionMembers only handles existing entries in aDimList
939cdf0e10cSrcweir return pNew;
940cdf0e10cSrcweir }
941cdf0e10cSrcweir
RemoveDimensionByName(const String & rName)942cdf0e10cSrcweir void ScDPSaveData::RemoveDimensionByName(const String& rName)
943cdf0e10cSrcweir {
944cdf0e10cSrcweir long nCount = aDimList.Count();
945cdf0e10cSrcweir for (long i=0; i<nCount; i++)
946cdf0e10cSrcweir {
947cdf0e10cSrcweir ScDPSaveDimension* pDim = (ScDPSaveDimension*)aDimList.GetObject(i);
948cdf0e10cSrcweir if ( pDim->GetName() == rName && !pDim->IsDataLayout() )
949cdf0e10cSrcweir {
950cdf0e10cSrcweir delete pDim;
951cdf0e10cSrcweir aDimList.Remove(i);
952cdf0e10cSrcweir break;
953cdf0e10cSrcweir }
954cdf0e10cSrcweir }
955cdf0e10cSrcweir }
956cdf0e10cSrcweir
DuplicateDimension(const ScDPSaveDimension & rDim)957cdf0e10cSrcweir ScDPSaveDimension& ScDPSaveData::DuplicateDimension( const ScDPSaveDimension& rDim )
958cdf0e10cSrcweir {
959cdf0e10cSrcweir ScDPSaveDimension* pNew = new ScDPSaveDimension( rDim );
960cdf0e10cSrcweir pNew->SetDupFlag( sal_True );
961cdf0e10cSrcweir aDimList.Insert( pNew, LIST_APPEND );
962cdf0e10cSrcweir mbDimensionMembersBuilt = false; // BuildAllDimensionMembers only handles existing entries in aDimList
963cdf0e10cSrcweir return *pNew;
964cdf0e10cSrcweir }
965cdf0e10cSrcweir
GetInnermostDimension(sal_uInt16 nOrientation)966cdf0e10cSrcweir ScDPSaveDimension* ScDPSaveData::GetInnermostDimension(sal_uInt16 nOrientation)
967cdf0e10cSrcweir {
968cdf0e10cSrcweir // return the innermost dimension for the given orientation,
969cdf0e10cSrcweir // excluding data layout dimension
970cdf0e10cSrcweir
971cdf0e10cSrcweir ScDPSaveDimension* pInner = NULL;
972cdf0e10cSrcweir long nCount = aDimList.Count();
973cdf0e10cSrcweir for (long i=0; i<nCount; i++)
974cdf0e10cSrcweir {
975cdf0e10cSrcweir ScDPSaveDimension* pDim = static_cast<ScDPSaveDimension*>(aDimList.GetObject(i));
976cdf0e10cSrcweir if ( pDim->GetOrientation() == nOrientation && !pDim->IsDataLayout() )
977cdf0e10cSrcweir pInner = pDim;
978cdf0e10cSrcweir }
979cdf0e10cSrcweir return pInner; // the last matching one
980cdf0e10cSrcweir }
981cdf0e10cSrcweir
GetFirstDimension(sheet::DataPilotFieldOrientation eOrientation)982cdf0e10cSrcweir ScDPSaveDimension* ScDPSaveData::GetFirstDimension(sheet::DataPilotFieldOrientation eOrientation)
983cdf0e10cSrcweir {
984cdf0e10cSrcweir long nCount = aDimList.Count();
985cdf0e10cSrcweir for (long i = 0; i < nCount; ++i)
986cdf0e10cSrcweir {
987cdf0e10cSrcweir ScDPSaveDimension* pDim = static_cast<ScDPSaveDimension*>(aDimList.GetObject(i));
988cdf0e10cSrcweir if (pDim->GetOrientation() == eOrientation && !pDim->IsDataLayout())
989cdf0e10cSrcweir return pDim;
990cdf0e10cSrcweir }
991cdf0e10cSrcweir return NULL;
992cdf0e10cSrcweir }
993cdf0e10cSrcweir
GetDataDimensionCount() const994cdf0e10cSrcweir long ScDPSaveData::GetDataDimensionCount() const
995cdf0e10cSrcweir {
996cdf0e10cSrcweir long nDataCount = 0;
997cdf0e10cSrcweir
998cdf0e10cSrcweir long nCount = aDimList.Count();
999cdf0e10cSrcweir for (long i=0; i<nCount; i++)
1000cdf0e10cSrcweir {
1001cdf0e10cSrcweir const ScDPSaveDimension* pDim = static_cast<const ScDPSaveDimension*>(aDimList.GetObject(i));
1002cdf0e10cSrcweir if ( pDim->GetOrientation() == sheet::DataPilotFieldOrientation_DATA )
1003cdf0e10cSrcweir ++nDataCount;
1004cdf0e10cSrcweir }
1005cdf0e10cSrcweir
1006cdf0e10cSrcweir return nDataCount;
1007cdf0e10cSrcweir }
1008cdf0e10cSrcweir
SetPosition(ScDPSaveDimension * pDim,long nNew)1009cdf0e10cSrcweir void ScDPSaveData::SetPosition( ScDPSaveDimension* pDim, long nNew )
1010cdf0e10cSrcweir {
1011cdf0e10cSrcweir // position (nNew) is counted within dimensions of the same orientation
1012cdf0e10cSrcweir
1013cdf0e10cSrcweir sal_uInt16 nOrient = pDim->GetOrientation();
1014cdf0e10cSrcweir
1015cdf0e10cSrcweir aDimList.Remove( pDim );
1016cdf0e10cSrcweir sal_uLong nCount = aDimList.Count(); // after remove
1017cdf0e10cSrcweir
1018cdf0e10cSrcweir sal_uLong nInsPos = 0;
1019cdf0e10cSrcweir while ( nNew > 0 && nInsPos < nCount )
1020cdf0e10cSrcweir {
1021cdf0e10cSrcweir if ( ((ScDPSaveDimension*)aDimList.GetObject(nInsPos))->GetOrientation() == nOrient )
1022cdf0e10cSrcweir --nNew;
1023cdf0e10cSrcweir ++nInsPos;
1024cdf0e10cSrcweir }
1025cdf0e10cSrcweir
1026cdf0e10cSrcweir aDimList.Insert( pDim, nInsPos );
1027cdf0e10cSrcweir }
1028cdf0e10cSrcweir
SetColumnGrand(sal_Bool bSet)1029cdf0e10cSrcweir void ScDPSaveData::SetColumnGrand(sal_Bool bSet)
1030cdf0e10cSrcweir {
1031cdf0e10cSrcweir nColumnGrandMode = bSet;
1032cdf0e10cSrcweir }
1033cdf0e10cSrcweir
SetRowGrand(sal_Bool bSet)1034cdf0e10cSrcweir void ScDPSaveData::SetRowGrand(sal_Bool bSet)
1035cdf0e10cSrcweir {
1036cdf0e10cSrcweir nRowGrandMode = bSet;
1037cdf0e10cSrcweir }
1038cdf0e10cSrcweir
SetIgnoreEmptyRows(sal_Bool bSet)1039cdf0e10cSrcweir void ScDPSaveData::SetIgnoreEmptyRows(sal_Bool bSet)
1040cdf0e10cSrcweir {
1041cdf0e10cSrcweir nIgnoreEmptyMode = bSet;
1042cdf0e10cSrcweir }
1043cdf0e10cSrcweir
SetRepeatIfEmpty(sal_Bool bSet)1044cdf0e10cSrcweir void ScDPSaveData::SetRepeatIfEmpty(sal_Bool bSet)
1045cdf0e10cSrcweir {
1046cdf0e10cSrcweir nRepeatEmptyMode = bSet;
1047cdf0e10cSrcweir }
1048cdf0e10cSrcweir
SetFilterButton(sal_Bool bSet)1049cdf0e10cSrcweir void ScDPSaveData::SetFilterButton(sal_Bool bSet)
1050cdf0e10cSrcweir {
1051cdf0e10cSrcweir bFilterButton = bSet;
1052cdf0e10cSrcweir }
1053cdf0e10cSrcweir
SetDrillDown(sal_Bool bSet)1054cdf0e10cSrcweir void ScDPSaveData::SetDrillDown(sal_Bool bSet)
1055cdf0e10cSrcweir {
1056cdf0e10cSrcweir bDrillDown = bSet;
1057cdf0e10cSrcweir }
1058cdf0e10cSrcweir
lcl_ResetOrient(const uno::Reference<sheet::XDimensionsSupplier> & xSource)1059cdf0e10cSrcweir void lcl_ResetOrient( const uno::Reference<sheet::XDimensionsSupplier>& xSource )
1060cdf0e10cSrcweir {
1061cdf0e10cSrcweir sheet::DataPilotFieldOrientation eOrient = sheet::DataPilotFieldOrientation_HIDDEN;
1062cdf0e10cSrcweir
1063cdf0e10cSrcweir uno::Reference<container::XNameAccess> xDimsName = xSource->getDimensions();
1064cdf0e10cSrcweir uno::Reference<container::XIndexAccess> xIntDims = new ScNameToIndexAccess( xDimsName );
1065cdf0e10cSrcweir long nIntCount = xIntDims->getCount();
1066cdf0e10cSrcweir for (long nIntDim=0; nIntDim<nIntCount; nIntDim++)
1067cdf0e10cSrcweir {
1068cdf0e10cSrcweir uno::Reference<uno::XInterface> xIntDim = ScUnoHelpFunctions::AnyToInterface( xIntDims->getByIndex(nIntDim) );
1069cdf0e10cSrcweir uno::Reference<beans::XPropertySet> xDimProp( xIntDim, uno::UNO_QUERY );
1070cdf0e10cSrcweir if (xDimProp.is())
1071cdf0e10cSrcweir {
1072cdf0e10cSrcweir uno::Any aAny;
1073cdf0e10cSrcweir aAny <<= eOrient;
1074cdf0e10cSrcweir xDimProp->setPropertyValue( rtl::OUString::createFromAscii(DP_PROP_ORIENTATION), aAny );
1075cdf0e10cSrcweir }
1076cdf0e10cSrcweir }
1077cdf0e10cSrcweir }
1078cdf0e10cSrcweir
WriteToSource(const uno::Reference<sheet::XDimensionsSupplier> & xSource)1079cdf0e10cSrcweir void ScDPSaveData::WriteToSource( const uno::Reference<sheet::XDimensionsSupplier>& xSource )
1080cdf0e10cSrcweir {
1081cdf0e10cSrcweir if (!xSource.is())
1082cdf0e10cSrcweir return;
1083cdf0e10cSrcweir
1084cdf0e10cSrcweir // source options must be first!
1085cdf0e10cSrcweir
1086cdf0e10cSrcweir uno::Reference<beans::XPropertySet> xSourceProp( xSource, uno::UNO_QUERY );
1087cdf0e10cSrcweir DBG_ASSERT( xSourceProp.is(), "no properties at source" );
1088cdf0e10cSrcweir if ( xSourceProp.is() )
1089cdf0e10cSrcweir {
1090cdf0e10cSrcweir // source options are not available for external sources
1091cdf0e10cSrcweir //! use XPropertySetInfo to test for availability?
1092cdf0e10cSrcweir
1093cdf0e10cSrcweir try
1094cdf0e10cSrcweir {
1095cdf0e10cSrcweir if ( nIgnoreEmptyMode != SC_DPSAVEMODE_DONTKNOW )
1096cdf0e10cSrcweir lcl_SetBoolProperty( xSourceProp,
1097cdf0e10cSrcweir rtl::OUString::createFromAscii(DP_PROP_IGNOREEMPTY), (sal_Bool)nIgnoreEmptyMode );
1098cdf0e10cSrcweir if ( nRepeatEmptyMode != SC_DPSAVEMODE_DONTKNOW )
1099cdf0e10cSrcweir lcl_SetBoolProperty( xSourceProp,
1100cdf0e10cSrcweir rtl::OUString::createFromAscii(DP_PROP_REPEATIFEMPTY), (sal_Bool)nRepeatEmptyMode );
1101cdf0e10cSrcweir }
1102cdf0e10cSrcweir catch(uno::Exception&)
1103cdf0e10cSrcweir {
1104cdf0e10cSrcweir // no error
1105cdf0e10cSrcweir }
1106cdf0e10cSrcweir
1107cdf0e10cSrcweir const OUString* pGrandTotalName = GetGrandTotalName();
1108cdf0e10cSrcweir if (pGrandTotalName)
1109cdf0e10cSrcweir ScUnoHelpFunctions::SetOptionalPropertyValue(xSourceProp, SC_UNO_GRANDTOTAL_NAME, *pGrandTotalName);
1110cdf0e10cSrcweir }
1111cdf0e10cSrcweir
1112cdf0e10cSrcweir // exceptions in the other calls are errors
1113cdf0e10cSrcweir try
1114cdf0e10cSrcweir {
1115cdf0e10cSrcweir // reset all orientations
1116cdf0e10cSrcweir //! "forgetSettings" or similar at source ?????
1117cdf0e10cSrcweir //! reset all duplicated dimensions, or reuse them below !!!
1118cdf0e10cSrcweir DBG_TRACE( "ScDPSaveData::WriteToSource" );
1119cdf0e10cSrcweir
1120cdf0e10cSrcweir lcl_ResetOrient( xSource );
1121cdf0e10cSrcweir
1122cdf0e10cSrcweir long nCount = aDimList.Count();
1123cdf0e10cSrcweir for (long i=0; i<nCount; i++)
1124cdf0e10cSrcweir {
1125cdf0e10cSrcweir ScDPSaveDimension* pDim = (ScDPSaveDimension*)aDimList.GetObject(i);
1126cdf0e10cSrcweir rtl::OUString aName = pDim->GetName();
1127cdf0e10cSrcweir
1128cdf0e10cSrcweir DBG_TRACESTR(pDim->GetName());
1129cdf0e10cSrcweir
1130cdf0e10cSrcweir sal_Bool bData = pDim->IsDataLayout();
1131cdf0e10cSrcweir
1132cdf0e10cSrcweir //! getByName for ScDPSource, including DataLayoutDimension !!!!!!!!
1133cdf0e10cSrcweir
1134cdf0e10cSrcweir uno::Reference<container::XNameAccess> xDimsName = xSource->getDimensions();
1135cdf0e10cSrcweir uno::Reference<container::XIndexAccess> xIntDims = new ScNameToIndexAccess( xDimsName );
1136cdf0e10cSrcweir long nIntCount = xIntDims->getCount();
1137cdf0e10cSrcweir sal_Bool bFound = sal_False;
1138cdf0e10cSrcweir for (long nIntDim=0; nIntDim<nIntCount && !bFound; nIntDim++)
1139cdf0e10cSrcweir {
1140cdf0e10cSrcweir uno::Reference<uno::XInterface> xIntDim = ScUnoHelpFunctions::AnyToInterface( xIntDims->getByIndex(nIntDim) );
1141cdf0e10cSrcweir if ( bData )
1142cdf0e10cSrcweir {
1143cdf0e10cSrcweir uno::Reference<beans::XPropertySet> xDimProp( xIntDim, uno::UNO_QUERY );
1144cdf0e10cSrcweir if ( xDimProp.is() )
1145cdf0e10cSrcweir {
1146cdf0e10cSrcweir bFound = ScUnoHelpFunctions::GetBoolProperty( xDimProp,
1147cdf0e10cSrcweir rtl::OUString::createFromAscii(DP_PROP_ISDATALAYOUT) );
1148cdf0e10cSrcweir //! error checking -- is "IsDataLayoutDimension" property required??
1149cdf0e10cSrcweir }
1150cdf0e10cSrcweir }
1151cdf0e10cSrcweir else
1152cdf0e10cSrcweir {
1153cdf0e10cSrcweir uno::Reference<container::XNamed> xDimName( xIntDim, uno::UNO_QUERY );
1154cdf0e10cSrcweir if ( xDimName.is() && xDimName->getName() == aName )
1155cdf0e10cSrcweir bFound = sal_True;
1156cdf0e10cSrcweir }
1157cdf0e10cSrcweir
1158cdf0e10cSrcweir if ( bFound )
1159cdf0e10cSrcweir {
1160cdf0e10cSrcweir if ( pDim->GetDupFlag() )
1161cdf0e10cSrcweir {
1162cdf0e10cSrcweir String aNewName = pDim->GetName();
1163cdf0e10cSrcweir
1164cdf0e10cSrcweir // different name for each duplication of a (real) dimension...
1165cdf0e10cSrcweir for (long j=0; j<=i; j++) //! Test !!!!!!
1166cdf0e10cSrcweir aNewName += '*'; //! modify name at creation of SaveDimension
1167cdf0e10cSrcweir
1168cdf0e10cSrcweir uno::Reference<util::XCloneable> xCloneable( xIntDim, uno::UNO_QUERY );
1169cdf0e10cSrcweir DBG_ASSERT( xCloneable.is(), "cannot clone dimension" );
1170cdf0e10cSrcweir if (xCloneable.is())
1171cdf0e10cSrcweir {
1172cdf0e10cSrcweir uno::Reference<util::XCloneable> xNew = xCloneable->createClone();
1173cdf0e10cSrcweir uno::Reference<container::XNamed> xNewName( xNew, uno::UNO_QUERY );
1174cdf0e10cSrcweir if (xNewName.is())
1175cdf0e10cSrcweir {
1176cdf0e10cSrcweir xNewName->setName( aNewName );
1177cdf0e10cSrcweir pDim->WriteToSource( xNew );
1178cdf0e10cSrcweir }
1179cdf0e10cSrcweir }
1180cdf0e10cSrcweir }
1181cdf0e10cSrcweir else
1182cdf0e10cSrcweir pDim->WriteToSource( xIntDim );
1183cdf0e10cSrcweir }
1184cdf0e10cSrcweir }
1185cdf0e10cSrcweir DBG_ASSERT(bFound, "WriteToSource: Dimension not found");
1186cdf0e10cSrcweir }
1187cdf0e10cSrcweir
1188cdf0e10cSrcweir if ( xSourceProp.is() )
1189cdf0e10cSrcweir {
1190cdf0e10cSrcweir if ( nColumnGrandMode != SC_DPSAVEMODE_DONTKNOW )
1191cdf0e10cSrcweir lcl_SetBoolProperty( xSourceProp,
1192cdf0e10cSrcweir rtl::OUString::createFromAscii(DP_PROP_COLUMNGRAND), (sal_Bool)nColumnGrandMode );
1193cdf0e10cSrcweir if ( nRowGrandMode != SC_DPSAVEMODE_DONTKNOW )
1194cdf0e10cSrcweir lcl_SetBoolProperty( xSourceProp,
1195cdf0e10cSrcweir rtl::OUString::createFromAscii(DP_PROP_ROWGRAND), (sal_Bool)nRowGrandMode );
1196cdf0e10cSrcweir }
1197cdf0e10cSrcweir }
1198cdf0e10cSrcweir catch(uno::Exception&)
1199cdf0e10cSrcweir {
1200cdf0e10cSrcweir DBG_ERROR("exception in WriteToSource");
1201cdf0e10cSrcweir }
1202cdf0e10cSrcweir }
1203cdf0e10cSrcweir
IsEmpty() const1204cdf0e10cSrcweir sal_Bool ScDPSaveData::IsEmpty() const
1205cdf0e10cSrcweir {
1206cdf0e10cSrcweir long nCount = aDimList.Count();
1207cdf0e10cSrcweir for (long i=0; i<nCount; i++)
1208cdf0e10cSrcweir {
1209cdf0e10cSrcweir ScDPSaveDimension* pDim = (ScDPSaveDimension*)aDimList.GetObject(i);
1210cdf0e10cSrcweir if ( pDim->GetOrientation() != sheet::DataPilotFieldOrientation_HIDDEN && !pDim->IsDataLayout() )
1211cdf0e10cSrcweir return sal_False;
1212cdf0e10cSrcweir }
1213cdf0e10cSrcweir return sal_True; // no entries that are not hidden
1214cdf0e10cSrcweir }
1215cdf0e10cSrcweir
GetDimensionData()1216cdf0e10cSrcweir ScDPDimensionSaveData* ScDPSaveData::GetDimensionData()
1217cdf0e10cSrcweir {
1218cdf0e10cSrcweir if (!pDimensionData)
1219cdf0e10cSrcweir pDimensionData = new ScDPDimensionSaveData;
1220cdf0e10cSrcweir return pDimensionData;
1221cdf0e10cSrcweir }
1222cdf0e10cSrcweir
SetDimensionData(const ScDPDimensionSaveData * pNew)1223cdf0e10cSrcweir void ScDPSaveData::SetDimensionData( const ScDPDimensionSaveData* pNew )
1224cdf0e10cSrcweir {
1225cdf0e10cSrcweir delete pDimensionData;
1226cdf0e10cSrcweir if ( pNew )
1227cdf0e10cSrcweir pDimensionData = new ScDPDimensionSaveData( *pNew );
1228cdf0e10cSrcweir else
1229cdf0e10cSrcweir pDimensionData = NULL;
1230cdf0e10cSrcweir }
1231cdf0e10cSrcweir
BuildAllDimensionMembers(ScDPTableData * pData)1232cdf0e10cSrcweir void ScDPSaveData::BuildAllDimensionMembers(ScDPTableData* pData)
1233cdf0e10cSrcweir {
1234cdf0e10cSrcweir if (mbDimensionMembersBuilt)
1235cdf0e10cSrcweir return;
1236cdf0e10cSrcweir
1237cdf0e10cSrcweir // First, build a dimension name-to-index map.
1238cdf0e10cSrcweir typedef hash_map<OUString, long, ::rtl::OUStringHash> NameIndexMap;
1239cdf0e10cSrcweir NameIndexMap aMap;
1240cdf0e10cSrcweir long nColCount = pData->GetColumnCount();
1241cdf0e10cSrcweir for (long i = 0; i < nColCount; ++i)
1242cdf0e10cSrcweir aMap.insert( NameIndexMap::value_type(pData->getDimensionName(i), i));
1243cdf0e10cSrcweir
1244cdf0e10cSrcweir NameIndexMap::const_iterator itrEnd = aMap.end();
1245cdf0e10cSrcweir
1246cdf0e10cSrcweir sal_uInt32 n = aDimList.Count();
1247cdf0e10cSrcweir for (sal_uInt32 i = 0; i < n; ++i)
1248cdf0e10cSrcweir {
1249cdf0e10cSrcweir ScDPSaveDimension* pDim = static_cast<ScDPSaveDimension*>(aDimList.GetObject(i));
1250cdf0e10cSrcweir const String& rDimName = pDim->GetName();
1251cdf0e10cSrcweir if (!rDimName.Len())
1252cdf0e10cSrcweir // empty dimension name. It must be data layout.
1253cdf0e10cSrcweir continue;
1254cdf0e10cSrcweir
1255cdf0e10cSrcweir NameIndexMap::const_iterator itr = aMap.find(rDimName);
1256cdf0e10cSrcweir if (itr == itrEnd)
1257cdf0e10cSrcweir // dimension name not in the data. This should never happen!
1258cdf0e10cSrcweir continue;
1259cdf0e10cSrcweir
1260cdf0e10cSrcweir long nDimIndex = itr->second;
1261cdf0e10cSrcweir const std::vector<SCROW>& rMembers = pData->GetColumnEntries(nDimIndex);
1262cdf0e10cSrcweir size_t mMemberCount = rMembers.size();
1263cdf0e10cSrcweir for (size_t j = 0; j < mMemberCount; ++j)
1264cdf0e10cSrcweir {
1265cdf0e10cSrcweir const ScDPItemData* pMemberData = pData->GetMemberById( nDimIndex, rMembers[j] );
1266cdf0e10cSrcweir String aMemName = pMemberData->GetString();
1267cdf0e10cSrcweir if (pDim->GetExistingMemberByName(aMemName))
1268cdf0e10cSrcweir // this member instance already exists. nothing to do.
1269cdf0e10cSrcweir continue;
1270cdf0e10cSrcweir
1271cdf0e10cSrcweir auto_ptr<ScDPSaveMember> pNewMember(new ScDPSaveMember(aMemName));
1272cdf0e10cSrcweir pNewMember->SetIsVisible(true);
1273cdf0e10cSrcweir pDim->AddMember(pNewMember.release());
1274cdf0e10cSrcweir }
1275cdf0e10cSrcweir }
1276cdf0e10cSrcweir
1277cdf0e10cSrcweir mbDimensionMembersBuilt = true;
1278cdf0e10cSrcweir }
1279cdf0e10cSrcweir
BuildAllDimensionMembersFromSource(ScDPObject * pDPObj)1280cdf0e10cSrcweir void ScDPSaveData::BuildAllDimensionMembersFromSource( ScDPObject* pDPObj )
1281cdf0e10cSrcweir {
1282cdf0e10cSrcweir // Initialize all members like BuildAllDimensionMembers, but access only the DataPilotSource, not the table data.
1283cdf0e10cSrcweir // This could also replace BuildAllDimensionMembers, but the performance implications still have to be checked.
1284cdf0e10cSrcweir // ScDPObject is used for the helper method GetMemberNames.
1285cdf0e10cSrcweir
1286cdf0e10cSrcweir if (mbDimensionMembersBuilt)
1287cdf0e10cSrcweir return;
1288cdf0e10cSrcweir
1289cdf0e10cSrcweir uno::Reference<sheet::XDimensionsSupplier> xSource = pDPObj->GetSource();
1290cdf0e10cSrcweir uno::Reference<container::XNameAccess> xDimsName = xSource->getDimensions();
1291cdf0e10cSrcweir // GetMemberNames uses the dimension index from getElementNames
1292cdf0e10cSrcweir uno::Sequence<OUString> aDimNames = xDimsName->getElementNames();
1293cdf0e10cSrcweir
1294cdf0e10cSrcweir // First, build a dimension name-to-index map.
1295cdf0e10cSrcweir typedef hash_map<OUString, long, ::rtl::OUStringHash> NameIndexMap;
1296cdf0e10cSrcweir NameIndexMap aMap;
1297cdf0e10cSrcweir long nColCount = aDimNames.getLength();
1298cdf0e10cSrcweir for (long i = 0; i < nColCount; ++i)
1299cdf0e10cSrcweir aMap.insert( NameIndexMap::value_type(aDimNames[i], i) );
1300cdf0e10cSrcweir
1301cdf0e10cSrcweir NameIndexMap::const_iterator itrEnd = aMap.end();
1302cdf0e10cSrcweir
1303cdf0e10cSrcweir sal_uInt32 n = aDimList.Count();
1304cdf0e10cSrcweir for (sal_uInt32 i = 0; i < n; ++i)
1305cdf0e10cSrcweir {
1306cdf0e10cSrcweir ScDPSaveDimension* pDim = static_cast<ScDPSaveDimension*>(aDimList.GetObject(i));
1307cdf0e10cSrcweir const String& rDimName = pDim->GetName();
1308cdf0e10cSrcweir if (!rDimName.Len())
1309cdf0e10cSrcweir // empty dimension name. It must be data layout.
1310cdf0e10cSrcweir continue;
1311cdf0e10cSrcweir
1312cdf0e10cSrcweir NameIndexMap::const_iterator itr = aMap.find(rDimName);
1313cdf0e10cSrcweir if (itr == itrEnd)
1314cdf0e10cSrcweir // dimension name not in the data. This should never happen!
1315cdf0e10cSrcweir continue;
1316cdf0e10cSrcweir
1317cdf0e10cSrcweir long nDimIndex = itr->second;
1318cdf0e10cSrcweir uno::Sequence<OUString> aMemberNames;
1319cdf0e10cSrcweir pDPObj->GetMemberNames( nDimIndex, aMemberNames );
1320cdf0e10cSrcweir sal_Int32 nMemberCount = aMemberNames.getLength();
1321cdf0e10cSrcweir for (sal_Int32 j = 0; j < nMemberCount; ++j)
1322cdf0e10cSrcweir {
1323cdf0e10cSrcweir String aMemName = aMemberNames[j];
1324cdf0e10cSrcweir if (pDim->GetExistingMemberByName(aMemName))
1325cdf0e10cSrcweir // this member instance already exists. nothing to do.
1326cdf0e10cSrcweir continue;
1327cdf0e10cSrcweir
1328cdf0e10cSrcweir auto_ptr<ScDPSaveMember> pNewMember(new ScDPSaveMember(aMemName));
1329cdf0e10cSrcweir pNewMember->SetIsVisible(true);
1330cdf0e10cSrcweir pDim->AddMember(pNewMember.release());
1331cdf0e10cSrcweir }
1332cdf0e10cSrcweir }
1333cdf0e10cSrcweir
1334cdf0e10cSrcweir mbDimensionMembersBuilt = true;
1335cdf0e10cSrcweir }
1336cdf0e10cSrcweir
HasInvisibleMember(const OUString & rDimName) const1337cdf0e10cSrcweir bool ScDPSaveData::HasInvisibleMember(const OUString& rDimName) const
1338cdf0e10cSrcweir {
1339cdf0e10cSrcweir ScDPSaveDimension* pDim = GetExistingDimensionByName(rDimName);
1340cdf0e10cSrcweir if (!pDim)
1341cdf0e10cSrcweir return false;
1342cdf0e10cSrcweir
1343cdf0e10cSrcweir return pDim->HasInvisibleMember();
1344cdf0e10cSrcweir }
1345cdf0e10cSrcweir
Refresh(const uno::Reference<sheet::XDimensionsSupplier> & xSource)1346cdf0e10cSrcweir void ScDPSaveData::Refresh( const uno::Reference<sheet::XDimensionsSupplier>& xSource )
1347cdf0e10cSrcweir {
1348cdf0e10cSrcweir try
1349cdf0e10cSrcweir {
1350cdf0e10cSrcweir long nCount = aDimList.Count();
1351cdf0e10cSrcweir std::list<String> deletedDims;
1352cdf0e10cSrcweir for (long i=nCount-1; i >=0 ; i--)
1353cdf0e10cSrcweir {
1354cdf0e10cSrcweir ScDPSaveDimension* pDim = (ScDPSaveDimension*)aDimList.GetObject(i);
1355cdf0e10cSrcweir
1356cdf0e10cSrcweir rtl::OUString aName = pDim->GetName();
1357cdf0e10cSrcweir if ( pDim->IsDataLayout() )
1358cdf0e10cSrcweir continue;
1359cdf0e10cSrcweir
1360cdf0e10cSrcweir uno::Reference<container::XNameAccess> xDimsName = xSource->getDimensions();
1361cdf0e10cSrcweir uno::Reference<container::XIndexAccess> xIntDims = new ScNameToIndexAccess( xDimsName );
1362cdf0e10cSrcweir long nIntCount = xIntDims->getCount();
1363cdf0e10cSrcweir sal_Bool bFound = sal_False;
1364cdf0e10cSrcweir for (long nIntDim=0; nIntDim<nIntCount && !bFound; nIntDim++)
1365cdf0e10cSrcweir {
1366cdf0e10cSrcweir uno::Reference<uno::XInterface> xIntDim = ScUnoHelpFunctions::AnyToInterface( xIntDims->getByIndex(nIntDim) );
1367cdf0e10cSrcweir uno::Reference<container::XNamed> xDimName( xIntDim, uno::UNO_QUERY );
1368cdf0e10cSrcweir if ( xDimName.is() && xDimName->getName() == aName )
1369cdf0e10cSrcweir bFound = sal_True;
1370cdf0e10cSrcweir }
1371cdf0e10cSrcweir if ( !bFound )
1372cdf0e10cSrcweir {
1373cdf0e10cSrcweir deletedDims.push_back( aName );
1374cdf0e10cSrcweir aDimList.Remove(i);
1375cdf0e10cSrcweir DBG_TRACE( "\n Remove dim: \t" );
1376cdf0e10cSrcweir DBG_TRACESTR( String( aName ) );
1377cdf0e10cSrcweir }
1378cdf0e10cSrcweir
1379cdf0e10cSrcweir }
1380cdf0e10cSrcweir
1381cdf0e10cSrcweir nCount = aDimList.Count();
1382cdf0e10cSrcweir for (long i=nCount-1; i >=0 ; i--) //check every dimension ??
1383cdf0e10cSrcweir {
1384cdf0e10cSrcweir ScDPSaveDimension* pDim = (ScDPSaveDimension*)aDimList.GetObject(i);
1385cdf0e10cSrcweir
1386cdf0e10cSrcweir rtl::OUString aName = pDim->GetName();
1387cdf0e10cSrcweir if ( pDim->IsDataLayout() )
1388cdf0e10cSrcweir continue;
1389cdf0e10cSrcweir pDim->Refresh( xSource, deletedDims );
1390cdf0e10cSrcweir
1391cdf0e10cSrcweir }
1392cdf0e10cSrcweir
1393cdf0e10cSrcweir mbDimensionMembersBuilt = false; // there may be new members
1394cdf0e10cSrcweir }
1395cdf0e10cSrcweir catch(uno::Exception&)
1396cdf0e10cSrcweir {
1397cdf0e10cSrcweir DBG_ERROR("error in ScDPSaveData::Refresh");
1398cdf0e10cSrcweir }
1399cdf0e10cSrcweir
1400cdf0e10cSrcweir }
Refresh(const com::sun::star::uno::Reference<com::sun::star::sheet::XDimensionsSupplier> & xSource,const std::list<String> & deletedDims)1401cdf0e10cSrcweir void ScDPSaveDimension::Refresh( const com::sun::star::uno::Reference<
1402cdf0e10cSrcweir com::sun::star::sheet::XDimensionsSupplier>& xSource ,
1403cdf0e10cSrcweir const std::list<String>& deletedDims)
1404cdf0e10cSrcweir {
1405cdf0e10cSrcweir if ( xSource.is() )
1406cdf0e10cSrcweir {
1407cdf0e10cSrcweir ScDPSource* pTabSource = static_cast<ScDPSource*>( xSource.get() );
1408cdf0e10cSrcweir ScDPTableDataCache* pCache = pTabSource->GetCache();
1409cdf0e10cSrcweir if ( pCache->GetId() == -1 )
1410cdf0e10cSrcweir return;
1411cdf0e10cSrcweir
1412cdf0e10cSrcweir SCCOL nSrcDim = pCache->GetDimensionIndex( GetName() );
1413cdf0e10cSrcweir
1414cdf0e10cSrcweir if ( nSrcDim == -1 )
1415cdf0e10cSrcweir return;
1416cdf0e10cSrcweir if ( pSelectedPage )
1417cdf0e10cSrcweir {//check pSelected page
1418cdf0e10cSrcweir DBG_TRACESTR( (*pSelectedPage) );
1419cdf0e10cSrcweir if ( pCache->GetIdByItemData( nSrcDim, *pSelectedPage ) == -1 )
1420cdf0e10cSrcweir {
1421cdf0e10cSrcweir delete pSelectedPage;
1422cdf0e10cSrcweir pSelectedPage = NULL;
1423cdf0e10cSrcweir }
1424cdf0e10cSrcweir
1425cdf0e10cSrcweir };
1426cdf0e10cSrcweir
1427cdf0e10cSrcweir if ( pReferenceValue && pReferenceValue->ReferenceItemType == DataPilotFieldReferenceItemType::NAMED )
1428cdf0e10cSrcweir {//check pReferenceValue
1429cdf0e10cSrcweir #ifdef DEBUG
1430cdf0e10cSrcweir switch( pReferenceValue->ReferenceType)
1431cdf0e10cSrcweir {
1432cdf0e10cSrcweir case sheet::DataPilotFieldReferenceType::ITEM_PERCENTAGE: //both
1433cdf0e10cSrcweir DBG_TRACE( "\n sheet::DataPilotFieldReferenceType::ITEM_PERCENTAGE \n" );
1434cdf0e10cSrcweir break;
1435cdf0e10cSrcweir case sheet::DataPilotFieldReferenceType::ITEM_DIFFERENCE: //both
1436cdf0e10cSrcweir DBG_TRACE( "\n sheet::DataPilotFieldReferenceType::ITEM_DIFFERENCE \n" );
1437cdf0e10cSrcweir break;
1438cdf0e10cSrcweir case sheet::DataPilotFieldReferenceType::ITEM_PERCENTAGE_DIFFERENCE: //both
1439cdf0e10cSrcweir DBG_TRACE( "\n sheet::DataPilotFieldReferenceType::ITEM_PERCENTAGE_DIFFERENCE \n" );
1440cdf0e10cSrcweir break;
1441cdf0e10cSrcweir case sheet::DataPilotFieldReferenceType::RUNNING_TOTAL:
1442cdf0e10cSrcweir DBG_TRACE( "\n sheet::DataPilotFieldReferenceType::RUNNING_TOTAL \n" ); //enable name
1443cdf0e10cSrcweir break;
1444cdf0e10cSrcweir }
1445cdf0e10cSrcweir #endif
1446cdf0e10cSrcweir switch( pReferenceValue->ReferenceType)
1447cdf0e10cSrcweir {
1448cdf0e10cSrcweir case sheet::DataPilotFieldReferenceType::ITEM_PERCENTAGE:
1449cdf0e10cSrcweir case sheet::DataPilotFieldReferenceType::ITEM_DIFFERENCE:
1450cdf0e10cSrcweir case sheet::DataPilotFieldReferenceType::ITEM_PERCENTAGE_DIFFERENCE:
1451cdf0e10cSrcweir case sheet::DataPilotFieldReferenceType::RUNNING_TOTAL:
1452cdf0e10cSrcweir {
1453cdf0e10cSrcweir if( pReferenceValue->ReferenceItemType == DataPilotFieldReferenceItemType::NAMED )
1454cdf0e10cSrcweir {
1455cdf0e10cSrcweir const String& sReferenceFieldName = pReferenceValue->ReferenceField;
1456cdf0e10cSrcweir DBG_TRACESTR( sReferenceFieldName );
1457cdf0e10cSrcweir SCCOL nRefDim = pCache->GetDimensionIndex( sReferenceFieldName );
1458cdf0e10cSrcweir bool bValid = true;
1459cdf0e10cSrcweir if ( nRefDim == -1 )
1460cdf0e10cSrcweir bValid = false;
1461cdf0e10cSrcweir else if ( pReferenceValue->ReferenceType != sheet::DataPilotFieldReferenceType::RUNNING_TOTAL )
1462cdf0e10cSrcweir { //running total has not reference item
1463cdf0e10cSrcweir const String& sReferenceItemName = pReferenceValue->ReferenceItemName;
1464cdf0e10cSrcweir DBG_TRACESTR( sReferenceItemName );
1465cdf0e10cSrcweir if ( pCache->GetIdByItemData( nRefDim, sReferenceItemName ) == -1 )
1466cdf0e10cSrcweir bValid = false;
1467cdf0e10cSrcweir }
1468cdf0e10cSrcweir if ( !bValid )
1469cdf0e10cSrcweir {
1470cdf0e10cSrcweir delete pReferenceValue;
1471cdf0e10cSrcweir pReferenceValue = NULL;
1472cdf0e10cSrcweir }
1473cdf0e10cSrcweir }
1474cdf0e10cSrcweir }
1475cdf0e10cSrcweir break;
1476cdf0e10cSrcweir }
1477cdf0e10cSrcweir
1478cdf0e10cSrcweir };
1479cdf0e10cSrcweir
1480cdf0e10cSrcweir if ( pSortInfo )
1481cdf0e10cSrcweir { //check sortinfo
1482cdf0e10cSrcweir if ( pSortInfo->Mode == DataPilotFieldSortMode::DATA )
1483cdf0e10cSrcweir {
1484cdf0e10cSrcweir DBG_TRACE( "\n DataPilotFieldSortMode::DATA \n" );
1485cdf0e10cSrcweir const String& sFieldDimName = pSortInfo->Field;
1486cdf0e10cSrcweir std::list<String>::const_iterator iter = std::find( deletedDims.begin(), deletedDims.end(), sFieldDimName );
1487cdf0e10cSrcweir if ( iter != deletedDims.end() && pCache->GetDimensionIndex( sFieldDimName ) == -1 )
1488cdf0e10cSrcweir {
1489cdf0e10cSrcweir pSortInfo->Mode = DataPilotFieldSortMode::MANUAL;
1490cdf0e10cSrcweir pSortInfo->Field = GetName();
1491cdf0e10cSrcweir }
1492cdf0e10cSrcweir }
1493cdf0e10cSrcweir
1494cdf0e10cSrcweir };
1495cdf0e10cSrcweir
1496cdf0e10cSrcweir if ( pAutoShowInfo )
1497cdf0e10cSrcweir { //check autoshow
1498cdf0e10cSrcweir const String& sFieldDimName = pAutoShowInfo->DataField;
1499cdf0e10cSrcweir std::list<String>::const_iterator iter = std::find( deletedDims.begin(), deletedDims.end(), sFieldDimName );
1500cdf0e10cSrcweir if ( iter != deletedDims.end() && pCache->GetDimensionIndex( sFieldDimName ) == -1 )
1501cdf0e10cSrcweir {
1502cdf0e10cSrcweir delete pAutoShowInfo;
1503cdf0e10cSrcweir pAutoShowInfo = NULL;
1504cdf0e10cSrcweir }
1505cdf0e10cSrcweir
1506cdf0e10cSrcweir };
1507cdf0e10cSrcweir
1508cdf0e10cSrcweir //remove unused members
1509cdf0e10cSrcweir for (MemberList::iterator i=maMemberList.begin(); i != maMemberList.end() ; )
1510cdf0e10cSrcweir {
1511cdf0e10cSrcweir rtl::OUString aMemberName = (*i)->GetName();
1512cdf0e10cSrcweir if ( pCache->GetIdByItemData( nSrcDim, aMemberName ) == -1 )
1513cdf0e10cSrcweir i = maMemberList.erase( i );
1514cdf0e10cSrcweir else
1515cdf0e10cSrcweir i++;
1516cdf0e10cSrcweir }
1517cdf0e10cSrcweir }
1518cdf0e10cSrcweir }
1519cdf0e10cSrcweir // End Comments
operator ==(const::com::sun::star::sheet::DataPilotFieldSortInfo & l,const::com::sun::star::sheet::DataPilotFieldSortInfo & r)1520cdf0e10cSrcweir bool operator == (const ::com::sun::star::sheet::DataPilotFieldSortInfo &l, const ::com::sun::star::sheet::DataPilotFieldSortInfo &r )
1521cdf0e10cSrcweir {
1522cdf0e10cSrcweir return l.Field == r.Field && l.IsAscending == r.IsAscending && l.Mode == r.Mode;
1523cdf0e10cSrcweir }
operator ==(const::com::sun::star::sheet::DataPilotFieldAutoShowInfo & l,const::com::sun::star::sheet::DataPilotFieldAutoShowInfo & r)1524cdf0e10cSrcweir bool operator == (const ::com::sun::star::sheet::DataPilotFieldAutoShowInfo &l, const ::com::sun::star::sheet::DataPilotFieldAutoShowInfo &r )
1525cdf0e10cSrcweir {
1526cdf0e10cSrcweir return l.IsEnabled == r.IsEnabled &&
1527cdf0e10cSrcweir l.ShowItemsMode == r.ShowItemsMode &&
1528cdf0e10cSrcweir l.ItemCount == r.ItemCount &&
1529cdf0e10cSrcweir l.DataField == r.DataField;
1530cdf0e10cSrcweir }
operator ==(const::com::sun::star::sheet::DataPilotFieldReference & l,const::com::sun::star::sheet::DataPilotFieldReference & r)1531cdf0e10cSrcweir bool operator == (const ::com::sun::star::sheet::DataPilotFieldReference &l, const ::com::sun::star::sheet::DataPilotFieldReference &r )
1532cdf0e10cSrcweir {
1533cdf0e10cSrcweir return l.ReferenceType == r.ReferenceType &&
1534cdf0e10cSrcweir l.ReferenceField == r.ReferenceField &&
1535cdf0e10cSrcweir l.ReferenceItemType == r.ReferenceItemType &&
1536cdf0e10cSrcweir l.ReferenceItemName == r.ReferenceItemName;
1537cdf0e10cSrcweir }
1538cdf0e10cSrcweir
1539