1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <sax/tools/converter.hxx>
23 #include "SchXMLPlotAreaContext.hxx"
24 #include "SchXMLImport.hxx"
25 #include "SchXMLAxisContext.hxx"
26 #include "SchXMLSeries2Context.hxx"
27 #include "SchXMLTools.hxx"
28 #include <tools/debug.hxx>
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>
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/RegressionEquation.hpp>
50 #include <com/sun/star/chart2/RelativePosition.hpp>
51 #include <com/sun/star/chart2/XChartTypeContainer.hpp>
52 #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
53 #include <com/sun/star/chart2/data/XDataSink.hpp>
54 #include <com/sun/star/chart2/data/XRangeXMLConversion.hpp>
55 #include <com/sun/star/chart2/data/LabeledDataSequence.hpp>
56 #include <com/sun/star/drawing/CameraGeometry.hpp>
57 #include <com/sun/star/drawing/FillStyle.hpp>
58 #include <com/sun/star/lang/XServiceInfo.hpp>
59 #include <com/sun/star/util/XStringMapping.hpp>
60 #include <com/sun/star/xml/sax/XAttributeList.hpp>
62 using namespace com::sun::star
;
63 using namespace ::xmloff::token
;
65 using com::sun::star::uno::Reference
;
70 struct lcl_AxisHasCategories
: public ::std::unary_function
< SchXMLAxis
, bool >
72 bool operator() ( const SchXMLAxis
& rAxis
)
74 return rAxis
.bHasCategories
;
78 OUString
lcl_ConvertRange( const OUString
& rRange
, const uno::Reference
< chart2::XChartDocument
> & xDoc
)
80 OUString aResult
= rRange
;
83 uno::Reference
< chart2::data::XRangeXMLConversion
> xConversion(
84 xDoc
->getDataProvider(), uno::UNO_QUERY
);
86 aResult
= xConversion
->convertRangeFromXML( rRange
);
90 } // anonymous namespace
92 SchXML3DSceneAttributesHelper::SchXML3DSceneAttributesHelper( SvXMLImport
& rImporter
)
93 : SdXML3DSceneAttributesHelper( rImporter
)
97 void SchXML3DSceneAttributesHelper::getCameraDefaultFromDiagram( const uno::Reference
< chart::XDiagram
>& xDiagram
)
99 //different defaults for camera geometry necessary to workaround wrong behaviour in old chart
100 //in future make this version dependent if we have versioning (metastream) for ole objects
104 uno::Reference
< beans::XPropertySet
> xProp( xDiagram
, uno::UNO_QUERY
);
107 drawing::CameraGeometry aCamGeo
;
108 xProp
->getPropertyValue( OUString( "D3DCameraGeometry" )) >>= aCamGeo
;
109 maVRP
.setX( aCamGeo
.vrp
.PositionX
);
110 maVRP
.setY( aCamGeo
.vrp
.PositionY
);
111 maVRP
.setZ( aCamGeo
.vrp
.PositionZ
);
112 maVPN
.setX( aCamGeo
.vpn
.DirectionX
);
113 maVPN
.setY( aCamGeo
.vpn
.DirectionY
);
114 maVPN
.setZ( aCamGeo
.vpn
.DirectionZ
);
115 maVUP
.setX( aCamGeo
.vup
.DirectionX
);
116 maVUP
.setY( aCamGeo
.vup
.DirectionY
);
117 maVUP
.setZ( aCamGeo
.vup
.DirectionZ
);
120 catch( const uno::Exception
& rEx
)
122 OString
aBStr(OUStringToOString(rEx
.Message
, RTL_TEXTENCODING_ASCII_US
));
123 SAL_INFO("xmloff.chart", "Exception caught for property NumberOfLines: " << aBStr
);
127 SchXML3DSceneAttributesHelper::~SchXML3DSceneAttributesHelper()
131 SchXMLPlotAreaContext::SchXMLPlotAreaContext(
132 SchXMLImportHelper
& rImpHelper
,
133 SvXMLImport
& rImport
, const OUString
& rLocalName
,
134 const OUString
& rXLinkHRefAttributeToIndicateDataProvider
,
135 OUString
& rCategoriesAddress
,
136 OUString
& rChartAddress
,
137 bool& rbHasRangeAtPlotArea
,
138 sal_Bool
& rAllRangeAddressesAvailable
,
139 sal_Bool
& rColHasLabels
,
140 sal_Bool
& rRowHasLabels
,
141 chart::ChartDataRowSource
& rDataRowSource
,
142 SeriesDefaultsAndStyles
& rSeriesDefaultsAndStyles
,
143 const OUString
& aChartTypeServiceName
,
144 tSchXMLLSequencesPerIndex
& rLSequencesPerIndex
,
145 const awt::Size
& rChartSize
) :
146 SvXMLImportContext( rImport
, XML_NAMESPACE_CHART
, rLocalName
),
147 mrImportHelper( rImpHelper
),
148 mrCategoriesAddress( rCategoriesAddress
),
149 mrSeriesDefaultsAndStyles( rSeriesDefaultsAndStyles
),
150 mnNumOfLinesProp( 0 ),
151 mbStockHasVolume( sal_False
),
153 m_aGlobalSeriesImportInfo( rAllRangeAddressesAvailable
),
154 maSceneImportHelper( rImport
),
155 m_aOuterPositioning( rImport
),
156 m_aInnerPositioning( rImport
),
157 mbPercentStacked(false),
158 m_bAxisPositionAttributeImported(false),
159 m_rXLinkHRefAttributeToIndicateDataProvider(rXLinkHRefAttributeToIndicateDataProvider
),
160 mrChartAddress( rChartAddress
),
161 m_rbHasRangeAtPlotArea( rbHasRangeAtPlotArea
),
162 mrColHasLabels( rColHasLabels
),
163 mrRowHasLabels( rRowHasLabels
),
164 mrDataRowSource( rDataRowSource
),
165 maChartTypeServiceName( aChartTypeServiceName
),
166 mrLSequencesPerIndex( rLSequencesPerIndex
),
167 mbGlobalChartTypeUsedBySeries( false ),
168 maChartSize( rChartSize
)
170 m_rbHasRangeAtPlotArea
= false;
173 uno::Reference
< chart::XChartDocument
> xDoc( rImpHelper
.GetChartDocument(), uno::UNO_QUERY
);
176 mxDiagram
= xDoc
->getDiagram();
177 mxNewDoc
.set( xDoc
, uno::UNO_QUERY
);
179 maSceneImportHelper
.getCameraDefaultFromDiagram( mxDiagram
);
181 SAL_WARN_IF( !mxDiagram
.is(),"xmloff.chart", "Couldn't get XDiagram" );
183 // turn off all axes initially
185 aFalseBool
<<= (sal_Bool
)(sal_False
);
187 uno::Reference
< lang::XServiceInfo
> xInfo( mxDiagram
, uno::UNO_QUERY
);
188 uno::Reference
< beans::XPropertySet
> xProp( mxDiagram
, uno::UNO_QUERY
);
194 xProp
->setPropertyValue(
195 OUString( "HasXAxis" ), aFalseBool
);
196 xProp
->setPropertyValue(
197 OUString( "HasXAxisGrid" ), aFalseBool
);
198 xProp
->setPropertyValue(
199 OUString( "HasXAxisDescription" ), aFalseBool
);
200 xProp
->setPropertyValue(
201 OUString( "HasSecondaryXAxis" ), aFalseBool
);
202 xProp
->setPropertyValue(
203 OUString( "HasSecondaryXAxisDescription" ), aFalseBool
);
205 xProp
->setPropertyValue(
206 OUString( "HasYAxis" ), aFalseBool
);
207 xProp
->setPropertyValue(
208 OUString( "HasYAxisGrid" ), aFalseBool
);
209 xProp
->setPropertyValue(
210 OUString( "HasYAxisDescription" ), aFalseBool
);
211 xProp
->setPropertyValue(
212 OUString( "HasSecondaryYAxis" ), aFalseBool
);
213 xProp
->setPropertyValue(
214 OUString( "HasSecondaryYAxisDescription" ), aFalseBool
);
216 xProp
->setPropertyValue(
217 OUString( "HasZAxis" ), aFalseBool
);
218 xProp
->setPropertyValue(
219 OUString( "HasZAxisDescription" ), aFalseBool
);
222 chart::ChartDataRowSource eSource
= chart::ChartDataRowSource_COLUMNS
;
224 xProp
->setPropertyValue( OUString( "DataRowSource" ), aAny
);
226 catch( const beans::UnknownPropertyException
& )
228 SAL_WARN("xmloff.chart", "Property required by service not supported" );
233 SchXMLPlotAreaContext::~SchXMLPlotAreaContext()
236 void SchXMLPlotAreaContext::StartElement( const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
)
239 sal_Int16 nAttrCount
= xAttrList
.is()? xAttrList
->getLength(): 0;
240 const SvXMLTokenMap
& rAttrTokenMap
= mrImportHelper
.GetPlotAreaAttrTokenMap();
241 uno::Reference
< chart2::XChartDocument
> xNewDoc( GetImport().GetModel(), uno::UNO_QUERY
);
243 for( sal_Int16 i
= 0; i
< nAttrCount
; i
++ )
245 OUString sAttrName
= xAttrList
->getNameByIndex( i
);
247 OUString aValue
= xAttrList
->getValueByIndex( i
);
248 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName
, &aLocalName
);
250 switch( rAttrTokenMap
.Get( nPrefix
, aLocalName
))
254 case XML_TOK_PA_WIDTH
:
255 case XML_TOK_PA_HEIGHT
:
256 m_aOuterPositioning
.readPositioningAttribute( nPrefix
, aLocalName
, aValue
);
258 case XML_TOK_PA_STYLE_NAME
:
259 msAutoStyleName
= aValue
;
261 case XML_TOK_PA_CHART_ADDRESS
:
262 mrChartAddress
= lcl_ConvertRange( aValue
, xNewDoc
);
263 // indicator for getting data from the outside
264 m_rbHasRangeAtPlotArea
= true;
266 case XML_TOK_PA_DS_HAS_LABELS
:
268 if( aValue
.equals( ::xmloff::token::GetXMLToken( ::xmloff::token::XML_BOTH
)))
269 mrColHasLabels
= mrRowHasLabels
= sal_True
;
270 else if( aValue
.equals( ::xmloff::token::GetXMLToken( ::xmloff::token::XML_ROW
)))
271 mrRowHasLabels
= sal_True
;
272 else if( aValue
.equals( ::xmloff::token::GetXMLToken( ::xmloff::token::XML_COLUMN
)))
273 mrColHasLabels
= sal_True
;
276 case XML_TOK_PA_TRANSFORM
:
280 case XML_TOK_PA_PROJECTION
:
281 case XML_TOK_PA_DISTANCE
:
282 case XML_TOK_PA_FOCAL_LENGTH
:
283 case XML_TOK_PA_SHADOW_SLANT
:
284 case XML_TOK_PA_SHADE_MODE
:
285 case XML_TOK_PA_AMBIENT_COLOR
:
286 case XML_TOK_PA_LIGHTING_MODE
:
287 maSceneImportHelper
.processSceneAttribute( nPrefix
, aLocalName
, aValue
);
294 uno::Reference
< beans::XPropertySet
> xDocProp( mrImportHelper
.GetChartDocument(), uno::UNO_QUERY
);
300 aAny
<<= (sal_Bool
)(mrColHasLabels
);
301 xDocProp
->setPropertyValue(
302 OUString( "DataSourceLabelsInFirstColumn" ),
305 aAny
<<= (sal_Bool
)(mrRowHasLabels
);
306 xDocProp
->setPropertyValue(
307 OUString( "DataSourceLabelsInFirstRow" ),
310 catch( const beans::UnknownPropertyException
& )
312 SAL_WARN("xmloff.chart", "Properties missing" );
318 uno::Reference
< beans::XPropertySet
> xProp( mxDiagram
, uno::UNO_QUERY
);
319 if( !msAutoStyleName
.isEmpty())
323 const SvXMLStylesContext
* pStylesCtxt
= mrImportHelper
.GetAutoStylesContext();
326 const SvXMLStyleContext
* pStyle
= pStylesCtxt
->FindStyleChildContext(
327 mrImportHelper
.GetChartFamilyID(), msAutoStyleName
);
329 XMLPropStyleContext
* pPropStyleContext
=
330 const_cast< XMLPropStyleContext
* >(
331 dynamic_cast< const XMLPropStyleContext
* >( pStyle
) );
332 if( pPropStyleContext
)
334 pPropStyleContext
->FillPropertySet( xProp
);
336 // get the data row source that was set without having data
337 xProp
->getPropertyValue( OUString( "DataRowSource" ))
341 //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
342 mrSeriesDefaultsAndStyles
.maLinesOnProperty
= SchXMLTools::getPropertyFromContext(
343 OUString("Lines"), pPropStyleContext
, pStylesCtxt
);
345 //handle automatic position and size
346 m_aOuterPositioning
.readAutomaticPositioningProperties( pPropStyleContext
, pStylesCtxt
);
348 //correct default starting angle for old 3D pies
349 if( SchXMLTools::isDocumentGeneratedWithOpenOfficeOlderThan3_0( GetImport().GetModel() ) )
352 if( xProp
.is() && ( xProp
->getPropertyValue(OUString("Dim3D")) >>= bIs3d
) &&
355 if( maChartTypeServiceName
== "com.sun.star.chart2.PieChartType" || maChartTypeServiceName
== "com.sun.star.chart2.DonutChartType" )
357 OUString
aPropName( OUString("StartingAngle") );
358 uno::Any
aAStartingAngle( SchXMLTools::getPropertyFromContext( aPropName
, pPropStyleContext
, pStylesCtxt
) );
359 if( !aAStartingAngle
.hasValue() )
360 xProp
->setPropertyValue( aPropName
, uno::makeAny(sal_Int32(0)) ) ;
369 //remember default values for dataseries
374 mrSeriesDefaultsAndStyles
.maSymbolTypeDefault
= xProp
->getPropertyValue(OUString("SymbolType"));
375 mrSeriesDefaultsAndStyles
.maDataCaptionDefault
= xProp
->getPropertyValue(OUString("DataCaption"));
377 mrSeriesDefaultsAndStyles
.maMeanValueDefault
= xProp
->getPropertyValue(OUString("MeanValue"));
378 mrSeriesDefaultsAndStyles
.maRegressionCurvesDefault
= xProp
->getPropertyValue(OUString("RegressionCurves"));
380 bool bStacked
= false;
381 mrSeriesDefaultsAndStyles
.maStackedDefault
= xProp
->getPropertyValue(OUString("Stacked"));
382 mrSeriesDefaultsAndStyles
.maStackedDefault
>>= bStacked
;
383 mrSeriesDefaultsAndStyles
.maPercentDefault
= xProp
->getPropertyValue(OUString("Percent"));
384 mrSeriesDefaultsAndStyles
.maPercentDefault
>>= mbPercentStacked
;
385 mrSeriesDefaultsAndStyles
.maStackedBarsConnectedDefault
= xProp
->getPropertyValue(OUString("StackedBarsConnected"));
388 uno::Any
aDeepProperty( xProp
->getPropertyValue(OUString("Deep")));
389 // #124488# old versions store a 3d area and 3D line deep chart with Deep==false => workaround for this
390 if( ! (bStacked
|| mbPercentStacked
))
392 if( SchXMLTools::isDocumentGeneratedWithOpenOfficeOlderThan2_3( GetImport().GetModel() ) )
395 if( ( xProp
->getPropertyValue(OUString("Dim3D")) >>= bIs3d
) &&
398 if( maChartTypeServiceName
== "com.sun.star.chart2.AreaChartType" || maChartTypeServiceName
== "com.sun.star.chart2.LineChartType" )
400 aDeepProperty
<<= uno::makeAny( true );
405 mrSeriesDefaultsAndStyles
.maDeepDefault
= aDeepProperty
;
407 xProp
->getPropertyValue(OUString("NumberOfLines")) >>= mnNumOfLinesProp
;
408 xProp
->getPropertyValue(OUString("Volume")) >>= mbStockHasVolume
;
410 catch( const uno::Exception
& rEx
)
412 OString
aBStr(OUStringToOString(rEx
.Message
, RTL_TEXTENCODING_ASCII_US
));
413 SAL_INFO("xmloff.chart", "PlotAreaContext:EndElement(): Exception caught: " << aBStr
);
417 bool bCreateInternalDataProvider
= false;
418 if( m_rXLinkHRefAttributeToIndicateDataProvider
== "." ) //data comes from the chart itself
419 bCreateInternalDataProvider
= true;
420 else if( m_rXLinkHRefAttributeToIndicateDataProvider
== ".." ) //data comes from the parent application
421 bCreateInternalDataProvider
= false;
422 else if( !m_rXLinkHRefAttributeToIndicateDataProvider
.isEmpty() ) //not supported so far to get the data by sibling objects -> fall back to chart itself
423 bCreateInternalDataProvider
= true;
424 else if( !m_rbHasRangeAtPlotArea
)
425 bCreateInternalDataProvider
= true;
427 if( bCreateInternalDataProvider
&& mxNewDoc
.is() )
429 // we have no complete range => we have own data, so switch the data
430 // provider to internal. Clone is not necessary, as we don't have any
432 mxNewDoc
->createInternalDataProvider( false /* bCloneExistingData */ );
433 if( xProp
.is() && mrDataRowSource
!=chart::ChartDataRowSource_COLUMNS
)
434 xProp
->setPropertyValue( OUString( "DataRowSource" ), uno::makeAny(mrDataRowSource
) );
438 SvXMLImportContext
* SchXMLPlotAreaContext::CreateChildContext(
440 const OUString
& rLocalName
,
441 const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
)
443 SvXMLImportContext
* pContext
= 0;
444 const SvXMLTokenMap
& rTokenMap
= mrImportHelper
.GetPlotAreaElemTokenMap();
446 switch( rTokenMap
.Get( nPrefix
, rLocalName
))
448 case XML_TOK_PA_COORDINATE_REGION_EXT
:
449 case XML_TOK_PA_COORDINATE_REGION
:
451 pContext
= new SchXMLCoordinateRegionContext( GetImport(), nPrefix
, rLocalName
, m_aInnerPositioning
);
455 case XML_TOK_PA_AXIS
:
457 bool bAddMissingXAxisForNetCharts
= false;
458 bool bAdaptWrongPercentScaleValues
= false;
459 if( SchXMLTools::isDocumentGeneratedWithOpenOfficeOlderThan2_3( GetImport().GetModel() ) )
461 //correct errors from older versions
463 // for NetCharts there were no xAxis exported to older files
464 // so we need to add the x axis here for those old NetChart files
465 if ( maChartTypeServiceName
== "com.sun.star.chart2.NetChartType" )
466 bAddMissingXAxisForNetCharts
= true;
469 if( mbPercentStacked
)
470 bAdaptWrongPercentScaleValues
= true;
473 bool bAdaptXAxisOrientationForOld2DBarCharts
= false;
474 if( SchXMLTools::isDocumentGeneratedWithOpenOfficeOlderThan2_4( GetImport().GetModel() ) )
477 if ( maChartTypeServiceName
== "com.sun.star.chart2.ColumnChartType" )
478 bAdaptXAxisOrientationForOld2DBarCharts
= true;
481 pContext
= new SchXMLAxisContext( mrImportHelper
, GetImport(), rLocalName
, mxDiagram
, maAxes
, mrCategoriesAddress
,
482 bAddMissingXAxisForNetCharts
, bAdaptWrongPercentScaleValues
, bAdaptXAxisOrientationForOld2DBarCharts
, m_bAxisPositionAttributeImported
);
486 case XML_TOK_PA_SERIES
:
490 pContext
= new SchXMLSeries2Context(
491 mrImportHelper
, GetImport(), rLocalName
,
493 mrSeriesDefaultsAndStyles
.maSeriesStyleList
,
496 m_aGlobalSeriesImportInfo
,
497 maChartTypeServiceName
,
498 mrLSequencesPerIndex
,
499 mbGlobalChartTypeUsedBySeries
, maChartSize
);
505 case XML_TOK_PA_WALL
:
506 pContext
= new SchXMLWallFloorContext( mrImportHelper
, GetImport(), nPrefix
, rLocalName
, mxDiagram
,
507 SchXMLWallFloorContext::CONTEXT_TYPE_WALL
);
509 case XML_TOK_PA_FLOOR
:
510 pContext
= new SchXMLWallFloorContext( mrImportHelper
, GetImport(), nPrefix
, rLocalName
, mxDiagram
,
511 SchXMLWallFloorContext::CONTEXT_TYPE_FLOOR
);
514 case XML_TOK_PA_LIGHT_SOURCE
:
515 pContext
= maSceneImportHelper
.create3DLightContext( nPrefix
, rLocalName
, xAttrList
);
518 // elements for stock charts
519 case XML_TOK_PA_STOCK_GAIN
:
520 pContext
= new SchXMLStockContext( mrImportHelper
, GetImport(), nPrefix
, rLocalName
, mxDiagram
,
521 SchXMLStockContext::CONTEXT_TYPE_GAIN
);
523 case XML_TOK_PA_STOCK_LOSS
:
524 pContext
= new SchXMLStockContext( mrImportHelper
, GetImport(), nPrefix
, rLocalName
, mxDiagram
,
525 SchXMLStockContext::CONTEXT_TYPE_LOSS
);
527 case XML_TOK_PA_STOCK_RANGE
:
528 pContext
= new SchXMLStockContext( mrImportHelper
, GetImport(), nPrefix
, rLocalName
, mxDiagram
,
529 SchXMLStockContext::CONTEXT_TYPE_RANGE
);
533 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLocalName
);
539 void SchXMLPlotAreaContext::EndElement()
542 if( !mrCategoriesAddress
.isEmpty() && mxNewDoc
.is())
544 uno::Reference
< chart2::data::XDataProvider
> xDataProvider(
545 mxNewDoc
->getDataProvider() );
546 // @todo: correct coordinate system index
547 sal_Int32
nDimension( 0 );
548 ::std::vector
< SchXMLAxis
>::const_iterator
aIt(
549 ::std::find_if( maAxes
.begin(), maAxes
.end(), lcl_AxisHasCategories()));
550 if( aIt
!= maAxes
.end())
551 nDimension
= static_cast< sal_Int32
>( (*aIt
).eDimension
);
552 SchXMLTools::CreateCategories(
553 xDataProvider
, mxNewDoc
, mrCategoriesAddress
,
554 0 /* nCooSysIndex */,
555 nDimension
, &mrLSequencesPerIndex
);
558 uno::Reference
< beans::XPropertySet
> xDiaProp( mxDiagram
, uno::UNO_QUERY
);
561 sal_Bool bIsThreeDim
= sal_False
;
562 uno::Any aAny
= xDiaProp
->getPropertyValue( OUString( "Dim3D" ));
563 aAny
>>= bIsThreeDim
;
565 // set 3d scene attributes
568 // set scene attributes at diagram
569 maSceneImportHelper
.setSceneAttributes( xDiaProp
);
572 // set correct number of lines at series
573 if( ! m_aGlobalSeriesImportInfo
.rbAllRangeAddressesAvailable
&& mnNumOfLinesProp
> 0 && maChartTypeServiceName
== "com.sun.star.chart2.ColumnChartType" )
577 xDiaProp
->setPropertyValue( OUString( "NumberOfLines" ),
578 uno::makeAny( mnNumOfLinesProp
));
580 catch( const uno::Exception
& rEx
)
582 OString
aBStr(OUStringToOString(rEx
.Message
, RTL_TEXTENCODING_ASCII_US
));
583 SAL_INFO("xmloff.chart", "Exception caught for property NumberOfLines: " << aBStr
);
587 // #i32366# stock has volume
588 if( ( 0 == mxDiagram
->getDiagramType().reverseCompareTo("com.sun.star.chart.StockDiagram" )) &&
593 xDiaProp
->setPropertyValue( OUString( "Volume" ),
594 uno::makeAny( true ));
596 catch( const uno::Exception
& rEx
)
598 OString
aBStr(OUStringToOString(rEx
.Message
, RTL_TEXTENCODING_ASCII_US
));
599 SAL_INFO("xmloff.chart", "Exception caught for property Volume: " << aBStr
);
604 // set changed size and position after properties (esp. 3d)
606 uno::Reference
< chart::XDiagramPositioning
> xDiaPos( mxDiagram
, uno::UNO_QUERY
);
609 if( !m_aOuterPositioning
.isAutomatic() )
611 if( m_aInnerPositioning
.hasPosSize() )
612 xDiaPos
->setDiagramPositionExcludingAxes( m_aInnerPositioning
.getRectangle() );
613 else if( m_aOuterPositioning
.hasPosSize() )
615 if( SchXMLTools::isDocumentGeneratedWithOpenOfficeOlderThan3_3( GetImport().GetModel() ) ) //old version of OOo did write a wrong rectangle for the diagram size
616 xDiaPos
->setDiagramPositionIncludingAxesAndAxisTitles( m_aOuterPositioning
.getRectangle() );
618 xDiaPos
->setDiagramPositionIncludingAxes( m_aOuterPositioning
.getRectangle() );
623 SchXMLAxisContext::CorrectAxisPositions( uno::Reference
< chart2::XChartDocument
>( mrImportHelper
.GetChartDocument(), uno::UNO_QUERY
), maChartTypeServiceName
, GetImport().GetODFVersion(), m_bAxisPositionAttributeImported
);
626 // ========================================
628 SchXMLDataPointContext::SchXMLDataPointContext( SvXMLImport
& rImport
, const OUString
& rLocalName
,
629 ::std::list
< DataRowPointStyle
>& rStyleList
,
630 const ::com::sun::star::uno::Reference
<
631 ::com::sun::star::chart2::XDataSeries
>& xSeries
,
633 bool bSymbolSizeForSeriesIsMissingInFile
) :
634 SvXMLImportContext( rImport
, XML_NAMESPACE_CHART
, rLocalName
),
635 mrStyleList( rStyleList
),
636 m_xSeries( xSeries
),
638 mbSymbolSizeForSeriesIsMissingInFile( bSymbolSizeForSeriesIsMissingInFile
)
642 SchXMLDataPointContext::~SchXMLDataPointContext()
646 void SchXMLDataPointContext::StartElement( const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
)
648 sal_Int16 nAttrCount
= xAttrList
.is()? xAttrList
->getLength(): 0;
649 OUString sAutoStyleName
;
650 sal_Int32 nRepeat
= 1;
652 for( sal_Int16 i
= 0; i
< nAttrCount
; i
++ )
654 OUString sAttrName
= xAttrList
->getNameByIndex( i
);
656 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName
, &aLocalName
);
658 if( nPrefix
== XML_NAMESPACE_CHART
)
660 if( IsXMLToken( aLocalName
, XML_STYLE_NAME
) )
661 sAutoStyleName
= xAttrList
->getValueByIndex( i
);
662 else if( IsXMLToken( aLocalName
, XML_REPEATED
) )
663 nRepeat
= xAttrList
->getValueByIndex( i
).toInt32();
667 if( !sAutoStyleName
.isEmpty())
669 DataRowPointStyle
aStyle(
670 DataRowPointStyle::DATA_POINT
,
671 m_xSeries
, mrIndex
, nRepeat
, sAutoStyleName
);
672 aStyle
.mbSymbolSizeForSeriesIsMissingInFile
= mbSymbolSizeForSeriesIsMissingInFile
;
673 mrStyleList
.push_back( aStyle
);
678 // ========================================
680 SchXMLPositonAttributesHelper::SchXMLPositonAttributesHelper( SvXMLImport
& rImporter
)
681 : m_rImport( rImporter
)
684 , m_bHasSizeWidth( false )
685 , m_bHasSizeHeight( false )
686 , m_bHasPositionX( false )
687 , m_bHasPositionY( false )
688 , m_bAutoSize( false )
689 , m_bAutoPosition( false )
693 SchXMLPositonAttributesHelper::~SchXMLPositonAttributesHelper()
697 bool SchXMLPositonAttributesHelper::hasSize() const
699 return m_bHasSizeWidth
&& m_bHasSizeHeight
;
701 bool SchXMLPositonAttributesHelper::hasPosition() const
703 return m_bHasPositionX
&& m_bHasPositionY
;
705 bool SchXMLPositonAttributesHelper::hasPosSize() const
707 return hasPosition() && hasSize();
709 bool SchXMLPositonAttributesHelper::isAutomatic() const
711 return m_bAutoSize
|| m_bAutoPosition
;
713 awt::Rectangle
SchXMLPositonAttributesHelper::getRectangle() const
715 return awt::Rectangle( m_aPosition
.X
, m_aPosition
.Y
, m_aSize
.Width
, m_aSize
.Height
);
718 bool SchXMLPositonAttributesHelper::readPositioningAttribute( sal_uInt16 nPrefix
, const OUString
& rLocalName
, const OUString
& rValue
)
720 //returns true if the attribute was proccessed
723 if( XML_NAMESPACE_SVG
== nPrefix
)
725 if( IsXMLToken( rLocalName
, XML_X
) )
727 m_rImport
.GetMM100UnitConverter().convertMeasureToCore(
728 m_aPosition
.X
, rValue
);
729 m_bHasPositionX
= true;
731 else if( IsXMLToken( rLocalName
, XML_Y
) )
733 m_rImport
.GetMM100UnitConverter().convertMeasureToCore(
734 m_aPosition
.Y
, rValue
);
735 m_bHasPositionY
= true;
737 else if( IsXMLToken( rLocalName
, XML_WIDTH
) )
739 m_rImport
.GetMM100UnitConverter().convertMeasureToCore(
740 m_aSize
.Width
, rValue
);
741 m_bHasSizeWidth
= true;
743 else if( IsXMLToken( rLocalName
, XML_HEIGHT
) )
745 m_rImport
.GetMM100UnitConverter().convertMeasureToCore(
746 m_aSize
.Height
, rValue
);
747 m_bHasSizeHeight
= true;
759 void SchXMLPositonAttributesHelper::readAutomaticPositioningProperties( XMLPropStyleContext
* pPropStyleContext
, const SvXMLStylesContext
* pStylesCtxt
)
761 if( pPropStyleContext
&& pStylesCtxt
)
763 //handle automatic position and size
764 SchXMLTools::getPropertyFromContext(
765 OUString("AutomaticSize"), pPropStyleContext
, pStylesCtxt
) >>= m_bAutoSize
;
766 SchXMLTools::getPropertyFromContext(
767 OUString("AutomaticPosition"), pPropStyleContext
, pStylesCtxt
) >>= m_bAutoPosition
;
771 // ========================================
773 SchXMLCoordinateRegionContext::SchXMLCoordinateRegionContext(
776 , const OUString
& rLocalName
777 , SchXMLPositonAttributesHelper
& rPositioning
)
778 : SvXMLImportContext( rImport
, nPrefix
, rLocalName
)
779 , m_rPositioning( rPositioning
)
783 SchXMLCoordinateRegionContext::~SchXMLCoordinateRegionContext()
787 void SchXMLCoordinateRegionContext::StartElement( const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
)
790 sal_Int16 nAttrCount
= xAttrList
.is()? xAttrList
->getLength(): 0;
792 for( sal_Int16 i
= 0; i
< nAttrCount
; i
++ )
794 OUString sAttrName
= xAttrList
->getNameByIndex( i
);
796 OUString aValue
= xAttrList
->getValueByIndex( i
);
797 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName
, &aLocalName
);
798 m_rPositioning
.readPositioningAttribute( nPrefix
, aLocalName
, aValue
);
802 // ========================================
804 SchXMLWallFloorContext::SchXMLWallFloorContext(
805 SchXMLImportHelper
& rImpHelper
,
806 SvXMLImport
& rImport
,
808 const OUString
& rLocalName
,
809 uno::Reference
< chart::XDiagram
>& xDiagram
,
810 ContextType eContextType
) :
811 SvXMLImportContext( rImport
, nPrefix
, rLocalName
),
812 mrImportHelper( rImpHelper
),
813 mxWallFloorSupplier( xDiagram
, uno::UNO_QUERY
),
814 meContextType( eContextType
)
818 SchXMLWallFloorContext::~SchXMLWallFloorContext()
822 void SchXMLWallFloorContext::StartElement( const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
)
824 if( mxWallFloorSupplier
.is())
826 sal_Int16 nAttrCount
= xAttrList
.is()? xAttrList
->getLength(): 0;
827 OUString sAutoStyleName
;
829 for( sal_Int16 i
= 0; i
< nAttrCount
; i
++ )
831 OUString sAttrName
= xAttrList
->getNameByIndex( i
);
833 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName
, &aLocalName
);
835 if( nPrefix
== XML_NAMESPACE_CHART
&&
836 IsXMLToken( aLocalName
, XML_STYLE_NAME
) )
838 sAutoStyleName
= xAttrList
->getValueByIndex( i
);
843 uno::Reference
< beans::XPropertySet
> xProp( ( meContextType
== CONTEXT_TYPE_WALL
)
844 ? mxWallFloorSupplier
->getWall()
845 : mxWallFloorSupplier
->getFloor(),
849 if( !sAutoStyleName
.isEmpty())
851 const SvXMLStylesContext
* pStylesCtxt
= mrImportHelper
.GetAutoStylesContext();
854 const SvXMLStyleContext
* pStyle
= pStylesCtxt
->FindStyleChildContext(
855 mrImportHelper
.GetChartFamilyID(), sAutoStyleName
);
857 if( pStyle
&& pStyle
->ISA( XMLPropStyleContext
))
858 (( XMLPropStyleContext
* )pStyle
)->FillPropertySet( xProp
);
865 // ========================================
867 SchXMLStockContext::SchXMLStockContext(
868 SchXMLImportHelper
& rImpHelper
,
869 SvXMLImport
& rImport
,
871 const OUString
& rLocalName
,
872 uno::Reference
< chart::XDiagram
>& xDiagram
,
873 ContextType eContextType
) :
874 SvXMLImportContext( rImport
, nPrefix
, rLocalName
),
875 mrImportHelper( rImpHelper
),
876 mxStockPropProvider( xDiagram
, uno::UNO_QUERY
),
877 meContextType( eContextType
)
881 SchXMLStockContext::~SchXMLStockContext()
885 void SchXMLStockContext::StartElement( const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
)
887 if( mxStockPropProvider
.is())
889 sal_Int16 nAttrCount
= xAttrList
.is()? xAttrList
->getLength(): 0;
890 OUString sAutoStyleName
;
892 for( sal_Int16 i
= 0; i
< nAttrCount
; i
++ )
894 OUString sAttrName
= xAttrList
->getNameByIndex( i
);
896 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName
, &aLocalName
);
898 if( nPrefix
== XML_NAMESPACE_CHART
&&
899 IsXMLToken( aLocalName
, XML_STYLE_NAME
) )
901 sAutoStyleName
= xAttrList
->getValueByIndex( i
);
905 if( !sAutoStyleName
.isEmpty())
908 uno::Reference
< beans::XPropertySet
> xProp
;
909 switch( meContextType
)
911 case CONTEXT_TYPE_GAIN
:
912 xProp
= mxStockPropProvider
->getUpBar();
914 case CONTEXT_TYPE_LOSS
:
915 xProp
= mxStockPropProvider
->getDownBar();
917 case CONTEXT_TYPE_RANGE
:
918 xProp
= mxStockPropProvider
->getMinMaxLine();
923 const SvXMLStylesContext
* pStylesCtxt
= mrImportHelper
.GetAutoStylesContext();
926 const SvXMLStyleContext
* pStyle
= pStylesCtxt
->FindStyleChildContext(
927 mrImportHelper
.GetChartFamilyID(), sAutoStyleName
);
929 if( pStyle
&& pStyle
->ISA( XMLPropStyleContext
))
930 (( XMLPropStyleContext
* )pStyle
)->FillPropertySet( xProp
);
937 // ========================================
939 static void lcl_setErrorBarSequence ( const uno::Reference
< chart2::XChartDocument
> &xDoc
,
940 const uno::Reference
< beans::XPropertySet
> &xBarProp
,
941 const OUString
&aXMLRange
,
942 bool bPositiveValue
, bool bYError
,
943 tSchXMLLSequencesPerIndex
& rSequences
)
945 uno::Reference
< com::sun::star::chart2::data::XDataProvider
> xDataProvider(xDoc
->getDataProvider());
946 uno::Reference
< com::sun::star::chart2::data::XDataSource
> xDataSource( xBarProp
, uno::UNO_QUERY
);
947 uno::Reference
< com::sun::star::chart2::data::XDataSink
> xDataSink( xDataSource
, uno::UNO_QUERY
);
949 assert( xDataSink
.is() && xDataSource
.is() && xDataProvider
.is() );
951 OUString
aRange(lcl_ConvertRange(aXMLRange
,xDoc
));
953 uno::Reference
< chart2::data::XDataSequence
> xNewSequence(
954 xDataProvider
->createDataSequenceByRangeRepresentation( aRange
));
956 if( xNewSequence
.is())
958 SchXMLTools::setXMLRangePropertyAtDataSequence(xNewSequence
,aXMLRange
);
960 OUStringBuffer
aRoleBuffer("error-bars-");
962 aRoleBuffer
.append( sal_Unicode( 'y' ));
964 aRoleBuffer
.append( sal_Unicode( 'x' ));
966 aRoleBuffer
.append( sal_Unicode( '-' ));
969 aRoleBuffer
= aRoleBuffer
.appendAscii( "positive" );
971 aRoleBuffer
= aRoleBuffer
.appendAscii( "negative" );
973 OUString aRole
= aRoleBuffer
.makeStringAndClear();
975 Reference
< beans::XPropertySet
> xSeqProp( xNewSequence
, uno::UNO_QUERY
);
977 xSeqProp
->setPropertyValue("Role", uno::makeAny( aRole
));
979 Reference
< uno::XComponentContext
> xContext
= comphelper::getProcessComponentContext();
981 Reference
< chart2::data::XLabeledDataSequence
> xLabelSeq( chart2::data::LabeledDataSequence::create(xContext
),
982 uno::UNO_QUERY_THROW
);
984 rSequences
.insert( tSchXMLLSequencesPerIndex::value_type(
985 tSchXMLIndexWithPart( -2, SCH_XML_PART_ERROR_BARS
), xLabelSeq
) );
987 xLabelSeq
->setValues( xNewSequence
);
989 uno::Sequence
< Reference
< chart2::data::XLabeledDataSequence
> > aSequences(
990 xDataSource
->getDataSequences());
992 aSequences
.realloc( aSequences
.getLength() + 1 );
993 aSequences
[ aSequences
.getLength() - 1 ] = xLabelSeq
;
994 xDataSink
->setData( aSequences
);
998 SchXMLStatisticsObjectContext::SchXMLStatisticsObjectContext(
1000 SchXMLImportHelper
& rImpHelper
,
1001 SvXMLImport
& rImport
,
1003 const OUString
& rLocalName
,
1004 const OUString
&rSeriesStyleName
,
1005 ::std::list
< DataRowPointStyle
>& rStyleList
,
1006 const ::com::sun::star::uno::Reference
<
1007 ::com::sun::star::chart2::XDataSeries
>& xSeries
,
1008 ContextType eContextType
,
1009 const awt::Size
& rChartSize
,
1010 tSchXMLLSequencesPerIndex
& rLSequencesPerIndex
) :
1012 SvXMLImportContext( rImport
, nPrefix
, rLocalName
),
1013 mrImportHelper( rImpHelper
),
1014 mrStyleList( rStyleList
),
1015 m_xSeries( xSeries
),
1016 meContextType( eContextType
),
1017 maChartSize( rChartSize
),
1018 maSeriesStyleName( rSeriesStyleName
),
1019 mrLSequencesPerIndex(rLSequencesPerIndex
)
1022 SchXMLStatisticsObjectContext::~SchXMLStatisticsObjectContext()
1028 void SetErrorBarPropertiesFromStyleName( const OUString
& aStyleName
, uno::Reference
< beans::XPropertySet
> xBarProp
,
1029 SchXMLImportHelper
& rImportHelper
, OUString
& aPosRange
, OUString
& aNegRange
)
1031 const SvXMLStylesContext
* pStylesCtxt
= rImportHelper
.GetAutoStylesContext();
1032 const SvXMLStyleContext
* pStyle
= pStylesCtxt
->FindStyleChildContext(rImportHelper
.GetChartFamilyID(),
1035 XMLPropStyleContext
* pSeriesStyleContext
=
1036 const_cast< XMLPropStyleContext
* >( dynamic_cast< const XMLPropStyleContext
* >( pStyle
));
1038 uno::Any aAny
= SchXMLTools::getPropertyFromContext("ErrorBarStyle",
1039 pSeriesStyleContext
,pStylesCtxt
);
1041 if ( aAny
.hasValue() )
1043 sal_Int32 aBarStyle
= com::sun::star::chart::ErrorBarStyle::NONE
;
1045 xBarProp
->setPropertyValue("ErrorBarStyle", aAny
);
1047 aAny
= SchXMLTools::getPropertyFromContext("ShowPositiveError",
1048 pSeriesStyleContext
,pStylesCtxt
);
1051 xBarProp
->setPropertyValue("ShowPositiveError",aAny
);
1053 aAny
= SchXMLTools::getPropertyFromContext("ShowNegativeError",
1054 pSeriesStyleContext
,pStylesCtxt
);
1057 xBarProp
->setPropertyValue("ShowNegativeError",aAny
);
1059 aAny
= SchXMLTools::getPropertyFromContext("PositiveError",
1060 pSeriesStyleContext
, pStylesCtxt
);
1063 xBarProp
->setPropertyValue("PositiveError", aAny
);
1066 aAny
= SchXMLTools::getPropertyFromContext("ConstantErrorHigh",
1067 pSeriesStyleContext
, pStylesCtxt
);
1070 xBarProp
->setPropertyValue("PositiveError", aAny
);
1073 aAny
= SchXMLTools::getPropertyFromContext("NegativeError",
1074 pSeriesStyleContext
, pStylesCtxt
);
1077 xBarProp
->setPropertyValue("NegativeError", aAny
);
1080 aAny
= SchXMLTools::getPropertyFromContext("ConstantErrorLow",
1081 pSeriesStyleContext
, pStylesCtxt
);
1084 xBarProp
->setPropertyValue("NegativeError", aAny
);
1087 aAny
= SchXMLTools::getPropertyFromContext("ErrorBarRangePositive",
1088 pSeriesStyleContext
, pStylesCtxt
);
1089 if( aAny
.hasValue() )
1094 aAny
= SchXMLTools::getPropertyFromContext("ErrorBarRangeNegative",
1095 pSeriesStyleContext
, pStylesCtxt
);
1096 if( aAny
.hasValue() )
1101 aAny
= SchXMLTools::getPropertyFromContext("Weight",
1102 pSeriesStyleContext
, pStylesCtxt
);
1103 if( aAny
.hasValue() )
1105 xBarProp
->setPropertyValue("Weight", aAny
);
1108 aAny
= SchXMLTools::getPropertyFromContext("PercentageError",
1109 pSeriesStyleContext
, pStylesCtxt
);
1110 if( aAny
.hasValue() && aBarStyle
== com::sun::star::chart::ErrorBarStyle::RELATIVE
)
1112 xBarProp
->setPropertyValue("PositiveError", aAny
);
1113 xBarProp
->setPropertyValue("NegativeError", aAny
);
1118 case com::sun::star::chart::ErrorBarStyle::ERROR_MARGIN
:
1120 aAny
= SchXMLTools::getPropertyFromContext("NegativeError",
1121 pSeriesStyleContext
,pStylesCtxt
);
1123 xBarProp
->setPropertyValue("NegativeError",aAny
);
1125 aAny
= SchXMLTools::getPropertyFromContext("PositiveError",
1126 pSeriesStyleContext
,pStylesCtxt
);
1128 xBarProp
->setPropertyValue("PositiveError",aAny
);
1140 void SchXMLStatisticsObjectContext::StartElement( const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
)
1142 sal_Int16 nAttrCount
= xAttrList
.is()? xAttrList
->getLength(): 0;
1143 OUString sAutoStyleName
;
1146 bool bYError
= true; /// Default errorbar, to be backward compatible with older files!
1148 for( sal_Int16 i
= 0; i
< nAttrCount
; i
++ )
1150 OUString sAttrName
= xAttrList
->getNameByIndex( i
);
1151 OUString aLocalName
;
1152 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName
, &aLocalName
);
1154 if( nPrefix
== XML_NAMESPACE_CHART
)
1156 if( IsXMLToken( aLocalName
, XML_STYLE_NAME
) )
1157 sAutoStyleName
= xAttrList
->getValueByIndex( i
);
1158 else if( IsXMLToken( aLocalName
, XML_DIMENSION
) )
1159 bYError
= xAttrList
->getValueByIndex(i
) == "y";
1160 else if( IsXMLToken( aLocalName
, XML_ERROR_UPPER_RANGE
) )
1161 aPosRange
= xAttrList
->getValueByIndex(i
);
1162 else if( IsXMLToken( aLocalName
, XML_ERROR_LOWER_RANGE
) )
1163 aNegRange
= xAttrList
->getValueByIndex(i
);
1167 // note: regression-curves must get a style-object even if there is no
1168 // auto-style set, because they can contain an equation
1169 if( !sAutoStyleName
.isEmpty() || meContextType
== CONTEXT_TYPE_REGRESSION_CURVE
)
1171 DataRowPointStyle
aStyle( DataRowPointStyle::MEAN_VALUE
, m_xSeries
, -1, 1, sAutoStyleName
);
1173 switch( meContextType
)
1175 case CONTEXT_TYPE_MEAN_VALUE_LINE
:
1176 aStyle
.meType
= DataRowPointStyle::MEAN_VALUE
;
1178 case CONTEXT_TYPE_REGRESSION_CURVE
:
1179 aStyle
.meType
= DataRowPointStyle::REGRESSION
;
1181 case CONTEXT_TYPE_ERROR_INDICATOR
:
1183 aStyle
.meType
= DataRowPointStyle::ERROR_INDICATOR
;
1186 uno::Reference
< lang::XMultiServiceFactory
> xFact( comphelper::getProcessServiceFactory(),
1189 uno::Reference
< beans::XPropertySet
> xBarProp( xFact
->createInstance("com.sun.star.chart2.ErrorBar" ),
1192 xBarProp
->setPropertyValue("ErrorBarStyle",uno::makeAny(com::sun::star::chart::ErrorBarStyle::NONE
));
1193 xBarProp
->setPropertyValue("PositiveError",uno::makeAny(static_cast<double>(0.0)));
1194 xBarProp
->setPropertyValue("NegativeError",uno::makeAny(static_cast<double>(0.0)));
1195 xBarProp
->setPropertyValue("Weight",uno::makeAny(static_cast<double>(1.0)));
1196 xBarProp
->setPropertyValue("ShowPositiveError",uno::makeAny(sal_True
));
1197 xBarProp
->setPropertyValue("ShowNegativeError",uno::makeAny(sal_True
));
1200 // first import defaults from parent style
1201 SetErrorBarPropertiesFromStyleName( maSeriesStyleName
, xBarProp
, mrImportHelper
, aPosRange
, aNegRange
);
1202 SetErrorBarPropertiesFromStyleName( sAutoStyleName
, xBarProp
, mrImportHelper
, aPosRange
, aNegRange
);
1204 uno::Reference
< chart2::XChartDocument
> xDoc(GetImport().GetModel(),uno::UNO_QUERY
);
1206 if (!aPosRange
.isEmpty())
1207 lcl_setErrorBarSequence(xDoc
,xBarProp
,aPosRange
,true,bYError
, mrLSequencesPerIndex
);
1209 if (!aNegRange
.isEmpty())
1210 lcl_setErrorBarSequence(xDoc
,xBarProp
,aNegRange
,false,bYError
, mrLSequencesPerIndex
);
1214 aStyle
.m_xErrorXProperties
.set( xBarProp
);
1218 aStyle
.m_xErrorYProperties
.set( xBarProp
);
1224 mrStyleList
.push_back( aStyle
);
1228 SvXMLImportContext
* SchXMLStatisticsObjectContext::CreateChildContext(
1230 const OUString
& rLocalName
,
1231 const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
)
1233 SvXMLImportContext
* pContext
= 0;
1235 if( nPrefix
== XML_NAMESPACE_CHART
&&
1236 IsXMLToken( rLocalName
, XML_EQUATION
) )
1238 pContext
= new SchXMLEquationContext(
1239 mrImportHelper
, GetImport(), nPrefix
, rLocalName
, m_xSeries
, maChartSize
, mrStyleList
.back());
1243 pContext
= SvXMLImportContext::CreateChildContext( nPrefix
, rLocalName
, xAttrList
);
1249 // ========================================
1251 SchXMLEquationContext::SchXMLEquationContext(
1252 SchXMLImportHelper
& rImpHelper
,
1253 SvXMLImport
& rImport
,
1255 const OUString
& rLocalName
,
1256 const ::com::sun::star::uno::Reference
<
1257 ::com::sun::star::chart2::XDataSeries
>& xSeries
,
1258 const awt::Size
& rChartSize
,
1259 DataRowPointStyle
& rRegressionStyle
) :
1260 SvXMLImportContext( rImport
, nPrefix
, rLocalName
),
1261 mrImportHelper( rImpHelper
),
1262 mrRegressionStyle( rRegressionStyle
),
1263 m_xSeries( xSeries
),
1264 maChartSize( rChartSize
)
1267 SchXMLEquationContext::~SchXMLEquationContext()
1270 void SchXMLEquationContext::StartElement( const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
)
1273 sal_Int16 nAttrCount
= xAttrList
.is()? xAttrList
->getLength(): 0;
1274 SchXMLImport
& rImport
= ( SchXMLImport
& )GetImport();
1275 const SvXMLTokenMap
& rAttrTokenMap
= mrImportHelper
.GetRegEquationAttrTokenMap();
1276 OUString sAutoStyleName
;
1278 bool bShowEquation
= true;
1279 bool bShowRSquare
= false;
1280 awt::Point aPosition
;
1281 bool bHasXPos
= false;
1282 bool bHasYPos
= false;
1284 for( sal_Int16 i
= 0; i
< nAttrCount
; i
++ )
1286 OUString sAttrName
= xAttrList
->getNameByIndex( i
);
1287 OUString aLocalName
;
1288 OUString aValue
= xAttrList
->getValueByIndex( i
);
1289 sal_uInt16 nPrefix
= rImport
.GetNamespaceMap().GetKeyByAttrName( sAttrName
, &aLocalName
);
1291 switch( rAttrTokenMap
.Get( nPrefix
, aLocalName
))
1293 case XML_TOK_REGEQ_POS_X
:
1294 rImport
.GetMM100UnitConverter().convertMeasureToCore(
1295 aPosition
.X
, aValue
);
1298 case XML_TOK_REGEQ_POS_Y
:
1299 rImport
.GetMM100UnitConverter().convertMeasureToCore(
1300 aPosition
.Y
, aValue
);
1303 case XML_TOK_REGEQ_DISPLAY_EQUATION
:
1304 ::sax::Converter::convertBool(bShowEquation
, aValue
);
1306 case XML_TOK_REGEQ_DISPLAY_R_SQUARE
:
1307 ::sax::Converter::convertBool(bShowRSquare
, aValue
);
1309 case XML_TOK_REGEQ_STYLE_NAME
:
1310 sAutoStyleName
= aValue
;
1315 if( !sAutoStyleName
.isEmpty() || bShowEquation
|| bShowRSquare
)
1317 uno::Reference
< beans::XPropertySet
> xEqProp
= chart2::RegressionEquation::create( comphelper::getProcessComponentContext() );
1319 if( !sAutoStyleName
.isEmpty() )
1321 const SvXMLStylesContext
* pStylesCtxt
= mrImportHelper
.GetAutoStylesContext();
1324 const SvXMLStyleContext
* pStyle
= pStylesCtxt
->FindStyleChildContext(
1325 mrImportHelper
.GetChartFamilyID(), sAutoStyleName
);
1326 // note: SvXMLStyleContext::FillPropertySet is not const
1327 XMLPropStyleContext
* pPropStyleContext
=
1328 const_cast< XMLPropStyleContext
* >( dynamic_cast< const XMLPropStyleContext
* >( pStyle
));
1330 if( pPropStyleContext
)
1331 pPropStyleContext
->FillPropertySet( xEqProp
);
1334 xEqProp
->setPropertyValue( OUString( "ShowEquation"), uno::makeAny( bShowEquation
));
1335 xEqProp
->setPropertyValue( OUString( "ShowCorrelationCoefficient"), uno::makeAny( bShowRSquare
));
1337 if( bHasXPos
&& bHasYPos
)
1339 chart2::RelativePosition aRelPos
;
1340 aRelPos
.Primary
= static_cast< double >( aPosition
.X
) / static_cast< double >( maChartSize
.Width
);
1341 aRelPos
.Secondary
= static_cast< double >( aPosition
.Y
) / static_cast< double >( maChartSize
.Height
);
1342 xEqProp
->setPropertyValue( OUString( "RelativePosition" ),
1343 uno::makeAny( aRelPos
));
1345 SAL_WARN_IF( mrRegressionStyle
.meType
!= DataRowPointStyle::REGRESSION
, "xmloff.chart", "mrRegressionStyle.meType != DataRowPointStyle::REGRESSION" );
1346 mrRegressionStyle
.m_xEquationProperties
.set( xEqProp
);
1350 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */