merged tag ooo/OOO330_m14
[LibreOffice.git] / chart2 / source / controller / itemsetwrapper / RegressionEquationItemConverter.cxx
blob6035f21696a9a6ef8b78a4bd94245486b934a238
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_chart2.hxx"
31 #include "RegressionEquationItemConverter.hxx"
32 #include "SchWhichPairs.hxx"
33 #include "macros.hxx"
34 #include "ItemPropertyMap.hxx"
35 #include "GraphicPropertyItemConverter.hxx"
36 #include "CharacterPropertyItemConverter.hxx"
37 #include "MultipleItemConverter.hxx"
39 #include <svl/intitem.hxx>
40 #include <rtl/math.hxx>
42 #include <functional>
43 #include <algorithm>
45 using namespace ::com::sun::star;
47 namespace
49 ::comphelper::ItemPropertyMapType & lcl_GetEquationPropertyMap()
51 static ::comphelper::ItemPropertyMapType aEquationPropertyMap;
53 return aEquationPropertyMap;
55 } // anonymous namespace
57 namespace chart
59 namespace wrapper
62 RegressionEquationItemConverter::RegressionEquationItemConverter(
63 const ::com::sun::star::uno::Reference<
64 ::com::sun::star::beans::XPropertySet > & rPropertySet,
65 SfxItemPool& rItemPool,
66 SdrModel& rDrawModel,
67 const uno::Reference< lang::XMultiServiceFactory > & xNamedPropertyContainerFactory,
68 ::std::auto_ptr< ::com::sun::star::awt::Size > pRefSize ) :
69 ItemConverter( rPropertySet, rItemPool )
71 m_aConverters.push_back( new GraphicPropertyItemConverter(
72 rPropertySet, rItemPool, rDrawModel,
73 xNamedPropertyContainerFactory,
74 GraphicPropertyItemConverter::LINE_AND_FILL_PROPERTIES ));
76 m_aConverters.push_back( new CharacterPropertyItemConverter(
77 rPropertySet, rItemPool, pRefSize, C2U("ReferencePageSize")));
79 // // CharacterProperties are not at the title but at its contained XFormattedString objects
80 // // take the first formatted string in the sequence
81 // uno::Reference< chart2::XTitle > xTitle( rPropertySet, uno::UNO_QUERY );
82 // if( xTitle.is())
83 // {
84 // uno::Sequence< uno::Reference< chart2::XFormattedString > > aStringSeq( xTitle->getText());
85 // if( aStringSeq.getLength() > 0 )
86 // {
87 // m_aConverters.push_back(
88 // new FormattedStringsConverter( aStringSeq, rItemPool, pRefSize, rPropertySet ));
89 // }
90 // }
93 RegressionEquationItemConverter::~RegressionEquationItemConverter()
95 ::std::for_each( m_aConverters.begin(), m_aConverters.end(),
96 ::comphelper::DeleteItemConverterPtr() );
99 void RegressionEquationItemConverter::FillItemSet( SfxItemSet & rOutItemSet ) const
101 ::std::for_each( m_aConverters.begin(), m_aConverters.end(),
102 ::comphelper::FillItemSetFunc( rOutItemSet ));
104 // own items
105 ItemConverter::FillItemSet( rOutItemSet );
108 bool RegressionEquationItemConverter::ApplyItemSet( const SfxItemSet & rItemSet )
110 bool bResult = false;
112 ::std::for_each( m_aConverters.begin(), m_aConverters.end(),
113 ::comphelper::ApplyItemSetFunc( rItemSet, bResult ));
115 // own items
116 return ItemConverter::ApplyItemSet( rItemSet ) || bResult;
119 const USHORT * RegressionEquationItemConverter::GetWhichPairs() const
121 // must span all used items!
122 return nRegEquationWhichPairs;
125 bool RegressionEquationItemConverter::GetItemProperty( tWhichIdType nWhichId, tPropertyNameWithMemberId & rOutProperty ) const
127 ::comphelper::ItemPropertyMapType & rMap( lcl_GetEquationPropertyMap());
128 ::comphelper::ItemPropertyMapType::const_iterator aIt( rMap.find( nWhichId ));
130 if( aIt == rMap.end())
131 return false;
133 rOutProperty =(*aIt).second;
134 return true;
137 bool RegressionEquationItemConverter::ApplySpecialItem(
138 USHORT nWhichId, const SfxItemSet & rItemSet )
139 throw( uno::Exception )
141 bool bChanged = false;
143 switch( nWhichId )
145 case SID_ATTR_NUMBERFORMAT_VALUE:
147 // bool bUseSourceFormat =
148 // (static_cast< const SfxBoolItem & >(
149 // rItemSet.Get( SID_ATTR_NUMBERFORMAT_SOURCE )).GetValue() );
151 // if( ! bUseSourceFormat )
152 // {
153 uno::Any aValue( static_cast< sal_Int32 >(
154 static_cast< const SfxUInt32Item & >(
155 rItemSet.Get( nWhichId )).GetValue()));
156 if( GetPropertySet()->getPropertyValue( C2U( "NumberFormat" )) != aValue )
158 GetPropertySet()->setPropertyValue( C2U( "NumberFormat" ), aValue );
159 bChanged = true;
162 break;
165 return bChanged;
168 void RegressionEquationItemConverter::FillSpecialItem(
169 USHORT nWhichId, SfxItemSet & rOutItemSet ) const
170 throw( uno::Exception )
172 switch( nWhichId )
174 case SID_ATTR_NUMBERFORMAT_VALUE:
176 sal_Int32 nFormatKey = 0;
177 if( GetPropertySet()->getPropertyValue( C2U( "NumberFormat" )) >>= nFormatKey )
179 rOutItemSet.Put( SfxUInt32Item( nWhichId, nFormatKey ));
182 break;
186 } // namespace wrapper
187 } // namespace chart