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