tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / chart2 / source / controller / chartapiwrapper / WrappedDataCaptionProperties.cxx
blob792bfdfadcb440607afc14790f301482c3b687ce
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 "WrappedDataCaptionProperties.hxx"
21 #include "WrappedSeriesOrDiagramProperty.hxx"
22 #include <FastPropertyIdRanges.hxx>
23 #include <unonames.hxx>
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>
30 using namespace ::com::sun::star;
31 using ::com::sun::star::uno::Reference;
32 using ::com::sun::star::beans::Property;
34 namespace chart::wrapper
37 namespace
40 class WrappedDataCaptionProperty : public WrappedSeriesOrDiagramProperty< sal_Int32 >
42 public:
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;
46 explicit WrappedDataCaptionProperty(const std::shared_ptr<Chart2ModelContact>& spChart2ModelContact,
47 tSeriesOrDiagramPropertyType ePropertyType );
50 enum
52 //data caption properties
53 PROP_CHART_DATAPOINT_DATA_CAPTION = FAST_PROPERTY_ID_START_CHART_DATACAPTION_PROP
56 sal_Int32 lcl_LabelToCaption( const chart2::DataPointLabel& rLabel )
58 sal_Int32 nCaption=0;
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)
69 nCaption |= css::chart::ChartDataCaption::DATA_SERIES;
71 return nCaption;
74 chart2::DataPointLabel lcl_CaptionToLabel( sal_Int32 nCaption )
76 chart2::DataPointLabel aLabel(false,false,false,false,false,false);
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;
88 if( nCaption & css::chart::ChartDataCaption::DATA_SERIES )
89 aLabel.ShowSeriesName = true;
91 return aLabel;
94 void lcl_addWrappedProperties( std::vector< std::unique_ptr<WrappedProperty> >& rList
95 , const std::shared_ptr< Chart2ModelContact >& spChart2ModelContact
96 , tSeriesOrDiagramPropertyType ePropertyType )
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
101 rList.emplace_back( new WrappedDataCaptionProperty( spChart2ModelContact, ePropertyType ) );
104 }//anonymous namespace
106 void WrappedDataCaptionProperties::addProperties( std::vector< Property > & rOutProperties )
108 rOutProperties.emplace_back( "DataCaption",
109 PROP_CHART_DATAPOINT_DATA_CAPTION,
110 cppu::UnoType<sal_Int32>::get(),
111 beans::PropertyAttribute::BOUND
112 | beans::PropertyAttribute::MAYBEDEFAULT );
115 void WrappedDataCaptionProperties::addWrappedPropertiesForSeries( std::vector< std::unique_ptr<WrappedProperty> >& rList
116 , const std::shared_ptr< Chart2ModelContact >& spChart2ModelContact )
118 lcl_addWrappedProperties( rList, spChart2ModelContact, DATA_SERIES );
121 void WrappedDataCaptionProperties::addWrappedPropertiesForDiagram( std::vector< std::unique_ptr<WrappedProperty> >& rList
122 , const std::shared_ptr< Chart2ModelContact >& spChart2ModelContact )
124 lcl_addWrappedProperties( rList, spChart2ModelContact, DIAGRAM );
127 WrappedDataCaptionProperty::WrappedDataCaptionProperty(
128 const std::shared_ptr<Chart2ModelContact>& spChart2ModelContact
129 , tSeriesOrDiagramPropertyType ePropertyType )
130 : WrappedSeriesOrDiagramProperty< sal_Int32 >( u"DataCaption"_ustr
131 , uno::Any( sal_Int32(0) ), spChart2ModelContact, ePropertyType )
135 sal_Int32 WrappedDataCaptionProperty::getValueFromSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet ) const
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;
145 void WrappedDataCaptionProperty::setValueToSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet, const sal_Int32& nCaption ) const
147 if(!xSeriesPropertySet.is())
148 return;
150 chart2::DataPointLabel aLabel = lcl_CaptionToLabel( nCaption );
151 xSeriesPropertySet->setPropertyValue( CHART_UNONAME_LABEL, uno::Any( aLabel ) );
154 } //namespace chart::wrapper
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */