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