1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <xmloff/SchXMLSeriesHelper.hxx>
21 #include <com/sun/star/chart2/XChartDocument.hpp>
22 #include <com/sun/star/chart2/XChartTypeContainer.hpp>
23 #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
24 #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
25 #include <com/sun/star/lang/XInitialization.hpp>
26 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
28 #include <rtl/ustring.h>
29 // header for define DBG_ERROR1
30 #include <tools/debug.hxx>
34 using namespace ::com::sun::star
;
36 using ::com::sun::star::uno::Reference
;
37 using ::com::sun::star::uno::Sequence
;
39 // ----------------------------------------
41 ::std::vector
< Reference
< chart2::XDataSeries
> >
42 SchXMLSeriesHelper::getDataSeriesFromDiagram(
43 const Reference
< chart2::XDiagram
> & xDiagram
)
45 ::std::vector
< Reference
< chart2::XDataSeries
> > aResult
;
49 Reference
< chart2::XCoordinateSystemContainer
> xCooSysCnt(
50 xDiagram
, uno::UNO_QUERY_THROW
);
51 Sequence
< Reference
< chart2::XCoordinateSystem
> > aCooSysSeq(
52 xCooSysCnt
->getCoordinateSystems());
53 for( sal_Int32 i
=0; i
<aCooSysSeq
.getLength(); ++i
)
55 Reference
< chart2::XChartTypeContainer
> xCTCnt( aCooSysSeq
[i
], uno::UNO_QUERY_THROW
);
56 Sequence
< Reference
< chart2::XChartType
> > aChartTypeSeq( xCTCnt
->getChartTypes());
57 for( sal_Int32 j
=0; j
<aChartTypeSeq
.getLength(); ++j
)
59 Reference
< chart2::XDataSeriesContainer
> xDSCnt( aChartTypeSeq
[j
], uno::UNO_QUERY_THROW
);
60 Sequence
< Reference
< chart2::XDataSeries
> > aSeriesSeq( xDSCnt
->getDataSeries() );
61 ::std::copy( aSeriesSeq
.getConstArray(), aSeriesSeq
.getConstArray() + aSeriesSeq
.getLength(),
62 ::std::back_inserter( aResult
));
66 catch( const uno::Exception
& ex
)
68 SAL_WARN("xmloff.chart", "Exception caught. Type: " << OUString::createFromAscii( typeid( ex
).name() ) << ", Message: " << ex
.Message
);
74 ::std::map
< Reference
< chart2::XDataSeries
>, sal_Int32
> SchXMLSeriesHelper::getDataSeriesIndexMapFromDiagram(
75 const Reference
< chart2::XDiagram
> & xDiagram
)
77 ::std::map
< Reference
< chart2::XDataSeries
>, sal_Int32
> aRet
;
81 ::std::vector
< Reference
< chart2::XDataSeries
> > aSeriesVector( SchXMLSeriesHelper::getDataSeriesFromDiagram( xDiagram
));
82 const ::std::vector
< Reference
< chart2::XDataSeries
> >::const_iterator
aSeriesEnd( aSeriesVector
.end() );
83 for( ::std::vector
< Reference
< chart2::XDataSeries
> >::const_iterator
aSeriesIt( aSeriesVector
.begin() )
84 ; aSeriesIt
!= aSeriesEnd
85 ; ++aSeriesIt
, nIndex
++ )
87 Reference
< chart2::XDataSeries
> xSeries( *aSeriesIt
);
90 if( aRet
.end() == aRet
.find(xSeries
) )
98 uno::Reference
< chart2::XChartType
> lcl_getChartTypeOfSeries(
99 const uno::Reference
< chart2::XDiagram
>& xDiagram
100 , const Reference
< chart2::XDataSeries
>& xSeries
)
105 //iterate through the model to find the given xSeries
106 //the found parent indicates the charttype
108 //iterate through all coordinate systems
109 uno::Reference
< chart2::XCoordinateSystemContainer
> xCooSysContainer( xDiagram
, uno::UNO_QUERY
);
110 if( !xCooSysContainer
.is())
113 uno::Sequence
< uno::Reference
< chart2::XCoordinateSystem
> > aCooSysList( xCooSysContainer
->getCoordinateSystems() );
114 for( sal_Int32 nCS
= 0; nCS
< aCooSysList
.getLength(); ++nCS
)
116 uno::Reference
< chart2::XCoordinateSystem
> xCooSys( aCooSysList
[nCS
] );
118 //iterate through all chart types in the current coordinate system
119 uno::Reference
< chart2::XChartTypeContainer
> xChartTypeContainer( xCooSys
, uno::UNO_QUERY
);
120 SAL_WARN_IF( !xChartTypeContainer
.is(), "xmloff.chart", "xChartTypeContainer is NULL");
121 if( !xChartTypeContainer
.is() )
123 uno::Sequence
< uno::Reference
< chart2::XChartType
> > aChartTypeList( xChartTypeContainer
->getChartTypes() );
124 for( sal_Int32 nT
= 0; nT
< aChartTypeList
.getLength(); ++nT
)
126 uno::Reference
< chart2::XChartType
> xChartType( aChartTypeList
[nT
] );
128 //iterate through all series in this chart type
129 uno::Reference
< chart2::XDataSeriesContainer
> xDataSeriesContainer( xChartType
, uno::UNO_QUERY
);
130 SAL_WARN_IF( !xDataSeriesContainer
.is(), "xmloff.chart", "xDataSeriesContainer is NULL");
131 if( !xDataSeriesContainer
.is() )
134 uno::Sequence
< uno::Reference
< chart2::XDataSeries
> > aSeriesList( xDataSeriesContainer
->getDataSeries() );
135 for( sal_Int32 nS
= 0; nS
< aSeriesList
.getLength(); ++nS
)
137 Reference
< chart2::XDataSeries
> xCurrentSeries( aSeriesList
[nS
] );
139 if( xSeries
== xCurrentSeries
)
148 bool SchXMLSeriesHelper::isCandleStickSeries(
149 const Reference
< chart2::XDataSeries
>& xSeries
150 , const Reference
< frame::XModel
>& xChartModel
)
154 uno::Reference
< chart2::XChartDocument
> xNewDoc( xChartModel
, uno::UNO_QUERY
);
157 uno::Reference
< chart2::XDiagram
> xNewDiagram( xNewDoc
->getFirstDiagram() );
158 if( xNewDiagram
.is() )
160 uno::Reference
< chart2::XChartType
> xChartType( lcl_getChartTypeOfSeries(
161 xNewDiagram
, xSeries
) );
162 if( xChartType
.is() )
164 OUString
aServiceName( xChartType
->getChartType() );
165 if( aServiceName
== "com.sun.star.chart2.CandleStickChartType" )
174 uno::Reference
< beans::XPropertySet
> SchXMLSeriesHelper::createOldAPISeriesPropertySet(
175 const uno::Reference
< chart2::XDataSeries
>& xSeries
176 , const uno::Reference
< frame::XModel
>& xChartModel
)
178 uno::Reference
< beans::XPropertySet
> xRet
;
184 uno::Reference
< lang::XMultiServiceFactory
> xFactory( xChartModel
, uno::UNO_QUERY
);
187 xRet
= uno::Reference
< beans::XPropertySet
>( xFactory
->createInstance(
188 "com.sun.star.comp.chart2.DataSeriesWrapper" ), uno::UNO_QUERY
);
189 Reference
< lang::XInitialization
> xInit( xRet
, uno::UNO_QUERY
);
192 Sequence
< uno::Any
> aArguments(1);
193 aArguments
[0]=uno::makeAny(xSeries
);
194 xInit
->initialize(aArguments
);
198 catch( const uno::Exception
& rEx
)
200 SAL_INFO("xmloff.chart", "Exception caught SchXMLSeriesHelper::createOldAPISeriesPropertySet: " << rEx
.Message
);
208 uno::Reference
< beans::XPropertySet
> SchXMLSeriesHelper::createOldAPIDataPointPropertySet(
209 const uno::Reference
< chart2::XDataSeries
>& xSeries
210 , sal_Int32 nPointIndex
211 , const uno::Reference
< frame::XModel
>& xChartModel
)
213 uno::Reference
< beans::XPropertySet
> xRet
;
219 uno::Reference
< lang::XMultiServiceFactory
> xFactory( xChartModel
, uno::UNO_QUERY
);
222 xRet
= uno::Reference
< beans::XPropertySet
>( xFactory
->createInstance(
223 "com.sun.star.comp.chart2.DataSeriesWrapper" ), uno::UNO_QUERY
);
224 Reference
< lang::XInitialization
> xInit( xRet
, uno::UNO_QUERY
);
227 Sequence
< uno::Any
> aArguments(2);
228 aArguments
[0]=uno::makeAny(xSeries
);
229 aArguments
[1]=uno::makeAny(nPointIndex
);
230 xInit
->initialize(aArguments
);
234 catch( const uno::Exception
& rEx
)
236 SAL_INFO("xmloff.chart", "Exception caught SchXMLSeriesHelper::createOldAPIDataPointPropertySet: " << rEx
.Message
);
243 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */