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 "SchXMLPlotAreaContext.hxx"
23 : #include "SchXMLRegressionCurveObjectContext.hxx"
24 : #include "SchXMLImport.hxx"
25 : #include "SchXMLAxisContext.hxx"
26 : #include "SchXMLSeries2Context.hxx"
27 : #include "SchXMLTools.hxx"
28 : #include <tools/debug.hxx>
29 :
30 : #include <comphelper/processfactory.hxx>
31 : #include <xmloff/xmlnmspe.hxx>
32 : #include <xmloff/xmlement.hxx>
33 : #include <xmloff/nmspmap.hxx>
34 : #include <xmloff/xmluconv.hxx>
35 : #include <xmloff/prstylei.hxx>
36 : #include <xmloff/xmlstyle.hxx>
37 : #include "xexptran.hxx"
38 : #include <cppuhelper/implbase1.hxx>
39 :
40 : #include <com/sun/star/awt/Point.hpp>
41 : #include <com/sun/star/awt/Size.hpp>
42 : #include <com/sun/star/chart/ChartDataRowSource.hpp>
43 : #include <com/sun/star/chart/ChartErrorCategory.hpp>
44 : #include <com/sun/star/chart/ChartErrorIndicatorType.hpp>
45 : #include <com/sun/star/chart/ErrorBarStyle.hpp>
46 : #include <com/sun/star/chart/X3DDisplay.hpp>
47 : #include <com/sun/star/chart/XStatisticDisplay.hpp>
48 : #include <com/sun/star/chart/XDiagramPositioning.hpp>
49 : #include <com/sun/star/chart2/RelativePosition.hpp>
50 : #include <com/sun/star/chart2/XChartTypeContainer.hpp>
51 : #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
52 : #include <com/sun/star/chart2/data/XDataSink.hpp>
53 : #include <com/sun/star/chart2/data/XRangeXMLConversion.hpp>
54 : #include <com/sun/star/chart2/data/LabeledDataSequence.hpp>
55 : #include <com/sun/star/drawing/CameraGeometry.hpp>
56 : #include <com/sun/star/drawing/FillStyle.hpp>
57 : #include <com/sun/star/lang/XServiceInfo.hpp>
58 : #include <com/sun/star/util/XStringMapping.hpp>
59 : #include <com/sun/star/xml/sax/XAttributeList.hpp>
60 :
61 : using namespace com::sun::star;
62 : using namespace ::xmloff::token;
63 :
64 : using com::sun::star::uno::Reference;
65 :
66 : namespace
67 : {
68 :
69 : struct lcl_AxisHasCategories : public ::std::unary_function< SchXMLAxis, bool >
70 : {
71 145 : bool operator() ( const SchXMLAxis & rAxis )
72 : {
73 145 : return rAxis.bHasCategories;
74 : }
75 : };
76 :
77 35 : OUString lcl_ConvertRange( const OUString & rRange, const uno::Reference< chart2::XChartDocument > & xDoc )
78 : {
79 35 : OUString aResult = rRange;
80 35 : if(!xDoc.is())
81 0 : return aResult;
82 : uno::Reference< chart2::data::XRangeXMLConversion > xConversion(
83 70 : xDoc->getDataProvider(), uno::UNO_QUERY );
84 35 : if( xConversion.is())
85 35 : aResult = xConversion->convertRangeFromXML( rRange );
86 35 : return aResult;
87 : }
88 :
89 : } // anonymous namespace
90 :
91 83 : SchXML3DSceneAttributesHelper::SchXML3DSceneAttributesHelper( SvXMLImport& rImporter )
92 83 : : SdXML3DSceneAttributesHelper( rImporter )
93 : {
94 83 : }
95 :
96 83 : void SchXML3DSceneAttributesHelper::getCameraDefaultFromDiagram( const uno::Reference< chart::XDiagram >& xDiagram )
97 : {
98 : //different defaults for camera geometry necessary to workaround wrong behaviour in old chart
99 : //in future make this version dependent if we have versioning (metastream) for ole objects
100 :
101 : try
102 : {
103 83 : uno::Reference< beans::XPropertySet > xProp( xDiagram, uno::UNO_QUERY );
104 83 : if( xProp.is() )
105 : {
106 83 : drawing::CameraGeometry aCamGeo;
107 83 : xProp->getPropertyValue("D3DCameraGeometry") >>= aCamGeo;
108 83 : maVRP.setX( aCamGeo.vrp.PositionX );
109 83 : maVRP.setY( aCamGeo.vrp.PositionY );
110 83 : maVRP.setZ( aCamGeo.vrp.PositionZ );
111 83 : maVPN.setX( aCamGeo.vpn.DirectionX );
112 83 : maVPN.setY( aCamGeo.vpn.DirectionY );
113 83 : maVPN.setZ( aCamGeo.vpn.DirectionZ );
114 83 : maVUP.setX( aCamGeo.vup.DirectionX );
115 83 : maVUP.setY( aCamGeo.vup.DirectionY );
116 83 : maVUP.setZ( aCamGeo.vup.DirectionZ );
117 83 : }
118 : }
119 0 : catch( const uno::Exception & rEx )
120 : {
121 0 : OString aBStr(OUStringToOString(rEx.Message, RTL_TEXTENCODING_ASCII_US));
122 0 : SAL_INFO("xmloff.chart", "Exception caught for property NumberOfLines: " << aBStr);
123 : }
124 83 : }
125 :
126 83 : SchXML3DSceneAttributesHelper::~SchXML3DSceneAttributesHelper()
127 : {
128 83 : }
129 :
130 83 : SchXMLPlotAreaContext::SchXMLPlotAreaContext(
131 : SchXMLImportHelper& rImpHelper,
132 : SvXMLImport& rImport, const OUString& rLocalName,
133 : const OUString& rXLinkHRefAttributeToIndicateDataProvider,
134 : OUString& rCategoriesAddress,
135 : OUString& rChartAddress,
136 : bool& rbHasRangeAtPlotArea,
137 : sal_Bool & rAllRangeAddressesAvailable,
138 : sal_Bool & rColHasLabels,
139 : sal_Bool & rRowHasLabels,
140 : chart::ChartDataRowSource & rDataRowSource,
141 : SeriesDefaultsAndStyles& rSeriesDefaultsAndStyles,
142 : const OUString& aChartTypeServiceName,
143 : tSchXMLLSequencesPerIndex & rLSequencesPerIndex,
144 : const awt::Size & rChartSize ) :
145 : SvXMLImportContext( rImport, XML_NAMESPACE_CHART, rLocalName ),
146 : mrImportHelper( rImpHelper ),
147 : mrCategoriesAddress( rCategoriesAddress ),
148 : mrSeriesDefaultsAndStyles( rSeriesDefaultsAndStyles ),
149 : mnNumOfLinesProp( 0 ),
150 : mbStockHasVolume( sal_False ),
151 : mnSeries( 0 ),
152 : m_aGlobalSeriesImportInfo( rAllRangeAddressesAvailable ),
153 : maSceneImportHelper( rImport ),
154 : m_aOuterPositioning( rImport ),
155 : m_aInnerPositioning( rImport ),
156 : mbPercentStacked(false),
157 : m_bAxisPositionAttributeImported(false),
158 : m_rXLinkHRefAttributeToIndicateDataProvider(rXLinkHRefAttributeToIndicateDataProvider),
159 : mrChartAddress( rChartAddress ),
160 : m_rbHasRangeAtPlotArea( rbHasRangeAtPlotArea ),
161 : mrColHasLabels( rColHasLabels ),
162 : mrRowHasLabels( rRowHasLabels ),
163 : mrDataRowSource( rDataRowSource ),
164 : maChartTypeServiceName( aChartTypeServiceName ),
165 : mrLSequencesPerIndex( rLSequencesPerIndex ),
166 : mbGlobalChartTypeUsedBySeries( false ),
167 83 : maChartSize( rChartSize )
168 : {
169 83 : m_rbHasRangeAtPlotArea = false;
170 :
171 : // get Diagram
172 83 : uno::Reference< chart::XChartDocument > xDoc( rImpHelper.GetChartDocument(), uno::UNO_QUERY );
173 83 : if( xDoc.is())
174 : {
175 83 : mxDiagram = xDoc->getDiagram();
176 83 : mxNewDoc.set( xDoc, uno::UNO_QUERY );
177 :
178 83 : maSceneImportHelper.getCameraDefaultFromDiagram( mxDiagram );
179 : }
180 : SAL_WARN_IF( !mxDiagram.is(),"xmloff.chart", "Couldn't get XDiagram" );
181 :
182 : // turn off all axes initially
183 166 : uno::Any aFalseBool;
184 83 : aFalseBool <<= (sal_Bool)(sal_False);
185 :
186 166 : uno::Reference< lang::XServiceInfo > xInfo( mxDiagram, uno::UNO_QUERY );
187 166 : uno::Reference< beans::XPropertySet > xProp( mxDiagram, uno::UNO_QUERY );
188 166 : if( xInfo.is() &&
189 83 : xProp.is())
190 : {
191 : try
192 : {
193 83 : xProp->setPropertyValue(
194 83 : OUString( "HasXAxis" ), aFalseBool );
195 83 : xProp->setPropertyValue(
196 83 : OUString( "HasXAxisGrid" ), aFalseBool );
197 83 : xProp->setPropertyValue(
198 83 : OUString( "HasXAxisDescription" ), aFalseBool );
199 83 : xProp->setPropertyValue(
200 83 : OUString( "HasSecondaryXAxis" ), aFalseBool );
201 83 : xProp->setPropertyValue(
202 83 : OUString( "HasSecondaryXAxisDescription" ), aFalseBool );
203 :
204 83 : xProp->setPropertyValue(
205 83 : OUString( "HasYAxis" ), aFalseBool );
206 83 : xProp->setPropertyValue(
207 83 : OUString( "HasYAxisGrid" ), aFalseBool );
208 83 : xProp->setPropertyValue(
209 83 : OUString( "HasYAxisDescription" ), aFalseBool );
210 83 : xProp->setPropertyValue(
211 83 : OUString( "HasSecondaryYAxis" ), aFalseBool );
212 83 : xProp->setPropertyValue(
213 83 : OUString( "HasSecondaryYAxisDescription" ), aFalseBool );
214 :
215 83 : xProp->setPropertyValue(
216 83 : OUString( "HasZAxis" ), aFalseBool );
217 83 : xProp->setPropertyValue(
218 83 : OUString( "HasZAxisDescription" ), aFalseBool );
219 :
220 83 : uno::Any aAny;
221 83 : chart::ChartDataRowSource eSource = chart::ChartDataRowSource_COLUMNS;
222 83 : aAny <<= eSource;
223 83 : xProp->setPropertyValue("DataRowSource", aAny );
224 : }
225 0 : catch( const beans::UnknownPropertyException & )
226 : {
227 : SAL_WARN("xmloff.chart", "Property required by service not supported" );
228 : }
229 83 : }
230 83 : }
231 :
232 166 : SchXMLPlotAreaContext::~SchXMLPlotAreaContext()
233 166 : {}
234 :
235 83 : void SchXMLPlotAreaContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
236 : {
237 : // parse attributes
238 83 : sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
239 83 : const SvXMLTokenMap& rAttrTokenMap = mrImportHelper.GetPlotAreaAttrTokenMap();
240 83 : uno::Reference< chart2::XChartDocument > xNewDoc( GetImport().GetModel(), uno::UNO_QUERY );
241 :
242 892 : for( sal_Int16 i = 0; i < nAttrCount; i++ )
243 : {
244 809 : OUString sAttrName = xAttrList->getNameByIndex( i );
245 1618 : OUString aLocalName;
246 1618 : OUString aValue = xAttrList->getValueByIndex( i );
247 809 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
248 :
249 809 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ))
250 : {
251 : case XML_TOK_PA_X:
252 : case XML_TOK_PA_Y:
253 : case XML_TOK_PA_WIDTH:
254 : case XML_TOK_PA_HEIGHT:
255 332 : m_aOuterPositioning.readPositioningAttribute( nPrefix, aLocalName, aValue );
256 332 : break;
257 : case XML_TOK_PA_STYLE_NAME:
258 83 : msAutoStyleName = aValue;
259 83 : break;
260 : case XML_TOK_PA_CHART_ADDRESS:
261 29 : mrChartAddress = lcl_ConvertRange( aValue, xNewDoc );
262 : // indicator for getting data from the outside
263 29 : m_rbHasRangeAtPlotArea = true;
264 29 : break;
265 : case XML_TOK_PA_DS_HAS_LABELS:
266 : {
267 68 : if( aValue.equals( ::xmloff::token::GetXMLToken( ::xmloff::token::XML_BOTH )))
268 52 : mrColHasLabels = mrRowHasLabels = sal_True;
269 16 : else if( aValue.equals( ::xmloff::token::GetXMLToken( ::xmloff::token::XML_ROW )))
270 16 : mrRowHasLabels = sal_True;
271 0 : else if( aValue.equals( ::xmloff::token::GetXMLToken( ::xmloff::token::XML_COLUMN )))
272 0 : mrColHasLabels = sal_True;
273 : }
274 68 : break;
275 : case XML_TOK_PA_TRANSFORM:
276 : case XML_TOK_PA_VRP:
277 : case XML_TOK_PA_VPN:
278 : case XML_TOK_PA_VUP:
279 : case XML_TOK_PA_PROJECTION:
280 : case XML_TOK_PA_DISTANCE:
281 : case XML_TOK_PA_FOCAL_LENGTH:
282 : case XML_TOK_PA_SHADOW_SLANT:
283 : case XML_TOK_PA_SHADE_MODE:
284 : case XML_TOK_PA_AMBIENT_COLOR:
285 : case XML_TOK_PA_LIGHTING_MODE:
286 297 : maSceneImportHelper.processSceneAttribute( nPrefix, aLocalName, aValue );
287 297 : break;
288 : }
289 809 : }
290 :
291 83 : if( ! mxNewDoc.is())
292 : {
293 0 : uno::Reference< beans::XPropertySet > xDocProp( mrImportHelper.GetChartDocument(), uno::UNO_QUERY );
294 0 : if( xDocProp.is())
295 : {
296 : try
297 : {
298 0 : uno::Any aAny;
299 0 : aAny <<= (sal_Bool)(mrColHasLabels);
300 0 : xDocProp->setPropertyValue(
301 : OUString( "DataSourceLabelsInFirstColumn" ),
302 0 : aAny );
303 :
304 0 : aAny <<= (sal_Bool)(mrRowHasLabels);
305 0 : xDocProp->setPropertyValue(
306 : OUString( "DataSourceLabelsInFirstRow" ),
307 0 : aAny );
308 : }
309 0 : catch( const beans::UnknownPropertyException & )
310 : {
311 : SAL_WARN("xmloff.chart", "Properties missing" );
312 : }
313 0 : }
314 : }
315 :
316 : // set properties
317 83 : uno::Reference< beans::XPropertySet > xProp( mxDiagram, uno::UNO_QUERY );
318 83 : if( !msAutoStyleName.isEmpty())
319 : {
320 83 : if( xProp.is())
321 : {
322 83 : const SvXMLStylesContext* pStylesCtxt = mrImportHelper.GetAutoStylesContext();
323 83 : if( pStylesCtxt )
324 : {
325 : const SvXMLStyleContext* pStyle = pStylesCtxt->FindStyleChildContext(
326 83 : mrImportHelper.GetChartFamilyID(), msAutoStyleName );
327 :
328 : XMLPropStyleContext* pPropStyleContext =
329 : const_cast< XMLPropStyleContext * >(
330 83 : dynamic_cast< const XMLPropStyleContext * >( pStyle ) );
331 83 : if( pPropStyleContext )
332 : {
333 83 : pPropStyleContext->FillPropertySet( xProp );
334 :
335 : // get the data row source that was set without having data
336 83 : xProp->getPropertyValue("DataRowSource")
337 166 : >>= mrDataRowSource;
338 :
339 : //lines on/off
340 : //this old property is not supported fully anymore with the new chart, so we need to get the information a little bit different from similar properties
341 166 : mrSeriesDefaultsAndStyles.maLinesOnProperty = SchXMLTools::getPropertyFromContext(
342 83 : OUString("Lines"), pPropStyleContext, pStylesCtxt );
343 :
344 : //handle automatic position and size
345 83 : m_aOuterPositioning.readAutomaticPositioningProperties( pPropStyleContext, pStylesCtxt );
346 :
347 : //correct default starting angle for old 3D pies
348 83 : if( SchXMLTools::isDocumentGeneratedWithOpenOfficeOlderThan3_0( GetImport().GetModel() ) )
349 : {
350 0 : bool bIs3d = false;
351 0 : if( xProp.is() && ( xProp->getPropertyValue("Dim3D") >>= bIs3d ) &&
352 : bIs3d )
353 : {
354 0 : if( maChartTypeServiceName == "com.sun.star.chart2.PieChartType" || maChartTypeServiceName == "com.sun.star.chart2.DonutChartType" )
355 : {
356 0 : OUString aPropName( "StartingAngle" );
357 0 : uno::Any aAStartingAngle( SchXMLTools::getPropertyFromContext( aPropName, pPropStyleContext, pStylesCtxt ) );
358 0 : if( !aAStartingAngle.hasValue() )
359 0 : xProp->setPropertyValue( aPropName, uno::makeAny(sal_Int32(0)) ) ;
360 : }
361 : }
362 : }
363 : }
364 : }
365 : }
366 : }
367 :
368 : //remember default values for dataseries
369 83 : if(xProp.is())
370 : {
371 : try
372 : {
373 83 : mrSeriesDefaultsAndStyles.maSymbolTypeDefault = xProp->getPropertyValue("SymbolType");
374 83 : mrSeriesDefaultsAndStyles.maDataCaptionDefault = xProp->getPropertyValue("DataCaption");
375 :
376 83 : mrSeriesDefaultsAndStyles.maMeanValueDefault = xProp->getPropertyValue("MeanValue");
377 83 : mrSeriesDefaultsAndStyles.maRegressionCurvesDefault = xProp->getPropertyValue("RegressionCurves");
378 :
379 83 : bool bStacked = false;
380 83 : mrSeriesDefaultsAndStyles.maStackedDefault = xProp->getPropertyValue("Stacked");
381 83 : mrSeriesDefaultsAndStyles.maStackedDefault >>= bStacked;
382 83 : mrSeriesDefaultsAndStyles.maPercentDefault = xProp->getPropertyValue("Percent");
383 83 : mrSeriesDefaultsAndStyles.maPercentDefault >>= mbPercentStacked;
384 83 : mrSeriesDefaultsAndStyles.maStackedBarsConnectedDefault = xProp->getPropertyValue("StackedBarsConnected");
385 :
386 : // deep
387 83 : uno::Any aDeepProperty( xProp->getPropertyValue("Deep"));
388 : // #124488# old versions store a 3d area and 3D line deep chart with Deep==false => workaround for this
389 83 : if( ! (bStacked || mbPercentStacked ))
390 : {
391 68 : if( SchXMLTools::isDocumentGeneratedWithOpenOfficeOlderThan2_3( GetImport().GetModel() ) )
392 : {
393 0 : bool bIs3d = false;
394 0 : if( ( xProp->getPropertyValue("Dim3D") >>= bIs3d ) &&
395 : bIs3d )
396 : {
397 0 : if( maChartTypeServiceName == "com.sun.star.chart2.AreaChartType" || maChartTypeServiceName == "com.sun.star.chart2.LineChartType" )
398 : {
399 0 : aDeepProperty <<= uno::makeAny( true );
400 : }
401 : }
402 : }
403 : }
404 83 : mrSeriesDefaultsAndStyles.maDeepDefault = aDeepProperty;
405 :
406 83 : xProp->getPropertyValue("NumberOfLines") >>= mnNumOfLinesProp;
407 83 : xProp->getPropertyValue("Volume") >>= mbStockHasVolume;
408 : }
409 0 : catch( const uno::Exception & rEx )
410 : {
411 0 : OString aBStr(OUStringToOString(rEx.Message, RTL_TEXTENCODING_ASCII_US));
412 0 : SAL_INFO("xmloff.chart", "PlotAreaContext:EndElement(): Exception caught: " << aBStr);
413 : }
414 : } // if
415 :
416 83 : bool bCreateInternalDataProvider = false;
417 83 : if( m_rXLinkHRefAttributeToIndicateDataProvider == "." ) //data comes from the chart itself
418 51 : bCreateInternalDataProvider = true;
419 32 : else if( m_rXLinkHRefAttributeToIndicateDataProvider == ".." ) //data comes from the parent application
420 29 : bCreateInternalDataProvider = false;
421 3 : else if( !m_rXLinkHRefAttributeToIndicateDataProvider.isEmpty() ) //not supported so far to get the data by sibling objects -> fall back to chart itself
422 0 : bCreateInternalDataProvider = true;
423 3 : else if( !m_rbHasRangeAtPlotArea )
424 3 : bCreateInternalDataProvider = true;
425 :
426 83 : if( bCreateInternalDataProvider && mxNewDoc.is() )
427 : {
428 : // we have no complete range => we have own data, so switch the data
429 : // provider to internal. Clone is not necessary, as we don't have any
430 : // data yet.
431 54 : mxNewDoc->createInternalDataProvider( false /* bCloneExistingData */ );
432 54 : if( xProp.is() && mrDataRowSource!=chart::ChartDataRowSource_COLUMNS )
433 1 : xProp->setPropertyValue("DataRowSource", uno::makeAny(mrDataRowSource) );
434 83 : }
435 83 : }
436 :
437 843 : SvXMLImportContext* SchXMLPlotAreaContext::CreateChildContext(
438 : sal_uInt16 nPrefix,
439 : const OUString& rLocalName,
440 : const uno::Reference< xml::sax::XAttributeList >& xAttrList )
441 : {
442 843 : SvXMLImportContext* pContext = 0;
443 843 : const SvXMLTokenMap& rTokenMap = mrImportHelper.GetPlotAreaElemTokenMap();
444 :
445 843 : switch( rTokenMap.Get( nPrefix, rLocalName ))
446 : {
447 : case XML_TOK_PA_COORDINATE_REGION_EXT:
448 : case XML_TOK_PA_COORDINATE_REGION:
449 : {
450 79 : pContext = new SchXMLCoordinateRegionContext( GetImport(), nPrefix, rLocalName, m_aInnerPositioning );
451 : }
452 79 : break;
453 :
454 : case XML_TOK_PA_AXIS:
455 : {
456 201 : bool bAddMissingXAxisForNetCharts = false;
457 201 : bool bAdaptWrongPercentScaleValues = false;
458 201 : if( SchXMLTools::isDocumentGeneratedWithOpenOfficeOlderThan2_3( GetImport().GetModel() ) )
459 : {
460 : //correct errors from older versions
461 :
462 : // for NetCharts there were no xAxis exported to older files
463 : // so we need to add the x axis here for those old NetChart files
464 0 : if ( maChartTypeServiceName == "com.sun.star.chart2.NetChartType" )
465 0 : bAddMissingXAxisForNetCharts = true;
466 :
467 : //Issue 59288
468 0 : if( mbPercentStacked )
469 0 : bAdaptWrongPercentScaleValues = true;
470 : }
471 :
472 201 : bool bAdaptXAxisOrientationForOld2DBarCharts = false;
473 201 : if( SchXMLTools::isDocumentGeneratedWithOpenOfficeOlderThan2_4( GetImport().GetModel() ) )
474 : {
475 : //issue74660
476 0 : if ( maChartTypeServiceName == "com.sun.star.chart2.ColumnChartType" )
477 0 : bAdaptXAxisOrientationForOld2DBarCharts = true;
478 : }
479 :
480 201 : pContext = new SchXMLAxisContext( mrImportHelper, GetImport(), rLocalName, mxDiagram, maAxes, mrCategoriesAddress,
481 201 : bAddMissingXAxisForNetCharts, bAdaptWrongPercentScaleValues, bAdaptXAxisOrientationForOld2DBarCharts, m_bAxisPositionAttributeImported );
482 : }
483 201 : break;
484 :
485 : case XML_TOK_PA_SERIES:
486 : {
487 175 : if( mxNewDoc.is())
488 : {
489 : pContext = new SchXMLSeries2Context(
490 175 : mrImportHelper, GetImport(), rLocalName,
491 : mxNewDoc, maAxes,
492 : mrSeriesDefaultsAndStyles.maSeriesStyleList,
493 : mrSeriesDefaultsAndStyles.maRegressionStyleList,
494 : mnSeries,
495 : mbStockHasVolume,
496 : m_aGlobalSeriesImportInfo,
497 : maChartTypeServiceName,
498 : mrLSequencesPerIndex,
499 175 : mbGlobalChartTypeUsedBySeries, maChartSize );
500 : }
501 175 : mnSeries++;
502 : }
503 175 : break;
504 :
505 : case XML_TOK_PA_WALL:
506 83 : pContext = new SchXMLWallFloorContext( mrImportHelper, GetImport(), nPrefix, rLocalName, mxDiagram,
507 83 : SchXMLWallFloorContext::CONTEXT_TYPE_WALL );
508 83 : break;
509 : case XML_TOK_PA_FLOOR:
510 83 : pContext = new SchXMLWallFloorContext( mrImportHelper, GetImport(), nPrefix, rLocalName, mxDiagram,
511 83 : SchXMLWallFloorContext::CONTEXT_TYPE_FLOOR );
512 83 : break;
513 :
514 : case XML_TOK_PA_LIGHT_SOURCE:
515 216 : pContext = maSceneImportHelper.create3DLightContext( nPrefix, rLocalName, xAttrList );
516 216 : break;
517 :
518 : // elements for stock charts
519 : case XML_TOK_PA_STOCK_GAIN:
520 2 : pContext = new SchXMLStockContext( mrImportHelper, GetImport(), nPrefix, rLocalName, mxDiagram,
521 2 : SchXMLStockContext::CONTEXT_TYPE_GAIN );
522 2 : break;
523 : case XML_TOK_PA_STOCK_LOSS:
524 2 : pContext = new SchXMLStockContext( mrImportHelper, GetImport(), nPrefix, rLocalName, mxDiagram,
525 2 : SchXMLStockContext::CONTEXT_TYPE_LOSS );
526 2 : break;
527 : case XML_TOK_PA_STOCK_RANGE:
528 2 : pContext = new SchXMLStockContext( mrImportHelper, GetImport(), nPrefix, rLocalName, mxDiagram,
529 2 : SchXMLStockContext::CONTEXT_TYPE_RANGE );
530 2 : break;
531 :
532 : default:
533 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
534 : }
535 :
536 843 : return pContext;
537 : }
538 :
539 83 : void SchXMLPlotAreaContext::EndElement()
540 : {
541 : // set categories
542 83 : if( !mrCategoriesAddress.isEmpty() && mxNewDoc.is())
543 : {
544 : uno::Reference< chart2::data::XDataProvider > xDataProvider(
545 55 : mxNewDoc->getDataProvider() );
546 : // @todo: correct coordinate system index
547 55 : sal_Int32 nDimension( 0 );
548 : ::std::vector< SchXMLAxis >::const_iterator aIt(
549 55 : ::std::find_if( maAxes.begin(), maAxes.end(), lcl_AxisHasCategories()));
550 55 : if( aIt != maAxes.end())
551 0 : nDimension = static_cast< sal_Int32 >( (*aIt).eDimension );
552 : SchXMLTools::CreateCategories(
553 : xDataProvider, mxNewDoc, mrCategoriesAddress,
554 : 0 /* nCooSysIndex */,
555 55 : nDimension, &mrLSequencesPerIndex );
556 : }
557 :
558 83 : uno::Reference< beans::XPropertySet > xDiaProp( mxDiagram, uno::UNO_QUERY );
559 83 : if( xDiaProp.is())
560 : {
561 83 : sal_Bool bIsThreeDim = sal_False;
562 83 : uno::Any aAny = xDiaProp->getPropertyValue("Dim3D");
563 83 : aAny >>= bIsThreeDim;
564 :
565 : // set 3d scene attributes
566 83 : if( bIsThreeDim )
567 : {
568 : // set scene attributes at diagram
569 27 : maSceneImportHelper.setSceneAttributes( xDiaProp );
570 : }
571 :
572 : // set correct number of lines at series
573 83 : if( ! m_aGlobalSeriesImportInfo.rbAllRangeAddressesAvailable && mnNumOfLinesProp > 0 && maChartTypeServiceName == "com.sun.star.chart2.ColumnChartType" )
574 : {
575 : try
576 : {
577 0 : xDiaProp->setPropertyValue("NumberOfLines",
578 0 : uno::makeAny( mnNumOfLinesProp ));
579 : }
580 0 : catch( const uno::Exception & rEx )
581 : {
582 0 : OString aBStr(OUStringToOString(rEx.Message, RTL_TEXTENCODING_ASCII_US));
583 0 : SAL_INFO("xmloff.chart", "Exception caught for property NumberOfLines: " << aBStr);
584 : }
585 : }
586 :
587 : // #i32366# stock has volume
588 83 : if( mxDiagram->getDiagramType() == "com.sun.star.chart.StockDiagram" &&
589 : mbStockHasVolume )
590 : {
591 : try
592 : {
593 0 : xDiaProp->setPropertyValue("Volume",
594 0 : uno::makeAny( true ));
595 : }
596 0 : catch( const uno::Exception & rEx )
597 : {
598 0 : OString aBStr(OUStringToOString(rEx.Message, RTL_TEXTENCODING_ASCII_US));
599 0 : SAL_INFO("xmloff.chart", "Exception caught for property Volume: " << aBStr);
600 : }
601 83 : }
602 : }
603 :
604 : // set changed size and position after properties (esp. 3d)
605 :
606 166 : uno::Reference< chart::XDiagramPositioning > xDiaPos( mxDiagram, uno::UNO_QUERY );
607 83 : if( xDiaPos.is())
608 : {
609 83 : if( !m_aOuterPositioning.isAutomatic() )
610 : {
611 3 : if( m_aInnerPositioning.hasPosSize() )
612 0 : xDiaPos->setDiagramPositionExcludingAxes( m_aInnerPositioning.getRectangle() );
613 3 : else if( m_aOuterPositioning.hasPosSize() )
614 : {
615 3 : if( SchXMLTools::isDocumentGeneratedWithOpenOfficeOlderThan3_3( GetImport().GetModel() ) ) //old version of OOo did write a wrong rectangle for the diagram size
616 0 : xDiaPos->setDiagramPositionIncludingAxesAndAxisTitles( m_aOuterPositioning.getRectangle() );
617 : else
618 3 : xDiaPos->setDiagramPositionIncludingAxes( m_aOuterPositioning.getRectangle() );
619 : }
620 : }
621 : }
622 :
623 166 : SchXMLAxisContext::CorrectAxisPositions( uno::Reference< chart2::XChartDocument >( mrImportHelper.GetChartDocument(), uno::UNO_QUERY ), maChartTypeServiceName, GetImport().GetODFVersion(), m_bAxisPositionAttributeImported );
624 83 : }
625 :
626 210 : SchXMLDataPointContext::SchXMLDataPointContext( SvXMLImport& rImport, const OUString& rLocalName,
627 : ::std::list< DataRowPointStyle >& rStyleList,
628 : const ::com::sun::star::uno::Reference<
629 : ::com::sun::star::chart2::XDataSeries >& xSeries,
630 : sal_Int32& rIndex,
631 : bool bSymbolSizeForSeriesIsMissingInFile ) :
632 : SvXMLImportContext( rImport, XML_NAMESPACE_CHART, rLocalName ),
633 : mrStyleList( rStyleList ),
634 : m_xSeries( xSeries ),
635 : mrIndex( rIndex ),
636 210 : mbSymbolSizeForSeriesIsMissingInFile( bSymbolSizeForSeriesIsMissingInFile )
637 : {
638 210 : }
639 :
640 420 : SchXMLDataPointContext::~SchXMLDataPointContext()
641 : {
642 420 : }
643 :
644 210 : void SchXMLDataPointContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
645 : {
646 210 : sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
647 210 : OUString sAutoStyleName;
648 210 : sal_Int32 nRepeat = 1;
649 :
650 422 : for( sal_Int16 i = 0; i < nAttrCount; i++ )
651 : {
652 212 : OUString sAttrName = xAttrList->getNameByIndex( i );
653 424 : OUString aLocalName;
654 212 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
655 :
656 212 : if( nPrefix == XML_NAMESPACE_CHART )
657 : {
658 212 : if( IsXMLToken( aLocalName, XML_STYLE_NAME ) )
659 44 : sAutoStyleName = xAttrList->getValueByIndex( i );
660 168 : else if( IsXMLToken( aLocalName, XML_REPEATED ) )
661 168 : nRepeat = xAttrList->getValueByIndex( i ).toInt32();
662 : }
663 212 : }
664 :
665 210 : if( !sAutoStyleName.isEmpty())
666 : {
667 : DataRowPointStyle aStyle(
668 : DataRowPointStyle::DATA_POINT,
669 44 : m_xSeries, mrIndex, nRepeat, sAutoStyleName );
670 44 : aStyle.mbSymbolSizeForSeriesIsMissingInFile = mbSymbolSizeForSeriesIsMissingInFile;
671 44 : mrStyleList.push_back( aStyle );
672 : }
673 210 : mrIndex += nRepeat;
674 210 : }
675 :
676 166 : SchXMLPositonAttributesHelper::SchXMLPositonAttributesHelper( SvXMLImport& rImporter )
677 : : m_rImport( rImporter )
678 : , m_aPosition(0,0)
679 : , m_aSize(0,0)
680 : , m_bHasSizeWidth( false )
681 : , m_bHasSizeHeight( false )
682 : , m_bHasPositionX( false )
683 : , m_bHasPositionY( false )
684 : , m_bAutoSize( false )
685 166 : , m_bAutoPosition( false )
686 : {
687 166 : }
688 :
689 166 : SchXMLPositonAttributesHelper::~SchXMLPositonAttributesHelper()
690 : {
691 166 : }
692 :
693 3 : bool SchXMLPositonAttributesHelper::hasSize() const
694 : {
695 3 : return m_bHasSizeWidth && m_bHasSizeHeight;
696 : }
697 6 : bool SchXMLPositonAttributesHelper::hasPosition() const
698 : {
699 6 : return m_bHasPositionX && m_bHasPositionY;
700 : }
701 6 : bool SchXMLPositonAttributesHelper::hasPosSize() const
702 : {
703 6 : return hasPosition() && hasSize();
704 : }
705 83 : bool SchXMLPositonAttributesHelper::isAutomatic() const
706 : {
707 83 : return m_bAutoSize || m_bAutoPosition;
708 : }
709 3 : awt::Rectangle SchXMLPositonAttributesHelper::getRectangle() const
710 : {
711 3 : return awt::Rectangle( m_aPosition.X, m_aPosition.Y, m_aSize.Width, m_aSize.Height );
712 : }
713 :
714 648 : bool SchXMLPositonAttributesHelper::readPositioningAttribute( sal_uInt16 nPrefix, const OUString& rLocalName, const OUString& rValue )
715 : {
716 : //returns true if the attribute was proccessed
717 648 : bool bReturn = true;
718 :
719 648 : if( XML_NAMESPACE_SVG == nPrefix )
720 : {
721 648 : if( IsXMLToken( rLocalName, XML_X ) )
722 : {
723 162 : m_rImport.GetMM100UnitConverter().convertMeasureToCore(
724 324 : m_aPosition.X, rValue );
725 162 : m_bHasPositionX = true;
726 : }
727 486 : else if( IsXMLToken( rLocalName, XML_Y ) )
728 : {
729 162 : m_rImport.GetMM100UnitConverter().convertMeasureToCore(
730 324 : m_aPosition.Y, rValue );
731 162 : m_bHasPositionY = true;
732 : }
733 324 : else if( IsXMLToken( rLocalName, XML_WIDTH ) )
734 : {
735 162 : m_rImport.GetMM100UnitConverter().convertMeasureToCore(
736 324 : m_aSize.Width, rValue );
737 162 : m_bHasSizeWidth = true;
738 : }
739 162 : else if( IsXMLToken( rLocalName, XML_HEIGHT ) )
740 : {
741 162 : m_rImport.GetMM100UnitConverter().convertMeasureToCore(
742 324 : m_aSize.Height, rValue );
743 162 : m_bHasSizeHeight = true;
744 : }
745 : else
746 0 : bReturn = false;
747 : }
748 : else
749 0 : bReturn = false;
750 :
751 648 : return bReturn;
752 : }
753 :
754 83 : void SchXMLPositonAttributesHelper::readAutomaticPositioningProperties( XMLPropStyleContext* pPropStyleContext, const SvXMLStylesContext* pStylesCtxt )
755 : {
756 83 : if( pPropStyleContext && pStylesCtxt )
757 : {
758 : //handle automatic position and size
759 : SchXMLTools::getPropertyFromContext(
760 83 : OUString("AutomaticSize"), pPropStyleContext, pStylesCtxt ) >>= m_bAutoSize;
761 : SchXMLTools::getPropertyFromContext(
762 83 : OUString("AutomaticPosition"), pPropStyleContext, pStylesCtxt ) >>= m_bAutoPosition;
763 : }
764 83 : }
765 :
766 79 : SchXMLCoordinateRegionContext::SchXMLCoordinateRegionContext(
767 : SvXMLImport& rImport
768 : , sal_uInt16 nPrefix
769 : , const OUString& rLocalName
770 : , SchXMLPositonAttributesHelper& rPositioning )
771 : : SvXMLImportContext( rImport, nPrefix, rLocalName )
772 79 : , m_rPositioning( rPositioning )
773 : {
774 79 : }
775 :
776 158 : SchXMLCoordinateRegionContext::~SchXMLCoordinateRegionContext()
777 : {
778 158 : }
779 :
780 79 : void SchXMLCoordinateRegionContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
781 : {
782 : // parse attributes
783 79 : sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
784 :
785 395 : for( sal_Int16 i = 0; i < nAttrCount; i++ )
786 : {
787 316 : OUString sAttrName = xAttrList->getNameByIndex( i );
788 632 : OUString aLocalName;
789 632 : OUString aValue = xAttrList->getValueByIndex( i );
790 316 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
791 316 : m_rPositioning.readPositioningAttribute( nPrefix, aLocalName, aValue );
792 316 : }
793 79 : }
794 :
795 166 : SchXMLWallFloorContext::SchXMLWallFloorContext(
796 : SchXMLImportHelper& rImpHelper,
797 : SvXMLImport& rImport,
798 : sal_uInt16 nPrefix,
799 : const OUString& rLocalName,
800 : uno::Reference< chart::XDiagram >& xDiagram,
801 : ContextType eContextType ) :
802 : SvXMLImportContext( rImport, nPrefix, rLocalName ),
803 : mrImportHelper( rImpHelper ),
804 : mxWallFloorSupplier( xDiagram, uno::UNO_QUERY ),
805 166 : meContextType( eContextType )
806 : {
807 166 : }
808 :
809 332 : SchXMLWallFloorContext::~SchXMLWallFloorContext()
810 : {
811 332 : }
812 :
813 166 : void SchXMLWallFloorContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
814 : {
815 166 : if( mxWallFloorSupplier.is())
816 : {
817 166 : sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
818 166 : OUString sAutoStyleName;
819 :
820 332 : for( sal_Int16 i = 0; i < nAttrCount; i++ )
821 : {
822 166 : OUString sAttrName = xAttrList->getNameByIndex( i );
823 332 : OUString aLocalName;
824 166 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
825 :
826 332 : if( nPrefix == XML_NAMESPACE_CHART &&
827 166 : IsXMLToken( aLocalName, XML_STYLE_NAME ) )
828 : {
829 166 : sAutoStyleName = xAttrList->getValueByIndex( i );
830 : }
831 166 : }
832 :
833 : // set properties
834 166 : uno::Reference< beans::XPropertySet > xProp( ( meContextType == CONTEXT_TYPE_WALL )
835 83 : ? mxWallFloorSupplier->getWall()
836 83 : : mxWallFloorSupplier->getFloor(),
837 498 : uno::UNO_QUERY );
838 166 : if( xProp.is())
839 : {
840 166 : if( !sAutoStyleName.isEmpty())
841 : {
842 166 : const SvXMLStylesContext* pStylesCtxt = mrImportHelper.GetAutoStylesContext();
843 166 : if( pStylesCtxt )
844 : {
845 : const SvXMLStyleContext* pStyle = pStylesCtxt->FindStyleChildContext(
846 166 : mrImportHelper.GetChartFamilyID(), sAutoStyleName );
847 :
848 166 : if( pStyle && pStyle->ISA( XMLPropStyleContext ))
849 166 : (( XMLPropStyleContext* )pStyle )->FillPropertySet( xProp );
850 : }
851 : }
852 166 : }
853 : }
854 166 : }
855 :
856 6 : SchXMLStockContext::SchXMLStockContext(
857 : SchXMLImportHelper& rImpHelper,
858 : SvXMLImport& rImport,
859 : sal_uInt16 nPrefix,
860 : const OUString& rLocalName,
861 : uno::Reference< chart::XDiagram >& xDiagram,
862 : ContextType eContextType ) :
863 : SvXMLImportContext( rImport, nPrefix, rLocalName ),
864 : mrImportHelper( rImpHelper ),
865 : mxStockPropProvider( xDiagram, uno::UNO_QUERY ),
866 6 : meContextType( eContextType )
867 : {
868 6 : }
869 :
870 12 : SchXMLStockContext::~SchXMLStockContext()
871 : {
872 12 : }
873 :
874 6 : void SchXMLStockContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
875 : {
876 6 : if( mxStockPropProvider.is())
877 : {
878 6 : sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
879 6 : OUString sAutoStyleName;
880 :
881 12 : for( sal_Int16 i = 0; i < nAttrCount; i++ )
882 : {
883 6 : OUString sAttrName = xAttrList->getNameByIndex( i );
884 12 : OUString aLocalName;
885 6 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
886 :
887 12 : if( nPrefix == XML_NAMESPACE_CHART &&
888 6 : IsXMLToken( aLocalName, XML_STYLE_NAME ) )
889 : {
890 6 : sAutoStyleName = xAttrList->getValueByIndex( i );
891 : }
892 6 : }
893 :
894 6 : if( !sAutoStyleName.isEmpty())
895 : {
896 : // set properties
897 6 : uno::Reference< beans::XPropertySet > xProp;
898 6 : switch( meContextType )
899 : {
900 : case CONTEXT_TYPE_GAIN:
901 2 : xProp = mxStockPropProvider->getUpBar();
902 2 : break;
903 : case CONTEXT_TYPE_LOSS:
904 2 : xProp = mxStockPropProvider->getDownBar();
905 2 : break;
906 : case CONTEXT_TYPE_RANGE:
907 2 : xProp = mxStockPropProvider->getMinMaxLine();
908 2 : break;
909 : }
910 6 : if( xProp.is())
911 : {
912 6 : const SvXMLStylesContext* pStylesCtxt = mrImportHelper.GetAutoStylesContext();
913 6 : if( pStylesCtxt )
914 : {
915 : const SvXMLStyleContext* pStyle = pStylesCtxt->FindStyleChildContext(
916 6 : mrImportHelper.GetChartFamilyID(), sAutoStyleName );
917 :
918 6 : if( pStyle && pStyle->ISA( XMLPropStyleContext ))
919 6 : (( XMLPropStyleContext* )pStyle )->FillPropertySet( xProp );
920 : }
921 6 : }
922 6 : }
923 : }
924 6 : }
925 :
926 6 : static void lcl_setErrorBarSequence ( const uno::Reference< chart2::XChartDocument > &xDoc,
927 : const uno::Reference< beans::XPropertySet > &xBarProp,
928 : const OUString &aXMLRange,
929 : bool bPositiveValue, bool bYError,
930 : tSchXMLLSequencesPerIndex& rSequences)
931 : {
932 6 : uno::Reference< com::sun::star::chart2::data::XDataProvider > xDataProvider(xDoc->getDataProvider());
933 12 : uno::Reference< com::sun::star::chart2::data::XDataSource > xDataSource( xBarProp, uno::UNO_QUERY );
934 12 : uno::Reference< com::sun::star::chart2::data::XDataSink > xDataSink( xDataSource, uno::UNO_QUERY );
935 :
936 : assert( xDataSink.is() && xDataSource.is() && xDataProvider.is() );
937 :
938 12 : OUString aRange(lcl_ConvertRange(aXMLRange,xDoc));
939 :
940 : uno::Reference< chart2::data::XDataSequence > xNewSequence(
941 12 : xDataProvider->createDataSequenceByRangeRepresentation( aRange ));
942 :
943 6 : if( xNewSequence.is())
944 : {
945 6 : SchXMLTools::setXMLRangePropertyAtDataSequence(xNewSequence,aXMLRange);
946 :
947 6 : OUStringBuffer aRoleBuffer("error-bars-");
948 6 : if( bYError )
949 6 : aRoleBuffer.append( 'y' );
950 : else
951 0 : aRoleBuffer.append( 'x');
952 :
953 6 : aRoleBuffer.append( '-' );
954 :
955 6 : if( bPositiveValue )
956 3 : aRoleBuffer = aRoleBuffer.appendAscii( "positive" );
957 : else
958 3 : aRoleBuffer = aRoleBuffer.appendAscii( "negative" );
959 :
960 12 : OUString aRole = aRoleBuffer.makeStringAndClear();
961 :
962 12 : Reference< beans::XPropertySet > xSeqProp( xNewSequence, uno::UNO_QUERY );
963 :
964 6 : xSeqProp->setPropertyValue("Role", uno::makeAny( aRole ));
965 :
966 12 : Reference< uno::XComponentContext > xContext = comphelper::getProcessComponentContext();
967 :
968 : Reference< chart2::data::XLabeledDataSequence > xLabelSeq( chart2::data::LabeledDataSequence::create(xContext),
969 12 : uno::UNO_QUERY_THROW );
970 :
971 : rSequences.insert( tSchXMLLSequencesPerIndex::value_type(
972 6 : tSchXMLIndexWithPart( -2, SCH_XML_PART_ERROR_BARS ), xLabelSeq ) );
973 :
974 6 : xLabelSeq->setValues( xNewSequence );
975 :
976 : uno::Sequence< Reference< chart2::data::XLabeledDataSequence > > aSequences(
977 12 : xDataSource->getDataSequences());
978 :
979 6 : aSequences.realloc( aSequences.getLength() + 1 );
980 6 : aSequences[ aSequences.getLength() - 1 ] = xLabelSeq;
981 12 : xDataSink->setData( aSequences );
982 6 : }
983 6 : }
984 :
985 5 : SchXMLStatisticsObjectContext::SchXMLStatisticsObjectContext(
986 : SchXMLImportHelper& rImpHelper,
987 : SvXMLImport& rImport,
988 : sal_uInt16 nPrefix,
989 : const OUString& rLocalName,
990 : const OUString &rSeriesStyleName,
991 : ::std::list< DataRowPointStyle >& rStyleList,
992 : const ::com::sun::star::uno::Reference<
993 : ::com::sun::star::chart2::XDataSeries >& xSeries,
994 : ContextType eContextType,
995 : const awt::Size & rChartSize,
996 : tSchXMLLSequencesPerIndex & rLSequencesPerIndex) :
997 :
998 : SvXMLImportContext( rImport, nPrefix, rLocalName ),
999 : mrImportHelper( rImpHelper ),
1000 : mrStyleList( rStyleList ),
1001 : m_xSeries( xSeries ),
1002 : meContextType( eContextType ),
1003 : maChartSize( rChartSize ),
1004 : maSeriesStyleName( rSeriesStyleName),
1005 5 : mrLSequencesPerIndex(rLSequencesPerIndex)
1006 5 : {}
1007 :
1008 10 : SchXMLStatisticsObjectContext::~SchXMLStatisticsObjectContext()
1009 : {
1010 10 : }
1011 :
1012 : namespace {
1013 :
1014 10 : void SetErrorBarPropertiesFromStyleName( const OUString& aStyleName, uno::Reference< beans::XPropertySet> xBarProp,
1015 : SchXMLImportHelper& rImportHelper, OUString& aPosRange, OUString& aNegRange)
1016 : {
1017 10 : const SvXMLStylesContext* pStylesCtxt = rImportHelper.GetAutoStylesContext();
1018 10 : const SvXMLStyleContext* pStyle = pStylesCtxt->FindStyleChildContext(rImportHelper.GetChartFamilyID(),
1019 10 : aStyleName);
1020 :
1021 : XMLPropStyleContext * pSeriesStyleContext =
1022 10 : const_cast< XMLPropStyleContext * >( dynamic_cast< const XMLPropStyleContext * >( pStyle ));
1023 :
1024 : uno::Any aAny = SchXMLTools::getPropertyFromContext("ErrorBarStyle",
1025 10 : pSeriesStyleContext,pStylesCtxt);
1026 :
1027 10 : if ( aAny.hasValue() )
1028 : {
1029 10 : sal_Int32 aBarStyle = com::sun::star::chart::ErrorBarStyle::NONE;
1030 10 : aAny >>= aBarStyle;
1031 10 : xBarProp->setPropertyValue("ErrorBarStyle", aAny);
1032 :
1033 20 : aAny = SchXMLTools::getPropertyFromContext("ShowPositiveError",
1034 10 : pSeriesStyleContext,pStylesCtxt);
1035 :
1036 10 : if(aAny.hasValue())
1037 5 : xBarProp->setPropertyValue("ShowPositiveError",aAny);
1038 :
1039 20 : aAny = SchXMLTools::getPropertyFromContext("ShowNegativeError",
1040 10 : pSeriesStyleContext,pStylesCtxt);
1041 :
1042 10 : if(aAny.hasValue())
1043 5 : xBarProp->setPropertyValue("ShowNegativeError",aAny);
1044 :
1045 20 : aAny = SchXMLTools::getPropertyFromContext("PositiveError",
1046 10 : pSeriesStyleContext, pStylesCtxt);
1047 :
1048 10 : if(aAny.hasValue())
1049 0 : xBarProp->setPropertyValue("PositiveError", aAny);
1050 : else
1051 : {
1052 20 : aAny = SchXMLTools::getPropertyFromContext("ConstantErrorHigh",
1053 10 : pSeriesStyleContext, pStylesCtxt);
1054 :
1055 10 : if(aAny.hasValue())
1056 0 : xBarProp->setPropertyValue("PositiveError", aAny);
1057 : }
1058 :
1059 20 : aAny = SchXMLTools::getPropertyFromContext("NegativeError",
1060 10 : pSeriesStyleContext, pStylesCtxt);
1061 :
1062 10 : if(aAny.hasValue())
1063 0 : xBarProp->setPropertyValue("NegativeError", aAny);
1064 : else
1065 : {
1066 20 : aAny = SchXMLTools::getPropertyFromContext("ConstantErrorLow",
1067 10 : pSeriesStyleContext, pStylesCtxt);
1068 :
1069 10 : if(aAny.hasValue())
1070 0 : xBarProp->setPropertyValue("NegativeError", aAny);
1071 : }
1072 :
1073 20 : aAny = SchXMLTools::getPropertyFromContext("ErrorBarRangePositive",
1074 10 : pSeriesStyleContext, pStylesCtxt);
1075 10 : if( aAny.hasValue() )
1076 : {
1077 6 : aAny >>= aPosRange;
1078 : }
1079 :
1080 20 : aAny = SchXMLTools::getPropertyFromContext("ErrorBarRangeNegative",
1081 10 : pSeriesStyleContext, pStylesCtxt);
1082 10 : if( aAny.hasValue() )
1083 : {
1084 6 : aAny >>= aNegRange;
1085 : }
1086 :
1087 20 : aAny = SchXMLTools::getPropertyFromContext("Weight",
1088 10 : pSeriesStyleContext, pStylesCtxt);
1089 10 : if( aAny.hasValue() )
1090 : {
1091 3 : xBarProp->setPropertyValue("Weight", aAny);
1092 : }
1093 :
1094 20 : aAny = SchXMLTools::getPropertyFromContext("PercentageError",
1095 10 : pSeriesStyleContext, pStylesCtxt);
1096 10 : if( aAny.hasValue() && aBarStyle == com::sun::star::chart::ErrorBarStyle::RELATIVE )
1097 : {
1098 4 : xBarProp->setPropertyValue("PositiveError", aAny);
1099 4 : xBarProp->setPropertyValue("NegativeError", aAny);
1100 : }
1101 :
1102 10 : switch(aBarStyle)
1103 : {
1104 : case com::sun::star::chart::ErrorBarStyle::ERROR_MARGIN:
1105 : {
1106 0 : aAny = SchXMLTools::getPropertyFromContext("NegativeError",
1107 0 : pSeriesStyleContext,pStylesCtxt);
1108 :
1109 0 : xBarProp->setPropertyValue("NegativeError",aAny);
1110 :
1111 0 : aAny = SchXMLTools::getPropertyFromContext("PositiveError",
1112 0 : pSeriesStyleContext,pStylesCtxt);
1113 :
1114 0 : xBarProp->setPropertyValue("PositiveError",aAny);
1115 : }
1116 0 : break;
1117 : default:
1118 10 : break;
1119 : }
1120 10 : }
1121 10 : }
1122 :
1123 : }
1124 :
1125 5 : void SchXMLStatisticsObjectContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
1126 : {
1127 5 : sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
1128 5 : OUString sAutoStyleName;
1129 10 : OUString aPosRange;
1130 10 : OUString aNegRange;
1131 5 : bool bYError = true; /// Default errorbar, to be backward compatible with older files!
1132 :
1133 15 : for( sal_Int16 i = 0; i < nAttrCount; i++ )
1134 : {
1135 10 : OUString sAttrName = xAttrList->getNameByIndex( i );
1136 20 : OUString aLocalName;
1137 :
1138 10 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
1139 :
1140 10 : if( nPrefix == XML_NAMESPACE_CHART )
1141 : {
1142 10 : if( IsXMLToken( aLocalName, XML_STYLE_NAME ) )
1143 5 : sAutoStyleName = xAttrList->getValueByIndex( i );
1144 5 : else if( IsXMLToken( aLocalName, XML_DIMENSION ) )
1145 5 : bYError = xAttrList->getValueByIndex(i) == "y";
1146 0 : else if( IsXMLToken( aLocalName, XML_ERROR_UPPER_RANGE) )
1147 0 : aPosRange = xAttrList->getValueByIndex(i);
1148 0 : else if( IsXMLToken( aLocalName, XML_ERROR_LOWER_RANGE) )
1149 0 : aNegRange = xAttrList->getValueByIndex(i);
1150 : }
1151 10 : }
1152 :
1153 5 : if( !sAutoStyleName.isEmpty() )
1154 : {
1155 5 : DataRowPointStyle aStyle( DataRowPointStyle::MEAN_VALUE, m_xSeries, -1, 1, sAutoStyleName );
1156 :
1157 5 : switch( meContextType )
1158 : {
1159 : case CONTEXT_TYPE_MEAN_VALUE_LINE:
1160 0 : aStyle.meType = DataRowPointStyle::MEAN_VALUE;
1161 0 : break;
1162 : case CONTEXT_TYPE_ERROR_INDICATOR:
1163 : {
1164 5 : aStyle.meType = DataRowPointStyle::ERROR_INDICATOR;
1165 :
1166 : uno::Reference< lang::XMultiServiceFactory > xFact( comphelper::getProcessServiceFactory(),
1167 5 : uno::UNO_QUERY );
1168 :
1169 5 : uno::Reference< beans::XPropertySet > xBarProp( xFact->createInstance("com.sun.star.chart2.ErrorBar" ),
1170 10 : uno::UNO_QUERY );
1171 :
1172 5 : xBarProp->setPropertyValue("ErrorBarStyle",uno::makeAny(com::sun::star::chart::ErrorBarStyle::NONE));
1173 5 : xBarProp->setPropertyValue("PositiveError",uno::makeAny(static_cast<double>(0.0)));
1174 5 : xBarProp->setPropertyValue("NegativeError",uno::makeAny(static_cast<double>(0.0)));
1175 5 : xBarProp->setPropertyValue("Weight",uno::makeAny(static_cast<double>(1.0)));
1176 5 : xBarProp->setPropertyValue("ShowPositiveError",uno::makeAny(sal_True));
1177 5 : xBarProp->setPropertyValue("ShowNegativeError",uno::makeAny(sal_True));
1178 :
1179 : // first import defaults from parent style
1180 5 : SetErrorBarPropertiesFromStyleName( maSeriesStyleName, xBarProp, mrImportHelper, aPosRange, aNegRange );
1181 5 : SetErrorBarPropertiesFromStyleName( sAutoStyleName, xBarProp, mrImportHelper, aPosRange, aNegRange );
1182 :
1183 10 : uno::Reference< chart2::XChartDocument > xDoc(GetImport().GetModel(),uno::UNO_QUERY);
1184 :
1185 5 : if (!aPosRange.isEmpty())
1186 3 : lcl_setErrorBarSequence(xDoc,xBarProp,aPosRange,true,bYError, mrLSequencesPerIndex);
1187 :
1188 5 : if (!aNegRange.isEmpty())
1189 3 : lcl_setErrorBarSequence(xDoc,xBarProp,aNegRange,false,bYError, mrLSequencesPerIndex);
1190 :
1191 5 : if ( !bYError )
1192 : {
1193 0 : aStyle.m_xErrorXProperties.set( xBarProp );
1194 : }
1195 : else
1196 : {
1197 5 : aStyle.m_xErrorYProperties.set( xBarProp );
1198 5 : }
1199 : }
1200 5 : break;
1201 : }
1202 :
1203 5 : mrStyleList.push_back( aStyle );
1204 5 : }
1205 5 : }
1206 :
1207 0 : SvXMLImportContext* SchXMLStatisticsObjectContext::CreateChildContext(
1208 : sal_uInt16 nPrefix,
1209 : const OUString& rLocalName,
1210 : const uno::Reference< xml::sax::XAttributeList >& xAttrList )
1211 : {
1212 0 : SvXMLImportContext* pContext = 0;
1213 0 : pContext = SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList );
1214 0 : return pContext;
1215 : }
1216 :
1217 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|