1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: RegressionCurveItemConverter.cxx,v $
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"
37 #include "ItemPropertyMap.hxx"
38 #include "GraphicPropertyItemConverter.hxx"
40 #include <com/sun/star/chart2/XRegressionCurve.hpp>
43 #include <svtools/eitem.hxx>
44 #include <svx/chrtitem.hxx>
49 using namespace ::com::sun::star
;
54 ::chart::RegressionCurveHelper::tRegressionType
lcl_convertRegressionType( SvxChartRegress eRegress
)
56 ::chart::RegressionCurveHelper::tRegressionType eType
= ::chart::RegressionCurveHelper::REGRESSION_TYPE_NONE
;
59 case CHREGRESS_LINEAR
:
60 eType
= ::chart::RegressionCurveHelper::REGRESSION_TYPE_LINEAR
;
63 eType
= ::chart::RegressionCurveHelper::REGRESSION_TYPE_LOG
;
66 eType
= ::chart::RegressionCurveHelper::REGRESSION_TYPE_EXP
;
69 eType
= ::chart::RegressionCurveHelper::REGRESSION_TYPE_POWER
;
77 } // anonymous namespace
84 RegressionCurveItemConverter::RegressionCurveItemConverter(
85 const uno::Reference
< beans::XPropertySet
> & rPropertySet
,
86 const uno::Reference
< chart2::XRegressionCurveContainer
> & xRegCurveCnt
,
87 SfxItemPool
& rItemPool
,
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
);
106 ItemConverter::FillItemSet( rOutItemSet
);
109 bool RegressionCurveItemConverter::ApplyItemSet( const SfxItemSet
& rItemSet
)
111 bool bResult
= m_spGraphicConverter
->ApplyItemSet( rItemSet
);
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
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;
140 case SCHATTR_REGRESSION_TYPE
:
142 OSL_ASSERT( 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
),
161 OSL_ASSERT( xNewPropSet
.is());
162 if( xNewPropSet
.is())
164 resetPropertySet( xNewPropSet
);
172 case SCHATTR_REGRESSION_SHOW_EQUATION
:
174 OSL_ASSERT( 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;
185 (xEqProp
->getPropertyValue( C2U( "ShowEquation" )) >>= bOldShow
) &&
186 bOldShow
!= bNewShow
)
188 xEqProp
->setPropertyValue( C2U( "ShowEquation" ), uno::makeAny( bNewShow
));
195 case SCHATTR_REGRESSION_SHOW_COEFF
:
197 OSL_ASSERT( 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;
208 (xEqProp
->getPropertyValue( C2U( "ShowCorrelationCoefficient" )) >>= bOldShow
) &&
209 bOldShow
!= bNewShow
)
211 xEqProp
->setPropertyValue( C2U( "ShowCorrelationCoefficient" ), uno::makeAny( bNewShow
));
222 void RegressionCurveItemConverter::FillSpecialItem(
223 USHORT nWhichId
, SfxItemSet
& rOutItemSet
) const
224 throw( uno::Exception
)
226 uno::Reference
< chart2::XRegressionCurve
> xCurve( GetPropertySet(), uno::UNO_QUERY
);
230 case SCHATTR_REGRESSION_TYPE
:
232 OSL_ASSERT( xCurve
.is());
235 SvxChartRegress eRegress
= static_cast< SvxChartRegress
>(
236 static_cast< sal_Int32
>( RegressionCurveHelper::getRegressionType( xCurve
)));
237 rOutItemSet
.Put( SvxChartRegressItem( eRegress
, SCHATTR_REGRESSION_TYPE
));
242 case SCHATTR_REGRESSION_SHOW_EQUATION
:
244 OSL_ASSERT( xCurve
.is());
247 uno::Reference
< beans::XPropertySet
> xEqProp( xCurve
->getEquationProperties());
248 OSL_ASSERT( xEqProp
.is());
251 (xEqProp
->getPropertyValue( C2U( "ShowEquation" )) >>= bShow
))
253 rOutItemSet
.Put( SfxBoolItem( nWhichId
, bShow
));
259 case SCHATTR_REGRESSION_SHOW_COEFF
:
261 OSL_ASSERT( xCurve
.is());
264 uno::Reference
< beans::XPropertySet
> xEqProp( xCurve
->getEquationProperties());
265 OSL_ASSERT( xEqProp
.is());
268 (xEqProp
->getPropertyValue( C2U( "ShowCorrelationCoefficient" )) >>= bShow
))
270 rOutItemSet
.Put( SfxBoolItem( nWhichId
, bShow
));
278 } // namespace wrapper