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

Generated by: LCOV version 1.10