1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <xestream.hxx>
22 #include <xistream.hxx>
23 #include <xestring.hxx>
24 #include <xlpivot.hxx>
25 #include <generalfunction.hxx>
26 #include <osl/diagnose.h>
27 #include <sal/log.hxx>
28 #include <com/sun/star/sheet/DataPilotFieldGroupBy.hpp>
29 #include <com/sun/star/sheet/DataPilotFieldSortMode.hpp>
30 #include <com/sun/star/sheet/DataPilotFieldShowItemsMode.hpp>
31 #include <com/sun/star/sheet/DataPilotFieldLayoutMode.hpp>
32 #include <com/sun/star/sheet/DataPilotFieldReferenceType.hpp>
33 #include <com/sun/star/sheet/DataPilotFieldReferenceItemType.hpp>
35 using ::com::sun::star::sheet::DataPilotFieldOrientation
;
37 namespace ScDPSortMode
= ::com::sun::star::sheet::DataPilotFieldSortMode
;
38 namespace ScDPShowItemsMode
= ::com::sun::star::sheet::DataPilotFieldShowItemsMode
;
39 namespace ScDPLayoutMode
= ::com::sun::star::sheet::DataPilotFieldLayoutMode
;
40 namespace ScDPRefItemType
= ::com::sun::star::sheet::DataPilotFieldReferenceItemType
;
41 namespace ScDPGroupBy
= ::com::sun::star::sheet::DataPilotFieldGroupBy
;
45 XclPCItem::XclPCItem() :
46 meType( EXC_PCITEM_INVALID
),
47 maDateTime( DateTime::EMPTY
)
51 XclPCItem::~XclPCItem()
55 void XclPCItem::SetEmpty()
57 meType
= EXC_PCITEM_EMPTY
;
61 void XclPCItem::SetText( const OUString
& rText
)
63 meType
= EXC_PCITEM_TEXT
;
67 void XclPCItem::SetDouble( double fValue
, const OUString
& rText
)
69 meType
= EXC_PCITEM_DOUBLE
;
74 void XclPCItem::SetDateTime( const DateTime
& rDateTime
, const OUString
& rText
)
76 meType
= EXC_PCITEM_DATETIME
;
78 maDateTime
= rDateTime
;
81 void XclPCItem::SetInteger( sal_Int16 nValue
)
83 meType
= EXC_PCITEM_INTEGER
;
84 maText
= OUString::number(nValue
);
88 void XclPCItem::SetError( sal_uInt16 nError
)
90 meType
= EXC_PCITEM_ERROR
;
95 case 0x00: maText
= "#nullptr!"; break;
96 case 0x07: maText
= "#DIV/0!"; break;
97 case 0x0F: maText
= "#VALUE!"; break;
98 case 0x17: maText
= "#REF!"; break;
99 case 0x1D: maText
= "#NAME?"; break;
100 case 0x24: maText
= "#NUM!"; break;
101 case 0x2A: maText
= "#N/A"; break;
106 void XclPCItem::SetBool( bool bValue
, const OUString
& rText
)
108 meType
= EXC_PCITEM_BOOL
;
113 bool XclPCItem::IsEqual( const XclPCItem
& rItem
) const
115 if( meType
== rItem
.meType
) switch( meType
)
117 case EXC_PCITEM_INVALID
: return true;
118 case EXC_PCITEM_EMPTY
: return true;
119 case EXC_PCITEM_TEXT
: return maText
== rItem
.maText
;
120 case EXC_PCITEM_DOUBLE
: return mfValue
== rItem
.mfValue
;
121 case EXC_PCITEM_DATETIME
: return maDateTime
== rItem
.maDateTime
;
122 case EXC_PCITEM_INTEGER
: return mnValue
== rItem
.mnValue
;
123 case EXC_PCITEM_BOOL
: return mbValue
== rItem
.mbValue
;
124 case EXC_PCITEM_ERROR
: return mnError
== rItem
.mnError
;
125 default: OSL_FAIL( "XclPCItem::IsEqual - unknown pivot cache item type" );
130 bool XclPCItem::IsEmpty() const
132 return meType
== EXC_PCITEM_EMPTY
;
135 const OUString
* XclPCItem::GetText() const
137 return (meType
== EXC_PCITEM_TEXT
|| meType
== EXC_PCITEM_ERROR
) ? &maText
: nullptr;
140 const double* XclPCItem::GetDouble() const
142 return (meType
== EXC_PCITEM_DOUBLE
) ? &mfValue
: nullptr;
145 const DateTime
* XclPCItem::GetDateTime() const
147 return (meType
== EXC_PCITEM_DATETIME
) ? &maDateTime
: nullptr;
150 const sal_Int16
* XclPCItem::GetInteger() const
152 return (meType
== EXC_PCITEM_INTEGER
) ? &mnValue
: nullptr;
155 const sal_uInt16
* XclPCItem::GetError() const
157 return (meType
== EXC_PCITEM_ERROR
) ? &mnError
: nullptr;
160 const bool* XclPCItem::GetBool() const
162 return (meType
== EXC_PCITEM_BOOL
) ? &mbValue
: nullptr;
165 XclPCItemType
XclPCItem::GetType() const
170 // Field settings =============================================================
172 XclPCFieldInfo::XclPCFieldInfo() :
183 XclImpStream
& operator>>( XclImpStream
& rStrm
, XclPCFieldInfo
& rInfo
)
185 rInfo
.mnFlags
= rStrm
.ReaduInt16();
186 rInfo
.mnGroupChild
= rStrm
.ReaduInt16();
187 rInfo
.mnGroupBase
= rStrm
.ReaduInt16();
188 rInfo
.mnVisItems
= rStrm
.ReaduInt16();
189 rInfo
.mnGroupItems
= rStrm
.ReaduInt16();
190 rInfo
.mnBaseItems
= rStrm
.ReaduInt16();
191 rInfo
.mnOrigItems
= rStrm
.ReaduInt16();
192 if( rStrm
.GetRecLeft() >= 3 )
193 rInfo
.maName
= rStrm
.ReadUniString();
195 rInfo
.maName
.clear();
199 XclExpStream
& operator<<( XclExpStream
& rStrm
, const XclPCFieldInfo
& rInfo
)
203 << rInfo
.mnGroupChild
206 << rInfo
.mnGroupItems
209 << XclExpString( rInfo
.maName
);
212 // Numeric grouping field settings ============================================
214 XclPCNumGroupInfo::XclPCNumGroupInfo() :
215 mnFlags( EXC_SXNUMGROUP_AUTOMIN
| EXC_SXNUMGROUP_AUTOMAX
)
220 void XclPCNumGroupInfo::SetNumType()
222 SetXclDataType( EXC_SXNUMGROUP_TYPE_NUM
);
225 sal_Int32
XclPCNumGroupInfo::GetScDateType() const
227 sal_Int32 nScType
= 0;
228 switch( GetXclDataType() )
230 case EXC_SXNUMGROUP_TYPE_SEC
: nScType
= ScDPGroupBy::SECONDS
; break;
231 case EXC_SXNUMGROUP_TYPE_MIN
: nScType
= ScDPGroupBy::MINUTES
; break;
232 case EXC_SXNUMGROUP_TYPE_HOUR
: nScType
= ScDPGroupBy::HOURS
; break;
233 case EXC_SXNUMGROUP_TYPE_DAY
: nScType
= ScDPGroupBy::DAYS
; break;
234 case EXC_SXNUMGROUP_TYPE_MONTH
: nScType
= ScDPGroupBy::MONTHS
; break;
235 case EXC_SXNUMGROUP_TYPE_QUART
: nScType
= ScDPGroupBy::QUARTERS
; break;
236 case EXC_SXNUMGROUP_TYPE_YEAR
: nScType
= ScDPGroupBy::YEARS
; break;
237 default: SAL_WARN("sc.filter", "XclPCNumGroupInfo::GetScDateType - unexpected date type " << GetXclDataType() );
242 void XclPCNumGroupInfo::SetScDateType( sal_Int32 nScType
)
244 sal_uInt16 nXclType
= EXC_SXNUMGROUP_TYPE_NUM
;
247 case ScDPGroupBy::SECONDS
: nXclType
= EXC_SXNUMGROUP_TYPE_SEC
; break;
248 case ScDPGroupBy::MINUTES
: nXclType
= EXC_SXNUMGROUP_TYPE_MIN
; break;
249 case ScDPGroupBy::HOURS
: nXclType
= EXC_SXNUMGROUP_TYPE_HOUR
; break;
250 case ScDPGroupBy::DAYS
: nXclType
= EXC_SXNUMGROUP_TYPE_DAY
; break;
251 case ScDPGroupBy::MONTHS
: nXclType
= EXC_SXNUMGROUP_TYPE_MONTH
; break;
252 case ScDPGroupBy::QUARTERS
: nXclType
= EXC_SXNUMGROUP_TYPE_QUART
; break;
253 case ScDPGroupBy::YEARS
: nXclType
= EXC_SXNUMGROUP_TYPE_YEAR
; break;
255 SAL_INFO("sc.filter", "unexpected date type " << nScType
);
257 SetXclDataType( nXclType
);
260 sal_uInt16
XclPCNumGroupInfo::GetXclDataType() const
262 return ::extract_value
< sal_uInt16
>( mnFlags
, 2, 4 );
265 void XclPCNumGroupInfo::SetXclDataType( sal_uInt16 nXclType
)
267 ::insert_value( mnFlags
, nXclType
, 2, 4 );
270 XclImpStream
& operator>>( XclImpStream
& rStrm
, XclPCNumGroupInfo
& rInfo
)
272 rInfo
.mnFlags
= rStrm
.ReaduInt16();
276 XclExpStream
& operator<<( XclExpStream
& rStrm
, const XclPCNumGroupInfo
& rInfo
)
278 return rStrm
<< rInfo
.mnFlags
;
281 // Base class for pivot cache fields ==========================================
283 XclPCField::XclPCField( XclPCFieldType eFieldType
, sal_uInt16 nFieldIdx
) :
284 meFieldType( eFieldType
),
285 mnFieldIdx( nFieldIdx
)
289 XclPCField::~XclPCField()
293 bool XclPCField::IsSupportedField() const
295 return (meFieldType
!= EXC_PCFIELD_CALCED
) && (meFieldType
!= EXC_PCFIELD_UNKNOWN
);
298 bool XclPCField::IsStandardField() const
300 return meFieldType
== EXC_PCFIELD_STANDARD
;
303 bool XclPCField::IsStdGroupField() const
305 return meFieldType
== EXC_PCFIELD_STDGROUP
;
308 bool XclPCField::IsNumGroupField() const
310 return meFieldType
== EXC_PCFIELD_NUMGROUP
;
313 bool XclPCField::IsDateGroupField() const
315 return (meFieldType
== EXC_PCFIELD_DATEGROUP
) || (meFieldType
== EXC_PCFIELD_DATECHILD
);
318 bool XclPCField::IsGroupField() const
320 return IsStdGroupField() || IsNumGroupField() || IsDateGroupField();
323 bool XclPCField::IsGroupBaseField() const
325 return ::get_flag( maFieldInfo
.mnFlags
, EXC_SXFIELD_HASCHILD
);
328 bool XclPCField::IsGroupChildField() const
330 return (meFieldType
== EXC_PCFIELD_STDGROUP
) || (meFieldType
== EXC_PCFIELD_DATECHILD
);
333 bool XclPCField::HasOrigItems() const
335 return IsSupportedField() && ((maFieldInfo
.mnOrigItems
> 0) || HasPostponedItems());
338 bool XclPCField::HasInlineItems() const
340 return (IsStandardField() || IsGroupField()) && ((maFieldInfo
.mnGroupItems
> 0) || (maFieldInfo
.mnOrigItems
> 0));
343 bool XclPCField::HasPostponedItems() const
345 return IsStandardField() && ::get_flag( maFieldInfo
.mnFlags
, EXC_SXFIELD_POSTPONE
);
348 bool XclPCField::Has16BitIndexes() const
350 return IsStandardField() && ::get_flag( maFieldInfo
.mnFlags
, EXC_SXFIELD_16BIT
);
353 // Pivot cache settings =======================================================
355 /** Contains data for a pivot cache (SXDB record). */
356 XclPCInfo::XclPCInfo() :
359 mnFlags( EXC_SXDB_DEFAULTFLAGS
),
360 mnBlockRecs( EXC_SXDB_BLOCKRECS
),
363 mnSrcType( EXC_SXDB_SRC_SHEET
)
367 XclImpStream
& operator>>( XclImpStream
& rStrm
, XclPCInfo
& rInfo
)
369 rInfo
.mnSrcRecs
= rStrm
.ReaduInt32();
370 rInfo
.mnStrmId
= rStrm
.ReaduInt16();
371 rInfo
.mnFlags
= rStrm
.ReaduInt16();
372 rInfo
.mnBlockRecs
= rStrm
.ReaduInt16();
373 rInfo
.mnStdFields
= rStrm
.ReaduInt16();
374 rInfo
.mnTotalFields
= rStrm
.ReaduInt16();
376 rInfo
.mnSrcType
= rStrm
.ReaduInt16();
377 rInfo
.maUserName
= rStrm
.ReadUniString();
381 XclExpStream
& operator<<( XclExpStream
& rStrm
, const XclPCInfo
& rInfo
)
389 << rInfo
.mnTotalFields
392 << XclExpString( rInfo
.maUserName
);
397 // cached name ================================================================
399 XclImpStream
& operator>>( XclImpStream
& rStrm
, XclPTCachedName
& rCachedName
)
402 nStrLen
= rStrm
.ReaduInt16();
403 rCachedName
.mbUseCache
= nStrLen
== EXC_PT_NOSTRING
;
404 if( rCachedName
.mbUseCache
)
405 rCachedName
.maName
.clear();
407 rCachedName
.maName
= rStrm
.ReadUniString( nStrLen
);
411 XclExpStream
& operator<<( XclExpStream
& rStrm
, const XclPTCachedName
& rCachedName
)
413 if( rCachedName
.mbUseCache
)
414 rStrm
<< EXC_PT_NOSTRING
;
416 rStrm
<< XclExpString( rCachedName
.maName
, XclStrFlags::NONE
, EXC_PT_MAXSTRLEN
);
420 const OUString
* XclPTVisNameInfo::GetVisName() const
422 return HasVisName() ? &maVisName
.maName
: nullptr;
425 void XclPTVisNameInfo::SetVisName( const OUString
& rName
)
427 maVisName
.maName
= rName
;
428 maVisName
.mbUseCache
= rName
.isEmpty();
431 // Field item settings ========================================================
433 XclPTItemInfo::XclPTItemInfo() :
434 mnType( EXC_SXVI_TYPE_DATA
),
435 mnFlags( EXC_SXVI_DEFAULTFLAGS
),
436 mnCacheIdx( EXC_SXVI_DEFAULT_CACHE
)
440 XclImpStream
& operator>>( XclImpStream
& rStrm
, XclPTItemInfo
& rInfo
)
442 rInfo
.mnType
= rStrm
.ReaduInt16();
443 rInfo
.mnFlags
= rStrm
.ReaduInt16();
444 rInfo
.mnCacheIdx
= rStrm
.ReaduInt16();
445 rStrm
>> rInfo
.maVisName
;
449 XclExpStream
& operator<<( XclExpStream
& rStrm
, const XclPTItemInfo
& rInfo
)
458 // General field settings =====================================================
460 XclPTFieldInfo::XclPTFieldInfo() :
461 mnAxes( EXC_SXVD_AXIS_NONE
),
463 mnSubtotals( EXC_SXVD_SUBT_DEFAULT
),
465 mnCacheIdx( EXC_SXVD_DEFAULT_CACHE
)
469 DataPilotFieldOrientation
XclPTFieldInfo::GetApiOrient( sal_uInt16 nMask
) const
471 using namespace ::com::sun::star::sheet
;
472 DataPilotFieldOrientation eOrient
= DataPilotFieldOrientation_HIDDEN
;
473 sal_uInt16 nUsedAxes
= mnAxes
& nMask
;
474 if( nUsedAxes
& EXC_SXVD_AXIS_ROW
)
475 eOrient
= DataPilotFieldOrientation_ROW
;
476 else if( nUsedAxes
& EXC_SXVD_AXIS_COL
)
477 eOrient
= DataPilotFieldOrientation_COLUMN
;
478 else if( nUsedAxes
& EXC_SXVD_AXIS_PAGE
)
479 eOrient
= DataPilotFieldOrientation_PAGE
;
480 else if( nUsedAxes
& EXC_SXVD_AXIS_DATA
)
481 eOrient
= DataPilotFieldOrientation_DATA
;
485 void XclPTFieldInfo::AddApiOrient( DataPilotFieldOrientation eOrient
)
487 using namespace ::com::sun::star::sheet
;
490 case DataPilotFieldOrientation_ROW
: mnAxes
|= EXC_SXVD_AXIS_ROW
; break;
491 case DataPilotFieldOrientation_COLUMN
: mnAxes
|= EXC_SXVD_AXIS_COL
; break;
492 case DataPilotFieldOrientation_PAGE
: mnAxes
|= EXC_SXVD_AXIS_PAGE
; break;
493 case DataPilotFieldOrientation_DATA
: mnAxes
|= EXC_SXVD_AXIS_DATA
; break;
498 //TODO: should be a Sequence<GeneralFunction> in ScDPSaveData
499 void XclPTFieldInfo::GetSubtotals( XclPTSubtotalVec
& rSubtotals
) const
502 rSubtotals
.reserve( 16 );
504 if( mnSubtotals
& EXC_SXVD_SUBT_DEFAULT
) rSubtotals
.push_back( ScGeneralFunction::AUTO
);
505 if( mnSubtotals
& EXC_SXVD_SUBT_SUM
) rSubtotals
.push_back( ScGeneralFunction::SUM
);
506 if( mnSubtotals
& EXC_SXVD_SUBT_COUNT
) rSubtotals
.push_back( ScGeneralFunction::COUNT
);
507 if( mnSubtotals
& EXC_SXVD_SUBT_AVERAGE
) rSubtotals
.push_back( ScGeneralFunction::AVERAGE
);
508 if( mnSubtotals
& EXC_SXVD_SUBT_MAX
) rSubtotals
.push_back( ScGeneralFunction::MAX
);
509 if( mnSubtotals
& EXC_SXVD_SUBT_MIN
) rSubtotals
.push_back( ScGeneralFunction::MIN
);
510 if( mnSubtotals
& EXC_SXVD_SUBT_PROD
) rSubtotals
.push_back( ScGeneralFunction::PRODUCT
);
511 if( mnSubtotals
& EXC_SXVD_SUBT_COUNTNUM
) rSubtotals
.push_back( ScGeneralFunction::COUNTNUMS
);
512 if( mnSubtotals
& EXC_SXVD_SUBT_STDDEV
) rSubtotals
.push_back( ScGeneralFunction::STDEV
);
513 if( mnSubtotals
& EXC_SXVD_SUBT_STDDEVP
) rSubtotals
.push_back( ScGeneralFunction::STDEVP
);
514 if( mnSubtotals
& EXC_SXVD_SUBT_VAR
) rSubtotals
.push_back( ScGeneralFunction::VAR
);
515 if( mnSubtotals
& EXC_SXVD_SUBT_VARP
) rSubtotals
.push_back( ScGeneralFunction::VARP
);
518 void XclPTFieldInfo::SetSubtotals( const XclPTSubtotalVec
& rSubtotals
)
520 mnSubtotals
= EXC_SXVD_SUBT_NONE
;
521 for( const auto& rSubtotal
: rSubtotals
)
525 case ScGeneralFunction::AUTO
: mnSubtotals
|= EXC_SXVD_SUBT_DEFAULT
; break;
526 case ScGeneralFunction::SUM
: mnSubtotals
|= EXC_SXVD_SUBT_SUM
; break;
527 case ScGeneralFunction::COUNT
: mnSubtotals
|= EXC_SXVD_SUBT_COUNT
; break;
528 case ScGeneralFunction::AVERAGE
: mnSubtotals
|= EXC_SXVD_SUBT_AVERAGE
; break;
529 case ScGeneralFunction::MAX
: mnSubtotals
|= EXC_SXVD_SUBT_MAX
; break;
530 case ScGeneralFunction::MIN
: mnSubtotals
|= EXC_SXVD_SUBT_MIN
; break;
531 case ScGeneralFunction::PRODUCT
: mnSubtotals
|= EXC_SXVD_SUBT_PROD
; break;
532 case ScGeneralFunction::COUNTNUMS
: mnSubtotals
|= EXC_SXVD_SUBT_COUNTNUM
; break;
533 case ScGeneralFunction::STDEV
: mnSubtotals
|= EXC_SXVD_SUBT_STDDEV
; break;
534 case ScGeneralFunction::STDEVP
: mnSubtotals
|= EXC_SXVD_SUBT_STDDEVP
; break;
535 case ScGeneralFunction::VAR
: mnSubtotals
|= EXC_SXVD_SUBT_VAR
; break;
536 case ScGeneralFunction::VARP
: mnSubtotals
|= EXC_SXVD_SUBT_VARP
; break;
542 for( sal_uInt16 nMask
= 0x8000; nMask
; nMask
>>= 1 )
543 if( mnSubtotals
& nMask
)
547 XclImpStream
& operator>>( XclImpStream
& rStrm
, XclPTFieldInfo
& rInfo
)
549 // rInfo.mnCacheIdx is not part of the SXVD record
550 rInfo
.mnAxes
= rStrm
.ReaduInt16();
551 rInfo
.mnSubtCount
= rStrm
.ReaduInt16();
552 rInfo
.mnSubtotals
= rStrm
.ReaduInt16();
553 rInfo
.mnItemCount
= rStrm
.ReaduInt16();
554 rStrm
>> rInfo
.maVisName
;
558 XclExpStream
& operator<<( XclExpStream
& rStrm
, const XclPTFieldInfo
& rInfo
)
560 // rInfo.mnCacheIdx is not part of the SXVD record
569 // Extended field settings ====================================================
571 XclPTFieldExtInfo::XclPTFieldExtInfo() :
572 mnFlags( EXC_SXVDEX_DEFAULTFLAGS
),
573 mnSortField( EXC_SXVDEX_SORT_OWN
),
574 mnShowField( EXC_SXVDEX_SHOW_NONE
),
579 sal_Int32
XclPTFieldExtInfo::GetApiSortMode() const
581 sal_Int32 nSortMode
= ScDPSortMode::MANUAL
;
582 if( ::get_flag( mnFlags
, EXC_SXVDEX_SORT
) )
583 nSortMode
= (mnSortField
== EXC_SXVDEX_SORT_OWN
) ? ScDPSortMode::NAME
: ScDPSortMode::DATA
;
587 void XclPTFieldExtInfo::SetApiSortMode( sal_Int32 nSortMode
)
589 bool bSort
= (nSortMode
== ScDPSortMode::NAME
) || (nSortMode
== ScDPSortMode::DATA
);
590 ::set_flag( mnFlags
, EXC_SXVDEX_SORT
, bSort
);
591 if( nSortMode
== ScDPSortMode::NAME
)
592 mnSortField
= EXC_SXVDEX_SORT_OWN
; // otherwise sort field has to be set by caller
595 sal_Int32
XclPTFieldExtInfo::GetApiAutoShowMode() const
597 return ::get_flagvalue( mnFlags
, EXC_SXVDEX_AUTOSHOW_ASC
,
598 ScDPShowItemsMode::FROM_TOP
, ScDPShowItemsMode::FROM_BOTTOM
);
601 void XclPTFieldExtInfo::SetApiAutoShowMode( sal_Int32 nShowMode
)
603 ::set_flag( mnFlags
, EXC_SXVDEX_AUTOSHOW_ASC
, nShowMode
== ScDPShowItemsMode::FROM_TOP
);
606 sal_Int32
XclPTFieldExtInfo::GetApiAutoShowCount() const
608 return ::extract_value
< sal_Int32
>( mnFlags
, 24, 8 );
611 void XclPTFieldExtInfo::SetApiAutoShowCount( sal_Int32 nShowCount
)
613 ::insert_value( mnFlags
, limit_cast
< sal_uInt8
>( nShowCount
), 24, 8 );
616 sal_Int32
XclPTFieldExtInfo::GetApiLayoutMode() const
618 sal_Int32 nLayoutMode
= ScDPLayoutMode::TABULAR_LAYOUT
;
619 if( ::get_flag( mnFlags
, EXC_SXVDEX_LAYOUT_REPORT
) )
620 nLayoutMode
= ::get_flag( mnFlags
, EXC_SXVDEX_LAYOUT_TOP
) ?
621 ScDPLayoutMode::OUTLINE_SUBTOTALS_TOP
: ScDPLayoutMode::OUTLINE_SUBTOTALS_BOTTOM
;
625 void XclPTFieldExtInfo::SetApiLayoutMode( sal_Int32 nLayoutMode
)
627 ::set_flag( mnFlags
, EXC_SXVDEX_LAYOUT_REPORT
, nLayoutMode
!= ScDPLayoutMode::TABULAR_LAYOUT
);
628 ::set_flag( mnFlags
, EXC_SXVDEX_LAYOUT_TOP
, nLayoutMode
== ScDPLayoutMode::OUTLINE_SUBTOTALS_TOP
);
631 XclImpStream
& operator>>( XclImpStream
& rStrm
, XclPTFieldExtInfo
& rInfo
)
633 sal_uInt8 nNameLen
= 0;
634 rInfo
.mnFlags
= rStrm
.ReaduInt32();
635 rInfo
.mnSortField
= rStrm
.ReaduInt16();
636 rInfo
.mnShowField
= rStrm
.ReaduInt16();
637 rInfo
.mnNumFmt
= rStrm
.ReaduInt16();
638 nNameLen
= rStrm
.ReaduInt8();
641 if (nNameLen
!= 0xFF)
642 // Custom field total name is used. Pick it up.
643 rInfo
.mpFieldTotalName
= rStrm
.ReadUniString(nNameLen
, 0);
648 XclExpStream
& operator<<( XclExpStream
& rStrm
, const XclPTFieldExtInfo
& rInfo
)
650 rStrm
<< rInfo
.mnFlags
653 << EXC_SXVDEX_FORMAT_NONE
;
655 if (rInfo
.mpFieldTotalName
&& !rInfo
.mpFieldTotalName
->isEmpty())
657 OUString aFinalName
= *rInfo
.mpFieldTotalName
;
658 if (aFinalName
.getLength() >= 254)
659 aFinalName
= aFinalName
.copy(0, 254);
660 sal_uInt8 nNameLen
= static_cast<sal_uInt8
>(aFinalName
.getLength());
662 rStrm
.WriteZeroBytes(10);
663 rStrm
<< XclExpString(aFinalName
, XclStrFlags::NoHeader
);
667 rStrm
<< sal_uInt16(0xFFFF);
668 rStrm
.WriteZeroBytes(8);
673 // Page field settings ========================================================
675 XclPTPageFieldInfo::XclPTPageFieldInfo() :
677 mnSelItem( EXC_SXPI_ALLITEMS
),
682 XclImpStream
& operator>>( XclImpStream
& rStrm
, XclPTPageFieldInfo
& rInfo
)
684 rInfo
.mnField
= rStrm
.ReaduInt16();
685 rInfo
.mnSelItem
= rStrm
.ReaduInt16();
686 rInfo
.mnObjId
= rStrm
.ReaduInt16();
690 XclExpStream
& operator<<( XclExpStream
& rStrm
, const XclPTPageFieldInfo
& rInfo
)
698 // Data field settings ========================================================
700 XclPTDataFieldInfo::XclPTDataFieldInfo() :
702 mnAggFunc( EXC_SXDI_FUNC_SUM
),
703 mnRefType( EXC_SXDI_REF_NORMAL
),
710 ScGeneralFunction
XclPTDataFieldInfo::GetApiAggFunc() const
712 ScGeneralFunction eAggFunc
;
715 case EXC_SXDI_FUNC_SUM
: eAggFunc
= ScGeneralFunction::SUM
; break;
716 case EXC_SXDI_FUNC_COUNT
: eAggFunc
= ScGeneralFunction::COUNT
; break;
717 case EXC_SXDI_FUNC_AVERAGE
: eAggFunc
= ScGeneralFunction::AVERAGE
; break;
718 case EXC_SXDI_FUNC_MAX
: eAggFunc
= ScGeneralFunction::MAX
; break;
719 case EXC_SXDI_FUNC_MIN
: eAggFunc
= ScGeneralFunction::MIN
; break;
720 case EXC_SXDI_FUNC_PRODUCT
: eAggFunc
= ScGeneralFunction::PRODUCT
; break;
721 case EXC_SXDI_FUNC_COUNTNUM
: eAggFunc
= ScGeneralFunction::COUNTNUMS
; break;
722 case EXC_SXDI_FUNC_STDDEV
: eAggFunc
= ScGeneralFunction::STDEV
; break;
723 case EXC_SXDI_FUNC_STDDEVP
: eAggFunc
= ScGeneralFunction::STDEVP
; break;
724 case EXC_SXDI_FUNC_VAR
: eAggFunc
= ScGeneralFunction::VAR
; break;
725 case EXC_SXDI_FUNC_VARP
: eAggFunc
= ScGeneralFunction::VARP
; break;
726 default: eAggFunc
= ScGeneralFunction::SUM
;
731 void XclPTDataFieldInfo::SetApiAggFunc( ScGeneralFunction eAggFunc
)
735 case ScGeneralFunction::SUM
: mnAggFunc
= EXC_SXDI_FUNC_SUM
; break;
736 case ScGeneralFunction::COUNT
: mnAggFunc
= EXC_SXDI_FUNC_COUNT
; break;
737 case ScGeneralFunction::AVERAGE
: mnAggFunc
= EXC_SXDI_FUNC_AVERAGE
; break;
738 case ScGeneralFunction::MAX
: mnAggFunc
= EXC_SXDI_FUNC_MAX
; break;
739 case ScGeneralFunction::MIN
: mnAggFunc
= EXC_SXDI_FUNC_MIN
; break;
740 case ScGeneralFunction::PRODUCT
: mnAggFunc
= EXC_SXDI_FUNC_PRODUCT
; break;
741 case ScGeneralFunction::COUNTNUMS
: mnAggFunc
= EXC_SXDI_FUNC_COUNTNUM
; break;
742 case ScGeneralFunction::STDEV
: mnAggFunc
= EXC_SXDI_FUNC_STDDEV
; break;
743 case ScGeneralFunction::STDEVP
: mnAggFunc
= EXC_SXDI_FUNC_STDDEVP
; break;
744 case ScGeneralFunction::VAR
: mnAggFunc
= EXC_SXDI_FUNC_VAR
; break;
745 case ScGeneralFunction::VARP
: mnAggFunc
= EXC_SXDI_FUNC_VARP
; break;
746 default: mnAggFunc
= EXC_SXDI_FUNC_SUM
;
750 sal_Int32
XclPTDataFieldInfo::GetApiRefType() const
752 namespace ScDPRefType
= ::com::sun::star::sheet::DataPilotFieldReferenceType
;
756 case EXC_SXDI_REF_DIFF
: nRefType
= ScDPRefType::ITEM_DIFFERENCE
; break;
757 case EXC_SXDI_REF_PERC
: nRefType
= ScDPRefType::ITEM_PERCENTAGE
; break;
758 case EXC_SXDI_REF_PERC_DIFF
: nRefType
= ScDPRefType::ITEM_PERCENTAGE_DIFFERENCE
; break;
759 case EXC_SXDI_REF_RUN_TOTAL
: nRefType
= ScDPRefType::RUNNING_TOTAL
; break;
760 case EXC_SXDI_REF_PERC_ROW
: nRefType
= ScDPRefType::ROW_PERCENTAGE
; break;
761 case EXC_SXDI_REF_PERC_COL
: nRefType
= ScDPRefType::COLUMN_PERCENTAGE
; break;
762 case EXC_SXDI_REF_PERC_TOTAL
: nRefType
= ScDPRefType::TOTAL_PERCENTAGE
; break;
763 case EXC_SXDI_REF_INDEX
: nRefType
= ScDPRefType::INDEX
; break;
764 default: nRefType
= ScDPRefType::NONE
;
769 void XclPTDataFieldInfo::SetApiRefType( sal_Int32 nRefType
)
771 namespace ScDPRefType
= ::com::sun::star::sheet::DataPilotFieldReferenceType
;
774 case ScDPRefType::ITEM_DIFFERENCE
: mnRefType
= EXC_SXDI_REF_DIFF
; break;
775 case ScDPRefType::ITEM_PERCENTAGE
: mnRefType
= EXC_SXDI_REF_PERC
; break;
776 case ScDPRefType::ITEM_PERCENTAGE_DIFFERENCE
: mnRefType
= EXC_SXDI_REF_PERC_DIFF
; break;
777 case ScDPRefType::RUNNING_TOTAL
: mnRefType
= EXC_SXDI_REF_RUN_TOTAL
; break;
778 case ScDPRefType::ROW_PERCENTAGE
: mnRefType
= EXC_SXDI_REF_PERC_ROW
; break;
779 case ScDPRefType::COLUMN_PERCENTAGE
: mnRefType
= EXC_SXDI_REF_PERC_COL
; break;
780 case ScDPRefType::TOTAL_PERCENTAGE
: mnRefType
= EXC_SXDI_REF_PERC_TOTAL
;break;
781 case ScDPRefType::INDEX
: mnRefType
= EXC_SXDI_REF_INDEX
; break;
782 default: mnRefType
= EXC_SXDI_REF_NORMAL
;
786 sal_Int32
XclPTDataFieldInfo::GetApiRefItemType() const
788 sal_Int32 nRefItemType
;
791 case EXC_SXDI_PREVITEM
: nRefItemType
= ScDPRefItemType::PREVIOUS
; break;
792 case EXC_SXDI_NEXTITEM
: nRefItemType
= ScDPRefItemType::NEXT
; break;
793 default: nRefItemType
= ScDPRefItemType::NAMED
;
798 void XclPTDataFieldInfo::SetApiRefItemType( sal_Int32 nRefItemType
)
800 switch( nRefItemType
)
802 case ScDPRefItemType::PREVIOUS
: mnRefItem
= EXC_SXDI_PREVITEM
; break;
803 case ScDPRefItemType::NEXT
: mnRefItem
= EXC_SXDI_NEXTITEM
; break;
804 // nothing for named item reference
808 XclImpStream
& operator>>( XclImpStream
& rStrm
, XclPTDataFieldInfo
& rInfo
)
810 rInfo
.mnField
= rStrm
.ReaduInt16();
811 rInfo
.mnAggFunc
= rStrm
.ReaduInt16();
812 rInfo
.mnRefType
= rStrm
.ReaduInt16();
813 rInfo
.mnRefField
= rStrm
.ReaduInt16();
814 rInfo
.mnRefItem
= rStrm
.ReaduInt16();
815 rInfo
.mnNumFmt
= rStrm
.ReaduInt16();
816 rStrm
>> rInfo
.maVisName
;
820 XclExpStream
& operator<<( XclExpStream
& rStrm
, const XclPTDataFieldInfo
& rInfo
)
832 // Pivot table settings =======================================================
834 XclPTInfo::XclPTInfo() :
836 mnCacheIdx( 0xFFFF ),
837 mnDataAxis( EXC_SXVD_AXIS_NONE
),
838 mnDataPos( EXC_SXVIEW_DATALAST
),
846 mnFlags( EXC_SXVIEW_DEFAULTFLAGS
),
847 mnAutoFmtIdx( EXC_SXVIEW_AUTOFMT
)
851 XclImpStream
& operator>>( XclImpStream
& rStrm
, XclPTInfo
& rInfo
)
853 sal_uInt16 nTabLen
, nDataLen
;
855 rStrm
>> rInfo
.maOutXclRange
;
856 rInfo
.mnFirstHeadRow
= rStrm
.ReaduInt16();
857 rStrm
>> rInfo
.maDataXclPos
;
858 rInfo
.mnCacheIdx
= rStrm
.ReaduInt16();
860 rInfo
.mnDataAxis
= rStrm
.ReaduInt16();
861 rInfo
.mnDataPos
= rStrm
.ReaduInt16();
862 rInfo
.mnFields
= rStrm
.ReaduInt16();
863 rInfo
.mnRowFields
= rStrm
.ReaduInt16();
864 rInfo
.mnColFields
= rStrm
.ReaduInt16();
865 rInfo
.mnPageFields
= rStrm
.ReaduInt16();
866 rInfo
.mnDataFields
= rStrm
.ReaduInt16();
867 rInfo
.mnDataRows
= rStrm
.ReaduInt16();
868 rInfo
.mnDataCols
= rStrm
.ReaduInt16();
869 rInfo
.mnFlags
= rStrm
.ReaduInt16();
870 rInfo
.mnAutoFmtIdx
= rStrm
.ReaduInt16();
871 nTabLen
= rStrm
.ReaduInt16();
872 nDataLen
= rStrm
.ReaduInt16();
873 rInfo
.maTableName
= rStrm
.ReadUniString( nTabLen
);
874 rInfo
.maDataName
= rStrm
.ReadUniString( nDataLen
);
878 XclExpStream
& operator<<( XclExpStream
& rStrm
, const XclPTInfo
& rInfo
)
880 XclExpString
aXclTableName( rInfo
.maTableName
);
881 XclExpString
aXclDataName( rInfo
.maDataName
);
883 rStrm
<< rInfo
.maOutXclRange
884 << rInfo
.mnFirstHeadRow
885 << rInfo
.maDataXclPos
888 << rInfo
.mnDataAxis
<< rInfo
.mnDataPos
890 << rInfo
.mnRowFields
<< rInfo
.mnColFields
891 << rInfo
.mnPageFields
<< rInfo
.mnDataFields
892 << rInfo
.mnDataRows
<< rInfo
.mnDataCols
894 << rInfo
.mnAutoFmtIdx
895 << aXclTableName
.Len() << aXclDataName
.Len();
896 aXclTableName
.WriteFlagField( rStrm
);
897 aXclTableName
.WriteBuffer( rStrm
);
898 aXclDataName
.WriteFlagField( rStrm
);
899 aXclDataName
.WriteBuffer( rStrm
);
903 // Extended pivot table settings ==============================================
905 XclPTExtInfo::XclPTExtInfo() :
906 mnSxformulaRecs( 0 ),
910 mnFlags( EXC_SXEX_DEFAULTFLAGS
)
914 XclImpStream
& operator>>( XclImpStream
& rStrm
, XclPTExtInfo
& rInfo
)
916 rInfo
.mnSxformulaRecs
= rStrm
.ReaduInt16();
918 rInfo
.mnSxselectRecs
= rStrm
.ReaduInt16();
919 rInfo
.mnPagePerRow
= rStrm
.ReaduInt16();
920 rInfo
.mnPagePerCol
= rStrm
.ReaduInt16();
921 rInfo
.mnFlags
= rStrm
.ReaduInt32();
925 XclExpStream
& operator<<( XclExpStream
& rStrm
, const XclPTExtInfo
& rInfo
)
928 << rInfo
.mnSxformulaRecs
929 << EXC_PT_NOSTRING
// length of alt. error text
930 << EXC_PT_NOSTRING
// length of alt. empty text
931 << EXC_PT_NOSTRING
// length of tag
932 << rInfo
.mnSxselectRecs
933 << rInfo
.mnPagePerRow
934 << rInfo
.mnPagePerCol
936 << EXC_PT_NOSTRING
// length of page field style name
937 << EXC_PT_NOSTRING
// length of table style name
938 << EXC_PT_NOSTRING
; // length of vacate style name
941 // Pivot table autoformat settings ============================================
944 classic : 10 08 00 00 00 00 00 00 20 00 00 00 01 00 00 00 00
945 default : 10 08 00 00 00 00 00 00 20 00 00 00 01 00 00 00 00
946 report01 : 10 08 02 00 00 00 00 00 20 00 00 00 00 10 00 00 00
947 report02 : 10 08 02 00 00 00 00 00 20 00 00 00 01 10 00 00 00
948 report03 : 10 08 02 00 00 00 00 00 20 00 00 00 02 10 00 00 00
949 report04 : 10 08 02 00 00 00 00 00 20 00 00 00 03 10 00 00 00
950 report05 : 10 08 02 00 00 00 00 00 20 00 00 00 04 10 00 00 00
951 report06 : 10 08 02 00 00 00 00 00 20 00 00 00 05 10 00 00 00
952 report07 : 10 08 02 00 00 00 00 00 20 00 00 00 06 10 00 00 00
953 report08 : 10 08 02 00 00 00 00 00 20 00 00 00 07 10 00 00 00
954 report09 : 10 08 02 00 00 00 00 00 20 00 00 00 08 10 00 00 00
955 report10 : 10 08 02 00 00 00 00 00 20 00 00 00 09 10 00 00 00
956 table01 : 10 08 00 00 00 00 00 00 20 00 00 00 0a 10 00 00 00
957 table02 : 10 08 00 00 00 00 00 00 20 00 00 00 0b 10 00 00 00
958 table03 : 10 08 00 00 00 00 00 00 20 00 00 00 0c 10 00 00 00
959 table04 : 10 08 00 00 00 00 00 00 20 00 00 00 0d 10 00 00 00
960 table05 : 10 08 00 00 00 00 00 00 20 00 00 00 0e 10 00 00 00
961 table06 : 10 08 00 00 00 00 00 00 20 00 00 00 0f 10 00 00 00
962 table07 : 10 08 00 00 00 00 00 00 20 00 00 00 10 10 00 00 00
963 table08 : 10 08 00 00 00 00 00 00 20 00 00 00 11 10 00 00 00
964 table09 : 10 08 00 00 00 00 00 00 20 00 00 00 12 10 00 00 00
965 table10 : 10 08 00 00 00 00 00 00 20 00 00 00 13 10 00 00 00
966 none : 10 08 00 00 00 00 00 00 20 00 00 00 15 10 00 00 00
969 XclPTViewEx9Info::XclPTViewEx9Info() :
976 void XclPTViewEx9Info::Init( const ScDPObject
& rDPObj
)
978 if( rDPObj
.GetHeaderLayout() )
987 // TODO : sync with autoformat indices
993 const ScDPSaveData
* pData
= rDPObj
.GetSaveData();
996 const std::optional
<OUString
> & pGrandTotal
= pData
->GetGrandTotalName();
998 maGrandTotalName
= *pGrandTotal
;
1002 XclImpStream
& operator>>( XclImpStream
& rStrm
, XclPTViewEx9Info
& rInfo
)
1005 rInfo
.mbReport
= rStrm
.ReaduInt32(); /// 2 for report* fmts ?
1007 rInfo
.mnAutoFormat
= rStrm
.ReaduInt8();
1008 rInfo
.mnGridLayout
= rStrm
.ReaduInt8();
1009 rInfo
.maGrandTotalName
= rStrm
.ReadUniString();
1013 XclExpStream
& operator<<( XclExpStream
& rStrm
, const XclPTViewEx9Info
& rInfo
)
1016 << EXC_PT_AUTOFMT_HEADER
1018 << EXC_PT_AUTOFMT_ZERO
1019 << EXC_PT_AUTOFMT_FLAGS
1020 << rInfo
.mnAutoFormat
1021 << rInfo
.mnGridLayout
1022 << XclExpString(rInfo
.maGrandTotalName
, XclStrFlags::NONE
, EXC_PT_MAXSTRLEN
);
1025 XclPTAddl::XclPTAddl() :
1026 mbCompactMode(false)
1030 XclImpStream
& operator>>(XclImpStream
& rStrm
, XclPTAddl
& rInfo
)
1033 sal_uInt8 sxc
= rStrm
.ReaduInt8();
1034 sal_uInt8 sxd
= rStrm
.ReaduInt8();
1035 if(sxc
== 0x00 && sxd
== 0x19) // SxcView / sxdVer12Info
1037 sal_uInt32 nFlags
= rStrm
.ReaduInt32();
1038 rInfo
.mbCompactMode
= ((nFlags
& 0x00000008) != 0);
1043 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */