/src/libreoffice/xmloff/source/chart/SchXMLSeriesHelper.cxx
Line | Count | Source |
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 <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> |
27 | | |
28 | | #include <sal/log.hxx> |
29 | | #include <comphelper/diagnose_ex.hxx> |
30 | | |
31 | | using namespace ::com::sun::star; |
32 | | |
33 | | using ::com::sun::star::uno::Reference; |
34 | | using ::com::sun::star::uno::Sequence; |
35 | | |
36 | | ::std::vector< Reference< chart2::XDataSeries > > |
37 | | SchXMLSeriesHelper::getDataSeriesFromDiagram( |
38 | | const Reference< chart2::XDiagram > & xDiagram ) |
39 | 0 | { |
40 | 0 | ::std::vector< Reference< chart2::XDataSeries > > aResult; |
41 | |
|
42 | 0 | try |
43 | 0 | { |
44 | 0 | Reference< chart2::XCoordinateSystemContainer > xCooSysCnt( |
45 | 0 | xDiagram, uno::UNO_QUERY_THROW ); |
46 | 0 | const Sequence< Reference< chart2::XCoordinateSystem > > aCooSysSeq( |
47 | 0 | xCooSysCnt->getCoordinateSystems()); |
48 | 0 | for( const auto& rCooSys : aCooSysSeq ) |
49 | 0 | { |
50 | 0 | Reference< chart2::XChartTypeContainer > xCTCnt( rCooSys, uno::UNO_QUERY_THROW ); |
51 | 0 | const Sequence< Reference< chart2::XChartType > > aChartTypeSeq( xCTCnt->getChartTypes()); |
52 | 0 | for( const auto& rChartType : aChartTypeSeq ) |
53 | 0 | { |
54 | 0 | Reference< chart2::XDataSeriesContainer > xDSCnt( rChartType, uno::UNO_QUERY_THROW ); |
55 | 0 | const Sequence< Reference< chart2::XDataSeries > > aSeriesSeq( xDSCnt->getDataSeries() ); |
56 | 0 | aResult.insert( aResult.end(), aSeriesSeq.begin(), aSeriesSeq.end() ); |
57 | 0 | } |
58 | 0 | } |
59 | 0 | } |
60 | 0 | catch( const uno::Exception & ) |
61 | 0 | { |
62 | 0 | DBG_UNHANDLED_EXCEPTION("xmloff.chart"); |
63 | 0 | } |
64 | |
|
65 | 0 | return aResult; |
66 | 0 | } |
67 | | |
68 | | ::std::map< Reference< chart2::XDataSeries >, sal_Int32 > SchXMLSeriesHelper::getDataSeriesIndexMapFromDiagram( |
69 | | const Reference< chart2::XDiagram > & xDiagram ) |
70 | 0 | { |
71 | 0 | ::std::map< Reference< chart2::XDataSeries >, sal_Int32 > aRet; |
72 | |
|
73 | 0 | sal_Int32 nIndex=0; |
74 | |
|
75 | 0 | ::std::vector< Reference< chart2::XDataSeries > > aSeriesVector( SchXMLSeriesHelper::getDataSeriesFromDiagram( xDiagram )); |
76 | 0 | for( const Reference< chart2::XDataSeries >& xSeries : aSeriesVector ) |
77 | 0 | { |
78 | 0 | if( xSeries.is() ) |
79 | 0 | { |
80 | 0 | if( aRet.end() == aRet.find(xSeries) ) |
81 | 0 | aRet[xSeries]=nIndex; |
82 | 0 | } |
83 | 0 | nIndex++; |
84 | 0 | } |
85 | 0 | return aRet; |
86 | 0 | } |
87 | | |
88 | | namespace { |
89 | | uno::Reference< chart2::XChartType > lcl_getChartTypeOfSeries( |
90 | | const uno::Reference< chart2::XDiagram >& xDiagram |
91 | | , const Reference< chart2::XDataSeries >& xSeries ) |
92 | 0 | { |
93 | 0 | if(!xDiagram.is()) |
94 | 0 | return nullptr; |
95 | | |
96 | | //iterate through the model to find the given xSeries |
97 | | //the found parent indicates the charttype |
98 | | |
99 | | //iterate through all coordinate systems |
100 | 0 | uno::Reference< chart2::XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY ); |
101 | 0 | if( !xCooSysContainer.is()) |
102 | 0 | return nullptr; |
103 | | |
104 | 0 | const uno::Sequence< uno::Reference< chart2::XCoordinateSystem > > aCooSysList( xCooSysContainer->getCoordinateSystems() ); |
105 | 0 | for( const auto& xCooSys : aCooSysList ) |
106 | 0 | { |
107 | | //iterate through all chart types in the current coordinate system |
108 | 0 | uno::Reference< chart2::XChartTypeContainer > xChartTypeContainer( xCooSys, uno::UNO_QUERY ); |
109 | 0 | SAL_WARN_IF( !xChartTypeContainer.is(), "xmloff.chart", "xChartTypeContainer is NULL"); |
110 | 0 | if( !xChartTypeContainer.is() ) |
111 | 0 | continue; |
112 | 0 | const uno::Sequence< uno::Reference< chart2::XChartType > > aChartTypeList( xChartTypeContainer->getChartTypes() ); |
113 | 0 | for( const auto& xChartType : aChartTypeList ) |
114 | 0 | { |
115 | | //iterate through all series in this chart type |
116 | 0 | uno::Reference< chart2::XDataSeriesContainer > xDataSeriesContainer( xChartType, uno::UNO_QUERY ); |
117 | 0 | SAL_WARN_IF( !xDataSeriesContainer.is(), "xmloff.chart", "xDataSeriesContainer is NULL"); |
118 | 0 | if( !xDataSeriesContainer.is() ) |
119 | 0 | continue; |
120 | | |
121 | 0 | const uno::Sequence< uno::Reference< chart2::XDataSeries > > aSeriesList( xDataSeriesContainer->getDataSeries() ); |
122 | 0 | if (std::find(aSeriesList.begin(), aSeriesList.end(), xSeries) != aSeriesList.end()) |
123 | 0 | return xChartType; |
124 | 0 | } |
125 | 0 | } |
126 | 0 | return nullptr; |
127 | 0 | } |
128 | | } |
129 | | |
130 | | bool SchXMLSeriesHelper::isCandleStickSeries( |
131 | | const Reference< chart2::XDataSeries >& xSeries |
132 | | , const Reference< frame::XModel >& xChartModel ) |
133 | 0 | { |
134 | 0 | bool bRet = false; |
135 | |
|
136 | 0 | uno::Reference< chart2::XChartDocument > xNewDoc( xChartModel, uno::UNO_QUERY ); |
137 | 0 | if( xNewDoc.is() ) |
138 | 0 | { |
139 | 0 | uno::Reference< chart2::XDiagram > xNewDiagram( xNewDoc->getFirstDiagram() ); |
140 | 0 | if( xNewDiagram.is() ) |
141 | 0 | { |
142 | 0 | uno::Reference< chart2::XChartType > xChartType( lcl_getChartTypeOfSeries( |
143 | 0 | xNewDiagram, xSeries ) ); |
144 | 0 | if( xChartType.is() ) |
145 | 0 | { |
146 | 0 | OUString aServiceName( xChartType->getChartType() ); |
147 | 0 | if( aServiceName == "com.sun.star.chart2.CandleStickChartType" ) |
148 | 0 | bRet = true; |
149 | 0 | } |
150 | 0 | } |
151 | 0 | } |
152 | 0 | return bRet; |
153 | 0 | } |
154 | | |
155 | | //static |
156 | | uno::Reference< beans::XPropertySet > SchXMLSeriesHelper::createOldAPISeriesPropertySet( |
157 | | const uno::Reference< chart2::XDataSeries >& xSeries |
158 | | , const uno::Reference< frame::XModel >& xChartModel ) |
159 | 0 | { |
160 | 0 | uno::Reference< beans::XPropertySet > xRet; |
161 | |
|
162 | 0 | if( xSeries.is() ) |
163 | 0 | { |
164 | 0 | try |
165 | 0 | { |
166 | 0 | uno::Reference< lang::XMultiServiceFactory > xFactory( xChartModel, uno::UNO_QUERY ); |
167 | 0 | if( xFactory.is() ) |
168 | 0 | { |
169 | 0 | xRet.set( xFactory->createInstance( u"com.sun.star.comp.chart2.DataSeriesWrapper"_ustr ), uno::UNO_QUERY ); |
170 | 0 | Reference< lang::XInitialization > xInit( xRet, uno::UNO_QUERY ); |
171 | 0 | if(xInit.is()) |
172 | 0 | { |
173 | 0 | xInit->initialize( { uno::Any(xSeries) }); |
174 | 0 | } |
175 | 0 | } |
176 | 0 | } |
177 | 0 | catch( const uno::Exception & ) |
178 | 0 | { |
179 | 0 | TOOLS_INFO_EXCEPTION("xmloff.chart", "Exception caught SchXMLSeriesHelper::createOldAPISeriesPropertySet" ); |
180 | 0 | } |
181 | 0 | } |
182 | | |
183 | 0 | return xRet; |
184 | 0 | } |
185 | | |
186 | | //static |
187 | | uno::Reference< beans::XPropertySet > SchXMLSeriesHelper::createOldAPIDataPointPropertySet( |
188 | | const uno::Reference< chart2::XDataSeries >& xSeries |
189 | | , sal_Int32 nPointIndex |
190 | | , const uno::Reference< frame::XModel >& xChartModel ) |
191 | 0 | { |
192 | 0 | uno::Reference< beans::XPropertySet > xRet; |
193 | |
|
194 | 0 | if( xSeries.is() ) |
195 | 0 | { |
196 | 0 | try |
197 | 0 | { |
198 | 0 | uno::Reference< lang::XMultiServiceFactory > xFactory( xChartModel, uno::UNO_QUERY ); |
199 | 0 | if( xFactory.is() ) |
200 | 0 | { |
201 | 0 | xRet.set( xFactory->createInstance( u"com.sun.star.comp.chart2.DataSeriesWrapper"_ustr ), uno::UNO_QUERY ); |
202 | 0 | Reference< lang::XInitialization > xInit( xRet, uno::UNO_QUERY ); |
203 | 0 | if(xInit.is()) |
204 | 0 | { |
205 | 0 | xInit->initialize({ uno::Any(xSeries), uno::Any(nPointIndex) }); |
206 | 0 | } |
207 | 0 | } |
208 | 0 | } |
209 | 0 | catch( const uno::Exception & ) |
210 | 0 | { |
211 | 0 | TOOLS_INFO_EXCEPTION("xmloff.chart", "Exception caught SchXMLSeriesHelper::createOldAPIDataPointPropertySet" ); |
212 | 0 | } |
213 | 0 | } |
214 | | |
215 | 0 | return xRet; |
216 | 0 | } |
217 | | |
218 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |