Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "SchXMLSeries2Context.hxx"
31 : : #include "SchXMLPlotAreaContext.hxx"
32 : : #include "SchXMLSeriesHelper.hxx"
33 : : #include "SchXMLTools.hxx"
34 : : #include "PropertyMap.hxx"
35 : :
36 : : #include <com/sun/star/chart2/XChartDocument.hpp>
37 : : #include <com/sun/star/chart2/XDataSeries.hpp>
38 : : #include <com/sun/star/chart2/XRegressionCurve.hpp>
39 : : #include <com/sun/star/chart2/data/XDataSink.hpp>
40 : : #include <com/sun/star/chart2/data/XDataReceiver.hpp>
41 : :
42 : : #include <com/sun/star/chart/ChartAxisAssign.hpp>
43 : : #include <com/sun/star/chart/ChartSymbolType.hpp>
44 : : #include <com/sun/star/container/XChild.hpp>
45 : : #include <com/sun/star/chart/ChartLegendPosition.hpp>
46 : : #include <com/sun/star/drawing/LineStyle.hpp>
47 : : #include <com/sun/star/embed/Aspects.hpp>
48 : : #include <com/sun/star/embed/XVisualObject.hpp>
49 : : #include <com/sun/star/uno/XComponentContext.hpp>
50 : :
51 : : // header for define DBG_ERROR1
52 : : #include <tools/debug.hxx>
53 : : #include <rtl/ustrbuf.hxx>
54 : : #include "xmloff/xmlnmspe.hxx"
55 : : #include <xmloff/xmlimp.hxx>
56 : : #include <xmloff/nmspmap.hxx>
57 : : #include "SchXMLImport.hxx"
58 : : // header for class XMLPropStyleContext
59 : : #include <xmloff/prstylei.hxx>
60 : : #include <xmloff/xmlprmap.hxx>
61 : :
62 : : #include <typeinfo>
63 : :
64 : : using namespace ::com::sun::star;
65 : : using namespace ::xmloff::token;
66 : :
67 : : using ::com::sun::star::uno::Reference;
68 : : using ::com::sun::star::uno::Sequence;
69 : : using ::rtl::OUString;
70 : : using ::rtl::OUStringBuffer;
71 : :
72 : : // ================================================================================
73 : :
74 : : namespace
75 : : {
76 : :
77 : : class SchXMLDomain2Context : public SvXMLImportContext
78 : : {
79 : : private:
80 : : ::std::vector< OUString > & mrAddresses;
81 : :
82 : : public:
83 : : SchXMLDomain2Context( SvXMLImport& rImport,
84 : : sal_uInt16 nPrefix,
85 : : const rtl::OUString& rLocalName,
86 : : ::std::vector< OUString > & rAddresses );
87 : : virtual ~SchXMLDomain2Context();
88 : : virtual void StartElement( const Reference< xml::sax::XAttributeList >& xAttrList );
89 : : };
90 : :
91 : 0 : SchXMLDomain2Context::SchXMLDomain2Context(
92 : : SvXMLImport& rImport,
93 : : sal_uInt16 nPrefix,
94 : : const rtl::OUString& rLocalName,
95 : : ::std::vector< ::rtl::OUString > & rAddresses ) :
96 : : SvXMLImportContext( rImport, nPrefix, rLocalName ),
97 : 0 : mrAddresses( rAddresses )
98 : : {
99 : 0 : }
100 : :
101 : 0 : SchXMLDomain2Context::~SchXMLDomain2Context()
102 : : {
103 [ # # ]: 0 : }
104 : :
105 : 0 : void SchXMLDomain2Context::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
106 : : {
107 [ # # ]: 0 : sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
108 : :
109 [ # # ]: 0 : for( sal_Int16 i = 0; i < nAttrCount; i++ )
110 : : {
111 [ # # ][ # # ]: 0 : rtl::OUString sAttrName = xAttrList->getNameByIndex( i );
112 : 0 : rtl::OUString aLocalName;
113 [ # # ]: 0 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
114 : :
115 [ # # ][ # # ]: 0 : if( nPrefix == XML_NAMESPACE_TABLE &&
[ # # ]
116 [ # # ]: 0 : IsXMLToken( aLocalName, XML_CELL_RANGE_ADDRESS ) )
117 : : {
118 [ # # ]: 0 : Reference< chart2::XChartDocument > xNewDoc( GetImport().GetModel(), uno::UNO_QUERY );
119 [ # # ][ # # ]: 0 : mrAddresses.push_back( xAttrList->getValueByIndex( i ));
[ # # ]
120 : : }
121 : 0 : }
122 : 0 : }
123 : :
124 : 0 : void lcl_setAutomaticSymbolSize( const uno::Reference< beans::XPropertySet >& xSeriesOrPointProp, const SvXMLImport& rImport )
125 : : {
126 : 0 : awt::Size aSymbolSize(140,140);//old default for standard sized charts 7cm height
127 : :
128 [ # # ]: 0 : uno::Reference< chart::XChartDocument > xChartDoc( rImport.GetModel(), uno::UNO_QUERY );
129 [ # # ]: 0 : if( xChartDoc.is() )
130 : : {
131 : 0 : double fScale = 1;
132 [ # # ][ # # ]: 0 : uno::Reference< beans::XPropertySet > xLegendProp( xChartDoc->getLegend(), uno::UNO_QUERY );
[ # # ]
133 : 0 : chart::ChartLegendPosition aLegendPosition = chart::ChartLegendPosition_NONE;
134 [ # # ][ # # ]: 0 : if( xLegendProp.is() && (xLegendProp->getPropertyValue( OUString( "Alignment" )) >>= aLegendPosition)
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # # #
# # # # ]
[ # # ]
135 : : && chart::ChartLegendPosition_NONE != aLegendPosition )
136 : : {
137 : :
138 : 0 : double fFontHeight = 6.0;
139 [ # # ][ # # ]: 0 : if( xLegendProp->getPropertyValue( OUString( "CharHeight" )) >>= fFontHeight )
[ # # ]
140 : 0 : fScale = 0.75*fFontHeight/6.0;
141 : : }
142 : : else
143 : : {
144 [ # # ]: 0 : uno::Reference< embed::XVisualObject > xVisualObject( rImport.GetModel(), uno::UNO_QUERY );
145 [ # # ]: 0 : if( xVisualObject.is() )
146 : : {
147 [ # # ][ # # ]: 0 : awt::Size aPageSize( xVisualObject->getVisualAreaSize( embed::Aspects::MSOLE_CONTENT ) );
148 : 0 : fScale = aPageSize.Height/7000.0;
149 : 0 : }
150 : : }
151 [ # # ]: 0 : if( fScale>0 )
152 : : {
153 : 0 : aSymbolSize.Height = static_cast<sal_Int32>( fScale * aSymbolSize.Height );
154 : 0 : aSymbolSize.Width = aSymbolSize.Height;
155 : 0 : }
156 : : }
157 [ # # ][ # # ]: 0 : xSeriesOrPointProp->setPropertyValue(::rtl::OUString("SymbolSize"),uno::makeAny( aSymbolSize ));
[ # # ]
158 : 0 : }
159 : :
160 : 18 : void lcl_setSymbolSizeIfNeeded( const uno::Reference< beans::XPropertySet >& xSeriesOrPointProp, const SvXMLImport& rImport )
161 : : {
162 [ + - ]: 18 : if( !xSeriesOrPointProp.is() )
163 : 18 : return;
164 : :
165 : 18 : sal_Int32 nSymbolType = chart::ChartSymbolType::NONE;
166 [ + - ][ + - ]: 18 : if( xSeriesOrPointProp.is() && ( xSeriesOrPointProp->getPropertyValue(::rtl::OUString("SymbolType")) >>= nSymbolType) )
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + -
# # # # #
# ]
167 : : {
168 [ - + ]: 18 : if(chart::ChartSymbolType::NONE!=nSymbolType)
169 : : {
170 [ # # ]: 0 : if( chart::ChartSymbolType::BITMAPURL==nSymbolType )
171 : : {
172 : : //set special size for graphics to indicate to use the bitmap size itself
173 [ # # ][ # # ]: 0 : xSeriesOrPointProp->setPropertyValue(::rtl::OUString("SymbolSize"),uno::makeAny( awt::Size(-1,-1) ));
[ # # ]
174 : : }
175 : : else
176 : : {
177 [ # # ]: 18 : lcl_setAutomaticSymbolSize( xSeriesOrPointProp, rImport );
178 : : }
179 : : }
180 : : }
181 : : }
182 : :
183 : 0 : void lcl_resetSymbolSizeForPointsIfNecessary( const uno::Reference< beans::XPropertySet >& xPointProp, const SvXMLImport& rImport
184 : : , const XMLPropStyleContext * pPropStyleContext, const SvXMLStylesContext* pStylesCtxt )
185 : : {
186 [ # # ]: 0 : uno::Any aASymbolSize( SchXMLTools::getPropertyFromContext( ::rtl::OUString("SymbolSize"), pPropStyleContext, pStylesCtxt ) );
187 [ # # ]: 0 : if( !aASymbolSize.hasValue() )
188 [ # # ]: 0 : lcl_setSymbolSizeIfNeeded( xPointProp, rImport );
189 : 0 : }
190 : :
191 : 0 : void lcl_insertErrorBarLSequencesToMap(
192 : : tSchXMLLSequencesPerIndex & rInOutMap,
193 : : const uno::Reference< beans::XPropertySet > & xSeriesProp,
194 : : bool bYError = true )
195 : : {
196 : 0 : Reference< chart2::data::XDataSource > xErrorBarSource;
197 : : const OUString aPropName(
198 : : bYError
199 : : ? ::rtl::OUString( "ErrorBarY" )
200 [ # # ][ # # ]: 0 : : ::rtl::OUString( "ErrorBarX" ));
[ # # ]
201 [ # # ][ # # ]: 0 : if( ( xSeriesProp->getPropertyValue( aPropName ) >>= xErrorBarSource ) &&
[ # # ]
[ # # # # ]
[ # # ]
[ # # # # ]
202 : 0 : xErrorBarSource.is() )
203 : : {
204 : : Sequence< Reference< chart2::data::XLabeledDataSequence > > aLSequences(
205 [ # # ][ # # ]: 0 : xErrorBarSource->getDataSequences());
206 [ # # ]: 0 : for( sal_Int32 nIndex = 0; nIndex < aLSequences.getLength(); ++nIndex )
207 : : {
208 : : // use "0" as data index. This is ok, as it is not used for error bars
209 : : rInOutMap.insert(
210 : : tSchXMLLSequencesPerIndex::value_type(
211 [ # # ][ # # ]: 0 : tSchXMLIndexWithPart( 0, SCH_XML_PART_ERROR_BARS ), aLSequences[ nIndex ] ));
[ # # ][ # # ]
[ # # ]
212 [ # # ]: 0 : }
213 : 0 : }
214 : 0 : }
215 : :
216 : 0 : Reference< chart2::data::XLabeledDataSequence > lcl_createAndAddSequenceToSeries( const rtl::OUString& rRole
217 : : , const rtl::OUString& rRange
218 : : , const Reference< chart2::XChartDocument >& xChartDoc
219 : : , const Reference< chart2::XDataSeries >& xSeries )
220 : : {
221 : 0 : Reference< chart2::data::XLabeledDataSequence > xLabeledSeq;
222 : :
223 [ # # ]: 0 : Reference< chart2::data::XDataSource > xSeriesSource( xSeries,uno::UNO_QUERY );
224 [ # # ]: 0 : Reference< chart2::data::XDataSink > xSeriesSink( xSeries, uno::UNO_QUERY );
225 : :
226 [ # # ][ # # ]: 0 : if( !(!rRange.isEmpty() && xChartDoc.is() && xSeriesSource.is() && xSeriesSink.is()) )
[ # # ][ # # ]
[ # # ]
227 : : return xLabeledSeq;
228 : :
229 : : // create a new sequence
230 [ # # ][ # # ]: 0 : xLabeledSeq = SchXMLTools::GetNewLabeledDataSequence();
231 : :
232 : : // set values at the new sequence
233 [ # # ]: 0 : Reference< chart2::data::XDataSequence > xSeq = SchXMLTools::CreateDataSequence( rRange, xChartDoc );
234 [ # # ]: 0 : Reference< beans::XPropertySet > xSeqProp( xSeq, uno::UNO_QUERY );
235 [ # # ]: 0 : if( xSeqProp.is())
236 [ # # ][ # # ]: 0 : xSeqProp->setPropertyValue(OUString( "Role" ), uno::makeAny( rRole));
[ # # ]
237 [ # # ][ # # ]: 0 : xLabeledSeq->setValues( xSeq );
238 : :
239 : : // add new sequence to data series / push to front to have the correct sequence order if charttype is changed afterwards
240 [ # # ][ # # ]: 0 : Sequence< Reference< chart2::data::XLabeledDataSequence > > aOldSeq( xSeriesSource->getDataSequences());
241 : 0 : sal_Int32 nOldCount = aOldSeq.getLength();
242 [ # # ]: 0 : Sequence< Reference< chart2::data::XLabeledDataSequence > > aNewSeq( nOldCount + 1 );
243 [ # # ][ # # ]: 0 : aNewSeq[0]=xLabeledSeq;
244 [ # # ]: 0 : for( sal_Int32 nN=0; nN<nOldCount; nN++ )
245 [ # # ][ # # ]: 0 : aNewSeq[nN+1] = aOldSeq[nN];
[ # # ]
246 [ # # ][ # # ]: 0 : xSeriesSink->setData( aNewSeq );
247 : :
248 [ # # ][ # # ]: 0 : return xLabeledSeq;
249 : : }
250 : :
251 : : } // anonymous namespace
252 : :
253 : : // ================================================================================
254 : :
255 : 18 : SchXMLSeries2Context::SchXMLSeries2Context(
256 : : SchXMLImportHelper& rImpHelper,
257 : : SvXMLImport& rImport, const rtl::OUString& rLocalName,
258 : : const Reference< chart2::XChartDocument > & xNewDoc,
259 : : std::vector< SchXMLAxis >& rAxes,
260 : : ::std::list< DataRowPointStyle >& rStyleList,
261 : : sal_Int32 nSeriesIndex,
262 : : sal_Bool bStockHasVolume,
263 : : GlobalSeriesImportInfo& rGlobalSeriesImportInfo,
264 : : const OUString & aGlobalChartTypeName,
265 : : tSchXMLLSequencesPerIndex & rLSequencesPerIndex,
266 : : bool& rGlobalChartTypeUsedBySeries,
267 : : const awt::Size & rChartSize ) :
268 : : SvXMLImportContext( rImport, XML_NAMESPACE_CHART, rLocalName ),
269 : : mrImportHelper( rImpHelper ),
270 : : mxNewDoc( xNewDoc ),
271 : : mrAxes( rAxes ),
272 : : mrStyleList( rStyleList ),
273 : : m_xSeries(0),
274 : : mnSeriesIndex( nSeriesIndex ),
275 : : mnDataPointIndex( 0 ),
276 : : m_bStockHasVolume( bStockHasVolume ),
277 : : m_rGlobalSeriesImportInfo(rGlobalSeriesImportInfo),
278 : : mpAttachedAxis( NULL ),
279 : : maGlobalChartTypeName( aGlobalChartTypeName ),
280 : : maSeriesChartTypeName( aGlobalChartTypeName ),
281 : : m_bHasDomainContext(false),
282 : : mrLSequencesPerIndex( rLSequencesPerIndex ),
283 : : mrGlobalChartTypeUsedBySeries( rGlobalChartTypeUsedBySeries ),
284 : : mbSymbolSizeIsMissingInFile(false),
285 [ + - ][ + - ]: 18 : maChartSize( rChartSize )
[ + - ]
286 : : {
287 [ - + ]: 18 : if( 0 == aGlobalChartTypeName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.DonutChartType" ) ) )
288 : : {
289 : 0 : maSeriesChartTypeName = ::rtl::OUString("com.sun.star.chart2.PieChartType" );
290 : 0 : maGlobalChartTypeName = maSeriesChartTypeName;
291 : : }
292 : 18 : }
293 : :
294 : 18 : SchXMLSeries2Context::~SchXMLSeries2Context()
295 : : {
296 : : OSL_ASSERT( maPostponedSequences.empty());
297 [ - + ]: 36 : }
298 : :
299 : 18 : void SchXMLSeries2Context::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
300 : : {
301 : : // parse attributes
302 [ + - ]: 18 : sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
303 : 18 : const SvXMLTokenMap& rAttrTokenMap = mrImportHelper.GetSeriesAttrTokenMap();
304 : 18 : mnAttachedAxis = 1;
305 : :
306 : 18 : bool bHasRange = false;
307 : 18 : bool bHasLabelRange = false;
308 : :
309 [ + + ]: 72 : for( sal_Int16 i = 0; i < nAttrCount; i++ )
310 : : {
311 [ + - ][ + - ]: 54 : rtl::OUString sAttrName = xAttrList->getNameByIndex( i );
312 : 54 : rtl::OUString aLocalName;
313 [ + - ][ + - ]: 54 : rtl::OUString aValue = xAttrList->getValueByIndex( i );
314 [ + - ]: 54 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
315 : :
316 [ + - ][ + + : 54 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ))
- + - - ]
317 : : {
318 : : case XML_TOK_SERIES_CELL_RANGE:
319 : 18 : m_aSeriesRange = aValue;
320 : 18 : bHasRange = true;
321 : 18 : break;
322 : : case XML_TOK_SERIES_LABEL_ADDRESS:
323 : 18 : m_aSeriesLabelRange = aValue;
324 : 18 : bHasLabelRange = true;
325 : 18 : break;
326 : : case XML_TOK_SERIES_ATTACHED_AXIS:
327 : : {
328 : 0 : sal_Int32 nNumOfAxes = mrAxes.size();
329 [ # # ]: 0 : for( sal_Int32 nCurrent = 0; nCurrent < nNumOfAxes; nCurrent++ )
330 : : {
331 [ # # # # ]: 0 : if( aValue.equals( mrAxes[ nCurrent ].aName ) &&
[ # # ]
332 : 0 : mrAxes[ nCurrent ].eDimension == SCH_XML_AXIS_Y )
333 : : {
334 : 0 : mpAttachedAxis = &( mrAxes[ nCurrent ] );
335 : : }
336 : : }
337 : : }
338 : 0 : break;
339 : : case XML_TOK_SERIES_STYLE_NAME:
340 : 18 : msAutoStyleName = aValue;
341 : 18 : break;
342 : : case XML_TOK_SERIES_CHART_CLASS:
343 : : {
344 : 0 : OUString aClassName;
345 : : sal_uInt16 nClassPrefix =
346 : 0 : GetImport().GetNamespaceMap().GetKeyByAttrName(
347 [ # # ]: 0 : aValue, &aClassName );
348 [ # # ]: 0 : if( XML_NAMESPACE_CHART == nClassPrefix )
349 [ # # ]: 0 : maSeriesChartTypeName = SchXMLTools::GetChartTypeByClassName( aClassName, false /* bUseOldNames */ );
350 : :
351 [ # # ]: 0 : if( maSeriesChartTypeName.isEmpty())
352 : 0 : maSeriesChartTypeName = aClassName;
353 : : }
354 : 0 : break;
355 : : }
356 : 54 : }
357 : :
358 [ - + ]: 18 : if( mpAttachedAxis )
359 : : {
360 [ # # ]: 0 : if( mpAttachedAxis->nAxisIndex > 0 )
361 : : {
362 : : // secondary axis => property has to be set (primary is default)
363 : 0 : mnAttachedAxis = 2;
364 : : }
365 : : }
366 : :
367 : : try
368 : : {
369 : : OSL_ASSERT( mxNewDoc.is());
370 [ + - ][ - + ]: 18 : if( m_rGlobalSeriesImportInfo.rbAllRangeAddressesAvailable && ! bHasRange )
371 : 0 : m_rGlobalSeriesImportInfo.rbAllRangeAddressesAvailable = sal_False;
372 : :
373 : 18 : bool bIsCandleStick = maGlobalChartTypeName == "com.sun.star.chart2.CandleStickChartType";
374 [ + - ]: 18 : if( !maSeriesChartTypeName.isEmpty() )
375 : : {
376 : 18 : bIsCandleStick = maSeriesChartTypeName == "com.sun.star.chart2.CandleStickChartType";
377 : : }
378 : : else
379 : : {
380 [ # # ][ # # ]: 0 : if( bIsCandleStick
[ # # ]
381 : : && m_bStockHasVolume
382 : : && mnSeriesIndex == 0 )
383 : : {
384 : 0 : maSeriesChartTypeName = OUString( "com.sun.star.chart2.ColumnChartType" );
385 : 0 : bIsCandleStick = false;
386 : : }
387 : : else
388 : : {
389 : 0 : maSeriesChartTypeName = maGlobalChartTypeName;
390 : : }
391 : : }
392 [ + + ]: 18 : if( ! mrGlobalChartTypeUsedBySeries )
393 : 6 : mrGlobalChartTypeUsedBySeries = (maSeriesChartTypeName.equals( maGlobalChartTypeName ));
394 : 18 : sal_Int32 nCoordinateSystemIndex = 0;//so far we can only import one coordinate system
395 : : m_xSeries.set(
396 [ + - ][ + - ]: 18 : mrImportHelper.GetNewDataSeries( mxNewDoc, nCoordinateSystemIndex, maSeriesChartTypeName, ! mrGlobalChartTypeUsedBySeries ));
397 : : Reference< chart2::data::XLabeledDataSequence > xLabeledSeq(
398 [ + - ]: 18 : SchXMLTools::GetNewLabeledDataSequence());
399 : :
400 [ - + ]: 18 : if( bIsCandleStick )
401 : : {
402 : : // set default color for range-line to black (before applying styles)
403 [ # # ]: 0 : Reference< beans::XPropertySet > xSeriesProp( m_xSeries, uno::UNO_QUERY );
404 [ # # ]: 0 : if( xSeriesProp.is())
405 [ # # ]: 0 : xSeriesProp->setPropertyValue( ::rtl::OUString("Color"),
406 [ # # ][ # # ]: 0 : uno::makeAny( sal_Int32( 0x000000 ))); // black
407 : : }
408 [ - + ]: 18 : else if ( maSeriesChartTypeName == "com.sun.star.chart2.PieChartType" )
409 : : {
410 : : //@todo: this property should be saved
411 [ # # ]: 0 : Reference< beans::XPropertySet > xSeriesProp( m_xSeries, uno::UNO_QUERY );
412 [ # # ]: 0 : if( xSeriesProp.is())
413 [ # # ]: 0 : xSeriesProp->setPropertyValue( ::rtl::OUString("VaryColorsByPoint"),
414 [ # # ][ # # ]: 0 : uno::makeAny( true ));
415 : : }
416 : :
417 : : // values
418 : 18 : Reference< chart2::data::XDataSequence > xSeq;
419 [ + - ][ + - ]: 18 : if( bHasRange && !m_aSeriesRange.isEmpty() )
[ + - ]
420 [ + - ][ + - ]: 18 : xSeq = SchXMLTools::CreateDataSequence( m_aSeriesRange, mxNewDoc );
421 : :
422 [ + - ]: 18 : Reference< beans::XPropertySet > xSeqProp( xSeq, uno::UNO_QUERY );
423 [ + - ]: 18 : if( xSeqProp.is())
424 : : {
425 : 18 : OUString aMainRole("values-y");
426 [ - + ]: 18 : if ( maSeriesChartTypeName == "com.sun.star.chart2.BubbleChartType" )
427 : 0 : aMainRole = OUString( "values-size" );
428 [ + - ][ + - ]: 18 : xSeqProp->setPropertyValue(OUString( "Role" ), uno::makeAny( aMainRole ));
[ + - ]
429 : : }
430 [ + - ][ + - ]: 18 : xLabeledSeq->setValues( xSeq );
431 : :
432 : : // register for setting local data if external data provider is not present
433 : : maPostponedSequences.insert(
434 : : tSchXMLLSequencesPerIndex::value_type(
435 [ + - ][ + - ]: 18 : tSchXMLIndexWithPart( m_rGlobalSeriesImportInfo.nCurrentDataIndex, SCH_XML_PART_VALUES ), xLabeledSeq ));
[ + - ][ + - ]
436 : :
437 : : // label
438 [ + - ][ + - ]: 18 : if( bHasLabelRange && !m_aSeriesLabelRange.isEmpty() )
[ + - ]
439 : : {
440 : : Reference< chart2::data::XDataSequence > xLabelSequence =
441 [ + - ]: 18 : SchXMLTools::CreateDataSequence( m_aSeriesLabelRange, mxNewDoc );
442 [ + - ][ + - ]: 18 : xLabeledSeq->setLabel( xLabelSequence );
443 : : }
444 : :
445 : : // Note: Even if we have no label, we have to register the label
446 : : // for creation, because internal data always has labels. If
447 : : // they don't exist in the original, auto-generated labels are
448 : : // used for the internal data.
449 : : maPostponedSequences.insert(
450 : : tSchXMLLSequencesPerIndex::value_type(
451 [ + - ][ + - ]: 18 : tSchXMLIndexWithPart( m_rGlobalSeriesImportInfo.nCurrentDataIndex, SCH_XML_PART_LABEL ), xLabeledSeq ));
[ + - ][ + - ]
452 : :
453 : :
454 [ + - ]: 18 : Sequence< Reference< chart2::data::XLabeledDataSequence > > aSeq( &xLabeledSeq, 1 );
455 [ + - ]: 18 : Reference< chart2::data::XDataSink > xSink( m_xSeries, uno::UNO_QUERY_THROW );
456 [ + - ][ + - ]: 18 : xSink->setData( aSeq );
[ + - ][ # # ]
457 : : }
458 : 0 : catch( const uno::Exception & ex )
459 : : {
460 : : (void)ex; // avoid warning for pro build
461 : : OSL_FAIL( ::rtl::OUStringToOString(
462 : : ::rtl::OUString( "Exception caught. Type: " ) +
463 : : ::rtl::OUString::createFromAscii( typeid( ex ).name()) +
464 : : ::rtl::OUString( ", Message: " ) +
465 : : ex.Message, RTL_TEXTENCODING_ASCII_US ).getStr());
466 : : }
467 : :
468 : : //init mbSymbolSizeIsMissingInFile:
469 : : try
470 : : {
471 [ + - ]: 18 : if( !msAutoStyleName.isEmpty() )
472 : : {
473 : 18 : const SvXMLStylesContext* pStylesCtxt = mrImportHelper.GetAutoStylesContext();
474 [ + - ]: 18 : if( pStylesCtxt )
475 : : {
476 : : const SvXMLStyleContext* pStyle = pStylesCtxt->FindStyleChildContext(
477 [ + - ]: 18 : mrImportHelper.GetChartFamilyID(), msAutoStyleName );
478 : :
479 [ - + ]: 18 : const XMLPropStyleContext* pPropStyleContext = dynamic_cast< const XMLPropStyleContext * >( pStyle );
480 : :
481 : : uno::Any aASymbolSize( SchXMLTools::getPropertyFromContext( ::rtl::OUString("SymbolSize")
482 [ + - ][ # # ]: 18 : , pPropStyleContext, pStylesCtxt ) );
483 : 18 : mbSymbolSizeIsMissingInFile = !aASymbolSize.hasValue();
484 : : }
485 : : }
486 : : }
487 : 0 : catch( const uno::Exception & )
488 : : {
489 : : }
490 : 18 : }
491 : :
492 : 0 : struct DomainInfo
493 : : {
494 : 0 : DomainInfo( const rtl::OUString& rRole, const rtl::OUString& rRange, sal_Int32 nIndex )
495 : 0 : : aRole(rRole), aRange(rRange), nIndexForLocalData(nIndex)
496 : 0 : {}
497 : :
498 : : rtl::OUString aRole;
499 : : rtl::OUString aRange;
500 : : sal_Int32 nIndexForLocalData;
501 : : };
502 : :
503 : 18 : void SchXMLSeries2Context::EndElement()
504 : : {
505 : : // special handling for different chart types. This is necessary as the
506 : : // roles are not yet saved in the file format
507 : 18 : sal_Int32 nDomainCount = maDomainAddresses.size();
508 : 18 : bool bIsScatterChart = maSeriesChartTypeName == "com.sun.star.chart2.ScatterChartType";
509 : 18 : bool bIsBubbleChart = maSeriesChartTypeName == "com.sun.star.chart2.BubbleChartType";
510 : 18 : bool bDeleteSeries = false;
511 [ + - ]: 18 : std::vector< DomainInfo > aDomainInfos;
512 : :
513 : : //different handling for different chart types necessary
514 [ + - ][ - + ]: 18 : if( bIsScatterChart || ( nDomainCount==1 && !bIsBubbleChart ) )
[ # # ]
515 : : {
516 : 0 : DomainInfo aDomainInfo( OUString( "values-x" ), m_rGlobalSeriesImportInfo.aFirstFirstDomainAddress, m_rGlobalSeriesImportInfo.nFirstFirstDomainIndex ) ;
517 : 0 : bool bCreateXValues = true;
518 [ # # ]: 0 : if( !maDomainAddresses.empty() )
519 : : {
520 [ # # ]: 0 : if( m_rGlobalSeriesImportInfo.aFirstFirstDomainAddress.isEmpty() )
521 : : {
522 [ # # ]: 0 : m_rGlobalSeriesImportInfo.aFirstFirstDomainAddress = maDomainAddresses.front();
523 : 0 : m_rGlobalSeriesImportInfo.nFirstFirstDomainIndex = m_rGlobalSeriesImportInfo.nCurrentDataIndex;
524 : : }
525 [ # # ]: 0 : aDomainInfo.aRange = maDomainAddresses.front();
526 : 0 : aDomainInfo.nIndexForLocalData = m_rGlobalSeriesImportInfo.nCurrentDataIndex;
527 : 0 : m_rGlobalSeriesImportInfo.nCurrentDataIndex++;
528 : : }
529 [ # # ][ # # ]: 0 : else if( m_rGlobalSeriesImportInfo.aFirstFirstDomainAddress.isEmpty() && !m_bHasDomainContext && mnSeriesIndex==0 )
[ # # ][ # # ]
530 : : {
531 [ # # ][ # # ]: 0 : if( SchXMLTools::isDocumentGeneratedWithOpenOfficeOlderThan2_3( GetImport().GetModel() ) ) //wrong old chart files:
532 : : {
533 : : //for xy charts the first series needs to have a domain
534 : : //if this by error iss not the case the first series is taken s x values
535 : : //needed for wrong files created while having an addin (e.g. BoxPlot)
536 : 0 : m_rGlobalSeriesImportInfo.aFirstFirstDomainAddress = m_aSeriesRange;
537 : 0 : m_rGlobalSeriesImportInfo.nFirstFirstDomainIndex = m_rGlobalSeriesImportInfo.nCurrentDataIndex++;
538 : 0 : bDeleteSeries = true;
539 : 0 : bCreateXValues = false;//they will be created for the next series
540 : : }
541 : : }
542 [ # # ]: 0 : if( bCreateXValues )
543 [ # # ]: 0 : aDomainInfos.push_back( aDomainInfo );
544 : : }
545 [ - + ]: 18 : else if( bIsBubbleChart )
546 : : {
547 [ # # ]: 0 : if( nDomainCount>1 )
548 : : {
549 : 0 : DomainInfo aDomainInfo( OUString( "values-x" ), maDomainAddresses[1], m_rGlobalSeriesImportInfo.nCurrentDataIndex ) ;
550 [ # # ]: 0 : if( m_rGlobalSeriesImportInfo.aFirstSecondDomainAddress.isEmpty() )
551 : : {
552 : : //for bubble chart the second domain contains the x values which should become an index smaller than y values for own data table
553 : : //->so second first
554 : 0 : m_rGlobalSeriesImportInfo.aFirstSecondDomainAddress = maDomainAddresses[1];
555 : 0 : m_rGlobalSeriesImportInfo.nFirstSecondDomainIndex = m_rGlobalSeriesImportInfo.nCurrentDataIndex;
556 : : }
557 [ # # ]: 0 : aDomainInfos.push_back( aDomainInfo );
558 : 0 : m_rGlobalSeriesImportInfo.nCurrentDataIndex++;
559 : : }
560 [ # # ]: 0 : else if( !m_rGlobalSeriesImportInfo.aFirstSecondDomainAddress.isEmpty() )
561 : : {
562 : 0 : DomainInfo aDomainInfo( OUString( "values-x" ), m_rGlobalSeriesImportInfo.aFirstSecondDomainAddress, m_rGlobalSeriesImportInfo.nFirstSecondDomainIndex ) ;
563 [ # # ]: 0 : aDomainInfos.push_back( aDomainInfo );
564 : : }
565 [ # # ]: 0 : if( nDomainCount>0)
566 : : {
567 [ # # ]: 0 : DomainInfo aDomainInfo( OUString( "values-y" ), maDomainAddresses.front(), m_rGlobalSeriesImportInfo.nCurrentDataIndex ) ;
568 [ # # ]: 0 : if( m_rGlobalSeriesImportInfo.aFirstFirstDomainAddress.isEmpty() )
569 : : {
570 [ # # ]: 0 : m_rGlobalSeriesImportInfo.aFirstFirstDomainAddress = maDomainAddresses.front();
571 : 0 : m_rGlobalSeriesImportInfo.nFirstFirstDomainIndex = m_rGlobalSeriesImportInfo.nCurrentDataIndex;
572 : : }
573 [ # # ]: 0 : aDomainInfos.push_back( aDomainInfo );
574 : 0 : m_rGlobalSeriesImportInfo.nCurrentDataIndex++;
575 : : }
576 [ # # ]: 0 : else if( !m_rGlobalSeriesImportInfo.aFirstFirstDomainAddress.isEmpty() )
577 : : {
578 : 0 : DomainInfo aDomainInfo( OUString("values-y"), m_rGlobalSeriesImportInfo.aFirstFirstDomainAddress, m_rGlobalSeriesImportInfo.nFirstFirstDomainIndex ) ;
579 [ # # ]: 0 : aDomainInfos.push_back( aDomainInfo );
580 : : }
581 : : }
582 : :
583 [ - + ]: 18 : if( bDeleteSeries )
584 : : {
585 : : //delete created series
586 : : SchXMLImportHelper::DeleteDataSeries(
587 [ # # ][ # # ]: 0 : m_xSeries, Reference< chart2::XChartDocument >( GetImport().GetModel(), uno::UNO_QUERY ) );
588 : : }
589 : : else
590 : : {
591 : : //add style
592 [ - + ][ # # ]: 18 : if( !msAutoStyleName.isEmpty() || mnAttachedAxis != 1 )
[ + - ]
593 : : {
594 : : DataRowPointStyle aStyle(
595 : : DataRowPointStyle::DATA_SERIES,
596 : : m_xSeries,
597 : : -1, 1,
598 [ + - ]: 18 : msAutoStyleName, mnAttachedAxis );
599 : 18 : aStyle.mbSymbolSizeForSeriesIsMissingInFile=mbSymbolSizeIsMissingInFile;
600 [ + - ][ + - ]: 18 : mrStyleList.push_back( aStyle );
601 : : }
602 : : }
603 : :
604 [ # # ][ + - ]: 18 : for( std::vector< DomainInfo >::reverse_iterator aIt( aDomainInfos.rbegin() ); aIt!= aDomainInfos.rend(); ++aIt )
[ - + ]
605 : : {
606 [ # # ]: 0 : DomainInfo aDomainInfo( *aIt );
607 : : Reference< chart2::data::XLabeledDataSequence > xLabeledSeq =
608 [ # # ]: 0 : lcl_createAndAddSequenceToSeries( aDomainInfo.aRole, aDomainInfo.aRange, mxNewDoc, m_xSeries );
609 [ # # ]: 0 : if( xLabeledSeq.is() )
610 : : {
611 : : // register for setting local data if external data provider is not present
612 : : mrLSequencesPerIndex.insert(
613 : : tSchXMLLSequencesPerIndex::value_type(
614 [ # # ][ # # ]: 0 : tSchXMLIndexWithPart( aDomainInfo.nIndexForLocalData, SCH_XML_PART_VALUES ), xLabeledSeq ));
[ # # ][ # # ]
615 : : }
616 : 0 : }
617 : :
618 [ + - ]: 18 : if( !bDeleteSeries )
619 : : {
620 [ + + ]: 108 : for( tSchXMLLSequencesPerIndex::const_iterator aIt( maPostponedSequences.begin());
621 : 54 : aIt != maPostponedSequences.end(); ++aIt )
622 : : {
623 : 36 : sal_Int32 nNewIndex = aIt->first.first + nDomainCount;
624 : : mrLSequencesPerIndex.insert(
625 : : tSchXMLLSequencesPerIndex::value_type(
626 [ + - ][ + - ]: 36 : tSchXMLIndexWithPart( nNewIndex, aIt->first.second ), aIt->second ));
[ + - ][ + - ]
627 : : }
628 : 18 : m_rGlobalSeriesImportInfo.nCurrentDataIndex++;
629 : : }
630 : 18 : maPostponedSequences.clear();
631 : 18 : }
632 : :
633 : 18 : SvXMLImportContext* SchXMLSeries2Context::CreateChildContext(
634 : : sal_uInt16 nPrefix,
635 : : const rtl::OUString& rLocalName,
636 : : const uno::Reference< xml::sax::XAttributeList >& )
637 : : {
638 : 18 : SvXMLImportContext* pContext = 0;
639 : 18 : const SvXMLTokenMap& rTokenMap = mrImportHelper.GetSeriesElemTokenMap();
640 : :
641 [ - - - - : 18 : switch( rTokenMap.Get( nPrefix, rLocalName ))
+ - ]
642 : : {
643 : : case XML_TOK_SERIES_DOMAIN:
644 [ # # ]: 0 : if( m_xSeries.is())
645 : : {
646 : 0 : m_bHasDomainContext = true;
647 : : pContext = new SchXMLDomain2Context(
648 : 0 : GetImport(),
649 : : nPrefix, rLocalName,
650 [ # # ]: 0 : maDomainAddresses );
651 : : }
652 : 0 : break;
653 : :
654 : : case XML_TOK_SERIES_MEAN_VALUE_LINE:
655 : : pContext = new SchXMLStatisticsObjectContext(
656 : 0 : mrImportHelper, GetImport(),
657 : : nPrefix, rLocalName, msAutoStyleName,
658 : : mrStyleList, m_xSeries,
659 : : SchXMLStatisticsObjectContext::CONTEXT_TYPE_MEAN_VALUE_LINE,
660 [ # # ]: 0 : maChartSize );
661 : 0 : break;
662 : : case XML_TOK_SERIES_REGRESSION_CURVE:
663 : : pContext = new SchXMLStatisticsObjectContext(
664 : 0 : mrImportHelper, GetImport(),
665 : : nPrefix, rLocalName, msAutoStyleName,
666 : : mrStyleList, m_xSeries,
667 : : SchXMLStatisticsObjectContext::CONTEXT_TYPE_REGRESSION_CURVE,
668 [ # # ]: 0 : maChartSize );
669 : 0 : break;
670 : : case XML_TOK_SERIES_ERROR_INDICATOR:
671 : : pContext = new SchXMLStatisticsObjectContext(
672 : 0 : mrImportHelper, GetImport(),
673 : : nPrefix, rLocalName, msAutoStyleName,
674 : : mrStyleList, m_xSeries,
675 : : SchXMLStatisticsObjectContext::CONTEXT_TYPE_ERROR_INDICATOR,
676 [ # # ]: 0 : maChartSize );
677 : 0 : break;
678 : :
679 : : case XML_TOK_SERIES_DATA_POINT:
680 : 18 : pContext = new SchXMLDataPointContext( GetImport(), rLocalName,
681 [ + - ]: 18 : mrStyleList, m_xSeries, mnDataPointIndex, mbSymbolSizeIsMissingInFile );
682 : 18 : break;
683 : :
684 : : default:
685 [ # # ]: 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
686 : : }
687 : :
688 : 18 : return pContext;
689 : : }
690 : :
691 : : //static
692 : 6 : void SchXMLSeries2Context::initSeriesPropertySets( SeriesDefaultsAndStyles& rSeriesDefaultsAndStyles
693 : : , const uno::Reference< frame::XModel >& xChartModel )
694 : : {
695 : 6 : ::std::list< DataRowPointStyle >::iterator iStyle;
696 : :
697 : : // iterate over series first and remind propertysets in map
698 : : // new api <-> old api wrapper
699 [ + - ]: 6 : ::std::map< Reference< chart2::XDataSeries >, Reference< beans::XPropertySet > > aSeriesMap;
700 [ + + ]: 24 : for( iStyle = rSeriesDefaultsAndStyles.maSeriesStyleList.begin(); iStyle != rSeriesDefaultsAndStyles.maSeriesStyleList.end(); ++iStyle )
701 : : {
702 [ - + ]: 18 : if( iStyle->meType != DataRowPointStyle::DATA_SERIES )
703 : 0 : continue;
704 : :
705 [ + - ]: 18 : if( !iStyle->m_xOldAPISeries.is() )
706 [ + - ][ + - ]: 18 : iStyle->m_xOldAPISeries = SchXMLSeriesHelper::createOldAPISeriesPropertySet( iStyle->m_xSeries, xChartModel );
707 : :
708 [ + - ][ + - ]: 18 : aSeriesMap[iStyle->m_xSeries] = iStyle->m_xOldAPISeries;
709 : :
710 : : }
711 : :
712 : : //initialize m_xOldAPISeries for all other styles also
713 [ + + ]: 24 : for( iStyle = rSeriesDefaultsAndStyles.maSeriesStyleList.begin(); iStyle != rSeriesDefaultsAndStyles.maSeriesStyleList.end(); ++iStyle )
714 : : {
715 [ + - ]: 18 : if( iStyle->meType == DataRowPointStyle::DATA_SERIES )
716 : 18 : continue;
717 [ # # ][ # # ]: 0 : iStyle->m_xOldAPISeries = aSeriesMap[iStyle->m_xSeries];
718 : 6 : }
719 : 6 : }
720 : :
721 : : //static
722 : 6 : void SchXMLSeries2Context::setDefaultsToSeries( SeriesDefaultsAndStyles& rSeriesDefaultsAndStyles )
723 : : {
724 : 6 : ::std::list< DataRowPointStyle >::iterator iStyle;
725 : : // iterate over series
726 : : // call initSeriesPropertySets first
727 : :
728 [ + + ]: 24 : for( iStyle = rSeriesDefaultsAndStyles.maSeriesStyleList.begin(); iStyle != rSeriesDefaultsAndStyles.maSeriesStyleList.end(); ++iStyle )
729 : : {
730 [ - + ]: 18 : if( iStyle->meType != DataRowPointStyle::DATA_SERIES )
731 : 0 : continue;
732 : :
733 : : try
734 : : {
735 : 18 : uno::Reference< beans::XPropertySet > xSeries( iStyle->m_xOldAPISeries );
736 [ - + ]: 18 : if( !xSeries.is() )
737 : 0 : continue;
738 : :
739 [ + - ]: 18 : if( rSeriesDefaultsAndStyles.maSymbolTypeDefault.hasValue() )
740 [ + - ][ + - ]: 18 : xSeries->setPropertyValue(::rtl::OUString("SymbolType"),rSeriesDefaultsAndStyles.maSymbolTypeDefault);
741 [ + - ]: 18 : if( rSeriesDefaultsAndStyles.maDataCaptionDefault.hasValue() )
742 [ + - ][ + - ]: 18 : xSeries->setPropertyValue(::rtl::OUString("DataCaption"),rSeriesDefaultsAndStyles.maDataCaptionDefault);
743 : :
744 [ - + ]: 18 : if( rSeriesDefaultsAndStyles.maErrorIndicatorDefault.hasValue() )
745 [ # # ][ # # ]: 0 : xSeries->setPropertyValue(::rtl::OUString("ErrorIndicator"),rSeriesDefaultsAndStyles.maErrorIndicatorDefault);
746 [ - + ]: 18 : if( rSeriesDefaultsAndStyles.maErrorCategoryDefault.hasValue() )
747 [ # # ][ # # ]: 0 : xSeries->setPropertyValue(::rtl::OUString("ErrorCategory"),rSeriesDefaultsAndStyles.maErrorCategoryDefault);
748 [ - + ]: 18 : if( rSeriesDefaultsAndStyles.maConstantErrorLowDefault.hasValue() )
749 [ # # ][ # # ]: 0 : xSeries->setPropertyValue(::rtl::OUString("ConstantErrorLow"),rSeriesDefaultsAndStyles.maConstantErrorLowDefault);
750 [ - + ]: 18 : if( rSeriesDefaultsAndStyles.maConstantErrorHighDefault.hasValue() )
751 [ # # ][ # # ]: 0 : xSeries->setPropertyValue(::rtl::OUString("ConstantErrorHigh"),rSeriesDefaultsAndStyles.maConstantErrorHighDefault);
752 [ - + ]: 18 : if( rSeriesDefaultsAndStyles.maPercentageErrorDefault.hasValue() )
753 [ # # ][ # # ]: 0 : xSeries->setPropertyValue(::rtl::OUString("PercentageError"),rSeriesDefaultsAndStyles.maPercentageErrorDefault);
754 [ - + ]: 18 : if( rSeriesDefaultsAndStyles.maErrorMarginDefault.hasValue() )
755 [ # # ][ # # ]: 0 : xSeries->setPropertyValue(::rtl::OUString("ErrorMargin"),rSeriesDefaultsAndStyles.maErrorMarginDefault);
756 : :
757 [ + - ]: 18 : if( rSeriesDefaultsAndStyles.maMeanValueDefault.hasValue() )
758 [ + - ][ + - ]: 18 : xSeries->setPropertyValue(::rtl::OUString("MeanValue"),rSeriesDefaultsAndStyles.maMeanValueDefault);
759 [ + - ]: 18 : if( rSeriesDefaultsAndStyles.maRegressionCurvesDefault.hasValue() )
760 [ + - ][ + - ]: 18 : xSeries->setPropertyValue(::rtl::OUString("RegressionCurves"),rSeriesDefaultsAndStyles.maRegressionCurvesDefault);
[ + - ][ # # ]
761 : : }
762 [ # # ]: 0 : catch( uno::Exception & )
763 : : {
764 : : //end of series reached
765 : : }
766 : : }
767 : 6 : }
768 : :
769 : : //static
770 : 6 : void SchXMLSeries2Context::setStylesToSeries( SeriesDefaultsAndStyles& rSeriesDefaultsAndStyles
771 : : , const SvXMLStylesContext* pStylesCtxt
772 : : , const SvXMLStyleContext*& rpStyle
773 : : , ::rtl::OUString& rCurrStyleName
774 : : , SchXMLImportHelper& rImportHelper
775 : : , const SvXMLImport& rImport
776 : : , bool bIsStockChart
777 : : , tSchXMLLSequencesPerIndex & rInOutLSequencesPerIndex )
778 : : {
779 : 6 : ::std::list< DataRowPointStyle >::iterator iStyle;
780 : :
781 : : // iterate over series
782 [ + + ]: 24 : for( iStyle = rSeriesDefaultsAndStyles.maSeriesStyleList.begin(); iStyle != rSeriesDefaultsAndStyles.maSeriesStyleList.end(); ++iStyle )
783 : : {
784 [ + - ]: 18 : if( iStyle->meType == DataRowPointStyle::DATA_SERIES )
785 : : {
786 : : try
787 : : {
788 : 18 : uno::Reference< beans::XPropertySet > xSeriesProp( iStyle->m_xOldAPISeries );
789 [ - + ]: 18 : if( !xSeriesProp.is() )
790 : 0 : continue;
791 : :
792 [ - + ]: 18 : if( iStyle->mnAttachedAxis != 1 )
793 : : {
794 [ # # ]: 0 : xSeriesProp->setPropertyValue( rtl::OUString( "Axis" )
795 [ # # ][ # # ]: 0 : , uno::makeAny(chart::ChartAxisAssign::SECONDARY_Y) );
796 : : }
797 : :
798 [ + - ]: 18 : if( !(iStyle->msStyleName).isEmpty())
799 : : {
800 [ + - ]: 18 : if( ! rCurrStyleName.equals( iStyle->msStyleName ))
801 : : {
802 : 18 : rCurrStyleName = iStyle->msStyleName;
803 : : rpStyle = pStylesCtxt->FindStyleChildContext(
804 [ + - ]: 18 : rImportHelper.GetChartFamilyID(), rCurrStyleName );
805 : : }
806 : :
807 : : //set style to series
808 : : // note: SvXMLStyleContext::FillPropertySet is not const
809 : : XMLPropStyleContext * pPropStyleContext =
810 : : const_cast< XMLPropStyleContext * >(
811 [ - + ]: 18 : dynamic_cast< const XMLPropStyleContext * >( rpStyle ));
812 [ + - ]: 18 : if( pPropStyleContext )
813 : : {
814 : : // error bar style must be set before the other error
815 : : // bar properties (which may be alphabetically before
816 : : // this property)
817 : 18 : bool bHasErrorBarRangesFromData = false;
818 : : {
819 : 18 : const ::rtl::OUString aErrorBarStylePropName( "ErrorBarStyle");
820 : : uno::Any aErrorBarStyle(
821 [ + - ]: 18 : SchXMLTools::getPropertyFromContext( aErrorBarStylePropName, pPropStyleContext, pStylesCtxt ));
822 [ + - ]: 18 : if( aErrorBarStyle.hasValue())
823 : : {
824 [ + - ][ + - ]: 18 : xSeriesProp->setPropertyValue( aErrorBarStylePropName, aErrorBarStyle );
825 : 18 : sal_Int32 eEBStyle = chart::ErrorBarStyle::NONE;
826 : : bHasErrorBarRangesFromData =
827 : 18 : ( ( aErrorBarStyle >>= eEBStyle ) &&
828 [ - + ][ + - ]: 18 : eEBStyle == chart::ErrorBarStyle::FROM_DATA );
829 : 18 : }
830 : : }
831 : :
832 : : //don't set the style to the min max line series of a stock chart
833 : : //otherwise the min max line properties gets overwritten and the series becomes invisible typically
834 : 18 : bool bIsMinMaxSeries = false;
835 [ - + ]: 18 : if( bIsStockChart )
836 : : {
837 [ # # # # ]: 0 : if( SchXMLSeriesHelper::isCandleStickSeries( iStyle->m_xSeries
838 [ # # ]: 0 : , uno::Reference< frame::XModel >( rImportHelper.GetChartDocument(), uno::UNO_QUERY ) ) )
839 : 0 : bIsMinMaxSeries = true;
840 : : }
841 [ + - ]: 18 : if( !bIsMinMaxSeries )
842 : : {
843 [ + - ]: 18 : pPropStyleContext->FillPropertySet( xSeriesProp );
844 [ + - ]: 18 : if( iStyle->mbSymbolSizeForSeriesIsMissingInFile )
845 [ + - ]: 18 : lcl_setSymbolSizeIfNeeded( xSeriesProp, rImport );
846 [ - + ]: 18 : if( bHasErrorBarRangesFromData )
847 [ # # ]: 18 : lcl_insertErrorBarLSequencesToMap( rInOutLSequencesPerIndex, xSeriesProp );
848 : : }
849 : : }
850 [ + - ][ # # ]: 18 : }
851 : : }
852 [ # # ]: 0 : catch( const uno::Exception & rEx )
853 : : {
854 : : (void)rEx; // avoid warning for pro build
855 : : OSL_TRACE( "Exception caught during setting styles to series: %s",
856 : : OUStringToOString( rEx.Message, RTL_TEXTENCODING_ASCII_US ).getStr() );
857 : : }
858 : : }
859 : : }
860 : 6 : }
861 : :
862 : : // static
863 : 6 : void SchXMLSeries2Context::setStylesToStatisticsObjects( SeriesDefaultsAndStyles& rSeriesDefaultsAndStyles
864 : : , const SvXMLStylesContext* pStylesCtxt
865 : : , const SvXMLStyleContext*& rpStyle
866 : : , ::rtl::OUString& rCurrStyleName )
867 : : {
868 : 6 : ::std::list< DataRowPointStyle >::iterator iStyle;
869 : :
870 : : // iterate over regession etc
871 [ + + ]: 24 : for( iStyle = rSeriesDefaultsAndStyles.maSeriesStyleList.begin(); iStyle != rSeriesDefaultsAndStyles.maSeriesStyleList.end(); ++iStyle )
872 : : {
873 [ + - + - : 54 : if( iStyle->meType == DataRowPointStyle::REGRESSION ||
- + ][ - + ]
874 : 18 : iStyle->meType == DataRowPointStyle::ERROR_INDICATOR ||
875 : 18 : iStyle->meType == DataRowPointStyle::MEAN_VALUE )
876 : : {
877 [ # # ]: 0 : if ( iStyle->meType == DataRowPointStyle::ERROR_INDICATOR )
878 : : {
879 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xNewSeriesProp(iStyle->m_xSeries,uno::UNO_QUERY);
880 : :
881 [ # # ]: 0 : if (iStyle->m_xErrorXProperties.is())
882 [ # # ][ # # ]: 0 : xNewSeriesProp->setPropertyValue("ErrorBarX",uno::makeAny(iStyle->m_xErrorXProperties));
[ # # ]
883 : :
884 [ # # ]: 0 : if (iStyle->m_xErrorYProperties.is())
885 [ # # ][ # # ]: 0 : xNewSeriesProp->setPropertyValue("ErrorBarY",uno::makeAny(iStyle->m_xErrorYProperties));
[ # # ]
886 : : }
887 : :
888 : : try
889 : : {
890 : 0 : uno::Reference< beans::XPropertySet > xSeriesProp( iStyle->m_xOldAPISeries );
891 [ # # ]: 0 : if( !xSeriesProp.is() )
892 : 0 : continue;
893 : :
894 [ # # ]: 0 : if( !(iStyle->msStyleName).isEmpty())
895 : : {
896 [ # # ]: 0 : if( ! rCurrStyleName.equals( iStyle->msStyleName ))
897 : : {
898 : 0 : rCurrStyleName = iStyle->msStyleName;
899 : : rpStyle = pStylesCtxt->FindStyleChildContext(
900 [ # # ]: 0 : SchXMLImportHelper::GetChartFamilyID(), rCurrStyleName );
901 : : }
902 : :
903 : : // note: SvXMLStyleContext::FillPropertySet is not const
904 : : XMLPropStyleContext * pPropStyleContext =
905 : : const_cast< XMLPropStyleContext * >(
906 [ # # ]: 0 : dynamic_cast< const XMLPropStyleContext * >( rpStyle ));
907 [ # # ]: 0 : if( pPropStyleContext )
908 : : {
909 : 0 : Reference< beans::XPropertySet > xStatPropSet;
910 [ # # # # ]: 0 : switch( iStyle->meType )
911 : : {
912 : : case DataRowPointStyle::MEAN_VALUE:
913 [ # # ]: 0 : xSeriesProp->getPropertyValue(
914 [ # # ][ # # ]: 0 : OUString( "DataMeanValueProperties" )) >>= xStatPropSet;
915 : 0 : break;
916 : : case DataRowPointStyle::REGRESSION:
917 [ # # ]: 0 : xSeriesProp->getPropertyValue(
918 [ # # ][ # # ]: 0 : OUString( "DataRegressionProperties" )) >>= xStatPropSet;
919 : 0 : break;
920 : : case DataRowPointStyle::ERROR_INDICATOR:
921 [ # # ]: 0 : xSeriesProp->getPropertyValue(
922 [ # # ][ # # ]: 0 : OUString( "DataErrorProperties" )) >>= xStatPropSet;
923 : 0 : break;
924 : : default:
925 : 0 : break;
926 : : }
927 [ # # ]: 0 : if( xStatPropSet.is())
928 [ # # ]: 0 : pPropStyleContext->FillPropertySet( xStatPropSet );
929 : : }
930 : : }
931 : :
932 : : // set equation properties at a regression curve
933 : : // note: this must be done after setting the regression
934 : : // properties at the old API, otherwise the curve itself does
935 : : // not exist here
936 [ # # ][ # # ]: 0 : if( iStyle->meType == DataRowPointStyle::REGRESSION && iStyle->m_xEquationProperties.is())
[ # # ]
937 : : {
938 : : OSL_ASSERT( iStyle->m_xSeries.is());
939 [ # # ]: 0 : Reference< chart2::XRegressionCurve > xRegCurve( SchXMLTools::getRegressionCurve( iStyle->m_xSeries ));
940 [ # # ]: 0 : if( xRegCurve.is())
941 [ # # ][ # # ]: 0 : xRegCurve->setEquationProperties( iStyle->m_xEquationProperties );
942 [ # # ][ # # ]: 0 : }
943 : : }
944 [ # # ]: 0 : catch( const uno::Exception & rEx )
945 : : {
946 : : (void)rEx; // avoid warning for pro build
947 : : OSL_TRACE( "Exception caught during setting styles to series: %s",
948 : : OUStringToOString( rEx.Message, RTL_TEXTENCODING_ASCII_US ).getStr() );
949 : : }
950 : : }
951 : : }
952 : 6 : }
953 : :
954 : : //static
955 : 6 : void SchXMLSeries2Context::setStylesToDataPoints( SeriesDefaultsAndStyles& rSeriesDefaultsAndStyles
956 : : , const SvXMLStylesContext* pStylesCtxt
957 : : , const SvXMLStyleContext*& rpStyle
958 : : , ::rtl::OUString& rCurrStyleName
959 : : , SchXMLImportHelper& rImportHelper
960 : : , const SvXMLImport& rImport
961 : : , bool bIsStockChart, bool bIsDonutChart, bool bSwitchOffLinesForScatter )
962 : : {
963 : 6 : ::std::list< DataRowPointStyle >::iterator iStyle;
964 [ + + ]: 24 : for( iStyle = rSeriesDefaultsAndStyles.maSeriesStyleList.begin(); iStyle != rSeriesDefaultsAndStyles.maSeriesStyleList.end(); ++iStyle )
965 : : {
966 [ + - ]: 18 : if( iStyle->meType != DataRowPointStyle::DATA_POINT )
967 : 18 : continue;
968 : :
969 [ # # ]: 0 : if( iStyle->m_nPointIndex == -1 )
970 : 0 : continue;
971 : :
972 : : //ignore datapoint properties for stock charts
973 : : //... todo ...
974 [ # # ]: 0 : if( bIsStockChart )
975 : : {
976 [ # # ][ # # ]: 0 : if( SchXMLSeriesHelper::isCandleStickSeries( iStyle->m_xSeries, uno::Reference< frame::XModel >( rImportHelper.GetChartDocument(), uno::UNO_QUERY ) ) )
[ # # ]
977 : 0 : continue;
978 : : }
979 : :
980 : : // data point style
981 [ # # ]: 0 : for( sal_Int32 i = 0; i < iStyle->m_nPointRepeat; i++ )
982 : : {
983 : : try
984 : : {
985 : 0 : uno::Reference< beans::XPropertySet > xSeriesProp( iStyle->m_xOldAPISeries );
986 [ # # ]: 0 : if(!xSeriesProp.is())
987 : 0 : continue;
988 : :
989 : : uno::Reference< beans::XPropertySet > xPointProp(
990 : 0 : SchXMLSeriesHelper::createOldAPIDataPointPropertySet( iStyle->m_xSeries, iStyle->m_nPointIndex + i
991 [ # # # # ]: 0 : , uno::Reference< frame::XModel >( rImportHelper.GetChartDocument(), uno::UNO_QUERY ) ) );
992 : :
993 [ # # ]: 0 : if( !xPointProp.is() )
994 : 0 : continue;
995 : :
996 [ # # ]: 0 : if( bIsDonutChart )
997 : : {
998 : : //set special series styles for donut charts first
999 [ # # ]: 0 : if( !rCurrStyleName.equals( iStyle->msSeriesStyleNameForDonuts ) )
1000 : : {
1001 : 0 : rCurrStyleName = iStyle->msSeriesStyleNameForDonuts;
1002 : : rpStyle = pStylesCtxt->FindStyleChildContext(
1003 [ # # ]: 0 : rImportHelper.GetChartFamilyID(), rCurrStyleName );
1004 : : }
1005 : :
1006 : : // note: SvXMLStyleContext::FillPropertySet is not const
1007 : : XMLPropStyleContext * pPropStyleContext =
1008 : : const_cast< XMLPropStyleContext * >(
1009 [ # # ]: 0 : dynamic_cast< const XMLPropStyleContext * >( rpStyle ));
1010 [ # # ]: 0 : if( pPropStyleContext )
1011 [ # # ]: 0 : pPropStyleContext->FillPropertySet( xPointProp );
1012 : : }
1013 : :
1014 : : try
1015 : : {
1016 : : //need to set this explicitly here for old files as the new api does not support this property fully anymore
1017 [ # # ]: 0 : if( bSwitchOffLinesForScatter )
1018 [ # # ][ # # ]: 0 : xPointProp->setPropertyValue(::rtl::OUString("Lines"),uno::makeAny(sal_False));
[ # # ][ # # ]
1019 : : }
1020 [ # # ]: 0 : catch( const uno::Exception & )
1021 : : {
1022 : : }
1023 : :
1024 [ # # ]: 0 : if( !rCurrStyleName.equals( iStyle->msStyleName ) )
1025 : : {
1026 : 0 : rCurrStyleName = iStyle->msStyleName;
1027 : : rpStyle = pStylesCtxt->FindStyleChildContext(
1028 [ # # ]: 0 : rImportHelper.GetChartFamilyID(), rCurrStyleName );
1029 : : }
1030 : :
1031 : : // note: SvXMLStyleContext::FillPropertySet is not const
1032 : : XMLPropStyleContext * pPropStyleContext =
1033 : : const_cast< XMLPropStyleContext * >(
1034 [ # # ]: 0 : dynamic_cast< const XMLPropStyleContext * >( rpStyle ));
1035 [ # # ]: 0 : if( pPropStyleContext )
1036 : : {
1037 [ # # ]: 0 : pPropStyleContext->FillPropertySet( xPointProp );
1038 [ # # ]: 0 : if( iStyle->mbSymbolSizeForSeriesIsMissingInFile )
1039 [ # # ]: 0 : lcl_resetSymbolSizeForPointsIfNecessary( xPointProp, rImport, pPropStyleContext, pStylesCtxt );
1040 [ # # ][ # # ]: 0 : }
[ # # ]
1041 : : }
1042 [ # # ]: 0 : catch( const uno::Exception & rEx )
1043 : : {
1044 : : (void)rEx; // avoid warning for pro build
1045 : : OSL_TRACE( "Exception caught during setting styles to data points: %s",
1046 : : OUStringToOString( rEx.Message, RTL_TEXTENCODING_ASCII_US ).getStr() );
1047 : : }
1048 : : }
1049 : : } // styles iterator
1050 : 6 : }
1051 : :
1052 : : //static
1053 : 0 : void SchXMLSeries2Context::switchSeriesLinesOff( ::std::list< DataRowPointStyle >& rSeriesStyleList )
1054 : : {
1055 : 0 : ::std::list< DataRowPointStyle >::iterator iStyle;
1056 : : // iterate over series
1057 : :
1058 [ # # ]: 0 : for( iStyle = rSeriesStyleList.begin(); iStyle != rSeriesStyleList.end(); ++iStyle )
1059 : : {
1060 [ # # ]: 0 : if( iStyle->meType != DataRowPointStyle::DATA_SERIES )
1061 : 0 : continue;
1062 : :
1063 : : try
1064 : : {
1065 : 0 : uno::Reference< beans::XPropertySet > xSeries( iStyle->m_xOldAPISeries );
1066 [ # # ]: 0 : if( !xSeries.is() )
1067 : 0 : continue;
1068 : :
1069 [ # # ][ # # ]: 0 : xSeries->setPropertyValue(::rtl::OUString("Lines"),uno::makeAny(sal_False));
[ # # ][ # # ]
[ # # ]
1070 : : }
1071 [ # # ]: 0 : catch( uno::Exception & )
1072 : : {
1073 : : //end of series reached
1074 : : }
1075 : : }
1076 : 0 : }
1077 : :
1078 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|