LibreOffice Module sc (master)  1
XMLConsolidationContext.cxx
Go to the documentation of this file.
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 
21 #include <document.hxx>
22 #include <rangeutl.hxx>
23 #include "xmlimprt.hxx"
24 #include "XMLConverter.hxx"
25 #include <xmloff/xmltoken.hxx>
26 #include <xmloff/xmlnamespace.hxx>
27 
28 using namespace ::com::sun::star;
29 using namespace xmloff::token;
30 
32  ScXMLImport& rImport,
34  ScXMLImportContext( rImport ),
35  eFunction( SUBTOTAL_FUNC_NONE ),
36  bLinkToSource( false ),
37  bTargetAddr(false)
38 {
39  rImport.LockSolarMutex();
40  if ( !rAttrList.is() )
41  return;
42 
43  for (auto &aIter : *rAttrList)
44  {
45  switch (aIter.getToken())
46  {
49  break;
51  sSourceList = aIter.toString();
52  break;
54  {
55  sal_Int32 nOffset(0);
57  assert(pDoc);
59  aTargetAddr, aIter.toString(), *pDoc, ::formula::FormulaGrammar::CONV_OOO, nOffset );
60  }
61  break;
63  sUseLabel = aIter.toString();
64  break;
66  bLinkToSource = IsXMLToken( aIter, XML_TRUE );
67  break;
68  }
69  }
70 }
71 
73 {
75 }
76 
77 void SAL_CALL ScXMLConsolidationContext::endFastElement( sal_Int32 /*nElement*/ )
78 {
79  if (!bTargetAddr)
80  return;
81 
82  std::unique_ptr<ScConsolidateParam> pConsParam(new ScConsolidateParam);
83  pConsParam->nCol = aTargetAddr.Col();
84  pConsParam->nRow = aTargetAddr.Row();
85  pConsParam->nTab = aTargetAddr.Tab();
86  pConsParam->eFunction = eFunction;
87 
88  sal_uInt16 nCount = static_cast<sal_uInt16>(std::min( ScRangeStringConverter::GetTokenCount( sSourceList ), sal_Int32(0xFFFF) ));
89  if( nCount )
90  {
91  std::unique_ptr<ScArea[]> ppAreas(new ScArea[ nCount ]);
92  sal_Int32 nOffset = 0;
93  sal_uInt16 nIndex;
95  assert(pDoc);
96  for( nIndex = 0; nIndex < nCount; ++nIndex )
97  {
99  ppAreas[ nIndex ], sSourceList, *pDoc, ::formula::FormulaGrammar::CONV_OOO, nOffset ) )
100  {
102  }
103  }
104 
105  pConsParam->SetAreas( std::move(ppAreas), nCount );
106  }
107 
108  pConsParam->bByCol = pConsParam->bByRow = false;
110  pConsParam->bByCol = true;
111  else if( IsXMLToken( sUseLabel, XML_ROW ) )
112  pConsParam->bByRow = true;
113  else if( IsXMLToken( sUseLabel, XML_BOTH ) )
114  pConsParam->bByCol = pConsParam->bByRow = true;
115 
116  pConsParam->bReferenceData = bLinkToSource;
117 
118  ScDocument* pDoc = GetScImport().GetDocument();
119  if( pDoc )
120  pDoc->SetConsolidateDlgData( std::move(pConsParam) );
121 }
122 
123 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsXMLToken(const OUString &rString, enum XMLTokenEnum eToken)
sal_Int32 nIndex
void SetConsolidateDlgData(std::unique_ptr< ScConsolidateParam > pData)
Definition: documen2.cxx:1104
SCROW Row() const
Definition: address.hxx:262
static bool GetAddressFromString(ScAddress &rAddress, const OUString &rAddressStr, const ScDocument &rDocument, formula::FormulaGrammar::AddressConvention eConv, sal_Int32 &nOffset, sal_Unicode cSeparator= ' ', sal_Unicode cQuote= '\'')
String to Range core.
Definition: rangeutl.cxx:435
XML_COLUMN
ScDocument * GetDocument()
Definition: xmlimprt.hxx:296
static bool GetAreaFromString(ScArea &rArea, const OUString &rRangeStr, const ScDocument &rDocument, formula::FormulaGrammar::AddressConvention eConv, sal_Int32 &nOffset, sal_Unicode cSeparator= ' ')
Definition: rangeutl.cxx:553
XML_SOURCE_CELL_RANGE_ADDRESSES
XML_ROW
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
void LockSolarMutex()
Definition: xmlimprt.cxx:1697
int nCount
SCTAB Tab() const
Definition: address.hxx:271
static sal_Int32 GetTokenCount(const OUString &rString, sal_Unicode cSeparator= ' ')
Definition: rangeutl.cxx:421
This class exists only to provide GetScImport() to its derived classes.
XML_LINK_TO_SOURCE_DATA
static ScSubTotalFunc GetSubTotalFuncFromString(const OUString &rString)
ScXMLConsolidationContext(ScXMLImport &rImport, const rtl::Reference< sax_fastparser::FastAttributeList > &rAttrList)
XML_BOTH
XML_USE_LABEL
ScXMLImport & GetScImport()
SCCOL Col() const
Definition: address.hxx:267
TABLE
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
void UnlockSolarMutex()
Definition: xmlimprt.cxx:1715
#define XML_ELEMENT(prefix, name)
XML_TARGET_CELL_ADDRESS
XML_TRUE
virtual ~ScXMLConsolidationContext() override
XML_FUNCTION