Debian Codegraph @

chart2/source/controller/chartapiwrapper/WrappedGapwidthProperty.cxx

raw
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 <sal/config.h>
21
22 #include <cstddef>
23
24 #include "WrappedGapwidthProperty.hxx"
25 #include "Chart2ModelContact.hxx"
26 #include <ChartType.hxx>
27 #include <tools/long.hxx>
28 #include <utility>
29
30 using namespace ::com::sun::star;
31 using ::com::sun::star::uno::Reference;
32 using ::com::sun::star::uno::Sequence;
33 using ::com::sun::star::uno::Any;
34
35 namespace chart::wrapper
36 {
37
38 const sal_Int32 DEFAULT_GAPWIDTH = 100;
39 const sal_Int32 DEFAULT_OVERLAP = 0;
40
41 WrappedBarPositionProperty_Base::WrappedBarPositionProperty_Base(
42 const OUString& rOuterName
43 , OUString aInnerSequencePropertyName
44 , sal_Int32 nDefaultValue
45 , std::shared_ptr<Chart2ModelContact> spChart2ModelContact )
46 : WrappedDefaultProperty( rOuterName, OUString(), uno::Any( nDefaultValue ) )
47 , m_nDimensionIndex(0)
48 , m_nAxisIndex(0)
49 , m_spChart2ModelContact(std::move( spChart2ModelContact ))
50 , m_nDefaultValue( nDefaultValue )
51 , m_InnerSequencePropertyName(std::move( aInnerSequencePropertyName ))
52 {
53 }
54
55 void WrappedBarPositionProperty_Base::setDimensionAndAxisIndex( sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex )
56 {
57 m_nDimensionIndex = nDimensionIndex;
58 m_nAxisIndex = nAxisIndex;
59 }
60
61 WrappedBarPositionProperty_Base::~WrappedBarPositionProperty_Base()
62 {
63 }
64
65 void WrappedBarPositionProperty_Base::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
66 {
67 sal_Int32 nNewValue = 0;
68 if( ! (rOuterValue >>= nNewValue) )
69 throw lang::IllegalArgumentException( u"GapWidth and Overlap property require value of type sal_Int32"_ustr, nullptr, 0 );
70
71 m_aOuterValue = rOuterValue;
72
73 rtl::Reference< ::chart::Diagram > xDiagram( m_spChart2ModelContact->getDiagram() );
74 if( !xDiagram.is() )
75 return;
76
77 if( m_nDimensionIndex!=1 )
78 return;
79
80 const std::vector< rtl::Reference< ChartType > > aChartTypeList( xDiagram->getChartTypes() );
81 for( rtl::Reference< ChartType > const & chartType : aChartTypeList )
82 {
83 try
84 {
85 Sequence< sal_Int32 > aBarPositionSequence;
86 chartType->getPropertyValue( m_InnerSequencePropertyName ) >>= aBarPositionSequence;
87
88 tools::Long nOldLength = aBarPositionSequence.getLength();
89 if( nOldLength <= m_nAxisIndex )
90 aBarPositionSequence.realloc( m_nAxisIndex+1 );
91 auto pBarPositionSequence = aBarPositionSequence.getArray();
92 for( sal_Int32 i=nOldLength; i<m_nAxisIndex; i++ )
93 {
94 pBarPositionSequence[i] = m_nDefaultValue;
95 }
96 pBarPositionSequence[m_nAxisIndex] = nNewValue;
97
98 chartType->setPropertyValue( m_InnerSequencePropertyName, uno::Any( aBarPositionSequence ) );
99 }
100 catch( uno::Exception& e )
101 {
102 //the above properties are not supported by all charttypes (only by column and bar)
103 //in that cases this exception is ok
104 e.Context.is();//to have debug information without compilation warnings
105 }
106 }
107 }
108
109 Any WrappedBarPositionProperty_Base::getPropertyValue( const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
110 {
111 rtl::Reference< ::chart::Diagram > xDiagram( m_spChart2ModelContact->getDiagram() );
112 if( xDiagram.is() )
113 {
114 bool bInnerValueDetected = false;
115 sal_Int32 nInnerValue = m_nDefaultValue;
116
117 if( m_nDimensionIndex==1 )
118 {
119 std::vector< rtl::Reference< ChartType > > aChartTypeList = xDiagram->getChartTypes();
120 for( std::size_t nN = 0; nN < aChartTypeList.size() && !bInnerValueDetected; nN++ )
121 {
122 try
123 {
124 Sequence< sal_Int32 > aBarPositionSequence;
125 aChartTypeList[nN]->getPropertyValue( m_InnerSequencePropertyName ) >>= aBarPositionSequence;
126 if( m_nAxisIndex < aBarPositionSequence.getLength() )
127 {
128 nInnerValue = aBarPositionSequence[m_nAxisIndex];
129 bInnerValueDetected = true;
130 }
131 }
132 catch( uno::Exception& e )
133 {
134 //the above properties are not supported by all charttypes (only by column and bar)
135 //in that cases this exception is ok
136 e.Context.is();//to have debug information without compilation warnings
137 }
138 }
139 }
140 if( bInnerValueDetected )
141 {
142 m_aOuterValue <<= nInnerValue;
143 }
144 }
145 return m_aOuterValue;
146 }
147
148 WrappedGapwidthProperty::WrappedGapwidthProperty(
149 const std::shared_ptr<Chart2ModelContact>& spChart2ModelContact)
150 : WrappedBarPositionProperty_Base( u"GapWidth"_ustr, u"GapwidthSequence"_ustr, DEFAULT_GAPWIDTH, spChart2ModelContact )
151 {
152 }
153 WrappedGapwidthProperty::~WrappedGapwidthProperty()
154 {
155 }
156
157 WrappedBarOverlapProperty::WrappedBarOverlapProperty(
158 const std::shared_ptr<Chart2ModelContact>& spChart2ModelContact )
159 : WrappedBarPositionProperty_Base( u"Overlap"_ustr, u"OverlapSequence"_ustr, DEFAULT_OVERLAP, spChart2ModelContact )
160 {
161 }
162 WrappedBarOverlapProperty::~WrappedBarOverlapProperty()
163 {
164 }
165
166 } // namespace chart::wrapper
167
168 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */