tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / chart2 / source / model / template / PieChartType.cxx
blob36f9a59d08620535f522af59199a50669dd87fb7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "PieChartType.hxx"
21 #include <PropertyHelper.hxx>
22 #include <PolarCoordinateSystem.hxx>
23 #include <Axis.hxx>
24 #include <AxisHelper.hxx>
25 #include <servicenames_charttypes.hxx>
26 #include <AxisIndexDefines.hxx>
27 #include <cppuhelper/supportsservice.hxx>
28 #include <com/sun/star/beans/PropertyAttribute.hpp>
29 #include <com/sun/star/chart2/AxisType.hpp>
30 #include <com/sun/star/chart2/PieChartSubType.hpp>
32 using namespace ::com::sun::star;
34 using ::com::sun::star::beans::Property;
35 using ::com::sun::star::uno::Sequence;
36 using ::com::sun::star::uno::Reference;
38 namespace
41 ::chart::tPropertyValueMap& StaticPieChartTypeDefaults()
43 static ::chart::tPropertyValueMap aStaticDefaults =
44 []()
46 ::chart::tPropertyValueMap aOutMap;
47 ::chart::PropertyHelper::setPropertyValueDefault( aOutMap, ::chart::PROP_PIECHARTTYPE_USE_RINGS, false );
48 ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( aOutMap, ::chart::PROP_PIECHARTTYPE_3DRELATIVEHEIGHT, 100 );
49 ::chart::PropertyHelper::setPropertyValueDefault( aOutMap, ::chart::PROP_PIECHARTTYPE_SUBTYPE, chart2::PieChartSubType_NONE );
50 ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( aOutMap, ::chart::PROP_PIECHARTTYPE_SPLIT_POS, 2 );
51 return aOutMap;
52 }();
53 return aStaticDefaults;
56 ::cppu::OPropertyArrayHelper& StaticPieChartTypeInfoHelper()
58 static ::cppu::OPropertyArrayHelper aPropHelper(
59 []()
61 std::vector< css::beans::Property > aProperties {
62 { u"UseRings"_ustr,
63 ::chart::PROP_PIECHARTTYPE_USE_RINGS,
64 cppu::UnoType<bool>::get(),
65 beans::PropertyAttribute::BOUND
66 | beans::PropertyAttribute::MAYBEDEFAULT },
67 { u"3DRelativeHeight"_ustr,
68 ::chart::PROP_PIECHARTTYPE_3DRELATIVEHEIGHT,
69 cppu::UnoType<sal_Int32>::get(),
70 beans::PropertyAttribute::MAYBEVOID },
71 { u"SubPieType"_ustr,
72 ::chart::PROP_PIECHARTTYPE_SUBTYPE,
73 cppu::UnoType<chart2::PieChartSubType>::get(),
74 beans::PropertyAttribute::MAYBEDEFAULT },
75 { u"SplitPos"_ustr,
76 ::chart::PROP_PIECHARTTYPE_SPLIT_POS,
77 cppu::UnoType<sal_Int32>::get(),
78 beans::PropertyAttribute::MAYBEVOID }
80 std::sort( aProperties.begin(), aProperties.end(),
81 ::chart::PropertyNameLess() );
83 return comphelper::containerToSequence( aProperties );
84 }());
85 return aPropHelper;
88 uno::Reference< beans::XPropertySetInfo >& StaticPieChartTypeInfo()
90 static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
91 ::cppu::OPropertySetHelper::createPropertySetInfo( StaticPieChartTypeInfoHelper() ) );
92 return xPropertySetInfo;
95 } // anonymous namespace
97 namespace chart
100 PieChartType::PieChartType()
104 PieChartType::PieChartType( const PieChartType & rOther ) :
105 ChartType( rOther )
109 PieChartType::~PieChartType()
112 // ____ XCloneable ____
113 uno::Reference< util::XCloneable > SAL_CALL PieChartType::createClone()
115 return uno::Reference< util::XCloneable >( new PieChartType( *this ));
118 rtl::Reference< ChartType > PieChartType::cloneChartType() const
120 return new PieChartType( *this );
123 // ____ XChartType ____
124 OUString SAL_CALL PieChartType::getChartType()
126 return CHART2_SERVICE_NAME_CHARTTYPE_PIE;
129 rtl::Reference< ::chart::BaseCoordinateSystem >
130 PieChartType::createCoordinateSystem2( sal_Int32 DimensionCount )
132 rtl::Reference< PolarCoordinateSystem > xResult =
133 new PolarCoordinateSystem( DimensionCount );
135 for( sal_Int32 i=0; i<DimensionCount; ++i )
137 rtl::Reference< Axis > xAxis = xResult->getAxisByDimension2( i, MAIN_AXIS_INDEX );
138 if( !xAxis.is() )
140 OSL_FAIL("a created coordinate system should have an axis for each dimension");
141 continue;
144 //hhhh todo make axis invisible
146 chart2::ScaleData aScaleData = xAxis->getScaleData();
147 aScaleData.Scaling = AxisHelper::createLinearScaling();
148 aScaleData.AxisType = chart2::AxisType::REALNUMBER;
150 if( i == 0 )
151 aScaleData.Orientation = chart2::AxisOrientation_REVERSE;
152 else
153 aScaleData.Orientation = chart2::AxisOrientation_MATHEMATICAL;
155 //remove explicit scalings from all axes
156 AxisHelper::removeExplicitScaling( aScaleData );
158 xAxis->setScaleData( aScaleData );
161 return xResult;
164 uno::Sequence< OUString > PieChartType::getSupportedPropertyRoles()
166 return { u"FillColor"_ustr, u"BorderColor"_ustr };
169 // ____ OPropertySet ____
170 void PieChartType::GetDefaultValue( sal_Int32 nHandle, uno::Any& rAny ) const
172 const tPropertyValueMap& rStaticDefaults = StaticPieChartTypeDefaults();
173 tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
174 if( aFound == rStaticDefaults.end() )
175 rAny.clear();
176 else
177 rAny = (*aFound).second;
180 // ____ OPropertySet ____
181 ::cppu::IPropertyArrayHelper & SAL_CALL PieChartType::getInfoHelper()
183 return StaticPieChartTypeInfoHelper();
186 // ____ XPropertySet ____
187 uno::Reference< beans::XPropertySetInfo > SAL_CALL PieChartType::getPropertySetInfo()
189 return StaticPieChartTypeInfo();
192 OUString SAL_CALL PieChartType::getImplementationName()
194 return u"com.sun.star.comp.chart.PieChartType"_ustr;
197 sal_Bool SAL_CALL PieChartType::supportsService( const OUString& rServiceName )
199 return cppu::supportsService(this, rServiceName);
202 css::uno::Sequence< OUString > SAL_CALL PieChartType::getSupportedServiceNames()
204 return {
205 CHART2_SERVICE_NAME_CHARTTYPE_PIE,
206 u"com.sun.star.chart2.ChartType"_ustr,
207 u"com.sun.star.beans.PropertySet"_ustr };
210 } // namespace chart
212 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
213 com_sun_star_comp_chart_PieChartType_get_implementation(css::uno::XComponentContext * /*context*/,
214 css::uno::Sequence<css::uno::Any> const &)
216 return cppu::acquire(new ::chart::PieChartType);
219 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */