LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sc/source/filter/oox - tablebuffer.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 8 58 13.8 %
Date: 2013-07-09 Functions: 4 13 30.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "tablebuffer.hxx"
      21             : 
      22             : #include <com/sun/star/sheet/XDatabaseRange.hpp>
      23             : #include "oox/helper/attributelist.hxx"
      24             : #include "oox/helper/binaryinputstream.hxx"
      25             : #include "oox/helper/propertyset.hxx"
      26             : #include "oox/token/properties.hxx"
      27             : #include "addressconverter.hxx"
      28             : 
      29             : namespace oox {
      30             : namespace xls {
      31             : 
      32             : // ============================================================================
      33             : 
      34             : using namespace ::com::sun::star::container;
      35             : using namespace ::com::sun::star::sheet;
      36             : using namespace ::com::sun::star::uno;
      37             : 
      38             : 
      39             : // ============================================================================
      40             : 
      41           0 : TableModel::TableModel() :
      42             :     mnId( -1 ),
      43             :     mnType( XML_worksheet ),
      44             :     mnHeaderRows( 1 ),
      45           0 :     mnTotalsRows( 0 )
      46             : {
      47           0 : }
      48             : 
      49             : // ============================================================================
      50             : 
      51           0 : Table::Table( const WorkbookHelper& rHelper ) :
      52             :     WorkbookHelper( rHelper ),
      53             :     maAutoFilters( rHelper ),
      54           0 :     mnTokenIndex( -1 )
      55             : {
      56           0 : }
      57             : 
      58           0 : void Table::importTable( const AttributeList& rAttribs, sal_Int16 nSheet )
      59             : {
      60           0 :     getAddressConverter().convertToCellRangeUnchecked( maModel.maRange, rAttribs.getString( XML_ref, OUString() ), nSheet );
      61           0 :     maModel.maProgName    = rAttribs.getXString( XML_name, OUString() );
      62           0 :     maModel.maDisplayName = rAttribs.getXString( XML_displayName, OUString() );
      63           0 :     maModel.mnId          = rAttribs.getInteger( XML_id, -1 );
      64           0 :     maModel.mnType        = rAttribs.getToken( XML_tableType, XML_worksheet );
      65           0 :     maModel.mnHeaderRows  = rAttribs.getInteger( XML_headerRowCount, 1 );
      66           0 :     maModel.mnTotalsRows  = rAttribs.getInteger( XML_totalsRowCount, 0 );
      67           0 : }
      68             : 
      69           0 : void Table::importTable( SequenceInputStream& rStrm, sal_Int16 nSheet )
      70             : {
      71           0 :     BinRange aBinRange;
      72             :     sal_Int32 nType;
      73           0 :     rStrm >> aBinRange >> nType >> maModel.mnId >> maModel.mnHeaderRows >> maModel.mnTotalsRows;
      74           0 :     rStrm.skip( 32 );
      75           0 :     rStrm >> maModel.maProgName >> maModel.maDisplayName;
      76             : 
      77           0 :     getAddressConverter().convertToCellRangeUnchecked( maModel.maRange, aBinRange, nSheet );
      78             :     static const sal_Int32 spnTypes[] = { XML_worksheet, XML_TOKEN_INVALID, XML_TOKEN_INVALID, XML_queryTable };
      79           0 :     maModel.mnType = STATIC_ARRAY_SELECT( spnTypes, nType, XML_TOKEN_INVALID );
      80           0 : }
      81             : 
      82           0 : void Table::finalizeImport()
      83             : {
      84             :     // Create database range.  Note that Excel 2007 and later names database
      85             :     // ranges (or tables in their terminology) as Table1, Table2 etc.  We need
      86             :     // to import them as named db ranges because they may be referenced by
      87             :     // name in formula expressions.
      88           0 :     if( (maModel.mnId > 0) && !maModel.maDisplayName.isEmpty() ) try
      89             :     {
      90           0 :         maDBRangeName = maModel.maDisplayName;
      91             :         Reference< XDatabaseRange > xDatabaseRange(
      92           0 :             createDatabaseRangeObject( maDBRangeName, maModel.maRange ), UNO_SET_THROW);
      93           0 :         maDestRange = xDatabaseRange->getDataArea();
      94             : 
      95             :         // get formula token index of the database range
      96           0 :         PropertySet aPropSet( xDatabaseRange );
      97           0 :         if( !aPropSet.getProperty( mnTokenIndex, PROP_TokenIndex ) )
      98           0 :             mnTokenIndex = -1;
      99             : 
     100             :         // filter settings
     101           0 :         maAutoFilters.finalizeImport( xDatabaseRange );
     102             :     }
     103           0 :     catch( Exception& )
     104             :     {
     105             :         OSL_FAIL( "Table::finalizeImport - cannot create database range" );
     106             :     }
     107           0 : }
     108             : 
     109             : // ============================================================================
     110             : 
     111          21 : TableBuffer::TableBuffer( const WorkbookHelper& rHelper ) :
     112          21 :     WorkbookHelper( rHelper )
     113             : {
     114          21 : }
     115             : 
     116           0 : Table& TableBuffer::createTable()
     117             : {
     118           0 :     TableVector::value_type xTable( new Table( *this ) );
     119           0 :     maTables.push_back( xTable );
     120           0 :     return *xTable;
     121             : }
     122             : 
     123          21 : void TableBuffer::finalizeImport()
     124             : {
     125             :     // map all tables by identifier and display name
     126          21 :     for( TableVector::iterator aIt = maTables.begin(), aEnd = maTables.end(); aIt != aEnd; ++aIt )
     127           0 :         insertTableToMaps( *aIt );
     128             :     // finalize all valid tables
     129          21 :     maIdTables.forEachMem( &Table::finalizeImport );
     130          21 : }
     131             : 
     132           0 : TableRef TableBuffer::getTable( sal_Int32 nTableId ) const
     133             : {
     134           0 :     return maIdTables.get( nTableId );
     135             : }
     136             : 
     137           0 : TableRef TableBuffer::getTable( const OUString& rDispName ) const
     138             : {
     139           0 :     return maNameTables.get( rDispName );
     140             : }
     141             : 
     142             : // private --------------------------------------------------------------------
     143             : 
     144           0 : void TableBuffer::insertTableToMaps( const TableRef& rxTable )
     145             : {
     146           0 :     sal_Int32 nTableId = rxTable->getTableId();
     147           0 :     const OUString& rDispName = rxTable->getDisplayName();
     148           0 :     if( (nTableId > 0) && !rDispName.isEmpty() )
     149             :     {
     150             :         OSL_ENSURE( !maIdTables.has( nTableId ), "TableBuffer::insertTableToMaps - multiple table identifier" );
     151           0 :         maIdTables[ nTableId ] = rxTable;
     152             :         OSL_ENSURE( !maNameTables.has( rDispName ), "TableBuffer::insertTableToMaps - multiple table name" );
     153           0 :         maNameTables[ rDispName ] = rxTable;
     154             :     }
     155           0 : }
     156             : 
     157             : // ============================================================================
     158             : 
     159             : } // namespace xls
     160          15 : } // namespace oox
     161             : 
     162             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10