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 "ScatterChartTypeTemplate.hxx"
21 : : #include "macros.hxx"
22 : : #include "XYDataInterpreter.hxx"
23 : : #include "CartesianCoordinateSystem.hxx"
24 : : #include "DiagramHelper.hxx"
25 : : #include "servicenames_charttypes.hxx"
26 : : #include "ContainerHelper.hxx"
27 : : #include "DataSeriesHelper.hxx"
28 : : #include <com/sun/star/chart2/SymbolStyle.hpp>
29 : : #include <com/sun/star/chart2/Symbol.hpp>
30 : : #include <com/sun/star/drawing/LineStyle.hpp>
31 : : #include "PropertyHelper.hxx"
32 : : #include <com/sun/star/beans/PropertyAttribute.hpp>
33 : :
34 : : #include <algorithm>
35 : :
36 : : using namespace ::com::sun::star;
37 : :
38 : : using ::com::sun::star::uno::Reference;
39 : : using ::com::sun::star::uno::Sequence;
40 : : using ::rtl::OUString;
41 : : using ::com::sun::star::beans::Property;
42 : : using ::com::sun::star::uno::Reference;
43 : : using ::com::sun::star::uno::Any;
44 : : using ::osl::MutexGuard;
45 : :
46 : : namespace
47 : : {
48 : :
49 : 16 : static const OUString lcl_aServiceName(
50 : : RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.ScatterChartTypeTemplate" ));
51 : :
52 : : enum
53 : : {
54 : : PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_STYLE,
55 : : PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_RESOLUTION,
56 : : PROP_SCATTERCHARTTYPE_TEMPLATE_SPLINE_ORDER
57 : :
58 : : };
59 : :
60 : 2 : void lcl_AddPropertiesToVector(
61 : : ::std::vector< Property > & rOutProperties )
62 : : {
63 : : rOutProperties.push_back(
64 : : Property( C2U( "CurveStyle" ),
65 : : PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_STYLE,
66 [ + - ]: 2 : ::getCppuType( reinterpret_cast< const chart2::CurveStyle * >(0)),
67 : : beans::PropertyAttribute::BOUND
68 [ + - ][ + - ]: 2 : | beans::PropertyAttribute::MAYBEDEFAULT ));
69 : : rOutProperties.push_back(
70 : : Property( C2U( "CurveResolution" ),
71 : : PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_RESOLUTION,
72 [ + - ]: 2 : ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
73 : : beans::PropertyAttribute::BOUND
74 [ + - ][ + - ]: 2 : | beans::PropertyAttribute::MAYBEDEFAULT ));
75 : : rOutProperties.push_back(
76 : : Property( C2U( "SplineOrder" ),
77 : : PROP_SCATTERCHARTTYPE_TEMPLATE_SPLINE_ORDER,
78 [ + - ]: 2 : ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
79 : : beans::PropertyAttribute::BOUND
80 [ + - ][ + - ]: 2 : | beans::PropertyAttribute::MAYBEDEFAULT ));
81 : 2 : }
82 : :
83 : : struct StaticScatterChartTypeTemplateDefaults_Initializer
84 : : {
85 : 2 : ::chart::tPropertyValueMap* operator()()
86 : : {
87 [ + - ][ + - ]: 2 : static ::chart::tPropertyValueMap aStaticDefaults;
[ + - ][ # # ]
88 : 2 : lcl_AddDefaultsToMap( aStaticDefaults );
89 : 2 : return &aStaticDefaults;
90 : : }
91 : : private:
92 : 2 : void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
93 : : {
94 [ + - ]: 2 : ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_STYLE, chart2::CurveStyle_LINES );
95 [ + - ]: 2 : ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_RESOLUTION, 20 );
96 : :
97 : : // todo: check whether order 3 means polygons of order 3 or 2. (see
98 : : // http://www.people.nnov.ru/fractal/Splines/Basis.htm )
99 [ + - ]: 2 : ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_SCATTERCHARTTYPE_TEMPLATE_SPLINE_ORDER, 3 );
100 : 2 : }
101 : : };
102 : :
103 : : struct StaticScatterChartTypeTemplateDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticScatterChartTypeTemplateDefaults_Initializer >
104 : : {
105 : : };
106 : :
107 : : struct StaticScatterChartTypeTemplateInfoHelper_Initializer
108 : : {
109 : 2 : ::cppu::OPropertyArrayHelper* operator()()
110 : : {
111 [ + - ][ + - ]: 2 : static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
[ + - ][ + - ]
[ + - ][ # # ]
112 : 2 : return &aPropHelper;
113 : : }
114 : :
115 : : private:
116 : 2 : Sequence< Property > lcl_GetPropertySequence()
117 : : {
118 [ + - ]: 2 : ::std::vector< ::com::sun::star::beans::Property > aProperties;
119 [ + - ]: 2 : lcl_AddPropertiesToVector( aProperties );
120 : :
121 : : ::std::sort( aProperties.begin(), aProperties.end(),
122 [ + - ]: 2 : ::chart::PropertyNameLess() );
123 : :
124 [ + - ]: 2 : return ::chart::ContainerHelper::ContainerToSequence( aProperties );
125 : : }
126 : :
127 : : };
128 : :
129 : : struct StaticScatterChartTypeTemplateInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticScatterChartTypeTemplateInfoHelper_Initializer >
130 : : {
131 : : };
132 : :
133 : : struct StaticScatterChartTypeTemplateInfo_Initializer
134 : : {
135 : 0 : uno::Reference< beans::XPropertySetInfo >* operator()()
136 : : {
137 : : static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
138 [ # # ][ # # ]: 0 : ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticScatterChartTypeTemplateInfoHelper::get() ) );
[ # # ][ # # ]
[ # # ]
139 : 0 : return &xPropertySetInfo;
140 : : }
141 : : };
142 : :
143 : : struct StaticScatterChartTypeTemplateInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticScatterChartTypeTemplateInfo_Initializer >
144 : : {
145 : : };
146 : :
147 : : } // anonymous namespace
148 : :
149 : : namespace chart
150 : : {
151 : :
152 : 30 : ScatterChartTypeTemplate::ScatterChartTypeTemplate(
153 : : Reference<
154 : : uno::XComponentContext > const & xContext,
155 : : const OUString & rServiceName,
156 : : bool bSymbols,
157 : : bool bHasLines /* = true */,
158 : : sal_Int32 nDim /* = 2 */ ) :
159 : : ChartTypeTemplate( xContext, rServiceName ),
160 : : ::property::OPropertySet( m_aMutex ),
161 : : m_bHasSymbols( bSymbols ),
162 : : m_bHasLines( bHasLines ),
163 [ + - ][ + - ]: 30 : m_nDim( nDim )
164 : : {
165 [ - + ]: 30 : if( nDim == 3 )
166 : 0 : m_bHasSymbols = false;
167 : 30 : }
168 : :
169 [ + - ][ + - ]: 30 : ScatterChartTypeTemplate::~ScatterChartTypeTemplate()
170 [ - + ]: 60 : {}
171 : :
172 : : // ____ OPropertySet ____
173 : 318 : uno::Any ScatterChartTypeTemplate::GetDefaultValue( sal_Int32 nHandle ) const
174 : : throw(beans::UnknownPropertyException)
175 : : {
176 [ + - ]: 318 : const tPropertyValueMap& rStaticDefaults = *StaticScatterChartTypeTemplateDefaults::get();
177 [ + - ]: 318 : tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
178 [ - + ]: 318 : if( aFound == rStaticDefaults.end() )
179 : 0 : return uno::Any();
180 : 318 : return (*aFound).second;
181 : : }
182 : :
183 : 300 : ::cppu::IPropertyArrayHelper & SAL_CALL ScatterChartTypeTemplate::getInfoHelper()
184 : : {
185 : 300 : return *StaticScatterChartTypeTemplateInfoHelper::get();
186 : : }
187 : :
188 : : // ____ XPropertySet ____
189 : 0 : uno::Reference< beans::XPropertySetInfo > SAL_CALL ScatterChartTypeTemplate::getPropertySetInfo()
190 : : throw (uno::RuntimeException)
191 : : {
192 : 0 : return *StaticScatterChartTypeTemplateInfo::get();
193 : : }
194 : :
195 : 158 : sal_Int32 ScatterChartTypeTemplate::getDimension() const
196 : : {
197 : 158 : return m_nDim;
198 : : }
199 : :
200 : 94 : StackMode ScatterChartTypeTemplate::getStackMode( sal_Int32 /* nChartTypeIndex */ ) const
201 : : {
202 [ - + ]: 94 : if( m_nDim == 3 )
203 : 0 : return StackMode_Z_STACKED;
204 : 94 : return StackMode_NONE;
205 : : }
206 : :
207 : 58 : void SAL_CALL ScatterChartTypeTemplate::applyStyle(
208 : : const Reference< chart2::XDataSeries >& xSeries,
209 : : ::sal_Int32 nChartTypeIndex,
210 : : ::sal_Int32 nSeriesIndex,
211 : : ::sal_Int32 nSeriesCount )
212 : : throw (uno::RuntimeException)
213 : : {
214 : 58 : ChartTypeTemplate::applyStyle( xSeries, nChartTypeIndex, nSeriesIndex, nSeriesCount );
215 : :
216 : : try
217 : : {
218 [ + - ]: 58 : Reference< beans::XPropertySet > xProp( xSeries, uno::UNO_QUERY_THROW );
219 : :
220 [ + - ]: 58 : DataSeriesHelper::switchSymbolsOnOrOff( xProp, m_bHasSymbols, nSeriesIndex );
221 [ + - ]: 58 : DataSeriesHelper::switchLinesOnOrOff( xProp, m_bHasLines );
222 [ + - ]: 58 : DataSeriesHelper::makeLinesThickOrThin( xProp, m_nDim==2 );
223 [ - + ]: 58 : if( m_nDim==3 )
224 [ # # ][ # # ]: 58 : DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, C2U( "BorderStyle" ), uno::makeAny( drawing::LineStyle_NONE ) );
[ # # ][ # # ]
225 : : }
226 : 0 : catch( const uno::Exception & ex )
227 : : {
228 : : ASSERT_EXCEPTION( ex );
229 : : }
230 : 58 : }
231 : :
232 : : // ____ XChartTypeTemplate ____
233 : 6 : sal_Bool SAL_CALL ScatterChartTypeTemplate::supportsCategories()
234 : : throw (uno::RuntimeException)
235 : : {
236 : 6 : return sal_False;
237 : : }
238 : :
239 : 24 : sal_Bool SAL_CALL ScatterChartTypeTemplate::matchesTemplate(
240 : : const Reference< chart2::XDiagram >& xDiagram,
241 : : sal_Bool bAdaptProperties )
242 : : throw (uno::RuntimeException)
243 : : {
244 : 24 : sal_Bool bResult = ChartTypeTemplate::matchesTemplate( xDiagram, bAdaptProperties );
245 : :
246 : : // check symbol-style and line-style
247 : : // for a template with symbols (or with lines) it is ok, if there is at least one series
248 : : // with symbols (or with lines)
249 [ + + ]: 24 : if( bResult )
250 : : {
251 : 12 : bool bSymbolFound = false;
252 : 12 : bool bLineFound = false;
253 : :
254 : : ::std::vector< Reference< chart2::XDataSeries > > aSeriesVec(
255 [ + - ]: 12 : DiagramHelper::getDataSeriesFromDiagram( xDiagram ));
256 : :
257 [ + - ][ + + ]: 140 : for( ::std::vector< Reference< chart2::XDataSeries > >::const_iterator aIt =
258 [ + - ]: 82 : aSeriesVec.begin(); aIt != aSeriesVec.end(); ++aIt )
259 : : {
260 : : try
261 : : {
262 [ + - ]: 64 : chart2::Symbol aSymbProp;
263 : : drawing::LineStyle eLineStyle;
264 [ + - ]: 64 : Reference< beans::XPropertySet > xProp( *aIt, uno::UNO_QUERY_THROW );
265 : :
266 [ + - ][ + - ]: 128 : bool bCurrentHasSymbol = (xProp->getPropertyValue( C2U( "Symbol" )) >>= aSymbProp) &&
[ + - ][ + - ]
[ + - ][ + - ]
[ # # # # ]
267 [ + - ][ + - ]: 64 : (aSymbProp.Style != chart2::SymbolStyle_NONE);
268 : :
269 [ + - ]: 64 : if( bCurrentHasSymbol )
270 : 64 : bSymbolFound = true;
271 : :
272 [ + - ][ + + ]: 64 : if( bCurrentHasSymbol && (!m_bHasSymbols) )
273 : : {
274 : 6 : bResult = false;
275 : : break;
276 : : }
277 : :
278 [ + - ][ + - ]: 116 : bool bCurrentHasLine = (xProp->getPropertyValue( C2U( "LineStyle" )) >>= eLineStyle) &&
[ + - ][ + - ]
[ + - ][ + - ]
[ # # # # ]
279 [ + - ][ + - ]: 58 : ( eLineStyle != drawing::LineStyle_NONE );
280 : :
281 [ + - ]: 58 : if( bCurrentHasLine )
282 : 58 : bLineFound = true;
283 : :
284 [ + - ][ - + ]: 58 : if( bCurrentHasLine && (!m_bHasLines) )
285 : : {
286 : 58 : bResult = false;
287 : : break;
288 [ + + ][ + - ]: 64 : }
[ + + ][ # # ]
289 : : }
290 [ # # ]: 0 : catch( const uno::Exception & ex )
291 : : {
292 : : ASSERT_EXCEPTION( ex );
293 : : }
294 : : }
295 : :
296 [ + + ]: 12 : if(bResult)
297 : : {
298 [ - + ][ # # ]: 6 : if( !bLineFound && m_bHasLines && bSymbolFound )
[ # # ]
299 : 0 : bResult = false;
300 [ - + ][ # # ]: 6 : else if( !bSymbolFound && m_bHasSymbols && bLineFound )
[ # # ]
301 : 0 : bResult = false;
302 [ - + ][ # # ]: 6 : else if( !bLineFound && !bSymbolFound )
303 [ # # ][ # # ]: 12 : return m_bHasLines && m_bHasSymbols;
304 [ + - ]: 12 : }
305 : : }
306 : :
307 : : // adapt curve style, spline order and resolution
308 [ + + ][ + - ]: 24 : if( bResult && bAdaptProperties )
309 : : {
310 : : try
311 : : {
312 : : uno::Reference< beans::XPropertySet > xChartTypeProp(
313 : : DiagramHelper::getChartTypeByIndex( xDiagram, 0 ),
314 [ + - ][ + - ]: 6 : uno::UNO_QUERY_THROW );
315 [ + - ][ + - ]: 6 : setFastPropertyValue_NoBroadcast( PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_STYLE, xChartTypeProp->getPropertyValue(C2U("CurveStyle" )) );
[ + - ][ + - ]
316 [ + - ][ + - ]: 6 : setFastPropertyValue_NoBroadcast( PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_RESOLUTION, xChartTypeProp->getPropertyValue(C2U("CurveResolution" )) );
[ + - ][ + - ]
317 [ + - ][ + - ]: 6 : setFastPropertyValue_NoBroadcast( PROP_SCATTERCHARTTYPE_TEMPLATE_SPLINE_ORDER, xChartTypeProp->getPropertyValue(C2U("SplineOrder" )) );
[ + - ][ # # ]
[ + - ]
318 : : }
319 : 0 : catch( const uno::Exception & ex )
320 : : {
321 : : ASSERT_EXCEPTION( ex );
322 : : }
323 : : }
324 : :
325 : 24 : return bResult;
326 : : }
327 : :
328 : 64 : Reference< chart2::XChartType > ScatterChartTypeTemplate::getChartTypeForIndex( sal_Int32 /*nChartTypeIndex*/ )
329 : : {
330 : 64 : Reference< chart2::XChartType > xResult;
331 : :
332 : : try
333 : : {
334 : : Reference< lang::XMultiServiceFactory > xFact(
335 [ + - ][ + - ]: 64 : GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW );
[ + - ][ + - ]
336 [ + - ]: 64 : xResult.set( xFact->createInstance(
337 [ + - ][ + - ]: 64 : CHART2_SERVICE_NAME_CHARTTYPE_SCATTER ), uno::UNO_QUERY_THROW );
[ + - ]
338 : :
339 [ + - ]: 64 : Reference< beans::XPropertySet > xCTProp( xResult, uno::UNO_QUERY );
340 [ + - ]: 64 : if( xCTProp.is())
341 : : {
342 [ + - ]: 64 : xCTProp->setPropertyValue(
343 [ + - ][ + - ]: 64 : C2U( "CurveStyle" ), getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_STYLE ));
[ + - ]
344 [ + - ]: 64 : xCTProp->setPropertyValue(
345 [ + - ][ + - ]: 64 : C2U( "CurveResolution" ), getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_RESOLUTION ));
[ + - ]
346 [ + - ]: 64 : xCTProp->setPropertyValue(
347 [ + - ][ + - ]: 64 : C2U( "SplineOrder" ), getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_SPLINE_ORDER ));
[ + - ]
348 [ # # ]: 64 : }
349 : : }
350 [ # # ]: 0 : catch( const uno::Exception & ex )
351 : : {
352 : : ASSERT_EXCEPTION( ex );
353 : : }
354 : :
355 : 64 : return xResult;
356 : : }
357 : :
358 : 36 : Reference< chart2::XChartType > SAL_CALL ScatterChartTypeTemplate::getChartTypeForNewSeries(
359 : : const uno::Sequence< Reference< chart2::XChartType > >& aFormerlyUsedChartTypes )
360 : : throw (uno::RuntimeException)
361 : : {
362 : 36 : Reference< chart2::XChartType > xResult;
363 : :
364 : : try
365 : : {
366 : : Reference< lang::XMultiServiceFactory > xFact(
367 [ + - ][ + - ]: 36 : GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW );
[ + - ][ + - ]
368 [ + - ]: 36 : xResult.set( xFact->createInstance(
369 [ + - ][ + - ]: 36 : CHART2_SERVICE_NAME_CHARTTYPE_SCATTER ), uno::UNO_QUERY_THROW );
[ + - ]
370 : :
371 [ + - ]: 36 : ChartTypeTemplate::copyPropertiesFromOldToNewCoordianteSystem( aFormerlyUsedChartTypes, xResult );
372 : :
373 [ + - ]: 36 : Reference< beans::XPropertySet > xCTProp( xResult, uno::UNO_QUERY );
374 [ + - ]: 36 : if( xCTProp.is())
375 : : {
376 [ + - ]: 36 : xCTProp->setPropertyValue(
377 [ + - ][ + - ]: 36 : C2U( "CurveStyle" ), getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_STYLE ));
[ + - ]
378 [ + - ]: 36 : xCTProp->setPropertyValue(
379 [ + - ][ + - ]: 36 : C2U( "CurveResolution" ), getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_RESOLUTION ));
[ + - ]
380 [ + - ]: 36 : xCTProp->setPropertyValue(
381 [ + - ][ + - ]: 36 : C2U( "SplineOrder" ), getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_SPLINE_ORDER ));
[ + - ]
382 [ # # ]: 36 : }
383 : : }
384 [ # # ]: 0 : catch( const uno::Exception & ex )
385 : : {
386 : : ASSERT_EXCEPTION( ex );
387 : : }
388 : :
389 : 36 : return xResult;
390 : : }
391 : :
392 : 6 : Reference< chart2::XDataInterpreter > SAL_CALL ScatterChartTypeTemplate::getDataInterpreter()
393 : : throw (uno::RuntimeException)
394 : : {
395 [ + - ]: 6 : if( ! m_xDataInterpreter.is())
396 [ + - ][ + - ]: 6 : m_xDataInterpreter.set( new XYDataInterpreter( GetComponentContext()) );
[ + - ]
397 : :
398 : 6 : return m_xDataInterpreter;
399 : : }
400 : :
401 : : // ----------------------------------------
402 : :
403 : 0 : Sequence< OUString > ScatterChartTypeTemplate::getSupportedServiceNames_Static()
404 : : {
405 : 0 : Sequence< OUString > aServices( 2 );
406 [ # # ]: 0 : aServices[ 0 ] = lcl_aServiceName;
407 [ # # ][ # # ]: 0 : aServices[ 1 ] = C2U( "com.sun.star.chart2.ChartTypeTemplate" );
408 : 0 : return aServices;
409 : : }
410 : :
411 : : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
412 [ # # ][ # # ]: 0 : APPHELPER_XSERVICEINFO_IMPL( ScatterChartTypeTemplate, lcl_aServiceName );
[ # # ][ # # ]
[ # # ]
413 : :
414 [ - + ][ # # ]: 252 : IMPLEMENT_FORWARD_XINTERFACE2( ScatterChartTypeTemplate, ChartTypeTemplate, OPropertySet )
415 [ # # ][ # # ]: 0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( ScatterChartTypeTemplate, ChartTypeTemplate, OPropertySet )
[ # # ]
416 : :
417 [ + - ][ + - ]: 48 : } // namespace chart
418 : :
419 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|