Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : : #include "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>
27 : :
28 : : #include <rtl/ustring.h>
29 : : // header for define DBG_ERROR1
30 : : #include <tools/debug.hxx>
31 : :
32 : : #include <typeinfo>
33 : :
34 : : using namespace ::com::sun::star;
35 : : using ::rtl::OUString;
36 : : using ::rtl::OUStringToOString;
37 : :
38 : : using ::com::sun::star::uno::Reference;
39 : : using ::com::sun::star::uno::Sequence;
40 : : using ::rtl::OUString;
41 : :
42 : : // ----------------------------------------
43 : :
44 : : ::std::vector< Reference< chart2::XDataSeries > >
45 : 0 : SchXMLSeriesHelper::getDataSeriesFromDiagram(
46 : : const Reference< chart2::XDiagram > & xDiagram )
47 : : {
48 : 0 : ::std::vector< Reference< chart2::XDataSeries > > aResult;
49 : :
50 : : try
51 : : {
52 : : Reference< chart2::XCoordinateSystemContainer > xCooSysCnt(
53 [ # # ]: 0 : xDiagram, uno::UNO_QUERY_THROW );
54 : : Sequence< Reference< chart2::XCoordinateSystem > > aCooSysSeq(
55 [ # # ][ # # ]: 0 : xCooSysCnt->getCoordinateSystems());
56 [ # # ]: 0 : for( sal_Int32 i=0; i<aCooSysSeq.getLength(); ++i )
57 : : {
58 [ # # ][ # # ]: 0 : Reference< chart2::XChartTypeContainer > xCTCnt( aCooSysSeq[i], uno::UNO_QUERY_THROW );
59 [ # # ][ # # ]: 0 : Sequence< Reference< chart2::XChartType > > aChartTypeSeq( xCTCnt->getChartTypes());
60 [ # # ]: 0 : for( sal_Int32 j=0; j<aChartTypeSeq.getLength(); ++j )
61 : : {
62 [ # # ][ # # ]: 0 : Reference< chart2::XDataSeriesContainer > xDSCnt( aChartTypeSeq[j], uno::UNO_QUERY_THROW );
63 [ # # ][ # # ]: 0 : Sequence< Reference< chart2::XDataSeries > > aSeriesSeq( xDSCnt->getDataSeries() );
64 : 0 : ::std::copy( aSeriesSeq.getConstArray(), aSeriesSeq.getConstArray() + aSeriesSeq.getLength(),
65 [ # # # # ]: 0 : ::std::back_inserter( aResult ));
66 [ # # ]: 0 : }
67 [ # # ][ # # ]: 0 : }
[ # # ]
68 : : }
69 [ # # ]: 0 : catch( const uno::Exception & ex )
70 : : {
71 : : (void)ex; // avoid warning for pro build
72 : :
73 : : OSL_FAIL( OUStringToOString( "Exception caught. Type: " +
74 : : OUString::createFromAscii( typeid( ex ).name() ) +
75 : : ", Message: " + ex.Message, RTL_TEXTENCODING_ASCII_US ).getStr());
76 : : }
77 : :
78 : 0 : return aResult;
79 : : }
80 : :
81 : 0 : ::std::map< Reference< chart2::XDataSeries >, sal_Int32 > SchXMLSeriesHelper::getDataSeriesIndexMapFromDiagram(
82 : : const Reference< chart2::XDiagram > & xDiagram )
83 : : {
84 [ # # ]: 0 : ::std::map< Reference< chart2::XDataSeries >, sal_Int32 > aRet;
85 : :
86 : 0 : sal_Int32 nIndex=0;
87 : :
88 [ # # ]: 0 : ::std::vector< Reference< chart2::XDataSeries > > aSeriesVector( SchXMLSeriesHelper::getDataSeriesFromDiagram( xDiagram ));
89 [ # # ][ # # ]: 0 : for( ::std::vector< Reference< chart2::XDataSeries > >::const_iterator aSeriesIt( aSeriesVector.begin() )
[ # # ][ # # ]
90 : 0 : ; aSeriesIt != aSeriesVector.end()
91 : : ; aSeriesIt++, nIndex++ )
92 : : {
93 : 0 : Reference< chart2::XDataSeries > xSeries( *aSeriesIt );
94 [ # # ]: 0 : if( xSeries.is() )
95 : : {
96 [ # # ][ # # ]: 0 : if( aRet.end() == aRet.find(xSeries) )
97 [ # # ]: 0 : aRet[xSeries]=nIndex;
98 : : }
99 : 0 : }
100 : 0 : return aRet;
101 : : }
102 : :
103 : 0 : uno::Reference< chart2::XChartType > lcl_getChartTypeOfSeries(
104 : : const uno::Reference< chart2::XDiagram >& xDiagram
105 : : , const Reference< chart2::XDataSeries >& xSeries )
106 : : {
107 [ # # ]: 0 : if(!xDiagram.is())
108 [ # # ]: 0 : return 0;
109 : :
110 : : //iterate through the model to find the given xSeries
111 : : //the found parent indicates the charttype
112 : :
113 : : //iterate through all coordinate systems
114 [ # # ]: 0 : uno::Reference< chart2::XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY );
115 [ # # ]: 0 : if( !xCooSysContainer.is())
116 [ # # ]: 0 : return 0;
117 : :
118 [ # # ][ # # ]: 0 : uno::Sequence< uno::Reference< chart2::XCoordinateSystem > > aCooSysList( xCooSysContainer->getCoordinateSystems() );
119 [ # # ]: 0 : for( sal_Int32 nCS = 0; nCS < aCooSysList.getLength(); ++nCS )
120 : : {
121 [ # # ]: 0 : uno::Reference< chart2::XCoordinateSystem > xCooSys( aCooSysList[nCS] );
122 : :
123 : : //iterate through all chart types in the current coordinate system
124 [ # # ]: 0 : uno::Reference< chart2::XChartTypeContainer > xChartTypeContainer( xCooSys, uno::UNO_QUERY );
125 : : OSL_ASSERT( xChartTypeContainer.is());
126 [ # # ]: 0 : if( !xChartTypeContainer.is() )
127 : 0 : continue;
128 [ # # ][ # # ]: 0 : uno::Sequence< uno::Reference< chart2::XChartType > > aChartTypeList( xChartTypeContainer->getChartTypes() );
129 [ # # ]: 0 : for( sal_Int32 nT = 0; nT < aChartTypeList.getLength(); ++nT )
130 : : {
131 [ # # ]: 0 : uno::Reference< chart2::XChartType > xChartType( aChartTypeList[nT] );
132 : :
133 : : //iterate through all series in this chart type
134 [ # # ]: 0 : uno::Reference< chart2::XDataSeriesContainer > xDataSeriesContainer( xChartType, uno::UNO_QUERY );
135 : : OSL_ASSERT( xDataSeriesContainer.is());
136 [ # # ]: 0 : if( !xDataSeriesContainer.is() )
137 : 0 : continue;
138 : :
139 [ # # ][ # # ]: 0 : uno::Sequence< uno::Reference< chart2::XDataSeries > > aSeriesList( xDataSeriesContainer->getDataSeries() );
140 [ # # ]: 0 : for( sal_Int32 nS = 0; nS < aSeriesList.getLength(); ++nS )
141 : : {
142 [ # # ]: 0 : Reference< chart2::XDataSeries > xCurrentSeries( aSeriesList[nS] );
143 : :
144 [ # # ][ # # ]: 0 : if( xSeries == xCurrentSeries )
145 : 0 : return xChartType;
146 [ # # ]: 0 : }
147 [ # # ][ # # ]: 0 : }
[ # # # ]
[ # # # ]
148 [ # # ][ # # ]: 0 : }
[ # # # ]
[ # # # ]
149 [ # # ][ # # ]: 0 : return 0;
150 : : }
151 : :
152 : 0 : bool SchXMLSeriesHelper::isCandleStickSeries(
153 : : const Reference< chart2::XDataSeries >& xSeries
154 : : , const Reference< frame::XModel >& xChartModel )
155 : : {
156 : 0 : bool bRet = false;
157 : :
158 [ # # ]: 0 : uno::Reference< chart2::XChartDocument > xNewDoc( xChartModel, uno::UNO_QUERY );
159 [ # # ]: 0 : if( xNewDoc.is() )
160 : : {
161 [ # # ][ # # ]: 0 : uno::Reference< chart2::XDiagram > xNewDiagram( xNewDoc->getFirstDiagram() );
162 [ # # ]: 0 : if( xNewDiagram.is() )
163 : : {
164 : : uno::Reference< chart2::XChartType > xChartType( lcl_getChartTypeOfSeries(
165 [ # # ]: 0 : xNewDiagram, xSeries ) );
166 [ # # ]: 0 : if( xChartType.is() )
167 : : {
168 [ # # ][ # # ]: 0 : rtl::OUString aServiceName( xChartType->getChartType() );
169 [ # # ]: 0 : if( aServiceName == "com.sun.star.chart2.CandleStickChartType" )
170 : 0 : bRet = true;
171 : 0 : }
172 : 0 : }
173 : : }
174 : 0 : return bRet;
175 : : }
176 : :
177 : : //static
178 : 0 : uno::Reference< beans::XPropertySet > SchXMLSeriesHelper::createOldAPISeriesPropertySet(
179 : : const uno::Reference< chart2::XDataSeries >& xSeries
180 : : , const uno::Reference< frame::XModel >& xChartModel )
181 : : {
182 : 0 : uno::Reference< beans::XPropertySet > xRet;
183 : :
184 [ # # ]: 0 : if( xSeries.is() )
185 : : {
186 : : try
187 : : {
188 [ # # ]: 0 : uno::Reference< lang::XMultiServiceFactory > xFactory( xChartModel, uno::UNO_QUERY );
189 [ # # ]: 0 : if( xFactory.is() )
190 : : {
191 [ # # ]: 0 : xRet = uno::Reference< beans::XPropertySet >( xFactory->createInstance(
192 [ # # ][ # # ]: 0 : "com.sun.star.comp.chart2.DataSeriesWrapper" ), uno::UNO_QUERY );
[ # # ]
193 [ # # ]: 0 : Reference< lang::XInitialization > xInit( xRet, uno::UNO_QUERY );
194 [ # # ]: 0 : if(xInit.is())
195 : : {
196 [ # # ]: 0 : Sequence< uno::Any > aArguments(1);
197 [ # # ][ # # ]: 0 : aArguments[0]=uno::makeAny(xSeries);
198 [ # # ][ # # ]: 0 : xInit->initialize(aArguments);
[ # # ]
199 : 0 : }
200 [ # # ]: 0 : }
201 : : }
202 [ # # ]: 0 : catch( const uno::Exception & rEx )
203 : : {
204 : : (void)rEx; // avoid warning for pro build
205 : : OSL_TRACE( "Exception caught SchXMLSeriesHelper::createOldAPISeriesPropertySet: %s",
206 : : OUStringToOString( rEx.Message, RTL_TEXTENCODING_ASCII_US ).getStr() );
207 : : }
208 : : }
209 : :
210 : 0 : return xRet;
211 : : }
212 : :
213 : : //static
214 : 0 : uno::Reference< beans::XPropertySet > SchXMLSeriesHelper::createOldAPIDataPointPropertySet(
215 : : const uno::Reference< chart2::XDataSeries >& xSeries
216 : : , sal_Int32 nPointIndex
217 : : , const uno::Reference< frame::XModel >& xChartModel )
218 : : {
219 : 0 : uno::Reference< beans::XPropertySet > xRet;
220 : :
221 [ # # ]: 0 : if( xSeries.is() )
222 : : {
223 : : try
224 : : {
225 [ # # ]: 0 : uno::Reference< lang::XMultiServiceFactory > xFactory( xChartModel, uno::UNO_QUERY );
226 [ # # ]: 0 : if( xFactory.is() )
227 : : {
228 [ # # ]: 0 : xRet = uno::Reference< beans::XPropertySet >( xFactory->createInstance(
229 [ # # ][ # # ]: 0 : "com.sun.star.comp.chart2.DataSeriesWrapper" ), uno::UNO_QUERY );
[ # # ]
230 [ # # ]: 0 : Reference< lang::XInitialization > xInit( xRet, uno::UNO_QUERY );
231 [ # # ]: 0 : if(xInit.is())
232 : : {
233 [ # # ]: 0 : Sequence< uno::Any > aArguments(2);
234 [ # # ][ # # ]: 0 : aArguments[0]=uno::makeAny(xSeries);
235 [ # # ][ # # ]: 0 : aArguments[1]=uno::makeAny(nPointIndex);
236 [ # # ][ # # ]: 0 : xInit->initialize(aArguments);
[ # # ]
237 : 0 : }
238 [ # # ]: 0 : }
239 : : }
240 [ # # ]: 0 : catch( const uno::Exception & rEx )
241 : : {
242 : : (void)rEx; // avoid warning for pro build
243 : :
244 : : OSL_TRACE( "Exception caught SchXMLSeriesHelper::createOldAPIDataPointPropertySet: %s",
245 : : OUStringToOString( rEx.Message, RTL_TEXTENCODING_ASCII_US ).getStr() );
246 : : }
247 : : }
248 : :
249 : 0 : return xRet;
250 : : }
251 : :
252 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|