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 "PieChartType.hxx"
21 : : #include "PropertyHelper.hxx"
22 : : #include "macros.hxx"
23 : : #include "PolarCoordinateSystem.hxx"
24 : : #include "AxisHelper.hxx"
25 : : #include "servicenames_charttypes.hxx"
26 : : #include "ContainerHelper.hxx"
27 : : #include "AxisIndexDefines.hxx"
28 : : #include <com/sun/star/beans/PropertyAttribute.hpp>
29 : : #include <com/sun/star/chart2/AxisType.hpp>
30 : :
31 : : using namespace ::com::sun::star;
32 : :
33 : : using ::rtl::OUString;
34 : : using ::com::sun::star::beans::Property;
35 : : using ::com::sun::star::uno::Sequence;
36 : : using ::com::sun::star::uno::Reference;
37 : : using ::com::sun::star::uno::Any;
38 : : using ::osl::MutexGuard;
39 : :
40 : : namespace
41 : : {
42 : :
43 : : enum
44 : : {
45 : : PROP_PIECHARTTYPE_USE_RINGS
46 : : };
47 : :
48 : 2 : static void lcl_AddPropertiesToVector(
49 : : ::std::vector< Property > & rOutProperties )
50 : : {
51 : : rOutProperties.push_back(
52 : : Property( C2U( "UseRings" ),
53 : : PROP_PIECHARTTYPE_USE_RINGS,
54 [ + - ]: 2 : ::getBooleanCppuType(),
55 : : beans::PropertyAttribute::BOUND
56 [ + - ][ + - ]: 2 : | beans::PropertyAttribute::MAYBEDEFAULT ));
57 : 2 : }
58 : :
59 : : struct StaticPieChartTypeDefaults_Initializer
60 : : {
61 : 2 : ::chart::tPropertyValueMap* operator()()
62 : : {
63 [ + - ][ + - ]: 2 : static ::chart::tPropertyValueMap aStaticDefaults;
[ + - ][ # # ]
64 : 2 : lcl_AddDefaultsToMap( aStaticDefaults );
65 : 2 : return &aStaticDefaults;
66 : : }
67 : : private:
68 : 2 : void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
69 : : {
70 [ + - ]: 2 : ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_PIECHARTTYPE_USE_RINGS, false );
71 : 2 : }
72 : : };
73 : :
74 : : struct StaticPieChartTypeDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticPieChartTypeDefaults_Initializer >
75 : : {
76 : : };
77 : :
78 : : struct StaticPieChartTypeInfoHelper_Initializer
79 : : {
80 : 2 : ::cppu::OPropertyArrayHelper* operator()()
81 : : {
82 [ + - ][ + - ]: 2 : static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
[ + - ][ + - ]
[ + - ][ # # ]
83 : 2 : return &aPropHelper;
84 : : }
85 : :
86 : : private:
87 : 2 : Sequence< Property > lcl_GetPropertySequence()
88 : : {
89 [ + - ]: 2 : ::std::vector< ::com::sun::star::beans::Property > aProperties;
90 [ + - ]: 2 : lcl_AddPropertiesToVector( aProperties );
91 : :
92 : : ::std::sort( aProperties.begin(), aProperties.end(),
93 [ + - ]: 2 : ::chart::PropertyNameLess() );
94 : :
95 [ + - ]: 2 : return ::chart::ContainerHelper::ContainerToSequence( aProperties );
96 : : }
97 : :
98 : : };
99 : :
100 : : struct StaticPieChartTypeInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticPieChartTypeInfoHelper_Initializer >
101 : : {
102 : : };
103 : :
104 : : struct StaticPieChartTypeInfo_Initializer
105 : : {
106 : 0 : uno::Reference< beans::XPropertySetInfo >* operator()()
107 : : {
108 : : static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
109 [ # # ][ # # ]: 0 : ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticPieChartTypeInfoHelper::get() ) );
[ # # ][ # # ]
[ # # ]
110 : 0 : return &xPropertySetInfo;
111 : : }
112 : : };
113 : :
114 : : struct StaticPieChartTypeInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticPieChartTypeInfo_Initializer >
115 : : {
116 : : };
117 : :
118 : : } // anonymous namespace
119 : :
120 : : namespace chart
121 : : {
122 : :
123 : 106 : PieChartType::PieChartType(
124 : : const uno::Reference< uno::XComponentContext > & xContext,
125 : : sal_Bool bUseRings /* = sal_False */) :
126 : 106 : ChartType( xContext )
127 : : {
128 [ - + ]: 106 : if( bUseRings )
129 [ # # ][ # # ]: 0 : setFastPropertyValue_NoBroadcast( PROP_PIECHARTTYPE_USE_RINGS, uno::makeAny( bUseRings ));
130 : 106 : }
131 : :
132 : 0 : PieChartType::PieChartType( const PieChartType & rOther ) :
133 : 0 : ChartType( rOther )
134 : : {
135 : 0 : }
136 : :
137 : 106 : PieChartType::~PieChartType()
138 [ - + ]: 212 : {}
139 : :
140 : : // ____ XCloneable ____
141 : 0 : uno::Reference< util::XCloneable > SAL_CALL PieChartType::createClone()
142 : : throw (uno::RuntimeException)
143 : : {
144 [ # # ][ # # ]: 0 : return uno::Reference< util::XCloneable >( new PieChartType( *this ));
145 : : }
146 : :
147 : : // ____ XChartType ____
148 : 1082 : ::rtl::OUString SAL_CALL PieChartType::getChartType()
149 : : throw (uno::RuntimeException)
150 : : {
151 : 1082 : return CHART2_SERVICE_NAME_CHARTTYPE_PIE;
152 : : }
153 : :
154 : : Reference< chart2::XCoordinateSystem > SAL_CALL
155 : 4 : PieChartType::createCoordinateSystem( ::sal_Int32 DimensionCount )
156 : : throw (lang::IllegalArgumentException,
157 : : uno::RuntimeException)
158 : : {
159 : : Reference< chart2::XCoordinateSystem > xResult(
160 : : new PolarCoordinateSystem(
161 [ + - ][ + - ]: 4 : GetComponentContext(), DimensionCount, /* bSwapXAndYAxis */ sal_False ));
[ + - ]
162 : :
163 [ + + ]: 12 : for( sal_Int32 i=0; i<DimensionCount; ++i )
164 : : {
165 [ + - ][ + - ]: 8 : Reference< chart2::XAxis > xAxis( xResult->getAxisByDimension( i, MAIN_AXIS_INDEX ) );
166 [ - + ]: 8 : if( !xAxis.is() )
167 : : {
168 : : OSL_FAIL("a created coordinate system should have an axis for each dimension");
169 : 0 : continue;
170 : : }
171 : :
172 : : //hhhh todo make axis invisible
173 : :
174 [ + - ][ + - ]: 8 : chart2::ScaleData aScaleData = xAxis->getScaleData();
175 [ + - ][ + - ]: 8 : aScaleData.Scaling = AxisHelper::createLinearScaling();
176 : 8 : aScaleData.AxisType = chart2::AxisType::REALNUMBER;
177 : :
178 [ + + ]: 8 : if( i == 0 )
179 : 4 : aScaleData.Orientation = chart2::AxisOrientation_REVERSE;
180 : : else
181 : 4 : aScaleData.Orientation = chart2::AxisOrientation_MATHEMATICAL;
182 : :
183 : : //remove explicit scalings from all axes
184 [ + - ]: 8 : AxisHelper::removeExplicitScaling( aScaleData );
185 : :
186 [ + - ][ + - ]: 8 : xAxis->setScaleData( aScaleData );
187 [ + - ][ + - ]: 8 : }
188 : :
189 : 4 : return xResult;
190 : : }
191 : :
192 : : // ____ OPropertySet ____
193 : 240 : uno::Any PieChartType::GetDefaultValue( sal_Int32 nHandle ) const
194 : : throw(beans::UnknownPropertyException)
195 : : {
196 [ + - ]: 240 : const tPropertyValueMap& rStaticDefaults = *StaticPieChartTypeDefaults::get();
197 [ + - ]: 240 : tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
198 [ - + ]: 240 : if( aFound == rStaticDefaults.end() )
199 : 0 : return uno::Any();
200 : 240 : return (*aFound).second;
201 : : }
202 : :
203 : : // ____ OPropertySet ____
204 : 428 : ::cppu::IPropertyArrayHelper & SAL_CALL PieChartType::getInfoHelper()
205 : : {
206 : 428 : return *StaticPieChartTypeInfoHelper::get();
207 : : }
208 : :
209 : : // ____ XPropertySet ____
210 : 0 : uno::Reference< beans::XPropertySetInfo > SAL_CALL PieChartType::getPropertySetInfo()
211 : : throw (uno::RuntimeException)
212 : : {
213 : 0 : return *StaticPieChartTypeInfo::get();
214 : : }
215 : :
216 : 2 : uno::Sequence< ::rtl::OUString > PieChartType::getSupportedServiceNames_Static()
217 : : {
218 : 2 : uno::Sequence< ::rtl::OUString > aServices( 3 );
219 [ + - ][ + - ]: 2 : aServices[ 0 ] = CHART2_SERVICE_NAME_CHARTTYPE_PIE;
220 [ + - ][ + - ]: 2 : aServices[ 1 ] = C2U( "com.sun.star.chart2.ChartType" );
221 [ + - ][ + - ]: 2 : aServices[ 2 ] = C2U( "com.sun.star.beans.PropertySet" );
222 : 2 : return aServices;
223 : : }
224 : :
225 : : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
226 [ # # ][ # # ]: 77 : APPHELPER_XSERVICEINFO_IMPL( PieChartType,
[ # # ][ # # ]
[ # # ]
227 : : C2U( "com.sun.star.comp.chart.PieChartType" ));
228 : :
229 : : } // namespace chart
230 : :
231 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|