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>
32 using namespace ::com::sun::star
;
34 using ::com::sun::star::uno::Reference
;
35 using ::com::sun::star::uno::Sequence
;
37 ::std::vector
< Reference
< chart2::XDataSeries
> >
38 SchXMLSeriesHelper::getDataSeriesFromDiagram(
39 const Reference
< chart2::XDiagram
> & xDiagram
)
41 ::std::vector
< Reference
< chart2::XDataSeries
> > aResult
;
45 Reference
< chart2::XCoordinateSystemContainer
> xCooSysCnt(
46 xDiagram
, uno::UNO_QUERY_THROW
);
47 Sequence
< Reference
< chart2::XCoordinateSystem
> > aCooSysSeq(
48 xCooSysCnt
->getCoordinateSystems());
49 for( sal_Int32 i
=0; i
<aCooSysSeq
.getLength(); ++i
)
51 Reference
< chart2::XChartTypeContainer
> xCTCnt( aCooSysSeq
[i
], uno::UNO_QUERY_THROW
);
52 Sequence
< Reference
< chart2::XChartType
> > aChartTypeSeq( xCTCnt
->getChartTypes());
53 for( sal_Int32 j
=0; j
<aChartTypeSeq
.getLength(); ++j
)
55 Reference
< chart2::XDataSeriesContainer
> xDSCnt( aChartTypeSeq
[j
], uno::UNO_QUERY_THROW
);
56 Sequence
< Reference
< chart2::XDataSeries
> > aSeriesSeq( xDSCnt
->getDataSeries() );
57 ::std::copy( aSeriesSeq
.begin(), aSeriesSeq
.end(),
58 ::std::back_inserter( aResult
));
62 catch( const uno::Exception
& ex
)
64 SAL_WARN("xmloff.chart", "Exception caught. Type: " << OUString::createFromAscii( typeid( ex
).name() ) << ", Message: " << ex
.Message
);
70 ::std::map
< Reference
< chart2::XDataSeries
>, sal_Int32
> SchXMLSeriesHelper::getDataSeriesIndexMapFromDiagram(
71 const Reference
< chart2::XDiagram
> & xDiagram
)
73 ::std::map
< Reference
< chart2::XDataSeries
>, sal_Int32
> aRet
;
77 ::std::vector
< Reference
< chart2::XDataSeries
> > aSeriesVector( SchXMLSeriesHelper::getDataSeriesFromDiagram( xDiagram
));
78 const ::std::vector
< Reference
< chart2::XDataSeries
> >::const_iterator
aSeriesEnd( aSeriesVector
.end() );
79 for( ::std::vector
< Reference
< chart2::XDataSeries
> >::const_iterator
aSeriesIt( aSeriesVector
.begin() )
80 ; aSeriesIt
!= aSeriesEnd
81 ; ++aSeriesIt
, nIndex
++ )
83 Reference
< chart2::XDataSeries
> xSeries( *aSeriesIt
);
86 if( aRet
.end() == aRet
.find(xSeries
) )
94 uno::Reference
< chart2::XChartType
> lcl_getChartTypeOfSeries(
95 const uno::Reference
< chart2::XDiagram
>& xDiagram
96 , const Reference
< chart2::XDataSeries
>& xSeries
)
101 //iterate through the model to find the given xSeries
102 //the found parent indicates the charttype
104 //iterate through all coordinate systems
105 uno::Reference
< chart2::XCoordinateSystemContainer
> xCooSysContainer( xDiagram
, uno::UNO_QUERY
);
106 if( !xCooSysContainer
.is())
109 uno::Sequence
< uno::Reference
< chart2::XCoordinateSystem
> > aCooSysList( xCooSysContainer
->getCoordinateSystems() );
110 for( sal_Int32 nCS
= 0; nCS
< aCooSysList
.getLength(); ++nCS
)
112 uno::Reference
< chart2::XCoordinateSystem
> xCooSys( aCooSysList
[nCS
] );
114 //iterate through all chart types in the current coordinate system
115 uno::Reference
< chart2::XChartTypeContainer
> xChartTypeContainer( xCooSys
, uno::UNO_QUERY
);
116 SAL_WARN_IF( !xChartTypeContainer
.is(), "xmloff.chart", "xChartTypeContainer is NULL");
117 if( !xChartTypeContainer
.is() )
119 uno::Sequence
< uno::Reference
< chart2::XChartType
> > aChartTypeList( xChartTypeContainer
->getChartTypes() );
120 for( sal_Int32 nT
= 0; nT
< aChartTypeList
.getLength(); ++nT
)
122 uno::Reference
< chart2::XChartType
> xChartType( aChartTypeList
[nT
] );
124 //iterate through all series in this chart type
125 uno::Reference
< chart2::XDataSeriesContainer
> xDataSeriesContainer( xChartType
, uno::UNO_QUERY
);
126 SAL_WARN_IF( !xDataSeriesContainer
.is(), "xmloff.chart", "xDataSeriesContainer is NULL");
127 if( !xDataSeriesContainer
.is() )
130 uno::Sequence
< uno::Reference
< chart2::XDataSeries
> > aSeriesList( xDataSeriesContainer
->getDataSeries() );
131 for( sal_Int32 nS
= 0; nS
< aSeriesList
.getLength(); ++nS
)
133 Reference
< chart2::XDataSeries
> xCurrentSeries( aSeriesList
[nS
] );
135 if( xSeries
== xCurrentSeries
)
144 bool SchXMLSeriesHelper::isCandleStickSeries(
145 const Reference
< chart2::XDataSeries
>& xSeries
146 , const Reference
< frame::XModel
>& xChartModel
)
150 uno::Reference
< chart2::XChartDocument
> xNewDoc( xChartModel
, uno::UNO_QUERY
);
153 uno::Reference
< chart2::XDiagram
> xNewDiagram( xNewDoc
->getFirstDiagram() );
154 if( xNewDiagram
.is() )
156 uno::Reference
< chart2::XChartType
> xChartType( lcl_getChartTypeOfSeries(
157 xNewDiagram
, xSeries
) );
158 if( xChartType
.is() )
160 OUString
aServiceName( xChartType
->getChartType() );
161 if( aServiceName
== "com.sun.star.chart2.CandleStickChartType" )
170 uno::Reference
< beans::XPropertySet
> SchXMLSeriesHelper::createOldAPISeriesPropertySet(
171 const uno::Reference
< chart2::XDataSeries
>& xSeries
172 , const uno::Reference
< frame::XModel
>& xChartModel
)
174 uno::Reference
< beans::XPropertySet
> xRet
;
180 uno::Reference
< lang::XMultiServiceFactory
> xFactory( xChartModel
, uno::UNO_QUERY
);
183 xRet
.set( xFactory
->createInstance( "com.sun.star.comp.chart2.DataSeriesWrapper" ), uno::UNO_QUERY
);
184 Reference
< lang::XInitialization
> xInit( xRet
, uno::UNO_QUERY
);
187 Sequence
< uno::Any
> aArguments(1);
188 aArguments
[0]=uno::makeAny(xSeries
);
189 xInit
->initialize(aArguments
);
193 catch( const uno::Exception
& rEx
)
195 SAL_INFO("xmloff.chart", "Exception caught SchXMLSeriesHelper::createOldAPISeriesPropertySet: " << rEx
.Message
);
203 uno::Reference
< beans::XPropertySet
> SchXMLSeriesHelper::createOldAPIDataPointPropertySet(
204 const uno::Reference
< chart2::XDataSeries
>& xSeries
205 , sal_Int32 nPointIndex
206 , const uno::Reference
< frame::XModel
>& xChartModel
)
208 uno::Reference
< beans::XPropertySet
> xRet
;
214 uno::Reference
< lang::XMultiServiceFactory
> xFactory( xChartModel
, uno::UNO_QUERY
);
217 xRet
.set( xFactory
->createInstance( "com.sun.star.comp.chart2.DataSeriesWrapper" ), uno::UNO_QUERY
);
218 Reference
< lang::XInitialization
> xInit( xRet
, uno::UNO_QUERY
);
221 Sequence
< uno::Any
> aArguments(2);
222 aArguments
[0]=uno::makeAny(xSeries
);
223 aArguments
[1]=uno::makeAny(nPointIndex
);
224 xInit
->initialize(aArguments
);
228 catch( const uno::Exception
& rEx
)
230 SAL_INFO("xmloff.chart", "Exception caught SchXMLSeriesHelper::createOldAPIDataPointPropertySet: " << rEx
.Message
);
237 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */