Teach symstore more duplicated DLLs
[LibreOffice.git] / xmloff / source / chart / SchXMLSeriesHelper.cxx
blob00adebc0d34723aa223c717815db8bfb697dc800
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <sal/log.hxx>
29 #include <tools/diagnose_ex.h>
31 using namespace ::com::sun::star;
33 using ::com::sun::star::uno::Reference;
34 using ::com::sun::star::uno::Sequence;
36 ::std::vector< Reference< chart2::XDataSeries > >
37 SchXMLSeriesHelper::getDataSeriesFromDiagram(
38 const Reference< chart2::XDiagram > & xDiagram )
40 ::std::vector< Reference< chart2::XDataSeries > > aResult;
42 try
44 Reference< chart2::XCoordinateSystemContainer > xCooSysCnt(
45 xDiagram, uno::UNO_QUERY_THROW );
46 const Sequence< Reference< chart2::XCoordinateSystem > > aCooSysSeq(
47 xCooSysCnt->getCoordinateSystems());
48 for( const auto& rCooSys : aCooSysSeq )
50 Reference< chart2::XChartTypeContainer > xCTCnt( rCooSys, uno::UNO_QUERY_THROW );
51 const Sequence< Reference< chart2::XChartType > > aChartTypeSeq( xCTCnt->getChartTypes());
52 for( const auto& rChartType : aChartTypeSeq )
54 Reference< chart2::XDataSeriesContainer > xDSCnt( rChartType, uno::UNO_QUERY_THROW );
55 Sequence< Reference< chart2::XDataSeries > > aSeriesSeq( xDSCnt->getDataSeries() );
56 ::std::copy( aSeriesSeq.begin(), aSeriesSeq.end(),
57 ::std::back_inserter( aResult ));
61 catch( const uno::Exception & )
63 DBG_UNHANDLED_EXCEPTION("xmloff.chart");
66 return aResult;
69 ::std::map< Reference< chart2::XDataSeries >, sal_Int32 > SchXMLSeriesHelper::getDataSeriesIndexMapFromDiagram(
70 const Reference< chart2::XDiagram > & xDiagram )
72 ::std::map< Reference< chart2::XDataSeries >, sal_Int32 > aRet;
74 sal_Int32 nIndex=0;
76 ::std::vector< Reference< chart2::XDataSeries > > aSeriesVector( SchXMLSeriesHelper::getDataSeriesFromDiagram( xDiagram ));
77 for( const Reference< chart2::XDataSeries >& xSeries : aSeriesVector )
79 if( xSeries.is() )
81 if( aRet.end() == aRet.find(xSeries) )
82 aRet[xSeries]=nIndex;
84 nIndex++;
86 return aRet;
89 namespace {
90 uno::Reference< chart2::XChartType > lcl_getChartTypeOfSeries(
91 const uno::Reference< chart2::XDiagram >& xDiagram
92 , const Reference< chart2::XDataSeries >& xSeries )
94 if(!xDiagram.is())
95 return nullptr;
97 //iterate through the model to find the given xSeries
98 //the found parent indicates the charttype
100 //iterate through all coordinate systems
101 uno::Reference< chart2::XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY );
102 if( !xCooSysContainer.is())
103 return nullptr;
105 const uno::Sequence< uno::Reference< chart2::XCoordinateSystem > > aCooSysList( xCooSysContainer->getCoordinateSystems() );
106 for( const auto& xCooSys : aCooSysList )
108 //iterate through all chart types in the current coordinate system
109 uno::Reference< chart2::XChartTypeContainer > xChartTypeContainer( xCooSys, uno::UNO_QUERY );
110 SAL_WARN_IF( !xChartTypeContainer.is(), "xmloff.chart", "xChartTypeContainer is NULL");
111 if( !xChartTypeContainer.is() )
112 continue;
113 const uno::Sequence< uno::Reference< chart2::XChartType > > aChartTypeList( xChartTypeContainer->getChartTypes() );
114 for( const auto& xChartType : aChartTypeList )
116 //iterate through all series in this chart type
117 uno::Reference< chart2::XDataSeriesContainer > xDataSeriesContainer( xChartType, uno::UNO_QUERY );
118 SAL_WARN_IF( !xDataSeriesContainer.is(), "xmloff.chart", "xDataSeriesContainer is NULL");
119 if( !xDataSeriesContainer.is() )
120 continue;
122 uno::Sequence< uno::Reference< chart2::XDataSeries > > aSeriesList( xDataSeriesContainer->getDataSeries() );
123 if (std::find(aSeriesList.begin(), aSeriesList.end(), xSeries) != aSeriesList.end())
124 return xChartType;
127 return nullptr;
131 bool SchXMLSeriesHelper::isCandleStickSeries(
132 const Reference< chart2::XDataSeries >& xSeries
133 , const Reference< frame::XModel >& xChartModel )
135 bool bRet = false;
137 uno::Reference< chart2::XChartDocument > xNewDoc( xChartModel, uno::UNO_QUERY );
138 if( xNewDoc.is() )
140 uno::Reference< chart2::XDiagram > xNewDiagram( xNewDoc->getFirstDiagram() );
141 if( xNewDiagram.is() )
143 uno::Reference< chart2::XChartType > xChartType( lcl_getChartTypeOfSeries(
144 xNewDiagram, xSeries ) );
145 if( xChartType.is() )
147 OUString aServiceName( xChartType->getChartType() );
148 if( aServiceName == "com.sun.star.chart2.CandleStickChartType" )
149 bRet = true;
153 return bRet;
156 //static
157 uno::Reference< beans::XPropertySet > SchXMLSeriesHelper::createOldAPISeriesPropertySet(
158 const uno::Reference< chart2::XDataSeries >& xSeries
159 , const uno::Reference< frame::XModel >& xChartModel )
161 uno::Reference< beans::XPropertySet > xRet;
163 if( xSeries.is() )
167 uno::Reference< lang::XMultiServiceFactory > xFactory( xChartModel, uno::UNO_QUERY );
168 if( xFactory.is() )
170 xRet.set( xFactory->createInstance( "com.sun.star.comp.chart2.DataSeriesWrapper" ), uno::UNO_QUERY );
171 Reference< lang::XInitialization > xInit( xRet, uno::UNO_QUERY );
172 if(xInit.is())
174 Sequence< uno::Any > aArguments(1);
175 aArguments[0] <<= xSeries;
176 xInit->initialize(aArguments);
180 catch( const uno::Exception & )
182 TOOLS_INFO_EXCEPTION("xmloff.chart", "Exception caught SchXMLSeriesHelper::createOldAPISeriesPropertySet" );
186 return xRet;
189 //static
190 uno::Reference< beans::XPropertySet > SchXMLSeriesHelper::createOldAPIDataPointPropertySet(
191 const uno::Reference< chart2::XDataSeries >& xSeries
192 , sal_Int32 nPointIndex
193 , const uno::Reference< frame::XModel >& xChartModel )
195 uno::Reference< beans::XPropertySet > xRet;
197 if( xSeries.is() )
201 uno::Reference< lang::XMultiServiceFactory > xFactory( xChartModel, uno::UNO_QUERY );
202 if( xFactory.is() )
204 xRet.set( xFactory->createInstance( "com.sun.star.comp.chart2.DataSeriesWrapper" ), uno::UNO_QUERY );
205 Reference< lang::XInitialization > xInit( xRet, uno::UNO_QUERY );
206 if(xInit.is())
208 Sequence< uno::Any > aArguments(2);
209 aArguments[0] <<= xSeries;
210 aArguments[1] <<= nPointIndex;
211 xInit->initialize(aArguments);
215 catch( const uno::Exception & )
217 TOOLS_INFO_EXCEPTION("xmloff.chart", "Exception caught SchXMLSeriesHelper::createOldAPIDataPointPropertySet" );
221 return xRet;
224 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */