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