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