Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "dpsave.hxx"
30 : : #include "dpdimsave.hxx"
31 : : #include "miscuno.hxx"
32 : : #include "scerrors.hxx"
33 : : #include "unonames.hxx"
34 : : #include "global.hxx"
35 : : #include "dptabsrc.hxx"
36 : : #include "dputil.hxx"
37 : :
38 : : #include <sal/types.h>
39 : : #include "comphelper/string.hxx"
40 : :
41 : : #include <com/sun/star/sheet/GeneralFunction.hpp>
42 : : #include <com/sun/star/sheet/DataPilotFieldAutoShowInfo.hpp>
43 : : #include <com/sun/star/sheet/DataPilotFieldLayoutInfo.hpp>
44 : : #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
45 : : #include <com/sun/star/sheet/DataPilotFieldReference.hpp>
46 : : #include <com/sun/star/sheet/DataPilotFieldSortInfo.hpp>
47 : : #include <com/sun/star/sheet/DataPilotFieldSortMode.hpp>
48 : : #include <com/sun/star/sheet/TableFilterField.hpp>
49 : : #include <com/sun/star/sheet/XHierarchiesSupplier.hpp>
50 : : #include <com/sun/star/sheet/XLevelsSupplier.hpp>
51 : : #include <com/sun/star/sheet/XMembersSupplier.hpp>
52 : : #include <com/sun/star/container/XNamed.hpp>
53 : : #include <com/sun/star/util/XCloneable.hpp>
54 : :
55 : : #include <com/sun/star/sheet/DataPilotFieldReferenceType.hpp>
56 : : #include <com/sun/star/sheet/DataPilotFieldReferenceItemType.hpp>
57 : :
58 : : #include <boost/unordered_map.hpp>
59 : : #include <boost/unordered_set.hpp>
60 : :
61 : : using namespace com::sun::star;
62 : : using namespace com::sun::star::sheet;
63 : : using ::com::sun::star::uno::Reference;
64 : : using ::com::sun::star::uno::Any;
65 : : using ::rtl::OUString;
66 : : using ::rtl::OUStringBuffer;
67 : : using ::rtl::OUStringHash;
68 : : using ::std::auto_ptr;
69 : :
70 : : #define SC_DPSAVEMODE_NO 0
71 : : #define SC_DPSAVEMODE_YES 1
72 : : #define SC_DPSAVEMODE_DONTKNOW 2
73 : :
74 : 1677 : void lcl_SetBoolProperty( const uno::Reference<beans::XPropertySet>& xProp,
75 : : const rtl::OUString& rName, sal_Bool bValue )
76 : : {
77 : : //! move to ScUnoHelpFunctions?
78 : :
79 [ + - ]: 1677 : xProp->setPropertyValue( rName, uno::Any( &bValue, getBooleanCppuType() ) );
80 : 1677 : }
81 : :
82 : 44 : ScDPSaveMember::ScDPSaveMember(const ::rtl::OUString& rName) :
83 : : aName( rName ),
84 : : mpLayoutName(NULL),
85 : : nVisibleMode( SC_DPSAVEMODE_DONTKNOW ),
86 : 44 : nShowDetailsMode( SC_DPSAVEMODE_DONTKNOW )
87 : : {
88 : 44 : }
89 : :
90 : 1080 : ScDPSaveMember::ScDPSaveMember(const ScDPSaveMember& r) :
91 : : aName( r.aName ),
92 : : mpLayoutName(NULL),
93 : : nVisibleMode( r.nVisibleMode ),
94 : 1080 : nShowDetailsMode( r.nShowDetailsMode )
95 : : {
96 [ - + ]: 1080 : if (r.mpLayoutName)
97 [ # # ][ # # ]: 0 : mpLayoutName.reset(new OUString(*r.mpLayoutName));
98 : 1080 : }
99 : :
100 [ + - ]: 1084 : ScDPSaveMember::~ScDPSaveMember()
101 : : {
102 : 1084 : }
103 : :
104 : 0 : bool ScDPSaveMember::operator== ( const ScDPSaveMember& r ) const
105 : : {
106 [ # # ][ # # ]: 0 : if ( aName != r.aName ||
[ # # ][ # # ]
107 : : nVisibleMode != r.nVisibleMode ||
108 : : nShowDetailsMode != r.nShowDetailsMode )
109 : 0 : return false;
110 : :
111 : 0 : return true;
112 : : }
113 : :
114 : 7 : bool ScDPSaveMember::HasIsVisible() const
115 : : {
116 : 7 : return nVisibleMode != SC_DPSAVEMODE_DONTKNOW;
117 : : }
118 : :
119 : 46 : void ScDPSaveMember::SetIsVisible(bool bSet)
120 : : {
121 : 46 : nVisibleMode = bSet;
122 : 46 : }
123 : :
124 : 6 : bool ScDPSaveMember::HasShowDetails() const
125 : : {
126 : 6 : return nShowDetailsMode != SC_DPSAVEMODE_DONTKNOW;
127 : : }
128 : :
129 : 43 : void ScDPSaveMember::SetShowDetails(bool bSet)
130 : : {
131 : 43 : nShowDetailsMode = bSet;
132 : 43 : }
133 : :
134 : 0 : void ScDPSaveMember::SetName( const ::rtl::OUString& rNew )
135 : : {
136 : : // Used only if the source member was renamed (groups).
137 : : // For UI renaming of members, a layout name must be used.
138 : :
139 : 0 : aName = rNew;
140 : 0 : }
141 : :
142 : 0 : void ScDPSaveMember::SetLayoutName( const OUString& rName )
143 : : {
144 : 0 : mpLayoutName.reset(new OUString(rName));
145 : 0 : }
146 : :
147 : 0 : const OUString* ScDPSaveMember::GetLayoutName() const
148 : : {
149 : 0 : return mpLayoutName.get();
150 : : }
151 : :
152 : 0 : void ScDPSaveMember::RemoveLayoutName()
153 : : {
154 : 0 : mpLayoutName.reset(NULL);
155 : 0 : }
156 : :
157 : 403 : void ScDPSaveMember::WriteToSource( const uno::Reference<uno::XInterface>& xMember, sal_Int32 nPosition )
158 : : {
159 [ + - ]: 403 : uno::Reference<beans::XPropertySet> xMembProp( xMember, uno::UNO_QUERY );
160 : : OSL_ENSURE( xMembProp.is(), "no properties at member" );
161 [ + - ]: 403 : if ( xMembProp.is() )
162 : : {
163 : : // exceptions are caught at ScDPSaveData::WriteToSource
164 : :
165 [ + - ]: 403 : if ( nVisibleMode != SC_DPSAVEMODE_DONTKNOW )
166 : : lcl_SetBoolProperty( xMembProp,
167 [ + - ][ + - ]: 403 : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_DP_ISVISIBLE)), (bool)nVisibleMode );
168 : :
169 [ + + ]: 403 : if ( nShowDetailsMode != SC_DPSAVEMODE_DONTKNOW )
170 : : lcl_SetBoolProperty( xMembProp,
171 [ + - ][ + - ]: 400 : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_DP_SHOWDETAILS)), (bool)nShowDetailsMode );
172 : :
173 [ - + ]: 403 : if (mpLayoutName)
174 [ # # ]: 0 : ScUnoHelpFunctions::SetOptionalPropertyValue(xMembProp, SC_UNO_DP_LAYOUTNAME, *mpLayoutName);
175 : :
176 [ + + ]: 403 : if ( nPosition >= 0 )
177 [ + - ]: 93 : ScUnoHelpFunctions::SetOptionalPropertyValue(xMembProp, SC_UNO_DP_POSITION, nPosition);
178 : 403 : }
179 : 403 : }
180 : :
181 : 240 : ScDPSaveDimension::ScDPSaveDimension(const ::rtl::OUString& rName, bool bDataLayout) :
182 : : aName( rName ),
183 : : pSelectedPage( NULL ),
184 : : mpLayoutName(NULL),
185 : : mpSubtotalName(NULL),
186 : : bIsDataLayout( bDataLayout ),
187 : : bDupFlag( false ),
188 : : nOrientation( sheet::DataPilotFieldOrientation_HIDDEN ),
189 : : nFunction( sheet::GeneralFunction_AUTO ),
190 : : nUsedHierarchy( -1 ),
191 : : nShowEmptyMode( SC_DPSAVEMODE_DONTKNOW ),
192 : : bSubTotalDefault( true ),
193 : : nSubTotalCount( 0 ),
194 : : pSubTotalFuncs( NULL ),
195 : : pReferenceValue( NULL ),
196 : : pSortInfo( NULL ),
197 : : pAutoShowInfo( NULL ),
198 [ + - ][ + - ]: 240 : pLayoutInfo( NULL )
199 : : {
200 : 240 : }
201 : :
202 : 810 : ScDPSaveDimension::ScDPSaveDimension(const ScDPSaveDimension& r) :
203 : : aName( r.aName ),
204 : : mpLayoutName(NULL),
205 : : mpSubtotalName(NULL),
206 : : bIsDataLayout( r.bIsDataLayout ),
207 : : bDupFlag( r.bDupFlag ),
208 : : nOrientation( r.nOrientation ),
209 : : nFunction( r.nFunction ),
210 : : nUsedHierarchy( r.nUsedHierarchy ),
211 : : nShowEmptyMode( r.nShowEmptyMode ),
212 : : bSubTotalDefault( r.bSubTotalDefault ),
213 : : nSubTotalCount( r.nSubTotalCount ),
214 [ + - ][ + - ]: 810 : pSubTotalFuncs( NULL )
215 : : {
216 [ + + ][ + - ]: 810 : if ( nSubTotalCount && r.pSubTotalFuncs )
217 : : {
218 [ + - ]: 170 : pSubTotalFuncs = new sal_uInt16[nSubTotalCount];
219 [ + + ]: 340 : for (long nSub=0; nSub<nSubTotalCount; nSub++)
220 : 170 : pSubTotalFuncs[nSub] = r.pSubTotalFuncs[nSub];
221 : : }
222 : :
223 [ + + ]: 1890 : for (MemberList::const_iterator i=r.maMemberList.begin(); i != r.maMemberList.end() ; ++i)
224 : : {
225 : 1080 : const ::rtl::OUString& rName = (*i)->GetName();
226 [ + - ][ + - ]: 1080 : ScDPSaveMember* pNew = new ScDPSaveMember( **i );
227 [ + - ]: 1080 : maMemberHash[rName] = pNew;
228 [ + - ]: 1080 : maMemberList.push_back( pNew );
229 : : }
230 [ + + ]: 810 : if (r.pReferenceValue)
231 [ + - ]: 6 : pReferenceValue = new sheet::DataPilotFieldReference( *(r.pReferenceValue) );
232 : : else
233 : 804 : pReferenceValue = NULL;
234 [ + + ]: 810 : if (r.pSortInfo)
235 [ + - ]: 254 : pSortInfo = new sheet::DataPilotFieldSortInfo( *(r.pSortInfo) );
236 : : else
237 : 556 : pSortInfo = NULL;
238 [ + + ]: 810 : if (r.pAutoShowInfo)
239 [ + - ]: 278 : pAutoShowInfo = new sheet::DataPilotFieldAutoShowInfo( *(r.pAutoShowInfo) );
240 : : else
241 : 532 : pAutoShowInfo = NULL;
242 [ + + ]: 810 : if (r.pLayoutInfo)
243 [ + - ]: 266 : pLayoutInfo = new sheet::DataPilotFieldLayoutInfo( *(r.pLayoutInfo) );
244 : : else
245 : 544 : pLayoutInfo = NULL;
246 [ + + ]: 810 : if (r.pSelectedPage)
247 [ + - ]: 3 : pSelectedPage = new ::rtl::OUString( *(r.pSelectedPage) );
248 : : else
249 : 807 : pSelectedPage = NULL;
250 [ - + ]: 810 : if (r.mpLayoutName)
251 [ # # ][ # # ]: 0 : mpLayoutName.reset(new OUString(*r.mpLayoutName));
252 [ - + ]: 810 : if (r.mpSubtotalName)
253 [ # # ][ # # ]: 0 : mpSubtotalName.reset(new OUString(*r.mpSubtotalName));
254 : 810 : }
255 : :
256 [ + - ][ + - ]: 1028 : ScDPSaveDimension::~ScDPSaveDimension()
[ + - ]
257 : : {
258 [ + - ][ + - ]: 2112 : for (MemberHash::const_iterator i=maMemberHash.begin(); i != maMemberHash.end() ; ++i)
[ + + ]
259 [ + - ][ + - ]: 1084 : delete i->second;
[ + - ]
260 [ + + ]: 1028 : delete pReferenceValue;
261 [ + + ]: 1028 : delete pSortInfo;
262 [ + + ]: 1028 : delete pAutoShowInfo;
263 : 1028 : delete pLayoutInfo;
264 [ + + ]: 1028 : delete pSelectedPage;
265 [ + + ]: 1028 : delete [] pSubTotalFuncs;
266 : 1028 : }
267 : :
268 : 0 : bool ScDPSaveDimension::operator== ( const ScDPSaveDimension& r ) const
269 : : {
270 [ # # ][ # # ]: 0 : if ( aName != r.aName ||
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
271 : : bIsDataLayout != r.bIsDataLayout ||
272 : : bDupFlag != r.bDupFlag ||
273 : : nOrientation != r.nOrientation ||
274 : : nFunction != r.nFunction ||
275 : : nUsedHierarchy != r.nUsedHierarchy ||
276 : : nShowEmptyMode != r.nShowEmptyMode ||
277 : : bSubTotalDefault != r.bSubTotalDefault ||
278 : : nSubTotalCount != r.nSubTotalCount )
279 : 0 : return false;
280 : :
281 [ # # ][ # # ]: 0 : if ( nSubTotalCount && ( !pSubTotalFuncs || !r.pSubTotalFuncs ) ) // should not happen
[ # # ]
282 : 0 : return false;
283 : :
284 : : long i;
285 [ # # ]: 0 : for (i=0; i<nSubTotalCount; i++)
286 [ # # ]: 0 : if ( pSubTotalFuncs[i] != r.pSubTotalFuncs[i] )
287 : 0 : return false;
288 : :
289 [ # # ]: 0 : if (maMemberHash.size() != r.maMemberHash.size() )
290 : 0 : return false;
291 : :
292 : 0 : MemberList::const_iterator a=maMemberList.begin();
293 : 0 : MemberList::const_iterator b=r.maMemberList.begin();
294 [ # # ]: 0 : for (; a != maMemberList.end() ; ++a, ++b)
295 [ # # ]: 0 : if (!(**a == **b))
296 : 0 : return false;
297 : :
298 [ # # ][ # # ]: 0 : if ( this->HasCurrentPage() && r.HasCurrentPage() )
[ # # ][ # # ]
[ # # ]
299 : : {
300 [ # # ][ # # ]: 0 : if ( this->GetCurrentPage() != r.GetCurrentPage() )
[ # # ]
301 : : {
302 : 0 : return false;
303 : : }
304 : : }
305 [ # # ][ # # ]: 0 : else if ( this->HasCurrentPage() || r.HasCurrentPage() )
[ # # ][ # # ]
[ # # ]
306 : : {
307 : 0 : return false;
308 : : }
309 [ # # ][ # # ]: 0 : if( pReferenceValue && r.pReferenceValue )
310 : : {
311 [ # # ]: 0 : if ( !(*pReferenceValue == *r.pReferenceValue) )
312 : : {
313 : 0 : return false;
314 : : }
315 : : }
316 [ # # ][ # # ]: 0 : else if ( pReferenceValue || r.pReferenceValue )
317 : : {
318 : 0 : return false;
319 : : }
320 [ # # ][ # # ]: 0 : if( this->pSortInfo && r.pSortInfo )
321 : : {
322 [ # # ]: 0 : if ( !(*this->pSortInfo == *r.pSortInfo) )
323 : : {
324 : 0 : return false;
325 : : }
326 : : }
327 [ # # ][ # # ]: 0 : else if ( this->pSortInfo || r.pSortInfo )
328 : : {
329 : 0 : return false;
330 : : }
331 [ # # ][ # # ]: 0 : if( this->pAutoShowInfo && r.pAutoShowInfo )
332 : : {
333 [ # # ]: 0 : if ( !(*this->pAutoShowInfo == *r.pAutoShowInfo) )
334 : : {
335 : 0 : return false;
336 : : }
337 : : }
338 [ # # ][ # # ]: 0 : else if ( this->pAutoShowInfo || r.pAutoShowInfo )
339 : : {
340 : 0 : return false;
341 : : }
342 : :
343 : 0 : return true;
344 : : }
345 : :
346 : 40 : void ScDPSaveDimension::AddMember(ScDPSaveMember* pMember)
347 : : {
348 : 40 : const ::rtl::OUString & rName = pMember->GetName();
349 [ + - ]: 40 : MemberHash::iterator aExisting = maMemberHash.find( rName );
350 [ + - ][ + - ]: 40 : if ( aExisting == maMemberHash.end() )
351 : : {
352 : 40 : std::pair< const ::rtl::OUString, ScDPSaveMember *> key( rName, pMember );
353 [ + - ]: 40 : maMemberHash.insert ( key );
354 : : }
355 : : else
356 : : {
357 [ # # ][ # # ]: 0 : maMemberList.remove( aExisting->second );
358 [ # # ][ # # ]: 0 : delete aExisting->second;
[ # # ]
359 [ # # ]: 0 : aExisting->second = pMember;
360 : : }
361 [ + - ]: 40 : maMemberList.push_back( pMember );
362 : 40 : }
363 : :
364 : 3 : void ScDPSaveDimension::SetName( const ::rtl::OUString& rNew )
365 : : {
366 : : // Used only if the source dim was renamed (groups).
367 : : // For UI renaming of dimensions, the layout name must be used.
368 : :
369 : 3 : aName = rNew;
370 : 3 : }
371 : :
372 : 252 : void ScDPSaveDimension::SetOrientation(sal_uInt16 nNew)
373 : : {
374 : 252 : nOrientation = nNew;
375 : 252 : }
376 : :
377 : 24 : void ScDPSaveDimension::SetSubTotals(long nCount, const sal_uInt16* pFuncs)
378 : : {
379 [ + + ]: 24 : if (pSubTotalFuncs)
380 [ + - ]: 3 : delete [] pSubTotalFuncs;
381 : 24 : nSubTotalCount = nCount;
382 [ + + ][ + - ]: 24 : if ( nCount && pFuncs )
383 : : {
384 : 23 : pSubTotalFuncs = new sal_uInt16[nCount];
385 [ + + ]: 46 : for (long i=0; i<nCount; i++)
386 : 23 : pSubTotalFuncs[i] = pFuncs[i];
387 : : }
388 : : else
389 : 1 : pSubTotalFuncs = NULL;
390 : :
391 : 24 : bSubTotalDefault = false;
392 : 24 : }
393 : :
394 : 0 : bool ScDPSaveDimension::HasShowEmpty() const
395 : : {
396 : 0 : return nShowEmptyMode != SC_DPSAVEMODE_DONTKNOW;
397 : : }
398 : :
399 : 53 : void ScDPSaveDimension::SetShowEmpty(bool bSet)
400 : : {
401 : 53 : nShowEmptyMode = bSet;
402 : 53 : }
403 : :
404 : 69 : void ScDPSaveDimension::SetFunction(sal_uInt16 nNew)
405 : : {
406 : 69 : nFunction = nNew;
407 : 69 : }
408 : :
409 : 127 : void ScDPSaveDimension::SetUsedHierarchy(long nNew)
410 : : {
411 : 127 : nUsedHierarchy = nNew;
412 : 127 : }
413 : :
414 : 0 : void ScDPSaveDimension::SetSubtotalName(const OUString& rName)
415 : : {
416 : 0 : mpSubtotalName.reset(new OUString(rName));
417 : 0 : }
418 : :
419 : 521 : const OUString* ScDPSaveDimension::GetSubtotalName() const
420 : : {
421 : 521 : return mpSubtotalName.get();
422 : : }
423 : :
424 : 0 : void ScDPSaveDimension::RemoveSubtotalName()
425 : : {
426 : 0 : mpSubtotalName.reset();
427 : 0 : }
428 : :
429 : 0 : bool ScDPSaveDimension::IsMemberNameInUse(const OUString& rName) const
430 : : {
431 : 0 : MemberList::const_iterator itr = maMemberList.begin(), itrEnd = maMemberList.end();
432 [ # # ]: 0 : for (; itr != itrEnd; ++itr)
433 : : {
434 : 0 : const ScDPSaveMember* pMem = *itr;
435 [ # # ]: 0 : if (rName.equalsIgnoreAsciiCase(pMem->GetName()))
436 : 0 : return true;
437 : :
438 [ # # ]: 0 : const OUString* pLayoutName = pMem->GetLayoutName();
439 [ # # ][ # # ]: 0 : if (pLayoutName && rName.equalsIgnoreAsciiCase(*pLayoutName))
[ # # ]
440 : 0 : return true;
441 : : }
442 : 0 : return false;
443 : : }
444 : :
445 : 6 : void ScDPSaveDimension::SetLayoutName(const OUString& rName)
446 : : {
447 : 6 : mpLayoutName.reset(new OUString(rName));
448 : 6 : }
449 : :
450 : 79 : const OUString* ScDPSaveDimension::GetLayoutName() const
451 : : {
452 : 79 : return mpLayoutName.get();
453 : : }
454 : :
455 : 0 : void ScDPSaveDimension::RemoveLayoutName()
456 : : {
457 : 0 : mpLayoutName.reset(NULL);
458 : 0 : }
459 : :
460 : 49 : void ScDPSaveDimension::SetReferenceValue(const sheet::DataPilotFieldReference* pNew)
461 : : {
462 [ + + ]: 49 : delete pReferenceValue;
463 [ + + ]: 49 : if (pNew)
464 : 2 : pReferenceValue = new sheet::DataPilotFieldReference(*pNew);
465 : : else
466 : 47 : pReferenceValue = NULL;
467 : 49 : }
468 : :
469 : 72 : void ScDPSaveDimension::SetSortInfo(const sheet::DataPilotFieldSortInfo* pNew)
470 : : {
471 [ + + ]: 72 : delete pSortInfo;
472 [ + + ]: 72 : if (pNew)
473 : 70 : pSortInfo = new sheet::DataPilotFieldSortInfo(*pNew);
474 : : else
475 : 2 : pSortInfo = NULL;
476 : 72 : }
477 : :
478 : 72 : void ScDPSaveDimension::SetAutoShowInfo(const sheet::DataPilotFieldAutoShowInfo* pNew)
479 : : {
480 [ + + ]: 72 : delete pAutoShowInfo;
481 [ + + ]: 72 : if (pNew)
482 : 70 : pAutoShowInfo = new sheet::DataPilotFieldAutoShowInfo(*pNew);
483 : : else
484 : 2 : pAutoShowInfo = NULL;
485 : 72 : }
486 : :
487 : 72 : void ScDPSaveDimension::SetLayoutInfo(const sheet::DataPilotFieldLayoutInfo* pNew)
488 : : {
489 : 72 : delete pLayoutInfo;
490 [ + + ]: 72 : if (pNew)
491 : 70 : pLayoutInfo = new sheet::DataPilotFieldLayoutInfo(*pNew);
492 : : else
493 : 2 : pLayoutInfo = NULL;
494 : 72 : }
495 : :
496 : 13 : void ScDPSaveDimension::SetCurrentPage( const ::rtl::OUString* pPage )
497 : : {
498 [ + + ]: 13 : delete pSelectedPage;
499 [ + + ]: 13 : if (pPage)
500 : 10 : pSelectedPage = new ::rtl::OUString( *pPage );
501 : : else
502 : 3 : pSelectedPage = NULL;
503 : 13 : }
504 : :
505 : 27 : bool ScDPSaveDimension::HasCurrentPage() const
506 : : {
507 : 27 : return ( pSelectedPage != NULL );
508 : : }
509 : :
510 : 8 : const ::rtl::OUString& ScDPSaveDimension::GetCurrentPage() const
511 : : {
512 [ + + ][ + - ]: 8 : static const ::rtl::OUString emptyOUString = ::rtl::OUString();
513 [ + - ]: 8 : if (pSelectedPage)
514 : 8 : return *pSelectedPage;
515 : 8 : return emptyOUString;
516 : : }
517 : :
518 : 15 : ScDPSaveMember* ScDPSaveDimension::GetExistingMemberByName(const ::rtl::OUString& rName)
519 : : {
520 [ + - ]: 15 : MemberHash::const_iterator res = maMemberHash.find (rName);
521 [ + + ][ + - ]: 15 : if (res != maMemberHash.end())
522 [ + - ]: 14 : return res->second;
523 : 15 : return NULL;
524 : : }
525 : :
526 : 10 : ScDPSaveMember* ScDPSaveDimension::GetMemberByName(const ::rtl::OUString& rName)
527 : : {
528 [ + - ]: 10 : MemberHash::const_iterator res = maMemberHash.find (rName);
529 [ + + ][ + - ]: 10 : if (res != maMemberHash.end())
530 [ + - ]: 6 : return res->second;
531 : :
532 [ + - ][ + - ]: 4 : ScDPSaveMember* pNew = new ScDPSaveMember( rName );
533 [ + - ]: 4 : maMemberHash[rName] = pNew;
534 [ + - ]: 4 : maMemberList.push_back( pNew );
535 : 10 : return pNew;
536 : : }
537 : :
538 : 0 : void ScDPSaveDimension::SetMemberPosition( const ::rtl::OUString& rName, sal_Int32 nNewPos )
539 : : {
540 [ # # ]: 0 : ScDPSaveMember* pMember = GetMemberByName( rName ); // make sure it exists and is in the hash
541 : :
542 [ # # ]: 0 : maMemberList.remove( pMember );
543 : :
544 : 0 : MemberList::iterator aIter = maMemberList.begin();
545 [ # # ][ # # ]: 0 : for (sal_Int32 i=0; i<nNewPos && aIter != maMemberList.end(); i++)
[ # # ][ # # ]
546 : 0 : ++aIter;
547 [ # # ]: 0 : maMemberList.insert( aIter, pMember );
548 : 0 : }
549 : :
550 : 521 : void ScDPSaveDimension::WriteToSource( const uno::Reference<uno::XInterface>& xDim )
551 : : {
552 [ + - ]: 521 : uno::Reference<beans::XPropertySet> xDimProp( xDim, uno::UNO_QUERY );
553 : : OSL_ENSURE( xDimProp.is(), "no properties at dimension" );
554 [ + - ]: 521 : if ( xDimProp.is() )
555 : : {
556 : : // exceptions are caught at ScDPSaveData::WriteToSource
557 : 521 : uno::Any aAny;
558 : :
559 : 521 : sheet::DataPilotFieldOrientation eOrient = (sheet::DataPilotFieldOrientation)nOrientation;
560 [ + - ]: 521 : aAny <<= eOrient;
561 [ + - ][ + - ]: 521 : xDimProp->setPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_DP_ORIENTATION)), aAny );
[ + - ]
562 : :
563 : 521 : sheet::GeneralFunction eFunc = (sheet::GeneralFunction)nFunction;
564 [ + - ]: 521 : aAny <<= eFunc;
565 [ + - ][ + - ]: 521 : xDimProp->setPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_DP_FUNCTION)), aAny );
[ + - ]
566 : :
567 [ + + ]: 521 : if ( nUsedHierarchy >= 0 )
568 : : {
569 [ + - ]: 263 : aAny <<= (sal_Int32)nUsedHierarchy;
570 [ + - ][ + - ]: 263 : xDimProp->setPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_DP_USEDHIERARCHY)), aAny );
[ + - ]
571 : : }
572 : :
573 [ + + ]: 521 : if ( pReferenceValue )
574 : : {
575 [ + - ]: 2 : aAny <<= *pReferenceValue;
576 [ + - ][ + - ]: 2 : xDimProp->setPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_DP_REFVALUE)), aAny );
[ + - ]
577 : : }
578 : :
579 [ + - ]: 521 : uno::Sequence<sheet::TableFilterField> aFilter;
580 : : // set the selected page field only if the dimension is used as page dimension
581 [ + + ][ + - ]: 521 : if ( pSelectedPage && nOrientation == sheet::DataPilotFieldOrientation_PAGE )
582 : : {
583 : : // single filter field: first field equal to selected string
584 : : sheet::TableFilterField aField( sheet::FilterConnection_AND, 0,
585 : 6 : sheet::FilterOperator_EQUAL, false, 0.0, *pSelectedPage );
586 [ + - ][ + - ]: 6 : aFilter = uno::Sequence<sheet::TableFilterField>( &aField, 1 );
[ + - ]
587 : : }
588 : : // else keep empty sequence
589 : :
590 [ + - ]: 521 : ScUnoHelpFunctions::SetOptionalPropertyValue(xDimProp, SC_UNO_DP_FILTER, aFilter);
591 [ - + ]: 521 : if (mpLayoutName)
592 [ # # ]: 0 : ScUnoHelpFunctions::SetOptionalPropertyValue(xDimProp, SC_UNO_DP_LAYOUTNAME, *mpLayoutName);
593 : :
594 [ + - ]: 521 : const OUString* pSubTotalName = GetSubtotalName();
595 [ - + ]: 521 : if (pSubTotalName)
596 : : // Custom subtotal name, with '?' being replaced by the visible field name later.
597 [ # # ][ + - ]: 521 : ScUnoHelpFunctions::SetOptionalPropertyValue(xDimProp, SC_UNO_DP_FIELD_SUBTOTALNAME, *pSubTotalName);
598 : : }
599 : :
600 : : // Level loop outside of maMemberList loop
601 : : // because SubTotals have to be set independently of known members
602 : :
603 : 521 : long nCount = maMemberHash.size();
604 : :
605 : 521 : long nHierCount = 0;
606 : 521 : uno::Reference<container::XIndexAccess> xHiers;
607 [ + - ]: 521 : uno::Reference<sheet::XHierarchiesSupplier> xHierSupp( xDim, uno::UNO_QUERY );
608 [ + - ]: 521 : if ( xHierSupp.is() )
609 : : {
610 [ + - ][ + - ]: 521 : uno::Reference<container::XNameAccess> xHiersName = xHierSupp->getHierarchies();
611 [ + - ][ + - ]: 521 : xHiers = new ScNameToIndexAccess( xHiersName );
[ + - ]
612 [ + - ][ + - ]: 521 : nHierCount = xHiers->getCount();
613 : : }
614 : :
615 : 521 : bool bHasHiddenMember = false;
616 : :
617 [ + + ]: 1042 : for (long nHier=0; nHier<nHierCount; nHier++)
618 : : {
619 [ + - ][ + - ]: 521 : uno::Reference<uno::XInterface> xHierarchy = ScUnoHelpFunctions::AnyToInterface( xHiers->getByIndex(nHier) );
[ + - ]
620 : :
621 : 521 : long nLevCount = 0;
622 : 521 : uno::Reference<container::XIndexAccess> xLevels;
623 [ + - ]: 521 : uno::Reference<sheet::XLevelsSupplier> xLevSupp( xHierarchy, uno::UNO_QUERY );
624 [ + - ]: 521 : if ( xLevSupp.is() )
625 : : {
626 [ + - ][ + - ]: 521 : uno::Reference<container::XNameAccess> xLevelsName = xLevSupp->getLevels();
627 [ + - ][ + - ]: 521 : xLevels = new ScNameToIndexAccess( xLevelsName );
[ + - ]
628 [ + - ][ + - ]: 521 : nLevCount = xLevels->getCount();
629 : : }
630 : :
631 [ + + ]: 1042 : for (long nLev=0; nLev<nLevCount; nLev++)
632 : : {
633 [ + - ][ + - ]: 521 : uno::Reference<uno::XInterface> xLevel = ScUnoHelpFunctions::AnyToInterface( xLevels->getByIndex(nLev) );
[ + - ]
634 [ + - ]: 521 : uno::Reference<beans::XPropertySet> xLevProp( xLevel, uno::UNO_QUERY );
635 : : OSL_ENSURE( xLevProp.is(), "no properties at level" );
636 [ + - ]: 521 : if ( xLevProp.is() )
637 : : {
638 : 521 : uno::Any aAny;
639 [ + + ]: 521 : if ( !bSubTotalDefault )
640 : : {
641 [ - + ]: 69 : if ( !pSubTotalFuncs )
642 : 0 : nSubTotalCount = 0;
643 : :
644 [ + - ]: 69 : uno::Sequence<sheet::GeneralFunction> aSeq(nSubTotalCount);
645 [ + - ]: 69 : sheet::GeneralFunction* pArray = aSeq.getArray();
646 [ + + ]: 138 : for (long i=0; i<nSubTotalCount; i++)
647 : 69 : pArray[i] = (sheet::GeneralFunction)pSubTotalFuncs[i];
648 [ + - ]: 69 : aAny <<= aSeq;
649 [ + - ][ + - ]: 69 : xLevProp->setPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_DP_SUBTOTAL)), aAny );
[ + - ][ + - ]
650 : : }
651 [ + + ]: 521 : if ( nShowEmptyMode != SC_DPSAVEMODE_DONTKNOW )
652 : : lcl_SetBoolProperty( xLevProp,
653 [ + - ][ + - ]: 166 : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_DP_SHOWEMPTY)), (bool)nShowEmptyMode );
654 : :
655 [ + + ]: 521 : if ( pSortInfo )
656 [ + - ]: 166 : ScUnoHelpFunctions::SetOptionalPropertyValue(xLevProp, SC_UNO_DP_SORTING, *pSortInfo);
657 : :
658 [ + + ]: 521 : if ( pAutoShowInfo )
659 [ + - ]: 174 : ScUnoHelpFunctions::SetOptionalPropertyValue(xLevProp, SC_UNO_DP_AUTOSHOW, *pAutoShowInfo);
660 : :
661 [ + + ]: 521 : if ( pLayoutInfo )
662 [ + - ]: 521 : ScUnoHelpFunctions::SetOptionalPropertyValue(xLevProp, SC_UNO_DP_LAYOUT, *pLayoutInfo);
663 : :
664 : : // exceptions are caught at ScDPSaveData::WriteToSource
665 : : }
666 : :
667 [ + + ]: 521 : if ( nCount > 0 )
668 : : {
669 [ + - ]: 83 : uno::Reference<sheet::XMembersSupplier> xMembSupp( xLevel, uno::UNO_QUERY );
670 [ + - ]: 83 : if ( xMembSupp.is() )
671 : : {
672 [ + - ][ + - ]: 83 : uno::Reference<container::XNameAccess> xMembers = xMembSupp->getMembers();
673 [ + - ]: 83 : if ( xMembers.is() )
674 : : {
675 : 83 : sal_Int32 nPosition = -1; // set position only in manual mode
676 [ + + ][ + + ]: 83 : if ( !pSortInfo || pSortInfo->Mode == sheet::DataPilotFieldSortMode::MANUAL )
677 : 21 : nPosition = 0;
678 : :
679 [ + + ]: 486 : for (MemberList::const_iterator i=maMemberList.begin(); i != maMemberList.end() ; ++i)
680 : : {
681 : 403 : ScDPSaveMember* pMember = *i;
682 [ + + ]: 403 : if (!pMember->GetIsVisible())
683 : 3 : bHasHiddenMember = true;
684 : 403 : rtl::OUString aMemberName = pMember->GetName();
685 [ + - ][ + - ]: 403 : if ( xMembers->hasByName( aMemberName ) )
[ + - ]
686 : : {
687 : : uno::Reference<uno::XInterface> xMemberInt = ScUnoHelpFunctions::AnyToInterface(
688 [ + - ][ + - ]: 403 : xMembers->getByName( aMemberName ) );
[ + - ]
689 [ + - ]: 403 : pMember->WriteToSource( xMemberInt, nPosition );
690 : :
691 [ + + ]: 403 : if ( nPosition >= 0 )
692 : 403 : ++nPosition; // increase if initialized
693 : : }
694 : : // missing member is no error
695 : 403 : }
696 : 83 : }
697 : 83 : }
698 : : }
699 : 521 : }
700 : 521 : }
701 : :
702 [ + - ]: 521 : if (xDimProp.is())
703 [ + - ]: 521 : ScUnoHelpFunctions::SetOptionalPropertyValue(xDimProp, SC_UNO_DP_HAS_HIDDEN_MEMBER, bHasHiddenMember);
704 : 521 : }
705 : :
706 : 0 : void ScDPSaveDimension::UpdateMemberVisibility(const boost::unordered_map<OUString, bool, OUStringHash>& rData)
707 : : {
708 : : typedef boost::unordered_map<OUString, bool, OUStringHash> DataMap;
709 : 0 : MemberList::iterator itrMem = maMemberList.begin(), itrMemEnd = maMemberList.end();
710 [ # # ]: 0 : for (; itrMem != itrMemEnd; ++itrMem)
711 : : {
712 : 0 : ScDPSaveMember* pMem = *itrMem;
713 : 0 : const ::rtl::OUString& rMemName = pMem->GetName();
714 [ # # ]: 0 : DataMap::const_iterator itr = rData.find(rMemName);
715 [ # # ][ # # ]: 0 : if (itr != rData.end())
716 [ # # ][ # # ]: 0 : pMem->SetIsVisible(itr->second);
717 : : }
718 : 0 : }
719 : :
720 : 10 : bool ScDPSaveDimension::HasInvisibleMember() const
721 : : {
722 : 10 : MemberList::const_iterator itrMem = maMemberList.begin(), itrMemEnd = maMemberList.end();
723 [ + + ]: 20 : for (; itrMem != itrMemEnd; ++itrMem)
724 : : {
725 : 10 : const ScDPSaveMember* pMem = *itrMem;
726 [ - + ]: 10 : if (!pMem->GetIsVisible())
727 : 0 : return true;
728 : : }
729 : 10 : return false;
730 : : }
731 : :
732 : 24 : void ScDPSaveDimension::RemoveObsoleteMembers(const MemberSetType& rMembers)
733 : : {
734 [ + - ]: 24 : maMemberHash.clear();
735 [ + - ]: 24 : MemberList aNew;
736 : 24 : MemberList::iterator it = maMemberList.begin(), itEnd = maMemberList.end();
737 [ - + ]: 24 : for (; it != itEnd; ++it)
738 : : {
739 : 0 : ScDPSaveMember* pMem = *it;
740 [ # # ][ # # ]: 0 : if (rMembers.count(pMem->GetName()))
741 : : {
742 : : // This member still exists.
743 [ # # ]: 0 : maMemberHash.insert(MemberHash::value_type(pMem->GetName(), pMem));
744 [ # # ]: 0 : aNew.push_back(pMem);
745 : : }
746 : : else
747 : : {
748 : : // This member no longer exists.
749 [ # # ][ # # ]: 0 : delete pMem;
750 : : }
751 : : }
752 : :
753 [ + - ]: 24 : maMemberList.swap(aNew);
754 : 24 : }
755 : :
756 : 115 : ScDPSaveData::ScDPSaveData() :
757 : : pDimensionData( NULL ),
758 : : nColumnGrandMode( SC_DPSAVEMODE_DONTKNOW ),
759 : : nRowGrandMode( SC_DPSAVEMODE_DONTKNOW ),
760 : : nIgnoreEmptyMode( SC_DPSAVEMODE_DONTKNOW ),
761 : : nRepeatEmptyMode( SC_DPSAVEMODE_DONTKNOW ),
762 : : bFilterButton( true ),
763 : : bDrillDown( true ),
764 : : mbDimensionMembersBuilt(false),
765 [ + - ]: 115 : mpGrandTotalName(NULL)
766 : : {
767 : 115 : }
768 : :
769 : 249 : ScDPSaveData::ScDPSaveData(const ScDPSaveData& r) :
770 : : nColumnGrandMode( r.nColumnGrandMode ),
771 : : nRowGrandMode( r.nRowGrandMode ),
772 : : nIgnoreEmptyMode( r.nIgnoreEmptyMode ),
773 : : nRepeatEmptyMode( r.nRepeatEmptyMode ),
774 : : bFilterButton( r.bFilterButton ),
775 : : bDrillDown( r.bDrillDown ),
776 : : mbDimensionMembersBuilt(r.mbDimensionMembersBuilt),
777 [ + - ]: 249 : mpGrandTotalName(NULL)
778 : : {
779 [ + + ]: 249 : if ( r.pDimensionData )
780 [ + - ][ + - ]: 5 : pDimensionData = new ScDPDimensionSaveData( *r.pDimensionData );
781 : : else
782 : 244 : pDimensionData = NULL;
783 : :
784 [ + - ][ + - ]: 249 : aDimList = r.aDimList.clone();
[ + - ][ + - ]
785 : :
786 [ - + ]: 249 : if (r.mpGrandTotalName)
787 [ # # ][ # # ]: 0 : mpGrandTotalName.reset(new OUString(*r.mpGrandTotalName));
788 : 249 : }
789 : :
790 : 0 : ScDPSaveData& ScDPSaveData::operator= ( const ScDPSaveData& r )
791 : : {
792 [ # # ]: 0 : if ( &r != this )
793 : : {
794 : 0 : this->~ScDPSaveData();
795 [ # # ][ # # ]: 0 : new( this ) ScDPSaveData ( r );
796 : : }
797 : 0 : return *this;
798 : : }
799 : :
800 : 0 : bool ScDPSaveData::operator== ( const ScDPSaveData& r ) const
801 : : {
802 [ # # ][ # # ]: 0 : if ( nColumnGrandMode != r.nColumnGrandMode ||
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
803 : : nRowGrandMode != r.nRowGrandMode ||
804 : : nIgnoreEmptyMode != r.nIgnoreEmptyMode ||
805 : : nRepeatEmptyMode != r.nRepeatEmptyMode ||
806 : : bFilterButton != r.bFilterButton ||
807 : : bDrillDown != r.bDrillDown ||
808 : : mbDimensionMembersBuilt != r.mbDimensionMembersBuilt)
809 : 0 : return false;
810 : :
811 [ # # ][ # # ]: 0 : if ( pDimensionData || r.pDimensionData )
812 [ # # ][ # # ]: 0 : if ( !pDimensionData || !r.pDimensionData || !( *pDimensionData == *r.pDimensionData ) )
[ # # ][ # # ]
813 : 0 : return false;
814 : :
815 [ # # ]: 0 : if ( aDimList.size() != r.aDimList.size() )
816 : 0 : return false;
817 : :
818 [ # # ]: 0 : if (aDimList != r.aDimList)
819 : 0 : return false;
820 : :
821 [ # # ]: 0 : if (mpGrandTotalName)
822 : : {
823 [ # # ]: 0 : if (!r.mpGrandTotalName)
824 : 0 : return false;
825 [ # # ]: 0 : if (!mpGrandTotalName->equals(*r.mpGrandTotalName))
826 : 0 : return false;
827 : : }
828 [ # # ]: 0 : else if (r.mpGrandTotalName)
829 : 0 : return false;
830 : :
831 : 0 : return true;
832 : : }
833 : :
834 [ + - ][ + - ]: 324 : ScDPSaveData::~ScDPSaveData()
835 : : {
836 [ + + ][ + - ]: 324 : delete pDimensionData;
837 : 324 : }
838 : :
839 : 0 : void ScDPSaveData::SetGrandTotalName(const OUString& rName)
840 : : {
841 : 0 : mpGrandTotalName.reset(new OUString(rName));
842 : 0 : }
843 : :
844 : 177 : const OUString* ScDPSaveData::GetGrandTotalName() const
845 : : {
846 : 177 : return mpGrandTotalName.get();
847 : : }
848 : :
849 : 70 : const ScDPSaveData::DimsType& ScDPSaveData::GetDimensions() const
850 : : {
851 : 70 : return aDimList;
852 : : }
853 : :
854 : 12 : void ScDPSaveData::GetAllDimensionsByOrientation(
855 : : sheet::DataPilotFieldOrientation eOrientation, std::vector<const ScDPSaveDimension*>& rDims) const
856 : : {
857 [ + - ]: 12 : std::vector<const ScDPSaveDimension*> aDims;
858 [ + - ][ + - ]: 12 : DimsType::const_iterator it = aDimList.begin(), itEnd = aDimList.end();
859 [ + - ][ + - ]: 56 : for (; it != itEnd; ++it)
[ + + ]
860 : : {
861 [ + - ]: 44 : const ScDPSaveDimension& rDim = *it;
862 [ + + ]: 44 : if (rDim.GetOrientation() != static_cast<sal_uInt16>(eOrientation))
863 : 30 : continue;
864 : :
865 [ + - ]: 14 : aDims.push_back(&rDim);
866 : : }
867 : :
868 : 12 : rDims.swap(aDims);
869 : 12 : }
870 : :
871 : 25 : void ScDPSaveData::AddDimension(ScDPSaveDimension* pDim)
872 : : {
873 [ - + ]: 25 : if (!pDim)
874 : 25 : return;
875 : :
876 : 25 : CheckDuplicateName(*pDim);
877 : 25 : aDimList.push_back(pDim);
878 : : }
879 : :
880 : 389 : ScDPSaveDimension* ScDPSaveData::GetDimensionByName(const ::rtl::OUString& rName)
881 : : {
882 [ + - ]: 389 : boost::ptr_vector<ScDPSaveDimension>::const_iterator iter;
883 [ + - ][ + - ]: 773 : for (iter = aDimList.begin(); iter != aDimList.end(); ++iter)
[ + - ][ + - ]
[ + - ][ + + ]
884 : : {
885 [ + - ][ + + ]: 699 : if (iter->GetName() == rName && !iter->IsDataLayout() )
[ + - ][ + - ]
[ + + ]
886 [ + - ]: 315 : return const_cast<ScDPSaveDimension*>(&(*iter));
887 : : }
888 : :
889 [ + - ]: 389 : return AppendNewDimension(rName, false);
890 : : }
891 : :
892 : 23 : ScDPSaveDimension* ScDPSaveData::GetExistingDimensionByName(const ::rtl::OUString& rName) const
893 : : {
894 [ + - ]: 23 : boost::ptr_vector<ScDPSaveDimension>::const_iterator iter;
895 [ + - ][ + - ]: 60 : for (iter = aDimList.begin(); iter != aDimList.end(); ++iter)
[ + - ][ + - ]
[ + + ]
896 : : {
897 [ + - ][ + + ]: 40 : if (iter->GetName() == rName && !iter->IsDataLayout() )
[ + - ][ + - ]
[ + + ]
898 [ + - ]: 3 : return const_cast<ScDPSaveDimension*>(&(*iter));
899 : : }
900 : 23 : return NULL; // don't create new
901 : : }
902 : :
903 : 105 : ScDPSaveDimension* ScDPSaveData::GetNewDimensionByName(const ::rtl::OUString& rName)
904 : : {
905 [ + - ]: 105 : boost::ptr_vector<ScDPSaveDimension>::const_iterator iter;
906 [ + - ][ + - ]: 204 : for (iter = aDimList.begin(); iter != aDimList.end(); ++iter)
[ + - ][ + - ]
[ + - ][ + + ]
907 : : {
908 [ + - ][ + + ]: 102 : if (iter->GetName() == rName && !iter->IsDataLayout() )
[ + - ][ + - ]
[ + + ]
909 [ + - ]: 3 : return DuplicateDimension(rName);
910 : : }
911 : :
912 [ + - ]: 105 : return AppendNewDimension(rName, false);
913 : : }
914 : :
915 : 45 : ScDPSaveDimension* ScDPSaveData::GetDataLayoutDimension()
916 : : {
917 : 45 : ScDPSaveDimension* pDim = GetExistingDataLayoutDimension();
918 [ + + ]: 45 : if (pDim)
919 : 3 : return pDim;
920 : :
921 [ + - ]: 45 : return AppendNewDimension(rtl::OUString(), true);
922 : : }
923 : :
924 : 45 : ScDPSaveDimension* ScDPSaveData::GetExistingDataLayoutDimension() const
925 : : {
926 [ + - ]: 45 : boost::ptr_vector<ScDPSaveDimension>::const_iterator iter;
927 [ + - ][ + - ]: 174 : for (iter = aDimList.begin(); iter != aDimList.end(); ++iter)
[ + - ][ + - ]
[ + + ]
928 : : {
929 [ + - ][ + + ]: 132 : if ( iter->IsDataLayout() )
930 [ + - ]: 3 : return const_cast<ScDPSaveDimension*>(&(*iter));
931 : : }
932 : 45 : return NULL;
933 : : }
934 : :
935 : 3 : ScDPSaveDimension* ScDPSaveData::DuplicateDimension(const ::rtl::OUString& rName)
936 : : {
937 : : // always insert new
938 : :
939 : 3 : ScDPSaveDimension* pOld = GetExistingDimensionByName(rName);
940 [ - + ]: 3 : if (!pOld)
941 : 0 : return NULL;
942 : :
943 [ + - ]: 3 : ScDPSaveDimension* pNew = new ScDPSaveDimension( *pOld );
944 : 3 : AddDimension(pNew);
945 : 3 : return pNew;
946 : : }
947 : :
948 : 0 : void ScDPSaveData::RemoveDimensionByName(const ::rtl::OUString& rName)
949 : : {
950 [ # # ]: 0 : boost::ptr_vector<ScDPSaveDimension>::iterator iter;
951 [ # # ][ # # ]: 0 : for (iter = aDimList.begin(); iter != aDimList.end(); ++iter)
[ # # ][ # # ]
[ # # ]
952 : : {
953 [ # # ][ # # ]: 0 : if (iter->GetName() != rName || iter->IsDataLayout())
[ # # ][ # # ]
[ # # ]
954 : 0 : continue;
955 : :
956 [ # # ]: 0 : aDimList.erase(iter);
957 [ # # ]: 0 : RemoveDuplicateNameCount(rName);
958 : 0 : return;
959 : : }
960 : : }
961 : :
962 : 0 : ScDPSaveDimension& ScDPSaveData::DuplicateDimension( const ScDPSaveDimension& rDim )
963 : : {
964 [ # # ]: 0 : ScDPSaveDimension* pNew = new ScDPSaveDimension( rDim );
965 : 0 : AddDimension(pNew);
966 : 0 : return *pNew;
967 : : }
968 : :
969 : 0 : ScDPSaveDimension* ScDPSaveData::GetInnermostDimension(sal_uInt16 nOrientation)
970 : : {
971 : : // return the innermost dimension for the given orientation,
972 : : // excluding data layout dimension
973 : :
974 [ # # ]: 0 : boost::ptr_vector<ScDPSaveDimension>::const_reverse_iterator iter;
975 [ # # ][ # # ]: 0 : for (iter = aDimList.rbegin(); iter != aDimList.rend(); ++iter)
[ # # ][ # # ]
[ # # ][ # # ]
976 : : {
977 [ # # ][ # # ]: 0 : if (iter->GetOrientation() == nOrientation && !iter->IsDataLayout())
[ # # ][ # # ]
[ # # ]
978 [ # # ]: 0 : return const_cast<ScDPSaveDimension*>(&(*iter));
979 : : }
980 : :
981 : 0 : return NULL;
982 : : }
983 : :
984 : 0 : ScDPSaveDimension* ScDPSaveData::GetFirstDimension(sheet::DataPilotFieldOrientation eOrientation)
985 : : {
986 [ # # ]: 0 : boost::ptr_vector<ScDPSaveDimension>::const_iterator iter;
987 [ # # ][ # # ]: 0 : for (iter = aDimList.begin(); iter != aDimList.end(); ++iter)
[ # # ][ # # ]
[ # # ][ # # ]
988 : : {
989 [ # # ][ # # ]: 0 : if (iter->GetOrientation() == eOrientation && !iter->IsDataLayout())
[ # # ][ # # ]
[ # # ]
990 [ # # ]: 0 : return const_cast<ScDPSaveDimension*>(&(*iter));
991 : : }
992 : 0 : return NULL;
993 : : }
994 : :
995 : 0 : long ScDPSaveData::GetDataDimensionCount() const
996 : : {
997 : 0 : long nDataCount = 0;
998 : :
999 [ # # ]: 0 : boost::ptr_vector<ScDPSaveDimension>::const_iterator iter;
1000 [ # # ][ # # ]: 0 : for (iter = aDimList.begin(); iter != aDimList.end(); ++iter)
[ # # ][ # # ]
[ # # ]
1001 : : {
1002 [ # # ][ # # ]: 0 : if (iter->GetOrientation() == sheet::DataPilotFieldOrientation_DATA)
1003 : 0 : ++nDataCount;
1004 : : }
1005 : :
1006 : 0 : return nDataCount;
1007 : : }
1008 : :
1009 : 83 : void ScDPSaveData::SetPosition( ScDPSaveDimension* pDim, long nNew )
1010 : : {
1011 : : // position (nNew) is counted within dimensions of the same orientation
1012 : :
1013 : 83 : sal_uInt16 nOrient = pDim->GetOrientation();
1014 : :
1015 [ + - ]: 83 : boost::ptr_vector<ScDPSaveDimension>::iterator it;
1016 [ + - ][ + - ]: 241 : for ( it = aDimList.begin(); it != aDimList.end(); ++it)
[ + - ][ + - ]
[ + - ]
1017 : : {
1018 [ + - ][ + + ]: 241 : if (pDim == &(*it))
1019 : : {
1020 : : // Tell ptr_vector to give up ownership of this element. Don't
1021 : : // delete this instance as it is re-inserted into the container
1022 : : // later.
1023 [ + - ][ + - ]: 83 : aDimList.release(it).release();
[ + - ]
1024 : 83 : break;
1025 : : }
1026 : : }
1027 : :
1028 [ + - ]: 83 : boost::ptr_vector<ScDPSaveDimension>::iterator iterInsert = aDimList.begin();
1029 [ + + ][ + - ]: 192 : while ( nNew > 0 && iterInsert != aDimList.end())
[ + - ][ + + ]
[ + + ]
[ + + # # ]
1030 : : {
1031 [ + - ][ + + ]: 109 : if (iterInsert->GetOrientation() == nOrient )
1032 : 2 : --nNew;
1033 : :
1034 [ + - ]: 109 : ++iterInsert;
1035 : : }
1036 : :
1037 [ + - ]: 83 : aDimList.insert(iterInsert,pDim);
1038 : 83 : }
1039 : :
1040 : 64 : void ScDPSaveData::SetColumnGrand(bool bSet)
1041 : : {
1042 : 64 : nColumnGrandMode = bSet;
1043 : 64 : }
1044 : :
1045 : 64 : void ScDPSaveData::SetRowGrand(bool bSet)
1046 : : {
1047 : 64 : nRowGrandMode = bSet;
1048 : 64 : }
1049 : :
1050 : 67 : void ScDPSaveData::SetIgnoreEmptyRows(bool bSet)
1051 : : {
1052 : 67 : nIgnoreEmptyMode = bSet;
1053 : 67 : }
1054 : :
1055 : 64 : void ScDPSaveData::SetRepeatIfEmpty(bool bSet)
1056 : : {
1057 : 64 : nRepeatEmptyMode = bSet;
1058 : 64 : }
1059 : :
1060 : 45 : void ScDPSaveData::SetFilterButton(bool bSet)
1061 : : {
1062 : 45 : bFilterButton = bSet;
1063 : 45 : }
1064 : :
1065 : 45 : void ScDPSaveData::SetDrillDown(bool bSet)
1066 : : {
1067 : 45 : bDrillDown = bSet;
1068 : 45 : }
1069 : :
1070 : 177 : void lcl_ResetOrient( const uno::Reference<sheet::XDimensionsSupplier>& xSource )
1071 : : {
1072 : 177 : sheet::DataPilotFieldOrientation eOrient = sheet::DataPilotFieldOrientation_HIDDEN;
1073 : :
1074 [ + - ][ + - ]: 177 : uno::Reference<container::XNameAccess> xDimsName = xSource->getDimensions();
1075 [ + - ][ + - ]: 177 : uno::Reference<container::XIndexAccess> xIntDims = new ScNameToIndexAccess( xDimsName );
[ + - ]
1076 [ + - ][ + - ]: 177 : long nIntCount = xIntDims->getCount();
1077 [ + + ]: 1031 : for (long nIntDim=0; nIntDim<nIntCount; nIntDim++)
1078 : : {
1079 [ + - ][ + - ]: 854 : uno::Reference<uno::XInterface> xIntDim = ScUnoHelpFunctions::AnyToInterface( xIntDims->getByIndex(nIntDim) );
[ + - ]
1080 [ + - ]: 854 : uno::Reference<beans::XPropertySet> xDimProp( xIntDim, uno::UNO_QUERY );
1081 [ + - ]: 854 : if (xDimProp.is())
1082 : : {
1083 : 854 : uno::Any aAny;
1084 [ + - ]: 854 : aAny <<= eOrient;
1085 [ + - ][ + - ]: 854 : xDimProp->setPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_DP_ORIENTATION)), aAny );
[ + - ]
1086 : : }
1087 : 1031 : }
1088 : 177 : }
1089 : :
1090 : 177 : void ScDPSaveData::WriteToSource( const uno::Reference<sheet::XDimensionsSupplier>& xSource )
1091 : : {
1092 [ + - ]: 177 : if (!xSource.is())
1093 : 177 : return;
1094 : :
1095 : : // source options must be first!
1096 : :
1097 [ + - ]: 177 : uno::Reference<beans::XPropertySet> xSourceProp( xSource, uno::UNO_QUERY );
1098 : : OSL_ENSURE( xSourceProp.is(), "no properties at source" );
1099 [ + - ]: 177 : if ( xSourceProp.is() )
1100 : : {
1101 : : // source options are not available for external sources
1102 : : //! use XPropertySetInfo to test for availability?
1103 : :
1104 : : try
1105 : : {
1106 [ + - ]: 177 : if ( nIgnoreEmptyMode != SC_DPSAVEMODE_DONTKNOW )
1107 : : lcl_SetBoolProperty( xSourceProp,
1108 [ + - ][ + - ]: 177 : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_DP_IGNOREEMPTY)), (bool)nIgnoreEmptyMode );
1109 [ + - ]: 177 : if ( nRepeatEmptyMode != SC_DPSAVEMODE_DONTKNOW )
1110 : : lcl_SetBoolProperty( xSourceProp,
1111 [ + - ][ + - ]: 177 : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_DP_REPEATEMPTY)), (bool)nRepeatEmptyMode );
[ # # ]
1112 : : }
1113 [ # # ]: 0 : catch(uno::Exception&)
1114 : : {
1115 : : // no error
1116 : : }
1117 : :
1118 [ + - ]: 177 : const OUString* pGrandTotalName = GetGrandTotalName();
1119 [ - + ]: 177 : if (pGrandTotalName)
1120 [ # # ]: 0 : ScUnoHelpFunctions::SetOptionalPropertyValue(xSourceProp, SC_UNO_DP_GRANDTOTAL_NAME, *pGrandTotalName);
1121 : : }
1122 : :
1123 : : // exceptions in the other calls are errors
1124 : : try
1125 : : {
1126 : : // reset all orientations
1127 : : //! "forgetSettings" or similar at source ?????
1128 : : //! reset all duplicated dimensions, or reuse them below !!!
1129 : : OSL_FAIL( "ScDPSaveData::WriteToSource" );
1130 : :
1131 [ + - ]: 177 : lcl_ResetOrient( xSource );
1132 : :
1133 [ + - ][ + - ]: 177 : uno::Reference<container::XNameAccess> xDimsName = xSource->getDimensions();
1134 [ + - ][ + - ]: 177 : uno::Reference<container::XIndexAccess> xIntDims = new ScNameToIndexAccess( xDimsName );
[ + - ]
1135 [ + - ][ + - ]: 177 : long nIntCount = xIntDims->getCount();
1136 : :
1137 [ + - ]: 177 : boost::ptr_vector<ScDPSaveDimension>::iterator iter = aDimList.begin();
1138 [ + - ][ + - ]: 700 : for (long i = 0; iter != aDimList.end(); ++iter, ++i)
[ + - ][ + + ]
1139 : : {
1140 [ + - ]: 523 : rtl::OUString aName = iter->GetName();
1141 [ + - ]: 523 : rtl::OUString aCoreName = ScDPUtil::getSourceDimensionName(aName);
1142 : :
1143 : : OSL_TRACE( "%s", aName.getStr() );
1144 : :
1145 [ + - ]: 523 : bool bData = iter->IsDataLayout();
1146 : :
1147 : : //! getByName for ScDPSource, including DataLayoutDimension !!!!!!!!
1148 : :
1149 : 523 : bool bFound = false;
1150 [ + + ][ + + ]: 1977 : for (long nIntDim=0; nIntDim<nIntCount && !bFound; nIntDim++)
[ + + ]
1151 : : {
1152 [ + - ][ + - ]: 1454 : uno::Reference<uno::XInterface> xIntDim = ScUnoHelpFunctions::AnyToInterface( xIntDims->getByIndex(nIntDim) );
[ + - ]
1153 [ + + ]: 1454 : if ( bData )
1154 : : {
1155 [ + - ]: 383 : uno::Reference<beans::XPropertySet> xDimProp( xIntDim, uno::UNO_QUERY );
1156 [ + - ]: 383 : if ( xDimProp.is() )
1157 : : {
1158 : : bFound = ScUnoHelpFunctions::GetBoolProperty( xDimProp,
1159 [ + - ][ + - ]: 383 : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_DP_ISDATALAYOUT)) );
1160 : : //! error checking -- is "IsDataLayoutDimension" property required??
1161 : 383 : }
1162 : : }
1163 : : else
1164 : : {
1165 [ + - ]: 1071 : uno::Reference<container::XNamed> xDimName( xIntDim, uno::UNO_QUERY );
1166 [ + - ][ + - ]: 1071 : if (xDimName.is() && xDimName->getName() == aCoreName)
[ + - ][ + + ]
[ + - ]
[ + + # # ]
1167 : 1071 : bFound = true;
1168 : : }
1169 : :
1170 [ + + ]: 1454 : if (bFound)
1171 : : {
1172 [ + - ][ + + ]: 521 : if (iter->GetDupFlag())
1173 : : {
1174 [ + - ]: 6 : uno::Reference<util::XCloneable> xCloneable(xIntDim, uno::UNO_QUERY);
1175 : : OSL_ENSURE(xCloneable.is(), "cannot clone dimension");
1176 [ + - ]: 6 : if (xCloneable.is())
1177 : : {
1178 [ + - ][ + - ]: 6 : uno::Reference<util::XCloneable> xNew = xCloneable->createClone();
1179 [ + - ]: 6 : uno::Reference<container::XNamed> xNewName(xNew, uno::UNO_QUERY);
1180 [ + - ]: 6 : if (xNewName.is())
1181 : : {
1182 [ + - ][ + - ]: 6 : xNewName->setName(aName);
1183 [ + - ][ + - ]: 6 : iter->WriteToSource(xNew);
1184 : 6 : }
1185 : 6 : }
1186 : : }
1187 : : else
1188 [ + - ][ + - ]: 515 : iter->WriteToSource( xIntDim );
1189 : : }
1190 : 1454 : }
1191 : : OSL_ENSURE(bFound, "WriteToSource: Dimension not found");
1192 : 523 : }
1193 : :
1194 [ + - ]: 177 : if ( xSourceProp.is() )
1195 : : {
1196 [ + - ]: 177 : if ( nColumnGrandMode != SC_DPSAVEMODE_DONTKNOW )
1197 : : lcl_SetBoolProperty( xSourceProp,
1198 [ + - ][ + - ]: 177 : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_DP_COLGRAND)), (bool)nColumnGrandMode );
1199 [ + - ]: 177 : if ( nRowGrandMode != SC_DPSAVEMODE_DONTKNOW )
1200 : : lcl_SetBoolProperty( xSourceProp,
1201 [ + - ][ + - ]: 177 : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_DP_ROWGRAND)), (bool)nRowGrandMode );
1202 [ # # ]: 177 : }
1203 : : }
1204 [ # # ]: 0 : catch(uno::Exception&)
1205 : : {
1206 : : OSL_FAIL("exception in WriteToSource");
1207 : 177 : }
1208 : : }
1209 : :
1210 : 0 : bool ScDPSaveData::IsEmpty() const
1211 : : {
1212 [ # # ]: 0 : boost::ptr_vector<ScDPSaveDimension>::const_iterator iter;
1213 [ # # ][ # # ]: 0 : for (iter = aDimList.begin(); iter != aDimList.end(); ++iter)
[ # # ][ # # ]
[ # # ]
1214 : : {
1215 [ # # ][ # # ]: 0 : if (iter->GetOrientation() != sheet::DataPilotFieldOrientation_HIDDEN && !iter->IsDataLayout())
[ # # ][ # # ]
[ # # ]
1216 : 0 : return false;
1217 : : }
1218 : 0 : return true; // no entries that are not hidden
1219 : : }
1220 : :
1221 : 17 : ScDPDimensionSaveData* ScDPSaveData::GetDimensionData()
1222 : : {
1223 [ + + ]: 17 : if (!pDimensionData)
1224 [ + - ]: 14 : pDimensionData = new ScDPDimensionSaveData;
1225 : 17 : return pDimensionData;
1226 : : }
1227 : :
1228 : 0 : void ScDPSaveData::SetDimensionData( const ScDPDimensionSaveData* pNew )
1229 : : {
1230 [ # # ]: 0 : delete pDimensionData;
1231 [ # # ]: 0 : if ( pNew )
1232 [ # # ]: 0 : pDimensionData = new ScDPDimensionSaveData( *pNew );
1233 : : else
1234 : 0 : pDimensionData = NULL;
1235 : 0 : }
1236 : :
1237 : 0 : void ScDPSaveData::BuildAllDimensionMembers(ScDPTableData* pData)
1238 : : {
1239 [ # # ]: 0 : if (mbDimensionMembersBuilt)
1240 : 0 : return;
1241 : :
1242 : : // First, build a dimension name-to-index map.
1243 : : typedef boost::unordered_map<OUString, long, ::rtl::OUStringHash> NameIndexMap;
1244 [ # # ]: 0 : NameIndexMap aMap;
1245 [ # # ]: 0 : long nColCount = pData->GetColumnCount();
1246 [ # # ]: 0 : for (long i = 0; i < nColCount; ++i)
1247 [ # # ][ # # ]: 0 : aMap.insert( NameIndexMap::value_type(pData->getDimensionName(i), i));
1248 : :
1249 [ # # ]: 0 : NameIndexMap::const_iterator itrEnd = aMap.end();
1250 : :
1251 [ # # ]: 0 : boost::ptr_vector<ScDPSaveDimension>::iterator iter;
1252 [ # # ][ # # ]: 0 : for (iter = aDimList.begin(); iter != aDimList.end(); ++iter)
[ # # ][ # # ]
[ # # ]
1253 : : {
1254 [ # # ]: 0 : const ::rtl::OUString& rDimName = iter->GetName();
1255 [ # # ]: 0 : if (rDimName.isEmpty())
1256 : : // empty dimension name. It must be data layout.
1257 : 0 : continue;
1258 : :
1259 [ # # ]: 0 : NameIndexMap::const_iterator itr = aMap.find(rDimName);
1260 [ # # ]: 0 : if (itr == itrEnd)
1261 : : // dimension name not in the data. This should never happen!
1262 : 0 : continue;
1263 : :
1264 [ # # ]: 0 : long nDimIndex = itr->second;
1265 [ # # ]: 0 : const std::vector<SCROW>& rMembers = pData->GetColumnEntries(nDimIndex);
1266 : 0 : size_t mMemberCount = rMembers.size();
1267 [ # # ]: 0 : for (size_t j = 0; j < mMemberCount; ++j)
1268 : : {
1269 [ # # ][ # # ]: 0 : const ScDPItemData* pMemberData = pData->GetMemberById( nDimIndex, rMembers[j] );
1270 [ # # ]: 0 : rtl::OUString aMemName = pData->GetFormattedString(nDimIndex, *pMemberData);
1271 [ # # ][ # # ]: 0 : if (iter->GetExistingMemberByName(aMemName))
[ # # ]
1272 : : // this member instance already exists. nothing to do.
1273 : 0 : continue;
1274 : :
1275 [ # # ][ # # ]: 0 : auto_ptr<ScDPSaveMember> pNewMember(new ScDPSaveMember(aMemName));
1276 [ # # ]: 0 : pNewMember->SetIsVisible(true);
1277 [ # # ][ # # ]: 0 : iter->AddMember(pNewMember.release());
1278 [ # # ][ # # ]: 0 : }
1279 : : }
1280 : :
1281 [ # # ]: 0 : mbDimensionMembersBuilt = true;
1282 : : }
1283 : :
1284 : 8 : void ScDPSaveData::SyncAllDimensionMembers(ScDPTableData* pData)
1285 : : {
1286 : : typedef boost::unordered_map<rtl::OUString, long, rtl::OUStringHash> NameIndexMap;
1287 : :
1288 : : // First, build a dimension name-to-index map.
1289 [ + - ]: 8 : NameIndexMap aMap;
1290 [ + - ]: 8 : long nColCount = pData->GetColumnCount();
1291 [ + + ]: 48 : for (long i = 0; i < nColCount; ++i)
1292 [ + - ][ + - ]: 40 : aMap.insert(NameIndexMap::value_type(pData->getDimensionName(i), i));
1293 : :
1294 [ + - ]: 8 : NameIndexMap::const_iterator itMapEnd = aMap.end();
1295 : :
1296 [ + - ][ + - ]: 8 : DimsType::iterator it = aDimList.begin(), itEnd = aDimList.end();
1297 [ + - ][ + - ]: 32 : for (it = aDimList.begin(); it != itEnd; ++it)
[ + - ][ + + ]
1298 : : {
1299 [ + - ]: 24 : const ::rtl::OUString& rDimName = it->GetName();
1300 [ - + ]: 24 : if (rDimName.isEmpty())
1301 : : // empty dimension name. It must be data layout.
1302 : 0 : continue;
1303 : :
1304 [ + - ]: 24 : NameIndexMap::const_iterator itMap = aMap.find(rDimName);
1305 [ - + ]: 24 : if (itMap == itMapEnd)
1306 : : // dimension name not in the data. This should never happen!
1307 : 0 : continue;
1308 : :
1309 [ + - ]: 24 : ScDPSaveDimension::MemberSetType aMemNames;
1310 [ + - ]: 24 : long nDimIndex = itMap->second;
1311 [ + - ]: 24 : const std::vector<SCROW>& rMembers = pData->GetColumnEntries(nDimIndex);
1312 : 24 : size_t nMemberCount = rMembers.size();
1313 [ + + ]: 140 : for (size_t j = 0; j < nMemberCount; ++j)
1314 : : {
1315 [ + - ][ + - ]: 116 : const ScDPItemData* pMemberData = pData->GetMemberById(nDimIndex, rMembers[j]);
1316 [ + - ]: 116 : rtl::OUString aMemName = pData->GetFormattedString(nDimIndex, *pMemberData);
1317 [ + - ]: 116 : aMemNames.insert(aMemName);
1318 : 116 : }
1319 : :
1320 [ + - ][ + - ]: 24 : it->RemoveObsoleteMembers(aMemNames);
1321 [ + - ][ + - ]: 32 : }
1322 : 8 : }
1323 : :
1324 : 0 : bool ScDPSaveData::HasInvisibleMember(const OUString& rDimName) const
1325 : : {
1326 : 0 : ScDPSaveDimension* pDim = GetExistingDimensionByName(rDimName);
1327 [ # # ]: 0 : if (!pDim)
1328 : 0 : return false;
1329 : :
1330 : 0 : return pDim->HasInvisibleMember();
1331 : : }
1332 : :
1333 : 25 : void ScDPSaveData::CheckDuplicateName(ScDPSaveDimension& rDim)
1334 : : {
1335 [ + - ]: 25 : const rtl::OUString aName = ScDPUtil::getSourceDimensionName(rDim.GetName());
1336 [ + - ]: 25 : DupNameCountType::iterator it = maDupNameCounts.find(aName);
1337 [ + - ][ + + ]: 25 : if (it != maDupNameCounts.end())
1338 : : {
1339 [ + - ][ + - ]: 3 : rDim.SetName(ScDPUtil::createDuplicateDimensionName(aName, ++it->second));
[ + - ]
1340 : 3 : rDim.SetDupFlag(true);
1341 : : }
1342 : : else
1343 : : // New name.
1344 [ + - ][ + - ]: 25 : maDupNameCounts.insert(DupNameCountType::value_type(aName, 0));
1345 : 25 : }
1346 : :
1347 : 0 : void ScDPSaveData::RemoveDuplicateNameCount(const rtl::OUString& rName)
1348 : : {
1349 : 0 : rtl::OUString aCoreName = rName;
1350 [ # # ][ # # ]: 0 : if (ScDPUtil::isDuplicateDimension(rName))
1351 [ # # ]: 0 : aCoreName = ScDPUtil::getSourceDimensionName(rName);
1352 : :
1353 [ # # ]: 0 : DupNameCountType::iterator it = maDupNameCounts.find(aCoreName);
1354 [ # # ][ # # ]: 0 : if (it == maDupNameCounts.end())
1355 : : return;
1356 : :
1357 [ # # ][ # # ]: 0 : if (!it->second)
1358 : : {
1359 [ # # ]: 0 : maDupNameCounts.erase(it);
1360 : : return;
1361 : : }
1362 : :
1363 [ # # ]: 0 : --it->second;
1364 : 0 : return;
1365 : : }
1366 : :
1367 : 218 : ScDPSaveDimension* ScDPSaveData::AppendNewDimension(const rtl::OUString& rName, bool bDataLayout)
1368 : : {
1369 [ - + ]: 218 : if (ScDPUtil::isDuplicateDimension(rName))
1370 : : // This call is for original dimensions only.
1371 : 0 : return NULL;
1372 : :
1373 [ + - ]: 218 : ScDPSaveDimension* pNew = new ScDPSaveDimension(rName, bDataLayout);
1374 : 218 : aDimList.push_back(pNew);
1375 [ + - ]: 218 : if (!maDupNameCounts.count(rName))
1376 [ + - ][ + - ]: 218 : maDupNameCounts.insert(DupNameCountType::value_type(rName, 0));
1377 : :
1378 : 218 : return pNew;
1379 : : }
1380 : :
1381 : 0 : bool operator == (const ::com::sun::star::sheet::DataPilotFieldSortInfo &l, const ::com::sun::star::sheet::DataPilotFieldSortInfo &r )
1382 : : {
1383 [ # # ][ # # ]: 0 : return l.Field == r.Field && l.IsAscending == r.IsAscending && l.Mode == r.Mode;
[ # # ]
1384 : : }
1385 : 0 : bool operator == (const ::com::sun::star::sheet::DataPilotFieldAutoShowInfo &l, const ::com::sun::star::sheet::DataPilotFieldAutoShowInfo &r )
1386 : : {
1387 : : return l.IsEnabled == r.IsEnabled &&
1388 : : l.ShowItemsMode == r.ShowItemsMode &&
1389 : : l.ItemCount == r.ItemCount &&
1390 [ # # ][ # # ]: 0 : l.DataField == r.DataField;
[ # # ][ # # ]
1391 : : }
1392 : 0 : bool operator == (const ::com::sun::star::sheet::DataPilotFieldReference &l, const ::com::sun::star::sheet::DataPilotFieldReference &r )
1393 : : {
1394 : : return l.ReferenceType == r.ReferenceType &&
1395 : 0 : l.ReferenceField == r.ReferenceField &&
1396 : : l.ReferenceItemType == r.ReferenceItemType &&
1397 [ # # # # ]: 0 : l.ReferenceItemName == r.ReferenceItemName;
[ # # ][ # # ]
1398 [ + - ][ + - ]: 153 : }
1399 : :
1400 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|