Update ooo320-m1
[ooovba.git] / chart2 / source / controller / itemsetwrapper / RegressionEquationItemConverter.cxx
blob3247676de77ab655233c9bfaaca98913be72fbf3
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: RegressionEquationItemConverter.cxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
34 #include "RegressionEquationItemConverter.hxx"
35 #include "SchWhichPairs.hxx"
36 #include "macros.hxx"
37 #include "ItemPropertyMap.hxx"
38 #include "GraphicPropertyItemConverter.hxx"
39 #include "CharacterPropertyItemConverter.hxx"
40 #include "MultipleItemConverter.hxx"
42 #include <svtools/intitem.hxx>
43 #include <rtl/math.hxx>
45 #include <functional>
46 #include <algorithm>
48 using namespace ::com::sun::star;
50 namespace
52 ::comphelper::ItemPropertyMapType & lcl_GetEquationPropertyMap()
54 static ::comphelper::ItemPropertyMapType aEquationPropertyMap;
56 return aEquationPropertyMap;
58 } // anonymous namespace
60 namespace chart
62 namespace wrapper
65 RegressionEquationItemConverter::RegressionEquationItemConverter(
66 const ::com::sun::star::uno::Reference<
67 ::com::sun::star::beans::XPropertySet > & rPropertySet,
68 SfxItemPool& rItemPool,
69 SdrModel& rDrawModel,
70 const uno::Reference< lang::XMultiServiceFactory > & xNamedPropertyContainerFactory,
71 ::std::auto_ptr< ::com::sun::star::awt::Size > pRefSize ) :
72 ItemConverter( rPropertySet, rItemPool )
74 m_aConverters.push_back( new GraphicPropertyItemConverter(
75 rPropertySet, rItemPool, rDrawModel,
76 xNamedPropertyContainerFactory,
77 GraphicPropertyItemConverter::LINE_AND_FILL_PROPERTIES ));
79 m_aConverters.push_back( new CharacterPropertyItemConverter(
80 rPropertySet, rItemPool, pRefSize, C2U("ReferencePageSize")));
82 // // CharacterProperties are not at the title but at its contained XFormattedString objects
83 // // take the first formatted string in the sequence
84 // uno::Reference< chart2::XTitle > xTitle( rPropertySet, uno::UNO_QUERY );
85 // if( xTitle.is())
86 // {
87 // uno::Sequence< uno::Reference< chart2::XFormattedString > > aStringSeq( xTitle->getText());
88 // if( aStringSeq.getLength() > 0 )
89 // {
90 // m_aConverters.push_back(
91 // new FormattedStringsConverter( aStringSeq, rItemPool, pRefSize, rPropertySet ));
92 // }
93 // }
96 RegressionEquationItemConverter::~RegressionEquationItemConverter()
98 ::std::for_each( m_aConverters.begin(), m_aConverters.end(),
99 ::comphelper::DeleteItemConverterPtr() );
102 void RegressionEquationItemConverter::FillItemSet( SfxItemSet & rOutItemSet ) const
104 ::std::for_each( m_aConverters.begin(), m_aConverters.end(),
105 ::comphelper::FillItemSetFunc( rOutItemSet ));
107 // own items
108 ItemConverter::FillItemSet( rOutItemSet );
111 bool RegressionEquationItemConverter::ApplyItemSet( const SfxItemSet & rItemSet )
113 bool bResult = false;
115 ::std::for_each( m_aConverters.begin(), m_aConverters.end(),
116 ::comphelper::ApplyItemSetFunc( rItemSet, bResult ));
118 // own items
119 return ItemConverter::ApplyItemSet( rItemSet ) || bResult;
122 const USHORT * RegressionEquationItemConverter::GetWhichPairs() const
124 // must span all used items!
125 return nRegEquationWhichPairs;
128 bool RegressionEquationItemConverter::GetItemProperty( tWhichIdType nWhichId, tPropertyNameWithMemberId & rOutProperty ) const
130 ::comphelper::ItemPropertyMapType & rMap( lcl_GetEquationPropertyMap());
131 ::comphelper::ItemPropertyMapType::const_iterator aIt( rMap.find( nWhichId ));
133 if( aIt == rMap.end())
134 return false;
136 rOutProperty =(*aIt).second;
137 return true;
140 bool RegressionEquationItemConverter::ApplySpecialItem(
141 USHORT nWhichId, const SfxItemSet & rItemSet )
142 throw( uno::Exception )
144 bool bChanged = false;
146 switch( nWhichId )
148 case SID_ATTR_NUMBERFORMAT_VALUE:
150 // bool bUseSourceFormat =
151 // (static_cast< const SfxBoolItem & >(
152 // rItemSet.Get( SID_ATTR_NUMBERFORMAT_SOURCE )).GetValue() );
154 // if( ! bUseSourceFormat )
155 // {
156 uno::Any aValue( static_cast< sal_Int32 >(
157 static_cast< const SfxUInt32Item & >(
158 rItemSet.Get( nWhichId )).GetValue()));
159 if( GetPropertySet()->getPropertyValue( C2U( "NumberFormat" )) != aValue )
161 GetPropertySet()->setPropertyValue( C2U( "NumberFormat" ), aValue );
162 bChanged = true;
165 break;
168 return bChanged;
171 void RegressionEquationItemConverter::FillSpecialItem(
172 USHORT nWhichId, SfxItemSet & rOutItemSet ) const
173 throw( uno::Exception )
175 switch( nWhichId )
177 case SID_ATTR_NUMBERFORMAT_VALUE:
179 sal_Int32 nFormatKey = 0;
180 if( GetPropertySet()->getPropertyValue( C2U( "NumberFormat" )) >>= nFormatKey )
182 rOutItemSet.Put( SfxUInt32Item( nWhichId, nFormatKey ));
185 break;
189 } // namespace wrapper
190 } // namespace chart