LCOV - code coverage report
Current view: top level - xmloff/source/chart - SchXMLRegressionCurveObjectContext.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 80 0.0 %
Date: 2014-04-14 Functions: 0 9 0.0 %
Legend: Lines: hit not hit

          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 "SchXMLRegressionCurveObjectContext.hxx"
      21             : 
      22             : #include <sax/tools/converter.hxx>
      23             : 
      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>
      30             : 
      31             : #include <comphelper/processfactory.hxx>
      32             : 
      33             : #include <com/sun/star/chart2/RegressionEquation.hpp>
      34             : #include <com/sun/star/chart2/RelativePosition.hpp>
      35             : 
      36             : using namespace com::sun::star;
      37             : using namespace xmloff::token;
      38             : 
      39             : using com::sun::star::uno::Reference;
      40             : 
      41           0 : SchXMLRegressionCurveObjectContext::SchXMLRegressionCurveObjectContext(
      42             :                                         SchXMLImportHelper& rImpHelper,
      43             :                                         SvXMLImport& rImport,
      44             :                                         sal_uInt16 nPrefix,
      45             :                                         const OUString& rLocalName,
      46             :                                         const OUString &rSeriesStyleName,
      47             :                                         std::list< RegressionStyle >& rRegressionStyleList,
      48             :                                         const css::uno::Reference<
      49             :                                                     css::chart2::XDataSeries >& xSeries,
      50             :                                         const awt::Size & rChartSize) :
      51             :     SvXMLImportContext( rImport, nPrefix, rLocalName ),
      52             :     mrImportHelper( rImpHelper ),
      53             :     mxSeries( xSeries ),
      54             :     maChartSize( rChartSize ),
      55             :     maSeriesStyleName( rSeriesStyleName),
      56           0 :     mrRegressionStyleList( rRegressionStyleList )
      57             : {
      58           0 : }
      59             : 
      60           0 : SchXMLRegressionCurveObjectContext::~SchXMLRegressionCurveObjectContext()
      61             : {
      62           0 : }
      63             : 
      64           0 : void SchXMLRegressionCurveObjectContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttributeList )
      65             : {
      66           0 :     sal_Int16 nAttributeCount = xAttributeList.is()? xAttributeList->getLength(): 0;
      67           0 :     OUString sAutoStyleName;
      68             : 
      69           0 :     for( sal_Int16 i = 0; i < nAttributeCount; i++ )
      70             :     {
      71           0 :         OUString sAttributeName = xAttributeList->getNameByIndex( i );
      72           0 :         OUString aLocalName;
      73             : 
      74           0 :         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttributeName, &aLocalName );
      75             : 
      76           0 :         if( nPrefix == XML_NAMESPACE_CHART )
      77             :         {
      78           0 :             if( IsXMLToken( aLocalName, XML_STYLE_NAME ) )
      79             :             {
      80           0 :                 sAutoStyleName = xAttributeList->getValueByIndex( i );
      81             :             }
      82             :         }
      83           0 :     }
      84             : 
      85           0 :     RegressionStyle aStyle( mxSeries, sAutoStyleName );
      86           0 :     mrRegressionStyleList.push_back( aStyle );
      87           0 : }
      88             : 
      89           0 : SvXMLImportContext* SchXMLRegressionCurveObjectContext::CreateChildContext(
      90             :     sal_uInt16 nPrefix,
      91             :     const OUString& rLocalName,
      92             :     const uno::Reference< xml::sax::XAttributeList >& xAttrList )
      93             : {
      94           0 :     SvXMLImportContext* pContext = 0;
      95             : 
      96           0 :     if( nPrefix == XML_NAMESPACE_CHART && IsXMLToken( rLocalName, XML_EQUATION ) )
      97             :     {
      98             :         pContext = new SchXMLEquationContext(
      99           0 :             mrImportHelper, GetImport(), nPrefix, rLocalName, mxSeries, maChartSize, mrRegressionStyleList.back());
     100             :     }
     101             :     else
     102             :     {
     103           0 :         pContext = SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList );
     104             :     }
     105             : 
     106           0 :     return pContext;
     107             : }
     108             : 
     109           0 : SchXMLEquationContext::SchXMLEquationContext(
     110             :     SchXMLImportHelper& rImpHelper,
     111             :     SvXMLImport& rImport,
     112             :     sal_uInt16 nPrefix,
     113             :     const OUString& rLocalName,
     114             :     const css::uno::Reference<
     115             :         css::chart2::XDataSeries >& xSeries,
     116             :     const awt::Size& rChartSize,
     117             :     RegressionStyle& rRegressionStyle ) :
     118             : 
     119             :         SvXMLImportContext( rImport, nPrefix, rLocalName ),
     120             :         mrImportHelper( rImpHelper ),
     121             :         mrRegressionStyle( rRegressionStyle ),
     122             :         mxSeries( xSeries ),
     123           0 :         maChartSize( rChartSize )
     124           0 : {}
     125             : 
     126           0 : SchXMLEquationContext::~SchXMLEquationContext()
     127           0 : {}
     128             : 
     129           0 : void SchXMLEquationContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
     130             : {
     131             :     // parse attributes
     132           0 :     sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
     133           0 :     SchXMLImport& rImport = ( SchXMLImport& )GetImport();
     134           0 :     const SvXMLTokenMap& rAttrTokenMap = mrImportHelper.GetRegEquationAttrTokenMap();
     135           0 :     OUString sAutoStyleName;
     136             : 
     137           0 :     bool bShowEquation = true;
     138           0 :     bool bShowRSquare = false;
     139           0 :     awt::Point aPosition;
     140           0 :     bool bHasXPos = false;
     141           0 :     bool bHasYPos = false;
     142             : 
     143           0 :     for( sal_Int16 i = 0; i < nAttrCount; i++ )
     144             :     {
     145           0 :         OUString sAttrName = xAttrList->getNameByIndex( i );
     146           0 :         OUString aLocalName;
     147           0 :         OUString aValue = xAttrList->getValueByIndex( i );
     148           0 :         sal_uInt16 nPrefix = rImport.GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
     149             : 
     150           0 :         switch( rAttrTokenMap.Get( nPrefix, aLocalName ))
     151             :         {
     152             :             case XML_TOK_REGEQ_POS_X:
     153           0 :                 rImport.GetMM100UnitConverter().convertMeasureToCore(
     154           0 :                         aPosition.X, aValue );
     155           0 :                 bHasXPos = true;
     156           0 :                 break;
     157             :             case XML_TOK_REGEQ_POS_Y:
     158           0 :                 rImport.GetMM100UnitConverter().convertMeasureToCore(
     159           0 :                         aPosition.Y, aValue );
     160           0 :                 bHasYPos = true;
     161           0 :                 break;
     162             :             case XML_TOK_REGEQ_DISPLAY_EQUATION:
     163           0 :                 ::sax::Converter::convertBool(bShowEquation, aValue);
     164           0 :                 break;
     165             :             case XML_TOK_REGEQ_DISPLAY_R_SQUARE:
     166           0 :                 ::sax::Converter::convertBool(bShowRSquare, aValue);
     167           0 :                 break;
     168             :             case XML_TOK_REGEQ_STYLE_NAME:
     169           0 :                 sAutoStyleName = aValue;
     170           0 :                 break;
     171             :         }
     172           0 :     }
     173             : 
     174           0 :     if( !sAutoStyleName.isEmpty() || bShowEquation || bShowRSquare )
     175             :     {
     176           0 :         uno::Reference< beans::XPropertySet > xEqationProperties = chart2::RegressionEquation::create( comphelper::getProcessComponentContext() );
     177             : 
     178           0 :         if( !sAutoStyleName.isEmpty() )
     179             :         {
     180           0 :             const SvXMLStylesContext* pStylesCtxt = mrImportHelper.GetAutoStylesContext();
     181           0 :             if( pStylesCtxt )
     182             :             {
     183             :                 const SvXMLStyleContext* pStyle = pStylesCtxt->FindStyleChildContext(
     184           0 :                     mrImportHelper.GetChartFamilyID(), sAutoStyleName );
     185             : 
     186             :                 XMLPropStyleContext* pPropStyleContext =
     187           0 :                     const_cast< XMLPropStyleContext* >( dynamic_cast< const XMLPropStyleContext* >( pStyle ));
     188             : 
     189           0 :                 if( pPropStyleContext )
     190           0 :                     pPropStyleContext->FillPropertySet( xEqationProperties );
     191             :             }
     192             :         }
     193           0 :         xEqationProperties->setPropertyValue( OUString( "ShowEquation"), uno::makeAny( bShowEquation ));
     194           0 :         xEqationProperties->setPropertyValue( OUString( "ShowCorrelationCoefficient"), uno::makeAny( bShowRSquare ));
     195             : 
     196           0 :         if( bHasXPos && bHasYPos )
     197             :         {
     198           0 :             chart2::RelativePosition aRelPos;
     199           0 :             aRelPos.Primary = static_cast< double >( aPosition.X ) / static_cast< double >( maChartSize.Width );
     200           0 :             aRelPos.Secondary = static_cast< double >( aPosition.Y ) / static_cast< double >( maChartSize.Height );
     201           0 :             xEqationProperties->setPropertyValue( OUString(  "RelativePosition" ), uno::makeAny( aRelPos ));
     202             :         }
     203           0 :         mrRegressionStyle.m_xEquationProperties.set( xEqationProperties );
     204           0 :     }
     205           0 : }
     206             : 
     207             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10