bump product version to 4.1.6.2
[LibreOffice.git] / chart2 / source / tools / RegressionEquation.cxx
blobe8bdfe9720d80dee4dbbe092b42d16c17a0e42fc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
21 #include "RegressionEquation.hxx"
22 #include "LinePropertiesHelper.hxx"
23 #include "FillProperties.hxx"
24 #include "UserDefinedProperties.hxx"
25 #include "CharacterProperties.hxx"
26 #include "PropertyHelper.hxx"
27 #include "macros.hxx"
28 #include "ContainerHelper.hxx"
30 #include <com/sun/star/uno/Sequence.hxx>
31 #include <com/sun/star/drawing/FillStyle.hpp>
32 #include <com/sun/star/drawing/LineStyle.hpp>
33 #include <com/sun/star/beans/PropertyAttribute.hpp>
34 #include <com/sun/star/chart2/RelativePosition.hpp>
35 #include <com/sun/star/awt/Size.hpp>
37 #include <algorithm>
39 using namespace ::com::sun::star;
41 using ::com::sun::star::uno::Reference;
42 using ::com::sun::star::beans::Property;
43 using ::osl::MutexGuard;
45 // ____________________________________________________________
47 namespace
50 static const OUString lcl_aImplementationName( "com.sun.star.comp.chart2.RegressionEquation" );
51 static const OUString lcl_aServiceName( "com.sun.star.chart2.RegressionEquation" );
53 enum
55 PROP_EQUATION_SHOW,
56 PROP_EQUATION_SHOW_CORRELATION_COEFF,
57 PROP_EQUATION_REF_PAGE_SIZE,
58 PROP_EQUATION_REL_POS,
59 PROP_EQUATION_NUMBER_FORMAT
62 void lcl_AddPropertiesToVector(
63 ::std::vector< Property > & rOutProperties )
65 rOutProperties.push_back(
66 Property( "ShowEquation",
67 PROP_EQUATION_SHOW,
68 ::getBooleanCppuType(),
69 beans::PropertyAttribute::BOUND
70 | beans::PropertyAttribute::MAYBEDEFAULT ));
72 rOutProperties.push_back(
73 Property( "ShowCorrelationCoefficient",
74 PROP_EQUATION_SHOW_CORRELATION_COEFF,
75 ::getBooleanCppuType(),
76 beans::PropertyAttribute::BOUND
77 | beans::PropertyAttribute::MAYBEDEFAULT ));
79 rOutProperties.push_back(
80 Property( "ReferencePageSize",
81 PROP_EQUATION_REF_PAGE_SIZE,
82 ::getCppuType( reinterpret_cast< const awt::Size * >(0)),
83 beans::PropertyAttribute::BOUND
84 | beans::PropertyAttribute::MAYBEVOID ));
86 rOutProperties.push_back(
87 Property( "RelativePosition",
88 PROP_EQUATION_REL_POS,
89 ::getCppuType( reinterpret_cast< const chart2::RelativePosition * >(0)),
90 beans::PropertyAttribute::BOUND
91 | beans::PropertyAttribute::MAYBEVOID ));
93 rOutProperties.push_back(
94 Property( "NumberFormat",
95 PROP_EQUATION_NUMBER_FORMAT,
96 ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
97 beans::PropertyAttribute::BOUND
98 | beans::PropertyAttribute::MAYBEVOID ));
101 struct StaticRegressionEquationDefaults_Initializer
103 ::chart::tPropertyValueMap* operator()()
105 static ::chart::tPropertyValueMap aStaticDefaults;
106 lcl_AddDefaultsToMap( aStaticDefaults );
107 return &aStaticDefaults;
109 private:
110 void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
112 ::chart::LinePropertiesHelper::AddDefaultsToMap( rOutMap );
113 ::chart::FillProperties::AddDefaultsToMap( rOutMap );
114 ::chart::CharacterProperties::AddDefaultsToMap( rOutMap );
116 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_EQUATION_SHOW, false );
117 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_EQUATION_SHOW_CORRELATION_COEFF, false );
118 //::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_EQUATION_SEPARATOR, OUString( sal_Unicode( '\n' )));
120 // override other defaults
121 ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::FillProperties::PROP_FILL_STYLE, drawing::FillStyle_NONE );
122 ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::LinePropertiesHelper::PROP_LINE_STYLE, drawing::LineStyle_NONE );
124 float fDefaultCharHeight = 10.0;
125 ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_CHAR_HEIGHT, fDefaultCharHeight );
126 ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_ASIAN_CHAR_HEIGHT, fDefaultCharHeight );
127 ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_COMPLEX_CHAR_HEIGHT, fDefaultCharHeight );
131 struct StaticRegressionEquationDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticRegressionEquationDefaults_Initializer >
135 struct StaticRegressionEquationInfoHelper_Initializer
137 ::cppu::OPropertyArrayHelper* operator()()
139 static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
140 return &aPropHelper;
143 private:
144 uno::Sequence< Property > lcl_GetPropertySequence()
146 ::std::vector< ::com::sun::star::beans::Property > aProperties;
147 lcl_AddPropertiesToVector( aProperties );
148 ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties );
149 ::chart::FillProperties::AddPropertiesToVector( aProperties );
150 ::chart::CharacterProperties::AddPropertiesToVector( aProperties );
151 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
153 ::std::sort( aProperties.begin(), aProperties.end(),
154 ::chart::PropertyNameLess() );
156 return ::chart::ContainerHelper::ContainerToSequence( aProperties );
161 struct StaticRegressionEquationInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticRegressionEquationInfoHelper_Initializer >
165 struct StaticRegressionEquationInfo_Initializer
167 uno::Reference< beans::XPropertySetInfo >* operator()()
169 static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
170 ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticRegressionEquationInfoHelper::get() ) );
171 return &xPropertySetInfo;
175 struct StaticRegressionEquationInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticRegressionEquationInfo_Initializer >
179 } // anonymous namespace
181 // ____________________________________________________________
183 namespace chart
186 RegressionEquation::RegressionEquation( const Reference< uno::XComponentContext > & xContext ) :
187 ::property::OPropertySet( m_aMutex ),
188 m_xModifyEventForwarder( new ModifyListenerHelper::ModifyEventForwarder()),
189 m_xContext( xContext )
192 RegressionEquation::RegressionEquation( const RegressionEquation & rOther ) :
193 MutexContainer(),
194 impl::RegressionEquation_Base(),
195 ::property::OPropertySet( rOther, m_aMutex ),
196 m_xModifyEventForwarder( new ModifyListenerHelper::ModifyEventForwarder()),
197 m_xContext( NULL )
200 RegressionEquation::~RegressionEquation()
204 // ____ XCloneable ____
205 uno::Reference< util::XCloneable > SAL_CALL RegressionEquation::createClone()
206 throw (uno::RuntimeException)
208 return uno::Reference< util::XCloneable >( new RegressionEquation( *this ));
211 // ____ OPropertySet ____
212 uno::Any RegressionEquation::GetDefaultValue( sal_Int32 nHandle ) const
213 throw(beans::UnknownPropertyException)
215 const tPropertyValueMap& rStaticDefaults = *StaticRegressionEquationDefaults::get();
216 tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
217 if( aFound == rStaticDefaults.end() )
218 return uno::Any();
219 return (*aFound).second;
222 ::cppu::IPropertyArrayHelper & SAL_CALL RegressionEquation::getInfoHelper()
224 return *StaticRegressionEquationInfoHelper::get();
227 // ____ XPropertySet ____
228 Reference< beans::XPropertySetInfo > SAL_CALL RegressionEquation::getPropertySetInfo()
229 throw (uno::RuntimeException)
231 return *StaticRegressionEquationInfo::get();
234 // ____ XModifyBroadcaster ____
235 void SAL_CALL RegressionEquation::addModifyListener( const uno::Reference< util::XModifyListener >& aListener )
236 throw (uno::RuntimeException)
240 uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
241 xBroadcaster->addModifyListener( aListener );
243 catch( const uno::Exception & ex )
245 ASSERT_EXCEPTION( ex );
249 void SAL_CALL RegressionEquation::removeModifyListener( const uno::Reference< util::XModifyListener >& aListener )
250 throw (uno::RuntimeException)
254 uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
255 xBroadcaster->removeModifyListener( aListener );
257 catch( const uno::Exception & ex )
259 ASSERT_EXCEPTION( ex );
263 // ____ XModifyListener ____
264 void SAL_CALL RegressionEquation::modified( const lang::EventObject& aEvent )
265 throw (uno::RuntimeException)
267 m_xModifyEventForwarder->modified( aEvent );
270 // ____ XEventListener (base of XModifyListener) ____
271 void SAL_CALL RegressionEquation::disposing( const lang::EventObject& /* Source */ )
272 throw (uno::RuntimeException)
274 // nothing
277 // ____ OPropertySet ____
278 void RegressionEquation::firePropertyChangeEvent()
280 fireModifyEvent();
283 void RegressionEquation::fireModifyEvent()
285 m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
288 // --------------------------------------------------------------------------------
290 // ____ XTitle ____
291 uno::Sequence< uno::Reference< chart2::XFormattedString > > SAL_CALL RegressionEquation::getText()
292 throw (uno::RuntimeException)
294 MutexGuard aGuard( GetMutex() );
295 return m_aStrings;
298 void SAL_CALL RegressionEquation::setText( const uno::Sequence< uno::Reference< chart2::XFormattedString > >& Strings )
299 throw (uno::RuntimeException)
301 MutexGuard aGuard( GetMutex() );
302 ModifyListenerHelper::removeListenerFromAllElements(
303 ContainerHelper::SequenceToVector( m_aStrings ), m_xModifyEventForwarder );
304 m_aStrings = Strings;
305 ModifyListenerHelper::addListenerToAllElements(
306 ContainerHelper::SequenceToVector( m_aStrings ), m_xModifyEventForwarder );
307 fireModifyEvent();
310 // ================================================================================
312 uno::Sequence< OUString > RegressionEquation::getSupportedServiceNames_Static()
314 const sal_Int32 nNumServices( 5 );
315 sal_Int32 nI = 0;
316 uno::Sequence< OUString > aServices( nNumServices );
317 aServices[ nI++ ] = lcl_aServiceName;
318 aServices[ nI++ ] = "com.sun.star.beans.PropertySet";
319 aServices[ nI++ ] = "com.sun.star.drawing.FillProperties";
320 aServices[ nI++ ] = "com.sun.star.drawing.LineProperties";
321 aServices[ nI++ ] = "com.sun.star.style.CharacterProperties";
322 OSL_ASSERT( nNumServices == nI );
323 return aServices;
326 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
327 APPHELPER_XSERVICEINFO_IMPL( RegressionEquation, lcl_aImplementationName );
329 using impl::RegressionEquation_Base;
331 IMPLEMENT_FORWARD_XINTERFACE2( RegressionEquation, RegressionEquation_Base, ::property::OPropertySet )
333 } // namespace chart
335 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */