LibreOffice Module chart2 (master) 1
WrappedDataCaptionProperties.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
23#include <unonames.hxx>
24
25#include <com/sun/star/chart2/DataPointLabel.hpp>
26#include <com/sun/star/chart/ChartDataCaption.hpp>
27#include <com/sun/star/beans/PropertyAttribute.hpp>
28#include <com/sun/star/beans/XPropertySet.hpp>
29
30using namespace ::com::sun::star;
31using ::com::sun::star::uno::Reference;
32using ::com::sun::star::beans::Property;
33
34namespace chart::wrapper
35{
36
37namespace
38{
39
40class WrappedDataCaptionProperty : public WrappedSeriesOrDiagramProperty< sal_Int32 >
41{
42public:
43 virtual sal_Int32 getValueFromSeries( const css::uno::Reference< css::beans::XPropertySet >& xSeriesPropertySet ) const override;
44 virtual void setValueToSeries( const css::uno::Reference< css::beans::XPropertySet >& xSeriesPropertySet, const sal_Int32& aNewValue ) const override;
45
46 explicit WrappedDataCaptionProperty(const std::shared_ptr<Chart2ModelContact>& spChart2ModelContact,
47 tSeriesOrDiagramPropertyType ePropertyType );
48};
49
50enum
51{
52 //data caption properties
53 PROP_CHART_DATAPOINT_DATA_CAPTION = FAST_PROPERTY_ID_START_CHART_DATACAPTION_PROP
54};
55
56sal_Int32 lcl_LabelToCaption( const chart2::DataPointLabel& rLabel )
57{
58 sal_Int32 nCaption=0;
59
60 if( rLabel.ShowNumber )
61 nCaption |= css::chart::ChartDataCaption::VALUE;
62 if( rLabel.ShowNumberInPercent )
63 nCaption |= css::chart::ChartDataCaption::PERCENT;
64 if( rLabel.ShowCategoryName )
65 nCaption |= css::chart::ChartDataCaption::TEXT;
66 if( rLabel.ShowLegendSymbol )
67 nCaption |= css::chart::ChartDataCaption::SYMBOL;
68 if (rLabel.ShowSeriesName)
70
71 return nCaption;
72}
73
74chart2::DataPointLabel lcl_CaptionToLabel( sal_Int32 nCaption )
75{
76 chart2::DataPointLabel aLabel(false,false,false,false,false,false);
77
78 if( nCaption & css::chart::ChartDataCaption::VALUE )
79 aLabel.ShowNumber = true;
80 if( nCaption & css::chart::ChartDataCaption::PERCENT )
81 aLabel.ShowNumberInPercent = true;
82 if( nCaption & css::chart::ChartDataCaption::TEXT )
83 aLabel.ShowCategoryName = true;
84 if( nCaption & css::chart::ChartDataCaption::SYMBOL )
85 aLabel.ShowLegendSymbol = true;
86 if( nCaption & css::chart::ChartDataCaption::CUSTOM )
87 aLabel.ShowCustomLabel = true;
89 aLabel.ShowSeriesName = true;
90
91 return aLabel;
92}
93
94void lcl_addWrappedProperties( std::vector< std::unique_ptr<WrappedProperty> >& rList
95 , const std::shared_ptr< Chart2ModelContact >& spChart2ModelContact
96 , tSeriesOrDiagramPropertyType ePropertyType )
97{
98 //if !spChart2ModelContact.get() is then the created properties do belong to a single series or single datapoint
99 //otherwise they do belong to the whole diagram
100
101 rList.emplace_back( new WrappedDataCaptionProperty( spChart2ModelContact, ePropertyType ) );
102}
103
104}//anonymous namespace
105
106void WrappedDataCaptionProperties::addProperties( std::vector< Property > & rOutProperties )
107{
108 rOutProperties.emplace_back( "DataCaption",
109 PROP_CHART_DATAPOINT_DATA_CAPTION,
111 beans::PropertyAttribute::BOUND
112 | beans::PropertyAttribute::MAYBEDEFAULT );
113}
114
115void WrappedDataCaptionProperties::addWrappedPropertiesForSeries( std::vector< std::unique_ptr<WrappedProperty> >& rList
116 , const std::shared_ptr< Chart2ModelContact >& spChart2ModelContact )
117{
118 lcl_addWrappedProperties( rList, spChart2ModelContact, DATA_SERIES );
119}
120
121void WrappedDataCaptionProperties::addWrappedPropertiesForDiagram( std::vector< std::unique_ptr<WrappedProperty> >& rList
122 , const std::shared_ptr< Chart2ModelContact >& spChart2ModelContact )
123{
124 lcl_addWrappedProperties( rList, spChart2ModelContact, DIAGRAM );
125}
126
127WrappedDataCaptionProperty::WrappedDataCaptionProperty(
128 const std::shared_ptr<Chart2ModelContact>& spChart2ModelContact
129 , tSeriesOrDiagramPropertyType ePropertyType )
130 : WrappedSeriesOrDiagramProperty< sal_Int32 >( "DataCaption"
131 , uno::Any( sal_Int32(0) ), spChart2ModelContact, ePropertyType )
132{
133}
134
135sal_Int32 WrappedDataCaptionProperty::getValueFromSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet ) const
136{
137 sal_Int32 aRet = 0;
138 m_aDefaultValue >>= aRet;
139 chart2::DataPointLabel aLabel;
140 if( xSeriesPropertySet.is() && ( xSeriesPropertySet->getPropertyValue(CHART_UNONAME_LABEL) >>= aLabel ) )
141 aRet = lcl_LabelToCaption( aLabel );
142 return aRet;
143}
144
145void WrappedDataCaptionProperty::setValueToSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet, const sal_Int32& nCaption ) const
146{
147 if(!xSeriesPropertySet.is())
148 return;
149
150 chart2::DataPointLabel aLabel = lcl_CaptionToLabel( nCaption );
151 xSeriesPropertySet->setPropertyValue( CHART_UNONAME_LABEL, uno::Any( aLabel ) );
152}
153
154} //namespace chart::wrapper
155
156/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Any m_aDefaultValue
static void addWrappedPropertiesForSeries(std::vector< std::unique_ptr< WrappedProperty > > &rList, const std::shared_ptr< Chart2ModelContact > &spChart2ModelContact)
static void addWrappedPropertiesForDiagram(std::vector< std::unique_ptr< WrappedProperty > > &rList, const std::shared_ptr< Chart2ModelContact > &spChart2ModelContact)
static void addProperties(std::vector< css::beans::Property > &rOutProperties)
@ FAST_PROPERTY_ID_START_CHART_DATACAPTION_PROP
OUString aLabel
constexpr OUStringLiteral CHART_UNONAME_LABEL
Definition: unonames.hxx:24