LibreOffice Module sc (master)  1
XMLColumnRowGroupExport.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 "xmlexprt.hxx"
22 #include <xmloff/namespacemap.hxx>
23 #include <xmloff/xmltoken.hxx>
24 #include <xmloff/xmlnamespace.hxx>
25 
26 #include <algorithm>
27 
28 using namespace xmloff::token;
29 
31  : nField(0)
32  , nLevel(0)
33  , bDisplay(false)
34 {
35 }
36 
38 {
39  if (rGroup.nField > nField)
40  return true;
41  else
42  if (rGroup.nField == nField && rGroup.nLevel > nLevel)
43  return true;
44  else
45  return false;
46 }
47 
49  : rExport(rTempExport),
50  rName(rExport.GetNamespaceMap().GetQNameByKey(XML_NAMESPACE_TABLE, GetXMLToken(XMLTokenEnum(nToken)))),
51  aTableStart(),
52  aTableEnd()
53 {
54 }
55 
57 {
58 }
59 
61 {
62  aTableStart.clear();
63  aTableEnd.clear();
64 }
65 
66 void ScMyOpenCloseColumnRowGroup::AddGroup(const ScMyColumnRowGroup& aGroup, const sal_Int32 nEndField)
67 {
68  aTableStart.push_back(aGroup);
69  aTableEnd.push_back(nEndField);
70 }
71 
72 bool ScMyOpenCloseColumnRowGroup::IsGroupStart(const sal_Int32 nField)
73 {
74  bool bGroupStart(false);
75  if (!aTableStart.empty())
76  {
77  // when used to find repeated rows at the beginning of a group,
78  // aTableStart may contain entries before nField. They must be skipped here
79  // (they will be used for OpenGroups later in the right order).
80 
81  ScMyColumnRowGroupVec::iterator aItr = std::find_if_not(aTableStart.begin(), aTableStart.end(),
82  [&nField](const ScMyColumnRowGroup& rGroup) { return rGroup.nField < nField; });
83  bGroupStart = (aItr != aTableStart.end()) && (aItr->nField == nField);
84  }
85  return bGroupStart;
86 }
87 
89 {
90  if (!rGroup.bDisplay)
92  rExport.StartElement( rName, true);
93 }
94 
95 void ScMyOpenCloseColumnRowGroup::OpenGroups(const sal_Int32 nField)
96 {
97  ScMyColumnRowGroupVec::iterator aItr(aTableStart.begin());
98  bool bReady(false);
99  while(!bReady && aItr != aTableStart.end())
100  {
101  if (aItr->nField == nField)
102  {
103  OpenGroup(*aItr);
104  aItr = aTableStart.erase(aItr);
105  }
106  else
107  bReady = true;
108  }
109 }
110 
111 bool ScMyOpenCloseColumnRowGroup::IsGroupEnd(const sal_Int32 nField)
112 {
113  return (!aTableEnd.empty()) && (aTableEnd.front() == nField);
114 }
115 
116 void ScMyOpenCloseColumnRowGroup::CloseGroups(const sal_Int32 nField)
117 {
118  ScMyFieldGroupVec::iterator aItr(aTableEnd.begin());
119  bool bReady(false);
120  while(!bReady && aItr != aTableEnd.end())
121  {
122  if (*aItr == nField)
123  {
124  rExport.EndElement( rName, true );
125  aItr = aTableEnd.erase(aItr);
126  }
127  else
128  bReady = true;
129  }
130 }
131 
133 {
134  sal_Int32 maximum(-1);
135  if (!aTableEnd.empty())
136  {
137  ScMyFieldGroupVec::iterator i(std::max_element(aTableEnd.begin(), aTableEnd.end()));
138  if (*i > maximum)
139  maximum = *i;
140  }
141  return maximum;
142 }
143 
145 {
146  std::sort(aTableStart.begin(), aTableStart.end());
147  std::sort(aTableEnd.begin(), aTableEnd.end());
148 }
149 
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XML_DISPLAY
void AddGroup(const ScMyColumnRowGroup &aGroup, const sal_Int32 nEndField)
void AddAttribute(sal_uInt16 nPrefix, const char *pName, const OUString &rValue)
void StartElement(sal_uInt16 nPrefix, enum::xmloff::token::XMLTokenEnum eName, bool bIgnWSOutside)
XML_FALSE
XMLTokenEnum
bool operator<(const ScMyColumnRowGroup &rGroup) const
bool IsGroupEnd(const sal_Int32 nField)
bool IsGroupStart(const sal_Int32 nField)
int i
ScMyOpenCloseColumnRowGroup(ScXMLExport &rExport, sal_uInt32 nToken)
void OpenGroup(const ScMyColumnRowGroup &rGroup)
DefTokenId nToken
Definition: qproform.cxx:399
constexpr sal_uInt16 XML_NAMESPACE_TABLE
void EndElement(sal_uInt16 nPrefix, enum::xmloff::token::XMLTokenEnum eName, bool bIgnWSInside)
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
void OpenGroups(const sal_Int32 nField)
void CloseGroups(const sal_Int32 nField)
css::uno::Any const SvXMLExport & rExport