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 806 : lcl_ApplyCellToData( Sequence< double > & rOutData ) :
69 : m_rData( rOutData ),
70 : m_nIndex( 0 ),
71 806 : m_nSize( rOutData.getLength()),
72 1612 : m_fNaN( 0.0 )
73 : {
74 806 : ::rtl::math::setNan( &m_fNaN );
75 806 : }
76 :
77 2082 : void operator() ( const SchXMLCell & rCell )
78 : {
79 2082 : if( m_nIndex < m_nSize )
80 : {
81 2082 : if( rCell.eType == SCH_CELL_TYPE_FLOAT )
82 2082 : m_rData[m_nIndex] = rCell.fValue;
83 : else
84 0 : m_rData[m_nIndex] = m_fNaN;
85 : }
86 2082 : ++m_nIndex;
87 2082 : }
88 :
89 806 : sal_Int32 getCurrentIndex() const
90 : {
91 806 : 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 174 : void lcl_fillRangeMapping(
102 : const SchXMLTable & rTable,
103 : lcl_tOriginalRangeToInternalRangeMap & rOutRangeMap,
104 : chart::ChartDataRowSource eDataRowSource )
105 : {
106 174 : sal_Int32 nRowOffset = ( rTable.bHasHeaderRow ? 1 : 0 );
107 174 : sal_Int32 nColOffset = ( rTable.bHasHeaderColumn ? 1 : 0 );
108 :
109 174 : const OUString lcl_aCategoriesRange(aCategoriesRange);
110 348 : const OUString lcl_aLabelPrefix(aLabelPrefix);
111 :
112 : // Fill range mapping
113 174 : const size_t nTableRowCount( rTable.aData.size());
114 1134 : for( size_t nRow = 0; nRow < nTableRowCount; ++nRow )
115 : {
116 960 : const ::std::vector< SchXMLCell > & rRow( rTable.aData[nRow] );
117 960 : const size_t nTableColCount( rRow.size());
118 4342 : for( size_t nCol = 0; nCol < nTableColCount; ++nCol )
119 : {
120 3382 : const OUString aRangeId( rRow[nCol].aRangeId );
121 3382 : 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 3382 : }
163 174 : }
164 174 : }
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 1028 : bool lcl_mapContainsRange(
187 : lcl_tOriginalRangeToInternalRangeMap & rRangeMap,
188 : const OUString & rRange )
189 : {
190 1028 : lcl_tOriginalRangeToInternalRangeMap::iterator aIt( rRangeMap.find( rRange ));
191 1028 : return ( aIt != rRangeMap.end());
192 : }
193 :
194 1044 : 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 2072 : return ( !rRange.isEmpty() &&
200 2072 : !rTableName.isEmpty() &&
201 2072 : (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 244 : 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 244 : mbHasColumnPermutation( false )
225 : {
226 244 : mrTable.nColumnIndex = -1;
227 244 : mrTable.nMaxColumnIndex = -1;
228 244 : mrTable.nRowIndex = -1;
229 244 : mrTable.aData.clear();
230 244 : }
231 :
232 488 : SchXMLTableContext::~SchXMLTableContext()
233 : {
234 488 : }
235 :
236 976 : SvXMLImportContext *SchXMLTableContext::CreateChildContext(
237 : sal_uInt16 nPrefix,
238 : const OUString& rLocalName,
239 : const uno::Reference< xml::sax::XAttributeList >& )
240 : {
241 976 : SvXMLImportContext* pContext = 0;
242 976 : const SvXMLTokenMap& rTokenMap = mrImportHelper.GetTableElemTokenMap();
243 :
244 976 : switch( rTokenMap.Get( nPrefix, rLocalName ))
245 : {
246 : case XML_TOK_TABLE_HEADER_COLS:
247 244 : mrTable.bHasHeaderColumn = true;
248 : // fall through intended
249 : case XML_TOK_TABLE_COLUMNS:
250 488 : pContext = new SchXMLTableColumnsContext( GetImport(), rLocalName, mrTable );
251 488 : 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 244 : mrTable.bHasHeaderRow = true;
259 : // fall through intended
260 : case XML_TOK_TABLE_ROWS:
261 488 : pContext = new SchXMLTableRowsContext( mrImportHelper, GetImport(), rLocalName, mrTable );
262 488 : 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 976 : return pContext;
273 : }
274 :
275 244 : void SchXMLTableContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
276 : {
277 : // get table-name
278 244 : sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
279 :
280 488 : for( sal_Int16 i = 0; i < nAttrCount; i++ )
281 : {
282 244 : OUString sAttrName = xAttrList->getNameByIndex( i );
283 488 : OUString aLocalName;
284 244 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
285 244 : if ( nPrefix == XML_NAMESPACE_TABLE )
286 : {
287 244 : if ( IsXMLToken( aLocalName, XML_NAME ) )
288 : {
289 244 : 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 244 : }
300 244 : }
301 :
302 244 : void SchXMLTableContext::EndElement()
303 : {
304 244 : 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 244 : 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 488 : SchXMLTableColumnsContext::SchXMLTableColumnsContext(
413 : SvXMLImport& rImport,
414 : const OUString& rLocalName,
415 : SchXMLTable& aTable ) :
416 : SvXMLImportContext( rImport, XML_NAMESPACE_TABLE, rLocalName ),
417 488 : mrTable( aTable )
418 : {
419 488 : }
420 :
421 976 : SchXMLTableColumnsContext::~SchXMLTableColumnsContext()
422 : {
423 976 : }
424 :
425 488 : SvXMLImportContext* SchXMLTableColumnsContext::CreateChildContext(
426 : sal_uInt16 nPrefix,
427 : const OUString& rLocalName,
428 : const uno::Reference< xml::sax::XAttributeList >& )
429 : {
430 488 : SvXMLImportContext* pContext = 0;
431 :
432 976 : if( nPrefix == XML_NAMESPACE_TABLE &&
433 488 : IsXMLToken( rLocalName, XML_TABLE_COLUMN ) )
434 : {
435 488 : pContext = new SchXMLTableColumnContext( GetImport(), rLocalName, mrTable );
436 : }
437 : else
438 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
439 :
440 488 : return pContext;
441 : }
442 :
443 : // class SchXMLTableColumnContext
444 488 : SchXMLTableColumnContext::SchXMLTableColumnContext(
445 : SvXMLImport& rImport,
446 : const OUString& rLocalName,
447 : SchXMLTable& aTable ) :
448 : SvXMLImportContext( rImport, XML_NAMESPACE_TABLE, rLocalName ),
449 488 : mrTable( aTable )
450 : {
451 488 : }
452 :
453 488 : void SchXMLTableColumnContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
454 : {
455 : // get number-columns-repeated attribute
456 488 : sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
457 488 : sal_Int32 nRepeated = 1;
458 488 : bool bHidden = false;
459 :
460 662 : for( sal_Int16 i = 0; i < nAttrCount; i++ )
461 : {
462 174 : OUString sAttrName = xAttrList->getNameByIndex( i );
463 348 : OUString aLocalName;
464 174 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
465 :
466 348 : if( nPrefix == XML_NAMESPACE_TABLE &&
467 174 : IsXMLToken( aLocalName, XML_NUMBER_COLUMNS_REPEATED ) )
468 : {
469 174 : OUString aValue = xAttrList->getValueByIndex( i );
470 174 : if( !aValue.isEmpty())
471 174 : 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 174 : }
480 :
481 488 : sal_Int32 nOldCount = mrTable.nNumberOfColsEstimate;
482 488 : sal_Int32 nNewCount = nOldCount + nRepeated;
483 488 : mrTable.nNumberOfColsEstimate = nNewCount;
484 :
485 488 : 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 488 : }
497 :
498 976 : SchXMLTableColumnContext::~SchXMLTableColumnContext()
499 : {
500 976 : }
501 :
502 : // classes for rows
503 : // class SchXMLTableRowsContext
504 488 : 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 488 : mrTable( aTable )
512 : {
513 488 : }
514 :
515 976 : SchXMLTableRowsContext::~SchXMLTableRowsContext()
516 : {
517 976 : }
518 :
519 1350 : SvXMLImportContext* SchXMLTableRowsContext::CreateChildContext(
520 : sal_uInt16 nPrefix,
521 : const OUString& rLocalName,
522 : const uno::Reference< xml::sax::XAttributeList >& )
523 : {
524 1350 : SvXMLImportContext* pContext = 0;
525 :
526 2700 : if( nPrefix == XML_NAMESPACE_TABLE &&
527 1350 : IsXMLToken( rLocalName, XML_TABLE_ROW ) )
528 : {
529 1350 : pContext = new SchXMLTableRowContext( mrImportHelper, GetImport(), rLocalName, mrTable );
530 : }
531 : else
532 : {
533 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
534 : }
535 :
536 1350 : return pContext;
537 : }
538 :
539 : // class SchXMLTableRowContext
540 1350 : 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 1350 : mrTable( aTable )
548 : {
549 1350 : mrTable.nColumnIndex = -1;
550 1350 : mrTable.nRowIndex++;
551 :
552 1350 : std::vector< SchXMLCell > aNewRow;
553 1350 : aNewRow.reserve( mrTable.nNumberOfColsEstimate );
554 4050 : while( mrTable.aData.size() <= (unsigned long)mrTable.nRowIndex )
555 2700 : mrTable.aData.push_back( aNewRow );
556 1350 : }
557 :
558 2700 : SchXMLTableRowContext::~SchXMLTableRowContext()
559 : {
560 2700 : }
561 :
562 4558 : SvXMLImportContext* SchXMLTableRowContext::CreateChildContext(
563 : sal_uInt16 nPrefix,
564 : const OUString& rLocalName,
565 : const uno::Reference< xml::sax::XAttributeList >& )
566 : {
567 4558 : SvXMLImportContext* pContext = 0;
568 :
569 : // <table:table-cell> element
570 9116 : if( nPrefix == XML_NAMESPACE_TABLE &&
571 4558 : IsXMLToken(rLocalName, XML_TABLE_CELL ) )
572 : {
573 4558 : pContext = new SchXMLTableCellContext( mrImportHelper, GetImport(), rLocalName, mrTable );
574 : }
575 : else
576 : {
577 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
578 : }
579 :
580 4558 : 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 4558 : 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 4558 : , mbReadText(false)
617 : {
618 4558 : }
619 :
620 9116 : SchXMLTableCellContext::~SchXMLTableCellContext()
621 : {
622 9116 : }
623 :
624 4558 : void SchXMLTableCellContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
625 : {
626 4558 : sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
627 4558 : OUString aValue;
628 9116 : OUString aLocalName;
629 9116 : OUString aCellContent;
630 4558 : SchXMLCellType eValueType = SCH_CELL_TYPE_UNKNOWN;
631 4558 : const SvXMLTokenMap& rAttrTokenMap = mrImportHelper.GetCellAttrTokenMap();
632 :
633 11496 : for( sal_Int16 i = 0; i < nAttrCount; i++ )
634 : {
635 6938 : OUString sAttrName = xAttrList->getNameByIndex( i );
636 6938 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
637 :
638 6938 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ))
639 : {
640 : case XML_TOK_CELL_VAL_TYPE:
641 4314 : aValue = xAttrList->getValueByIndex( i );
642 4314 : if( IsXMLToken( aValue, XML_FLOAT ) )
643 2624 : eValueType = SCH_CELL_TYPE_FLOAT;
644 1690 : else if( IsXMLToken( aValue, XML_STRING ) )
645 1690 : eValueType = SCH_CELL_TYPE_STRING;
646 4314 : break;
647 :
648 : case XML_TOK_CELL_VALUE:
649 2624 : aCellContent = xAttrList->getValueByIndex( i );
650 2624 : break;
651 : }
652 6938 : }
653 :
654 4558 : mbReadText = true;
655 4558 : SchXMLCell aCell;
656 4558 : aCell.eType = eValueType;
657 :
658 4558 : 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 2624 : ::sax::Converter::convertDouble( fData, aCellContent );
663 :
664 2624 : aCell.fValue = fData;
665 : // dont read text from following <text:p> or <text:list> element
666 2624 : mbReadText = false;
667 : }
668 :
669 4558 : mrTable.aData[ mrTable.nRowIndex ].push_back( aCell );
670 4558 : mrTable.nColumnIndex++;
671 4558 : if( mrTable.nMaxColumnIndex < mrTable.nColumnIndex )
672 5386 : mrTable.nMaxColumnIndex = mrTable.nColumnIndex;
673 4558 : }
674 :
675 4712 : SvXMLImportContext* SchXMLTableCellContext::CreateChildContext(
676 : sal_uInt16 nPrefix,
677 : const OUString& rLocalName,
678 : const uno::Reference< xml::sax::XAttributeList >& )
679 : {
680 4712 : SvXMLImportContext* pContext = 0;
681 :
682 : // <text:list> element
683 4712 : 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 4712 : else if( nPrefix == XML_NAMESPACE_TEXT && IsXMLToken( rLocalName, XML_P ) )
693 : {
694 4524 : pContext = new SchXMLParagraphContext( GetImport(), rLocalName, maCellContent, &maRangeId );
695 : }
696 : // <draw:g> element - read range
697 188 : 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 188 : pContext = new SchXMLRangeSomewhereContext( GetImport(), nPrefix, rLocalName, maRangeId );
702 : }
703 : else
704 : {
705 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
706 : }
707 :
708 4712 : return pContext;
709 : }
710 :
711 4558 : void SchXMLTableCellContext::EndElement()
712 : {
713 4558 : if( mbReadText && !maCellContent.isEmpty() ) //apply text from <text:p> element
714 1634 : mrTable.aData[ mrTable.nRowIndex ][ mrTable.nColumnIndex ].aString = maCellContent;
715 4558 : if( !maRangeId.isEmpty())
716 188 : mrTable.aData[ mrTable.nRowIndex ][ mrTable.nColumnIndex ].aRangeId = maRangeId;
717 4558 : }
718 :
719 1266 : static void lcl_ApplyCellToComplexLabel( const SchXMLCell& rCell, Sequence< uno::Any >& rComplexLabel )
720 : {
721 1266 : if( rCell.eType == SCH_CELL_TYPE_STRING )
722 : {
723 1266 : rComplexLabel.realloc(1);
724 1266 : 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 1266 : }
739 :
740 178 : 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 178 : if( !xChartDoc.is() || !xChartDoc->hasInternalDataProvider() )
746 0 : return;
747 178 : Reference< chart2::data::XDataProvider > xDataProv( xChartDoc->getDataProvider() );
748 178 : if( !xDataProv.is() )
749 0 : return;
750 :
751 : //prepare the read local table data
752 178 : sal_Int32 nNumRows( static_cast< sal_Int32 >( rTable.aData.size()));
753 178 : sal_Int32 nRowOffset = 0;
754 178 : if( rTable.bHasHeaderRow )
755 : {
756 178 : --nNumRows;
757 178 : nRowOffset = 1;
758 : }
759 178 : sal_Int32 nNumColumns( rTable.nMaxColumnIndex + 1 );
760 178 : sal_Int32 nColOffset = 0;
761 178 : if( rTable.bHasHeaderColumn )
762 : {
763 178 : --nNumColumns;
764 178 : nColOffset = 1;
765 : }
766 :
767 356 : Sequence< Sequence< double > > aDataInRows( nNumRows );
768 356 : Sequence< Sequence< uno::Any > > aComplexRowDescriptions( nNumRows );
769 356 : Sequence< Sequence< uno::Any > > aComplexColumnDescriptions( nNumColumns );
770 984 : for( sal_Int32 i=0; i<nNumRows; ++i )
771 806 : aDataInRows[i].realloc( nNumColumns );
772 :
773 178 : if( rTable.aData.begin() != rTable.aData.end())
774 : {
775 : //apply column labels
776 178 : if( rTable.bHasHeaderRow )
777 : {
778 178 : const ::std::vector< SchXMLCell >& rFirstRow = rTable.aData.front();
779 178 : const sal_Int32 nColumnLabelsSize = aComplexColumnDescriptions.getLength();
780 178 : 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 638 : for( sal_Int32 i=0; i<nMax; ++i )
783 460 : lcl_ApplyCellToComplexLabel( rFirstRow[i+nColOffset], aComplexColumnDescriptions[i] );
784 : }
785 :
786 178 : std::vector< ::std::vector< SchXMLCell > >::const_iterator aRowIter( rTable.aData.begin() + nRowOffset );
787 178 : std::vector< ::std::vector< SchXMLCell > >::const_iterator aEnd( rTable.aData.end() );
788 984 : for( sal_Int32 nRow = 0; aRowIter != aEnd && nRow < nNumRows; ++aRowIter, ++nRow )
789 : {
790 806 : const ::std::vector< SchXMLCell >& rRow = *aRowIter;
791 806 : if( !rRow.empty() )
792 : {
793 : // row label
794 806 : if( rTable.bHasHeaderColumn )
795 806 : lcl_ApplyCellToComplexLabel( rRow.front(), aComplexRowDescriptions[nRow] );
796 :
797 : // values
798 806 : Sequence< double >& rTargetRow = aDataInRows[nRow];
799 806 : lcl_ApplyCellToData aApplyCellToData = ::std::for_each( rRow.begin() + nColOffset, rRow.end(), lcl_ApplyCellToData( rTargetRow ) );
800 806 : double fNaN = 0.0;
801 806 : ::rtl::math::setNan( &fNaN );
802 806 : 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 356 : Reference< chart2::XAnyDescriptionAccess > xDataAccess( xDataProv, uno::UNO_QUERY );
810 178 : if( !xDataAccess.is() )
811 0 : return;
812 :
813 178 : xDataAccess->setData( aDataInRows );
814 178 : if( rTable.bHasHeaderColumn )
815 178 : xDataAccess->setAnyRowDescriptions( aComplexRowDescriptions );
816 178 : if( rTable.bHasHeaderRow )
817 178 : xDataAccess->setAnyColumnDescriptions( aComplexColumnDescriptions );
818 :
819 178 : 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 178 : }
831 : }
832 :
833 174 : void SchXMLTableHelper::switchRangesFromOuterToInternalIfNecessary(
834 : const SchXMLTable& rTable,
835 : const tSchXMLLSequencesPerIndex & rLSequencesPerIndex,
836 : uno::Reference< chart2::XChartDocument > xChartDoc,
837 : chart::ChartDataRowSource eDataRowSource )
838 : {
839 174 : if( ! (xChartDoc.is() && xChartDoc->hasInternalDataProvider()))
840 174 : 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 174 : Reference< chart2::data::XDataProvider > xDataProv( xChartDoc->getDataProvider());
850 :
851 : // create a mapping from original ranges to new ranges
852 348 : lcl_tOriginalRangeToInternalRangeMap aRangeMap;
853 :
854 174 : lcl_fillRangeMapping( rTable, aRangeMap, eDataRowSource );
855 :
856 348 : const OUString lcl_aCategoriesRange(aCategoriesRange);
857 :
858 174 : bool bCategoriesApplied = false;
859 : // translate ranges (using the map created before)
860 3654 : for( tSchXMLLSequencesPerIndex::const_iterator aLSeqIt( rLSequencesPerIndex.begin());
861 2436 : aLSeqIt != rLSequencesPerIndex.end(); ++aLSeqIt )
862 : {
863 1044 : if( aLSeqIt->second.is())
864 : {
865 : // values/error bars/categories
866 1464 : if( aLSeqIt->first.second == SCH_XML_PART_VALUES ||
867 420 : aLSeqIt->first.second == SCH_XML_PART_ERROR_BARS )
868 : {
869 624 : Reference< chart2::data::XDataSequence > xSeq( aLSeqIt->second->getValues());
870 :
871 1248 : OUString aRange;
872 1868 : if( xSeq.is() &&
873 1244 : SchXMLTools::getXMLRangePropertyFromDataSequence( xSeq, aRange, /* bClearProp = */ true ) &&
874 620 : lcl_mapContainsRange( aRangeMap, aRange ))
875 : {
876 : Reference< chart2::data::XDataSequence > xNewSeq(
877 0 : lcl_reassignDataSequence( xSeq, xDataProv, aRangeMap, aRange ));
878 0 : if( xNewSeq != xSeq )
879 : {
880 : SchXMLTools::copyProperties( Reference< beans::XPropertySet >( xSeq, uno::UNO_QUERY ),
881 0 : Reference< beans::XPropertySet >( xNewSeq, uno::UNO_QUERY ));
882 0 : aLSeqIt->second->setValues( xNewSeq );
883 0 : }
884 : }
885 : else
886 : {
887 624 : if( lcl_tableOfRangeMatches( aRange, rTable.aTableNameOfFile ))
888 : {
889 620 : if( aLSeqIt->first.first == SCH_XML_CATEGORIES_INDEX )
890 176 : bCategoriesApplied = true;
891 : }
892 : else
893 : {
894 4 : if( aLSeqIt->first.first == SCH_XML_CATEGORIES_INDEX )
895 : {
896 0 : Reference< beans::XPropertySet > xOldSequenceProp( aLSeqIt->second->getValues(), uno::UNO_QUERY );
897 : Reference< chart2::data::XDataSequence > xNewSequence(
898 0 : xDataProv->createDataSequenceByRangeRepresentation(
899 0 : OUString("categories")));
900 : SchXMLTools::copyProperties(
901 0 : xOldSequenceProp, Reference< beans::XPropertySet >( xNewSequence, uno::UNO_QUERY ));
902 0 : aLSeqIt->second->setValues( xNewSequence );
903 0 : bCategoriesApplied = true;
904 : }
905 : else
906 : {
907 4 : Reference< beans::XPropertySet > xOldSequenceProp( aLSeqIt->second->getValues(), uno::UNO_QUERY );
908 8 : OUString aRep( OUString::number( aLSeqIt->first.first ));
909 : Reference< chart2::data::XDataSequence > xNewSequence(
910 8 : xDataProv->createDataSequenceByRangeRepresentation( aRep ));
911 : SchXMLTools::copyProperties(
912 4 : xOldSequenceProp, Reference< beans::XPropertySet >( xNewSequence, uno::UNO_QUERY ));
913 8 : aLSeqIt->second->setValues( xNewSequence );
914 : }
915 : }
916 624 : }
917 : }
918 : else // labels
919 : {
920 : SAL_WARN_IF( aLSeqIt->first.second != SCH_XML_PART_LABEL, "xmloff.chart", "aLSeqIt->first.second != SCH_XML_PART_LABEL" );
921 : // labels
922 420 : Reference< chart2::data::XDataSequence > xSeq( aLSeqIt->second->getLabel());
923 840 : OUString aRange;
924 1248 : if( xSeq.is() &&
925 828 : SchXMLTools::getXMLRangePropertyFromDataSequence( xSeq, aRange, /* bClearProp = */ true ) &&
926 408 : lcl_mapContainsRange( aRangeMap, aRange ))
927 : {
928 : Reference< chart2::data::XDataSequence > xNewSeq(
929 0 : lcl_reassignDataSequence( xSeq, xDataProv, aRangeMap, aRange ));
930 0 : if( xNewSeq != xSeq )
931 : {
932 : SchXMLTools::copyProperties( Reference< beans::XPropertySet >( xSeq, uno::UNO_QUERY ),
933 0 : Reference< beans::XPropertySet >( xNewSeq, uno::UNO_QUERY ));
934 0 : aLSeqIt->second->setLabel( xNewSeq );
935 0 : }
936 : }
937 420 : else if( ! lcl_tableOfRangeMatches( aRange, rTable.aTableNameOfFile ))
938 : {
939 12 : OUString aRep("label ");
940 12 : aRep += OUString::number( aLSeqIt->first.first );
941 :
942 : Reference< chart2::data::XDataSequence > xNewSeq(
943 24 : xDataProv->createDataSequenceByRangeRepresentation( aRep ));
944 : SchXMLTools::copyProperties( Reference< beans::XPropertySet >( xSeq, uno::UNO_QUERY ),
945 12 : Reference< beans::XPropertySet >( xNewSeq, uno::UNO_QUERY ));
946 24 : aLSeqIt->second->setLabel( xNewSeq );
947 420 : }
948 : }
949 : }
950 : }
951 :
952 : // there exist files with own data without a categories element but with row
953 : // descriptions. The row descriptions were used as categories even without
954 : // the categories element
955 174 : if( ! bCategoriesApplied )
956 : {
957 : SchXMLTools::CreateCategories(
958 : xDataProv, xChartDoc, OUString("categories"),
959 8 : 0 /* nCooSysIndex */, 0 /* nDimension */ );
960 : }
961 :
962 : //i91578 display of hidden values (copy paste scenario; use hidden flag during migration to locale table upon paste )
963 : //remove series that consist only of hidden columns
964 348 : Reference< chart2::XInternalDataProvider > xInternalDataProvider( xDataProv, uno::UNO_QUERY );
965 174 : if( xInternalDataProvider.is() && !rTable.aHiddenColumns.empty() )
966 : {
967 : try
968 : {
969 0 : Reference< chart2::XCoordinateSystemContainer > xCooSysCnt( xChartDoc->getFirstDiagram(), uno::UNO_QUERY_THROW );
970 0 : Sequence< Reference< chart2::XCoordinateSystem > > aCooSysSeq( xCooSysCnt->getCoordinateSystems() );
971 0 : for( sal_Int32 nC=0; nC<aCooSysSeq.getLength(); ++nC )
972 : {
973 0 : Reference< chart2::XChartTypeContainer > xCooSysContainer( aCooSysSeq[nC], uno::UNO_QUERY_THROW );
974 0 : Sequence< Reference< chart2::XChartType > > aChartTypeSeq( xCooSysContainer->getChartTypes());
975 0 : for( sal_Int32 nT=0; nT<aChartTypeSeq.getLength(); ++nT )
976 : {
977 0 : Reference< chart2::XDataSeriesContainer > xSeriesContainer( aChartTypeSeq[nT], uno::UNO_QUERY );
978 0 : if(!xSeriesContainer.is())
979 0 : continue;
980 0 : Sequence< Reference< chart2::XDataSeries > > aSeriesSeq( xSeriesContainer->getDataSeries() );
981 0 : std::vector< Reference< chart2::XDataSeries > > aRemainingSeries;
982 :
983 0 : for( sal_Int32 nS = 0; nS < aSeriesSeq.getLength(); nS++ )
984 : {
985 0 : Reference< chart2::data::XDataSource > xDataSource( aSeriesSeq[nS], uno::UNO_QUERY );
986 0 : if( xDataSource.is() )
987 : {
988 0 : bool bHasUnhiddenColumns = false;
989 0 : OUString aRange;
990 0 : uno::Sequence< Reference< chart2::data::XLabeledDataSequence > > aSequences( xDataSource->getDataSequences() );
991 0 : for( sal_Int32 nN=0; nN< aSequences.getLength(); ++nN )
992 : {
993 0 : Reference< chart2::data::XLabeledDataSequence > xLabeledSequence( aSequences[nN] );
994 0 : if(!xLabeledSequence.is())
995 0 : continue;
996 0 : Reference< chart2::data::XDataSequence > xValues( xLabeledSequence->getValues() );
997 0 : if( xValues.is() )
998 : {
999 0 : aRange = xValues->getSourceRangeRepresentation();
1000 0 : if( ::std::find( rTable.aHiddenColumns.begin(), rTable.aHiddenColumns.end(), aRange.toInt32() ) == rTable.aHiddenColumns.end() )
1001 0 : bHasUnhiddenColumns = true;
1002 : }
1003 0 : if( !bHasUnhiddenColumns )
1004 : {
1005 0 : Reference< chart2::data::XDataSequence > xLabel( xLabeledSequence->getLabel() );
1006 0 : if( xLabel.is() )
1007 : {
1008 0 : aRange = xLabel->getSourceRangeRepresentation();
1009 0 : sal_Int32 nSearchIndex = 0;
1010 0 : OUString aSecondToken = aRange.getToken( 1, ' ', nSearchIndex );
1011 0 : if( ::std::find( rTable.aHiddenColumns.begin(), rTable.aHiddenColumns.end(), aSecondToken.toInt32() ) == rTable.aHiddenColumns.end() )
1012 0 : bHasUnhiddenColumns = true;
1013 0 : }
1014 : }
1015 0 : }
1016 0 : if( bHasUnhiddenColumns )
1017 0 : aRemainingSeries.push_back( aSeriesSeq[nS] );
1018 : }
1019 0 : }
1020 :
1021 0 : if( static_cast<sal_Int32>(aRemainingSeries.size()) != aSeriesSeq.getLength() )
1022 : {
1023 : //remove the series that have only hidden data
1024 0 : Sequence< Reference< chart2::XDataSeries > > aRemainingSeriesSeq( aRemainingSeries.size());
1025 0 : ::std::copy( aRemainingSeries.begin(), aRemainingSeries.end(), aRemainingSeriesSeq.getArray());
1026 0 : xSeriesContainer->setDataSeries( aRemainingSeriesSeq );
1027 :
1028 : //remove unused sequences
1029 0 : Reference< chart2::data::XDataSource > xDataSource( xChartDoc, uno::UNO_QUERY );
1030 0 : if( xDataSource.is() )
1031 : {
1032 : //first detect which collumns are really used
1033 0 : std::map< sal_Int32, bool > aUsageMap;
1034 0 : OUString aRange;
1035 0 : Sequence< Reference< chart2::data::XLabeledDataSequence > > aUsedSequences( xDataSource->getDataSequences() );
1036 0 : for( sal_Int32 nN=0; nN< aUsedSequences.getLength(); ++nN )
1037 : {
1038 0 : Reference< chart2::data::XLabeledDataSequence > xLabeledSequence( aUsedSequences[nN] );
1039 0 : if(!xLabeledSequence.is())
1040 0 : continue;
1041 0 : Reference< chart2::data::XDataSequence > xValues( xLabeledSequence->getValues() );
1042 0 : if( xValues.is() )
1043 : {
1044 0 : aRange = xValues->getSourceRangeRepresentation();
1045 0 : sal_Int32 nIndex = aRange.toInt32();
1046 0 : if( nIndex!=0 || !aRange.equals(lcl_aCategoriesRange) )
1047 0 : aUsageMap[nIndex] = true;
1048 : }
1049 0 : Reference< chart2::data::XDataSequence > xLabel( xLabeledSequence->getLabel() );
1050 0 : if( xLabel.is() )
1051 : {
1052 0 : aRange = xLabel->getSourceRangeRepresentation();
1053 0 : sal_Int32 nSearchIndex = 0;
1054 0 : OUString aSecondToken = aRange.getToken( 1, ' ', nSearchIndex );
1055 0 : if( !aSecondToken.isEmpty() )
1056 0 : aUsageMap[aSecondToken.toInt32()] = true;
1057 : }
1058 0 : }
1059 :
1060 0 : ::std::vector< sal_Int32 > aSequenceIndexesToDelete;
1061 0 : for( ::std::vector< sal_Int32 >::const_iterator aIt(
1062 0 : rTable.aHiddenColumns.begin()); aIt != rTable.aHiddenColumns.end(); ++aIt )
1063 : {
1064 0 : sal_Int32 nSequenceIndex = *aIt;
1065 0 : if( aUsageMap.find(nSequenceIndex) != aUsageMap.end() )
1066 0 : continue;
1067 0 : aSequenceIndexesToDelete.push_back(nSequenceIndex);
1068 : }
1069 :
1070 : // delete unnecessary sequences of the internal data
1071 : // iterate using greatest index first, so that deletion does not
1072 : // shift other sequences that will be deleted later
1073 0 : ::std::sort( aSequenceIndexesToDelete.begin(), aSequenceIndexesToDelete.end());
1074 0 : for( ::std::vector< sal_Int32 >::reverse_iterator aIt(
1075 0 : aSequenceIndexesToDelete.rbegin()); aIt != aSequenceIndexesToDelete.rend(); ++aIt )
1076 : {
1077 0 : if( *aIt != -1 )
1078 0 : xInternalDataProvider->deleteSequence( *aIt );
1079 0 : }
1080 0 : }
1081 : }
1082 0 : }
1083 0 : }
1084 : }
1085 0 : catch( const uno::Exception & )
1086 : {
1087 : }
1088 174 : }
1089 : }
1090 :
1091 188 : SchXMLRangeSomewhereContext::SchXMLRangeSomewhereContext( SvXMLImport& rImport,
1092 : sal_uInt16 nPrefix,
1093 : const OUString& rLocalName,
1094 : OUString& rRangeString ) :
1095 : SvXMLImportContext( rImport, nPrefix, rLocalName ),
1096 188 : mrRangeString( rRangeString )
1097 : {
1098 188 : }
1099 :
1100 376 : SchXMLRangeSomewhereContext::~SchXMLRangeSomewhereContext()
1101 : {
1102 376 : }
1103 :
1104 188 : SvXMLImportContext* SchXMLRangeSomewhereContext::CreateChildContext(
1105 : sal_uInt16 nPrefix,
1106 : const OUString& rLocalName,
1107 : const uno::Reference< xml::sax::XAttributeList >& )
1108 : {
1109 188 : if( XML_NAMESPACE_SVG == nPrefix && IsXMLToken( rLocalName, XML_DESC ) )
1110 : {
1111 : return new XMLStringBufferImportContext(
1112 188 : GetImport(), nPrefix, rLocalName, maRangeStringBuffer );
1113 : }
1114 0 : return new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
1115 : }
1116 :
1117 188 : void SchXMLRangeSomewhereContext::EndElement()
1118 : {
1119 188 : mrRangeString = maRangeStringBuffer.makeStringAndClear();
1120 188 : }
1121 :
1122 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|