Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / xmloff / source / chart / SchXMLRegressionCurveObjectContext.cxx
blob885f5336a610da97ca24c983ea1013b878a51f66
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include "SchXMLRegressionCurveObjectContext.hxx"
22 #include <sax/tools/converter.hxx>
24 #include <xmloff/nmspmap.hxx>
25 #include <xmloff/xmlnmspe.hxx>
26 #include <xmloff/xmlement.hxx>
27 #include <xmloff/xmluconv.hxx>
28 #include <xmloff/prstylei.hxx>
29 #include <xmloff/xmlstyle.hxx>
31 #include <comphelper/processfactory.hxx>
33 #include <com/sun/star/chart2/RegressionEquation.hpp>
34 #include <com/sun/star/chart2/RelativePosition.hpp>
36 using namespace com::sun::star;
37 using namespace xmloff::token;
39 SchXMLRegressionCurveObjectContext::SchXMLRegressionCurveObjectContext(
40 SchXMLImportHelper& rImpHelper,
41 SvXMLImport& rImport,
42 sal_uInt16 nPrefix,
43 const OUString& rLocalName,
44 std::list< RegressionStyle >& rRegressionStyleList,
45 const css::uno::Reference<
46 css::chart2::XDataSeries >& xSeries,
47 const awt::Size & rChartSize) :
48 SvXMLImportContext( rImport, nPrefix, rLocalName ),
49 mrImportHelper( rImpHelper ),
50 mxSeries( xSeries ),
51 maChartSize( rChartSize ),
52 mrRegressionStyleList( rRegressionStyleList )
56 SchXMLRegressionCurveObjectContext::~SchXMLRegressionCurveObjectContext()
60 void SchXMLRegressionCurveObjectContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttributeList )
62 sal_Int16 nAttributeCount = xAttributeList.is()? xAttributeList->getLength(): 0;
63 OUString sAutoStyleName;
65 for( sal_Int16 i = 0; i < nAttributeCount; i++ )
67 OUString sAttributeName = xAttributeList->getNameByIndex( i );
68 OUString aLocalName;
70 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttributeName, &aLocalName );
72 if( nPrefix == XML_NAMESPACE_CHART )
74 if( IsXMLToken( aLocalName, XML_STYLE_NAME ) )
76 sAutoStyleName = xAttributeList->getValueByIndex( i );
81 RegressionStyle aStyle( mxSeries, sAutoStyleName );
82 mrRegressionStyleList.push_back( aStyle );
85 SvXMLImportContext* SchXMLRegressionCurveObjectContext::CreateChildContext(
86 sal_uInt16 nPrefix,
87 const OUString& rLocalName,
88 const uno::Reference< xml::sax::XAttributeList >& xAttrList )
90 SvXMLImportContext* pContext = nullptr;
92 if( nPrefix == XML_NAMESPACE_CHART && IsXMLToken( rLocalName, XML_EQUATION ) )
94 pContext = new SchXMLEquationContext(
95 mrImportHelper, GetImport(), nPrefix, rLocalName, maChartSize, mrRegressionStyleList.back());
97 else
99 pContext = SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList );
102 return pContext;
105 SchXMLEquationContext::SchXMLEquationContext(
106 SchXMLImportHelper& rImpHelper,
107 SvXMLImport& rImport,
108 sal_uInt16 nPrefix,
109 const OUString& rLocalName,
110 const awt::Size& rChartSize,
111 RegressionStyle& rRegressionStyle ) :
113 SvXMLImportContext( rImport, nPrefix, rLocalName ),
114 mrImportHelper( rImpHelper ),
115 mrRegressionStyle( rRegressionStyle ),
116 maChartSize( rChartSize )
119 SchXMLEquationContext::~SchXMLEquationContext()
122 void SchXMLEquationContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
124 // parse attributes
125 sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
126 SchXMLImport& rImport = static_cast< SchXMLImport& >(GetImport());
127 const SvXMLTokenMap& rAttrTokenMap = mrImportHelper.GetRegEquationAttrTokenMap();
128 OUString sAutoStyleName;
130 bool bShowEquation = true;
131 bool bShowRSquare = false;
132 awt::Point aPosition;
133 bool bHasXPos = false;
134 bool bHasYPos = false;
136 for( sal_Int16 i = 0; i < nAttrCount; i++ )
138 OUString sAttrName = xAttrList->getNameByIndex( i );
139 OUString aLocalName;
140 OUString aValue = xAttrList->getValueByIndex( i );
141 sal_uInt16 nPrefix = rImport.GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
143 switch( rAttrTokenMap.Get( nPrefix, aLocalName ))
145 case XML_TOK_REGEQ_POS_X:
146 rImport.GetMM100UnitConverter().convertMeasureToCore(
147 aPosition.X, aValue );
148 bHasXPos = true;
149 break;
150 case XML_TOK_REGEQ_POS_Y:
151 rImport.GetMM100UnitConverter().convertMeasureToCore(
152 aPosition.Y, aValue );
153 bHasYPos = true;
154 break;
155 case XML_TOK_REGEQ_DISPLAY_EQUATION:
156 ::sax::Converter::convertBool(bShowEquation, aValue);
157 break;
158 case XML_TOK_REGEQ_DISPLAY_R_SQUARE:
159 ::sax::Converter::convertBool(bShowRSquare, aValue);
160 break;
161 case XML_TOK_REGEQ_STYLE_NAME:
162 sAutoStyleName = aValue;
163 break;
167 if( !sAutoStyleName.isEmpty() || bShowEquation || bShowRSquare )
169 uno::Reference< beans::XPropertySet > xEqationProperties = chart2::RegressionEquation::create( comphelper::getProcessComponentContext() );
171 if( !sAutoStyleName.isEmpty() )
173 const SvXMLStylesContext* pStylesCtxt = mrImportHelper.GetAutoStylesContext();
174 if( pStylesCtxt )
176 const SvXMLStyleContext* pStyle = pStylesCtxt->FindStyleChildContext(
177 SchXMLImportHelper::GetChartFamilyID(), sAutoStyleName );
179 XMLPropStyleContext* pPropStyleContext =
180 const_cast< XMLPropStyleContext* >( dynamic_cast< const XMLPropStyleContext* >( pStyle ));
182 if( pPropStyleContext )
183 pPropStyleContext->FillPropertySet( xEqationProperties );
186 xEqationProperties->setPropertyValue( "ShowEquation", uno::makeAny( bShowEquation ));
187 xEqationProperties->setPropertyValue( "ShowCorrelationCoefficient", uno::makeAny( bShowRSquare ));
189 if( bHasXPos && bHasYPos )
191 chart2::RelativePosition aRelPos;
192 aRelPos.Primary = static_cast< double >( aPosition.X ) / static_cast< double >( maChartSize.Width );
193 aRelPos.Secondary = static_cast< double >( aPosition.Y ) / static_cast< double >( maChartSize.Height );
194 xEqationProperties->setPropertyValue( "RelativePosition", uno::makeAny( aRelPos ));
196 mrRegressionStyle.m_xEquationProperties.set( xEqationProperties );
200 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */