LibreOffice Module chart2 (master) 1
PieChartType.cxx
Go to the documentation of this file.
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>
23#include <Axis.hxx>
24#include <AxisHelper.hxx>
26#include <AxisIndexDefines.hxx>
28#include <com/sun/star/beans/PropertyAttribute.hpp>
29#include <com/sun/star/chart2/AxisType.hpp>
30
31using namespace ::com::sun::star;
32
33using ::com::sun::star::beans::Property;
34using ::com::sun::star::uno::Sequence;
35using ::com::sun::star::uno::Reference;
36
37namespace
38{
39
40::chart::tPropertyValueMap& StaticPieChartTypeDefaults()
41{
42 static ::chart::tPropertyValueMap aStaticDefaults =
43 []()
44 {
47 ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( aOutMap, ::chart::PROP_PIECHARTTYPE_3DRELATIVEHEIGHT, 100 );
48 return aOutMap;
49 }();
50 return aStaticDefaults;
51}
52
53::cppu::OPropertyArrayHelper& StaticPieChartTypeInfoHelper()
54{
55 static ::cppu::OPropertyArrayHelper aPropHelper(
56 []()
57 {
58 std::vector< css::beans::Property > aProperties {
59 { "UseRings",
62 beans::PropertyAttribute::BOUND
63 | beans::PropertyAttribute::MAYBEDEFAULT },
64 { "3DRelativeHeight",
67 beans::PropertyAttribute::MAYBEVOID }
68 };
69 std::sort( aProperties.begin(), aProperties.end(),
71
72 return comphelper::containerToSequence( aProperties );
73 }());
74 return aPropHelper;
75}
76
77uno::Reference< beans::XPropertySetInfo >& StaticPieChartTypeInfo()
78{
79 static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
80 ::cppu::OPropertySetHelper::createPropertySetInfo( StaticPieChartTypeInfoHelper() ) );
81 return xPropertySetInfo;
82}
83
84} // anonymous namespace
85
86namespace chart
87{
88
90{
91}
92
94 ChartType( rOther )
95{
96}
97
99{}
100
101// ____ XCloneable ____
103{
105}
106
108{
109 return new PieChartType( *this );
110}
111
112// ____ XChartType ____
113OUString SAL_CALL PieChartType::getChartType()
114{
116}
117
119 PieChartType::createCoordinateSystem2( sal_Int32 DimensionCount )
120{
122 new PolarCoordinateSystem( DimensionCount );
123
124 for( sal_Int32 i=0; i<DimensionCount; ++i )
125 {
126 rtl::Reference< Axis > xAxis = xResult->getAxisByDimension2( i, MAIN_AXIS_INDEX );
127 if( !xAxis.is() )
128 {
129 OSL_FAIL("a created coordinate system should have an axis for each dimension");
130 continue;
131 }
132
133 //hhhh todo make axis invisible
134
135 chart2::ScaleData aScaleData = xAxis->getScaleData();
136 aScaleData.Scaling = AxisHelper::createLinearScaling();
137 aScaleData.AxisType = chart2::AxisType::REALNUMBER;
138
139 if( i == 0 )
140 aScaleData.Orientation = chart2::AxisOrientation_REVERSE;
141 else
142 aScaleData.Orientation = chart2::AxisOrientation_MATHEMATICAL;
143
144 //remove explicit scalings from all axes
146
147 xAxis->setScaleData( aScaleData );
148 }
149
150 return xResult;
151}
152
154{
155 return { "FillColor", "BorderColor" };
156}
157
158// ____ OPropertySet ____
159void PieChartType::GetDefaultValue( sal_Int32 nHandle, uno::Any& rAny ) const
160{
161 const tPropertyValueMap& rStaticDefaults = StaticPieChartTypeDefaults();
162 tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
163 if( aFound == rStaticDefaults.end() )
164 rAny.clear();
165 else
166 rAny = (*aFound).second;
167}
168
169// ____ OPropertySet ____
171{
172 return StaticPieChartTypeInfoHelper();
173}
174
175// ____ XPropertySet ____
177{
178 return StaticPieChartTypeInfo();
179}
180
182{
183 return "com.sun.star.comp.chart.PieChartType";
184}
185
186sal_Bool SAL_CALL PieChartType::supportsService( const OUString& rServiceName )
187{
188 return cppu::supportsService(this, rServiceName);
189}
190
191css::uno::Sequence< OUString > SAL_CALL PieChartType::getSupportedServiceNames()
192{
193 return {
195 "com.sun.star.chart2.ChartType",
196 "com.sun.star.beans.PropertySet" };
197}
198
199} // namespace chart
200
201extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
202com_sun_star_comp_chart_PieChartType_get_implementation(css::uno::XComponentContext * /*context*/,
203 css::uno::Sequence<css::uno::Any> const &)
204{
205 return cppu::acquire(new ::chart::PieChartType);
206}
207
208/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_chart_PieChartType_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
PropertiesInfo aProperties
static css::uno::Reference< css::chart2::XScaling > createLinearScaling()
Definition: AxisHelper.cxx:65
static void removeExplicitScaling(css::chart2::ScaleData &rScaleData)
Definition: AxisHelper.cxx:86
virtual rtl::Reference< ChartType > cloneChartType() const override
virtual void GetDefaultValue(sal_Int32 nHandle, css::uno::Any &rAny) const override
implement this method to provide default values for all properties supporting defaults.
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone() override
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
virtual ::cppu::IPropertyArrayHelper &SAL_CALL getInfoHelper() override
The InfoHelper table contains all property names and types of this object.
virtual ~PieChartType() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedPropertyRoles() override
virtual rtl::Reference< ::chart::BaseCoordinateSystem > createCoordinateSystem2(sal_Int32 DimensionCount) override
virtual OUString SAL_CALL getChartType() override
virtual OUString SAL_CALL getImplementationName() override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
static css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL createPropertySetInfo(IPropertyArrayHelper &rProperties)
css::uno::Type const & get()
void setPropertyValueDefault(tPropertyValueMap &rOutMap, tPropertyValueMapKey key, const Value &value)
Calls setPropertyValue() but asserts that the given property hasn't been set before.
std::unordered_map< tPropertyValueMapKey, css::uno::Any > tPropertyValueMap
@ PROP_PIECHARTTYPE_3DRELATIVEHEIGHT
Definition: ChartType.hxx:44
@ PROP_PIECHARTTYPE_USE_RINGS
Definition: ChartType.hxx:43
const sal_Int32 MAIN_AXIS_INDEX
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
int i
sal_Int32 nHandle
constexpr OUStringLiteral CHART2_SERVICE_NAME_CHARTTYPE_PIE
unsigned char sal_Bool