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