LCOV - code coverage report
Current view: top level - xmloff/source/chart - SchXMLSeries2Context.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 396 492 80.5 %
Date: 2015-06-13 12:38:46 Functions: 25 26 96.2 %
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 "SchXMLSeries2Context.hxx"
      21             : #include "SchXMLPlotAreaContext.hxx"
      22             : #include "SchXMLRegressionCurveObjectContext.hxx"
      23             : #include "SchXMLPropertyMappingContext.hxx"
      24             : #include "SchXMLTools.hxx"
      25             : #include "PropertyMap.hxx"
      26             : 
      27             : #include <com/sun/star/chart2/XChartDocument.hpp>
      28             : #include <com/sun/star/chart2/XDataSeries.hpp>
      29             : #include <com/sun/star/chart2/XRegressionCurve.hpp>
      30             : #include <com/sun/star/chart2/XRegressionCurveContainer.hpp>
      31             : #include <com/sun/star/chart2/data/XDataSink.hpp>
      32             : #include <com/sun/star/chart2/data/XDataReceiver.hpp>
      33             : 
      34             : #include <com/sun/star/chart/ChartAxisAssign.hpp>
      35             : #include <com/sun/star/chart/ChartSymbolType.hpp>
      36             : #include <com/sun/star/container/XChild.hpp>
      37             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      38             : #include <com/sun/star/chart/ChartLegendPosition.hpp>
      39             : #include <com/sun/star/drawing/LineStyle.hpp>
      40             : #include <com/sun/star/embed/Aspects.hpp>
      41             : #include <com/sun/star/embed/XVisualObject.hpp>
      42             : #include <com/sun/star/uno/XComponentContext.hpp>
      43             : 
      44             : #include <comphelper/processfactory.hxx>
      45             : 
      46             : #include <rtl/ustrbuf.hxx>
      47             : #include <xmloff/xmlnmspe.hxx>
      48             : #include <xmloff/xmlimp.hxx>
      49             : #include <xmloff/nmspmap.hxx>
      50             : #include <xmloff/SchXMLSeriesHelper.hxx>
      51             : #include "SchXMLImport.hxx"
      52             : #include <xmloff/prstylei.hxx>
      53             : #include <xmloff/xmlprmap.hxx>
      54             : 
      55             : #include <typeinfo>
      56             : 
      57             : using namespace ::com::sun::star;
      58             : using namespace ::xmloff::token;
      59             : 
      60             : using ::com::sun::star::uno::Reference;
      61             : using ::com::sun::star::uno::Sequence;
      62             : 
      63             : namespace
      64             : {
      65             : 
      66             : class SchXMLDomain2Context : public SvXMLImportContext
      67             : {
      68             : private:
      69             :     ::std::vector< OUString > & mrAddresses;
      70             : 
      71             : public:
      72             :     SchXMLDomain2Context( SvXMLImport& rImport,
      73             :                           sal_uInt16 nPrefix,
      74             :                           const OUString& rLocalName,
      75             :                           ::std::vector< OUString > & rAddresses );
      76             :     virtual ~SchXMLDomain2Context();
      77             :     virtual void StartElement( const Reference< xml::sax::XAttributeList >& xAttrList ) SAL_OVERRIDE;
      78             : };
      79             : 
      80          28 : SchXMLDomain2Context::SchXMLDomain2Context(
      81             :     SvXMLImport& rImport,
      82             :     sal_uInt16 nPrefix,
      83             :     const OUString& rLocalName,
      84             :     ::std::vector< OUString > & rAddresses ) :
      85             :         SvXMLImportContext( rImport, nPrefix, rLocalName ),
      86          28 :         mrAddresses( rAddresses )
      87             : {
      88          28 : }
      89             : 
      90          56 : SchXMLDomain2Context::~SchXMLDomain2Context()
      91             : {
      92          56 : }
      93             : 
      94          28 : void SchXMLDomain2Context::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
      95             : {
      96          28 :     sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
      97             : 
      98          56 :     for( sal_Int16 i = 0; i < nAttrCount; i++ )
      99             :     {
     100          28 :         OUString sAttrName = xAttrList->getNameByIndex( i );
     101          56 :         OUString aLocalName;
     102          28 :         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
     103             : 
     104          56 :         if( nPrefix == XML_NAMESPACE_TABLE &&
     105          28 :             IsXMLToken( aLocalName, XML_CELL_RANGE_ADDRESS ) )
     106             :         {
     107          28 :             Reference< chart2::XChartDocument > xNewDoc( GetImport().GetModel(), uno::UNO_QUERY );
     108          28 :             mrAddresses.push_back( xAttrList->getValueByIndex( i ));
     109             :         }
     110          28 :     }
     111          28 : }
     112             : 
     113           1 : void lcl_setAutomaticSymbolSize( const uno::Reference< beans::XPropertySet >& xSeriesOrPointProp, const SvXMLImport& rImport )
     114             : {
     115           1 :     awt::Size aSymbolSize(140,140);//old default for standard sized charts 7cm height
     116             : 
     117           1 :     uno::Reference< chart::XChartDocument > xChartDoc( rImport.GetModel(), uno::UNO_QUERY );
     118           1 :     if( xChartDoc.is() )
     119             :     {
     120           1 :         double fScale = 1;
     121           1 :         uno::Reference< beans::XPropertySet > xLegendProp( xChartDoc->getLegend(), uno::UNO_QUERY );
     122           1 :         chart::ChartLegendPosition aLegendPosition = chart::ChartLegendPosition_NONE;
     123           3 :         if( xLegendProp.is() && (xLegendProp->getPropertyValue("Alignment") >>= aLegendPosition)
     124           3 :             && chart::ChartLegendPosition_NONE != aLegendPosition )
     125             :         {
     126             : 
     127           1 :             double fFontHeight = 6.0;
     128           1 :             if( xLegendProp->getPropertyValue("CharHeight") >>= fFontHeight )
     129           1 :                 fScale = 0.75*fFontHeight/6.0;
     130             :         }
     131             :         else
     132             :         {
     133           0 :             uno::Reference< embed::XVisualObject > xVisualObject( rImport.GetModel(), uno::UNO_QUERY );
     134           0 :             if( xVisualObject.is() )
     135             :             {
     136           0 :                 awt::Size aPageSize( xVisualObject->getVisualAreaSize( embed::Aspects::MSOLE_CONTENT ) );
     137           0 :                 fScale = aPageSize.Height/7000.0;
     138           0 :             }
     139             :         }
     140           1 :         if( fScale>0 )
     141             :         {
     142           1 :             aSymbolSize.Height = static_cast<sal_Int32>( fScale * aSymbolSize.Height );
     143           1 :             aSymbolSize.Width = aSymbolSize.Height;
     144           1 :         }
     145             :     }
     146           1 :     xSeriesOrPointProp->setPropertyValue("SymbolSize",uno::makeAny( aSymbolSize ));
     147           1 : }
     148             : 
     149         176 : void lcl_setSymbolSizeIfNeeded( const uno::Reference< beans::XPropertySet >& xSeriesOrPointProp, const SvXMLImport& rImport )
     150             : {
     151         176 :     if( !xSeriesOrPointProp.is() )
     152         176 :         return;
     153             : 
     154         176 :     sal_Int32 nSymbolType = chart::ChartSymbolType::NONE;
     155         176 :     if( xSeriesOrPointProp.is() && ( xSeriesOrPointProp->getPropertyValue("SymbolType") >>= nSymbolType) )
     156             :     {
     157         176 :         if(chart::ChartSymbolType::NONE!=nSymbolType)
     158             :         {
     159           1 :             if( chart::ChartSymbolType::BITMAPURL==nSymbolType )
     160             :             {
     161             :                 //set special size for graphics to indicate to use the bitmap size itself
     162           0 :                 xSeriesOrPointProp->setPropertyValue("SymbolSize",uno::makeAny( awt::Size(-1,-1) ));
     163             :             }
     164             :             else
     165             :             {
     166           1 :                 lcl_setAutomaticSymbolSize( xSeriesOrPointProp, rImport );
     167             :             }
     168             :         }
     169             :     }
     170             : }
     171             : 
     172          64 : void lcl_resetSymbolSizeForPointsIfNecessary( const uno::Reference< beans::XPropertySet >& xPointProp, const SvXMLImport& rImport
     173             :     , const XMLPropStyleContext * pPropStyleContext, const SvXMLStylesContext* pStylesCtxt )
     174             : {
     175          64 :     uno::Any aASymbolSize( SchXMLTools::getPropertyFromContext( OUString("SymbolSize"), pPropStyleContext, pStylesCtxt ) );
     176          64 :     if( !aASymbolSize.hasValue() )
     177          64 :         lcl_setSymbolSizeIfNeeded( xPointProp, rImport );
     178          64 : }
     179             : 
     180           3 : void lcl_insertErrorBarLSequencesToMap(
     181             :     tSchXMLLSequencesPerIndex & rInOutMap,
     182             :     const uno::Reference< beans::XPropertySet > & xSeriesProp,
     183             :     bool bYError = true )
     184             : {
     185           3 :     Reference< chart2::data::XDataSource > xErrorBarSource;
     186             :     const OUString aPropName(
     187             :         bYError
     188             :         ? OUString(  "ErrorBarY" )
     189           6 :         : OUString(  "ErrorBarX" ));
     190           6 :     if( ( xSeriesProp->getPropertyValue( aPropName ) >>= xErrorBarSource ) &&
     191           3 :         xErrorBarSource.is() )
     192             :     {
     193             :         Sequence< Reference< chart2::data::XLabeledDataSequence > > aLSequences(
     194           3 :             xErrorBarSource->getDataSequences());
     195           9 :         for( sal_Int32 nIndex = 0; nIndex < aLSequences.getLength(); ++nIndex )
     196             :         {
     197             :             // use "0" as data index. This is ok, as it is not used for error bars
     198             :             rInOutMap.insert(
     199             :                 tSchXMLLSequencesPerIndex::value_type(
     200           6 :                     tSchXMLIndexWithPart( 0, SCH_XML_PART_ERROR_BARS ), aLSequences[ nIndex ] ));
     201           3 :         }
     202           3 :     }
     203           3 : }
     204             : 
     205          33 : Reference< chart2::data::XLabeledDataSequence2 > lcl_createAndAddSequenceToSeries( const OUString& rRole
     206             :         , const OUString& rRange
     207             :         , const Reference< chart2::XChartDocument >& xChartDoc
     208             :         , const Reference< chart2::XDataSeries >& xSeries )
     209             : {
     210          33 :     Reference< chart2::data::XLabeledDataSequence2 > xLabeledSeq;
     211             : 
     212          66 :     Reference< chart2::data::XDataSource > xSeriesSource( xSeries,uno::UNO_QUERY );
     213          66 :     Reference< chart2::data::XDataSink > xSeriesSink( xSeries, uno::UNO_QUERY );
     214             : 
     215          33 :     if( !(!rRange.isEmpty() && xChartDoc.is() && xSeriesSource.is() && xSeriesSink.is()) )
     216           0 :         return xLabeledSeq;
     217             : 
     218             :     // create a new sequence
     219          33 :     xLabeledSeq = SchXMLTools::GetNewLabeledDataSequence();
     220             : 
     221             :     // set values at the new sequence
     222          66 :     Reference< chart2::data::XDataSequence > xSeq = SchXMLTools::CreateDataSequence( rRange, xChartDoc );
     223          66 :     Reference< beans::XPropertySet > xSeqProp( xSeq, uno::UNO_QUERY );
     224          33 :     if( xSeqProp.is())
     225          33 :         xSeqProp->setPropertyValue("Role", uno::makeAny( rRole));
     226          33 :     xLabeledSeq->setValues( xSeq );
     227             : 
     228             :     // add new sequence to data series / push to front to have the correct sequence order if charttype is changed afterwards
     229          66 :     Sequence< Reference< chart2::data::XLabeledDataSequence > > aOldSeq( xSeriesSource->getDataSequences());
     230          33 :     sal_Int32 nOldCount = aOldSeq.getLength();
     231          66 :     Sequence< Reference< chart2::data::XLabeledDataSequence > > aNewSeq( nOldCount + 1 );
     232          33 :     aNewSeq[0] = Reference< chart2::data::XLabeledDataSequence >(xLabeledSeq, uno::UNO_QUERY_THROW);
     233          66 :     for( sal_Int32 nN=0; nN<nOldCount; nN++ )
     234          33 :         aNewSeq[nN+1] = aOldSeq[nN];
     235          33 :     xSeriesSink->setData( aNewSeq );
     236             : 
     237          33 :     return xLabeledSeq;
     238             : }
     239             : 
     240          24 : XMLPropStyleContext* lcl_GetStylePropContext(
     241             :                         const SvXMLStylesContext* pStylesCtxt,
     242             :                         const SvXMLStyleContext*& rpStyle,
     243             :                         OUString& rStyleName )
     244             : {
     245          24 :     rpStyle = pStylesCtxt->FindStyleChildContext( SchXMLImportHelper::GetChartFamilyID(), rStyleName );
     246             :     XMLPropStyleContext* pPropStyleContext =
     247          24 :                     const_cast< XMLPropStyleContext* >(dynamic_cast< const XMLPropStyleContext* >( rpStyle ));
     248          24 :     return pPropStyleContext;
     249             : }
     250             : 
     251             : } // anonymous namespace
     252             : 
     253         162 : SchXMLSeries2Context::SchXMLSeries2Context(
     254             :     SchXMLImportHelper& rImpHelper,
     255             :     SvXMLImport& rImport, const OUString& rLocalName,
     256             :     const Reference< chart2::XChartDocument > & xNewDoc,
     257             :     std::vector< SchXMLAxis >& rAxes,
     258             :     ::std::list< DataRowPointStyle >& rStyleList,
     259             :     ::std::list< RegressionStyle >& rRegressionStyleList,
     260             :     sal_Int32 nSeriesIndex,
     261             :     bool bStockHasVolume,
     262             :     GlobalSeriesImportInfo& rGlobalSeriesImportInfo,
     263             :     const OUString & aGlobalChartTypeName,
     264             :     tSchXMLLSequencesPerIndex & rLSequencesPerIndex,
     265             :     bool& rGlobalChartTypeUsedBySeries,
     266             :     const awt::Size & rChartSize ) :
     267             :         SvXMLImportContext( rImport, XML_NAMESPACE_CHART, rLocalName ),
     268             :         mrImportHelper( rImpHelper ),
     269             :         mxNewDoc( xNewDoc ),
     270             :         mrAxes( rAxes ),
     271             :         mrStyleList( rStyleList ),
     272             :         mrRegressionStyleList( rRegressionStyleList ),
     273             :         m_xSeries(0),
     274             :         mnSeriesIndex( nSeriesIndex ),
     275             :         mnDataPointIndex( 0 ),
     276             :         m_bStockHasVolume( bStockHasVolume ),
     277             :         m_rGlobalSeriesImportInfo(rGlobalSeriesImportInfo),
     278             :         mpAttachedAxis( NULL ),
     279             :         mnAttachedAxis( 0 ),
     280             :         maGlobalChartTypeName( aGlobalChartTypeName ),
     281             :         maSeriesChartTypeName( aGlobalChartTypeName ),
     282             :         m_bHasDomainContext(false),
     283             :         mrLSequencesPerIndex( rLSequencesPerIndex ),
     284             :         mrGlobalChartTypeUsedBySeries( rGlobalChartTypeUsedBySeries ),
     285             :         mbSymbolSizeIsMissingInFile(false),
     286         162 :         maChartSize( rChartSize )
     287             : {
     288         162 :     if( aGlobalChartTypeName == "com.sun.star.chart2.DonutChartType" )
     289             :     {
     290           2 :         maSeriesChartTypeName = "com.sun.star.chart2.PieChartType";
     291           2 :         maGlobalChartTypeName = maSeriesChartTypeName;
     292             :     }
     293         162 : }
     294             : 
     295         324 : SchXMLSeries2Context::~SchXMLSeries2Context()
     296             : {
     297             :     SAL_WARN_IF( !maPostponedSequences.empty(), "xmloff.chart", "maPostponedSequences is NULL");
     298         324 : }
     299             : 
     300         162 : void SchXMLSeries2Context::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
     301             : {
     302             :     // parse attributes
     303         162 :     sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
     304         162 :     const SvXMLTokenMap& rAttrTokenMap = mrImportHelper.GetSeriesAttrTokenMap();
     305         162 :     mnAttachedAxis = 1;
     306             : 
     307         162 :     bool bHasRange = false;
     308         162 :     OUString aSeriesLabelRange;
     309         324 :     OUString aSeriesLabelString;
     310             : 
     311         790 :     for( sal_Int16 i = 0; i < nAttrCount; i++ )
     312             :     {
     313         628 :         OUString sAttrName = xAttrList->getNameByIndex( i );
     314        1256 :         OUString aLocalName;
     315        1256 :         OUString aValue = xAttrList->getValueByIndex( i );
     316         628 :         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
     317             : 
     318         628 :         switch( rAttrTokenMap.Get( nPrefix, aLocalName ))
     319             :         {
     320             :             case XML_TOK_SERIES_CELL_RANGE:
     321         162 :                 m_aSeriesRange = aValue;
     322         162 :                 bHasRange = true;
     323         162 :                 break;
     324             :             case XML_TOK_SERIES_LABEL_ADDRESS:
     325         145 :                 aSeriesLabelRange = aValue;
     326         145 :                 break;
     327             :             case XML_TOK_SERIES_LABEL_STRING:
     328           2 :                 aSeriesLabelString = aValue;
     329           2 :                 break;
     330             :             case XML_TOK_SERIES_ATTACHED_AXIS:
     331             :                 {
     332          12 :                     sal_Int32 nNumOfAxes = mrAxes.size();
     333          58 :                     for( sal_Int32 nCurrent = 0; nCurrent < nNumOfAxes; nCurrent++ )
     334             :                     {
     335          58 :                         if( aValue.equals( mrAxes[ nCurrent ].aName ) &&
     336          12 :                             mrAxes[ nCurrent ].eDimension == SCH_XML_AXIS_Y )
     337             :                         {
     338          12 :                             mpAttachedAxis = &( mrAxes[ nCurrent ] );
     339             :                         }
     340             :                     }
     341             :                 }
     342          12 :                 break;
     343             :             case XML_TOK_SERIES_STYLE_NAME:
     344         158 :                 msAutoStyleName = aValue;
     345         158 :                 break;
     346             :             case XML_TOK_SERIES_CHART_CLASS:
     347             :                 {
     348         149 :                     OUString aClassName;
     349             :                     sal_uInt16 nClassPrefix =
     350         149 :                         GetImport().GetNamespaceMap().GetKeyByAttrName(
     351         149 :                             aValue, &aClassName );
     352         149 :                     if( XML_NAMESPACE_CHART == nClassPrefix )
     353         149 :                         maSeriesChartTypeName = SchXMLTools::GetChartTypeByClassName( aClassName, false /* bUseOldNames */ );
     354             : 
     355         149 :                     if( maSeriesChartTypeName.isEmpty())
     356           0 :                         maSeriesChartTypeName = aClassName;
     357             :                 }
     358         149 :                 break;
     359             :         }
     360         628 :     }
     361             : 
     362         162 :     if( mpAttachedAxis )
     363             :     {
     364          12 :         if( mpAttachedAxis->nAxisIndex > 0 )
     365             :         {
     366             :             // secondary axis => property has to be set (primary is default)
     367           8 :             mnAttachedAxis = 2;
     368             :         }
     369             :     }
     370             : 
     371             :     try
     372             :     {
     373             :         SAL_WARN_IF( !mxNewDoc.is(), "xmloff.chart", "mxNewDoc is NULL");
     374         162 :         if( m_rGlobalSeriesImportInfo.rbAllRangeAddressesAvailable && ! bHasRange )
     375           0 :             m_rGlobalSeriesImportInfo.rbAllRangeAddressesAvailable = false;
     376             : 
     377         162 :         bool bIsCandleStick = maGlobalChartTypeName == "com.sun.star.chart2.CandleStickChartType";
     378         162 :         if( !maSeriesChartTypeName.isEmpty() )
     379             :         {
     380         162 :             bIsCandleStick = maSeriesChartTypeName == "com.sun.star.chart2.CandleStickChartType";
     381             :         }
     382             :         else
     383             :         {
     384           0 :             if( bIsCandleStick
     385           0 :                 && m_bStockHasVolume
     386           0 :                 && mnSeriesIndex == 0 )
     387             :             {
     388           0 :                 maSeriesChartTypeName = "com.sun.star.chart2.ColumnChartType";
     389           0 :                 bIsCandleStick = false;
     390             :             }
     391             :             else
     392             :             {
     393           0 :                 maSeriesChartTypeName = maGlobalChartTypeName;
     394             :             }
     395             :         }
     396         162 :         if( ! mrGlobalChartTypeUsedBySeries )
     397          87 :             mrGlobalChartTypeUsedBySeries = (maSeriesChartTypeName.equals( maGlobalChartTypeName ));
     398         162 :         sal_Int32 nCoordinateSystemIndex = 0;//so far we can only import one coordinate system
     399             :         m_xSeries.set(
     400         162 :             SchXMLImportHelper::GetNewDataSeries( mxNewDoc, nCoordinateSystemIndex, maSeriesChartTypeName, ! mrGlobalChartTypeUsedBySeries ));
     401         162 :         Reference< chart2::data::XLabeledDataSequence > xLabeledSeq( SchXMLTools::GetNewLabeledDataSequence(), uno::UNO_QUERY_THROW );
     402             : 
     403         162 :         if( bIsCandleStick )
     404             :         {
     405             :             // set default color for range-line to black (before applying styles)
     406           4 :             Reference< beans::XPropertySet > xSeriesProp( m_xSeries, uno::UNO_QUERY );
     407           4 :             if( xSeriesProp.is())
     408           4 :                 xSeriesProp->setPropertyValue("Color",
     409           4 :                                                uno::makeAny( sal_Int32( 0x000000 ))); // black
     410             :         }
     411         158 :         else if ( maSeriesChartTypeName == "com.sun.star.chart2.PieChartType" )
     412             :         {
     413             :             //@todo: this property should be saved
     414           6 :             Reference< beans::XPropertySet > xSeriesProp( m_xSeries, uno::UNO_QUERY );
     415           6 :             if( xSeriesProp.is())
     416           6 :                 xSeriesProp->setPropertyValue("VaryColorsByPoint",
     417           6 :                                                uno::makeAny( true ));
     418             :         }
     419             : 
     420             :         // values
     421         324 :         Reference< chart2::data::XDataSequence > xSeq;
     422         162 :         if( bHasRange && !m_aSeriesRange.isEmpty() )
     423         162 :             xSeq = SchXMLTools::CreateDataSequence( m_aSeriesRange, mxNewDoc );
     424             : 
     425         324 :         Reference< beans::XPropertySet > xSeqProp( xSeq, uno::UNO_QUERY );
     426         162 :         if( xSeqProp.is())
     427             :         {
     428         162 :             OUString aMainRole("values-y");
     429         162 :             if ( maSeriesChartTypeName == "com.sun.star.chart2.BubbleChartType" )
     430           0 :                 aMainRole = "values-size";
     431         162 :             xSeqProp->setPropertyValue("Role", uno::makeAny( aMainRole ));
     432             :         }
     433         162 :         xLabeledSeq->setValues( xSeq );
     434             : 
     435             :         // register for setting local data if external data provider is not present
     436             :         maPostponedSequences.insert(
     437             :             tSchXMLLSequencesPerIndex::value_type(
     438         162 :                 tSchXMLIndexWithPart( m_rGlobalSeriesImportInfo.nCurrentDataIndex, SCH_XML_PART_VALUES ), xLabeledSeq ));
     439             : 
     440             :         // label
     441         162 :         if( !aSeriesLabelRange.isEmpty() )
     442             :         {
     443             :             Reference< chart2::data::XDataSequence > xLabelSequence =
     444         145 :                 SchXMLTools::CreateDataSequence( aSeriesLabelRange, mxNewDoc );
     445         145 :             xLabeledSeq->setLabel( xLabelSequence );
     446             :         }
     447          17 :         else if( !aSeriesLabelString.isEmpty() )
     448             :         {
     449             :             Reference< chart2::data::XDataSequence > xLabelSequence =
     450           2 :                 SchXMLTools::CreateDataSequenceWithoutConvert( aSeriesLabelString, mxNewDoc );
     451           2 :             xLabeledSeq->setLabel( xLabelSequence );
     452             :         }
     453             : 
     454             :         // Note: Even if we have no label, we have to register the label
     455             :         // for creation, because internal data always has labels. If
     456             :         // they don't exist in the original, auto-generated labels are
     457             :         // used for the internal data.
     458             :         maPostponedSequences.insert(
     459             :             tSchXMLLSequencesPerIndex::value_type(
     460         162 :                 tSchXMLIndexWithPart( m_rGlobalSeriesImportInfo.nCurrentDataIndex, SCH_XML_PART_LABEL ), xLabeledSeq ));
     461             : 
     462         324 :         Sequence< Reference< chart2::data::XLabeledDataSequence > > aSeq( &xLabeledSeq, 1 );
     463         324 :         Reference< chart2::data::XDataSink > xSink( m_xSeries, uno::UNO_QUERY_THROW );
     464         324 :         xSink->setData( aSeq );
     465             :     }
     466           0 :     catch( const uno::Exception & ex )
     467             :     {
     468             :         SAL_WARN("xmloff.chart", "Exception caught. Type: " << OUString::createFromAscii( typeid( ex ).name()) << ", Message: " << ex.Message);
     469             :     }
     470             : 
     471             :     //init mbSymbolSizeIsMissingInFile:
     472             :     try
     473             :     {
     474         162 :         if( !msAutoStyleName.isEmpty() )
     475             :         {
     476         158 :             const SvXMLStylesContext* pStylesCtxt = mrImportHelper.GetAutoStylesContext();
     477         158 :             if( pStylesCtxt )
     478             :             {
     479             :                 const SvXMLStyleContext* pStyle = pStylesCtxt->FindStyleChildContext(
     480         158 :                     SchXMLImportHelper::GetChartFamilyID(), msAutoStyleName );
     481             : 
     482         158 :                 const XMLPropStyleContext* pPropStyleContext = dynamic_cast< const XMLPropStyleContext * >( pStyle );
     483             : 
     484             :                 uno::Any aASymbolSize( SchXMLTools::getPropertyFromContext( OUString("SymbolSize")
     485         158 :                     , pPropStyleContext, pStylesCtxt ) );
     486         158 :                 mbSymbolSizeIsMissingInFile = !aASymbolSize.hasValue();
     487             :             }
     488             :         }
     489             :     }
     490           0 :     catch( const uno::Exception & )
     491             :     {
     492         162 :     }
     493         162 : }
     494             : 
     495         165 : struct DomainInfo
     496             : {
     497          33 :     DomainInfo( const OUString& rRole, const OUString& rRange, sal_Int32 nIndex )
     498          33 :         : aRole(rRole), aRange(rRange), nIndexForLocalData(nIndex)
     499          33 :     {}
     500             : 
     501             :     OUString aRole;
     502             :     OUString aRange;
     503             :     sal_Int32 nIndexForLocalData;
     504             : };
     505             : 
     506         162 : void SchXMLSeries2Context::EndElement()
     507             : {
     508             :     // special handling for different chart types.  This is necessary as the
     509             :     // roles are not yet saved in the file format
     510         162 :     sal_Int32 nDomainCount = maDomainAddresses.size();
     511         162 :     bool bIsScatterChart = maSeriesChartTypeName == "com.sun.star.chart2.ScatterChartType";
     512         162 :     bool bIsBubbleChart = maSeriesChartTypeName == "com.sun.star.chart2.BubbleChartType";
     513         162 :     bool bDeleteSeries = false;
     514         162 :     std::vector< DomainInfo > aDomainInfos;
     515             : 
     516             :     //different handling for different chart types necessary
     517         162 :     if( bIsScatterChart || ( nDomainCount==1 && !bIsBubbleChart ) )
     518             :     {
     519          33 :         DomainInfo aDomainInfo( OUString( "values-x" ), m_rGlobalSeriesImportInfo.aFirstFirstDomainAddress, m_rGlobalSeriesImportInfo.nFirstFirstDomainIndex ) ;
     520          33 :         bool bCreateXValues = true;
     521          33 :         if( !maDomainAddresses.empty() )
     522             :         {
     523          28 :             if( m_rGlobalSeriesImportInfo.aFirstFirstDomainAddress.isEmpty() )
     524             :             {
     525          26 :                 m_rGlobalSeriesImportInfo.aFirstFirstDomainAddress = maDomainAddresses.front();
     526          26 :                 m_rGlobalSeriesImportInfo.nFirstFirstDomainIndex = m_rGlobalSeriesImportInfo.nCurrentDataIndex;
     527             :             }
     528          28 :             aDomainInfo.aRange = maDomainAddresses.front();
     529          28 :             aDomainInfo.nIndexForLocalData = m_rGlobalSeriesImportInfo.nCurrentDataIndex;
     530          28 :             m_rGlobalSeriesImportInfo.nCurrentDataIndex++;
     531             :         }
     532           5 :         else if( m_rGlobalSeriesImportInfo.aFirstFirstDomainAddress.isEmpty() && !m_bHasDomainContext && mnSeriesIndex==0 )
     533             :         {
     534           0 :             if( SchXMLTools::isDocumentGeneratedWithOpenOfficeOlderThan2_3( GetImport().GetModel() ) ) //wrong old chart files:
     535             :             {
     536             :                 //for xy charts the first series needs to have a domain
     537             :                 //if this by error iss not the case the first series is taken s x values
     538             :                 //needed for wrong files created while having an addin (e.g. BoxPlot)
     539           0 :                 m_rGlobalSeriesImportInfo.aFirstFirstDomainAddress = m_aSeriesRange;
     540           0 :                 m_rGlobalSeriesImportInfo.nFirstFirstDomainIndex = m_rGlobalSeriesImportInfo.nCurrentDataIndex++;
     541           0 :                 bDeleteSeries = true;
     542           0 :                 bCreateXValues = false;//they will be created for the next series
     543             :             }
     544             :         }
     545          33 :         if( bCreateXValues )
     546          33 :             aDomainInfos.push_back( aDomainInfo );
     547             :     }
     548         129 :     else if( bIsBubbleChart )
     549             :     {
     550           0 :         if( nDomainCount>1 )
     551             :         {
     552           0 :             DomainInfo aDomainInfo( OUString( "values-x" ), maDomainAddresses[1], m_rGlobalSeriesImportInfo.nCurrentDataIndex ) ;
     553           0 :             if( m_rGlobalSeriesImportInfo.aFirstSecondDomainAddress.isEmpty() )
     554             :             {
     555             :                 //for bubble chart the second domain contains the x values which should become an index smaller than y values for own data table
     556             :                 //->so second first
     557           0 :                 m_rGlobalSeriesImportInfo.aFirstSecondDomainAddress = maDomainAddresses[1];
     558           0 :                 m_rGlobalSeriesImportInfo.nFirstSecondDomainIndex = m_rGlobalSeriesImportInfo.nCurrentDataIndex;
     559             :             }
     560           0 :             aDomainInfos.push_back( aDomainInfo );
     561           0 :             m_rGlobalSeriesImportInfo.nCurrentDataIndex++;
     562             :         }
     563           0 :         else if( !m_rGlobalSeriesImportInfo.aFirstSecondDomainAddress.isEmpty() )
     564             :         {
     565           0 :             DomainInfo aDomainInfo( OUString( "values-x" ), m_rGlobalSeriesImportInfo.aFirstSecondDomainAddress, m_rGlobalSeriesImportInfo.nFirstSecondDomainIndex ) ;
     566           0 :             aDomainInfos.push_back( aDomainInfo );
     567             :         }
     568           0 :         if( nDomainCount>0)
     569             :         {
     570           0 :             DomainInfo aDomainInfo( OUString( "values-y" ), maDomainAddresses.front(), m_rGlobalSeriesImportInfo.nCurrentDataIndex ) ;
     571           0 :             if( m_rGlobalSeriesImportInfo.aFirstFirstDomainAddress.isEmpty() )
     572             :             {
     573           0 :                 m_rGlobalSeriesImportInfo.aFirstFirstDomainAddress = maDomainAddresses.front();
     574           0 :                 m_rGlobalSeriesImportInfo.nFirstFirstDomainIndex = m_rGlobalSeriesImportInfo.nCurrentDataIndex;
     575             :             }
     576           0 :             aDomainInfos.push_back( aDomainInfo );
     577           0 :             m_rGlobalSeriesImportInfo.nCurrentDataIndex++;
     578             :         }
     579           0 :         else if( !m_rGlobalSeriesImportInfo.aFirstFirstDomainAddress.isEmpty() )
     580             :         {
     581           0 :             DomainInfo aDomainInfo( OUString("values-y"), m_rGlobalSeriesImportInfo.aFirstFirstDomainAddress, m_rGlobalSeriesImportInfo.nFirstFirstDomainIndex ) ;
     582           0 :             aDomainInfos.push_back( aDomainInfo );
     583             :         }
     584             :     }
     585             : 
     586         162 :     if( bDeleteSeries )
     587             :     {
     588             :         //delete created series
     589             :         SchXMLImportHelper::DeleteDataSeries(
     590           0 :             m_xSeries, Reference< chart2::XChartDocument >( GetImport().GetModel(), uno::UNO_QUERY ) );
     591             :     }
     592             :     else
     593             :     {
     594             :         //add style
     595         162 :         if( !msAutoStyleName.isEmpty() || mnAttachedAxis != 1 )
     596             :         {
     597             :             DataRowPointStyle aStyle(
     598             :                 DataRowPointStyle::DATA_SERIES,
     599             :                 m_xSeries,
     600             :                 -1, 1,
     601         162 :                 msAutoStyleName, mnAttachedAxis );
     602         162 :             aStyle.mbSymbolSizeForSeriesIsMissingInFile=mbSymbolSizeIsMissingInFile;
     603         162 :             mrStyleList.push_back( aStyle );
     604             :         }
     605             :     }
     606             : 
     607         195 :     for( std::vector< DomainInfo >::reverse_iterator aIt( aDomainInfos.rbegin() ); aIt!= aDomainInfos.rend(); ++aIt )
     608             :     {
     609          33 :         DomainInfo aDomainInfo( *aIt );
     610             :         Reference< chart2::data::XLabeledDataSequence2 > xLabeledSeq =
     611          66 :             lcl_createAndAddSequenceToSeries( aDomainInfo.aRole, aDomainInfo.aRange, mxNewDoc, m_xSeries );
     612          33 :         if( xLabeledSeq.is() )
     613             :         {
     614             :             // register for setting local data if external data provider is not present
     615             :             mrLSequencesPerIndex.insert(
     616             :                 tSchXMLLSequencesPerIndex::value_type(
     617             :                     tSchXMLIndexWithPart( aDomainInfo.nIndexForLocalData, SCH_XML_PART_VALUES ),
     618          33 :                     Reference< chart2::data::XLabeledDataSequence >(xLabeledSeq, uno::UNO_QUERY_THROW) ));
     619             :         }
     620          33 :     }
     621             : 
     622         162 :     if( !bDeleteSeries )
     623             :     {
     624        1458 :         for( tSchXMLLSequencesPerIndex::const_iterator aIt( maPostponedSequences.begin());
     625         972 :             aIt != maPostponedSequences.end(); ++aIt )
     626             :         {
     627         324 :             sal_Int32 nNewIndex = aIt->first.first + nDomainCount;
     628             :             mrLSequencesPerIndex.insert(
     629             :                 tSchXMLLSequencesPerIndex::value_type(
     630         324 :                     tSchXMLIndexWithPart( nNewIndex, aIt->first.second ), aIt->second ));
     631             :         }
     632         162 :         m_rGlobalSeriesImportInfo.nCurrentDataIndex++;
     633             :     }
     634         162 :     maPostponedSequences.clear();
     635         162 : }
     636             : 
     637         252 : SvXMLImportContext* SchXMLSeries2Context::CreateChildContext(
     638             :     sal_uInt16 nPrefix,
     639             :     const OUString& rLocalName,
     640             :     const uno::Reference< xml::sax::XAttributeList >&  )
     641             : {
     642         252 :     SvXMLImportContext* pContext = 0;
     643         252 :     const SvXMLTokenMap& rTokenMap = mrImportHelper.GetSeriesElemTokenMap();
     644             : 
     645         252 :     switch( rTokenMap.Get( nPrefix, rLocalName ))
     646             :     {
     647             :         case XML_TOK_SERIES_DOMAIN:
     648          28 :             if( m_xSeries.is())
     649             :             {
     650          28 :                 m_bHasDomainContext = true;
     651             :                 pContext = new SchXMLDomain2Context(
     652          28 :                     GetImport(),
     653             :                     nPrefix, rLocalName,
     654          28 :                     maDomainAddresses );
     655             :             }
     656          28 :             break;
     657             : 
     658             :         case XML_TOK_SERIES_MEAN_VALUE_LINE:
     659             :             pContext = new SchXMLStatisticsObjectContext(
     660           0 :                 mrImportHelper, GetImport(),
     661             :                 nPrefix, rLocalName, msAutoStyleName,
     662             :                 mrStyleList, m_xSeries,
     663             :                 SchXMLStatisticsObjectContext::CONTEXT_TYPE_MEAN_VALUE_LINE,
     664           0 :                 maChartSize, mrLSequencesPerIndex );
     665           0 :             break;
     666             :         case XML_TOK_SERIES_REGRESSION_CURVE:
     667             :             pContext = new SchXMLRegressionCurveObjectContext(
     668          12 :                 mrImportHelper, GetImport(),
     669             :                 nPrefix, rLocalName, mrRegressionStyleList,
     670          12 :                 m_xSeries, maChartSize );
     671          12 :             break;
     672             :         case XML_TOK_SERIES_ERROR_INDICATOR:
     673             :             pContext = new SchXMLStatisticsObjectContext(
     674           6 :                 mrImportHelper, GetImport(),
     675             :                 nPrefix, rLocalName, msAutoStyleName,
     676             :                 mrStyleList, m_xSeries,
     677             :                 SchXMLStatisticsObjectContext::CONTEXT_TYPE_ERROR_INDICATOR,
     678           6 :                 maChartSize, mrLSequencesPerIndex );
     679           6 :             break;
     680             : 
     681             :         case XML_TOK_SERIES_DATA_POINT:
     682         206 :             pContext = new SchXMLDataPointContext( GetImport(), rLocalName,
     683         206 :                                                    mrStyleList, m_xSeries, mnDataPointIndex, mbSymbolSizeIsMissingInFile );
     684         206 :             break;
     685             :         case XML_TOK_SERIES_PROPERTY_MAPPING:
     686             :             pContext = new SchXMLPropertyMappingContext( mrImportHelper,
     687           0 :                     GetImport(), rLocalName,
     688           0 :                     mrLSequencesPerIndex, m_xSeries );
     689           0 :             break;
     690             : 
     691             :         default:
     692           0 :             pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
     693             :     }
     694             : 
     695         252 :     return pContext;
     696             : }
     697             : 
     698             : //static
     699          86 : void SchXMLSeries2Context::initSeriesPropertySets( SeriesDefaultsAndStyles& rSeriesDefaultsAndStyles
     700             :         , const uno::Reference< frame::XModel >& xChartModel )
     701             : {
     702          86 :     ::std::list< DataRowPointStyle >::iterator iStyle;
     703             : 
     704             :     // iterate over series first and remind propertysets in map
     705             :     // new api <-> old api wrapper
     706          86 :     ::std::map< Reference< chart2::XDataSeries >, Reference< beans::XPropertySet > > aSeriesMap;
     707         303 :     for( iStyle = rSeriesDefaultsAndStyles.maSeriesStyleList.begin(); iStyle != rSeriesDefaultsAndStyles.maSeriesStyleList.end(); ++iStyle )
     708             :     {
     709         217 :         if( iStyle->meType != DataRowPointStyle::DATA_SERIES )
     710          55 :             continue;
     711             : 
     712         162 :         if( !iStyle->m_xOldAPISeries.is() )
     713         162 :             iStyle->m_xOldAPISeries = SchXMLSeriesHelper::createOldAPISeriesPropertySet( iStyle->m_xSeries, xChartModel );
     714             : 
     715         162 :         aSeriesMap[iStyle->m_xSeries] = iStyle->m_xOldAPISeries;
     716             : 
     717             :     }
     718             : 
     719             :     //initialize m_xOldAPISeries for all other styles also
     720         303 :     for( iStyle = rSeriesDefaultsAndStyles.maSeriesStyleList.begin(); iStyle != rSeriesDefaultsAndStyles.maSeriesStyleList.end(); ++iStyle )
     721             :     {
     722         217 :         if( iStyle->meType == DataRowPointStyle::DATA_SERIES )
     723         162 :             continue;
     724          55 :         iStyle->m_xOldAPISeries = aSeriesMap[iStyle->m_xSeries];
     725          86 :     }
     726          86 : }
     727             : 
     728             : //static
     729          86 : void SchXMLSeries2Context::setDefaultsToSeries( SeriesDefaultsAndStyles& rSeriesDefaultsAndStyles )
     730             : {
     731          86 :     ::std::list< DataRowPointStyle >::iterator iStyle;
     732             :     // iterate over series
     733             :     // call initSeriesPropertySets first
     734             : 
     735         303 :     for( iStyle = rSeriesDefaultsAndStyles.maSeriesStyleList.begin(); iStyle != rSeriesDefaultsAndStyles.maSeriesStyleList.end(); ++iStyle )
     736             :     {
     737         217 :         if( iStyle->meType != DataRowPointStyle::DATA_SERIES )
     738          55 :             continue;
     739             : 
     740             :         try
     741             :         {
     742         162 :             uno::Reference< beans::XPropertySet > xSeries( iStyle->m_xOldAPISeries );
     743         162 :             if( !xSeries.is() )
     744           0 :                 continue;
     745             : 
     746         162 :             if( rSeriesDefaultsAndStyles.maSymbolTypeDefault.hasValue() )
     747         162 :                 xSeries->setPropertyValue("SymbolType",rSeriesDefaultsAndStyles.maSymbolTypeDefault);
     748         162 :             if( rSeriesDefaultsAndStyles.maDataCaptionDefault.hasValue() )
     749         162 :                 xSeries->setPropertyValue("DataCaption",rSeriesDefaultsAndStyles.maDataCaptionDefault);
     750             : 
     751         162 :             if( rSeriesDefaultsAndStyles.maErrorIndicatorDefault.hasValue() )
     752           0 :                 xSeries->setPropertyValue("ErrorIndicator",rSeriesDefaultsAndStyles.maErrorIndicatorDefault);
     753         162 :             if( rSeriesDefaultsAndStyles.maErrorCategoryDefault.hasValue() )
     754           0 :                 xSeries->setPropertyValue("ErrorCategory",rSeriesDefaultsAndStyles.maErrorCategoryDefault);
     755         162 :             if( rSeriesDefaultsAndStyles.maConstantErrorLowDefault.hasValue() )
     756           0 :                 xSeries->setPropertyValue("ConstantErrorLow",rSeriesDefaultsAndStyles.maConstantErrorLowDefault);
     757         162 :             if( rSeriesDefaultsAndStyles.maConstantErrorHighDefault.hasValue() )
     758           0 :                 xSeries->setPropertyValue("ConstantErrorHigh",rSeriesDefaultsAndStyles.maConstantErrorHighDefault);
     759         162 :             if( rSeriesDefaultsAndStyles.maPercentageErrorDefault.hasValue() )
     760           0 :                 xSeries->setPropertyValue("PercentageError",rSeriesDefaultsAndStyles.maPercentageErrorDefault);
     761         162 :             if( rSeriesDefaultsAndStyles.maErrorMarginDefault.hasValue() )
     762           0 :                 xSeries->setPropertyValue("ErrorMargin",rSeriesDefaultsAndStyles.maErrorMarginDefault);
     763             : 
     764         162 :             if( rSeriesDefaultsAndStyles.maMeanValueDefault.hasValue() )
     765         162 :                 xSeries->setPropertyValue("MeanValue",rSeriesDefaultsAndStyles.maMeanValueDefault);
     766         162 :             if( rSeriesDefaultsAndStyles.maRegressionCurvesDefault.hasValue() )
     767         162 :                 xSeries->setPropertyValue("RegressionCurves",rSeriesDefaultsAndStyles.maRegressionCurvesDefault);
     768             :         }
     769           0 :         catch( uno::Exception &  )
     770             :         {
     771             :             //end of series reached
     772             :         }
     773             :     }
     774          86 : }
     775             : 
     776             : //static
     777          86 : void SchXMLSeries2Context::setStylesToSeries( SeriesDefaultsAndStyles& rSeriesDefaultsAndStyles
     778             :         , const SvXMLStylesContext* pStylesCtxt
     779             :         , const SvXMLStyleContext*& rpStyle
     780             :         , OUString& rCurrStyleName
     781             :         , SchXMLImportHelper& rImportHelper
     782             :         , const SvXMLImport& rImport
     783             :         , bool bIsStockChart
     784             :         , tSchXMLLSequencesPerIndex & rInOutLSequencesPerIndex )
     785             : {
     786          86 :     ::std::list< DataRowPointStyle >::iterator iStyle;
     787             : 
     788             :     // iterate over series
     789         303 :     for( iStyle = rSeriesDefaultsAndStyles.maSeriesStyleList.begin(); iStyle != rSeriesDefaultsAndStyles.maSeriesStyleList.end(); ++iStyle )
     790             :     {
     791         217 :         if( iStyle->meType == DataRowPointStyle::DATA_SERIES )
     792             :         {
     793             :             try
     794             :             {
     795         162 :                 uno::Reference< beans::XPropertySet > xSeriesProp( iStyle->m_xOldAPISeries );
     796         162 :                 if( !xSeriesProp.is() )
     797           0 :                     continue;
     798             : 
     799         162 :                 if( iStyle->mnAttachedAxis != 1 )
     800             :                 {
     801           8 :                     xSeriesProp->setPropertyValue("Axis"
     802           8 :                         , uno::makeAny(chart::ChartAxisAssign::SECONDARY_Y) );
     803             :                 }
     804             : 
     805         162 :                 if( !(iStyle->msStyleName).isEmpty())
     806             :                 {
     807         158 :                     if( ! rCurrStyleName.equals( iStyle->msStyleName ))
     808             :                     {
     809         157 :                         rCurrStyleName = iStyle->msStyleName;
     810             :                         rpStyle = pStylesCtxt->FindStyleChildContext(
     811         157 :                             SchXMLImportHelper::GetChartFamilyID(), rCurrStyleName );
     812             :                     }
     813             : 
     814             :                     //set style to series
     815             :                     // note: SvXMLStyleContext::FillPropertySet is not const
     816             :                     XMLPropStyleContext * pPropStyleContext =
     817             :                         const_cast< XMLPropStyleContext * >(
     818         158 :                             dynamic_cast< const XMLPropStyleContext * >( rpStyle ));
     819         158 :                     if( pPropStyleContext )
     820             :                     {
     821             :                         // error bar style must be set before the other error
     822             :                         // bar properties (which may be alphabetically before
     823             :                         // this property)
     824         158 :                         bool bHasErrorBarRangesFromData = false;
     825             :                         {
     826         158 :                             const OUString aErrorBarStylePropName( "ErrorBarStyle");
     827             :                             uno::Any aErrorBarStyle(
     828         316 :                                 SchXMLTools::getPropertyFromContext( aErrorBarStylePropName, pPropStyleContext, pStylesCtxt ));
     829         158 :                             if( aErrorBarStyle.hasValue())
     830             :                             {
     831          15 :                                 xSeriesProp->setPropertyValue( aErrorBarStylePropName, aErrorBarStyle );
     832          15 :                                 sal_Int32 eEBStyle = chart::ErrorBarStyle::NONE;
     833             :                                 bHasErrorBarRangesFromData =
     834          30 :                                     ( ( aErrorBarStyle >>= eEBStyle ) &&
     835          30 :                                       eEBStyle == chart::ErrorBarStyle::FROM_DATA );
     836         158 :                             }
     837             :                         }
     838             : 
     839             :                         //don't set the style to the min max line series of a stock chart
     840             :                         //otherwise the min max line properties gets overwritten and the series becomes invisible typically
     841         158 :                         bool bIsMinMaxSeries = false;
     842         158 :                         if( bIsStockChart )
     843             :                         {
     844           3 :                             if( SchXMLSeriesHelper::isCandleStickSeries( iStyle->m_xSeries
     845           3 :                                     , uno::Reference< frame::XModel >( rImportHelper.GetChartDocument(), uno::UNO_QUERY ) ) )
     846           0 :                                 bIsMinMaxSeries = true;
     847             :                         }
     848         158 :                         if( !bIsMinMaxSeries )
     849             :                         {
     850         158 :                             pPropStyleContext->FillPropertySet( xSeriesProp );
     851         158 :                             if( iStyle->mbSymbolSizeForSeriesIsMissingInFile )
     852         112 :                                 lcl_setSymbolSizeIfNeeded( xSeriesProp, rImport );
     853         158 :                             if( bHasErrorBarRangesFromData )
     854           3 :                                 lcl_insertErrorBarLSequencesToMap( rInOutLSequencesPerIndex, xSeriesProp );
     855             :                         }
     856             :                     }
     857         162 :                 }
     858             :             }
     859           0 :             catch( const uno::Exception & rEx )
     860             :             {
     861             :                 SAL_INFO("xmloff.chart", "Exception caught during setting styles to series: " << rEx.Message );
     862             :             }
     863             :         }
     864             :     }
     865          86 : }
     866             : 
     867             : // static
     868          86 : void SchXMLSeries2Context::setStylesToRegressionCurves(
     869             :                                 SeriesDefaultsAndStyles& rSeriesDefaultsAndStyles,
     870             :                                 const SvXMLStylesContext* pStylesCtxt,
     871             :                                 const SvXMLStyleContext*& rpStyle,
     872             :                                 OUString& rCurrentStyleName )
     873             : {
     874          86 :     std::list< RegressionStyle >::iterator iStyle;
     875             : 
     876             :     // iterate over regession etc
     877          98 :     for( iStyle = rSeriesDefaultsAndStyles.maRegressionStyleList.begin(); iStyle != rSeriesDefaultsAndStyles.maRegressionStyleList.end(); ++iStyle )
     878             :     {
     879             :         try
     880             :         {
     881          12 :             OUString aServiceName;
     882          12 :             XMLPropStyleContext* pPropStyleContext = NULL;
     883             : 
     884          12 :             if (!rCurrentStyleName.isEmpty())
     885             :             {
     886          12 :                 XMLPropStyleContext* pCurrent = lcl_GetStylePropContext(pStylesCtxt, rpStyle, rCurrentStyleName);
     887          12 :                 if( pCurrent )
     888             :                 {
     889          12 :                     pPropStyleContext = pCurrent;
     890          12 :                     uno::Any aAny = SchXMLTools::getPropertyFromContext("RegressionType", pPropStyleContext, pStylesCtxt);
     891          12 :                     if ( aAny.hasValue() )
     892             :                     {
     893           0 :                         aAny >>= aServiceName;
     894          12 :                     }
     895             :                 }
     896             :             }
     897             : 
     898          12 :             if (!iStyle->msStyleName.isEmpty())
     899             :             {
     900          12 :                 XMLPropStyleContext* pCurrent = lcl_GetStylePropContext(pStylesCtxt, rpStyle, iStyle->msStyleName);
     901          12 :                 if( pCurrent )
     902             :                 {
     903          12 :                     pPropStyleContext = pCurrent;
     904          12 :                     uno::Any aAny = SchXMLTools::getPropertyFromContext("RegressionType", pPropStyleContext, pStylesCtxt);
     905          12 :                     if ( aAny.hasValue() )
     906             :                     {
     907          12 :                         aAny >>= aServiceName;
     908          12 :                     }
     909             :                 }
     910             :             }
     911             : 
     912          12 :             if( !aServiceName.isEmpty() )
     913             :             {
     914          12 :                 Reference< lang::XMultiServiceFactory > xMSF( comphelper::getProcessServiceFactory(), uno::UNO_QUERY );
     915          24 :                 Reference< chart2::XRegressionCurve > xRegCurve( xMSF->createInstance( aServiceName ), uno::UNO_QUERY_THROW );
     916          24 :                 Reference< chart2::XRegressionCurveContainer > xRegCurveCont( iStyle->m_xSeries, uno::UNO_QUERY_THROW );
     917             : 
     918          12 :                 if( xRegCurve.is())
     919             :                 {
     920          12 :                     Reference< beans::XPropertySet > xCurveProperties( xRegCurve, uno::UNO_QUERY );
     921          12 :                     if( pPropStyleContext != NULL)
     922          12 :                         pPropStyleContext->FillPropertySet( xCurveProperties );
     923             : 
     924          12 :                     xRegCurve->setEquationProperties( iStyle->m_xEquationProperties );
     925             :                 }
     926             : 
     927          24 :                 xRegCurveCont->addRegressionCurve( xRegCurve );
     928          12 :             }
     929             :         }
     930           0 :         catch( const uno::Exception& rEx )
     931             :         {
     932             :             SAL_INFO("xmloff.chart", "Exception caught during setting styles to series: " << rEx.Message );
     933             :         }
     934             : 
     935             :     }
     936          86 : }
     937             : 
     938             : // static
     939          86 : void SchXMLSeries2Context::setStylesToStatisticsObjects( SeriesDefaultsAndStyles& rSeriesDefaultsAndStyles
     940             :         , const SvXMLStylesContext* pStylesCtxt
     941             :         , const SvXMLStyleContext*& rpStyle
     942             :         , OUString& rCurrStyleName )
     943             : {
     944          86 :     ::std::list< DataRowPointStyle >::iterator iStyle;
     945             : 
     946             :     // iterate over regession etc
     947         303 :     for( iStyle = rSeriesDefaultsAndStyles.maSeriesStyleList.begin(); iStyle != rSeriesDefaultsAndStyles.maSeriesStyleList.end(); ++iStyle )
     948             :     {
     949         428 :         if( iStyle->meType == DataRowPointStyle::ERROR_INDICATOR ||
     950         211 :             iStyle->meType == DataRowPointStyle::MEAN_VALUE )
     951             :         {
     952           6 :             if ( iStyle->meType == DataRowPointStyle::ERROR_INDICATOR )
     953             :             {
     954           6 :                 uno::Reference< beans::XPropertySet > xNewSeriesProp(iStyle->m_xSeries,uno::UNO_QUERY);
     955             : 
     956           6 :                 if (iStyle->m_xErrorXProperties.is())
     957           0 :                     xNewSeriesProp->setPropertyValue("ErrorBarX",uno::makeAny(iStyle->m_xErrorXProperties));
     958             : 
     959           6 :                 if (iStyle->m_xErrorYProperties.is())
     960           6 :                     xNewSeriesProp->setPropertyValue("ErrorBarY",uno::makeAny(iStyle->m_xErrorYProperties));
     961             :             }
     962             : 
     963             :             try
     964             :             {
     965           6 :                 uno::Reference< beans::XPropertySet > xSeriesProp( iStyle->m_xOldAPISeries );
     966           6 :                 if( !xSeriesProp.is() )
     967           0 :                     continue;
     968             : 
     969           6 :                 if( !(iStyle->msStyleName).isEmpty())
     970             :                 {
     971           6 :                     if( ! rCurrStyleName.equals( iStyle->msStyleName ))
     972             :                     {
     973           6 :                         rCurrStyleName = iStyle->msStyleName;
     974             :                         rpStyle = pStylesCtxt->FindStyleChildContext(
     975           6 :                             SchXMLImportHelper::GetChartFamilyID(), rCurrStyleName );
     976             :                     }
     977             : 
     978             :                     // note: SvXMLStyleContext::FillPropertySet is not const
     979             :                     XMLPropStyleContext * pPropStyleContext =
     980             :                         const_cast< XMLPropStyleContext * >(
     981           6 :                             dynamic_cast< const XMLPropStyleContext * >( rpStyle ));
     982           6 :                     if( pPropStyleContext )
     983             :                     {
     984           6 :                         Reference< beans::XPropertySet > xStatPropSet;
     985           6 :                         switch( iStyle->meType )
     986             :                         {
     987             :                             case DataRowPointStyle::MEAN_VALUE:
     988           0 :                                 xSeriesProp->getPropertyValue(
     989           0 :                                     OUString( "DataMeanValueProperties" )) >>= xStatPropSet;
     990           0 :                                 break;
     991             :                             case DataRowPointStyle::ERROR_INDICATOR:
     992           6 :                                 xSeriesProp->getPropertyValue(
     993           6 :                                     OUString( "DataErrorProperties" ))  >>= xStatPropSet;
     994           6 :                                 break;
     995             :                             default:
     996           0 :                                 break;
     997             :                         }
     998           6 :                         if( xStatPropSet.is())
     999           6 :                             pPropStyleContext->FillPropertySet( xStatPropSet );
    1000             :                     }
    1001           6 :                 }
    1002             :             }
    1003           0 :             catch( const uno::Exception & rEx )
    1004             :             {
    1005             :                 SAL_INFO("xmloff.chart", "Exception caught during setting styles to series: " << rEx.Message );
    1006             :             }
    1007             :         }
    1008             :     }
    1009          86 : }
    1010             : 
    1011             : //static
    1012          86 : void SchXMLSeries2Context::setStylesToDataPoints( SeriesDefaultsAndStyles& rSeriesDefaultsAndStyles
    1013             :         , const SvXMLStylesContext* pStylesCtxt
    1014             :         , const SvXMLStyleContext*& rpStyle
    1015             :         , OUString& rCurrStyleName
    1016             :         , SchXMLImportHelper& rImportHelper
    1017             :         , const SvXMLImport& rImport
    1018             :         , bool bIsStockChart, bool bIsDonutChart, bool bSwitchOffLinesForScatter )
    1019             : {
    1020          86 :     ::std::list< DataRowPointStyle >::iterator iStyle;
    1021         303 :     for( iStyle = rSeriesDefaultsAndStyles.maSeriesStyleList.begin(); iStyle != rSeriesDefaultsAndStyles.maSeriesStyleList.end(); ++iStyle )
    1022             :     {
    1023         217 :         if( iStyle->meType != DataRowPointStyle::DATA_POINT )
    1024         168 :             continue;
    1025             : 
    1026          49 :         if( iStyle->m_nPointIndex == -1 )
    1027           0 :             continue;
    1028             : 
    1029             :         //ignore datapoint properties for stock charts
    1030             :         //... todo ...
    1031          49 :         if( bIsStockChart )
    1032             :         {
    1033           0 :             if( SchXMLSeriesHelper::isCandleStickSeries( iStyle->m_xSeries, uno::Reference< frame::XModel >( rImportHelper.GetChartDocument(), uno::UNO_QUERY ) ) )
    1034           0 :                 continue;
    1035             :         }
    1036             : 
    1037             :         // data point style
    1038         113 :         for( sal_Int32 i = 0; i < iStyle->m_nPointRepeat; i++ )
    1039             :         {
    1040             :             try
    1041             :             {
    1042          64 :                 uno::Reference< beans::XPropertySet > xSeriesProp( iStyle->m_xOldAPISeries );
    1043          64 :                 if(!xSeriesProp.is())
    1044           0 :                     continue;
    1045             : 
    1046             :                 uno::Reference< beans::XPropertySet > xPointProp(
    1047         128 :                     SchXMLSeriesHelper::createOldAPIDataPointPropertySet( iStyle->m_xSeries, iStyle->m_nPointIndex + i
    1048         256 :                         , uno::Reference< frame::XModel >( rImportHelper.GetChartDocument(), uno::UNO_QUERY ) ) );
    1049             : 
    1050          64 :                 if( !xPointProp.is() )
    1051           0 :                     continue;
    1052             : 
    1053          64 :                 if( bIsDonutChart )
    1054             :                 {
    1055             :                     //set special series styles for donut charts first
    1056           0 :                     if( !rCurrStyleName.equals( iStyle->msSeriesStyleNameForDonuts ) )
    1057             :                     {
    1058           0 :                         rCurrStyleName = iStyle->msSeriesStyleNameForDonuts;
    1059             :                         rpStyle = pStylesCtxt->FindStyleChildContext(
    1060           0 :                             SchXMLImportHelper::GetChartFamilyID(), rCurrStyleName );
    1061             :                     }
    1062             : 
    1063             :                     // note: SvXMLStyleContext::FillPropertySet is not const
    1064             :                     XMLPropStyleContext * pPropStyleContext =
    1065             :                         const_cast< XMLPropStyleContext * >(
    1066           0 :                             dynamic_cast< const XMLPropStyleContext * >( rpStyle ));
    1067           0 :                     if( pPropStyleContext )
    1068           0 :                         pPropStyleContext->FillPropertySet( xPointProp );
    1069             :                 }
    1070             : 
    1071             :                 try
    1072             :                 {
    1073             :                     //need to set this explicitly here for old files as the new api does not support this property fully anymore
    1074          64 :                     if( bSwitchOffLinesForScatter )
    1075           0 :                         xPointProp->setPropertyValue("Lines",uno::makeAny(sal_False));
    1076             :                 }
    1077           0 :                 catch( const uno::Exception & )
    1078             :                 {
    1079             :                 }
    1080             : 
    1081          64 :                 if( !rCurrStyleName.equals( iStyle->msStyleName ) )
    1082             :                 {
    1083          46 :                     rCurrStyleName = iStyle->msStyleName;
    1084             :                     rpStyle = pStylesCtxt->FindStyleChildContext(
    1085          46 :                         SchXMLImportHelper::GetChartFamilyID(), rCurrStyleName );
    1086             :                 }
    1087             : 
    1088             :                 // note: SvXMLStyleContext::FillPropertySet is not const
    1089             :                 XMLPropStyleContext * pPropStyleContext =
    1090             :                     const_cast< XMLPropStyleContext * >(
    1091          64 :                         dynamic_cast< const XMLPropStyleContext * >( rpStyle ));
    1092          64 :                 if( pPropStyleContext )
    1093             :                 {
    1094          64 :                     pPropStyleContext->FillPropertySet( xPointProp );
    1095          64 :                     if( iStyle->mbSymbolSizeForSeriesIsMissingInFile )
    1096          64 :                         lcl_resetSymbolSizeForPointsIfNecessary( xPointProp, rImport, pPropStyleContext, pStylesCtxt );
    1097          64 :                 }
    1098             :             }
    1099           0 :             catch( const uno::Exception & rEx )
    1100             :             {
    1101             :                 SAL_INFO("xmloff.chart", "Exception caught during setting styles to data points: " << rEx.Message );
    1102             :             }
    1103             :         }
    1104             :     }   // styles iterator
    1105          86 : }
    1106             : 
    1107             : //static
    1108           0 : void SchXMLSeries2Context::switchSeriesLinesOff( ::std::list< DataRowPointStyle >& rSeriesStyleList )
    1109             : {
    1110           0 :     ::std::list< DataRowPointStyle >::iterator iStyle;
    1111             :     // iterate over series
    1112             : 
    1113           0 :     for( iStyle = rSeriesStyleList.begin(); iStyle != rSeriesStyleList.end(); ++iStyle )
    1114             :     {
    1115           0 :         if( iStyle->meType != DataRowPointStyle::DATA_SERIES )
    1116           0 :             continue;
    1117             : 
    1118             :         try
    1119             :         {
    1120           0 :             uno::Reference< beans::XPropertySet > xSeries( iStyle->m_xOldAPISeries );
    1121           0 :             if( !xSeries.is() )
    1122           0 :                 continue;
    1123             : 
    1124           0 :             xSeries->setPropertyValue("Lines",uno::makeAny(sal_False));
    1125             :         }
    1126           0 :         catch( uno::Exception &  )
    1127             :         {
    1128             :             //end of series reached
    1129             :         }
    1130             :     }
    1131           0 : }
    1132             : 
    1133             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11