LibreOffice Module xmloff (master)  1
SchXMLRegressionCurveObjectContext.cxx
Go to the documentation of this file.
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 
21 
22 #include <SchXMLImport.hxx>
23 
24 #include <sax/tools/converter.hxx>
25 #include <sal/log.hxx>
26 
27 #include <xmloff/namespacemap.hxx>
28 #include <xmloff/xmlnamespace.hxx>
29 #include <xmloff/xmluconv.hxx>
30 #include <xmloff/prstylei.hxx>
31 #include <xmloff/xmlstyle.hxx>
32 
34 
35 #include <com/sun/star/awt/Point.hpp>
36 #include <com/sun/star/chart2/RegressionEquation.hpp>
37 #include <com/sun/star/chart2/RelativePosition.hpp>
38 #include <com/sun/star/xml/sax/XAttributeList.hpp>
39 
40 using namespace com::sun::star;
41 using namespace xmloff::token;
42 
44  SchXMLImportHelper& rImpHelper,
45  SvXMLImport& rImport,
46  std::vector< RegressionStyle >& rRegressionStyleVector,
47  const css::uno::Reference<
48  css::chart2::XDataSeries >& xSeries,
49  const awt::Size & rChartSize) :
50  SvXMLImportContext( rImport ),
51  mrImportHelper( rImpHelper ),
52  mxSeries( xSeries ),
53  maChartSize( rChartSize ),
54  mrRegressionStyleVector( rRegressionStyleVector )
55 {
56 }
57 
59 {
60 }
61 
63  const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList)
64 {
65  OUString sAutoStyleName;
66  for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
67  {
68  if (aIter.getToken() == XML_ELEMENT(CHART, XML_STYLE_NAME) )
69  sAutoStyleName = aIter.toString();
70  else
71  XMLOFF_WARN_UNKNOWN("xmloff", aIter);
72  }
73 
74  RegressionStyle aStyle( mxSeries, sAutoStyleName );
75  mrRegressionStyleVector.push_back( aStyle );
76 }
77 
78 css::uno::Reference< css::xml::sax::XFastContextHandler > SchXMLRegressionCurveObjectContext::createFastChildContext(
79  sal_Int32 nElement,
80  const css::uno::Reference< css::xml::sax::XFastAttributeList >& )
81 {
82  if( nElement == XML_ELEMENT(CHART, XML_EQUATION) )
83  {
84  return new SchXMLEquationContext(
86  }
87  else
88  XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
89  return nullptr;
90 }
91 
93  SchXMLImportHelper& rImpHelper,
94  SvXMLImport& rImport,
95  const awt::Size& rChartSize,
96  RegressionStyle& rRegressionStyle ) :
97  SvXMLImportContext( rImport ),
98  mrImportHelper( rImpHelper ),
99  mrRegressionStyle( rRegressionStyle ),
100  maChartSize( rChartSize )
101 {}
102 
104 {}
105 
106 void SchXMLEquationContext::startFastElement (sal_Int32 /*nElement*/,
107  const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList)
108 {
109  // parse attributes
110  SchXMLImport& rImport = static_cast< SchXMLImport& >(GetImport());
111  OUString sAutoStyleName;
112  bool bShowEquation = true;
113  bool bShowRSquare = false;
114  awt::Point aPosition;
115  bool bHasXPos = false;
116  bool bHasYPos = false;
117 
118  for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
119  {
120  switch(aIter.getToken())
121  {
122  case XML_ELEMENT(SVG, XML_X):
123  case XML_ELEMENT(SVG_COMPAT, XML_X):
125  aPosition.X, aIter.toView() );
126  bHasXPos = true;
127  break;
128  case XML_ELEMENT(SVG, XML_Y):
129  case XML_ELEMENT(SVG_COMPAT, XML_Y):
131  aPosition.Y, aIter.toView() );
132  bHasYPos = true;
133  break;
135  (void)::sax::Converter::convertBool(bShowEquation, aIter.toView());
136  break;
138  (void)::sax::Converter::convertBool(bShowRSquare, aIter.toView());
139  break;
141  sAutoStyleName = aIter.toString();
142  break;
143  default:
144  XMLOFF_WARN_UNKNOWN("xmloff", aIter);
145  }
146  }
147 
148  if( sAutoStyleName.isEmpty() && !bShowEquation && !bShowRSquare )
149  return;
150 
151  uno::Reference< beans::XPropertySet > xEquationProperties = chart2::RegressionEquation::create( comphelper::getProcessComponentContext() );
152 
153  if( !sAutoStyleName.isEmpty() )
154  {
156  if( pStylesCtxt )
157  {
158  const SvXMLStyleContext* pStyle = pStylesCtxt->FindStyleChildContext(
159  SchXMLImportHelper::GetChartFamilyID(), sAutoStyleName );
160 
161  XMLPropStyleContext* pPropStyleContext =
162  const_cast< XMLPropStyleContext* >( dynamic_cast< const XMLPropStyleContext* >( pStyle ));
163 
164  if( pPropStyleContext )
165  pPropStyleContext->FillPropertySet( xEquationProperties );
166  }
167  }
168  xEquationProperties->setPropertyValue( "ShowEquation", uno::makeAny( bShowEquation ));
169  xEquationProperties->setPropertyValue( "ShowCorrelationCoefficient", uno::makeAny( bShowRSquare ));
170 
171  if( bHasXPos && bHasYPos )
172  {
173  chart2::RelativePosition aRelPos;
174  aRelPos.Primary = static_cast< double >( aPosition.X ) / static_cast< double >( maChartSize.Width );
175  aRelPos.Secondary = static_cast< double >( aPosition.Y ) / static_cast< double >( maChartSize.Height );
176  xEquationProperties->setPropertyValue( "RelativePosition", uno::makeAny( aRelPos ));
177  }
178  mrRegressionStyle.m_xEquationProperties.set( xEquationProperties );
179 }
180 
181 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool convertMeasureToCore(sal_Int32 &rValue, std::u16string_view rString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32) const
convert string to measure with meCoreMeasureUnit, using optional min and max values ...
Definition: xmluconv.cxx:186
css::uno::Reference< css::chart2::XDataSeries > mxSeries
SvXMLStylesContext * GetAutoStylesContext() const
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:59
css::uno::Reference< css::beans::XPropertySet > m_xEquationProperties
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
SchXMLEquationContext(SchXMLImportHelper &rImportHelper, SvXMLImport &rImport, const css::awt::Size &rChartSize, RegressionStyle &rRegressionStyle)
#define XMLOFF_WARN_UNKNOWN(area, rIter)
Definition: xmlictxt.hxx:113
virtual void FillPropertySet(const css::uno::Reference< css::beans::XPropertySet > &rPropSet)
Definition: prstylei.cxx:222
virtual void SAL_CALL startFastElement(sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
std::vector< RegressionStyle > & mrRegressionStyleVector
static XmlStyleFamily GetChartFamilyID()
With this class you can import a element containing its data as element o...
static bool convertBool(bool &rBool, std::u16string_view rString)
This class deliberately does not support XWeak, to improve performance when loading large documents...
Definition: xmlictxt.hxx:44
Handling of tokens in XML:
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:97
const SvXMLUnitConverter & GetMM100UnitConverter() const
Definition: xmlimp.hxx:400
Reference< XComponentContext > getProcessComponentContext()
const SvXMLStyleContext * FindStyleChildContext(XmlStyleFamily nFamily, const OUString &rName, bool bCreateIndex=false) const
Definition: xmlstyle.cxx:791
#define XMLOFF_WARN_UNKNOWN_ELEMENT(area, token)
Definition: xmlictxt.hxx:119
SchXMLRegressionCurveObjectContext(SchXMLImportHelper &rImportHelper, SvXMLImport &rImport, std::vector< RegressionStyle > &rRegressionStyleVector, const css::uno::Reference< css::chart2::XDataSeries > &xSeries, const css::awt::Size &rChartSize)
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo