Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / chart2 / source / controller / chartapiwrapper / WrappedGapwidthProperty.cxx
blobfaffb951077d6ab4309bf6811c6b12236c22141b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 "WrappedGapwidthProperty.hxx"
21 #include "Chart2ModelContact.hxx"
22 #include <DiagramHelper.hxx>
24 using namespace ::com::sun::star;
25 using ::com::sun::star::uno::Reference;
26 using ::com::sun::star::uno::Sequence;
27 using ::com::sun::star::uno::Any;
29 namespace chart
31 namespace wrapper
34 const sal_Int32 DEFAULT_GAPWIDTH = 100;
35 const sal_Int32 DEFAULT_OVERLAP = 0;
37 WrappedBarPositionProperty_Base::WrappedBarPositionProperty_Base(
38 const OUString& rOuterName
39 , const OUString& rInnerSequencePropertyName
40 , sal_Int32 nDefaultValue
41 , const std::shared_ptr<Chart2ModelContact>& spChart2ModelContact )
42 : WrappedDefaultProperty( rOuterName, OUString(), uno::Any( nDefaultValue ) )
43 , m_nDimensionIndex(0)
44 , m_nAxisIndex(0)
45 , m_spChart2ModelContact( spChart2ModelContact )
46 , m_nDefaultValue( nDefaultValue )
47 , m_InnerSequencePropertyName( rInnerSequencePropertyName )
51 void WrappedBarPositionProperty_Base::setDimensionAndAxisIndex( sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex )
53 m_nDimensionIndex = nDimensionIndex;
54 m_nAxisIndex = nAxisIndex;
57 WrappedBarPositionProperty_Base::~WrappedBarPositionProperty_Base()
61 void WrappedBarPositionProperty_Base::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
63 sal_Int32 nNewValue = 0;
64 if( ! (rOuterValue >>= nNewValue) )
65 throw lang::IllegalArgumentException( "GapWidth and Overlap property require value of type sal_Int32", nullptr, 0 );
67 m_aOuterValue = rOuterValue;
69 Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
70 if( !xDiagram.is() )
71 return;
73 if( m_nDimensionIndex==1 )
75 Sequence< Reference< chart2::XChartType > > aChartTypeList( DiagramHelper::getChartTypesFromDiagram( xDiagram ) );
76 for( sal_Int32 nN = 0; nN < aChartTypeList.getLength(); nN++ )
78 try
80 Reference< beans::XPropertySet > xProp( aChartTypeList[nN], uno::UNO_QUERY );
81 if( xProp.is() )
83 Sequence< sal_Int32 > aBarPositionSequence;
84 xProp->getPropertyValue( m_InnerSequencePropertyName ) >>= aBarPositionSequence;
86 long nOldLength = aBarPositionSequence.getLength();
87 if( nOldLength <= m_nAxisIndex )
89 aBarPositionSequence.realloc( m_nAxisIndex+1 );
90 for( sal_Int32 i=nOldLength; i<m_nAxisIndex; i++ )
92 aBarPositionSequence[i] = m_nDefaultValue;
95 aBarPositionSequence[m_nAxisIndex] = nNewValue;
97 xProp->setPropertyValue( m_InnerSequencePropertyName, uno::Any( aBarPositionSequence ) );
100 catch( uno::Exception& e )
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
110 Any WrappedBarPositionProperty_Base::getPropertyValue( const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
112 Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
113 if( xDiagram.is() )
115 bool bInnerValueDetected = false;
116 sal_Int32 nInnerValue = m_nDefaultValue;
118 if( m_nDimensionIndex==1 )
120 Sequence< Reference< chart2::XChartType > > aChartTypeList( DiagramHelper::getChartTypesFromDiagram( xDiagram ) );
121 for( sal_Int32 nN = 0; nN < aChartTypeList.getLength() && !bInnerValueDetected; nN++ )
125 Reference< beans::XPropertySet > xProp( aChartTypeList[nN], uno::UNO_QUERY );
126 if( xProp.is() )
128 Sequence< sal_Int32 > aBarPositionSequence;
129 xProp->getPropertyValue( m_InnerSequencePropertyName ) >>= aBarPositionSequence;
130 if( m_nAxisIndex < aBarPositionSequence.getLength() )
132 nInnerValue = aBarPositionSequence[m_nAxisIndex];
133 bInnerValueDetected = true;
137 catch( uno::Exception& e )
139 //the above properties are not supported by all charttypes (only by column and bar)
140 //in that cases this exception is ok
141 e.Context.is();//to have debug information without compilation warnings
145 if( bInnerValueDetected )
147 m_aOuterValue <<= nInnerValue;
150 return m_aOuterValue;
153 WrappedGapwidthProperty::WrappedGapwidthProperty(
154 const std::shared_ptr<Chart2ModelContact>& spChart2ModelContact)
155 : WrappedBarPositionProperty_Base( "GapWidth", "GapwidthSequence", DEFAULT_GAPWIDTH, spChart2ModelContact )
158 WrappedGapwidthProperty::~WrappedGapwidthProperty()
162 WrappedBarOverlapProperty::WrappedBarOverlapProperty(
163 const std::shared_ptr<Chart2ModelContact>& spChart2ModelContact )
164 : WrappedBarPositionProperty_Base( "Overlap", "OverlapSequence", DEFAULT_OVERLAP, spChart2ModelContact )
167 WrappedBarOverlapProperty::~WrappedBarOverlapProperty()
171 } // namespace wrapper
172 } // namespace chart
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */