Branch data Line data Source code
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 : :
20 : :
21 : : #include "WrappedDataCaptionProperties.hxx"
22 : : #include "WrappedSeriesOrDiagramProperty.hxx"
23 : : #include "macros.hxx"
24 : : #include "FastPropertyIdRanges.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 : :
29 : : using namespace ::com::sun::star;
30 : : using ::com::sun::star::uno::Any;
31 : : using ::com::sun::star::uno::Reference;
32 : : using ::com::sun::star::uno::Sequence;
33 : : using ::com::sun::star::beans::Property;
34 : : using ::rtl::OUString;
35 : :
36 : : //.............................................................................
37 : : namespace chart
38 : : {
39 : : namespace wrapper
40 : : {
41 : :
42 : : //-----------------------------------------------------------------------------
43 : :
44 : : class WrappedDataCaptionProperty : public WrappedSeriesOrDiagramProperty< sal_Int32 >
45 : : {
46 : : public:
47 : : virtual sal_Int32 getValueFromSeries( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xSeriesPropertySet ) const;
48 : : virtual void setValueToSeries( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xSeriesPropertySet, sal_Int32 aNewValue ) const;
49 : :
50 : : explicit WrappedDataCaptionProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact,
51 : : tSeriesOrDiagramPropertyType ePropertyType );
52 : : virtual ~WrappedDataCaptionProperty();
53 : : };
54 : :
55 : : namespace
56 : : {
57 : : enum
58 : : {
59 : : //data caption properties
60 : : PROP_CHART_DATAPOINT_DATA_CAPTION = FAST_PROPERTY_ID_START_CHART_DATACAPTION_PROP
61 : : };
62 : :
63 : 184 : sal_Int32 lcl_LabelToCaption( const chart2::DataPointLabel& rLabel )
64 : : {
65 : 184 : sal_Int32 nCaption=0;
66 : :
67 [ + + ]: 184 : if( rLabel.ShowNumber )
68 : 16 : nCaption |= ::com::sun::star::chart::ChartDataCaption::VALUE;
69 [ + + ]: 184 : if( rLabel.ShowNumberInPercent )
70 : 10 : nCaption |= ::com::sun::star::chart::ChartDataCaption::PERCENT;
71 [ + + ]: 184 : if( rLabel.ShowCategoryName )
72 : 18 : nCaption |= ::com::sun::star::chart::ChartDataCaption::TEXT;
73 [ - + ]: 184 : if( rLabel.ShowLegendSymbol )
74 : 0 : nCaption |= ::com::sun::star::chart::ChartDataCaption::SYMBOL;
75 : :
76 : 184 : return nCaption;
77 : : }
78 : :
79 : 52 : chart2::DataPointLabel lcl_CaptionToLabel( sal_Int32 nCaption )
80 : : {
81 : 52 : chart2::DataPointLabel aLabel(false,false,false,false);
82 : :
83 [ + + ]: 52 : if( nCaption & ::com::sun::star::chart::ChartDataCaption::VALUE )
84 : 12 : aLabel.ShowNumber = true;
85 [ + + ]: 52 : if( nCaption & ::com::sun::star::chart::ChartDataCaption::PERCENT )
86 : 4 : aLabel.ShowNumberInPercent = true;
87 [ + + ]: 52 : if( nCaption & ::com::sun::star::chart::ChartDataCaption::TEXT )
88 : 12 : aLabel.ShowCategoryName = true;
89 [ - + ]: 52 : if( nCaption & ::com::sun::star::chart::ChartDataCaption::SYMBOL )
90 : 0 : aLabel.ShowLegendSymbol = true;
91 : :
92 : 52 : return aLabel;
93 : : }
94 : :
95 : 129 : void lcl_addWrappedProperties( std::vector< WrappedProperty* >& rList
96 : : , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact
97 : : , tSeriesOrDiagramPropertyType ePropertyType )
98 : : {
99 : : //if !spChart2ModelContact.get() is then the created properties do belong to a single series or single datapoint
100 : : //otherwise they do belong to the whole diagram
101 : :
102 [ + - ][ + - ]: 129 : rList.push_back( new WrappedDataCaptionProperty( spChart2ModelContact, ePropertyType ) );
[ + - ]
103 : 129 : }
104 : :
105 : : }//anonymous namespace
106 : :
107 : : //-----------------------------------------------------------------------------
108 : :
109 : 19 : void WrappedDataCaptionProperties::addProperties( ::std::vector< Property > & rOutProperties )
110 : : {
111 : : rOutProperties.push_back(
112 : : Property( "DataCaption",
113 : : PROP_CHART_DATAPOINT_DATA_CAPTION,
114 [ + - ]: 19 : ::getCppuType( reinterpret_cast< sal_Int32 * >(0)),
115 : : beans::PropertyAttribute::BOUND
116 [ + - ]: 19 : | beans::PropertyAttribute::MAYBEDEFAULT ));
117 : 19 : }
118 : :
119 : : //-----------------------------------------------------------------------------
120 : :
121 : 96 : void WrappedDataCaptionProperties::addWrappedPropertiesForSeries( std::vector< WrappedProperty* >& rList
122 : : , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
123 : : {
124 [ + - ]: 96 : lcl_addWrappedProperties( rList, spChart2ModelContact, DATA_SERIES );
125 : 96 : }
126 : :
127 : : //-----------------------------------------------------------------------------
128 : :
129 : 33 : void WrappedDataCaptionProperties::addWrappedPropertiesForDiagram( std::vector< WrappedProperty* >& rList
130 : : , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
131 : : {
132 [ + - ]: 33 : lcl_addWrappedProperties( rList, spChart2ModelContact, DIAGRAM );
133 : 33 : }
134 : :
135 : : //-----------------------------------------------------------------------------
136 : :
137 : 129 : WrappedDataCaptionProperty::WrappedDataCaptionProperty(
138 : : ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact
139 : : , tSeriesOrDiagramPropertyType ePropertyType )
140 : : : WrappedSeriesOrDiagramProperty< sal_Int32 >( "DataCaption"
141 [ + - ][ + - ]: 129 : , uno::makeAny( sal_Int32(0) ), spChart2ModelContact, ePropertyType )
142 : : {
143 : 129 : }
144 : 129 : WrappedDataCaptionProperty::~WrappedDataCaptionProperty()
145 : : {
146 [ - + ]: 258 : }
147 : :
148 : 184 : sal_Int32 WrappedDataCaptionProperty::getValueFromSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet ) const
149 : : {
150 : 184 : sal_Int32 aRet = 0;
151 : 184 : m_aDefaultValue >>= aRet;
152 : 184 : chart2::DataPointLabel aLabel;
153 [ + - ][ + - ]: 184 : if( xSeriesPropertySet.is() && ( xSeriesPropertySet->getPropertyValue("Label") >>= aLabel ) )
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + -
# # # # #
# ][ + - ]
154 : 184 : aRet = lcl_LabelToCaption( aLabel );
155 : 184 : return aRet;
156 : : }
157 : :
158 : 52 : void WrappedDataCaptionProperty::setValueToSeries( const Reference< beans::XPropertySet >& xSeriesPropertySet, sal_Int32 nCaption ) const
159 : : {
160 [ + - ]: 52 : if(!xSeriesPropertySet.is())
161 : 52 : return;
162 : :
163 : 52 : chart2::DataPointLabel aLabel = lcl_CaptionToLabel( nCaption );
164 [ + - ][ + - ]: 52 : xSeriesPropertySet->setPropertyValue( "Label", uno::makeAny( aLabel ) );
[ + - ]
165 : : }
166 : :
167 : : //-----------------------------------------------------------------------------
168 : :
169 : : } //namespace wrapper
170 : : } //namespace chart
171 : : //.............................................................................
172 : :
173 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|