bump product version to 5.0.4.1
[LibreOffice.git] / chart2 / source / tools / RegressionEquation.cxx
blob0ddc2c97bd7fb789c1aae79163b9976ae5f2bd06
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 .
20 #include "RegressionEquation.hxx"
21 #include "LinePropertiesHelper.hxx"
22 #include "FillProperties.hxx"
23 #include "UserDefinedProperties.hxx"
24 #include "CharacterProperties.hxx"
25 #include "PropertyHelper.hxx"
26 #include "macros.hxx"
27 #include "ContainerHelper.hxx"
28 #include <unonames.hxx>
29 #include <cppuhelper/supportsservice.hxx>
31 #include <com/sun/star/uno/Sequence.hxx>
32 #include <com/sun/star/drawing/FillStyle.hpp>
33 #include <com/sun/star/drawing/LineStyle.hpp>
34 #include <com/sun/star/beans/PropertyAttribute.hpp>
35 #include <com/sun/star/chart2/RelativePosition.hpp>
36 #include <com/sun/star/awt/Size.hpp>
38 #include <algorithm>
40 using namespace ::com::sun::star;
42 using ::com::sun::star::uno::Reference;
43 using ::com::sun::star::beans::Property;
44 using ::osl::MutexGuard;
46 namespace
49 static const char lcl_aImplementationName[] = "com.sun.star.comp.chart2.RegressionEquation";
50 static const char lcl_aServiceName[] = "com.sun.star.chart2.RegressionEquation";
52 enum
54 PROP_EQUATION_SHOW,
55 PROP_EQUATION_SHOW_CORRELATION_COEFF,
56 PROP_EQUATION_REF_PAGE_SIZE,
57 PROP_EQUATION_REL_POS,
58 PROP_EQUATION_NUMBER_FORMAT
61 void lcl_AddPropertiesToVector(
62 ::std::vector< Property > & rOutProperties )
64 rOutProperties.push_back(
65 Property( "ShowEquation",
66 PROP_EQUATION_SHOW,
67 cppu::UnoType<bool>::get(),
68 beans::PropertyAttribute::BOUND
69 | beans::PropertyAttribute::MAYBEDEFAULT ));
71 rOutProperties.push_back(
72 Property( "ShowCorrelationCoefficient",
73 PROP_EQUATION_SHOW_CORRELATION_COEFF,
74 cppu::UnoType<bool>::get(),
75 beans::PropertyAttribute::BOUND
76 | beans::PropertyAttribute::MAYBEDEFAULT ));
78 rOutProperties.push_back(
79 Property( "ReferencePageSize",
80 PROP_EQUATION_REF_PAGE_SIZE,
81 cppu::UnoType<awt::Size>::get(),
82 beans::PropertyAttribute::BOUND
83 | beans::PropertyAttribute::MAYBEVOID ));
85 rOutProperties.push_back(
86 Property( "RelativePosition",
87 PROP_EQUATION_REL_POS,
88 cppu::UnoType<chart2::RelativePosition>::get(),
89 beans::PropertyAttribute::BOUND
90 | beans::PropertyAttribute::MAYBEVOID ));
92 rOutProperties.push_back(
93 Property( CHART_UNONAME_NUMFMT,
94 PROP_EQUATION_NUMBER_FORMAT,
95 cppu::UnoType<sal_Int32>::get(),
96 beans::PropertyAttribute::BOUND
97 | beans::PropertyAttribute::MAYBEVOID ));
100 struct StaticRegressionEquationDefaults_Initializer
102 ::chart::tPropertyValueMap* operator()()
104 static ::chart::tPropertyValueMap aStaticDefaults;
105 lcl_AddDefaultsToMap( aStaticDefaults );
106 return &aStaticDefaults;
108 private:
109 static void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
111 ::chart::LinePropertiesHelper::AddDefaultsToMap( rOutMap );
112 ::chart::FillProperties::AddDefaultsToMap( rOutMap );
113 ::chart::CharacterProperties::AddDefaultsToMap( rOutMap );
115 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_EQUATION_SHOW, false );
116 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_EQUATION_SHOW_CORRELATION_COEFF, false );
117 //::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_EQUATION_SEPARATOR, OUString( '\n' ));
119 // override other defaults
120 ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::FillProperties::PROP_FILL_STYLE, drawing::FillStyle_NONE );
121 ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::LinePropertiesHelper::PROP_LINE_STYLE, drawing::LineStyle_NONE );
123 float fDefaultCharHeight = 10.0;
124 ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_CHAR_HEIGHT, fDefaultCharHeight );
125 ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_ASIAN_CHAR_HEIGHT, fDefaultCharHeight );
126 ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_COMPLEX_CHAR_HEIGHT, fDefaultCharHeight );
130 struct StaticRegressionEquationDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticRegressionEquationDefaults_Initializer >
134 struct StaticRegressionEquationInfoHelper_Initializer
136 ::cppu::OPropertyArrayHelper* operator()()
138 static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
139 return &aPropHelper;
142 private:
143 static uno::Sequence< Property > lcl_GetPropertySequence()
145 ::std::vector< ::com::sun::star::beans::Property > aProperties;
146 lcl_AddPropertiesToVector( aProperties );
147 ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties );
148 ::chart::FillProperties::AddPropertiesToVector( aProperties );
149 ::chart::CharacterProperties::AddPropertiesToVector( aProperties );
150 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
152 ::std::sort( aProperties.begin(), aProperties.end(),
153 ::chart::PropertyNameLess() );
155 return ::chart::ContainerHelper::ContainerToSequence( aProperties );
160 struct StaticRegressionEquationInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticRegressionEquationInfoHelper_Initializer >
164 struct StaticRegressionEquationInfo_Initializer
166 uno::Reference< beans::XPropertySetInfo >* operator()()
168 static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
169 ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticRegressionEquationInfoHelper::get() ) );
170 return &xPropertySetInfo;
174 struct StaticRegressionEquationInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticRegressionEquationInfo_Initializer >
178 } // anonymous namespace
180 namespace chart
183 RegressionEquation::RegressionEquation( const Reference< uno::XComponentContext > & xContext ) :
184 ::property::OPropertySet( m_aMutex ),
185 m_xModifyEventForwarder( new ModifyListenerHelper::ModifyEventForwarder()),
186 m_xContext( xContext )
189 RegressionEquation::RegressionEquation( const RegressionEquation & rOther ) :
190 MutexContainer(),
191 impl::RegressionEquation_Base(),
192 ::property::OPropertySet( rOther, m_aMutex ),
193 m_xModifyEventForwarder( new ModifyListenerHelper::ModifyEventForwarder()),
194 m_xContext( NULL )
197 RegressionEquation::~RegressionEquation()
200 // ____ XCloneable ____
201 uno::Reference< util::XCloneable > SAL_CALL RegressionEquation::createClone()
202 throw (uno::RuntimeException, std::exception)
204 return uno::Reference< util::XCloneable >( new RegressionEquation( *this ));
207 // ____ OPropertySet ____
208 uno::Any RegressionEquation::GetDefaultValue( sal_Int32 nHandle ) const
209 throw (beans::UnknownPropertyException, uno::RuntimeException)
211 const tPropertyValueMap& rStaticDefaults = *StaticRegressionEquationDefaults::get();
212 tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
213 if( aFound == rStaticDefaults.end() )
214 return uno::Any();
215 return (*aFound).second;
218 ::cppu::IPropertyArrayHelper & SAL_CALL RegressionEquation::getInfoHelper()
220 return *StaticRegressionEquationInfoHelper::get();
223 // ____ XPropertySet ____
224 Reference< beans::XPropertySetInfo > SAL_CALL RegressionEquation::getPropertySetInfo()
225 throw (uno::RuntimeException, std::exception)
227 return *StaticRegressionEquationInfo::get();
230 // ____ XModifyBroadcaster ____
231 void SAL_CALL RegressionEquation::addModifyListener( const uno::Reference< util::XModifyListener >& aListener )
232 throw (uno::RuntimeException, std::exception)
236 uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
237 xBroadcaster->addModifyListener( aListener );
239 catch( const uno::Exception & ex )
241 ASSERT_EXCEPTION( ex );
245 void SAL_CALL RegressionEquation::removeModifyListener( const uno::Reference< util::XModifyListener >& aListener )
246 throw (uno::RuntimeException, std::exception)
250 uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
251 xBroadcaster->removeModifyListener( aListener );
253 catch( const uno::Exception & ex )
255 ASSERT_EXCEPTION( ex );
259 // ____ XModifyListener ____
260 void SAL_CALL RegressionEquation::modified( const lang::EventObject& aEvent )
261 throw (uno::RuntimeException, std::exception)
263 m_xModifyEventForwarder->modified( aEvent );
266 // ____ XEventListener (base of XModifyListener) ____
267 void SAL_CALL RegressionEquation::disposing( const lang::EventObject& /* Source */ )
268 throw (uno::RuntimeException, std::exception)
270 // nothing
273 // ____ OPropertySet ____
274 void RegressionEquation::firePropertyChangeEvent()
276 fireModifyEvent();
279 void RegressionEquation::fireModifyEvent()
281 m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
284 // ____ XTitle ____
285 uno::Sequence< uno::Reference< chart2::XFormattedString > > SAL_CALL RegressionEquation::getText()
286 throw (uno::RuntimeException, std::exception)
288 MutexGuard aGuard( GetMutex() );
289 return m_aStrings;
292 void SAL_CALL RegressionEquation::setText( const uno::Sequence< uno::Reference< chart2::XFormattedString > >& Strings )
293 throw (uno::RuntimeException, std::exception)
295 MutexGuard aGuard( GetMutex() );
296 ModifyListenerHelper::removeListenerFromAllElements(
297 ContainerHelper::SequenceToVector( m_aStrings ), m_xModifyEventForwarder );
298 m_aStrings = Strings;
299 ModifyListenerHelper::addListenerToAllElements(
300 ContainerHelper::SequenceToVector( m_aStrings ), m_xModifyEventForwarder );
301 fireModifyEvent();
304 uno::Sequence< OUString > RegressionEquation::getSupportedServiceNames_Static()
306 const sal_Int32 nNumServices( 5 );
307 sal_Int32 nI = 0;
308 uno::Sequence< OUString > aServices( nNumServices );
309 aServices[ nI++ ] = lcl_aServiceName;
310 aServices[ nI++ ] = "com.sun.star.beans.PropertySet";
311 aServices[ nI++ ] = "com.sun.star.drawing.FillProperties";
312 aServices[ nI++ ] = "com.sun.star.drawing.LineProperties";
313 aServices[ nI++ ] = "com.sun.star.style.CharacterProperties";
314 OSL_ASSERT( nNumServices == nI );
315 return aServices;
318 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
319 OUString SAL_CALL RegressionEquation::getImplementationName()
320 throw( css::uno::RuntimeException, std::exception )
322 return getImplementationName_Static();
325 OUString RegressionEquation::getImplementationName_Static()
327 return OUString(lcl_aImplementationName);
330 sal_Bool SAL_CALL RegressionEquation::supportsService( const OUString& rServiceName )
331 throw( css::uno::RuntimeException, std::exception )
333 return cppu::supportsService(this, rServiceName);
336 css::uno::Sequence< OUString > SAL_CALL RegressionEquation::getSupportedServiceNames()
337 throw( css::uno::RuntimeException, std::exception )
339 return getSupportedServiceNames_Static();
342 using impl::RegressionEquation_Base;
344 IMPLEMENT_FORWARD_XINTERFACE2( RegressionEquation, RegressionEquation_Base, ::property::OPropertySet )
346 } // namespace chart
348 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
349 com_sun_star_comp_chart2_RegressionEquation_get_implementation(css::uno::XComponentContext *context,
350 css::uno::Sequence<css::uno::Any> const &)
352 return cppu::acquire(new ::chart::RegressionEquation(context));
355 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */