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 228 : explicit lcl_ApplyCellToData( Sequence< double > & rOutData ) :
69 : m_rData( rOutData ),
70 : m_nIndex( 0 ),
71 228 : m_nSize( rOutData.getLength()),
72 456 : m_fNaN( 0.0 )
73 : {
74 228 : ::rtl::math::setNan( &m_fNaN );
75 228 : }
76 :
77 557 : void operator() ( const SchXMLCell & rCell )
78 : {
79 557 : if( m_nIndex < m_nSize )
80 : {
81 557 : if( rCell.eType == SCH_CELL_TYPE_FLOAT )
82 557 : m_rData[m_nIndex] = rCell.fValue;
83 : else
84 0 : m_rData[m_nIndex] = m_fNaN;
85 : }
86 557 : ++m_nIndex;
87 557 : }
88 :
89 228 : sal_Int32 getCurrentIndex() const
90 : {
91 228 : 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 49 : void lcl_fillRangeMapping(
102 : const SchXMLTable & rTable,
103 : lcl_tOriginalRangeToInternalRangeMap & rOutRangeMap,
104 : chart::ChartDataRowSource eDataRowSource )
105 : {
106 49 : sal_Int32 nRowOffset = ( rTable.bHasHeaderRow ? 1 : 0 );
107 49 : sal_Int32 nColOffset = ( rTable.bHasHeaderColumn ? 1 : 0 );
108 :
109 49 : const OUString lcl_aCategoriesRange(aCategoriesRange);
110 98 : const OUString lcl_aLabelPrefix(aLabelPrefix);
111 :
112 : // Fill range mapping
113 49 : const size_t nTableRowCount( rTable.aData.size());
114 321 : for( size_t nRow = 0; nRow < nTableRowCount; ++nRow )
115 : {
116 272 : const ::std::vector< SchXMLCell > & rRow( rTable.aData[nRow] );
117 272 : const size_t nTableColCount( rRow.size());
118 1197 : for( size_t nCol = 0; nCol < nTableColCount; ++nCol )
119 : {
120 925 : const OUString aRangeId( rRow[nCol].aRangeId );
121 925 : 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 925 : }
163 49 : }
164 49 : }
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 282 : bool lcl_mapContainsRange(
187 : lcl_tOriginalRangeToInternalRangeMap & rRangeMap,
188 : const OUString & rRange )
189 : {
190 282 : lcl_tOriginalRangeToInternalRangeMap::iterator aIt( rRangeMap.find( rRange ));
191 282 : return ( aIt != rRangeMap.end());
192 : }
193 :
194 285 : 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 567 : return ( !rRange.isEmpty() &&
200 567 : !rTableName.isEmpty() &&
201 567 : (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.begin(), rSequence.end(), aResult.begin());
209 0 : return aResult;
210 : }
211 :
212 : } // anonymous namespace
213 :
214 : // class SchXMLTableContext
215 86 : SchXMLTableContext::SchXMLTableContext( SchXMLImportHelper& rImpHelper,
216 : SvXMLImport& rImport,
217 : const OUString& rLName,
218 : SchXMLTable& aTable ) :
219 : SvXMLImportContext( rImport, XML_NAMESPACE_TABLE, rLName ),
220 : mrImportHelper( rImpHelper ),
221 : mrTable( aTable ),
222 : mbHasRowPermutation( false ),
223 86 : mbHasColumnPermutation( false )
224 : {
225 86 : mrTable.nColumnIndex = -1;
226 86 : mrTable.nMaxColumnIndex = -1;
227 86 : mrTable.nRowIndex = -1;
228 86 : mrTable.aData.clear();
229 86 : }
230 :
231 172 : SchXMLTableContext::~SchXMLTableContext()
232 : {
233 172 : }
234 :
235 344 : SvXMLImportContext *SchXMLTableContext::CreateChildContext(
236 : sal_uInt16 nPrefix,
237 : const OUString& rLocalName,
238 : const uno::Reference< xml::sax::XAttributeList >& )
239 : {
240 344 : SvXMLImportContext* pContext = 0;
241 344 : const SvXMLTokenMap& rTokenMap = mrImportHelper.GetTableElemTokenMap();
242 :
243 344 : switch( rTokenMap.Get( nPrefix, rLocalName ))
244 : {
245 : case XML_TOK_TABLE_HEADER_COLS:
246 86 : mrTable.bHasHeaderColumn = true;
247 : // fall through intended
248 : case XML_TOK_TABLE_COLUMNS:
249 172 : pContext = new SchXMLTableColumnsContext( GetImport(), rLocalName, mrTable );
250 172 : break;
251 :
252 : case XML_TOK_TABLE_COLUMN:
253 0 : pContext = new SchXMLTableColumnContext( GetImport(), rLocalName, mrTable );
254 0 : break;
255 :
256 : case XML_TOK_TABLE_HEADER_ROWS:
257 86 : mrTable.bHasHeaderRow = true;
258 : // fall through intended
259 : case XML_TOK_TABLE_ROWS:
260 172 : pContext = new SchXMLTableRowsContext( mrImportHelper, GetImport(), rLocalName, mrTable );
261 172 : break;
262 :
263 : case XML_TOK_TABLE_ROW:
264 0 : pContext = new SchXMLTableRowContext( mrImportHelper, GetImport(), rLocalName, mrTable );
265 0 : break;
266 :
267 : default:
268 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
269 : }
270 :
271 344 : return pContext;
272 : }
273 :
274 86 : void SchXMLTableContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
275 : {
276 : // get table-name
277 86 : sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
278 :
279 172 : for( sal_Int16 i = 0; i < nAttrCount; i++ )
280 : {
281 86 : OUString sAttrName = xAttrList->getNameByIndex( i );
282 172 : OUString aLocalName;
283 86 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
284 86 : if ( nPrefix == XML_NAMESPACE_TABLE )
285 : {
286 86 : if ( IsXMLToken( aLocalName, XML_NAME ) )
287 : {
288 86 : mrTable.aTableNameOfFile = xAttrList->getValueByIndex( i );
289 : }
290 0 : else if ( IsXMLToken( aLocalName, XML_PROTECTED ) )
291 : {
292 0 : if ( IsXMLToken( xAttrList->getValueByIndex( i ), XML_TRUE ) )
293 : {
294 0 : mrTable.bProtected = true;
295 : }
296 : }
297 : }
298 86 : }
299 86 : }
300 :
301 86 : void SchXMLTableContext::EndElement()
302 : {
303 86 : if( mbHasColumnPermutation )
304 : {
305 : SAL_WARN_IF( mbHasRowPermutation, "xmloff.chart", "mbHasColumnPermutation is true" );
306 0 : ::std::vector< sal_Int32 > aPermutation( lcl_SequenceToVector( maColumnPermutation ));
307 : SAL_WARN_IF( aPermutation.empty(), "xmloff.chart", "aPermutation is NULL");
308 0 : if( aPermutation.empty())
309 0 : return;
310 :
311 : // permute the values of all rows according to aPermutation
312 0 : for( ::std::vector< ::std::vector< SchXMLCell > >::iterator aRowIt( mrTable.aData.begin());
313 0 : aRowIt != mrTable.aData.end(); ++aRowIt )
314 : {
315 0 : bool bModified = false;
316 0 : ::std::vector< SchXMLCell > aModifiedRow;
317 0 : const size_t nPermSize = aPermutation.size();
318 : 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())");
319 0 : const size_t nRowSize = aRowIt->size();
320 0 : const size_t nDestSize = ::std::min( nPermSize, nRowSize );
321 0 : for( size_t nDestinationIndex = 0; nDestinationIndex < nDestSize; ++nDestinationIndex )
322 : {
323 0 : const size_t nSourceIndex = static_cast< size_t >( aPermutation[ nDestinationIndex ] );
324 0 : if( nSourceIndex != nDestinationIndex &&
325 0 : nSourceIndex < nRowSize )
326 : {
327 : // copy original on first real permutation
328 0 : if( !bModified )
329 : {
330 : SAL_WARN_IF( !aModifiedRow.empty(), "xmloff.chart", "aModifiedRow is NOT NULL");
331 0 : aModifiedRow.reserve( aRowIt->size());
332 0 : ::std::copy( aRowIt->begin(), aRowIt->end(), ::std::back_inserter( aModifiedRow ));
333 : SAL_WARN_IF( aModifiedRow.empty(), "xmloff.chart", "aModifiedRow is NULL");
334 : }
335 : SAL_WARN_IF( nDestinationIndex >= aModifiedRow.size(), "xmloff.chart", "nDestinationIndex >= aModifiedRow.size()");
336 0 : aModifiedRow[ nDestinationIndex ] = (*aRowIt)[ nSourceIndex ];
337 0 : bModified = true;
338 : }
339 : }
340 : // copy back
341 0 : if( bModified )
342 0 : ::std::copy( aModifiedRow.begin(), aModifiedRow.end(), aRowIt->begin());
343 0 : }
344 : }
345 86 : else if( mbHasRowPermutation )
346 : {
347 0 : ::std::vector< sal_Int32 > aPermutation( lcl_SequenceToVector( maRowPermutation ));
348 : SAL_WARN_IF( aPermutation.empty(), "xmloff.chart", "aPermutation is NULL");
349 0 : if( aPermutation.empty())
350 0 : return;
351 :
352 0 : bool bModified = false;
353 0 : const size_t nPermSize = aPermutation.size();
354 : 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())");
355 0 : const size_t nTableRowCount = mrTable.aData.size();
356 0 : const size_t nDestSize = ::std::min( nPermSize, nTableRowCount );
357 0 : ::std::vector< ::std::vector< SchXMLCell > > aDestination;
358 0 : for( size_t nDestinationIndex = 0; nDestinationIndex < nDestSize; ++nDestinationIndex )
359 : {
360 0 : const size_t nSourceIndex = static_cast< size_t >( aPermutation[ nDestinationIndex ] );
361 0 : if( nSourceIndex != nDestinationIndex &&
362 0 : nSourceIndex < nTableRowCount )
363 : {
364 : // copy original on first real permutation
365 0 : if( !bModified )
366 : {
367 : SAL_WARN_IF( !aDestination.empty(), "xmloff.chart", "aDestination is NOT NULL");
368 0 : aDestination.reserve( mrTable.aData.size());
369 0 : ::std::copy( mrTable.aData.begin(), mrTable.aData.end(), ::std::back_inserter( aDestination ));
370 : SAL_WARN_IF( aDestination.empty(), "xmloff.chart", "aDestination is NULL");
371 : }
372 : SAL_WARN_IF( nDestinationIndex >= aDestination.size(), "xmloff.chart", "nDestinationIndex >= aDestination.size()");
373 0 : aDestination[ nDestinationIndex ] = mrTable.aData[ nSourceIndex ];
374 0 : bModified = true;
375 : }
376 : }
377 0 : if( bModified )
378 : {
379 : // copy back
380 0 : ::std::copy( aDestination.begin(), aDestination.end(), mrTable.aData.begin());
381 0 : }
382 : }
383 : }
384 :
385 0 : void SchXMLTableContext::setRowPermutation( const uno::Sequence< sal_Int32 > & rPermutation )
386 : {
387 0 : maRowPermutation = rPermutation;
388 0 : mbHasRowPermutation = ( rPermutation.getLength() > 0 );
389 :
390 0 : if( mbHasRowPermutation && mbHasColumnPermutation )
391 : {
392 0 : mbHasColumnPermutation = false;
393 0 : maColumnPermutation.realloc( 0 );
394 : }
395 0 : }
396 :
397 0 : void SchXMLTableContext::setColumnPermutation( const uno::Sequence< sal_Int32 > & rPermutation )
398 : {
399 0 : maColumnPermutation = rPermutation;
400 0 : mbHasColumnPermutation = ( rPermutation.getLength() > 0 );
401 :
402 0 : if( mbHasColumnPermutation && mbHasRowPermutation )
403 : {
404 0 : mbHasRowPermutation = false;
405 0 : maRowPermutation.realloc( 0 );
406 : }
407 0 : }
408 :
409 : // classes for columns
410 : // class SchXMLTableColumnsContext
411 172 : SchXMLTableColumnsContext::SchXMLTableColumnsContext(
412 : SvXMLImport& rImport,
413 : const OUString& rLocalName,
414 : SchXMLTable& aTable ) :
415 : SvXMLImportContext( rImport, XML_NAMESPACE_TABLE, rLocalName ),
416 172 : mrTable( aTable )
417 : {
418 172 : }
419 :
420 344 : SchXMLTableColumnsContext::~SchXMLTableColumnsContext()
421 : {
422 344 : }
423 :
424 172 : SvXMLImportContext* SchXMLTableColumnsContext::CreateChildContext(
425 : sal_uInt16 nPrefix,
426 : const OUString& rLocalName,
427 : const uno::Reference< xml::sax::XAttributeList >& )
428 : {
429 172 : SvXMLImportContext* pContext = 0;
430 :
431 344 : if( nPrefix == XML_NAMESPACE_TABLE &&
432 172 : IsXMLToken( rLocalName, XML_TABLE_COLUMN ) )
433 : {
434 172 : pContext = new SchXMLTableColumnContext( GetImport(), rLocalName, mrTable );
435 : }
436 : else
437 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
438 :
439 172 : return pContext;
440 : }
441 :
442 : // class SchXMLTableColumnContext
443 172 : SchXMLTableColumnContext::SchXMLTableColumnContext(
444 : SvXMLImport& rImport,
445 : const OUString& rLocalName,
446 : SchXMLTable& aTable ) :
447 : SvXMLImportContext( rImport, XML_NAMESPACE_TABLE, rLocalName ),
448 172 : mrTable( aTable )
449 : {
450 172 : }
451 :
452 172 : void SchXMLTableColumnContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
453 : {
454 : // get number-columns-repeated attribute
455 172 : sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
456 172 : sal_Int32 nRepeated = 1;
457 172 : bool bHidden = false;
458 :
459 233 : for( sal_Int16 i = 0; i < nAttrCount; i++ )
460 : {
461 61 : OUString sAttrName = xAttrList->getNameByIndex( i );
462 122 : OUString aLocalName;
463 61 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
464 :
465 122 : if( nPrefix == XML_NAMESPACE_TABLE &&
466 61 : IsXMLToken( aLocalName, XML_NUMBER_COLUMNS_REPEATED ) )
467 : {
468 61 : OUString aValue = xAttrList->getValueByIndex( i );
469 61 : if( !aValue.isEmpty())
470 61 : nRepeated = aValue.toInt32();
471 : }
472 0 : else if( nPrefix == XML_NAMESPACE_TABLE &&
473 0 : IsXMLToken( aLocalName, XML_VISIBILITY ) )
474 : {
475 0 : OUString aVisibility = xAttrList->getValueByIndex( i );
476 0 : bHidden = aVisibility.equals( GetXMLToken( XML_COLLAPSE ) );
477 : }
478 61 : }
479 :
480 172 : sal_Int32 nOldCount = mrTable.nNumberOfColsEstimate;
481 172 : sal_Int32 nNewCount = nOldCount + nRepeated;
482 172 : mrTable.nNumberOfColsEstimate = nNewCount;
483 :
484 172 : if( bHidden )
485 : {
486 : //i91578 display of hidden values (copy paste scenario; use hidden flag during migration to locale table upon paste )
487 0 : sal_Int32 nColOffset = ( mrTable.bHasHeaderColumn ? 1 : 0 );
488 0 : for( sal_Int32 nN = nOldCount; nN<nNewCount; nN++ )
489 : {
490 0 : sal_Int32 nHiddenColumnIndex = nN-nColOffset;
491 0 : if( nHiddenColumnIndex>=0 )
492 0 : mrTable.aHiddenColumns.push_back(nHiddenColumnIndex);
493 : }
494 : }
495 172 : }
496 :
497 344 : SchXMLTableColumnContext::~SchXMLTableColumnContext()
498 : {
499 344 : }
500 :
501 : // classes for rows
502 : // class SchXMLTableRowsContext
503 172 : SchXMLTableRowsContext::SchXMLTableRowsContext(
504 : SchXMLImportHelper& rImpHelper,
505 : SvXMLImport& rImport,
506 : const OUString& rLocalName,
507 : SchXMLTable& aTable ) :
508 : SvXMLImportContext( rImport, XML_NAMESPACE_TABLE, rLocalName ),
509 : mrImportHelper( rImpHelper ),
510 172 : mrTable( aTable )
511 : {
512 172 : }
513 :
514 344 : SchXMLTableRowsContext::~SchXMLTableRowsContext()
515 : {
516 344 : }
517 :
518 472 : SvXMLImportContext* SchXMLTableRowsContext::CreateChildContext(
519 : sal_uInt16 nPrefix,
520 : const OUString& rLocalName,
521 : const uno::Reference< xml::sax::XAttributeList >& )
522 : {
523 472 : SvXMLImportContext* pContext = 0;
524 :
525 944 : if( nPrefix == XML_NAMESPACE_TABLE &&
526 472 : IsXMLToken( rLocalName, XML_TABLE_ROW ) )
527 : {
528 472 : pContext = new SchXMLTableRowContext( mrImportHelper, GetImport(), rLocalName, mrTable );
529 : }
530 : else
531 : {
532 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
533 : }
534 :
535 472 : return pContext;
536 : }
537 :
538 : // class SchXMLTableRowContext
539 472 : SchXMLTableRowContext::SchXMLTableRowContext(
540 : SchXMLImportHelper& rImpHelper,
541 : SvXMLImport& rImport,
542 : const OUString& rLocalName,
543 : SchXMLTable& aTable ) :
544 : SvXMLImportContext( rImport, XML_NAMESPACE_TABLE, rLocalName ),
545 : mrImportHelper( rImpHelper ),
546 472 : mrTable( aTable )
547 : {
548 472 : mrTable.nColumnIndex = -1;
549 472 : mrTable.nRowIndex++;
550 :
551 472 : std::vector< SchXMLCell > aNewRow;
552 472 : aNewRow.reserve( mrTable.nNumberOfColsEstimate );
553 1416 : while( mrTable.aData.size() <= (unsigned long)mrTable.nRowIndex )
554 944 : mrTable.aData.push_back( aNewRow );
555 472 : }
556 :
557 944 : SchXMLTableRowContext::~SchXMLTableRowContext()
558 : {
559 944 : }
560 :
561 1516 : SvXMLImportContext* SchXMLTableRowContext::CreateChildContext(
562 : sal_uInt16 nPrefix,
563 : const OUString& rLocalName,
564 : const uno::Reference< xml::sax::XAttributeList >& )
565 : {
566 1516 : SvXMLImportContext* pContext = 0;
567 :
568 : // <table:table-cell> element
569 3032 : if( nPrefix == XML_NAMESPACE_TABLE &&
570 1516 : IsXMLToken(rLocalName, XML_TABLE_CELL ) )
571 : {
572 1516 : pContext = new SchXMLTableCellContext( mrImportHelper, GetImport(), rLocalName, mrTable );
573 : }
574 : else
575 : {
576 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
577 : }
578 :
579 1516 : return pContext;
580 : }
581 :
582 : class SchXMLRangeSomewhereContext : public SvXMLImportContext
583 : {
584 : //#i113950# previously the range was exported to attribute text:id,
585 : //but that attribute does not allow arbitrary strings anymore
586 : //so we need to find an alternative to save that range info for copy/paste scenario ...
587 : //-> use description at an empty group element for now
588 :
589 : private:
590 : OUString& mrRangeString;
591 : OUStringBuffer maRangeStringBuffer;
592 :
593 : public:
594 : SchXMLRangeSomewhereContext( SvXMLImport& rImport,
595 : sal_uInt16 nPrefix,
596 : const OUString& rLocalName,
597 : OUString& rRangeString );
598 : virtual ~SchXMLRangeSomewhereContext();
599 :
600 : virtual SvXMLImportContext* CreateChildContext(
601 : sal_uInt16 nPrefix,
602 : const OUString& rLocalName,
603 : const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttrList ) SAL_OVERRIDE;
604 : virtual void EndElement() SAL_OVERRIDE;
605 : };
606 :
607 : // classes for cells and their content
608 : // class SchXMLTableCellContext
609 1516 : SchXMLTableCellContext::SchXMLTableCellContext(
610 : SchXMLImportHelper& rImpHelper, SvXMLImport& rImport,
611 : const OUString& rLocalName, SchXMLTable& aTable)
612 : : SvXMLImportContext(rImport, XML_NAMESPACE_TABLE, rLocalName)
613 : , mrImportHelper(rImpHelper)
614 : , mrTable(aTable)
615 1516 : , mbReadText(false)
616 : {
617 1516 : }
618 :
619 3032 : SchXMLTableCellContext::~SchXMLTableCellContext()
620 : {
621 3032 : }
622 :
623 1516 : void SchXMLTableCellContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
624 : {
625 1516 : sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
626 1516 : OUString aValue;
627 3032 : OUString aLocalName;
628 3032 : OUString aCellContent;
629 1516 : SchXMLCellType eValueType = SCH_CELL_TYPE_UNKNOWN;
630 1516 : const SvXMLTokenMap& rAttrTokenMap = mrImportHelper.GetCellAttrTokenMap();
631 :
632 3797 : for( sal_Int16 i = 0; i < nAttrCount; i++ )
633 : {
634 2281 : OUString sAttrName = xAttrList->getNameByIndex( i );
635 2281 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
636 :
637 2281 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ))
638 : {
639 : case XML_TOK_CELL_VAL_TYPE:
640 1430 : aValue = xAttrList->getValueByIndex( i );
641 1430 : if( IsXMLToken( aValue, XML_FLOAT ) )
642 851 : eValueType = SCH_CELL_TYPE_FLOAT;
643 579 : else if( IsXMLToken( aValue, XML_STRING ) )
644 579 : eValueType = SCH_CELL_TYPE_STRING;
645 1430 : break;
646 :
647 : case XML_TOK_CELL_VALUE:
648 851 : aCellContent = xAttrList->getValueByIndex( i );
649 851 : break;
650 : }
651 2281 : }
652 :
653 1516 : mbReadText = true;
654 1516 : SchXMLCell aCell;
655 1516 : aCell.eType = eValueType;
656 :
657 1516 : if( eValueType == SCH_CELL_TYPE_FLOAT )
658 : {
659 : double fData;
660 : // the result may be false if a NaN is read, but that's ok
661 851 : ::sax::Converter::convertDouble( fData, aCellContent );
662 :
663 851 : aCell.fValue = fData;
664 : // dont read text from following <text:p> or <text:list> element
665 851 : mbReadText = false;
666 : }
667 :
668 1516 : mrTable.aData[ mrTable.nRowIndex ].push_back( aCell );
669 1516 : mrTable.nColumnIndex++;
670 1516 : if( mrTable.nMaxColumnIndex < mrTable.nColumnIndex )
671 1798 : mrTable.nMaxColumnIndex = mrTable.nColumnIndex;
672 1516 : }
673 :
674 1611 : SvXMLImportContext* SchXMLTableCellContext::CreateChildContext(
675 : sal_uInt16 nPrefix,
676 : const OUString& rLocalName,
677 : const uno::Reference< xml::sax::XAttributeList >& )
678 : {
679 1611 : SvXMLImportContext* pContext = 0;
680 :
681 : // <text:list> element
682 1611 : if( nPrefix == XML_NAMESPACE_TEXT && IsXMLToken( rLocalName, XML_LIST ) && mbReadText )
683 : {
684 0 : SchXMLCell& rCell = mrTable.aData[ mrTable.nRowIndex ][ mrTable.nColumnIndex ];
685 0 : rCell.aComplexString = Sequence< OUString >();
686 0 : rCell.eType = SCH_CELL_TYPE_COMPLEX_STRING;
687 0 : pContext = new SchXMLTextListContext( GetImport(), rLocalName, rCell.aComplexString );
688 0 : mbReadText = false;//don't apply text from <text:p>
689 : }
690 : // <text:p> element - read text (and range from text:id old version)
691 1716 : else if( (nPrefix == XML_NAMESPACE_TEXT ||
692 3117 : nPrefix == XML_NAMESPACE_LO_EXT) && IsXMLToken( rLocalName, XML_P ) )
693 : {
694 1506 : pContext = new SchXMLParagraphContext( GetImport(), rLocalName, maCellContent, &maRangeId );
695 : }
696 : // <draw:g> element - read range
697 105 : 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 105 : pContext = new SchXMLRangeSomewhereContext( GetImport(), nPrefix, rLocalName, maRangeId );
702 : }
703 : else
704 : {
705 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
706 : }
707 :
708 1611 : return pContext;
709 : }
710 :
711 1516 : void SchXMLTableCellContext::EndElement()
712 : {
713 1516 : if( mbReadText && !maCellContent.isEmpty() ) //apply text from <text:p> element
714 563 : mrTable.aData[ mrTable.nRowIndex ][ mrTable.nColumnIndex ].aString = maCellContent;
715 1516 : if( !maRangeId.isEmpty())
716 105 : mrTable.aData[ mrTable.nRowIndex ][ mrTable.nColumnIndex ].aRangeId = maRangeId;
717 1516 : }
718 :
719 354 : static void lcl_ApplyCellToComplexLabel( const SchXMLCell& rCell, Sequence< uno::Any >& rComplexLabel )
720 : {
721 354 : if( rCell.eType == SCH_CELL_TYPE_STRING )
722 : {
723 354 : rComplexLabel.realloc(1);
724 354 : 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 354 : }
739 :
740 50 : 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 50 : if( !xChartDoc.is() || !xChartDoc->hasInternalDataProvider() )
746 0 : return;
747 50 : Reference< chart2::data::XDataProvider > xDataProv( xChartDoc->getDataProvider() );
748 50 : if( !xDataProv.is() )
749 0 : return;
750 :
751 : //prepare the read local table data
752 50 : sal_Int32 nNumRows( static_cast< sal_Int32 >( rTable.aData.size()));
753 50 : sal_Int32 nRowOffset = 0;
754 50 : if( rTable.bHasHeaderRow )
755 : {
756 50 : --nNumRows;
757 50 : nRowOffset = 1;
758 : }
759 50 : sal_Int32 nNumColumns( rTable.nMaxColumnIndex + 1 );
760 50 : sal_Int32 nColOffset = 0;
761 50 : if( rTable.bHasHeaderColumn )
762 : {
763 50 : --nNumColumns;
764 50 : nColOffset = 1;
765 : }
766 :
767 100 : Sequence< Sequence< double > > aDataInRows( nNumRows );
768 100 : Sequence< Sequence< uno::Any > > aComplexRowDescriptions( nNumRows );
769 100 : Sequence< Sequence< uno::Any > > aComplexColumnDescriptions( nNumColumns );
770 278 : for( sal_Int32 i=0; i<nNumRows; ++i )
771 228 : aDataInRows[i].realloc( nNumColumns );
772 :
773 50 : if( rTable.aData.begin() != rTable.aData.end())
774 : {
775 : //apply column labels
776 50 : if( rTable.bHasHeaderRow )
777 : {
778 50 : const ::std::vector< SchXMLCell >& rFirstRow = rTable.aData.front();
779 50 : const sal_Int32 nColumnLabelsSize = aComplexColumnDescriptions.getLength();
780 50 : 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 176 : for( sal_Int32 i=0; i<nMax; ++i )
783 126 : lcl_ApplyCellToComplexLabel( rFirstRow[i+nColOffset], aComplexColumnDescriptions[i] );
784 : }
785 :
786 50 : std::vector< ::std::vector< SchXMLCell > >::const_iterator aRowIter( rTable.aData.begin() + nRowOffset );
787 50 : std::vector< ::std::vector< SchXMLCell > >::const_iterator aEnd( rTable.aData.end() );
788 278 : for( sal_Int32 nRow = 0; aRowIter != aEnd && nRow < nNumRows; ++aRowIter, ++nRow )
789 : {
790 228 : const ::std::vector< SchXMLCell >& rRow = *aRowIter;
791 228 : if( !rRow.empty() )
792 : {
793 : // row label
794 228 : if( rTable.bHasHeaderColumn )
795 228 : lcl_ApplyCellToComplexLabel( rRow.front(), aComplexRowDescriptions[nRow] );
796 :
797 : // values
798 228 : Sequence< double >& rTargetRow = aDataInRows[nRow];
799 228 : lcl_ApplyCellToData aApplyCellToData = ::std::for_each( rRow.begin() + nColOffset, rRow.end(), lcl_ApplyCellToData( rTargetRow ) );
800 228 : double fNaN = 0.0;
801 228 : ::rtl::math::setNan( &fNaN );
802 228 : 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 100 : Reference< chart2::XAnyDescriptionAccess > xDataAccess( xDataProv, uno::UNO_QUERY );
810 50 : if( !xDataAccess.is() )
811 0 : return;
812 :
813 50 : xDataAccess->setData( aDataInRows );
814 50 : if( rTable.bHasHeaderColumn )
815 50 : xDataAccess->setAnyRowDescriptions( aComplexRowDescriptions );
816 50 : if( rTable.bHasHeaderRow )
817 50 : xDataAccess->setAnyColumnDescriptions( aComplexColumnDescriptions );
818 :
819 50 : 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 50 : }
831 : }
832 :
833 49 : void SchXMLTableHelper::switchRangesFromOuterToInternalIfNecessary(
834 : const SchXMLTable& rTable,
835 : const tSchXMLLSequencesPerIndex & rLSequencesPerIndex,
836 : uno::Reference< chart2::XChartDocument > xChartDoc,
837 : chart::ChartDataRowSource eDataRowSource )
838 : {
839 49 : if( ! (xChartDoc.is() && xChartDoc->hasInternalDataProvider()))
840 49 : 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 49 : Reference< chart2::data::XDataProvider > xDataProv( xChartDoc->getDataProvider());
850 :
851 : // create a mapping from original ranges to new ranges
852 98 : lcl_tOriginalRangeToInternalRangeMap aRangeMap;
853 :
854 49 : lcl_fillRangeMapping( rTable, aRangeMap, eDataRowSource );
855 :
856 98 : const OUString lcl_aCategoriesRange(aCategoriesRange);
857 :
858 49 : bool bCategoriesApplied = false;
859 : // translate ranges (using the map created before)
860 1002 : for( tSchXMLLSequencesPerIndex::const_iterator aLSeqIt( rLSequencesPerIndex.begin());
861 668 : aLSeqIt != rLSequencesPerIndex.end(); ++aLSeqIt )
862 : {
863 285 : if( aLSeqIt->second.is())
864 : {
865 : // values/error bars/categories
866 398 : if( aLSeqIt->first.second == SCH_XML_PART_VALUES ||
867 113 : aLSeqIt->first.second == SCH_XML_PART_ERROR_BARS )
868 : {
869 172 : Reference< chart2::data::XDataSequence > xSeq( aLSeqIt->second->getValues());
870 :
871 344 : OUString aRange;
872 516 : if( xSeq.is() &&
873 344 : SchXMLTools::getXMLRangePropertyFromDataSequence( xSeq, aRange, /* bClearProp = */ true ) &&
874 172 : 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 172 : if( lcl_tableOfRangeMatches( aRange, rTable.aTableNameOfFile ))
888 : {
889 172 : if( aLSeqIt->first.first == SCH_XML_CATEGORIES_INDEX )
890 49 : bCategoriesApplied = true;
891 : }
892 : else
893 : {
894 0 : 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 0 : Reference< beans::XPropertySet > xOldSequenceProp( aLSeqIt->second->getValues(), uno::UNO_QUERY );
908 0 : OUString aRep( OUString::number( aLSeqIt->first.first ));
909 : Reference< chart2::data::XDataSequence > xNewSequence(
910 0 : xDataProv->createDataSequenceByRangeRepresentation( aRep ));
911 : SchXMLTools::copyProperties(
912 0 : xOldSequenceProp, Reference< beans::XPropertySet >( xNewSequence, uno::UNO_QUERY ));
913 0 : aLSeqIt->second->setValues( xNewSequence );
914 : }
915 : }
916 172 : }
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 113 : Reference< chart2::data::XDataSequence > xSeq( aLSeqIt->second->getLabel());
923 226 : OUString aRange;
924 336 : if( xSeq.is() &&
925 223 : SchXMLTools::getXMLRangePropertyFromDataSequence( xSeq, aRange, /* bClearProp = */ true ) &&
926 110 : 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 113 : else if( ! lcl_tableOfRangeMatches( aRange, rTable.aTableNameOfFile ))
938 : {
939 3 : OUString aRep("label ");
940 3 : aRep += OUString::number( aLSeqIt->first.first );
941 :
942 : Reference< chart2::data::XDataSequence > xNewSeq(
943 6 : xDataProv->createDataSequenceByRangeRepresentation( aRep ));
944 : SchXMLTools::copyProperties( Reference< beans::XPropertySet >( xSeq, uno::UNO_QUERY ),
945 3 : Reference< beans::XPropertySet >( xNewSeq, uno::UNO_QUERY ));
946 6 : aLSeqIt->second->setLabel( xNewSeq );
947 113 : }
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 49 : if( ! bCategoriesApplied )
956 : {
957 : SchXMLTools::CreateCategories(
958 : xDataProv, xChartDoc, OUString("categories"),
959 2 : 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 98 : Reference< chart2::XInternalDataProvider > xInternalDataProvider( xDataProv, uno::UNO_QUERY );
965 49 : 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 49 : }
1089 : }
1090 :
1091 105 : SchXMLRangeSomewhereContext::SchXMLRangeSomewhereContext( SvXMLImport& rImport,
1092 : sal_uInt16 nPrefix,
1093 : const OUString& rLocalName,
1094 : OUString& rRangeString ) :
1095 : SvXMLImportContext( rImport, nPrefix, rLocalName ),
1096 105 : mrRangeString( rRangeString )
1097 : {
1098 105 : }
1099 :
1100 210 : SchXMLRangeSomewhereContext::~SchXMLRangeSomewhereContext()
1101 : {
1102 210 : }
1103 :
1104 105 : SvXMLImportContext* SchXMLRangeSomewhereContext::CreateChildContext(
1105 : sal_uInt16 nPrefix,
1106 : const OUString& rLocalName,
1107 : const uno::Reference< xml::sax::XAttributeList >& )
1108 : {
1109 105 : if( XML_NAMESPACE_SVG == nPrefix && IsXMLToken( rLocalName, XML_DESC ) )
1110 : {
1111 : return new XMLStringBufferImportContext(
1112 105 : GetImport(), nPrefix, rLocalName, maRangeStringBuffer );
1113 : }
1114 0 : return new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
1115 : }
1116 :
1117 105 : void SchXMLRangeSomewhereContext::EndElement()
1118 : {
1119 105 : mrRangeString = maRangeStringBuffer.makeStringAndClear();
1120 105 : }
1121 :
1122 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|