1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <sal/config.h>
24 #include "WrappedGapwidthProperty.hxx"
25 #include "Chart2ModelContact.hxx"
26 #include <ChartType.hxx>
27 #include <tools/long.hxx>
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
;
35 namespace chart::wrapper
38 const sal_Int32 DEFAULT_GAPWIDTH
= 100;
39 const sal_Int32 DEFAULT_OVERLAP
= 0;
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)
49 , m_spChart2ModelContact(std::move( spChart2ModelContact
))
50 , m_nDefaultValue( nDefaultValue
)
51 , m_InnerSequencePropertyName(std::move( aInnerSequencePropertyName
))
55 void WrappedBarPositionProperty_Base::setDimensionAndAxisIndex( sal_Int32 nDimensionIndex
, sal_Int32 nAxisIndex
)
57 m_nDimensionIndex
= nDimensionIndex
;
58 m_nAxisIndex
= nAxisIndex
;
61 WrappedBarPositionProperty_Base::~WrappedBarPositionProperty_Base()
65 void WrappedBarPositionProperty_Base::setPropertyValue( const Any
& rOuterValue
, const Reference
< beans::XPropertySet
>& /*xInnerPropertySet*/ ) const
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 );
71 m_aOuterValue
= rOuterValue
;
73 rtl::Reference
< ::chart::Diagram
> xDiagram( m_spChart2ModelContact
->getDiagram() );
77 if( m_nDimensionIndex
!=1 )
80 const std::vector
< rtl::Reference
< ChartType
> > aChartTypeList( xDiagram
->getChartTypes() );
81 for( rtl::Reference
< ChartType
> const & chartType
: aChartTypeList
)
85 Sequence
< sal_Int32
> aBarPositionSequence
;
86 chartType
->getPropertyValue( m_InnerSequencePropertyName
) >>= aBarPositionSequence
;
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
++ )
94 pBarPositionSequence
[i
] = m_nDefaultValue
;
96 pBarPositionSequence
[m_nAxisIndex
] = nNewValue
;
98 chartType
->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
109 Any
WrappedBarPositionProperty_Base::getPropertyValue( const Reference
< beans::XPropertySet
>& /*xInnerPropertySet*/ ) const
111 rtl::Reference
< ::chart::Diagram
> xDiagram( m_spChart2ModelContact
->getDiagram() );
114 bool bInnerValueDetected
= false;
115 sal_Int32 nInnerValue
= m_nDefaultValue
;
117 if( m_nDimensionIndex
==1 )
119 std::vector
< rtl::Reference
< ChartType
> > aChartTypeList
= xDiagram
->getChartTypes();
120 for( std::size_t nN
= 0; nN
< aChartTypeList
.size() && !bInnerValueDetected
; nN
++ )
124 Sequence
< sal_Int32
> aBarPositionSequence
;
125 aChartTypeList
[nN
]->getPropertyValue( m_InnerSequencePropertyName
) >>= aBarPositionSequence
;
126 if( m_nAxisIndex
< aBarPositionSequence
.getLength() )
128 nInnerValue
= aBarPositionSequence
[m_nAxisIndex
];
129 bInnerValueDetected
= true;
132 catch( uno::Exception
& e
)
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
140 if( bInnerValueDetected
)
142 m_aOuterValue
<<= nInnerValue
;
145 return m_aOuterValue
;
148 WrappedGapwidthProperty::WrappedGapwidthProperty(
149 const std::shared_ptr
<Chart2ModelContact
>& spChart2ModelContact
)
150 : WrappedBarPositionProperty_Base( u
"GapWidth"_ustr
, u
"GapwidthSequence"_ustr
, DEFAULT_GAPWIDTH
, spChart2ModelContact
)
153 WrappedGapwidthProperty::~WrappedGapwidthProperty()
157 WrappedBarOverlapProperty::WrappedBarOverlapProperty(
158 const std::shared_ptr
<Chart2ModelContact
>& spChart2ModelContact
)
159 : WrappedBarPositionProperty_Base( u
"Overlap"_ustr
, u
"OverlapSequence"_ustr
, DEFAULT_OVERLAP
, spChart2ModelContact
)
162 WrappedBarOverlapProperty::~WrappedBarOverlapProperty()
166 } // namespace chart::wrapper
168 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */