Update ooo320-m1
[ooovba.git] / chart2 / source / controller / itemsetwrapper / RegressionCurveItemConverter.cxx
blob70828e6952d40605449f68a741422d4f5e037711
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: RegressionCurveItemConverter.cxx,v $
10 * $Revision: 1.5 $
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"
33 #include "RegressionCurveHelper.hxx"
34 #include "RegressionCurveItemConverter.hxx"
35 #include "SchWhichPairs.hxx"
36 #include "macros.hxx"
37 #include "ItemPropertyMap.hxx"
38 #include "GraphicPropertyItemConverter.hxx"
40 #include <com/sun/star/chart2/XRegressionCurve.hpp>
42 // for SfxBoolItem
43 #include <svtools/eitem.hxx>
44 #include <svx/chrtitem.hxx>
46 #include <functional>
47 #include <algorithm>
49 using namespace ::com::sun::star;
51 namespace
54 ::chart::RegressionCurveHelper::tRegressionType lcl_convertRegressionType( SvxChartRegress eRegress )
56 ::chart::RegressionCurveHelper::tRegressionType eType = ::chart::RegressionCurveHelper::REGRESSION_TYPE_NONE;
57 switch( eRegress )
59 case CHREGRESS_LINEAR:
60 eType = ::chart::RegressionCurveHelper::REGRESSION_TYPE_LINEAR;
61 break;
62 case CHREGRESS_LOG:
63 eType = ::chart::RegressionCurveHelper::REGRESSION_TYPE_LOG;
64 break;
65 case CHREGRESS_EXP:
66 eType = ::chart::RegressionCurveHelper::REGRESSION_TYPE_EXP;
67 break;
68 case CHREGRESS_POWER:
69 eType = ::chart::RegressionCurveHelper::REGRESSION_TYPE_POWER;
70 break;
71 case CHREGRESS_NONE:
72 break;
74 return eType;
77 } // anonymous namespace
79 namespace chart
81 namespace wrapper
84 RegressionCurveItemConverter::RegressionCurveItemConverter(
85 const uno::Reference< beans::XPropertySet > & rPropertySet,
86 const uno::Reference< chart2::XRegressionCurveContainer > & xRegCurveCnt,
87 SfxItemPool& rItemPool,
88 SdrModel& rDrawModel,
89 const uno::Reference< lang::XMultiServiceFactory > & xNamedPropertyContainerFactory ) :
90 ItemConverter( rPropertySet, rItemPool ),
91 m_spGraphicConverter( new GraphicPropertyItemConverter(
92 rPropertySet, rItemPool, rDrawModel,
93 xNamedPropertyContainerFactory,
94 GraphicPropertyItemConverter::LINE_PROPERTIES )),
95 m_xCurveContainer( xRegCurveCnt )
98 RegressionCurveItemConverter::~RegressionCurveItemConverter()
101 void RegressionCurveItemConverter::FillItemSet( SfxItemSet & rOutItemSet ) const
103 m_spGraphicConverter->FillItemSet( rOutItemSet );
105 // own items
106 ItemConverter::FillItemSet( rOutItemSet );
109 bool RegressionCurveItemConverter::ApplyItemSet( const SfxItemSet & rItemSet )
111 bool bResult = m_spGraphicConverter->ApplyItemSet( rItemSet );
113 // own items
114 return ItemConverter::ApplyItemSet( rItemSet ) || bResult;
117 const USHORT * RegressionCurveItemConverter::GetWhichPairs() const
119 // must span all used items!
120 return nRegressionCurveWhichPairs;
123 bool RegressionCurveItemConverter::GetItemProperty(
124 tWhichIdType /* nWhichId */, tPropertyNameWithMemberId & /* rOutProperty */ ) const
126 // No own (non-special) properties
127 return false;
131 bool RegressionCurveItemConverter::ApplySpecialItem(
132 USHORT nWhichId, const SfxItemSet & rItemSet )
133 throw( uno::Exception )
135 uno::Reference< chart2::XRegressionCurve > xCurve( GetPropertySet(), uno::UNO_QUERY );
136 bool bChanged = false;
138 switch( nWhichId )
140 case SCHATTR_REGRESSION_TYPE:
142 OSL_ASSERT( xCurve.is());
143 if( xCurve.is())
145 SvxChartRegress eRegress = static_cast< SvxChartRegress >(
146 static_cast< sal_Int32 >( RegressionCurveHelper::getRegressionType( xCurve )));
147 SvxChartRegress eNewRegress = static_cast< const SvxChartRegressItem & >(
148 rItemSet.Get( nWhichId )).GetValue();
149 if( eRegress != eNewRegress )
151 // note that changing the regression type changes the object
152 // for which this converter was created. Not optimal, but
153 // currently the only way to handle the type in the
154 // regression curve properties dialog
155 RegressionCurveHelper::replaceOrAddCurveAndReduceToOne(
156 lcl_convertRegressionType( eNewRegress ), m_xCurveContainer,
157 uno::Reference< uno::XComponentContext >());
158 uno::Reference< beans::XPropertySet > xNewPropSet(
159 RegressionCurveHelper::getFirstCurveNotMeanValueLine( m_xCurveContainer ),
160 uno::UNO_QUERY );
161 OSL_ASSERT( xNewPropSet.is());
162 if( xNewPropSet.is())
164 resetPropertySet( xNewPropSet );
165 bChanged = true;
170 break;
172 case SCHATTR_REGRESSION_SHOW_EQUATION:
174 OSL_ASSERT( xCurve.is());
175 if( xCurve.is())
177 bool bNewShow = static_cast< BOOL >(
178 static_cast< const SfxBoolItem & >(
179 rItemSet.Get( nWhichId )).GetValue());
181 uno::Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties());
182 OSL_ASSERT( xEqProp.is());
183 bool bOldShow = false;
184 if( xEqProp.is() &&
185 (xEqProp->getPropertyValue( C2U( "ShowEquation" )) >>= bOldShow) &&
186 bOldShow != bNewShow )
188 xEqProp->setPropertyValue( C2U( "ShowEquation" ), uno::makeAny( bNewShow ));
189 bChanged = true;
193 break;
195 case SCHATTR_REGRESSION_SHOW_COEFF:
197 OSL_ASSERT( xCurve.is());
198 if( xCurve.is())
200 bool bNewShow = static_cast< BOOL >(
201 static_cast< const SfxBoolItem & >(
202 rItemSet.Get( nWhichId )).GetValue());
204 uno::Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties());
205 OSL_ASSERT( xEqProp.is());
206 bool bOldShow = false;
207 if( xEqProp.is() &&
208 (xEqProp->getPropertyValue( C2U( "ShowCorrelationCoefficient" )) >>= bOldShow) &&
209 bOldShow != bNewShow )
211 xEqProp->setPropertyValue( C2U( "ShowCorrelationCoefficient" ), uno::makeAny( bNewShow ));
212 bChanged = true;
216 break;
219 return bChanged;
222 void RegressionCurveItemConverter::FillSpecialItem(
223 USHORT nWhichId, SfxItemSet & rOutItemSet ) const
224 throw( uno::Exception )
226 uno::Reference< chart2::XRegressionCurve > xCurve( GetPropertySet(), uno::UNO_QUERY );
228 switch( nWhichId )
230 case SCHATTR_REGRESSION_TYPE:
232 OSL_ASSERT( xCurve.is());
233 if( xCurve.is())
235 SvxChartRegress eRegress = static_cast< SvxChartRegress >(
236 static_cast< sal_Int32 >( RegressionCurveHelper::getRegressionType( xCurve )));
237 rOutItemSet.Put( SvxChartRegressItem( eRegress, SCHATTR_REGRESSION_TYPE ));
240 break;
242 case SCHATTR_REGRESSION_SHOW_EQUATION:
244 OSL_ASSERT( xCurve.is());
245 if( xCurve.is())
247 uno::Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties());
248 OSL_ASSERT( xEqProp.is());
249 bool bShow = false;
250 if( xEqProp.is() &&
251 (xEqProp->getPropertyValue( C2U( "ShowEquation" )) >>= bShow))
253 rOutItemSet.Put( SfxBoolItem( nWhichId, bShow ));
257 break;
259 case SCHATTR_REGRESSION_SHOW_COEFF:
261 OSL_ASSERT( xCurve.is());
262 if( xCurve.is())
264 uno::Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties());
265 OSL_ASSERT( xEqProp.is());
266 bool bShow = false;
267 if( xEqProp.is() &&
268 (xEqProp->getPropertyValue( C2U( "ShowCorrelationCoefficient" )) >>= bShow))
270 rOutItemSet.Put( SfxBoolItem( nWhichId, bShow ));
274 break;
278 } // namespace wrapper
279 } // namespace chart