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"
23 #include "FastPropertyIdRanges.hxx"
24 #include <unonames.hxx>
26 #include <com/sun/star/chart2/DataPointLabel.hpp>
27 #include <com/sun/star/chart/ChartDataCaption.hpp>
28 #include <com/sun/star/beans/PropertyAttribute.hpp>
30 using namespace ::com::sun::star
;
31 using ::com::sun::star::uno::Any
;
32 using ::com::sun::star::uno::Reference
;
33 using ::com::sun::star::uno::Sequence
;
34 using ::com::sun::star::beans::Property
;
41 class WrappedDataCaptionProperty
: public WrappedSeriesOrDiagramProperty
< sal_Int32
>
44 virtual sal_Int32
getValueFromSeries( const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& xSeriesPropertySet
) const SAL_OVERRIDE
;
45 virtual void setValueToSeries( const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& xSeriesPropertySet
, const sal_Int32
& aNewValue
) const SAL_OVERRIDE
;
47 explicit WrappedDataCaptionProperty( ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
,
48 tSeriesOrDiagramPropertyType ePropertyType
);
49 virtual ~WrappedDataCaptionProperty();
56 //data caption properties
57 PROP_CHART_DATAPOINT_DATA_CAPTION
= FAST_PROPERTY_ID_START_CHART_DATACAPTION_PROP
60 sal_Int32
lcl_LabelToCaption( const chart2::DataPointLabel
& rLabel
)
64 if( rLabel
.ShowNumber
)
65 nCaption
|= ::com::sun::star::chart::ChartDataCaption::VALUE
;
66 if( rLabel
.ShowNumberInPercent
)
67 nCaption
|= ::com::sun::star::chart::ChartDataCaption::PERCENT
;
68 if( rLabel
.ShowCategoryName
)
69 nCaption
|= ::com::sun::star::chart::ChartDataCaption::TEXT
;
70 if( rLabel
.ShowLegendSymbol
)
71 nCaption
|= ::com::sun::star::chart::ChartDataCaption::SYMBOL
;
76 chart2::DataPointLabel
lcl_CaptionToLabel( sal_Int32 nCaption
)
78 chart2::DataPointLabel
aLabel(false,false,false,false);
80 if( nCaption
& ::com::sun::star::chart::ChartDataCaption::VALUE
)
81 aLabel
.ShowNumber
= true;
82 if( nCaption
& ::com::sun::star::chart::ChartDataCaption::PERCENT
)
83 aLabel
.ShowNumberInPercent
= true;
84 if( nCaption
& ::com::sun::star::chart::ChartDataCaption::TEXT
)
85 aLabel
.ShowCategoryName
= true;
86 if( nCaption
& ::com::sun::star::chart::ChartDataCaption::SYMBOL
)
87 aLabel
.ShowLegendSymbol
= true;
92 void lcl_addWrappedProperties( std::vector
< WrappedProperty
* >& rList
93 , ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
94 , tSeriesOrDiagramPropertyType ePropertyType
)
96 //if !spChart2ModelContact.get() is then the created properties do belong to a single series or single datapoint
97 //otherwise they do belong to the whole diagram
99 rList
.push_back( new WrappedDataCaptionProperty( spChart2ModelContact
, ePropertyType
) );
102 }//anonymous namespace
104 void WrappedDataCaptionProperties::addProperties( ::std::vector
< Property
> & rOutProperties
)
106 rOutProperties
.push_back(
107 Property( "DataCaption",
108 PROP_CHART_DATAPOINT_DATA_CAPTION
,
109 cppu::UnoType
<sal_Int32
>::get(),
110 beans::PropertyAttribute::BOUND
111 | beans::PropertyAttribute::MAYBEDEFAULT
));
114 void WrappedDataCaptionProperties::addWrappedPropertiesForSeries( std::vector
< WrappedProperty
* >& rList
115 , ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
)
117 lcl_addWrappedProperties( rList
, spChart2ModelContact
, DATA_SERIES
);
120 void WrappedDataCaptionProperties::addWrappedPropertiesForDiagram( std::vector
< WrappedProperty
* >& rList
121 , ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
)
123 lcl_addWrappedProperties( rList
, spChart2ModelContact
, DIAGRAM
);
126 WrappedDataCaptionProperty::WrappedDataCaptionProperty(
127 ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
128 , tSeriesOrDiagramPropertyType ePropertyType
)
129 : WrappedSeriesOrDiagramProperty
< sal_Int32
>( "DataCaption"
130 , uno::makeAny( sal_Int32(0) ), spChart2ModelContact
, ePropertyType
)
133 WrappedDataCaptionProperty::~WrappedDataCaptionProperty()
137 sal_Int32
WrappedDataCaptionProperty::getValueFromSeries( const Reference
< beans::XPropertySet
>& xSeriesPropertySet
) const
140 m_aDefaultValue
>>= aRet
;
141 chart2::DataPointLabel aLabel
;
142 if( xSeriesPropertySet
.is() && ( xSeriesPropertySet
->getPropertyValue(CHART_UNONAME_LABEL
) >>= aLabel
) )
143 aRet
= lcl_LabelToCaption( aLabel
);
147 void WrappedDataCaptionProperty::setValueToSeries( const Reference
< beans::XPropertySet
>& xSeriesPropertySet
, const sal_Int32
& nCaption
) const
149 if(!xSeriesPropertySet
.is())
152 chart2::DataPointLabel aLabel
= lcl_CaptionToLabel( nCaption
);
153 xSeriesPropertySet
->setPropertyValue( CHART_UNONAME_LABEL
, uno::makeAny( aLabel
) );
156 } //namespace wrapper
159 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */