LCOV - code coverage report
Current view: top level - sc/source/filter/xml - XMLColumnRowGroupExport.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 24 84 28.6 %
Date: 2014-11-03 Functions: 6 14 42.9 %
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 "XMLColumnRowGroupExport.hxx"
      21             : #include "xmlexprt.hxx"
      22             : #include <xmloff/nmspmap.hxx>
      23             : #include <xmloff/xmltoken.hxx>
      24             : #include <xmloff/xmlnmspe.hxx>
      25             : 
      26             : #include <algorithm>
      27             : 
      28             : using namespace xmloff::token;
      29             : 
      30           0 : ScMyColumnRowGroup::ScMyColumnRowGroup()
      31             :     : nField(0)
      32             :     , nLevel(0)
      33           0 :     , bDisplay(false)
      34             : {
      35           0 : }
      36             : 
      37           0 : bool ScMyColumnRowGroup::operator<(const ScMyColumnRowGroup& rGroup) const
      38             : {
      39           0 :     if (rGroup.nField > nField)
      40           0 :         return true;
      41             :     else
      42           0 :         if (rGroup.nField == nField && rGroup.nLevel > nLevel)
      43           0 :             return true;
      44             :         else
      45           0 :             return false;
      46             : }
      47             : 
      48         104 : ScMyOpenCloseColumnRowGroup::ScMyOpenCloseColumnRowGroup(ScXMLExport& rTempExport, sal_uInt32 nToken)
      49             :     : rExport(rTempExport),
      50         104 :     rName(rExport.GetNamespaceMap().GetQNameByKey(XML_NAMESPACE_TABLE, GetXMLToken(XMLTokenEnum(nToken)))),
      51             :     aTableStart(),
      52         208 :     aTableEnd()
      53             : {
      54         104 : }
      55             : 
      56         104 : ScMyOpenCloseColumnRowGroup::~ScMyOpenCloseColumnRowGroup()
      57             : {
      58         104 : }
      59             : 
      60         112 : void ScMyOpenCloseColumnRowGroup::NewTable()
      61             : {
      62         112 :     aTableStart.clear();
      63         112 :     aTableEnd.clear();
      64         112 : }
      65             : 
      66           0 : void ScMyOpenCloseColumnRowGroup::AddGroup(const ScMyColumnRowGroup& aGroup, const sal_Int32 nEndField)
      67             : {
      68           0 :     aTableStart.push_back(aGroup);
      69           0 :     aTableEnd.push_back(nEndField);
      70           0 : }
      71             : 
      72    12591556 : bool ScMyOpenCloseColumnRowGroup::IsGroupStart(const sal_Int32 nField)
      73             : {
      74    12591556 :     bool bGroupStart(false);
      75    12591556 :     if (!aTableStart.empty())
      76             :     {
      77           0 :         ScMyColumnRowGroupVec::iterator aItr(aTableStart.begin());
      78           0 :         sal_Int32 nItrField = aItr->nField;
      79           0 :         if ( nItrField < nField )
      80             :         {
      81             :             //  when used to find repeated rows at the beginning of a group,
      82             :             //  aTableStart may contain entries before nField. They must be skipped here
      83             :             //  (they will be used for OpenGroups later in the right order).
      84             : 
      85           0 :             ScMyColumnRowGroupVec::iterator aEnd(aTableStart.end());
      86           0 :             while ( aItr != aEnd && nItrField < nField )
      87             :             {
      88           0 :                 ++aItr;
      89           0 :                 if ( aItr != aEnd )
      90           0 :                     nItrField = aItr->nField;
      91             :             }
      92             :         }
      93             : 
      94           0 :         if (nItrField == nField)
      95           0 :             bGroupStart = true;
      96             :     }
      97    12591556 :     return bGroupStart;
      98             : }
      99             : 
     100           0 : void ScMyOpenCloseColumnRowGroup::OpenGroup(const ScMyColumnRowGroup& rGroup)
     101             : {
     102           0 :     if (!rGroup.bDisplay)
     103           0 :         rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_DISPLAY, XML_FALSE);
     104           0 :     rExport.StartElement( rName, true);
     105           0 : }
     106             : 
     107           0 : void ScMyOpenCloseColumnRowGroup::OpenGroups(const sal_Int32 nField)
     108             : {
     109           0 :     ScMyColumnRowGroupVec::iterator aItr(aTableStart.begin());
     110           0 :     ScMyColumnRowGroupVec::iterator aEndItr(aTableStart.end());
     111           0 :     bool bReady(false);
     112           0 :     while(!bReady && aItr != aEndItr)
     113             :     {
     114           0 :         if (aItr->nField == nField)
     115             :         {
     116           0 :             OpenGroup(*aItr);
     117           0 :             aItr = aTableStart.erase(aItr);
     118             :         }
     119             :         else
     120           0 :             bReady = true;
     121             :     }
     122           0 : }
     123             : 
     124    12591556 : bool ScMyOpenCloseColumnRowGroup::IsGroupEnd(const sal_Int32 nField)
     125             : {
     126    12591556 :     bool bGroupEnd(false);
     127    12591556 :     if (!aTableEnd.empty())
     128             :     {
     129           0 :         if (*(aTableEnd.begin()) == nField)
     130           0 :             bGroupEnd = true;
     131             :     }
     132    12591556 :     return bGroupEnd;
     133             : }
     134             : 
     135           0 : void ScMyOpenCloseColumnRowGroup::CloseGroup()
     136             : {
     137           0 :     rExport.EndElement( rName, true );
     138           0 : }
     139             : 
     140           0 : void ScMyOpenCloseColumnRowGroup::CloseGroups(const sal_Int32 nField)
     141             : {
     142           0 :     ScMyFieldGroupVec::iterator aItr(aTableEnd.begin());
     143           0 :     ScMyFieldGroupVec::iterator aEndItr(aTableEnd.end());
     144           0 :     bool bReady(false);
     145           0 :     while(!bReady && aItr != aEndItr)
     146             :     {
     147           0 :         if (*aItr == nField)
     148             :         {
     149           0 :             CloseGroup();
     150           0 :             aItr = aTableEnd.erase(aItr);
     151             :         }
     152             :         else
     153           0 :             bReady = true;
     154             :     }
     155           0 : }
     156             : 
     157           8 : sal_Int32 ScMyOpenCloseColumnRowGroup::GetLast()
     158             : {
     159           8 :     sal_Int32 maximum(-1);
     160           8 :     ScMyFieldGroupVec::iterator i(aTableEnd.begin());
     161           8 :     ScMyFieldGroupVec::iterator endi(aTableEnd.end());
     162          16 :     while (i != endi)
     163             :     {
     164           0 :         if (*i > maximum)
     165           0 :             maximum = *i;
     166           0 :         ++i;
     167             :     }
     168           8 :     return maximum;
     169             : }
     170             : 
     171           0 : void ScMyOpenCloseColumnRowGroup::Sort()
     172             : {
     173           0 :     aTableStart.sort();
     174           0 :     aTableEnd.sort();
     175           0 : }
     176             : 
     177             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10