1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
;
39 class WrappedDataCaptionProperty
: public WrappedSeriesOrDiagramProperty
< sal_Int32
>
42 virtual sal_Int32
getValueFromSeries( const css::uno::Reference
< css::beans::XPropertySet
>& xSeriesPropertySet
) const override
;
43 virtual void setValueToSeries( const css::uno::Reference
< css::beans::XPropertySet
>& xSeriesPropertySet
, const sal_Int32
& aNewValue
) const override
;
45 explicit WrappedDataCaptionProperty(const std::shared_ptr
<Chart2ModelContact
>& spChart2ModelContact
,
46 tSeriesOrDiagramPropertyType ePropertyType
);
53 //data caption properties
54 PROP_CHART_DATAPOINT_DATA_CAPTION
= FAST_PROPERTY_ID_START_CHART_DATACAPTION_PROP
57 sal_Int32
lcl_LabelToCaption( const chart2::DataPointLabel
& rLabel
)
61 if( rLabel
.ShowNumber
)
62 nCaption
|= css::chart::ChartDataCaption::VALUE
;
63 if( rLabel
.ShowNumberInPercent
)
64 nCaption
|= css::chart::ChartDataCaption::PERCENT
;
65 if( rLabel
.ShowCategoryName
)
66 nCaption
|= css::chart::ChartDataCaption::TEXT
;
67 if( rLabel
.ShowLegendSymbol
)
68 nCaption
|= css::chart::ChartDataCaption::SYMBOL
;
73 chart2::DataPointLabel
lcl_CaptionToLabel( sal_Int32 nCaption
)
75 chart2::DataPointLabel
aLabel(false,false,false,false);
77 if( nCaption
& css::chart::ChartDataCaption::VALUE
)
78 aLabel
.ShowNumber
= true;
79 if( nCaption
& css::chart::ChartDataCaption::PERCENT
)
80 aLabel
.ShowNumberInPercent
= true;
81 if( nCaption
& css::chart::ChartDataCaption::TEXT
)
82 aLabel
.ShowCategoryName
= true;
83 if( nCaption
& css::chart::ChartDataCaption::SYMBOL
)
84 aLabel
.ShowLegendSymbol
= true;
89 void lcl_addWrappedProperties( std::vector
< std::unique_ptr
<WrappedProperty
> >& rList
90 , const std::shared_ptr
< Chart2ModelContact
>& spChart2ModelContact
91 , tSeriesOrDiagramPropertyType ePropertyType
)
93 //if !spChart2ModelContact.get() is then the created properties do belong to a single series or single datapoint
94 //otherwise they do belong to the whole diagram
96 rList
.emplace_back( new WrappedDataCaptionProperty( spChart2ModelContact
, ePropertyType
) );
99 }//anonymous namespace
101 void WrappedDataCaptionProperties::addProperties( std::vector
< Property
> & rOutProperties
)
103 rOutProperties
.emplace_back( "DataCaption",
104 PROP_CHART_DATAPOINT_DATA_CAPTION
,
105 cppu::UnoType
<sal_Int32
>::get(),
106 beans::PropertyAttribute::BOUND
107 | beans::PropertyAttribute::MAYBEDEFAULT
);
110 void WrappedDataCaptionProperties::addWrappedPropertiesForSeries( std::vector
< std::unique_ptr
<WrappedProperty
> >& rList
111 , const std::shared_ptr
< Chart2ModelContact
>& spChart2ModelContact
)
113 lcl_addWrappedProperties( rList
, spChart2ModelContact
, DATA_SERIES
);
116 void WrappedDataCaptionProperties::addWrappedPropertiesForDiagram( std::vector
< std::unique_ptr
<WrappedProperty
> >& rList
117 , const std::shared_ptr
< Chart2ModelContact
>& spChart2ModelContact
)
119 lcl_addWrappedProperties( rList
, spChart2ModelContact
, DIAGRAM
);
122 WrappedDataCaptionProperty::WrappedDataCaptionProperty(
123 const std::shared_ptr
<Chart2ModelContact
>& spChart2ModelContact
124 , tSeriesOrDiagramPropertyType ePropertyType
)
125 : WrappedSeriesOrDiagramProperty
< sal_Int32
>( "DataCaption"
126 , uno::Any( sal_Int32(0) ), spChart2ModelContact
, ePropertyType
)
130 sal_Int32
WrappedDataCaptionProperty::getValueFromSeries( const Reference
< beans::XPropertySet
>& xSeriesPropertySet
) const
133 m_aDefaultValue
>>= aRet
;
134 chart2::DataPointLabel aLabel
;
135 if( xSeriesPropertySet
.is() && ( xSeriesPropertySet
->getPropertyValue(CHART_UNONAME_LABEL
) >>= aLabel
) )
136 aRet
= lcl_LabelToCaption( aLabel
);
140 void WrappedDataCaptionProperty::setValueToSeries( const Reference
< beans::XPropertySet
>& xSeriesPropertySet
, const sal_Int32
& nCaption
) const
142 if(!xSeriesPropertySet
.is())
145 chart2::DataPointLabel aLabel
= lcl_CaptionToLabel( nCaption
);
146 xSeriesPropertySet
->setPropertyValue( CHART_UNONAME_LABEL
, uno::Any( aLabel
) );
149 } //namespace wrapper
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */