LCOV - code coverage report
Current view: top level - sc/source/filter/oox - pivottablebuffer.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 7 654 1.1 %
Date: 2012-08-25 Functions: 4 68 5.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 3 896 0.3 %

           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 "pivottablebuffer.hxx"
      30                 :            : 
      31                 :            : #include <set>
      32                 :            : #include <com/sun/star/container/XIndexAccess.hpp>
      33                 :            : #include <com/sun/star/container/XNameAccess.hpp>
      34                 :            : #include <com/sun/star/sheet/CellFlags.hpp>
      35                 :            : #include <com/sun/star/sheet/DataPilotFieldAutoShowInfo.hpp>
      36                 :            : #include <com/sun/star/sheet/DataPilotFieldLayoutInfo.hpp>
      37                 :            : #include <com/sun/star/sheet/DataPilotFieldLayoutMode.hpp>
      38                 :            : #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
      39                 :            : #include <com/sun/star/sheet/DataPilotFieldReference.hpp>
      40                 :            : #include <com/sun/star/sheet/DataPilotFieldReferenceItemType.hpp>
      41                 :            : #include <com/sun/star/sheet/DataPilotFieldReferenceType.hpp>
      42                 :            : #include <com/sun/star/sheet/DataPilotFieldShowItemsMode.hpp>
      43                 :            : #include <com/sun/star/sheet/DataPilotFieldSortInfo.hpp>
      44                 :            : #include <com/sun/star/sheet/DataPilotFieldSortMode.hpp>
      45                 :            : #include <com/sun/star/sheet/GeneralFunction.hpp>
      46                 :            : #include <com/sun/star/sheet/XDataPilotDataLayoutFieldSupplier.hpp>
      47                 :            : #include <com/sun/star/sheet/XDataPilotField.hpp>
      48                 :            : #include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp>
      49                 :            : #include <com/sun/star/sheet/XSheetOperation.hpp>
      50                 :            : #include "oox/helper/attributelist.hxx"
      51                 :            : #include "oox/helper/containerhelper.hxx"
      52                 :            : #include "oox/helper/propertyset.hxx"
      53                 :            : #include "oox/token/properties.hxx"
      54                 :            : #include "addressconverter.hxx"
      55                 :            : #include "biffinputstream.hxx"
      56                 :            : 
      57                 :            : #include "dapiuno.hxx"
      58                 :            : #include "dpobject.hxx"
      59                 :            : #include "dpsave.hxx"
      60                 :            : 
      61                 :            : namespace oox {
      62                 :            : namespace xls {
      63                 :            : 
      64                 :            : // ============================================================================
      65                 :            : 
      66                 :            : using namespace ::com::sun::star::container;
      67                 :            : using namespace ::com::sun::star::sheet;
      68                 :            : using namespace ::com::sun::star::table;
      69                 :            : using namespace ::com::sun::star::uno;
      70                 :            : using namespace com::sun::star;
      71                 :            : 
      72                 :            : using ::rtl::OUString;
      73                 :            : 
      74                 :            : // ============================================================================
      75                 :            : 
      76                 :            : namespace {
      77                 :            : 
      78                 :            : const sal_Int32 OOX_PT_DATALAYOUTFIELD              = -2;           /// Placeholder index of data layout field.
      79                 :            : 
      80                 :            : const sal_Int32 OOX_PT_PREVIOUS_ITEM                = 0x001000FC;   /// Calculation of data item result is based on previous item.
      81                 :            : const sal_Int32 OOX_PT_NEXT_ITEM                    = 0x001000FD;   /// Calculation of data item result is based on next item.
      82                 :            : 
      83                 :            : // ----------------------------------------------------------------------------
      84                 :            : 
      85                 :            : const sal_uInt32 BIFF12_PTFIELD_DATAFIELD           = 0x00000008;
      86                 :            : const sal_uInt32 BIFF12_PTFIELD_DEFAULT             = 0x00000100;
      87                 :            : const sal_uInt32 BIFF12_PTFIELD_SUM                 = 0x00000200;
      88                 :            : const sal_uInt32 BIFF12_PTFIELD_COUNTA              = 0x00000400;
      89                 :            : const sal_uInt32 BIFF12_PTFIELD_AVERAGE             = 0x00000800;
      90                 :            : const sal_uInt32 BIFF12_PTFIELD_MAX                 = 0x00001000;
      91                 :            : const sal_uInt32 BIFF12_PTFIELD_MIN                 = 0x00002000;
      92                 :            : const sal_uInt32 BIFF12_PTFIELD_PRODUCT             = 0x00004000;
      93                 :            : const sal_uInt32 BIFF12_PTFIELD_COUNT               = 0x00008000;
      94                 :            : const sal_uInt32 BIFF12_PTFIELD_STDDEV              = 0x00010000;
      95                 :            : const sal_uInt32 BIFF12_PTFIELD_STDDEVP             = 0x00020000;
      96                 :            : const sal_uInt32 BIFF12_PTFIELD_VAR                 = 0x00040000;
      97                 :            : const sal_uInt32 BIFF12_PTFIELD_VARP                = 0x00080000;
      98                 :            : 
      99                 :            : const sal_uInt32 BIFF12_PTFIELD_SHOWALL             = 0x00000020;
     100                 :            : const sal_uInt32 BIFF12_PTFIELD_OUTLINE             = 0x00000040;
     101                 :            : const sal_uInt32 BIFF12_PTFIELD_INSERTBLANKROW      = 0x00000080;
     102                 :            : const sal_uInt32 BIFF12_PTFIELD_SUBTOTALTOP         = 0x00000100;
     103                 :            : const sal_uInt32 BIFF12_PTFIELD_INSERTPAGEBREAK     = 0x00000800;
     104                 :            : const sal_uInt32 BIFF12_PTFIELD_AUTOSORT            = 0x00001000;
     105                 :            : const sal_uInt32 BIFF12_PTFIELD_SORTASCENDING       = 0x00002000;
     106                 :            : const sal_uInt32 BIFF12_PTFIELD_AUTOSHOW            = 0x00004000;
     107                 :            : const sal_uInt32 BIFF12_PTFIELD_AUTOSHOWTOP         = 0x00008000;
     108                 :            : const sal_uInt32 BIFF12_PTFIELD_MULTIPAGEITEMS      = 0x00080000;
     109                 :            : 
     110                 :            : const sal_uInt16 BIFF12_PTFITEM_HIDDEN              = 0x0001;
     111                 :            : const sal_uInt16 BIFF12_PTFITEM_HIDEDETAILS         = 0x0002;
     112                 :            : 
     113                 :            : const sal_uInt8 BIFF12_PTPAGEFIELD_HASNAME          = 0x01;
     114                 :            : const sal_uInt8 BIFF12_PTPAGEFIELD_HASOLAPCAPTION   = 0x02;
     115                 :            : const sal_Int32 BIFF12_PTPAGEFIELD_MULTIITEMS       = 0x001000FE;
     116                 :            : 
     117                 :            : const sal_uInt16 BIFF12_PTFILTER_HASNAME            = 0x0001;
     118                 :            : const sal_uInt16 BIFF12_PTFILTER_HASDESCRIPTION     = 0x0002;
     119                 :            : const sal_uInt16 BIFF12_PTFILTER_HASSTRVALUE1       = 0x0004;
     120                 :            : const sal_uInt16 BIFF12_PTFILTER_HASSTRVALUE2       = 0x0008;
     121                 :            : 
     122                 :            : const sal_uInt8 BIFF12_TOP10FILTER_TOP              = 0x01;
     123                 :            : const sal_uInt8 BIFF12_TOP10FILTER_PERCENT          = 0x02;
     124                 :            : 
     125                 :            : const sal_uInt32 BIFF12_PTDEF_SHOWITEMS             = 0x00000100;
     126                 :            : const sal_uInt32 BIFF12_PTDEF_DISABLEFIELDLIST      = 0x00000400;
     127                 :            : const sal_uInt32 BIFF12_PTDEF_HIDECALCMEMBERS       = 0x00001000;
     128                 :            : const sal_uInt32 BIFF12_PTDEF_WITHHIDDENTOTALS      = 0x00002000;
     129                 :            : const sal_uInt32 BIFF12_PTDEF_HIDEDRILL             = 0x00100000;
     130                 :            : const sal_uInt32 BIFF12_PTDEF_PRINTDRILL            = 0x00200000;
     131                 :            : const sal_uInt32 BIFF12_PTDEF_HIDEHEADERS           = 0x80000000;
     132                 :            : 
     133                 :            : const sal_uInt32 BIFF12_PTDEF_SHOWEMPTYROW          = 0x00000004;
     134                 :            : const sal_uInt32 BIFF12_PTDEF_SHOWEMPTYCOL          = 0x00000008;
     135                 :            : const sal_uInt32 BIFF12_PTDEF_ENABLEDRILL           = 0x00000020;
     136                 :            : const sal_uInt32 BIFF12_PTDEF_PRESERVEFORMATTING    = 0x00000080;
     137                 :            : const sal_uInt32 BIFF12_PTDEF_USEAUTOFORMAT         = 0x00000100;
     138                 :            : const sal_uInt32 BIFF12_PTDEF_SHOWERROR             = 0x00000200;
     139                 :            : const sal_uInt32 BIFF12_PTDEF_SHOWMISSING           = 0x00000400;
     140                 :            : const sal_uInt32 BIFF12_PTDEF_PAGEOVERTHENDOWN      = 0x00000800;
     141                 :            : const sal_uInt32 BIFF12_PTDEF_SUBTOTALHIDDENITEMS   = 0x00001000;
     142                 :            : const sal_uInt32 BIFF12_PTDEF_ROWGRANDTOTALS        = 0x00002000;
     143                 :            : const sal_uInt32 BIFF12_PTDEF_COLGRANDTOTALS        = 0x00004000;
     144                 :            : const sal_uInt32 BIFF12_PTDEF_FIELDPRINTTITLES      = 0x00008000;
     145                 :            : const sal_uInt32 BIFF12_PTDEF_ITEMPRINTTITLES       = 0x00020000;
     146                 :            : const sal_uInt32 BIFF12_PTDEF_MERGEITEM             = 0x00040000;
     147                 :            : const sal_uInt32 BIFF12_PTDEF_HASDATACAPTION        = 0x00080000;
     148                 :            : const sal_uInt32 BIFF12_PTDEF_HASGRANDTOTALCAPTION  = 0x00100000;
     149                 :            : const sal_uInt32 BIFF12_PTDEF_HASPAGESTYLE          = 0x00200000;
     150                 :            : const sal_uInt32 BIFF12_PTDEF_HASPIVOTTABLESTYLE    = 0x00400000;
     151                 :            : const sal_uInt32 BIFF12_PTDEF_HASVACATEDSTYLE       = 0x00800000;
     152                 :            : const sal_uInt32 BIFF12_PTDEF_APPLYNUMFMT           = 0x01000000;
     153                 :            : const sal_uInt32 BIFF12_PTDEF_APPLYFONT             = 0x02000000;
     154                 :            : const sal_uInt32 BIFF12_PTDEF_APPLYALIGNMENT        = 0x04000000;
     155                 :            : const sal_uInt32 BIFF12_PTDEF_APPLYBORDER           = 0x08000000;
     156                 :            : const sal_uInt32 BIFF12_PTDEF_APPLYFILL             = 0x10000000;
     157                 :            : const sal_uInt32 BIFF12_PTDEF_APPLYPROTECTION       = 0x20000000;
     158                 :            : const sal_uInt32 BIFF12_PTDEF_HASTAG                = 0x40000000;
     159                 :            : 
     160                 :            : const sal_uInt32 BIFF12_PTDEF_NOERRORCAPTION        = 0x00000040;
     161                 :            : const sal_uInt32 BIFF12_PTDEF_NOMISSINGCAPTION      = 0x00000080;
     162                 :            : const sal_uInt32 BIFF12_PTDEF_HASROWHEADERCAPTION   = 0x00000400;
     163                 :            : const sal_uInt32 BIFF12_PTDEF_HASCOLHEADERCAPTION   = 0x00000800;
     164                 :            : const sal_uInt32 BIFF12_PTDEF_FIELDLISTSORTASC      = 0x00001000;
     165                 :            : const sal_uInt32 BIFF12_PTDEF_NOCUSTOMLISTSORT      = 0x00004000;
     166                 :            : 
     167                 :            : const sal_uInt8 BIFF12_PTDEF_ROWAXIS                = 1;
     168                 :            : const sal_uInt8 BIFF12_PTDEF_COLAXIS                = 2;
     169                 :            : 
     170                 :            : // ----------------------------------------------------------------------------
     171                 :            : 
     172                 :            : const sal_uInt16 BIFF_PT_NOSTRING                   = 0xFFFF;
     173                 :            : 
     174                 :            : const sal_uInt16 BIFF_PTFIELD_DATAFIELD             = 0x0008;
     175                 :            : const sal_uInt16 BIFF_PTFIELD_DEFAULT               = 0x0001;
     176                 :            : const sal_uInt16 BIFF_PTFIELD_SUM                   = 0x0002;
     177                 :            : const sal_uInt16 BIFF_PTFIELD_COUNTA                = 0x0004;
     178                 :            : const sal_uInt16 BIFF_PTFIELD_AVERAGE               = 0x0008;
     179                 :            : const sal_uInt16 BIFF_PTFIELD_MAX                   = 0x0010;
     180                 :            : const sal_uInt16 BIFF_PTFIELD_MIN                   = 0x0020;
     181                 :            : const sal_uInt16 BIFF_PTFIELD_PRODUCT               = 0x0040;
     182                 :            : const sal_uInt16 BIFF_PTFIELD_COUNT                 = 0x0080;
     183                 :            : const sal_uInt16 BIFF_PTFIELD_STDDEV                = 0x0100;
     184                 :            : const sal_uInt16 BIFF_PTFIELD_STDDEVP               = 0x0200;
     185                 :            : const sal_uInt16 BIFF_PTFIELD_VAR                   = 0x0400;
     186                 :            : const sal_uInt16 BIFF_PTFIELD_VARP                  = 0x0800;
     187                 :            : 
     188                 :            : const sal_uInt32 BIFF_PTFIELD2_SHOWALL              = 0x00000001;
     189                 :            : const sal_uInt32 BIFF_PTFIELD2_AUTOSORT             = 0x00000200;
     190                 :            : const sal_uInt32 BIFF_PTFIELD2_SORTASCENDING        = 0x00000400;
     191                 :            : const sal_uInt32 BIFF_PTFIELD2_AUTOSHOW             = 0x00000800;
     192                 :            : const sal_uInt32 BIFF_PTFIELD2_AUTOSHOWTOP          = 0x00001000;
     193                 :            : const sal_uInt32 BIFF_PTFIELD2_OUTLINE              = 0x00200000;
     194                 :            : const sal_uInt32 BIFF_PTFIELD2_INSERTBLANKROW       = 0x00400000;
     195                 :            : const sal_uInt32 BIFF_PTFIELD2_SUBTOTALTOP          = 0x00800000;
     196                 :            : 
     197                 :            : const sal_uInt16 BIFF_PTFITEM_HIDDEN                = 0x0001;
     198                 :            : const sal_uInt16 BIFF_PTFITEM_HIDEDETAILS           = 0x0002;
     199                 :            : 
     200                 :            : const sal_uInt16 BIFF_PTDEF_ROWGRANDTOTALS          = 0x0001;
     201                 :            : const sal_uInt16 BIFF_PTDEF_COLGRANDTOTALS          = 0x0002;
     202                 :            : 
     203                 :            : const sal_uInt8 BIFF_PTDEF_ROWAXIS                  = 1;
     204                 :            : const sal_uInt8 BIFF_PTDEF_COLAXIS                  = 2;
     205                 :            : 
     206                 :            : const sal_uInt32 BIFF_PTDEF2_PAGEOVERTHENDOWN       = 0x00000001;
     207                 :            : const sal_uInt32 BIFF_PTDE2F_ENABLEDRILL            = 0x00020000;
     208                 :            : const sal_uInt32 BIFF_PTDEF2_PRESERVEFORMATTING     = 0x00080000;
     209                 :            : const sal_uInt32 BIFF_PTDEF2_MERGEITEM              = 0x00100000;
     210                 :            : const sal_uInt32 BIFF_PTDEF2_SHOWERROR              = 0x00200000;
     211                 :            : const sal_uInt32 BIFF_PTDEF2_SHOWMISSING            = 0x00400000;
     212                 :            : const sal_uInt32 BIFF_PTDEF2_SUBTOTALHIDDENITEMS    = 0x00800000;
     213                 :            : 
     214                 :            : const sal_Int16 BIFF_PTPAGEFIELDS_ALLITEMS          = 0x7FFD;
     215                 :            : 
     216                 :            : const sal_Int16 BIFF_PTDATAFIELD_PREVIOUS           = 0x7FFB;
     217                 :            : const sal_Int16 BIFF_PTDATAFIELD_NEXT               = 0x7FFC;
     218                 :            : 
     219                 :            : } // namespace
     220                 :            : 
     221                 :            : // ============================================================================
     222                 :            : 
     223                 :          0 : PTFieldItemModel::PTFieldItemModel() :
     224                 :            :     mnCacheItem( -1 ),
     225                 :            :     mnType( XML_data ),
     226                 :            :     mbShowDetails( true ),
     227                 :          0 :     mbHidden( false )
     228                 :            : {
     229                 :          0 : }
     230                 :            : 
     231                 :          0 : void PTFieldItemModel::setBiffType( sal_uInt16 nType )
     232                 :            : {
     233                 :            :     static const sal_Int32 spnTypes[] = { XML_data, XML_default,
     234                 :            :         XML_sum, XML_countA, XML_avg, XML_max, XML_min, XML_product, XML_count,
     235                 :            :         XML_stdDev, XML_stdDevP, XML_var, XML_varP, XML_grand, XML_blank };
     236         [ #  # ]:          0 :     mnType = STATIC_ARRAY_SELECT( spnTypes, nType, XML_data );
     237                 :          0 : }
     238                 :            : 
     239                 :            : // ----------------------------------------------------------------------------
     240                 :            : 
     241                 :          0 : PTFieldModel::PTFieldModel() :
     242                 :            :     mnAxis( XML_TOKEN_INVALID ),
     243                 :            :     mnNumFmtId( 0 ),
     244                 :            :     mnAutoShowItems( 10 ),
     245                 :            :     mnAutoShowRankBy( -1 ),
     246                 :            :     mnSortType( XML_manual ),
     247                 :            :     mnSortRefField( -1 ),
     248                 :            :     mnSortRefItem( -1 ),
     249                 :            :     mbDataField( false ),
     250                 :            :     mbDefaultSubtotal( true ),
     251                 :            :     mbSumSubtotal( false ),
     252                 :            :     mbCountASubtotal( false ),
     253                 :            :     mbAverageSubtotal( false ),
     254                 :            :     mbMaxSubtotal( false ),
     255                 :            :     mbMinSubtotal( false ),
     256                 :            :     mbProductSubtotal( false ),
     257                 :            :     mbCountSubtotal( false ),
     258                 :            :     mbStdDevSubtotal( false ),
     259                 :            :     mbStdDevPSubtotal( false ),
     260                 :            :     mbVarSubtotal( false ),
     261                 :            :     mbVarPSubtotal( false ),
     262                 :            :     mbShowAll( true ),
     263                 :            :     mbOutline( true ),
     264                 :            :     mbSubtotalTop( true ),
     265                 :            :     mbInsertBlankRow( false ),
     266                 :            :     mbInsertPageBreak( false ),
     267                 :            :     mbAutoShow( false ),
     268                 :            :     mbTopAutoShow( true ),
     269                 :          0 :     mbMultiPageItems( false )
     270                 :            : {
     271                 :          0 : }
     272                 :            : 
     273                 :          0 : void PTFieldModel::setBiffAxis( sal_uInt8 nAxis )
     274                 :            : {
     275                 :            :     /*  Weird. The axis field is organized as bit field, but only one of the
     276                 :            :         row/col/page flags are allowed at the same time and refer to the values
     277                 :            :         'axisRow', 'axisCol', and 'axisPage' of the XML attribute
     278                 :            :         'pivotField@axis'. Additionally, the fourth bit determines if the field
     279                 :            :         is a data field, which may appear combined with the row/col/page flags.
     280                 :            :         Therefore, this bit is unrelated to the 'axisValues' value of the
     281                 :            :         'pivotField@axis' attribute, but refers to the 'pivotField@dataField'
     282                 :            :         boolean attribute. */
     283                 :            :     static const sal_Int32 spnAxisIds[] = { XML_TOKEN_INVALID, XML_axisRow, XML_axisCol, XML_TOKEN_INVALID, XML_axisPage };
     284         [ #  # ]:          0 :     mnAxis = STATIC_ARRAY_SELECT( spnAxisIds, nAxis, XML_TOKEN_INVALID );
     285                 :          0 : }
     286                 :            : 
     287                 :            : // ----------------------------------------------------------------------------
     288                 :            : 
     289                 :          0 : PTPageFieldModel::PTPageFieldModel() :
     290                 :            :     mnField( -1 ),
     291                 :          0 :     mnItem( BIFF12_PTPAGEFIELD_MULTIITEMS )
     292                 :            : {
     293                 :          0 : }
     294                 :            : 
     295                 :            : // ----------------------------------------------------------------------------
     296                 :            : 
     297                 :          0 : PTDataFieldModel::PTDataFieldModel() :
     298                 :            :     mnField( -1 ),
     299                 :            :     mnSubtotal( XML_sum ),
     300                 :            :     mnShowDataAs( XML_normal ),
     301                 :            :     mnBaseField( -1 ),
     302                 :            :     mnBaseItem( -1 ),
     303                 :          0 :     mnNumFmtId( 0 )
     304                 :            : {
     305                 :          0 : }
     306                 :            : 
     307                 :          0 : void PTDataFieldModel::setBiffSubtotal( sal_Int32 nSubtotal )
     308                 :            : {
     309                 :            :     static sal_Int32 spnSubtotals[] = { XML_sum, XML_count, XML_average, XML_max, XML_min, XML_product, XML_countNums, XML_stdDev, XML_stdDevp, XML_var, XML_varp };
     310         [ #  # ]:          0 :     mnSubtotal = STATIC_ARRAY_SELECT( spnSubtotals, nSubtotal, XML_TOKEN_INVALID );
     311                 :          0 : }
     312                 :            : 
     313                 :          0 : void PTDataFieldModel::setBiffShowDataAs( sal_Int32 nShowDataAs )
     314                 :            : {
     315                 :            :     static sal_Int32 spnShowDataAs[] = { XML_normal, XML_difference, XML_percent, XML_percentDiff, XML_runTotal, XML_percentOfRow, XML_percentOfCol, XML_percentOfTotal, XML_index };
     316         [ #  # ]:          0 :     mnShowDataAs = STATIC_ARRAY_SELECT( spnShowDataAs, nShowDataAs, XML_TOKEN_INVALID );
     317                 :          0 : }
     318                 :            : 
     319                 :            : // ----------------------------------------------------------------------------
     320                 :            : 
     321                 :          0 : PivotTableField::PivotTableField( PivotTable& rPivotTable, sal_Int32 nFieldIndex ) :
     322                 :            :     WorkbookHelper( rPivotTable ),
     323                 :            :     mrPivotTable( rPivotTable ),
     324         [ #  # ]:          0 :     mnFieldIndex( nFieldIndex )
     325                 :            : {
     326                 :          0 : }
     327                 :            : 
     328                 :          0 : void PivotTableField::importPivotField( const AttributeList& rAttribs )
     329                 :            : {
     330                 :            :     /*  The documentation mentions a value 'axisValues' for the attribute
     331                 :            :         'pivotField@axis'. But this value is not used to mark a data field, as
     332                 :            :         data fields may be inserted in one of the row/column/page dimensions at
     333                 :            :         the same time. Therefore, the boolean attribute 'pivotField@dataField'
     334                 :            :         is really used to mark data fields. */
     335                 :          0 :     maModel.mnAxis            = rAttribs.getToken( XML_axis, XML_TOKEN_INVALID );
     336                 :          0 :     maModel.mnNumFmtId        = rAttribs.getInteger( XML_numFmtId, 0 );
     337                 :          0 :     maModel.mnAutoShowItems   = rAttribs.getInteger( XML_itemPageCount, 10 );
     338                 :          0 :     maModel.mnAutoShowRankBy  = rAttribs.getInteger( XML_rankBy, -1 );
     339                 :          0 :     maModel.mnSortType        = rAttribs.getToken( XML_sortType, XML_manual );
     340                 :          0 :     maModel.mbDataField       = rAttribs.getBool( XML_dataField, false );
     341                 :          0 :     maModel.mbDefaultSubtotal = rAttribs.getBool( XML_defaultSubtotal, true );
     342                 :          0 :     maModel.mbSumSubtotal     = rAttribs.getBool( XML_sumSubtotal, false );
     343                 :          0 :     maModel.mbCountASubtotal  = rAttribs.getBool( XML_countASubtotal, false );
     344                 :          0 :     maModel.mbAverageSubtotal = rAttribs.getBool( XML_avgSubtotal, false );
     345                 :          0 :     maModel.mbMaxSubtotal     = rAttribs.getBool( XML_maxSubtotal, false );
     346                 :          0 :     maModel.mbMinSubtotal     = rAttribs.getBool( XML_minSubtotal, false );
     347                 :          0 :     maModel.mbProductSubtotal = rAttribs.getBool( XML_productSubtotal, false );
     348                 :          0 :     maModel.mbCountSubtotal   = rAttribs.getBool( XML_countSubtotal, false );
     349                 :          0 :     maModel.mbStdDevSubtotal  = rAttribs.getBool( XML_stdDevSubtotal, false );
     350                 :          0 :     maModel.mbStdDevPSubtotal = rAttribs.getBool( XML_stdDevPSubtotal, false );
     351                 :          0 :     maModel.mbVarSubtotal     = rAttribs.getBool( XML_varSubtotal, false );
     352                 :          0 :     maModel.mbVarPSubtotal    = rAttribs.getBool( XML_varPSubtotal, false );
     353                 :          0 :     maModel.mbShowAll         = rAttribs.getBool( XML_showAll, true );
     354                 :          0 :     maModel.mbOutline         = rAttribs.getBool( XML_outline, true );
     355                 :          0 :     maModel.mbSubtotalTop     = rAttribs.getBool( XML_subtotalTop, true );
     356                 :          0 :     maModel.mbInsertBlankRow  = rAttribs.getBool( XML_insertBlankRow, false );
     357                 :          0 :     maModel.mbInsertPageBreak = rAttribs.getBool( XML_insertPageBreak, false );
     358                 :          0 :     maModel.mbAutoShow        = rAttribs.getBool( XML_autoShow, false );
     359                 :          0 :     maModel.mbTopAutoShow     = rAttribs.getBool( XML_topAutoShow, true );
     360                 :          0 :     maModel.mbMultiPageItems  = rAttribs.getBool( XML_multipleItemSelectionAllowed, false );
     361                 :          0 : }
     362                 :            : 
     363                 :          0 : void PivotTableField::importItem( const AttributeList& rAttribs )
     364                 :            : {
     365                 :          0 :     PTFieldItemModel aModel;
     366         [ #  # ]:          0 :     aModel.mnCacheItem   = rAttribs.getInteger( XML_x, -1 );
     367         [ #  # ]:          0 :     aModel.mnType        = rAttribs.getToken( XML_t, XML_data );
     368         [ #  # ]:          0 :     aModel.mbShowDetails = rAttribs.getBool( XML_sd, true );
     369         [ #  # ]:          0 :     aModel.mbHidden      = rAttribs.getBool( XML_h, false );
     370         [ #  # ]:          0 :     aModel.msCaption     = rAttribs.getXString( XML_n, OUString() );
     371         [ #  # ]:          0 :     maItems.push_back( aModel );
     372                 :          0 : }
     373                 :            : 
     374                 :          0 : void PivotTableField::importReference( const AttributeList& rAttribs )
     375                 :            : {
     376                 :            :     // field index is stored as unsigned integer
     377                 :          0 :     maModel.mnSortRefField = static_cast< sal_Int32 >( rAttribs.getUnsigned( XML_field, SAL_MAX_UINT32 ) );
     378                 :          0 : }
     379                 :            : 
     380                 :          0 : void PivotTableField::importReferenceItem( const AttributeList& rAttribs )
     381                 :            : {
     382                 :          0 :     maModel.mnSortRefItem = rAttribs.getInteger( XML_v, -1 );
     383                 :          0 : }
     384                 :            : 
     385                 :          0 : void PivotTableField::importPTField( SequenceInputStream& rStrm )
     386                 :            : {
     387                 :            :     sal_uInt32 nFlags1, nFlags2;
     388 [ #  # ][ #  # ]:          0 :     rStrm >> nFlags1 >> maModel.mnNumFmtId >> nFlags2 >> maModel.mnAutoShowItems >> maModel.mnAutoShowRankBy;
         [ #  # ][ #  # ]
                 [ #  # ]
     389                 :            : 
     390                 :          0 :     maModel.setBiffAxis( extractValue< sal_uInt8 >( nFlags1, 0, 3 ) );
     391                 :          0 :     maModel.mbDataField       = getFlag( nFlags1, BIFF12_PTFIELD_DATAFIELD );
     392                 :          0 :     maModel.mbDefaultSubtotal = getFlag( nFlags1, BIFF12_PTFIELD_DEFAULT );
     393                 :          0 :     maModel.mbSumSubtotal     = getFlag( nFlags1, BIFF12_PTFIELD_SUM );
     394                 :          0 :     maModel.mbCountASubtotal  = getFlag( nFlags1, BIFF12_PTFIELD_COUNTA );
     395                 :          0 :     maModel.mbAverageSubtotal = getFlag( nFlags1, BIFF12_PTFIELD_AVERAGE );
     396                 :          0 :     maModel.mbMaxSubtotal     = getFlag( nFlags1, BIFF12_PTFIELD_MAX );
     397                 :          0 :     maModel.mbMinSubtotal     = getFlag( nFlags1, BIFF12_PTFIELD_MIN );
     398                 :          0 :     maModel.mbProductSubtotal = getFlag( nFlags1, BIFF12_PTFIELD_PRODUCT );
     399                 :          0 :     maModel.mbCountSubtotal   = getFlag( nFlags1, BIFF12_PTFIELD_COUNT );
     400                 :          0 :     maModel.mbStdDevSubtotal  = getFlag( nFlags1, BIFF12_PTFIELD_STDDEV );
     401                 :          0 :     maModel.mbStdDevPSubtotal = getFlag( nFlags1, BIFF12_PTFIELD_STDDEVP );
     402                 :          0 :     maModel.mbVarSubtotal     = getFlag( nFlags1, BIFF12_PTFIELD_VAR );
     403                 :          0 :     maModel.mbVarPSubtotal    = getFlag( nFlags1, BIFF12_PTFIELD_VARP );
     404                 :            : 
     405                 :          0 :     maModel.mbShowAll         = getFlag( nFlags2, BIFF12_PTFIELD_SHOWALL );
     406                 :          0 :     maModel.mbOutline         = getFlag( nFlags2, BIFF12_PTFIELD_OUTLINE );
     407                 :          0 :     maModel.mbSubtotalTop     = getFlag( nFlags2, BIFF12_PTFIELD_SUBTOTALTOP );
     408                 :          0 :     maModel.mbInsertBlankRow  = getFlag( nFlags2, BIFF12_PTFIELD_INSERTBLANKROW );
     409                 :          0 :     maModel.mbInsertPageBreak = getFlag( nFlags2, BIFF12_PTFIELD_INSERTPAGEBREAK );
     410                 :          0 :     maModel.mbAutoShow        = getFlag( nFlags2, BIFF12_PTFIELD_AUTOSHOW );
     411                 :          0 :     maModel.mbTopAutoShow     = getFlag( nFlags2, BIFF12_PTFIELD_AUTOSHOWTOP );
     412                 :          0 :     maModel.mbMultiPageItems  = getFlag( nFlags2, BIFF12_PTFIELD_MULTIPAGEITEMS );
     413                 :            : 
     414                 :          0 :     bool bAutoSort = getFlag( nFlags2, BIFF12_PTFIELD_AUTOSORT );
     415                 :          0 :     bool bAscending = getFlag( nFlags2, BIFF12_PTFIELD_SORTASCENDING );
     416 [ #  # ][ #  # ]:          0 :     maModel.mnSortType = bAutoSort ? (bAscending ? XML_ascending : XML_descending) : XML_manual;
     417                 :          0 : }
     418                 :            : 
     419                 :          0 : void PivotTableField::importPTFItem( SequenceInputStream& rStrm )
     420                 :            : {
     421                 :          0 :     PTFieldItemModel aModel;
     422                 :            :     sal_uInt8 nType;
     423                 :            :     sal_uInt16 nFlags;
     424 [ #  # ][ #  # ]:          0 :     rStrm >> nType >> nFlags >> aModel.mnCacheItem;
                 [ #  # ]
     425                 :            : 
     426                 :          0 :     aModel.setBiffType( nType );
     427                 :          0 :     aModel.mbShowDetails = !getFlag( nFlags, BIFF12_PTFITEM_HIDEDETAILS );
     428                 :          0 :     aModel.mbHidden      = getFlag( nFlags, BIFF12_PTFITEM_HIDDEN );
     429                 :            : 
     430         [ #  # ]:          0 :     maItems.push_back( aModel );
     431                 :          0 : }
     432                 :            : 
     433                 :          0 : void PivotTableField::importPTReference( SequenceInputStream& rStrm )
     434                 :            : {
     435                 :          0 :     rStrm >> maModel.mnSortRefField;
     436                 :          0 : }
     437                 :            : 
     438                 :          0 : void PivotTableField::importPTReferenceItem( SequenceInputStream& rStrm )
     439                 :            : {
     440                 :          0 :     rStrm >> maModel.mnSortRefItem;
     441                 :          0 : }
     442                 :            : 
     443                 :          0 : void PivotTableField::finalizeImport( const Reference< XDataPilotDescriptor >& rxDPDesc )
     444                 :            : {
     445                 :            :     /*  Process all fields based on source data, other fields (e.g. group
     446                 :            :         fields) are processed from here. PivotCacahe::getDatabaseIndex()
     447                 :            :         returns -1 for all fields not based on source data. */
     448                 :          0 :     Reference< XDataPilotField > xDPField;
     449         [ #  # ]:          0 :     sal_Int32 nDatabaseIdx = mrPivotTable.getCacheDatabaseIndex( mnFieldIndex );
     450 [ #  # ][ #  # ]:          0 :     if( (nDatabaseIdx >= 0) && rxDPDesc.is() ) try
                 [ #  # ]
     451                 :            :     {
     452                 :            :         // try to get the source field and its name from passed DataPilot descriptor
     453 [ #  # ][ #  # ]:          0 :         Reference< XIndexAccess > xDPFieldsIA( rxDPDesc->getDataPilotFields(), UNO_SET_THROW );
                 [ #  # ]
     454 [ #  # ][ #  # ]:          0 :         xDPField.set( xDPFieldsIA->getByIndex( nDatabaseIdx ), UNO_QUERY_THROW );
                 [ #  # ]
     455         [ #  # ]:          0 :         Reference< XNamed > xDPFieldName( xDPField, UNO_QUERY_THROW );
     456 [ #  # ][ #  # ]:          0 :         maDPFieldName = xDPFieldName->getName();
     457                 :            :         OSL_ENSURE( !maDPFieldName.isEmpty(), "PivotTableField::finalizeImport - no field name in source data found" );
     458                 :            : 
     459                 :            :         // try to convert grouping settings
     460 [ #  # ][ #  # ]:          0 :         if( const PivotCacheField* pCacheField = mrPivotTable.getCacheField( mnFieldIndex ) )
     461                 :            :         {
     462                 :            :             // numeric grouping is done inplace, no nested group fields will appear
     463         [ #  # ]:          0 :             if( pCacheField->hasNumericGrouping() )
     464                 :            :             {
     465         [ #  # ]:          0 :                 pCacheField->convertNumericGrouping( xDPField );
     466                 :            :             }
     467         [ #  # ]:          0 :             else if( pCacheField->hasDateGrouping() )
     468                 :            :             {
     469                 :            :                 // first date group settings are inplace
     470         [ #  # ]:          0 :                 pCacheField->createDateGroupField( xDPField );
     471                 :            :                 // create all nested group fields (if any)
     472         [ #  # ]:          0 :                 mrPivotTable.finalizeDateGroupingImport( xDPField, mnFieldIndex );
     473                 :            :             }
     474         [ #  # ]:          0 :             else if( pCacheField->hasParentGrouping() )
     475                 :            :             {
     476                 :            : 
     477                 :            :                 // create a list of all item names, needed to map between original and group items
     478         [ #  # ]:          0 :                 ::std::vector< OUString > aItems;
     479         [ #  # ]:          0 :                 pCacheField->getCacheItemNames( aItems );
     480         [ #  # ]:          0 :                 PivotCacheGroupItemVector aItemNames;
     481 [ #  # ][ #  # ]:          0 :                 for( ::std::vector< OUString >::iterator aIt = aItems.begin(), aEnd = aItems.end(); aIt != aEnd; ++aIt )
     482         [ #  # ]:          0 :                     aItemNames.push_back( PivotCacheGroupItem( *aIt ) );
     483                 :            :                 // create all nested group fields (if any)
     484         [ #  # ]:          0 :                 mrPivotTable.finalizeParentGroupingImport( xDPField, *pCacheField, aItemNames );
     485                 :            :             }
     486         [ #  # ]:          0 :         }
     487                 :            :     }
     488         [ #  # ]:          0 :     catch( Exception& )
     489                 :            :     {
     490                 :          0 :     }
     491                 :          0 : }
     492                 :            : 
     493                 :          0 : void PivotTableField::finalizeDateGroupingImport( const Reference< XDataPilotField >& rxBaseDPField, sal_Int32 nBaseFieldIdx )
     494                 :            : {
     495         [ #  # ]:          0 :     if( maDPFieldName.isEmpty() )    // prevent endless loops if file format is broken
     496                 :            :     {
     497         [ #  # ]:          0 :         if( const PivotCacheField* pCacheField = mrPivotTable.getCacheField( mnFieldIndex ) )
     498                 :            :         {
     499 [ #  # ][ #  # ]:          0 :             if( !pCacheField->isDatabaseField() && pCacheField->hasDateGrouping() && (pCacheField->getGroupBaseField() == nBaseFieldIdx) )
         [ #  # ][ #  # ]
     500                 :            :             {
     501                 :          0 :                 maDPFieldName = pCacheField->createDateGroupField( rxBaseDPField );
     502                 :            :                 OSL_ENSURE( !maDPFieldName.isEmpty(), "PivotTableField::finalizeDateGroupingImport - cannot create date group field" );
     503                 :            :             }
     504                 :            :         }
     505                 :            :     }
     506                 :          0 : }
     507                 :            : 
     508                 :          0 : void PivotTableField::finalizeParentGroupingImport( const Reference< XDataPilotField >& rxBaseDPField,  const PivotCacheField& rBaseCacheField, PivotCacheGroupItemVector& orItemNames )
     509                 :            : {
     510         [ #  # ]:          0 :     if( maDPFieldName.isEmpty() )    // prevent endless loops if file format is broken
     511                 :            :     {
     512         [ #  # ]:          0 :         if( const PivotCacheField* pCacheField = mrPivotTable.getCacheField( mnFieldIndex ) )
     513                 :            :         {
     514                 :            :             // data field can have user defined groupname captions, apply them
     515                 :            :             // if they do
     516         [ #  # ]:          0 :             IdCaptionPairList captionList;
     517 [ #  # ][ #  # ]:          0 :             for( ItemModelVector::iterator aIt = maItems.begin(), aEnd = maItems.end(); aIt != aEnd; ++aIt )
     518                 :            :             {
     519 [ #  # ][ #  # ]:          0 :                 if ( aIt->mnType == XML_data  && aIt->msCaption.getLength() )
                 [ #  # ]
     520         [ #  # ]:          0 :                     captionList.push_back( IdCaptionPair( aIt->mnCacheItem, aIt->msCaption ) );
     521                 :            :             }
     522                 :            :             // #FIXME find another way out of this const nightmare prison
     523         [ #  # ]:          0 :             if ( !captionList.empty() )
     524         [ #  # ]:          0 :                 const_cast<PivotCacheField*>( pCacheField )->applyItemCaptions( captionList );
     525         [ #  # ]:          0 :             maDPFieldName = pCacheField->createParentGroupField( rxBaseDPField, rBaseCacheField, orItemNames );
     526                 :            :             // on success, try to create nested group fields
     527         [ #  # ]:          0 :             Reference< XDataPilotField > xDPField = mrPivotTable.getDataPilotField( maDPFieldName );
     528         [ #  # ]:          0 :             if( xDPField.is() )
     529         [ #  # ]:          0 :                 mrPivotTable.finalizeParentGroupingImport( xDPField, *pCacheField, orItemNames );
     530                 :            :         }
     531                 :            :     }
     532                 :          0 : }
     533                 :            : 
     534                 :          0 : void PivotTableField::convertRowField()
     535                 :            : {
     536                 :          0 :     convertRowColPageField( XML_axisRow );
     537                 :          0 : }
     538                 :            : 
     539                 :          0 : void PivotTableField::convertColField()
     540                 :            : {
     541                 :          0 :     convertRowColPageField( XML_axisCol );
     542                 :          0 : }
     543                 :            : 
     544                 :          0 : void PivotTableField::convertHiddenField()
     545                 :            : {
     546                 :          0 :     convertRowColPageField( XML_TOKEN_INVALID );
     547                 :          0 : }
     548                 :            : 
     549                 :          0 : void PivotTableField::convertPageField( const PTPageFieldModel& rPageField )
     550                 :            : {
     551                 :            :     OSL_ENSURE( rPageField.mnField == mnFieldIndex, "PivotTableField::convertPageField - wrong field index" );
     552                 :            :     // convert all settings common for row/column/page fields
     553         [ #  # ]:          0 :     Reference< XDataPilotField > xDPField = convertRowColPageField( XML_axisPage );
     554                 :            : 
     555         [ #  # ]:          0 :     if( xDPField.is() )
     556                 :            :     {
     557         [ #  # ]:          0 :         PropertySet aPropSet( xDPField );
     558                 :            :         using namespace ::com::sun::star::sheet;
     559                 :            : 
     560                 :            :         // find cache item used as 'selected page'
     561                 :          0 :         sal_Int32 nCacheItem = -1;
     562         [ #  # ]:          0 :         if( maModel.mbMultiPageItems )
     563                 :            :         {
     564                 :            :             // multiple items may be selected
     565                 :            :             OSL_ENSURE( rPageField.mnItem == BIFF12_PTPAGEFIELD_MULTIITEMS, "PivotTableField::convertPageField - unexpected cache item index" );
     566                 :            :             // try to find a single visible item
     567                 :          0 :             bool bHasMultiItems = false;
     568 [ #  # ][ #  # ]:          0 :             for( ItemModelVector::iterator aIt = maItems.begin(), aEnd = maItems.end(); (aIt != aEnd) && !bHasMultiItems; ++aIt )
         [ #  # ][ #  # ]
     569                 :            :             {
     570 [ #  # ][ #  # ]:          0 :                 if( (aIt->mnType == XML_data) && !aIt->mbHidden )
                 [ #  # ]
     571                 :            :                 {
     572                 :          0 :                     bHasMultiItems = nCacheItem >= 0;
     573         [ #  # ]:          0 :                     nCacheItem = bHasMultiItems ? -1 : aIt->mnCacheItem;
     574                 :            :                 }
     575                 :            :             }
     576                 :            :         }
     577                 :            :         else
     578                 :            :         {
     579                 :            :             // single item may be selected
     580 [ #  # ][ #  # ]:          0 :             if( (0 <= rPageField.mnItem) && (rPageField.mnItem < static_cast< sal_Int32 >( maItems.size() )) )
                 [ #  # ]
     581                 :          0 :                 nCacheItem = maItems[ rPageField.mnItem ].mnCacheItem;
     582                 :            :         }
     583                 :            : 
     584         [ #  # ]:          0 :         if( nCacheItem >= 0 )
     585                 :            :         {
     586 [ #  # ][ #  # ]:          0 :             if( const PivotCacheField* pCacheField = mrPivotTable.getCacheField( mnFieldIndex ) )
     587                 :            :             {
     588 [ #  # ][ #  # ]:          0 :                 if( const PivotCacheItem* pSharedItem = pCacheField->getCacheItem( nCacheItem ) )
     589                 :            :                 {
     590         [ #  # ]:          0 :                     OUString aSelectedPage = pSharedItem->getName();
     591         [ #  # ]:          0 :                     if( !aSelectedPage.isEmpty() )
     592         [ #  # ]:          0 :                         aPropSet.setProperty( PROP_SelectedPage, aSelectedPage );
     593                 :            :                 }
     594                 :            :             }
     595         [ #  # ]:          0 :         }
     596                 :          0 :     }
     597                 :          0 : }
     598                 :            : 
     599                 :          0 : void PivotTableField::convertDataField( const PTDataFieldModel& rDataField )
     600                 :            : {
     601                 :            :     OSL_ENSURE( rDataField.mnField == mnFieldIndex, "PivotTableField::convertDataField - wrong field index" );
     602                 :            :     OSL_ENSURE( maModel.mbDataField, "PivotTableField::convertDataField - not a data field" );
     603         [ #  # ]:          0 :     Reference< XDataPilotField > xDPField = mrPivotTable.getDataPilotField( maDPFieldName );
     604         [ #  # ]:          0 :     if( xDPField.is() )
     605                 :            :     {
     606         [ #  # ]:          0 :         PropertySet aPropSet( xDPField );
     607                 :            :         using namespace ::com::sun::star::sheet;
     608                 :            : 
     609                 :            :         // field orientation
     610         [ #  # ]:          0 :         aPropSet.setProperty( PROP_Orientation, DataPilotFieldOrientation_DATA );
     611                 :            : 
     612                 :            :         /*  Field aggregation function. Documentation is a little bit confused
     613                 :            :             about which names to use for the count functions. The name 'count'
     614                 :            :             means 'count all', and 'countNum' means 'count numbers'. On the
     615                 :            :             other hand, for subtotals, 'countA' means 'count all', and 'count'
     616                 :            :             means 'count numbers' (see above). */
     617                 :          0 :         GeneralFunction eAggFunc = GeneralFunction_SUM;
     618   [ #  #  #  #  :          0 :         switch( rDataField.mnSubtotal )
          #  #  #  #  #  
                #  #  # ]
     619                 :            :         {
     620                 :          0 :             case XML_sum:       eAggFunc = GeneralFunction_SUM;         break;
     621                 :          0 :             case XML_count:     eAggFunc = GeneralFunction_COUNT;       break;
     622                 :          0 :             case XML_average:   eAggFunc = GeneralFunction_AVERAGE;     break;
     623                 :          0 :             case XML_max:       eAggFunc = GeneralFunction_MAX;         break;
     624                 :          0 :             case XML_min:       eAggFunc = GeneralFunction_MIN;         break;
     625                 :          0 :             case XML_product:   eAggFunc = GeneralFunction_PRODUCT;     break;
     626                 :          0 :             case XML_countNums: eAggFunc = GeneralFunction_COUNTNUMS;   break;
     627                 :          0 :             case XML_stdDev:    eAggFunc = GeneralFunction_STDEV;       break;
     628                 :          0 :             case XML_stdDevp:   eAggFunc = GeneralFunction_STDEVP;      break;
     629                 :          0 :             case XML_var:       eAggFunc = GeneralFunction_VAR;         break;
     630                 :          0 :             case XML_varp:      eAggFunc = GeneralFunction_VARP;        break;
     631                 :            :             default:            OSL_FAIL( "PivotTableField::convertDataField - unknown aggregation function" );
     632                 :            :         }
     633         [ #  # ]:          0 :         aPropSet.setProperty( PROP_Function, eAggFunc );
     634                 :            : 
     635                 :            :         // field reference ('show data as')
     636                 :          0 :         DataPilotFieldReference aReference;
     637                 :          0 :         aReference.ReferenceType = DataPilotFieldReferenceType::NONE;
     638   [ #  #  #  #  :          0 :         switch( rDataField.mnShowDataAs )
             #  #  #  #  
                      # ]
     639                 :            :         {
     640                 :          0 :             case XML_difference:        aReference.ReferenceType = DataPilotFieldReferenceType::ITEM_DIFFERENCE;            break;
     641                 :          0 :             case XML_percent:           aReference.ReferenceType = DataPilotFieldReferenceType::ITEM_PERCENTAGE;            break;
     642                 :          0 :             case XML_percentDiff:       aReference.ReferenceType = DataPilotFieldReferenceType::ITEM_PERCENTAGE_DIFFERENCE; break;
     643                 :          0 :             case XML_runTotal:          aReference.ReferenceType = DataPilotFieldReferenceType::RUNNING_TOTAL;              break;
     644                 :          0 :             case XML_percentOfRow:      aReference.ReferenceType = DataPilotFieldReferenceType::ROW_PERCENTAGE;             break;
     645                 :          0 :             case XML_percentOfCol:      aReference.ReferenceType = DataPilotFieldReferenceType::COLUMN_PERCENTAGE;          break;
     646                 :          0 :             case XML_percentOfTotal:    aReference.ReferenceType = DataPilotFieldReferenceType::TOTAL_PERCENTAGE;           break;
     647                 :          0 :             case XML_index:             aReference.ReferenceType = DataPilotFieldReferenceType::INDEX;                      break;
     648                 :            :         }
     649         [ #  # ]:          0 :         if( aReference.ReferenceType != DataPilotFieldReferenceType::NONE )
     650                 :            :         {
     651 [ #  # ][ #  # ]:          0 :             if( const PivotCacheField* pCacheField = mrPivotTable.getCacheField( rDataField.mnBaseField ) )
     652                 :            :             {
     653                 :          0 :                 aReference.ReferenceField = pCacheField->getName();
     654      [ #  #  # ]:          0 :                 switch( rDataField.mnBaseItem )
     655                 :            :                 {
     656                 :            :                     case OOX_PT_PREVIOUS_ITEM:
     657                 :          0 :                         aReference.ReferenceItemType = DataPilotFieldReferenceItemType::PREVIOUS;
     658                 :          0 :                     break;
     659                 :            :                     case OOX_PT_NEXT_ITEM:
     660                 :          0 :                         aReference.ReferenceItemType = DataPilotFieldReferenceItemType::NEXT;
     661                 :          0 :                     break;
     662                 :            :                     default:
     663                 :          0 :                         aReference.ReferenceItemType = DataPilotFieldReferenceItemType::NAMED;
     664 [ #  # ][ #  # ]:          0 :                         if( const PivotCacheItem* pCacheItem = pCacheField->getCacheItem( rDataField.mnBaseItem ) )
     665         [ #  # ]:          0 :                             aReference.ReferenceItemName = pCacheItem->getName();
     666                 :            :                 }
     667         [ #  # ]:          0 :                 aPropSet.setProperty( PROP_Reference, aReference );
     668                 :            :             }
     669         [ #  # ]:          0 :         }
     670                 :          0 :     }
     671                 :          0 : }
     672                 :            : 
     673                 :            : // private --------------------------------------------------------------------
     674                 :            : 
     675                 :          0 : Reference< XDataPilotField > PivotTableField::convertRowColPageField( sal_Int32 nAxis )
     676                 :            : {
     677                 :          0 :     bool bDataLayout = mnFieldIndex == OOX_PT_DATALAYOUTFIELD;
     678         [ #  # ]:          0 :     Reference< XDataPilotField > xDPField = bDataLayout ? mrPivotTable.getDataLayoutField() : mrPivotTable.getDataPilotField( maDPFieldName );
     679                 :            :     OSL_ENSURE( bDataLayout || (nAxis == maModel.mnAxis), "PivotTableField::convertRowColPageField - field axis mismatch" );
     680                 :            : 
     681         [ #  # ]:          0 :     if( xDPField.is() )
     682                 :            :     {
     683                 :            :         // TODO: Use this to set properties directly, bypassing the slow uno layer.
     684                 :          0 :         ScDPObject* pDPObj = mrPivotTable.getDPObject();
     685                 :            : 
     686         [ #  # ]:          0 :         PropertySet aPropSet( xDPField );
     687                 :            :         using namespace ::com::sun::star::sheet;
     688                 :            : 
     689                 :            :         // field orientation
     690                 :          0 :         DataPilotFieldOrientation eFieldOrient = DataPilotFieldOrientation_HIDDEN;
     691   [ #  #  #  # ]:          0 :         switch( nAxis )
     692                 :            :         {
     693                 :          0 :             case XML_axisRow:   eFieldOrient = DataPilotFieldOrientation_ROW;       break;
     694                 :          0 :             case XML_axisCol:   eFieldOrient = DataPilotFieldOrientation_COLUMN;    break;
     695                 :          0 :             case XML_axisPage:  eFieldOrient = DataPilotFieldOrientation_PAGE;      break;
     696                 :            :         }
     697         [ #  # ]:          0 :         if( eFieldOrient != DataPilotFieldOrientation_HIDDEN )
     698         [ #  # ]:          0 :             aPropSet.setProperty( PROP_Orientation, eFieldOrient );
     699                 :            : 
     700                 :            :         // all other settings not for the data layout field
     701         [ #  # ]:          0 :         if( !bDataLayout )
     702                 :            :         {
     703                 :            :             /*  Field subtotal functions. Ignore the 'defaultSubtotal' flag, if
     704                 :            :                 explicit functions are set. This is different behaviour between
     705                 :            :                 XML (where 'defaultSubtotal' is set regardless of other
     706                 :            :                 functions) and binary formats (where 'defaultSubtotal' is not
     707                 :            :                 set if other functions are set). */
     708         [ #  # ]:          0 :             ::std::vector< GeneralFunction > aSubtotals;
     709                 :            :             /*  Order of subtotals is fixed in Excel. Documentation is a little
     710                 :            :                 bit confused about which names to use for the count functions.
     711                 :            :                 For subtotals, 'countA' means 'count all', and 'count' means
     712                 :            :                 'count numbers'. On the other hand, for the data field
     713                 :            :                 aggregation function, 'count' means 'count all', and 'countNum'
     714                 :            :                 means 'count numbers' (see below). */
     715 [ #  # ][ #  # ]:          0 :             if( maModel.mbSumSubtotal )     aSubtotals.push_back( GeneralFunction_SUM );
     716 [ #  # ][ #  # ]:          0 :             if( maModel.mbCountASubtotal )  aSubtotals.push_back( GeneralFunction_COUNT );
     717 [ #  # ][ #  # ]:          0 :             if( maModel.mbAverageSubtotal ) aSubtotals.push_back( GeneralFunction_AVERAGE );
     718 [ #  # ][ #  # ]:          0 :             if( maModel.mbMaxSubtotal )     aSubtotals.push_back( GeneralFunction_MAX );
     719 [ #  # ][ #  # ]:          0 :             if( maModel.mbMinSubtotal )     aSubtotals.push_back( GeneralFunction_MIN );
     720 [ #  # ][ #  # ]:          0 :             if( maModel.mbProductSubtotal ) aSubtotals.push_back( GeneralFunction_PRODUCT );
     721 [ #  # ][ #  # ]:          0 :             if( maModel.mbCountSubtotal )   aSubtotals.push_back( GeneralFunction_COUNTNUMS );
     722 [ #  # ][ #  # ]:          0 :             if( maModel.mbStdDevSubtotal )  aSubtotals.push_back( GeneralFunction_STDEV );
     723 [ #  # ][ #  # ]:          0 :             if( maModel.mbStdDevPSubtotal ) aSubtotals.push_back( GeneralFunction_STDEVP );
     724 [ #  # ][ #  # ]:          0 :             if( maModel.mbVarSubtotal )     aSubtotals.push_back( GeneralFunction_VAR );
     725 [ #  # ][ #  # ]:          0 :             if( maModel.mbVarPSubtotal )    aSubtotals.push_back( GeneralFunction_VARP );
     726                 :            :             // if no function is set manually, check the 'defaultSubtotal' flag
     727 [ #  # ][ #  # ]:          0 :             if( aSubtotals.empty() && maModel.mbDefaultSubtotal )
                 [ #  # ]
     728         [ #  # ]:          0 :                 aSubtotals.push_back( GeneralFunction_AUTO );
     729 [ #  # ][ #  # ]:          0 :             aPropSet.setProperty( PROP_Subtotals, ContainerHelper::vectorToSequence( aSubtotals ) );
                 [ #  # ]
     730                 :            : 
     731                 :            :             // layout settings
     732                 :          0 :             DataPilotFieldLayoutInfo aLayoutInfo;
     733                 :            :             aLayoutInfo.LayoutMode = maModel.mbOutline ?
     734                 :            :                 (maModel.mbSubtotalTop ? DataPilotFieldLayoutMode::OUTLINE_SUBTOTALS_TOP : DataPilotFieldLayoutMode::OUTLINE_SUBTOTALS_BOTTOM) :
     735 [ #  # ][ #  # ]:          0 :                 DataPilotFieldLayoutMode::TABULAR_LAYOUT;
     736                 :          0 :             aLayoutInfo.AddEmptyLines = maModel.mbInsertBlankRow;
     737         [ #  # ]:          0 :             aPropSet.setProperty( PROP_LayoutInfo, aLayoutInfo );
     738         [ #  # ]:          0 :             aPropSet.setProperty( PROP_ShowEmpty, maModel.mbShowAll );
     739                 :            : 
     740                 :            :             // auto show (OOXML/BIFF12 only)
     741         [ #  # ]:          0 :             if( maModel.mbAutoShow )
     742                 :            :             {
     743                 :          0 :                 DataPilotFieldAutoShowInfo aAutoShowInfo;
     744                 :          0 :                 aAutoShowInfo.IsEnabled = sal_True;
     745         [ #  # ]:          0 :                 aAutoShowInfo.ShowItemsMode = maModel.mbTopAutoShow ? DataPilotFieldShowItemsMode::FROM_TOP : DataPilotFieldShowItemsMode::FROM_BOTTOM;
     746                 :          0 :                 aAutoShowInfo.ItemCount = maModel.mnAutoShowItems;
     747 [ #  # ][ #  # ]:          0 :                 if( const PivotCacheField* pCacheField = mrPivotTable.getCacheFieldOfDataField( maModel.mnAutoShowRankBy ) )
     748                 :          0 :                     aAutoShowInfo.DataField = pCacheField->getName();
     749         [ #  # ]:          0 :                 aPropSet.setProperty( PROP_AutoShowInfo, aAutoShowInfo );
     750                 :            :             }
     751                 :            : 
     752                 :            :             // auto sort
     753                 :          0 :             DataPilotFieldSortInfo aSortInfo;
     754                 :          0 :             aSortInfo.IsAscending = maModel.mnSortType == XML_ascending;
     755 [ #  # ][ #  # ]:          0 :             if( (maModel.mnSortType != XML_ascending) && (maModel.mnSortType != XML_descending) )
     756                 :            :             {
     757                 :          0 :                 aSortInfo.Mode = DataPilotFieldSortMode::MANUAL;
     758                 :            :             }
     759                 :            :             else
     760                 :            :             {
     761                 :            :                 const PivotCacheField* pCacheField = (maModel.mnSortRefField == OOX_PT_DATALAYOUTFIELD) ?
     762 [ #  # ][ #  # ]:          0 :                     mrPivotTable.getCacheFieldOfDataField( maModel.mnSortRefItem ) : 0;
     763         [ #  # ]:          0 :                 if( pCacheField )
     764                 :            :                 {
     765                 :          0 :                     aSortInfo.Mode = DataPilotFieldSortMode::DATA;
     766                 :          0 :                     aSortInfo.Field = pCacheField->getName();
     767                 :            :                 }
     768                 :            :                 else
     769                 :            :                 {
     770                 :          0 :                     aSortInfo.Mode = DataPilotFieldSortMode::NAME;
     771                 :            :                 }
     772                 :            :             }
     773         [ #  # ]:          0 :             aPropSet.setProperty( PROP_SortInfo, aSortInfo );
     774                 :            : 
     775                 :            :             // item settings
     776 [ #  # ][ #  # ]:          0 :             if (const PivotCacheField* pCacheField = mrPivotTable.getCacheField(mnFieldIndex))
     777                 :            :             {
     778                 :          0 :                 ScDPSaveData* pSaveData = pDPObj->GetSaveData();
     779         [ #  # ]:          0 :                 ScDPSaveDimension* pDim = pSaveData->GetDimensionByName(pCacheField->getName());
     780                 :            : 
     781                 :            :                 try
     782                 :            :                 {
     783 [ #  # ][ #  # ]:          0 :                     for( ItemModelVector::iterator aIt = maItems.begin(), aEnd = maItems.end(); aIt != aEnd; ++aIt )
     784                 :            :                     {
     785         [ #  # ]:          0 :                         if (aIt->mnType != XML_data)
     786                 :          0 :                             continue;
     787                 :            : 
     788         [ #  # ]:          0 :                         const PivotCacheItem* pSharedItem = pCacheField->getCacheItem(aIt->mnCacheItem);
     789         [ #  # ]:          0 :                         if (!pSharedItem)
     790                 :          0 :                             continue;
     791                 :            : 
     792                 :            :                         try
     793                 :            :                         {
     794 [ #  # ][ #  # ]:          0 :                             ScDPSaveMember* pMem = pDim->GetMemberByName(pSharedItem->getName());
                 [ #  # ]
     795         [ #  # ]:          0 :                             pMem->SetShowDetails(aIt->mbShowDetails);
     796         [ #  # ]:          0 :                             pMem->SetIsVisible(!aIt->mbHidden);
     797                 :            :                         }
     798   [ #  #  #  # ]:          0 :                         catch( Exception& )
     799                 :            :                         {
     800                 :            :                             // catch every failed container access to be able to process following items
     801                 :            :                         }
     802                 :            :                     }
     803                 :            :                 }
     804         [ #  # ]:          0 :                 catch (const Exception&) {}
     805                 :          0 :             }
     806         [ #  # ]:          0 :         }
     807                 :            :     }
     808                 :          0 :     return xDPField;
     809                 :            : }
     810                 :            : 
     811                 :            : // ============================================================================
     812                 :            : 
     813                 :          0 : PTFilterModel::PTFilterModel() :
     814                 :            :     mfValue( 0.0 ),
     815                 :            :     mnField( -1 ),
     816                 :            :     mnMemPropField( -1 ),
     817                 :            :     mnType( XML_TOKEN_INVALID ),
     818                 :            :     mnEvalOrder( 0 ),
     819                 :            :     mnId( -1 ),
     820                 :            :     mnMeasureField( -1 ),
     821                 :            :     mnMeasureHier( -1 ),
     822                 :          0 :     mbTopFilter( true )
     823                 :            : {
     824                 :          0 : }
     825                 :            : 
     826                 :            : // ----------------------------------------------------------------------------
     827                 :            : 
     828                 :          0 : PivotTableFilter::PivotTableFilter( const PivotTable& rPivotTable ) :
     829                 :            :     WorkbookHelper( rPivotTable ),
     830                 :          0 :     mrPivotTable( rPivotTable )
     831                 :            : {
     832                 :          0 : }
     833                 :            : 
     834                 :          0 : void PivotTableFilter::importFilter( const AttributeList& rAttribs )
     835                 :            : {
     836         [ #  # ]:          0 :     maModel.maName         = rAttribs.getXString( XML_name, OUString() );
     837         [ #  # ]:          0 :     maModel.maDescription  = rAttribs.getXString( XML_description, OUString() );
     838         [ #  # ]:          0 :     maModel.maStrValue1    = rAttribs.getXString( XML_stringValue1, OUString() );
     839         [ #  # ]:          0 :     maModel.maStrValue2    = rAttribs.getXString( XML_stringValue2, OUString() );
     840                 :          0 :     maModel.mnField        = rAttribs.getInteger( XML_fld, -1 );
     841                 :          0 :     maModel.mnMemPropField = rAttribs.getInteger( XML_mpFld, -1 );
     842                 :          0 :     maModel.mnType         = rAttribs.getToken( XML_type, XML_TOKEN_INVALID );
     843                 :          0 :     maModel.mnEvalOrder    = rAttribs.getInteger( XML_evalOrder, 0 );
     844                 :          0 :     maModel.mnId           = rAttribs.getInteger( XML_id, -1 );
     845                 :          0 :     maModel.mnMeasureField = rAttribs.getInteger( XML_iMeasureFld, -1 );
     846                 :          0 :     maModel.mnMeasureHier  = rAttribs.getInteger( XML_iMeasureHier, -1 );
     847                 :          0 : }
     848                 :            : 
     849                 :          0 : void PivotTableFilter::importTop10( const AttributeList& rAttribs )
     850                 :            : {
     851                 :            :     OSL_ENSURE( rAttribs.getBool( XML_percent, false ) == (maModel.mnType == XML_percent),
     852                 :            :         "PivotTableFilter::importTop10 - unexpected value of percent attribute" );
     853                 :          0 :     maModel.mfValue     = rAttribs.getDouble( XML_val, 0.0 );
     854                 :          0 :     maModel.mbTopFilter = rAttribs.getBool( XML_top, true );
     855                 :          0 : }
     856                 :            : 
     857                 :          0 : void PivotTableFilter::importPTFilter( SequenceInputStream& rStrm )
     858                 :            : {
     859                 :            :     sal_Int32 nType;
     860                 :            :     sal_uInt16 nFlags;
     861 [ #  # ][ #  # ]:          0 :     rStrm >> maModel.mnField >> maModel.mnMemPropField >> nType;
                 [ #  # ]
     862         [ #  # ]:          0 :     rStrm.skip( 4 );    // unused
     863 [ #  # ][ #  # ]:          0 :     rStrm >> maModel.mnId >> maModel.mnMeasureField >> maModel.mnMeasureHier >> nFlags;
         [ #  # ][ #  # ]
     864         [ #  # ]:          0 :     if( getFlag( nFlags, BIFF12_PTFILTER_HASNAME ) )
     865         [ #  # ]:          0 :         rStrm >> maModel.maName;
     866         [ #  # ]:          0 :     if( getFlag( nFlags, BIFF12_PTFILTER_HASDESCRIPTION ) )
     867         [ #  # ]:          0 :         rStrm >> maModel.maDescription;
     868         [ #  # ]:          0 :     if( getFlag( nFlags, BIFF12_PTFILTER_HASSTRVALUE1 ) )
     869         [ #  # ]:          0 :         rStrm >> maModel.maStrValue1;
     870         [ #  # ]:          0 :     if( getFlag( nFlags, BIFF12_PTFILTER_HASSTRVALUE2 ) )
     871         [ #  # ]:          0 :         rStrm >> maModel.maStrValue2;
     872                 :            : 
     873                 :            :     static sal_Int32 spnTypes[] =
     874                 :            :     {
     875                 :            :         XML_unknown,
     876                 :            :         // data field top10 filter (1-3)
     877                 :            :         XML_count, XML_percent, XML_sum,
     878                 :            :         // caption filter (4-17)
     879                 :            :         XML_captionEqual, XML_captionNotEqual,
     880                 :            :         XML_captionBeginsWith, XML_captionNotBeginsWith, XML_captionEndsWith, XML_captionNotEndsWith,
     881                 :            :         XML_captionContains, XML_captionNotContains, XML_captionGreaterThan, XML_captionGreaterThanOrEqual,
     882                 :            :         XML_captionLessThan, XML_captionLessThanOrEqual, XML_captionBetween, XML_captionNotBetween,
     883                 :            :         // value filter (18-25)
     884                 :            :         XML_valueEqual, XML_valueNotEqual, XML_valueGreaterThan, XML_valueGreaterThanOrEqual,
     885                 :            :         XML_valueLessThan, XML_valueLessThanOrEqual, XML_valueBetween, XML_valueNotBetween,
     886                 :            :         // date filter (26-65)
     887                 :            :         XML_dateEqual, XML_dateOlderThan, XML_dateNewerThan, XML_dateBetween,
     888                 :            :         XML_tomorrow, XML_today, XML_yesterday, XML_nextWeek, XML_thisWeek, XML_lastWeek,
     889                 :            :         XML_nextMonth, XML_thisMonth, XML_lastMonth, XML_nextQuarter, XML_thisQuarter, XML_lastQuarter,
     890                 :            :         XML_nextYear, XML_thisYear, XML_lastYear, XML_yearToDate, XML_Q1, XML_Q2, XML_Q3, XML_Q4,
     891                 :            :         XML_M1, XML_M2, XML_M3, XML_M4, XML_M5, XML_M6, XML_M7, XML_M8, XML_M9, XML_M10, XML_M11, XML_M12,
     892                 :            :         XML_dateNotEqual, XML_dateOlderThanOrEqual, XML_dateNewerThanOrEqual, XML_dateNotBetween
     893                 :            :     };
     894         [ #  # ]:          0 :     maModel.mnType = STATIC_ARRAY_SELECT( spnTypes, nType, XML_TOKEN_INVALID );
     895                 :          0 : }
     896                 :            : 
     897                 :          0 : void PivotTableFilter::importTop10Filter( SequenceInputStream& rStrm )
     898                 :            : {
     899                 :            :     sal_uInt8 nFlags;
     900 [ #  # ][ #  # ]:          0 :     rStrm >> nFlags >> maModel.mfValue;
     901                 :            : 
     902                 :            :     OSL_ENSURE( getFlag( nFlags, BIFF12_TOP10FILTER_PERCENT ) == (maModel.mnType == XML_percent),
     903                 :            :         "PivotTableFilter::importTop10 - unexpected value of percent attribute" );
     904                 :          0 :     maModel.mbTopFilter = getFlag( nFlags, BIFF12_TOP10FILTER_TOP );
     905                 :          0 : }
     906                 :            : 
     907                 :          0 : void PivotTableFilter::finalizeImport()
     908                 :            : {
     909                 :            :     // only simple top10 filter supported
     910         [ #  # ]:          0 :     if( maModel.mnType == XML_count )
     911                 :            :     {
     912 [ #  # ][ #  # ]:          0 :         PropertySet aPropSet( mrPivotTable.getDataPilotField( maModel.mnField ) );
     913         [ #  # ]:          0 :         if( aPropSet.is() )
     914                 :            :         {
     915                 :            :             using namespace ::com::sun::star::sheet;
     916                 :          0 :             DataPilotFieldAutoShowInfo aAutoShowInfo;
     917                 :          0 :             aAutoShowInfo.IsEnabled = sal_True;
     918         [ #  # ]:          0 :             aAutoShowInfo.ShowItemsMode = maModel.mbTopFilter ? DataPilotFieldShowItemsMode::FROM_TOP : DataPilotFieldShowItemsMode::FROM_BOTTOM;
     919         [ #  # ]:          0 :             aAutoShowInfo.ItemCount = getLimitedValue< sal_Int32, double >( maModel.mfValue, 0, SAL_MAX_INT32 );
     920 [ #  # ][ #  # ]:          0 :             if( const PivotCacheField* pCacheField = mrPivotTable.getCacheFieldOfDataField( maModel.mnMeasureField ) )
     921                 :          0 :                 aAutoShowInfo.DataField = pCacheField->getName();
     922         [ #  # ]:          0 :             aPropSet.setProperty( PROP_AutoShowInfo, aAutoShowInfo );
     923         [ #  # ]:          0 :         }
     924                 :            :     }
     925                 :          0 : }
     926                 :            : 
     927                 :            : // ============================================================================
     928                 :            : 
     929                 :          0 : PTDefinitionModel::PTDefinitionModel() :
     930                 :            :     mnCacheId( -1 ),
     931                 :            :     mnDataPosition( 0 ),
     932                 :            :     mnPageWrap( 0 ),
     933                 :            :     mnIndent( 1 ),
     934                 :            :     mnChartFormat( 0 ),
     935                 :            :     mnRowFields( 0 ),
     936                 :            :     mnColFields( 0 ),
     937                 :            :     mbDataOnRows( false ),
     938                 :            :     mbShowError( false ),
     939                 :            :     mbShowMissing( true ),
     940                 :            :     mbShowItems( true ),
     941                 :            :     mbDisableFieldList( false ),
     942                 :            :     mbShowCalcMembers( true ),
     943                 :            :     mbVisualTotals( true ),
     944                 :            :     mbShowDrill( true ),
     945                 :            :     mbPrintDrill( false ),
     946                 :            :     mbEnableDrill( true ),
     947                 :            :     mbPreserveFormatting( true ),
     948                 :            :     mbUseAutoFormat( false ),
     949                 :            :     mbPageOverThenDown( false ),
     950                 :            :     mbSubtotalHiddenItems( false ),
     951                 :            :     mbRowGrandTotals( true ),
     952                 :            :     mbColGrandTotals( true ),
     953                 :            :     mbFieldPrintTitles( false ),
     954                 :            :     mbItemPrintTitles( false ),
     955                 :            :     mbMergeItem( false ),
     956                 :            :     mbShowEmptyRow( false ),
     957                 :            :     mbShowEmptyCol( false ),
     958                 :            :     mbShowHeaders( true ),
     959                 :            :     mbFieldListSortAsc( false ),
     960                 :          0 :     mbCustomListSort( true )
     961                 :            : {
     962                 :          0 : }
     963                 :            : 
     964                 :            : // ----------------------------------------------------------------------------
     965                 :            : 
     966                 :          0 : PTLocationModel::PTLocationModel() :
     967                 :            :     mnFirstHeaderRow( 0 ),
     968                 :            :     mnFirstDataRow( 0 ),
     969                 :            :     mnFirstDataCol( 0 ),
     970                 :            :     mnRowPageCount( 0 ),
     971                 :          0 :     mnColPageCount( 0 )
     972                 :            : {
     973                 :          0 : }
     974                 :            : 
     975                 :            : // ----------------------------------------------------------------------------
     976                 :            : 
     977                 :          0 : PivotTable::PivotTable( const WorkbookHelper& rHelper ) :
     978                 :            :     WorkbookHelper( rHelper ),
     979                 :            :     mpDPObject(NULL),
     980                 :            :     maDataField( *this, OOX_PT_DATALAYOUTFIELD ),
     981 [ #  # ][ #  # ]:          0 :     mpPivotCache( 0 )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     982                 :            : {
     983                 :          0 : }
     984                 :            : 
     985                 :          0 : void PivotTable::importPivotTableDefinition( const AttributeList& rAttribs )
     986                 :            : {
     987         [ #  # ]:          0 :     maDefModel.maName                = rAttribs.getXString( XML_name, OUString() );
     988         [ #  # ]:          0 :     maDefModel.maDataCaption         = rAttribs.getXString( XML_dataCaption , OUString() );
     989         [ #  # ]:          0 :     maDefModel.maGrandTotalCaption   = rAttribs.getXString( XML_grandTotalCaption, OUString() );
     990         [ #  # ]:          0 :     maDefModel.maRowHeaderCaption    = rAttribs.getXString( XML_rowHeaderCaption, OUString() );
     991         [ #  # ]:          0 :     maDefModel.maColHeaderCaption    = rAttribs.getXString( XML_colHeaderCaption, OUString() );
     992         [ #  # ]:          0 :     maDefModel.maErrorCaption        = rAttribs.getXString( XML_errorCaption, OUString() );
     993         [ #  # ]:          0 :     maDefModel.maMissingCaption      = rAttribs.getXString( XML_missingCaption, OUString() );
     994         [ #  # ]:          0 :     maDefModel.maPageStyle           = rAttribs.getXString( XML_pageStyle, OUString() );
     995         [ #  # ]:          0 :     maDefModel.maPivotTableStyle     = rAttribs.getXString( XML_pivotTableStyle, OUString() );
     996         [ #  # ]:          0 :     maDefModel.maVacatedStyle        = rAttribs.getXString( XML_vacatedStyle, OUString() );
     997         [ #  # ]:          0 :     maDefModel.maTag                 = rAttribs.getXString( XML_tag, OUString() );
     998                 :          0 :     maDefModel.mnCacheId             = rAttribs.getInteger( XML_cacheId, -1 );
     999                 :          0 :     maDefModel.mnDataPosition        = rAttribs.getInteger( XML_dataPosition, 0 );
    1000                 :          0 :     maDefModel.mnPageWrap            = rAttribs.getInteger( XML_pageWrap, 0 );
    1001                 :          0 :     maDefModel.mnIndent              = rAttribs.getInteger( XML_indent, 1 );
    1002                 :          0 :     maDefModel.mnChartFormat         = rAttribs.getInteger( XML_chartFormat, 0 );
    1003                 :          0 :     maDefModel.mnAutoFormatId        = rAttribs.getInteger( XML_autoFormatId, 0 );
    1004                 :          0 :     maDefModel.mbDataOnRows          = rAttribs.getBool( XML_dataOnRows, false );
    1005                 :          0 :     maDefModel.mbShowError           = rAttribs.getBool( XML_showError, false );
    1006                 :          0 :     maDefModel.mbShowMissing         = rAttribs.getBool( XML_showMissing, true );
    1007                 :          0 :     maDefModel.mbShowItems           = rAttribs.getBool( XML_showItems, true );
    1008                 :          0 :     maDefModel.mbDisableFieldList    = rAttribs.getBool( XML_disableFieldList, false );
    1009                 :          0 :     maDefModel.mbShowCalcMembers     = rAttribs.getBool( XML_showCalcMbrs, true );
    1010                 :          0 :     maDefModel.mbVisualTotals        = rAttribs.getBool( XML_visualTotals, true );
    1011                 :          0 :     maDefModel.mbShowDrill           = rAttribs.getBool( XML_showDrill, true );
    1012                 :          0 :     maDefModel.mbPrintDrill          = rAttribs.getBool( XML_printDrill, false );
    1013                 :          0 :     maDefModel.mbEnableDrill         = rAttribs.getBool( XML_enableDrill, true );
    1014                 :          0 :     maDefModel.mbPreserveFormatting  = rAttribs.getBool( XML_preserveFormatting, true );
    1015                 :          0 :     maDefModel.mbUseAutoFormat       = rAttribs.getBool( XML_useAutoFormatting, false );
    1016                 :          0 :     maDefModel.mbPageOverThenDown    = rAttribs.getBool( XML_pageOverThenDown, false );
    1017                 :          0 :     maDefModel.mbSubtotalHiddenItems = rAttribs.getBool( XML_subtotalHiddenItems, false );
    1018                 :          0 :     maDefModel.mbRowGrandTotals      = rAttribs.getBool( XML_rowGrandTotals, true );
    1019                 :          0 :     maDefModel.mbColGrandTotals      = rAttribs.getBool( XML_colGrandTotals, true );
    1020                 :          0 :     maDefModel.mbFieldPrintTitles    = rAttribs.getBool( XML_fieldPrintTitles, false );
    1021                 :          0 :     maDefModel.mbItemPrintTitles     = rAttribs.getBool( XML_itemPrintTitles, false );
    1022                 :          0 :     maDefModel.mbMergeItem           = rAttribs.getBool( XML_mergeItem, false );
    1023                 :          0 :     maDefModel.mbShowEmptyRow        = rAttribs.getBool( XML_showEmptyRow, false );
    1024                 :          0 :     maDefModel.mbShowEmptyCol        = rAttribs.getBool( XML_showEmptyCol, false );
    1025                 :          0 :     maDefModel.mbShowHeaders         = rAttribs.getBool( XML_showHeaders, true );
    1026                 :          0 :     maDefModel.mbFieldListSortAsc    = rAttribs.getBool( XML_fieldListSortAscending, false );
    1027                 :          0 :     maDefModel.mbCustomListSort      = rAttribs.getBool( XML_customListSort, true );
    1028                 :          0 :     maDefModel.mbApplyNumFmt         = rAttribs.getBool( XML_applyNumberFormats, false );
    1029                 :          0 :     maDefModel.mbApplyFont           = rAttribs.getBool( XML_applyFontFormats, false );
    1030                 :          0 :     maDefModel.mbApplyAlignment      = rAttribs.getBool( XML_applyAlignmentFormats, false );
    1031                 :          0 :     maDefModel.mbApplyBorder         = rAttribs.getBool( XML_applyBorderFormats, false );
    1032                 :          0 :     maDefModel.mbApplyFill           = rAttribs.getBool( XML_applyPatternFormats, false );
    1033                 :            :     // OOXML and BIFF12 documentation differ: OOXML mentions width/height, BIFF12 mentions protection
    1034                 :          0 :     maDefModel.mbApplyProtection     = rAttribs.getBool( XML_applyWidthHeightFormats, false );
    1035                 :          0 : }
    1036                 :            : 
    1037                 :          0 : void PivotTable::importLocation( const AttributeList& rAttribs, sal_Int16 nSheet )
    1038                 :            : {
    1039 [ #  # ][ #  # ]:          0 :     getAddressConverter().convertToCellRangeUnchecked( maLocationModel.maRange, rAttribs.getString( XML_ref, OUString() ), nSheet );
                 [ #  # ]
    1040                 :          0 :     maLocationModel.mnFirstHeaderRow = rAttribs.getInteger( XML_firstHeaderRow, 0 );
    1041                 :          0 :     maLocationModel.mnFirstDataRow   = rAttribs.getInteger( XML_firstDataRow, 0 );
    1042                 :          0 :     maLocationModel.mnFirstDataCol   = rAttribs.getInteger( XML_firstDataCol, 0 );
    1043                 :          0 :     maLocationModel.mnRowPageCount   = rAttribs.getInteger( XML_rowPageCount, 0 );
    1044                 :          0 :     maLocationModel.mnColPageCount   = rAttribs.getInteger( XML_colPageCount, 0 );
    1045                 :          0 : }
    1046                 :            : 
    1047                 :          0 : void PivotTable::importRowField( const AttributeList& rAttribs )
    1048                 :            : {
    1049                 :          0 :     importField( maRowFields, rAttribs );
    1050                 :          0 : }
    1051                 :            : 
    1052                 :          0 : void PivotTable::importColField( const AttributeList& rAttribs )
    1053                 :            : {
    1054                 :          0 :     importField( maColFields, rAttribs );
    1055                 :          0 : }
    1056                 :            : 
    1057                 :          0 : void PivotTable::importPageField( const AttributeList& rAttribs )
    1058                 :            : {
    1059                 :          0 :     PTPageFieldModel aModel;
    1060         [ #  # ]:          0 :     aModel.maName      = rAttribs.getXString( XML_name, OUString() );
    1061         [ #  # ]:          0 :     aModel.mnField     = rAttribs.getInteger( XML_fld, -1 );
    1062                 :            :     // specification is wrong, XML_item is not the cache item, but the field item
    1063         [ #  # ]:          0 :     aModel.mnItem      = rAttribs.getInteger( XML_item, BIFF12_PTPAGEFIELD_MULTIITEMS );
    1064         [ #  # ]:          0 :     maPageFields.push_back( aModel );
    1065                 :          0 : }
    1066                 :            : 
    1067                 :          0 : void PivotTable::importDataField( const AttributeList& rAttribs )
    1068                 :            : {
    1069                 :          0 :     PTDataFieldModel aModel;
    1070         [ #  # ]:          0 :     aModel.maName       = rAttribs.getXString( XML_name, OUString() );
    1071         [ #  # ]:          0 :     aModel.mnField      = rAttribs.getInteger( XML_fld, -1 );
    1072         [ #  # ]:          0 :     aModel.mnSubtotal   = rAttribs.getToken( XML_subtotal, XML_sum );
    1073         [ #  # ]:          0 :     aModel.mnShowDataAs = rAttribs.getToken( XML_showDataAs, XML_normal );
    1074         [ #  # ]:          0 :     aModel.mnBaseField  = rAttribs.getInteger( XML_baseField, -1 );
    1075         [ #  # ]:          0 :     aModel.mnBaseItem   = rAttribs.getInteger( XML_baseItem, -1 );
    1076         [ #  # ]:          0 :     aModel.mnNumFmtId   = rAttribs.getInteger( XML_numFmtId, 0 );
    1077         [ #  # ]:          0 :     maDataFields.push_back( aModel );
    1078                 :          0 : }
    1079                 :            : 
    1080                 :          0 : void PivotTable::importPTDefinition( SequenceInputStream& rStrm )
    1081                 :            : {
    1082                 :            :     sal_uInt32 nFlags1, nFlags2, nFlags3;
    1083                 :            :     sal_uInt8 nDataAxis;
    1084 [ #  # ][ #  # ]:          0 :     rStrm >> nFlags1 >> nFlags2 >> nFlags3 >> nDataAxis;
         [ #  # ][ #  # ]
    1085         [ #  # ]:          0 :     maDefModel.mnPageWrap = rStrm.readuInt8();
    1086         [ #  # ]:          0 :     rStrm.skip( 2 );    // refresh versions
    1087         [ #  # ]:          0 :     rStrm >> maDefModel.mnDataPosition;
    1088         [ #  # ]:          0 :     maDefModel.mnAutoFormatId = rStrm.readuInt16();
    1089         [ #  # ]:          0 :     rStrm.skip( 2 );    // unused
    1090 [ #  # ][ #  # ]:          0 :     rStrm >> maDefModel.mnChartFormat >> maDefModel.mnCacheId >> maDefModel.maName;
                 [ #  # ]
    1091         [ #  # ]:          0 :     if( getFlag( nFlags2, BIFF12_PTDEF_HASDATACAPTION ) )
    1092         [ #  # ]:          0 :         rStrm >> maDefModel.maDataCaption;
    1093         [ #  # ]:          0 :     if( getFlag( nFlags2, BIFF12_PTDEF_HASGRANDTOTALCAPTION ) )
    1094         [ #  # ]:          0 :         rStrm >> maDefModel.maGrandTotalCaption;
    1095         [ #  # ]:          0 :     if( !getFlag( nFlags3, BIFF12_PTDEF_NOERRORCAPTION ) )   // missing flag indicates existing string
    1096         [ #  # ]:          0 :         rStrm >> maDefModel.maErrorCaption;
    1097         [ #  # ]:          0 :     if( !getFlag( nFlags3, BIFF12_PTDEF_NOMISSINGCAPTION ) ) // missing flag indicates existing string
    1098         [ #  # ]:          0 :         rStrm >> maDefModel.maMissingCaption;
    1099         [ #  # ]:          0 :     if( getFlag( nFlags2, BIFF12_PTDEF_HASPAGESTYLE ) )
    1100         [ #  # ]:          0 :         rStrm >> maDefModel.maPageStyle;
    1101         [ #  # ]:          0 :     if( getFlag( nFlags2, BIFF12_PTDEF_HASPIVOTTABLESTYLE ) )
    1102         [ #  # ]:          0 :         rStrm >> maDefModel.maPivotTableStyle;
    1103         [ #  # ]:          0 :     if( getFlag( nFlags2, BIFF12_PTDEF_HASVACATEDSTYLE ) )
    1104         [ #  # ]:          0 :         rStrm >> maDefModel.maVacatedStyle;
    1105         [ #  # ]:          0 :     if( getFlag( nFlags2, BIFF12_PTDEF_HASTAG ) )
    1106         [ #  # ]:          0 :         rStrm >> maDefModel.maTag;
    1107         [ #  # ]:          0 :     if( getFlag( nFlags3, BIFF12_PTDEF_HASCOLHEADERCAPTION ) )   // TODO: right order (col/row)? spec is unclear
    1108         [ #  # ]:          0 :         rStrm >> maDefModel.maColHeaderCaption;
    1109         [ #  # ]:          0 :     if( getFlag( nFlags3, BIFF12_PTDEF_HASROWHEADERCAPTION ) )
    1110         [ #  # ]:          0 :         rStrm >> maDefModel.maRowHeaderCaption;
    1111                 :            : 
    1112                 :            :     OSL_ENSURE( (nDataAxis == BIFF12_PTDEF_ROWAXIS) || (nDataAxis == BIFF12_PTDEF_COLAXIS),
    1113                 :            :         "PivotTable::importPTDefinition - unexpected axis position for data field" );
    1114                 :            : 
    1115                 :          0 :     maDefModel.mnIndent              = extractValue< sal_uInt8 >( nFlags1, 24, 7 );
    1116                 :          0 :     maDefModel.mbDataOnRows          = nDataAxis == BIFF12_PTDEF_ROWAXIS;
    1117                 :          0 :     maDefModel.mbShowError           = getFlag( nFlags2, BIFF12_PTDEF_SHOWERROR );
    1118                 :          0 :     maDefModel.mbShowMissing         = getFlag( nFlags2, BIFF12_PTDEF_SHOWMISSING );
    1119                 :          0 :     maDefModel.mbShowItems           = getFlag( nFlags1, BIFF12_PTDEF_SHOWITEMS );
    1120                 :          0 :     maDefModel.mbDisableFieldList    = getFlag( nFlags1, BIFF12_PTDEF_DISABLEFIELDLIST );
    1121                 :          0 :     maDefModel.mbShowCalcMembers     = !getFlag( nFlags1, BIFF12_PTDEF_HIDECALCMEMBERS );
    1122                 :          0 :     maDefModel.mbVisualTotals        = !getFlag( nFlags1, BIFF12_PTDEF_WITHHIDDENTOTALS );
    1123                 :          0 :     maDefModel.mbShowDrill           = !getFlag( nFlags1, BIFF12_PTDEF_HIDEDRILL );
    1124                 :          0 :     maDefModel.mbPrintDrill          = getFlag( nFlags1, BIFF12_PTDEF_PRINTDRILL );
    1125                 :          0 :     maDefModel.mbEnableDrill         = getFlag( nFlags2, BIFF12_PTDEF_ENABLEDRILL );
    1126                 :          0 :     maDefModel.mbPreserveFormatting  = getFlag( nFlags2, BIFF12_PTDEF_PRESERVEFORMATTING );
    1127                 :          0 :     maDefModel.mbUseAutoFormat       = getFlag( nFlags2, BIFF12_PTDEF_USEAUTOFORMAT );
    1128                 :          0 :     maDefModel.mbPageOverThenDown    = getFlag( nFlags2, BIFF12_PTDEF_PAGEOVERTHENDOWN );
    1129                 :          0 :     maDefModel.mbSubtotalHiddenItems = getFlag( nFlags2, BIFF12_PTDEF_SUBTOTALHIDDENITEMS );
    1130                 :          0 :     maDefModel.mbRowGrandTotals      = getFlag( nFlags2, BIFF12_PTDEF_ROWGRANDTOTALS );
    1131                 :          0 :     maDefModel.mbColGrandTotals      = getFlag( nFlags2, BIFF12_PTDEF_COLGRANDTOTALS );
    1132                 :          0 :     maDefModel.mbFieldPrintTitles    = getFlag( nFlags2, BIFF12_PTDEF_FIELDPRINTTITLES );
    1133                 :          0 :     maDefModel.mbItemPrintTitles     = getFlag( nFlags2, BIFF12_PTDEF_ITEMPRINTTITLES );
    1134                 :          0 :     maDefModel.mbMergeItem           = getFlag( nFlags2, BIFF12_PTDEF_MERGEITEM );
    1135                 :          0 :     maDefModel.mbApplyNumFmt         = getFlag( nFlags2, BIFF12_PTDEF_APPLYNUMFMT );
    1136                 :          0 :     maDefModel.mbApplyFont           = getFlag( nFlags2, BIFF12_PTDEF_APPLYFONT );
    1137                 :          0 :     maDefModel.mbApplyAlignment      = getFlag( nFlags2, BIFF12_PTDEF_APPLYALIGNMENT );
    1138                 :          0 :     maDefModel.mbApplyBorder         = getFlag( nFlags2, BIFF12_PTDEF_APPLYBORDER );
    1139                 :          0 :     maDefModel.mbApplyFill           = getFlag( nFlags2, BIFF12_PTDEF_APPLYFILL );
    1140                 :          0 :     maDefModel.mbApplyProtection     = getFlag( nFlags2, BIFF12_PTDEF_APPLYPROTECTION );
    1141                 :          0 :     maDefModel.mbShowEmptyRow        = getFlag( nFlags2, BIFF12_PTDEF_SHOWEMPTYROW );
    1142                 :          0 :     maDefModel.mbShowEmptyCol        = getFlag( nFlags2, BIFF12_PTDEF_SHOWEMPTYCOL );
    1143                 :          0 :     maDefModel.mbShowHeaders         = !getFlag( nFlags1, BIFF12_PTDEF_HIDEHEADERS );
    1144                 :          0 :     maDefModel.mbFieldListSortAsc    = getFlag( nFlags3, BIFF12_PTDEF_FIELDLISTSORTASC );
    1145                 :          0 :     maDefModel.mbCustomListSort      = !getFlag( nFlags3, BIFF12_PTDEF_NOCUSTOMLISTSORT );
    1146                 :          0 : }
    1147                 :            : 
    1148                 :          0 : void PivotTable::importPTLocation( SequenceInputStream& rStrm, sal_Int16 nSheet )
    1149                 :            : {
    1150                 :          0 :     BinRange aBinRange;
    1151 [ #  # ][ #  # ]:          0 :     rStrm   >> aBinRange >> maLocationModel.mnFirstHeaderRow
    1152 [ #  # ][ #  # ]:          0 :             >> maLocationModel.mnFirstDataRow >> maLocationModel.mnFirstDataCol
    1153 [ #  # ][ #  # ]:          0 :             >> maLocationModel.mnRowPageCount >> maLocationModel.mnColPageCount;
    1154 [ #  # ][ #  # ]:          0 :     getAddressConverter().convertToCellRangeUnchecked( maLocationModel.maRange, aBinRange, nSheet );
    1155                 :          0 : }
    1156                 :            : 
    1157                 :          0 : void PivotTable::importPTRowFields( SequenceInputStream& rStrm )
    1158                 :            : {
    1159                 :          0 :     importFields( maRowFields, rStrm );
    1160                 :          0 : }
    1161                 :            : 
    1162                 :          0 : void PivotTable::importPTColFields( SequenceInputStream& rStrm )
    1163                 :            : {
    1164                 :          0 :     importFields( maColFields, rStrm );
    1165                 :          0 : }
    1166                 :            : 
    1167                 :          0 : void PivotTable::importPTPageField( SequenceInputStream& rStrm )
    1168                 :            : {
    1169                 :          0 :     PTPageFieldModel aModel;
    1170                 :            :     sal_uInt8 nFlags;
    1171 [ #  # ][ #  # ]:          0 :     rStrm >> aModel.mnField >> aModel.mnItem;
    1172         [ #  # ]:          0 :     rStrm.skip( 4 );    // hierarchy
    1173         [ #  # ]:          0 :     rStrm >> nFlags;
    1174         [ #  # ]:          0 :     if( getFlag( nFlags, BIFF12_PTPAGEFIELD_HASNAME ) )
    1175         [ #  # ]:          0 :         rStrm >> aModel.maName;
    1176         [ #  # ]:          0 :     maPageFields.push_back( aModel );
    1177                 :          0 : }
    1178                 :            : 
    1179                 :          0 : void PivotTable::importPTDataField( SequenceInputStream& rStrm )
    1180                 :            : {
    1181                 :          0 :     PTDataFieldModel aModel;
    1182                 :            :     sal_Int32 nSubtotal, nShowDataAs;
    1183                 :            :     sal_uInt8 nHasName;
    1184 [ #  # ][ #  # ]:          0 :     rStrm >> aModel.mnField >> nSubtotal >> nShowDataAs >> aModel.mnBaseField >> aModel.mnBaseItem >> aModel.mnNumFmtId >> nHasName;
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1185         [ #  # ]:          0 :     if( nHasName == 1 )
    1186         [ #  # ]:          0 :         rStrm >> aModel.maName;
    1187                 :          0 :     aModel.setBiffSubtotal( nSubtotal );
    1188                 :          0 :     aModel.setBiffShowDataAs( nShowDataAs );
    1189         [ #  # ]:          0 :     maDataFields.push_back( aModel );
    1190                 :          0 : }
    1191                 :            : 
    1192                 :          0 : PivotTableField& PivotTable::createTableField()
    1193                 :            : {
    1194                 :          0 :     sal_Int32 nFieldIndex = static_cast< sal_Int32 >( maFields.size() );
    1195 [ #  # ][ #  # ]:          0 :     PivotTableFieldVector::value_type xTableField( new PivotTableField( *this, nFieldIndex ) );
                 [ #  # ]
    1196         [ #  # ]:          0 :     maFields.push_back( xTableField );
    1197         [ #  # ]:          0 :     return *xTableField;
    1198                 :            : }
    1199                 :            : 
    1200                 :          0 : PivotTableFilter& PivotTable::createTableFilter()
    1201                 :            : {
    1202 [ #  # ][ #  # ]:          0 :     PivotTableFilterVector::value_type xTableFilter( new PivotTableFilter( *this ) );
                 [ #  # ]
    1203         [ #  # ]:          0 :     maFilters.push_back( xTableFilter );
    1204         [ #  # ]:          0 :     return *xTableFilter;
    1205                 :            : }
    1206                 :            : 
    1207                 :          0 : void PivotTable::finalizeImport()
    1208                 :            : {
    1209         [ #  # ]:          0 :     if( getAddressConverter().validateCellRange( maLocationModel.maRange, true, true ) )
    1210                 :            :     {
    1211                 :          0 :         mpPivotCache = getPivotCaches().importPivotCacheFragment( maDefModel.mnCacheId );
    1212 [ #  # ][ #  # ]:          0 :         if( mpPivotCache && mpPivotCache->isValidDataSource() && !maDefModel.maName.isEmpty() )
         [ #  # ][ #  # ]
    1213                 :            :         {
    1214                 :            :             // clear destination area of the original pivot table
    1215                 :            :             try
    1216                 :            :             {
    1217 [ #  # ][ #  # ]:          0 :                 Reference< XSheetOperation > xSheetOp( getCellRangeFromDoc( maLocationModel.maRange ), UNO_QUERY_THROW );
    1218                 :            :                 using namespace ::com::sun::star::sheet::CellFlags;
    1219 [ #  # ][ #  # ]:          0 :                 xSheetOp->clearContents( VALUE | DATETIME | STRING | FORMULA | HARDATTR | STYLES | EDITATTR | FORMATTED );
                 [ #  # ]
    1220                 :            :             }
    1221                 :          0 :             catch( Exception& )
    1222                 :            :             {
    1223                 :            :             }
    1224                 :            : 
    1225                 :            :             try
    1226                 :            :             {
    1227                 :            :                 // create a new data pilot descriptor based on the source data
    1228 [ #  # ][ #  # ]:          0 :                 Reference< XDataPilotTablesSupplier > xDPTablesSupp( getSheetFromDoc( maLocationModel.maRange.Sheet ), UNO_QUERY_THROW );
    1229 [ #  # ][ #  # ]:          0 :                 Reference< XDataPilotTables > xDPTables( xDPTablesSupp->getDataPilotTables(), UNO_SET_THROW );
                 [ #  # ]
    1230 [ #  # ][ #  # ]:          0 :                 mxDPDescriptor.set( xDPTables->createDataPilotDescriptor(), UNO_SET_THROW );
                 [ #  # ]
    1231 [ #  # ][ #  # ]:          0 :                 mxDPDescriptor->setSourceRange( mpPivotCache->getSourceRange() );
    1232 [ #  # ][ #  # ]:          0 :                 mxDPDescriptor->setTag( maDefModel.maTag );
    1233                 :            : 
    1234                 :            :                 // TODO: This is a hack. Eventually we need to convert the whole thing to the internal API.
    1235         [ #  # ]:          0 :                 ScDataPilotDescriptorBase* pImpl = ScDataPilotDescriptorBase::getImplementation(mxDPDescriptor);
    1236         [ #  # ]:          0 :                 if (!pImpl)
    1237                 :            :                     return;
    1238                 :            : 
    1239         [ #  # ]:          0 :                 mpDPObject = pImpl->GetDPObject();
    1240         [ #  # ]:          0 :                 if (!mpDPObject)
    1241                 :            :                     return;
    1242                 :            : 
    1243                 :            :                 // global data pilot properties
    1244         [ #  # ]:          0 :                 PropertySet aDescProp( mxDPDescriptor );
    1245         [ #  # ]:          0 :                 aDescProp.setProperty( PROP_ColumnGrand, maDefModel.mbColGrandTotals );
    1246         [ #  # ]:          0 :                 aDescProp.setProperty( PROP_RowGrand, maDefModel.mbRowGrandTotals );
    1247         [ #  # ]:          0 :                 aDescProp.setProperty( PROP_ShowFilterButton, false );
    1248         [ #  # ]:          0 :                 aDescProp.setProperty( PROP_DrillDownOnDoubleClick, maDefModel.mbEnableDrill );
    1249                 :            : 
    1250                 :            :                 // finalize all fields, this finds field names and creates grouping fields
    1251 [ #  # ][ #  # ]:          0 :                 maFields.forEachMem( &PivotTableField::finalizeImport, ::boost::cref( mxDPDescriptor ) );
    1252                 :            : 
    1253                 :            :                 // all row fields
    1254 [ #  # ][ #  # ]:          0 :                 for( IndexVector::iterator aIt = maRowFields.begin(), aEnd = maRowFields.end(); aIt != aEnd; ++aIt )
                 [ #  # ]
    1255 [ #  # ][ #  # ]:          0 :                     if( PivotTableField* pField = getTableField( *aIt ) )
                 [ #  # ]
    1256         [ #  # ]:          0 :                         pField->convertRowField();
    1257                 :            : 
    1258                 :            :                 // all column fields
    1259 [ #  # ][ #  # ]:          0 :                 for( IndexVector::iterator aIt = maColFields.begin(), aEnd = maColFields.end(); aIt != aEnd; ++aIt )
                 [ #  # ]
    1260 [ #  # ][ #  # ]:          0 :                     if( PivotTableField* pField = getTableField( *aIt ) )
                 [ #  # ]
    1261         [ #  # ]:          0 :                         pField->convertColField();
    1262                 :            : 
    1263                 :            :                 // all page fields
    1264 [ #  # ][ #  # ]:          0 :                 for( PageFieldVector::iterator aIt = maPageFields.begin(), aEnd = maPageFields.end(); aIt != aEnd; ++aIt )
    1265 [ #  # ][ #  # ]:          0 :                     if( PivotTableField* pField = getTableField( aIt->mnField ) )
    1266         [ #  # ]:          0 :                         pField->convertPageField( *aIt );
    1267                 :            : 
    1268                 :            :                 // all hidden fields
    1269         [ #  # ]:          0 :                 ::std::set< sal_Int32 > aVisFields;
    1270         [ #  # ]:          0 :                 aVisFields.insert( maRowFields.begin(), maRowFields.end() );
    1271         [ #  # ]:          0 :                 aVisFields.insert( maColFields.begin(), maColFields.end() );
    1272 [ #  # ][ #  # ]:          0 :                 for( PageFieldVector::iterator aIt = maPageFields.begin(), aEnd = maPageFields.end(); aIt != aEnd; ++aIt )
    1273         [ #  # ]:          0 :                     aVisFields.insert( aIt->mnField );
    1274 [ #  # ][ #  # ]:          0 :                 for( PivotTableFieldVector::iterator aBeg = maFields.begin(), aIt = aBeg, aEnd = maFields.end(); aIt != aEnd; ++aIt )
    1275 [ #  # ][ #  # ]:          0 :                     if( aVisFields.count( static_cast< sal_Int32 >( aIt - aBeg ) ) == 0 )
                 [ #  # ]
    1276         [ #  # ]:          0 :                         (*aIt)->convertHiddenField();
    1277                 :            : 
    1278                 :            :                 // all data fields
    1279 [ #  # ][ #  # ]:          0 :                 for( DataFieldVector::iterator aIt = maDataFields.begin(), aEnd = maDataFields.end(); aIt != aEnd; ++aIt )
    1280                 :            :                 {
    1281 [ #  # ][ #  # ]:          0 :                     if( const PivotCacheField* pCacheField = getCacheField( aIt->mnField  ) )
    1282                 :            :                     {
    1283         [ #  # ]:          0 :                         if ( pCacheField-> getGroupBaseField() != -1 )
    1284                 :          0 :                             aIt->mnField = pCacheField-> getGroupBaseField();
    1285                 :            :                     }
    1286 [ #  # ][ #  # ]:          0 :                     if( PivotTableField* pField = getTableField( aIt->mnField ) )
    1287         [ #  # ]:          0 :                         pField->convertDataField( *aIt );
    1288                 :            :                 }
    1289                 :            : 
    1290                 :            :                 // filters
    1291         [ #  # ]:          0 :                 maFilters.forEachMem( &PivotTableFilter::finalizeImport );
    1292                 :            : 
    1293                 :            :                 // calculate base position of table
    1294                 :          0 :                 CellAddress aPos( maLocationModel.maRange.Sheet, maLocationModel.maRange.StartColumn, maLocationModel.maRange.StartRow );
    1295                 :            :                 /*  If page fields exist, include them into the destination
    1296                 :            :                     area (they are excluded in Excel). Add an extra blank row. */
    1297         [ #  # ]:          0 :                 if( !maPageFields.empty() )
    1298         [ #  # ]:          0 :                     aPos.Row = ::std::max< sal_Int32 >( static_cast< sal_Int32 >( aPos.Row - maPageFields.size() - 1 ), 0 );
    1299                 :            : 
    1300                 :            :                 // insert the DataPilot table into the sheet
    1301 [ #  # ][ #  # ]:          0 :                 xDPTables->insertNewByName( maDefModel.maName, aPos, mxDPDescriptor );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1302                 :            :             }
    1303                 :          0 :             catch( Exception& )
    1304                 :            :             {
    1305                 :            :                 OSL_FAIL( "PivotTable::finalizeImport - exception while creating the DataPilot table" );
    1306                 :            :             }
    1307                 :            :         }
    1308                 :            :     }
    1309                 :            : }
    1310                 :            : 
    1311                 :          0 : void PivotTable::finalizeDateGroupingImport( const Reference< XDataPilotField >& rxBaseDPField, sal_Int32 nBaseFieldIdx )
    1312                 :            : {
    1313                 :            :     // process all fields, there is no chaining information in the cache fields
    1314                 :          0 :     maFields.forEachMem( &PivotTableField::finalizeDateGroupingImport, ::boost::cref( rxBaseDPField ), nBaseFieldIdx );
    1315                 :          0 : }
    1316                 :            : 
    1317                 :          0 : void PivotTable::finalizeParentGroupingImport( const Reference< XDataPilotField >& rxBaseDPField,
    1318                 :            :         const PivotCacheField& rBaseCacheField, PivotCacheGroupItemVector& orItemNames )
    1319                 :            : {
    1320                 :            :     // try to create parent group fields that group the items of the passed base field
    1321         [ #  # ]:          0 :     if( PivotTableField* pParentTableField = maFields.get( rBaseCacheField.getParentGroupField() ).get() )
    1322                 :          0 :         pParentTableField->finalizeParentGroupingImport( rxBaseDPField, rBaseCacheField, orItemNames );
    1323                 :          0 : }
    1324                 :            : 
    1325                 :          0 : Reference< XDataPilotField > PivotTable::getDataPilotField( const OUString& rFieldName ) const
    1326                 :            : {
    1327                 :          0 :     Reference< XDataPilotField > xDPField;
    1328 [ #  # ][ #  # ]:          0 :     if( !rFieldName.isEmpty() && mxDPDescriptor.is() ) try
                 [ #  # ]
    1329                 :            :     {
    1330 [ #  # ][ #  # ]:          0 :         Reference< XNameAccess > xDPFieldsNA( mxDPDescriptor->getDataPilotFields(), UNO_QUERY_THROW );
                 [ #  # ]
    1331 [ #  # ][ #  # ]:          0 :         xDPField.set( xDPFieldsNA->getByName( rFieldName ), UNO_QUERY );
         [ #  # ][ #  # ]
    1332                 :            :     }
    1333         [ #  # ]:          0 :     catch( Exception& )
    1334                 :            :     {
    1335                 :            :     }
    1336                 :          0 :     return xDPField;
    1337                 :            : }
    1338                 :            : 
    1339                 :          0 : Reference< XDataPilotField > PivotTable::getDataPilotField( sal_Int32 nFieldIdx ) const
    1340                 :            : {
    1341                 :          0 :     Reference< XDataPilotField > xDPField;
    1342 [ #  # ][ #  # ]:          0 :     if( const PivotTableField* pTableField = maFields.get( nFieldIdx ).get() )
                 [ #  # ]
    1343 [ #  # ][ #  # ]:          0 :         xDPField = getDataPilotField( pTableField->getDPFieldName() );
    1344                 :          0 :     return xDPField;
    1345                 :            : }
    1346                 :            : 
    1347                 :          0 : Reference< XDataPilotField > PivotTable::getDataLayoutField() const
    1348                 :            : {
    1349                 :          0 :     Reference< XDataPilotField > xDPField;
    1350                 :            :     try
    1351                 :            :     {
    1352         [ #  # ]:          0 :         Reference< XDataPilotDataLayoutFieldSupplier > xDPDataFieldSupp( mxDPDescriptor, UNO_QUERY_THROW );
    1353 [ #  # ][ #  # ]:          0 :         xDPField = xDPDataFieldSupp->getDataLayoutField();
         [ #  # ][ #  # ]
    1354                 :            :     }
    1355         [ #  # ]:          0 :     catch( Exception& )
    1356                 :            :     {
    1357                 :            :     }
    1358                 :          0 :     return xDPField;
    1359                 :            : }
    1360                 :            : 
    1361                 :          0 : const PivotCacheField* PivotTable::getCacheField( sal_Int32 nFieldIdx ) const
    1362                 :            : {
    1363         [ #  # ]:          0 :     return mpPivotCache ? mpPivotCache->getCacheField( nFieldIdx ) : 0;
    1364                 :            : }
    1365                 :            : 
    1366                 :          0 : const PivotCacheField* PivotTable::getCacheFieldOfDataField( sal_Int32 nDataItemIdx ) const
    1367                 :            : {
    1368                 :          0 :     const PTDataFieldModel* pDataField = ContainerHelper::getVectorElement( maDataFields, nDataItemIdx );
    1369         [ #  # ]:          0 :     return pDataField ? getCacheField( pDataField->mnField ) : 0;
    1370                 :            : }
    1371                 :            : 
    1372                 :          0 : sal_Int32 PivotTable::getCacheDatabaseIndex( sal_Int32 nFieldIdx ) const
    1373                 :            : {
    1374         [ #  # ]:          0 :     return mpPivotCache ? mpPivotCache->getCacheDatabaseIndex( nFieldIdx ) : -1;
    1375                 :            : }
    1376                 :            : 
    1377                 :          0 : ScDPObject* PivotTable::getDPObject()
    1378                 :            : {
    1379                 :          0 :     return mpDPObject;
    1380                 :            : }
    1381                 :            : 
    1382                 :            : // private --------------------------------------------------------------------
    1383                 :            : 
    1384                 :          0 : PivotTableField* PivotTable::getTableField( sal_Int32 nFieldIdx )
    1385                 :            : {
    1386 [ #  # ][ #  # ]:          0 :     return (nFieldIdx == OOX_PT_DATALAYOUTFIELD) ? &maDataField : maFields.get( nFieldIdx ).get();
         [ #  # ][ #  # ]
    1387                 :            : }
    1388                 :            : 
    1389                 :          0 : void PivotTable::importField( IndexVector& orFields, const AttributeList& rAttribs )
    1390                 :            : {
    1391         [ #  # ]:          0 :     orFields.push_back( rAttribs.getInteger( XML_x, -1 ) );
    1392                 :          0 : }
    1393                 :            : 
    1394                 :          0 : void PivotTable::importFields( IndexVector& orFields, SequenceInputStream& rStrm )
    1395                 :            : {
    1396                 :            :     OSL_ENSURE( orFields.empty(), "PivotTable::importFields - multiple record instances" );
    1397                 :          0 :     orFields.clear();
    1398                 :          0 :     sal_Int32 nCount = rStrm.readInt32();
    1399                 :            :     OSL_ENSURE( 4 * nCount == rStrm.getRemaining(), "PivotTable::importFields - invalid field count" );
    1400                 :          0 :     nCount = static_cast< sal_Int32 >( rStrm.getRemaining() / 4 );
    1401         [ #  # ]:          0 :     for( sal_Int32 nIdx = 0; nIdx < nCount; ++nIdx )
    1402         [ #  # ]:          0 :         orFields.push_back( rStrm.readInt32() );
    1403                 :          0 : }
    1404                 :            : 
    1405                 :            : // ============================================================================
    1406                 :            : 
    1407                 :         24 : PivotTableBuffer::PivotTableBuffer( const WorkbookHelper& rHelper ) :
    1408         [ +  - ]:         24 :     WorkbookHelper( rHelper )
    1409                 :            : {
    1410                 :         24 : }
    1411                 :            : 
    1412                 :          0 : PivotTable& PivotTableBuffer::createPivotTable()
    1413                 :            : {
    1414 [ #  # ][ #  # ]:          0 :     PivotTableVector::value_type xTable( new PivotTable( *this ) );
                 [ #  # ]
    1415         [ #  # ]:          0 :     maTables.push_back( xTable );
    1416         [ #  # ]:          0 :     return *xTable;
    1417                 :            : }
    1418                 :            : 
    1419                 :         24 : void PivotTableBuffer::finalizeImport()
    1420                 :            : {
    1421                 :         24 :     maTables.forEachMem( &PivotTable::finalizeImport );
    1422                 :         24 : }
    1423                 :            : 
    1424                 :            : // ============================================================================
    1425                 :            : 
    1426                 :            : } // namespace xls
    1427 [ +  - ][ +  - ]:         24 : } // namespace oox
    1428                 :            : 
    1429                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10