1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "RegressionCurveModel.hxx"
22 #include "LinePropertiesHelper.hxx"
23 #include "RegressionCurveHelper.hxx"
24 #include "RegressionCalculationHelper.hxx"
25 #include "RegressionEquation.hxx"
26 #include "ContainerHelper.hxx"
27 #include "CloneHelper.hxx"
28 #include "PropertyHelper.hxx"
29 #include <com/sun/star/beans/PropertyAttribute.hpp>
30 #include <rtl/math.hxx>
31 #include <rtl/ustrbuf.hxx>
33 using namespace ::com::sun::star
;
35 using ::com::sun::star::beans::Property
;
36 using ::osl::MutexGuard
;
40 static const OUString
lcl_aImplementationName_MeanValue(
41 "com.sun.star.comp.chart2.MeanValueRegressionCurve" );
42 static const OUString
lcl_aImplementationName_Linear(
43 "com.sun.star.comp.chart2.LinearRegressionCurve" );
44 static const OUString
lcl_aImplementationName_Logarithmic(
45 "com.sun.star.comp.chart2.LogarithmicRegressionCurve" );
46 static const OUString
lcl_aImplementationName_Exponential(
47 "com.sun.star.comp.chart2.ExponentialRegressionCurve" );
48 static const OUString
lcl_aImplementationName_Potential(
49 "com.sun.star.comp.chart2.PotentialRegressionCurve" );
51 static const OUString
lcl_aServiceName(
52 "com.sun.star.chart2.RegressionCurve" );
54 struct StaticXXXDefaults_Initializer
56 ::chart::tPropertyValueMap
* operator()()
58 static ::chart::tPropertyValueMap aStaticDefaults
;
59 lcl_AddDefaultsToMap( aStaticDefaults
);
60 return &aStaticDefaults
;
63 void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap
& rOutMap
)
65 ::chart::LinePropertiesHelper::AddDefaultsToMap( rOutMap
);
69 struct StaticXXXDefaults
: public rtl::StaticAggregate
< ::chart::tPropertyValueMap
, StaticXXXDefaults_Initializer
>
73 struct StaticRegressionCurveInfoHelper_Initializer
75 ::cppu::OPropertyArrayHelper
* operator()()
77 static ::cppu::OPropertyArrayHelper
aPropHelper( lcl_GetPropertySequence() );
82 uno::Sequence
< Property
> lcl_GetPropertySequence()
84 ::std::vector
< ::com::sun::star::beans::Property
> aProperties
;
85 ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties
);
87 ::std::sort( aProperties
.begin(), aProperties
.end(),
88 ::chart::PropertyNameLess() );
90 return ::chart::ContainerHelper::ContainerToSequence( aProperties
);
94 struct StaticRegressionCurveInfoHelper
: public rtl::StaticAggregate
< ::cppu::OPropertyArrayHelper
, StaticRegressionCurveInfoHelper_Initializer
>
98 struct StaticRegressionCurveInfo_Initializer
100 uno::Reference
< beans::XPropertySetInfo
>* operator()()
102 static uno::Reference
< beans::XPropertySetInfo
> xPropertySetInfo(
103 ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticRegressionCurveInfoHelper::get() ) );
104 return &xPropertySetInfo
;
108 struct StaticRegressionCurveInfo
: public rtl::StaticAggregate
< uno::Reference
< beans::XPropertySetInfo
>, StaticRegressionCurveInfo_Initializer
>
112 } // anonymous namespace
117 RegressionCurveModel::RegressionCurveModel(
118 uno::Reference
< uno::XComponentContext
> const & xContext
,
119 tCurveType eCurveType
) :
120 ::property::OPropertySet( m_aMutex
),
121 m_xContext( xContext
),
122 m_eRegressionCurveType( eCurveType
),
123 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()),
124 m_xEquationProperties( new RegressionEquation( xContext
))
126 // set 0 line width (default) hard, so that it is always written to XML,
127 // because the old implementation uses different defaults
128 setFastPropertyValue_NoBroadcast(
129 LinePropertiesHelper::PROP_LINE_WIDTH
, uno::makeAny( sal_Int32( 0 )));
130 ModifyListenerHelper::addListener( m_xEquationProperties
, m_xModifyEventForwarder
);
133 RegressionCurveModel::RegressionCurveModel( const RegressionCurveModel
& rOther
) :
135 impl::RegressionCurveModel_Base(),
136 ::property::OPropertySet( rOther
, m_aMutex
),
137 m_xContext( rOther
.m_xContext
),
138 m_eRegressionCurveType( rOther
.m_eRegressionCurveType
),
139 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
141 m_xEquationProperties
.set( CloneHelper::CreateRefClone
< uno::Reference
< beans::XPropertySet
> >()( rOther
.m_xEquationProperties
));
142 ModifyListenerHelper::addListener( m_xEquationProperties
, m_xModifyEventForwarder
);
145 RegressionCurveModel::~RegressionCurveModel()
148 // ____ XRegressionCurve ____
149 uno::Reference
< chart2::XRegressionCurveCalculator
> SAL_CALL
150 RegressionCurveModel::getCalculator()
151 throw (uno::RuntimeException
)
153 return RegressionCurveHelper::createRegressionCurveCalculatorByServiceName( getServiceName());
156 uno::Reference
< beans::XPropertySet
> SAL_CALL
RegressionCurveModel::getEquationProperties()
157 throw (uno::RuntimeException
)
159 return m_xEquationProperties
;
162 void SAL_CALL
RegressionCurveModel::setEquationProperties( const uno::Reference
< beans::XPropertySet
>& xEquationProperties
)
163 throw (uno::RuntimeException
)
165 if( xEquationProperties
.is())
167 if( m_xEquationProperties
.is())
168 ModifyListenerHelper::removeListener( m_xEquationProperties
, m_xModifyEventForwarder
);
170 m_xEquationProperties
.set( xEquationProperties
);
171 ModifyListenerHelper::addListener( m_xEquationProperties
, m_xModifyEventForwarder
);
176 // ____ XServiceName ____
177 OUString SAL_CALL
RegressionCurveModel::getServiceName()
178 throw (uno::RuntimeException
)
180 switch( m_eRegressionCurveType
)
182 case CURVE_TYPE_MEAN_VALUE
:
183 return OUString("com.sun.star.chart2.MeanValueRegressionCurve");
184 case CURVE_TYPE_LINEAR
:
185 return OUString("com.sun.star.chart2.LinearRegressionCurve");
186 case CURVE_TYPE_LOGARITHM
:
187 return OUString("com.sun.star.chart2.LogarithmicRegressionCurve");
188 case CURVE_TYPE_EXPONENTIAL
:
189 return OUString("com.sun.star.chart2.ExponentialRegressionCurve");
190 case CURVE_TYPE_POWER
:
191 return OUString("com.sun.star.chart2.PotentialRegressionCurve");
197 // ____ XModifyBroadcaster ____
198 void SAL_CALL
RegressionCurveModel::addModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
199 throw (uno::RuntimeException
)
203 uno::Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
204 xBroadcaster
->addModifyListener( aListener
);
206 catch( const uno::Exception
& ex
)
208 ASSERT_EXCEPTION( ex
);
212 void SAL_CALL
RegressionCurveModel::removeModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
213 throw (uno::RuntimeException
)
217 uno::Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
218 xBroadcaster
->removeModifyListener( aListener
);
220 catch( const uno::Exception
& ex
)
222 ASSERT_EXCEPTION( ex
);
226 // ____ XModifyListener ____
227 void SAL_CALL
RegressionCurveModel::modified( const lang::EventObject
& aEvent
)
228 throw (uno::RuntimeException
)
230 m_xModifyEventForwarder
->modified( aEvent
);
233 // ____ XEventListener (base of XModifyListener) ____
234 void SAL_CALL
RegressionCurveModel::disposing( const lang::EventObject
& /* Source */ )
235 throw (uno::RuntimeException
)
240 // ____ OPropertySet ____
241 void RegressionCurveModel::firePropertyChangeEvent()
246 void RegressionCurveModel::fireModifyEvent()
248 m_xModifyEventForwarder
->modified( lang::EventObject( static_cast< uno::XWeak
* >( this )));
251 // ================================================================================
253 // ____ OPropertySet ____
254 uno::Any
RegressionCurveModel::GetDefaultValue( sal_Int32 nHandle
) const
255 throw(beans::UnknownPropertyException
)
257 const tPropertyValueMap
& rStaticDefaults
= *StaticXXXDefaults::get();
258 tPropertyValueMap::const_iterator
aFound( rStaticDefaults
.find( nHandle
) );
259 if( aFound
== rStaticDefaults
.end() )
261 return (*aFound
).second
;
264 ::cppu::IPropertyArrayHelper
& SAL_CALL
RegressionCurveModel::getInfoHelper()
266 return *StaticRegressionCurveInfoHelper::get();
269 // ____ XPropertySet ____
270 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
RegressionCurveModel::getPropertySetInfo()
271 throw (uno::RuntimeException
)
273 return *StaticRegressionCurveInfo::get();
276 // ================================================================================
278 // needed by MSC compiler
279 using impl::RegressionCurveModel_Base
;
281 IMPLEMENT_FORWARD_XINTERFACE2( RegressionCurveModel
, RegressionCurveModel_Base
, OPropertySet
)
282 IMPLEMENT_FORWARD_XTYPEPROVIDER2( RegressionCurveModel
, RegressionCurveModel_Base
, OPropertySet
)
288 // --------------------------------------------------------------------------------
290 MeanValueRegressionCurve::MeanValueRegressionCurve(
291 const uno::Reference
< uno::XComponentContext
> & xContext
)
292 : RegressionCurveModel( xContext
, RegressionCurveModel::CURVE_TYPE_MEAN_VALUE
)
294 MeanValueRegressionCurve::MeanValueRegressionCurve(
295 const MeanValueRegressionCurve
& rOther
) :
296 RegressionCurveModel( rOther
)
298 MeanValueRegressionCurve::~MeanValueRegressionCurve()
300 uno::Sequence
< OUString
> MeanValueRegressionCurve::getSupportedServiceNames_Static()
302 uno::Sequence
< OUString
> aServices( 2 );
303 aServices
[ 0 ] = lcl_aServiceName
;
304 aServices
[ 1 ] = "com.sun.star.chart2.MeanValueRegressionCurve";
307 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
308 APPHELPER_XSERVICEINFO_IMPL( MeanValueRegressionCurve
, lcl_aImplementationName_MeanValue
);
310 uno::Reference
< util::XCloneable
> SAL_CALL
MeanValueRegressionCurve::createClone()
311 throw (uno::RuntimeException
)
313 return uno::Reference
< util::XCloneable
>( new MeanValueRegressionCurve( *this ));
316 // --------------------------------------------------------------------------------
318 LinearRegressionCurve::LinearRegressionCurve(
319 const uno::Reference
< uno::XComponentContext
> & xContext
)
320 : RegressionCurveModel( xContext
, RegressionCurveModel::CURVE_TYPE_LINEAR
)
322 LinearRegressionCurve::LinearRegressionCurve(
323 const LinearRegressionCurve
& rOther
) :
324 RegressionCurveModel( rOther
)
326 LinearRegressionCurve::~LinearRegressionCurve()
328 uno::Sequence
< OUString
> LinearRegressionCurve::getSupportedServiceNames_Static()
330 uno::Sequence
< OUString
> aServices( 2 );
331 aServices
[ 0 ] = lcl_aServiceName
;
332 aServices
[ 1 ] = "com.sun.star.chart2.LinearRegressionCurve";
335 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
336 APPHELPER_XSERVICEINFO_IMPL( LinearRegressionCurve
, lcl_aImplementationName_Linear
);
338 uno::Reference
< util::XCloneable
> SAL_CALL
LinearRegressionCurve::createClone()
339 throw (uno::RuntimeException
)
341 return uno::Reference
< util::XCloneable
>( new LinearRegressionCurve( *this ));
344 // --------------------------------------------------------------------------------
346 LogarithmicRegressionCurve::LogarithmicRegressionCurve(
347 const uno::Reference
< uno::XComponentContext
> & xContext
)
348 : RegressionCurveModel( xContext
, RegressionCurveModel::CURVE_TYPE_LOGARITHM
)
350 LogarithmicRegressionCurve::LogarithmicRegressionCurve(
351 const LogarithmicRegressionCurve
& rOther
) :
352 RegressionCurveModel( rOther
)
354 LogarithmicRegressionCurve::~LogarithmicRegressionCurve()
356 uno::Sequence
< OUString
> LogarithmicRegressionCurve::getSupportedServiceNames_Static()
358 uno::Sequence
< OUString
> aServices( 2 );
359 aServices
[ 0 ] = lcl_aServiceName
;
360 aServices
[ 1 ] = "com.sun.star.chart2.LogarithmicRegressionCurve";
363 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
364 APPHELPER_XSERVICEINFO_IMPL( LogarithmicRegressionCurve
, lcl_aImplementationName_Logarithmic
);
366 uno::Reference
< util::XCloneable
> SAL_CALL
LogarithmicRegressionCurve::createClone()
367 throw (uno::RuntimeException
)
369 return uno::Reference
< util::XCloneable
>( new LogarithmicRegressionCurve( *this ));
372 // --------------------------------------------------------------------------------
374 ExponentialRegressionCurve::ExponentialRegressionCurve(
375 const uno::Reference
< uno::XComponentContext
> & xContext
)
376 : RegressionCurveModel( xContext
, RegressionCurveModel::CURVE_TYPE_EXPONENTIAL
)
378 ExponentialRegressionCurve::ExponentialRegressionCurve(
379 const ExponentialRegressionCurve
& rOther
) :
380 RegressionCurveModel( rOther
)
382 ExponentialRegressionCurve::~ExponentialRegressionCurve()
384 uno::Sequence
< OUString
> ExponentialRegressionCurve::getSupportedServiceNames_Static()
386 uno::Sequence
< OUString
> aServices( 2 );
387 aServices
[ 0 ] = lcl_aServiceName
;
388 aServices
[ 1 ] = "com.sun.star.chart2.ExponentialRegressionCurve";
391 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
392 APPHELPER_XSERVICEINFO_IMPL( ExponentialRegressionCurve
, lcl_aImplementationName_Exponential
);
394 uno::Reference
< util::XCloneable
> SAL_CALL
ExponentialRegressionCurve::createClone()
395 throw (uno::RuntimeException
)
397 return uno::Reference
< util::XCloneable
>( new ExponentialRegressionCurve( *this ));
400 // --------------------------------------------------------------------------------
402 PotentialRegressionCurve::PotentialRegressionCurve(
403 const uno::Reference
< uno::XComponentContext
> & xContext
)
404 : RegressionCurveModel( xContext
, RegressionCurveModel::CURVE_TYPE_POWER
)
406 PotentialRegressionCurve::PotentialRegressionCurve(
407 const PotentialRegressionCurve
& rOther
) :
408 RegressionCurveModel( rOther
)
410 PotentialRegressionCurve::~PotentialRegressionCurve()
412 uno::Sequence
< OUString
> PotentialRegressionCurve::getSupportedServiceNames_Static()
414 uno::Sequence
< OUString
> aServices( 2 );
415 aServices
[ 0 ] = lcl_aServiceName
;
416 aServices
[ 1 ] = "com.sun.star.chart2.PotentialRegressionCurve";
419 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
420 APPHELPER_XSERVICEINFO_IMPL( PotentialRegressionCurve
, lcl_aImplementationName_Potential
);
422 uno::Reference
< util::XCloneable
> SAL_CALL
PotentialRegressionCurve::createClone()
423 throw (uno::RuntimeException
)
425 return uno::Reference
< util::XCloneable
>( new PotentialRegressionCurve( *this ));
431 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */