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 <sax/tools/converter.hxx>
21 :
22 : #include "SchXMLTableContext.hxx"
23 : #include "SchXMLParagraphContext.hxx"
24 : #include "SchXMLTextListContext.hxx"
25 : #include "SchXMLImport.hxx"
26 : #include "SchXMLTools.hxx"
27 : #include "transporttypes.hxx"
28 : #include "XMLStringBufferImportContext.hxx"
29 : #include <rtl/math.hxx>
30 : #include <xmloff/xmlnmspe.hxx>
31 : #include <xmloff/xmltoken.hxx>
32 : #include <xmloff/nmspmap.hxx>
33 : #include <com/sun/star/frame/XModel.hpp>
34 : #include <com/sun/star/chart2/XAnyDescriptionAccess.hpp>
35 : #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
36 : #include <com/sun/star/chart2/XChartDocument.hpp>
37 : #include <com/sun/star/chart2/XChartTypeContainer.hpp>
38 : #include <com/sun/star/chart2/XInternalDataProvider.hpp>
39 : #include <com/sun/star/chart/ChartSeriesAddress.hpp>
40 : #include <com/sun/star/beans/XPropertySet.hpp>
41 : #include <com/sun/star/beans/XPropertySetInfo.hpp>
42 : #include <com/sun/star/beans/PropertyAttribute.hpp>
43 :
44 : #include <com/sun/star/chart2/XDiagram.hpp>
45 : #include <com/sun/star/chart2/XAxis.hpp>
46 : #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
47 : #include <com/sun/star/chart2/AxisType.hpp>
48 :
49 : #include <vector>
50 : #include <algorithm>
51 :
52 : using namespace com::sun::star;
53 : using namespace ::xmloff::token;
54 : using ::com::sun::star::uno::Sequence;
55 : using ::com::sun::star::uno::Reference;
56 :
57 : namespace
58 : {
59 :
60 : const char aLabelPrefix[] = "label ";
61 : const char aCategoriesRange[] = "categories";
62 :
63 : typedef ::std::multimap< OUString, OUString >
64 : lcl_tOriginalRangeToInternalRangeMap;
65 :
66 : struct lcl_ApplyCellToData : public ::std::unary_function< SchXMLCell, void >
67 : {
68 0 : lcl_ApplyCellToData( Sequence< double > & rOutData ) :
69 : m_rData( rOutData ),
70 : m_nIndex( 0 ),
71 0 : m_nSize( rOutData.getLength()),
72 0 : m_fNaN( 0.0 )
73 : {
74 0 : ::rtl::math::setNan( &m_fNaN );
75 0 : }
76 :
77 0 : void operator() ( const SchXMLCell & rCell )
78 : {
79 0 : if( m_nIndex < m_nSize )
80 : {
81 0 : if( rCell.eType == SCH_CELL_TYPE_FLOAT )
82 0 : m_rData[m_nIndex] = rCell.fValue;
83 : else
84 0 : m_rData[m_nIndex] = m_fNaN;
85 : }
86 0 : ++m_nIndex;
87 0 : }
88 :
89 0 : sal_Int32 getCurrentIndex() const
90 : {
91 0 : return m_nIndex;
92 : }
93 :
94 : private:
95 : Sequence< double > & m_rData;
96 : sal_Int32 m_nIndex;
97 : sal_Int32 m_nSize;
98 : double m_fNaN;
99 : };
100 :
101 0 : void lcl_fillRangeMapping(
102 : const SchXMLTable & rTable,
103 : lcl_tOriginalRangeToInternalRangeMap & rOutRangeMap,
104 : chart::ChartDataRowSource eDataRowSource )
105 : {
106 0 : sal_Int32 nRowOffset = ( rTable.bHasHeaderRow ? 1 : 0 );
107 0 : sal_Int32 nColOffset = ( rTable.bHasHeaderColumn ? 1 : 0 );
108 :
109 0 : const OUString lcl_aCategoriesRange(aCategoriesRange);
110 0 : const OUString lcl_aLabelPrefix(aLabelPrefix);
111 :
112 : // Fill range mapping
113 0 : const size_t nTableRowCount( rTable.aData.size());
114 0 : for( size_t nRow = 0; nRow < nTableRowCount; ++nRow )
115 : {
116 0 : const ::std::vector< SchXMLCell > & rRow( rTable.aData[nRow] );
117 0 : const size_t nTableColCount( rRow.size());
118 0 : for( size_t nCol = 0; nCol < nTableColCount; ++nCol )
119 : {
120 0 : const OUString aRangeId( rRow[nCol].aRangeId );
121 0 : if( !aRangeId.isEmpty())
122 : {
123 0 : if( eDataRowSource == chart::ChartDataRowSource_COLUMNS )
124 : {
125 0 : if( nCol == 0 && rTable.bHasHeaderColumn )
126 : {
127 : SAL_WARN_IF( static_cast< sal_Int32 >( nRow ) != nRowOffset, "xmloff.chart", "nRow != nRowOffset" );
128 : rOutRangeMap.insert( lcl_tOriginalRangeToInternalRangeMap::value_type(
129 0 : aRangeId, lcl_aCategoriesRange ));
130 : }
131 : else
132 : {
133 0 : OUString aColNumStr = OUString::number( nCol - nColOffset);
134 0 : if( nRow == 0 && rTable.bHasHeaderRow )
135 : rOutRangeMap.insert( lcl_tOriginalRangeToInternalRangeMap::value_type(
136 0 : aRangeId, lcl_aLabelPrefix + aColNumStr ));
137 : else
138 : rOutRangeMap.insert( lcl_tOriginalRangeToInternalRangeMap::value_type(
139 0 : aRangeId, aColNumStr ));
140 : }
141 : }
142 : else // eDataRowSource == chart::ChartDataRowSource_ROWS
143 : {
144 0 : if( nRow == 0 && rTable.bHasHeaderRow )
145 : {
146 : SAL_WARN_IF( static_cast< sal_Int32 >( nCol ) != nColOffset, "xmloff.chart", "nCol != nColOffset" );
147 : rOutRangeMap.insert( lcl_tOriginalRangeToInternalRangeMap::value_type(
148 0 : aRangeId, lcl_aCategoriesRange ));
149 : }
150 : else
151 : {
152 0 : OUString aRowNumStr = OUString::number( nRow - nRowOffset);
153 0 : if( nCol == 0 && rTable.bHasHeaderColumn )
154 : rOutRangeMap.insert( lcl_tOriginalRangeToInternalRangeMap::value_type(
155 0 : aRangeId, lcl_aLabelPrefix + aRowNumStr ));
156 : else
157 : rOutRangeMap.insert( lcl_tOriginalRangeToInternalRangeMap::value_type(
158 0 : aRangeId, aRowNumStr ));
159 : }
160 : }
161 : }
162 0 : }
163 0 : }
164 0 : }
165 :
166 : Reference< chart2::data::XDataSequence >
167 0 : lcl_reassignDataSequence(
168 : const Reference< chart2::data::XDataSequence > & xSequence,
169 : const Reference< chart2::data::XDataProvider > & xDataProvider,
170 : lcl_tOriginalRangeToInternalRangeMap & rRangeMap,
171 : const OUString & rRange )
172 : {
173 0 : Reference< chart2::data::XDataSequence > xResult( xSequence );
174 0 : lcl_tOriginalRangeToInternalRangeMap::iterator aIt( rRangeMap.find( rRange ));
175 0 : if( aIt != rRangeMap.end())
176 : {
177 : // set sequence with correct data
178 0 : xResult.set( xDataProvider->createDataSequenceByRangeRepresentation( aIt->second ));
179 : // remove translation, because it was used
180 0 : rRangeMap.erase( aIt );
181 : }
182 :
183 0 : return xResult;
184 : }
185 :
186 0 : bool lcl_mapContainsRange(
187 : lcl_tOriginalRangeToInternalRangeMap & rRangeMap,
188 : const OUString & rRange )
189 : {
190 0 : lcl_tOriginalRangeToInternalRangeMap::iterator aIt( rRangeMap.find( rRange ));
191 0 : return ( aIt != rRangeMap.end());
192 : }
193 :
194 0 : bool lcl_tableOfRangeMatches(
195 : const OUString & rRange,
196 : const OUString & rTableName )
197 : {
198 : // both strings are non-empty and the table name is part of the range
199 0 : return ( !rRange.isEmpty() &&
200 0 : !rTableName.isEmpty() &&
201 0 : (rRange.indexOf( rTableName ) != -1 ));
202 : }
203 :
204 : template< typename T >
205 0 : ::std::vector< T > lcl_SequenceToVector( const uno::Sequence< T > & rSequence )
206 : {
207 0 : ::std::vector< T > aResult( rSequence.getLength());
208 0 : ::std::copy( rSequence.getConstArray(), rSequence.getConstArray() + rSequence.getLength(),
209 0 : aResult.begin());
210 0 : return aResult;
211 : }
212 :
213 : } // anonymous namespace
214 :
215 : // class SchXMLTableContext
216 0 : SchXMLTableContext::SchXMLTableContext( SchXMLImportHelper& rImpHelper,
217 : SvXMLImport& rImport,
218 : const OUString& rLName,
219 : SchXMLTable& aTable ) :
220 : SvXMLImportContext( rImport, XML_NAMESPACE_TABLE, rLName ),
221 : mrImportHelper( rImpHelper ),
222 : mrTable( aTable ),
223 : mbHasRowPermutation( false ),
224 0 : mbHasColumnPermutation( false )
225 : {
226 0 : mrTable.nColumnIndex = -1;
227 0 : mrTable.nMaxColumnIndex = -1;
228 0 : mrTable.nRowIndex = -1;
229 0 : mrTable.aData.clear();
230 0 : }
231 :
232 0 : SchXMLTableContext::~SchXMLTableContext()
233 : {
234 0 : }
235 :
236 0 : SvXMLImportContext *SchXMLTableContext::CreateChildContext(
237 : sal_uInt16 nPrefix,
238 : const OUString& rLocalName,
239 : const uno::Reference< xml::sax::XAttributeList >& )
240 : {
241 0 : SvXMLImportContext* pContext = 0;
242 0 : const SvXMLTokenMap& rTokenMap = mrImportHelper.GetTableElemTokenMap();
243 :
244 0 : switch( rTokenMap.Get( nPrefix, rLocalName ))
245 : {
246 : case XML_TOK_TABLE_HEADER_COLS:
247 0 : mrTable.bHasHeaderColumn = true;
248 : // fall through intended
249 : case XML_TOK_TABLE_COLUMNS:
250 0 : pContext = new SchXMLTableColumnsContext( GetImport(), rLocalName, mrTable );
251 0 : break;
252 :
253 : case XML_TOK_TABLE_COLUMN:
254 0 : pContext = new SchXMLTableColumnContext( GetImport(), rLocalName, mrTable );
255 0 : break;
256 :
257 : case XML_TOK_TABLE_HEADER_ROWS:
258 0 : mrTable.bHasHeaderRow = true;
259 : // fall through intended
260 : case XML_TOK_TABLE_ROWS:
261 0 : pContext = new SchXMLTableRowsContext( mrImportHelper, GetImport(), rLocalName, mrTable );
262 0 : break;
263 :
264 : case XML_TOK_TABLE_ROW:
265 0 : pContext = new SchXMLTableRowContext( mrImportHelper, GetImport(), rLocalName, mrTable );
266 0 : break;
267 :
268 : default:
269 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
270 : }
271 :
272 0 : return pContext;
273 : }
274 :
275 0 : void SchXMLTableContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
276 : {
277 : // get table-name
278 0 : sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
279 :
280 0 : for( sal_Int16 i = 0; i < nAttrCount; i++ )
281 : {
282 0 : OUString sAttrName = xAttrList->getNameByIndex( i );
283 0 : OUString aLocalName;
284 0 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
285 0 : if ( nPrefix == XML_NAMESPACE_TABLE )
286 : {
287 0 : if ( IsXMLToken( aLocalName, XML_NAME ) )
288 : {
289 0 : mrTable.aTableNameOfFile = xAttrList->getValueByIndex( i );
290 : }
291 0 : else if ( IsXMLToken( aLocalName, XML_PROTECTED ) )
292 : {
293 0 : if ( IsXMLToken( xAttrList->getValueByIndex( i ), XML_TRUE ) )
294 : {
295 0 : mrTable.bProtected = true;
296 : }
297 : }
298 : }
299 0 : }
300 0 : }
301 :
302 0 : void SchXMLTableContext::EndElement()
303 : {
304 0 : if( mbHasColumnPermutation )
305 : {
306 : SAL_WARN_IF( mbHasRowPermutation, "xmloff.chart", "mbHasColumnPermutation is true" );
307 0 : ::std::vector< sal_Int32 > aPermutation( lcl_SequenceToVector( maColumnPermutation ));
308 : SAL_WARN_IF( aPermutation.empty(), "xmloff.chart", "aPermutation is NULL");
309 0 : if( aPermutation.empty())
310 0 : return;
311 :
312 : // permute the values of all rows according to aPermutation
313 0 : for( ::std::vector< ::std::vector< SchXMLCell > >::iterator aRowIt( mrTable.aData.begin());
314 0 : aRowIt != mrTable.aData.end(); ++aRowIt )
315 : {
316 0 : bool bModified = false;
317 0 : ::std::vector< SchXMLCell > aModifiedRow;
318 0 : const size_t nPermSize = aPermutation.size();
319 : SAL_WARN_IF( static_cast< sal_Int32 >( nPermSize ) - 1 != *(::std::max_element( aPermutation.begin(), aPermutation.end())), "xmloff.chart", "nPermSize - 1 != *(::std::max_element( aPermutation.begin(), aPermutation.end())");
320 0 : const size_t nRowSize = aRowIt->size();
321 0 : const size_t nDestSize = ::std::min( nPermSize, nRowSize );
322 0 : for( size_t nDestinationIndex = 0; nDestinationIndex < nDestSize; ++nDestinationIndex )
323 : {
324 0 : const size_t nSourceIndex = static_cast< size_t >( aPermutation[ nDestinationIndex ] );
325 0 : if( nSourceIndex != nDestinationIndex &&
326 0 : nSourceIndex < nRowSize )
327 : {
328 : // copy original on first real permutation
329 0 : if( !bModified )
330 : {
331 : SAL_WARN_IF( !aModifiedRow.empty(), "xmloff.chart", "aModifiedRow is NOT NULL");
332 0 : aModifiedRow.reserve( aRowIt->size());
333 0 : ::std::copy( aRowIt->begin(), aRowIt->end(), ::std::back_inserter( aModifiedRow ));
334 : SAL_WARN_IF( aModifiedRow.empty(), "xmloff.chart", "aModifiedRow is NULL");
335 : }
336 : SAL_WARN_IF( nDestinationIndex >= aModifiedRow.size(), "xmloff.chart", "nDestinationIndex >= aModifiedRow.size()");
337 0 : aModifiedRow[ nDestinationIndex ] = (*aRowIt)[ nSourceIndex ];
338 0 : bModified = true;
339 : }
340 : }
341 : // copy back
342 0 : if( bModified )
343 0 : ::std::copy( aModifiedRow.begin(), aModifiedRow.end(), aRowIt->begin());
344 0 : }
345 : }
346 0 : else if( mbHasRowPermutation )
347 : {
348 0 : ::std::vector< sal_Int32 > aPermutation( lcl_SequenceToVector( maRowPermutation ));
349 : SAL_WARN_IF( aPermutation.empty(), "xmloff.chart", "aPermutation is NULL");
350 0 : if( aPermutation.empty())
351 0 : return;
352 :
353 0 : bool bModified = false;
354 0 : const size_t nPermSize = aPermutation.size();
355 : SAL_WARN_IF( static_cast< sal_Int32 >( nPermSize ) - 1 != *(::std::max_element( aPermutation.begin(), aPermutation.end())), "xmloff.chart", "nPermSize - 1 != *(::std::max_element( aPermutation.begin(), aPermutation.end())");
356 0 : const size_t nTableRowCount = mrTable.aData.size();
357 0 : const size_t nDestSize = ::std::min( nPermSize, nTableRowCount );
358 0 : ::std::vector< ::std::vector< SchXMLCell > > aDestination;
359 0 : for( size_t nDestinationIndex = 0; nDestinationIndex < nDestSize; ++nDestinationIndex )
360 : {
361 0 : const size_t nSourceIndex = static_cast< size_t >( aPermutation[ nDestinationIndex ] );
362 0 : if( nSourceIndex != nDestinationIndex &&
363 0 : nSourceIndex < nTableRowCount )
364 : {
365 : // copy original on first real permutation
366 0 : if( !bModified )
367 : {
368 : SAL_WARN_IF( !aDestination.empty(), "xmloff.chart", "aDestination is NOT NULL");
369 0 : aDestination.reserve( mrTable.aData.size());
370 0 : ::std::copy( mrTable.aData.begin(), mrTable.aData.end(), ::std::back_inserter( aDestination ));
371 : SAL_WARN_IF( aDestination.empty(), "xmloff.chart", "aDestination is NULL");
372 : }
373 : SAL_WARN_IF( nDestinationIndex >= aDestination.size(), "xmloff.chart", "nDestinationIndex >= aDestination.size()");
374 0 : aDestination[ nDestinationIndex ] = mrTable.aData[ nSourceIndex ];
375 0 : bModified = true;
376 : }
377 : }
378 0 : if( bModified )
379 : {
380 : // copy back
381 0 : ::std::copy( aDestination.begin(), aDestination.end(), mrTable.aData.begin());
382 0 : }
383 : }
384 : }
385 :
386 0 : void SchXMLTableContext::setRowPermutation( const uno::Sequence< sal_Int32 > & rPermutation )
387 : {
388 0 : maRowPermutation = rPermutation;
389 0 : mbHasRowPermutation = ( rPermutation.getLength() > 0 );
390 :
391 0 : if( mbHasRowPermutation && mbHasColumnPermutation )
392 : {
393 0 : mbHasColumnPermutation = false;
394 0 : maColumnPermutation.realloc( 0 );
395 : }
396 0 : }
397 :
398 0 : void SchXMLTableContext::setColumnPermutation( const uno::Sequence< sal_Int32 > & rPermutation )
399 : {
400 0 : maColumnPermutation = rPermutation;
401 0 : mbHasColumnPermutation = ( rPermutation.getLength() > 0 );
402 :
403 0 : if( mbHasColumnPermutation && mbHasRowPermutation )
404 : {
405 0 : mbHasRowPermutation = false;
406 0 : maRowPermutation.realloc( 0 );
407 : }
408 0 : }
409 :
410 : // classes for columns
411 : // class SchXMLTableColumnsContext
412 0 : SchXMLTableColumnsContext::SchXMLTableColumnsContext(
413 : SvXMLImport& rImport,
414 : const OUString& rLocalName,
415 : SchXMLTable& aTable ) :
416 : SvXMLImportContext( rImport, XML_NAMESPACE_TABLE, rLocalName ),
417 0 : mrTable( aTable )
418 : {
419 0 : }
420 :
421 0 : SchXMLTableColumnsContext::~SchXMLTableColumnsContext()
422 : {
423 0 : }
424 :
425 0 : SvXMLImportContext* SchXMLTableColumnsContext::CreateChildContext(
426 : sal_uInt16 nPrefix,
427 : const OUString& rLocalName,
428 : const uno::Reference< xml::sax::XAttributeList >& )
429 : {
430 0 : SvXMLImportContext* pContext = 0;
431 :
432 0 : if( nPrefix == XML_NAMESPACE_TABLE &&
433 0 : IsXMLToken( rLocalName, XML_TABLE_COLUMN ) )
434 : {
435 0 : pContext = new SchXMLTableColumnContext( GetImport(), rLocalName, mrTable );
436 : }
437 : else
438 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
439 :
440 0 : return pContext;
441 : }
442 :
443 : // class SchXMLTableColumnContext
444 0 : SchXMLTableColumnContext::SchXMLTableColumnContext(
445 : SvXMLImport& rImport,
446 : const OUString& rLocalName,
447 : SchXMLTable& aTable ) :
448 : SvXMLImportContext( rImport, XML_NAMESPACE_TABLE, rLocalName ),
449 0 : mrTable( aTable )
450 : {
451 0 : }
452 :
453 0 : void SchXMLTableColumnContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
454 : {
455 : // get number-columns-repeated attribute
456 0 : sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
457 0 : sal_Int32 nRepeated = 1;
458 0 : bool bHidden = false;
459 :
460 0 : for( sal_Int16 i = 0; i < nAttrCount; i++ )
461 : {
462 0 : OUString sAttrName = xAttrList->getNameByIndex( i );
463 0 : OUString aLocalName;
464 0 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
465 :
466 0 : if( nPrefix == XML_NAMESPACE_TABLE &&
467 0 : IsXMLToken( aLocalName, XML_NUMBER_COLUMNS_REPEATED ) )
468 : {
469 0 : OUString aValue = xAttrList->getValueByIndex( i );
470 0 : if( !aValue.isEmpty())
471 0 : nRepeated = aValue.toInt32();
472 : }
473 0 : else if( nPrefix == XML_NAMESPACE_TABLE &&
474 0 : IsXMLToken( aLocalName, XML_VISIBILITY ) )
475 : {
476 0 : OUString aVisibility = xAttrList->getValueByIndex( i );
477 0 : bHidden = aVisibility.equals( GetXMLToken( XML_COLLAPSE ) );
478 : }
479 0 : }
480 :
481 0 : sal_Int32 nOldCount = mrTable.nNumberOfColsEstimate;
482 0 : sal_Int32 nNewCount = nOldCount + nRepeated;
483 0 : mrTable.nNumberOfColsEstimate = nNewCount;
484 :
485 0 : if( bHidden )
486 : {
487 : //i91578 display of hidden values (copy paste scenario; use hidden flag during migration to locale table upon paste )
488 0 : sal_Int32 nColOffset = ( mrTable.bHasHeaderColumn ? 1 : 0 );
489 0 : for( sal_Int32 nN = nOldCount; nN<nNewCount; nN++ )
490 : {
491 0 : sal_Int32 nHiddenColumnIndex = nN-nColOffset;
492 0 : if( nHiddenColumnIndex>=0 )
493 0 : mrTable.aHiddenColumns.push_back(nHiddenColumnIndex);
494 : }
495 : }
496 0 : }
497 :
498 0 : SchXMLTableColumnContext::~SchXMLTableColumnContext()
499 : {
500 0 : }
501 :
502 : // classes for rows
503 : // class SchXMLTableRowsContext
504 0 : SchXMLTableRowsContext::SchXMLTableRowsContext(
505 : SchXMLImportHelper& rImpHelper,
506 : SvXMLImport& rImport,
507 : const OUString& rLocalName,
508 : SchXMLTable& aTable ) :
509 : SvXMLImportContext( rImport, XML_NAMESPACE_TABLE, rLocalName ),
510 : mrImportHelper( rImpHelper ),
511 0 : mrTable( aTable )
512 : {
513 0 : }
514 :
515 0 : SchXMLTableRowsContext::~SchXMLTableRowsContext()
516 : {
517 0 : }
518 :
519 0 : SvXMLImportContext* SchXMLTableRowsContext::CreateChildContext(
520 : sal_uInt16 nPrefix,
521 : const OUString& rLocalName,
522 : const uno::Reference< xml::sax::XAttributeList >& )
523 : {
524 0 : SvXMLImportContext* pContext = 0;
525 :
526 0 : if( nPrefix == XML_NAMESPACE_TABLE &&
527 0 : IsXMLToken( rLocalName, XML_TABLE_ROW ) )
528 : {
529 0 : pContext = new SchXMLTableRowContext( mrImportHelper, GetImport(), rLocalName, mrTable );
530 : }
531 : else
532 : {
533 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
534 : }
535 :
536 0 : return pContext;
537 : }
538 :
539 : // class SchXMLTableRowContext
540 0 : SchXMLTableRowContext::SchXMLTableRowContext(
541 : SchXMLImportHelper& rImpHelper,
542 : SvXMLImport& rImport,
543 : const OUString& rLocalName,
544 : SchXMLTable& aTable ) :
545 : SvXMLImportContext( rImport, XML_NAMESPACE_TABLE, rLocalName ),
546 : mrImportHelper( rImpHelper ),
547 0 : mrTable( aTable )
548 : {
549 0 : mrTable.nColumnIndex = -1;
550 0 : mrTable.nRowIndex++;
551 :
552 0 : std::vector< SchXMLCell > aNewRow;
553 0 : aNewRow.reserve( mrTable.nNumberOfColsEstimate );
554 0 : while( mrTable.aData.size() <= (unsigned long)mrTable.nRowIndex )
555 0 : mrTable.aData.push_back( aNewRow );
556 0 : }
557 :
558 0 : SchXMLTableRowContext::~SchXMLTableRowContext()
559 : {
560 0 : }
561 :
562 0 : SvXMLImportContext* SchXMLTableRowContext::CreateChildContext(
563 : sal_uInt16 nPrefix,
564 : const OUString& rLocalName,
565 : const uno::Reference< xml::sax::XAttributeList >& )
566 : {
567 0 : SvXMLImportContext* pContext = 0;
568 :
569 : // <table:table-cell> element
570 0 : if( nPrefix == XML_NAMESPACE_TABLE &&
571 0 : IsXMLToken(rLocalName, XML_TABLE_CELL ) )
572 : {
573 0 : pContext = new SchXMLTableCellContext( mrImportHelper, GetImport(), rLocalName, mrTable );
574 : }
575 : else
576 : {
577 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
578 : }
579 :
580 0 : return pContext;
581 : }
582 :
583 : class SchXMLRangeSomewhereContext : public SvXMLImportContext
584 : {
585 : //#i113950# previously the range was exported to attribute text:id,
586 : //but that attribute does not allow arbitrary strings anymore
587 : //so we need to find an alternative to save that range info for copy/paste scenario ...
588 : //-> use description at an empty group element for now
589 :
590 : private:
591 : OUString& mrRangeString;
592 : OUStringBuffer maRangeStringBuffer;
593 :
594 : public:
595 : SchXMLRangeSomewhereContext( SvXMLImport& rImport,
596 : sal_uInt16 nPrefix,
597 : const OUString& rLocalName,
598 : OUString& rRangeString );
599 : virtual ~SchXMLRangeSomewhereContext();
600 :
601 : virtual SvXMLImportContext* CreateChildContext(
602 : sal_uInt16 nPrefix,
603 : const OUString& rLocalName,
604 : const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttrList ) SAL_OVERRIDE;
605 : virtual void EndElement() SAL_OVERRIDE;
606 : };
607 :
608 : // classes for cells and their content
609 : // class SchXMLTableCellContext
610 0 : SchXMLTableCellContext::SchXMLTableCellContext(
611 : SchXMLImportHelper& rImpHelper, SvXMLImport& rImport,
612 : const OUString& rLocalName, SchXMLTable& aTable)
613 : : SvXMLImportContext(rImport, XML_NAMESPACE_TABLE, rLocalName)
614 : , mrImportHelper(rImpHelper)
615 : , mrTable(aTable)
616 0 : , mbReadText(false)
617 : {
618 0 : }
619 :
620 0 : SchXMLTableCellContext::~SchXMLTableCellContext()
621 : {
622 0 : }
623 :
624 0 : void SchXMLTableCellContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
625 : {
626 0 : sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
627 0 : OUString aValue;
628 0 : OUString aLocalName;
629 0 : OUString aCellContent;
630 0 : SchXMLCellType eValueType = SCH_CELL_TYPE_UNKNOWN;
631 0 : const SvXMLTokenMap& rAttrTokenMap = mrImportHelper.GetCellAttrTokenMap();
632 :
633 0 : for( sal_Int16 i = 0; i < nAttrCount; i++ )
634 : {
635 0 : OUString sAttrName = xAttrList->getNameByIndex( i );
636 0 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
637 :
638 0 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ))
639 : {
640 : case XML_TOK_CELL_VAL_TYPE:
641 0 : aValue = xAttrList->getValueByIndex( i );
642 0 : if( IsXMLToken( aValue, XML_FLOAT ) )
643 0 : eValueType = SCH_CELL_TYPE_FLOAT;
644 0 : else if( IsXMLToken( aValue, XML_STRING ) )
645 0 : eValueType = SCH_CELL_TYPE_STRING;
646 0 : break;
647 :
648 : case XML_TOK_CELL_VALUE:
649 0 : aCellContent = xAttrList->getValueByIndex( i );
650 0 : break;
651 : }
652 0 : }
653 :
654 0 : mbReadText = true;
655 0 : SchXMLCell aCell;
656 0 : aCell.eType = eValueType;
657 :
658 0 : if( eValueType == SCH_CELL_TYPE_FLOAT )
659 : {
660 : double fData;
661 : // the result may be false if a NaN is read, but that's ok
662 0 : ::sax::Converter::convertDouble( fData, aCellContent );
663 :
664 0 : aCell.fValue = fData;
665 : // dont read text from following <text:p> or <text:list> element
666 0 : mbReadText = false;
667 : }
668 :
669 0 : mrTable.aData[ mrTable.nRowIndex ].push_back( aCell );
670 0 : mrTable.nColumnIndex++;
671 0 : if( mrTable.nMaxColumnIndex < mrTable.nColumnIndex )
672 0 : mrTable.nMaxColumnIndex = mrTable.nColumnIndex;
673 0 : }
674 :
675 0 : SvXMLImportContext* SchXMLTableCellContext::CreateChildContext(
676 : sal_uInt16 nPrefix,
677 : const OUString& rLocalName,
678 : const uno::Reference< xml::sax::XAttributeList >& )
679 : {
680 0 : SvXMLImportContext* pContext = 0;
681 :
682 : // <text:list> element
683 0 : if( nPrefix == XML_NAMESPACE_TEXT && IsXMLToken( rLocalName, XML_LIST ) && mbReadText )
684 : {
685 0 : SchXMLCell& rCell = mrTable.aData[ mrTable.nRowIndex ][ mrTable.nColumnIndex ];
686 0 : rCell.aComplexString = Sequence< OUString >();
687 0 : rCell.eType = SCH_CELL_TYPE_COMPLEX_STRING;
688 0 : pContext = new SchXMLTextListContext( GetImport(), rLocalName, rCell.aComplexString );
689 0 : mbReadText = false;//don't apply text from <text:p>
690 : }
691 : // <text:p> element - read text (and range from text:id old version)
692 0 : else if( nPrefix == XML_NAMESPACE_TEXT && IsXMLToken( rLocalName, XML_P ) )
693 : {
694 0 : pContext = new SchXMLParagraphContext( GetImport(), rLocalName, maCellContent, &maRangeId );
695 : }
696 : // <draw:g> element - read range
697 0 : else if( nPrefix == XML_NAMESPACE_DRAW && IsXMLToken( rLocalName, XML_G ) )
698 : {
699 : //#i113950# previously the range was exported to attribute text:id, but that attribute does not allow arbitrary strings anymore
700 : //so we need to find an alternative to save that range info for copy/paste scenario ... -> use description at an empty group element for now
701 0 : pContext = new SchXMLRangeSomewhereContext( GetImport(), nPrefix, rLocalName, maRangeId );
702 : }
703 : else
704 : {
705 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
706 : }
707 :
708 0 : return pContext;
709 : }
710 :
711 0 : void SchXMLTableCellContext::EndElement()
712 : {
713 0 : if( mbReadText && !maCellContent.isEmpty() ) //apply text from <text:p> element
714 0 : mrTable.aData[ mrTable.nRowIndex ][ mrTable.nColumnIndex ].aString = maCellContent;
715 0 : if( !maRangeId.isEmpty())
716 0 : mrTable.aData[ mrTable.nRowIndex ][ mrTable.nColumnIndex ].aRangeId = maRangeId;
717 0 : }
718 :
719 0 : static void lcl_ApplyCellToComplexLabel( const SchXMLCell& rCell, Sequence< uno::Any >& rComplexLabel )
720 : {
721 0 : if( rCell.eType == SCH_CELL_TYPE_STRING )
722 : {
723 0 : rComplexLabel.realloc(1);
724 0 : rComplexLabel[0] = uno::makeAny( rCell.aString );
725 : }
726 0 : else if( rCell.aComplexString.getLength() && rCell.eType == SCH_CELL_TYPE_COMPLEX_STRING )
727 : {
728 0 : sal_Int32 nCount = rCell.aComplexString.getLength();
729 0 : rComplexLabel.realloc( nCount );
730 0 : for( sal_Int32 nN=0; nN<nCount; nN++)
731 0 : rComplexLabel[nN] = uno::makeAny((rCell.aComplexString)[nN]);
732 : }
733 0 : else if( rCell.eType == SCH_CELL_TYPE_FLOAT )
734 : {
735 0 : rComplexLabel.realloc(1);
736 0 : rComplexLabel[0] = uno::makeAny( rCell.fValue );
737 : }
738 0 : }
739 :
740 0 : void SchXMLTableHelper::applyTableToInternalDataProvider(
741 : const SchXMLTable& rTable,
742 : uno::Reference< chart2::XChartDocument > xChartDoc )
743 : {
744 : // apply all data read from the local table to the internal data provider
745 0 : if( !xChartDoc.is() || !xChartDoc->hasInternalDataProvider() )
746 0 : return;
747 0 : Reference< chart2::data::XDataProvider > xDataProv( xChartDoc->getDataProvider() );
748 0 : if( !xDataProv.is() )
749 0 : return;
750 :
751 : //prepare the read local table data
752 0 : sal_Int32 nNumRows( static_cast< sal_Int32 >( rTable.aData.size()));
753 0 : sal_Int32 nRowOffset = 0;
754 0 : if( rTable.bHasHeaderRow )
755 : {
756 0 : --nNumRows;
757 0 : nRowOffset = 1;
758 : }
759 0 : sal_Int32 nNumColumns( rTable.nMaxColumnIndex + 1 );
760 0 : sal_Int32 nColOffset = 0;
761 0 : if( rTable.bHasHeaderColumn )
762 : {
763 0 : --nNumColumns;
764 0 : nColOffset = 1;
765 : }
766 :
767 0 : Sequence< Sequence< double > > aDataInRows( nNumRows );
768 0 : Sequence< Sequence< uno::Any > > aComplexRowDescriptions( nNumRows );
769 0 : Sequence< Sequence< uno::Any > > aComplexColumnDescriptions( nNumColumns );
770 0 : for( sal_Int32 i=0; i<nNumRows; ++i )
771 0 : aDataInRows[i].realloc( nNumColumns );
772 :
773 0 : if( rTable.aData.begin() != rTable.aData.end())
774 : {
775 : //apply column labels
776 0 : if( rTable.bHasHeaderRow )
777 : {
778 0 : const ::std::vector< SchXMLCell >& rFirstRow = rTable.aData.front();
779 0 : const sal_Int32 nColumnLabelsSize = aComplexColumnDescriptions.getLength();
780 0 : const sal_Int32 nMax = ::std::min< sal_Int32 >( nColumnLabelsSize, static_cast< sal_Int32 >( rFirstRow.size()) - nColOffset );
781 : SAL_WARN_IF( nMax != nColumnLabelsSize, "xmloff.chart", "nMax != nColumnLabelsSize");
782 0 : for( sal_Int32 i=0; i<nMax; ++i )
783 0 : lcl_ApplyCellToComplexLabel( rFirstRow[i+nColOffset], aComplexColumnDescriptions[i] );
784 : }
785 :
786 0 : std::vector< ::std::vector< SchXMLCell > >::const_iterator aRowIter( rTable.aData.begin() + nRowOffset );
787 0 : std::vector< ::std::vector< SchXMLCell > >::const_iterator aEnd( rTable.aData.end() );
788 0 : for( sal_Int32 nRow = 0; aRowIter != aEnd && nRow < nNumRows; ++aRowIter, ++nRow )
789 : {
790 0 : const ::std::vector< SchXMLCell >& rRow = *aRowIter;
791 0 : if( !rRow.empty() )
792 : {
793 : // row label
794 0 : if( rTable.bHasHeaderColumn )
795 0 : lcl_ApplyCellToComplexLabel( rRow.front(), aComplexRowDescriptions[nRow] );
796 :
797 : // values
798 0 : Sequence< double >& rTargetRow = aDataInRows[nRow];
799 0 : lcl_ApplyCellToData aApplyCellToData = ::std::for_each( rRow.begin() + nColOffset, rRow.end(), lcl_ApplyCellToData( rTargetRow ) );
800 0 : double fNaN = 0.0;
801 0 : ::rtl::math::setNan( &fNaN );
802 0 : for( sal_Int32 nCurrentIndex = aApplyCellToData.getCurrentIndex(); nCurrentIndex<nNumColumns; nCurrentIndex++ )
803 0 : rTargetRow[nCurrentIndex] = fNaN;//#i110615#
804 : }
805 : }
806 : }
807 :
808 : //apply the collected data to the chart
809 0 : Reference< chart2::XAnyDescriptionAccess > xDataAccess( xDataProv, uno::UNO_QUERY );
810 0 : if( !xDataAccess.is() )
811 0 : return;
812 :
813 0 : xDataAccess->setData( aDataInRows );
814 0 : if( rTable.bHasHeaderColumn )
815 0 : xDataAccess->setAnyRowDescriptions( aComplexRowDescriptions );
816 0 : if( rTable.bHasHeaderRow )
817 0 : xDataAccess->setAnyColumnDescriptions( aComplexColumnDescriptions );
818 :
819 0 : if ( rTable.bProtected )
820 : {
821 : try
822 : {
823 0 : Reference< beans::XPropertySet > xProps( xChartDoc, uno::UNO_QUERY_THROW );
824 0 : xProps->setPropertyValue( "DisableDataTableDialog", uno::makeAny( sal_True ) );
825 0 : xProps->setPropertyValue( "DisableComplexChartTypes", uno::makeAny( sal_True ) );
826 : }
827 0 : catch ( uno::Exception& )
828 : {
829 : }
830 0 : }
831 : }
832 :
833 0 : void SchXMLTableHelper::switchRangesFromOuterToInternalIfNecessary(
834 : const SchXMLTable& rTable,
835 : const tSchXMLLSequencesPerIndex & rLSequencesPerIndex,
836 : uno::Reference< chart2::XChartDocument > xChartDoc,
837 : chart::ChartDataRowSource eDataRowSource )
838 : {
839 0 : if( ! (xChartDoc.is() && xChartDoc->hasInternalDataProvider()))
840 0 : return;
841 :
842 : // If the range-strings are valid (starting with "local-table") they should
843 : // be interpreted like given, otherwise (when the ranges refer to Calc- or
844 : // Writer-ranges, but the container is not available like when pasting a
845 : // chart from Calc to Impress) the range is ignored, and every object gets
846 : // one table column in the order of appearance, which is: 1. categories,
847 : // 2. data series: 2.a) domains, 2.b) values (main-role, usually y-values)
848 :
849 0 : Reference< chart2::data::XDataProvider > xDataProv( xChartDoc->getDataProvider());
850 :
851 : // create a mapping from original ranges to new ranges
852 0 : lcl_tOriginalRangeToInternalRangeMap aRangeMap;
853 :
854 0 : lcl_fillRangeMapping( rTable, aRangeMap, eDataRowSource );
855 :
856 0 : const OUString lcl_aCategoriesRange(aCategoriesRange);
857 :
858 : // translate ranges (using the map created before)
859 0 : for( tSchXMLLSequencesPerIndex::const_iterator aLSeqIt( rLSequencesPerIndex.begin());
860 0 : aLSeqIt != rLSequencesPerIndex.end(); ++aLSeqIt )
861 : {
862 0 : if( aLSeqIt->second.is())
863 : {
864 : // values/error bars/categories
865 0 : if( aLSeqIt->first.second == SCH_XML_PART_VALUES ||
866 0 : aLSeqIt->first.second == SCH_XML_PART_ERROR_BARS )
867 : {
868 0 : Reference< chart2::data::XDataSequence > xSeq( aLSeqIt->second->getValues());
869 :
870 0 : OUString aRange;
871 0 : if( xSeq.is() &&
872 0 : SchXMLTools::getXMLRangePropertyFromDataSequence( xSeq, aRange, /* bClearProp = */ true ) &&
873 0 : lcl_mapContainsRange( aRangeMap, aRange ))
874 : {
875 : Reference< chart2::data::XDataSequence > xNewSeq(
876 0 : lcl_reassignDataSequence( xSeq, xDataProv, aRangeMap, aRange ));
877 0 : if( xNewSeq != xSeq )
878 : {
879 : SchXMLTools::copyProperties( Reference< beans::XPropertySet >( xSeq, uno::UNO_QUERY ),
880 0 : Reference< beans::XPropertySet >( xNewSeq, uno::UNO_QUERY ));
881 0 : aLSeqIt->second->setValues( xNewSeq );
882 0 : }
883 : }
884 : else
885 : {
886 0 : if( !lcl_tableOfRangeMatches( aRange, rTable.aTableNameOfFile ))
887 : {
888 0 : if( aLSeqIt->first.first == SCH_XML_CATEGORIES_INDEX )
889 : {
890 0 : Reference< beans::XPropertySet > xOldSequenceProp( aLSeqIt->second->getValues(), uno::UNO_QUERY );
891 : Reference< chart2::data::XDataSequence > xNewSequence(
892 0 : xDataProv->createDataSequenceByRangeRepresentation(
893 0 : OUString("categories")));
894 : SchXMLTools::copyProperties(
895 0 : xOldSequenceProp, Reference< beans::XPropertySet >( xNewSequence, uno::UNO_QUERY ));
896 0 : aLSeqIt->second->setValues( xNewSequence );
897 : }
898 : else
899 : {
900 0 : Reference< beans::XPropertySet > xOldSequenceProp( aLSeqIt->second->getValues(), uno::UNO_QUERY );
901 0 : OUString aRep( OUString::number( aLSeqIt->first.first ));
902 : Reference< chart2::data::XDataSequence > xNewSequence(
903 0 : xDataProv->createDataSequenceByRangeRepresentation( aRep ));
904 : SchXMLTools::copyProperties(
905 0 : xOldSequenceProp, Reference< beans::XPropertySet >( xNewSequence, uno::UNO_QUERY ));
906 0 : aLSeqIt->second->setValues( xNewSequence );
907 : }
908 : }
909 0 : }
910 : }
911 : else // labels
912 : {
913 : SAL_WARN_IF( aLSeqIt->first.second != SCH_XML_PART_LABEL, "xmloff.chart", "aLSeqIt->first.second != SCH_XML_PART_LABEL" );
914 : // labels
915 0 : Reference< chart2::data::XDataSequence > xSeq( aLSeqIt->second->getLabel());
916 0 : OUString aRange;
917 0 : if( xSeq.is() &&
918 0 : SchXMLTools::getXMLRangePropertyFromDataSequence( xSeq, aRange, /* bClearProp = */ true ) &&
919 0 : lcl_mapContainsRange( aRangeMap, aRange ))
920 : {
921 : Reference< chart2::data::XDataSequence > xNewSeq(
922 0 : lcl_reassignDataSequence( xSeq, xDataProv, aRangeMap, aRange ));
923 0 : if( xNewSeq != xSeq )
924 : {
925 : SchXMLTools::copyProperties( Reference< beans::XPropertySet >( xSeq, uno::UNO_QUERY ),
926 0 : Reference< beans::XPropertySet >( xNewSeq, uno::UNO_QUERY ));
927 0 : aLSeqIt->second->setLabel( xNewSeq );
928 0 : }
929 : }
930 0 : else if( ! lcl_tableOfRangeMatches( aRange, rTable.aTableNameOfFile ))
931 : {
932 0 : OUString aRep("label ");
933 0 : aRep += OUString::number( aLSeqIt->first.first );
934 :
935 : Reference< chart2::data::XDataSequence > xNewSeq(
936 0 : xDataProv->createDataSequenceByRangeRepresentation( aRep ));
937 : SchXMLTools::copyProperties( Reference< beans::XPropertySet >( xSeq, uno::UNO_QUERY ),
938 0 : Reference< beans::XPropertySet >( xNewSeq, uno::UNO_QUERY ));
939 0 : aLSeqIt->second->setLabel( xNewSeq );
940 0 : }
941 : }
942 : }
943 : }
944 :
945 : //i91578 display of hidden values (copy paste scenario; use hidden flag during migration to locale table upon paste )
946 : //remove series that consist only of hidden columns
947 0 : Reference< chart2::XInternalDataProvider > xInternalDataProvider( xDataProv, uno::UNO_QUERY );
948 0 : if( xInternalDataProvider.is() && !rTable.aHiddenColumns.empty() )
949 : {
950 : try
951 : {
952 0 : Reference< chart2::XCoordinateSystemContainer > xCooSysCnt( xChartDoc->getFirstDiagram(), uno::UNO_QUERY_THROW );
953 0 : Sequence< Reference< chart2::XCoordinateSystem > > aCooSysSeq( xCooSysCnt->getCoordinateSystems() );
954 0 : for( sal_Int32 nC=0; nC<aCooSysSeq.getLength(); ++nC )
955 : {
956 0 : Reference< chart2::XChartTypeContainer > xCooSysContainer( aCooSysSeq[nC], uno::UNO_QUERY_THROW );
957 0 : Sequence< Reference< chart2::XChartType > > aChartTypeSeq( xCooSysContainer->getChartTypes());
958 0 : for( sal_Int32 nT=0; nT<aChartTypeSeq.getLength(); ++nT )
959 : {
960 0 : Reference< chart2::XDataSeriesContainer > xSeriesContainer( aChartTypeSeq[nT], uno::UNO_QUERY );
961 0 : if(!xSeriesContainer.is())
962 0 : continue;
963 0 : Sequence< Reference< chart2::XDataSeries > > aSeriesSeq( xSeriesContainer->getDataSeries() );
964 0 : std::vector< Reference< chart2::XDataSeries > > aRemainingSeries;
965 :
966 0 : for( sal_Int32 nS = 0; nS < aSeriesSeq.getLength(); nS++ )
967 : {
968 0 : Reference< chart2::data::XDataSource > xDataSource( aSeriesSeq[nS], uno::UNO_QUERY );
969 0 : if( xDataSource.is() )
970 : {
971 0 : bool bHasUnhiddenColumns = false;
972 0 : OUString aRange;
973 0 : uno::Sequence< Reference< chart2::data::XLabeledDataSequence > > aSequences( xDataSource->getDataSequences() );
974 0 : for( sal_Int32 nN=0; nN< aSequences.getLength(); ++nN )
975 : {
976 0 : Reference< chart2::data::XLabeledDataSequence > xLabeledSequence( aSequences[nN] );
977 0 : if(!xLabeledSequence.is())
978 0 : continue;
979 0 : Reference< chart2::data::XDataSequence > xValues( xLabeledSequence->getValues() );
980 0 : if( xValues.is() )
981 : {
982 0 : aRange = xValues->getSourceRangeRepresentation();
983 0 : if( ::std::find( rTable.aHiddenColumns.begin(), rTable.aHiddenColumns.end(), aRange.toInt32() ) == rTable.aHiddenColumns.end() )
984 0 : bHasUnhiddenColumns = true;
985 : }
986 0 : if( !bHasUnhiddenColumns )
987 : {
988 0 : Reference< chart2::data::XDataSequence > xLabel( xLabeledSequence->getLabel() );
989 0 : if( xLabel.is() )
990 : {
991 0 : aRange = xLabel->getSourceRangeRepresentation();
992 0 : sal_Int32 nSearchIndex = 0;
993 0 : OUString aSecondToken = aRange.getToken( 1, ' ', nSearchIndex );
994 0 : if( ::std::find( rTable.aHiddenColumns.begin(), rTable.aHiddenColumns.end(), aSecondToken.toInt32() ) == rTable.aHiddenColumns.end() )
995 0 : bHasUnhiddenColumns = true;
996 0 : }
997 : }
998 0 : }
999 0 : if( bHasUnhiddenColumns )
1000 0 : aRemainingSeries.push_back( aSeriesSeq[nS] );
1001 : }
1002 0 : }
1003 :
1004 0 : if( static_cast<sal_Int32>(aRemainingSeries.size()) != aSeriesSeq.getLength() )
1005 : {
1006 : //remove the series that have only hidden data
1007 0 : Sequence< Reference< chart2::XDataSeries > > aRemainingSeriesSeq( aRemainingSeries.size());
1008 0 : ::std::copy( aRemainingSeries.begin(), aRemainingSeries.end(), aRemainingSeriesSeq.getArray());
1009 0 : xSeriesContainer->setDataSeries( aRemainingSeriesSeq );
1010 :
1011 : //remove unused sequences
1012 0 : Reference< chart2::data::XDataSource > xDataSource( xChartDoc, uno::UNO_QUERY );
1013 0 : if( xDataSource.is() )
1014 : {
1015 : //first detect which collumns are really used
1016 0 : std::map< sal_Int32, bool > aUsageMap;
1017 0 : OUString aRange;
1018 0 : Sequence< Reference< chart2::data::XLabeledDataSequence > > aUsedSequences( xDataSource->getDataSequences() );
1019 0 : for( sal_Int32 nN=0; nN< aUsedSequences.getLength(); ++nN )
1020 : {
1021 0 : Reference< chart2::data::XLabeledDataSequence > xLabeledSequence( aUsedSequences[nN] );
1022 0 : if(!xLabeledSequence.is())
1023 0 : continue;
1024 0 : Reference< chart2::data::XDataSequence > xValues( xLabeledSequence->getValues() );
1025 0 : if( xValues.is() )
1026 : {
1027 0 : aRange = xValues->getSourceRangeRepresentation();
1028 0 : sal_Int32 nIndex = aRange.toInt32();
1029 0 : if( nIndex!=0 || !aRange.equals(lcl_aCategoriesRange) )
1030 0 : aUsageMap[nIndex] = true;
1031 : }
1032 0 : Reference< chart2::data::XDataSequence > xLabel( xLabeledSequence->getLabel() );
1033 0 : if( xLabel.is() )
1034 : {
1035 0 : aRange = xLabel->getSourceRangeRepresentation();
1036 0 : sal_Int32 nSearchIndex = 0;
1037 0 : OUString aSecondToken = aRange.getToken( 1, ' ', nSearchIndex );
1038 0 : if( !aSecondToken.isEmpty() )
1039 0 : aUsageMap[aSecondToken.toInt32()] = true;
1040 : }
1041 0 : }
1042 :
1043 0 : ::std::vector< sal_Int32 > aSequenceIndexesToDelete;
1044 0 : for( ::std::vector< sal_Int32 >::const_iterator aIt(
1045 0 : rTable.aHiddenColumns.begin()); aIt != rTable.aHiddenColumns.end(); ++aIt )
1046 : {
1047 0 : sal_Int32 nSequenceIndex = *aIt;
1048 0 : if( aUsageMap.find(nSequenceIndex) != aUsageMap.end() )
1049 0 : continue;
1050 0 : aSequenceIndexesToDelete.push_back(nSequenceIndex);
1051 : }
1052 :
1053 : // delete unnecessary sequences of the internal data
1054 : // iterate using greatest index first, so that deletion does not
1055 : // shift other sequences that will be deleted later
1056 0 : ::std::sort( aSequenceIndexesToDelete.begin(), aSequenceIndexesToDelete.end());
1057 0 : for( ::std::vector< sal_Int32 >::reverse_iterator aIt(
1058 0 : aSequenceIndexesToDelete.rbegin()); aIt != aSequenceIndexesToDelete.rend(); ++aIt )
1059 : {
1060 0 : if( *aIt != -1 )
1061 0 : xInternalDataProvider->deleteSequence( *aIt );
1062 0 : }
1063 0 : }
1064 : }
1065 0 : }
1066 0 : }
1067 : }
1068 0 : catch( const uno::Exception & )
1069 : {
1070 : }
1071 0 : }
1072 : }
1073 :
1074 0 : SchXMLRangeSomewhereContext::SchXMLRangeSomewhereContext( SvXMLImport& rImport,
1075 : sal_uInt16 nPrefix,
1076 : const OUString& rLocalName,
1077 : OUString& rRangeString ) :
1078 : SvXMLImportContext( rImport, nPrefix, rLocalName ),
1079 0 : mrRangeString( rRangeString )
1080 : {
1081 0 : }
1082 :
1083 0 : SchXMLRangeSomewhereContext::~SchXMLRangeSomewhereContext()
1084 : {
1085 0 : }
1086 :
1087 0 : SvXMLImportContext* SchXMLRangeSomewhereContext::CreateChildContext(
1088 : sal_uInt16 nPrefix,
1089 : const OUString& rLocalName,
1090 : const uno::Reference< xml::sax::XAttributeList >& )
1091 : {
1092 0 : if( XML_NAMESPACE_SVG == nPrefix && IsXMLToken( rLocalName, XML_DESC ) )
1093 : {
1094 : return new XMLStringBufferImportContext(
1095 0 : GetImport(), nPrefix, rLocalName, maRangeStringBuffer );
1096 : }
1097 0 : return new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
1098 : }
1099 :
1100 0 : void SchXMLRangeSomewhereContext::EndElement()
1101 : {
1102 0 : mrRangeString = maRangeStringBuffer.makeStringAndClear();
1103 0 : }
1104 :
1105 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|