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"
21 #include <LinePropertiesHelper.hxx>
22 #include <RegressionCurveHelper.hxx>
23 #include "RegressionEquation.hxx"
24 #include <CloneHelper.hxx>
25 #include <PropertyHelper.hxx>
26 #include <ModifyListenerHelper.hxx>
27 #include <cppuhelper/supportsservice.hxx>
28 #include <com/sun/star/beans/PropertyAttribute.hpp>
29 #include <tools/diagnose_ex.h>
31 namespace com::sun::star::uno
{ class XComponentContext
; }
33 using namespace ::com::sun::star
;
35 using ::com::sun::star::beans::Property
;
43 PROPERTY_EXTRAPOLATE_FORWARD
,
44 PROPERTY_EXTRAPOLATE_BACKWARD
,
45 PROPERTY_FORCE_INTERCEPT
,
46 PROPERTY_INTERCEPT_VALUE
,
50 void lcl_AddPropertiesToVector(
51 std::vector
< Property
> & rOutProperties
)
53 rOutProperties
.emplace_back( "PolynomialDegree",
55 cppu::UnoType
<sal_Int32
>::get(),
56 beans::PropertyAttribute::BOUND
|
57 beans::PropertyAttribute::MAYBEDEFAULT
);
59 rOutProperties
.emplace_back( "MovingAveragePeriod",
61 cppu::UnoType
<sal_Int32
>::get(),
62 beans::PropertyAttribute::BOUND
|
63 beans::PropertyAttribute::MAYBEDEFAULT
);
65 rOutProperties
.emplace_back( "ExtrapolateForward",
66 PROPERTY_EXTRAPOLATE_FORWARD
,
67 cppu::UnoType
<double>::get(),
68 beans::PropertyAttribute::BOUND
|
69 beans::PropertyAttribute::MAYBEDEFAULT
);
71 rOutProperties
.emplace_back( "ExtrapolateBackward",
72 PROPERTY_EXTRAPOLATE_BACKWARD
,
73 cppu::UnoType
<double>::get(),
74 beans::PropertyAttribute::BOUND
|
75 beans::PropertyAttribute::MAYBEDEFAULT
);
77 rOutProperties
.emplace_back( "ForceIntercept",
78 PROPERTY_FORCE_INTERCEPT
,
79 cppu::UnoType
<bool>::get(),
80 beans::PropertyAttribute::BOUND
81 | beans::PropertyAttribute::MAYBEDEFAULT
);
83 rOutProperties
.emplace_back( "InterceptValue",
84 PROPERTY_INTERCEPT_VALUE
,
85 cppu::UnoType
<double>::get(),
86 beans::PropertyAttribute::BOUND
|
87 beans::PropertyAttribute::MAYBEDEFAULT
);
89 rOutProperties
.emplace_back( "CurveName",
91 cppu::UnoType
<OUString
>::get(),
92 beans::PropertyAttribute::BOUND
);
95 struct StaticXXXDefaults_Initializer
97 ::chart::tPropertyValueMap
* operator()()
99 static ::chart::tPropertyValueMap aStaticDefaults
;
100 ::chart::LinePropertiesHelper::AddDefaultsToMap( aStaticDefaults
);
101 return &aStaticDefaults
;
105 struct StaticXXXDefaults
: public rtl::StaticAggregate
< ::chart::tPropertyValueMap
, StaticXXXDefaults_Initializer
>
109 struct StaticRegressionCurveInfoHelper_Initializer
111 ::cppu::OPropertyArrayHelper
* operator()()
113 static ::cppu::OPropertyArrayHelper
aPropHelper( lcl_GetPropertySequence() );
118 static uno::Sequence
< Property
> lcl_GetPropertySequence()
120 std::vector
< css::beans::Property
> aProperties
;
121 lcl_AddPropertiesToVector( aProperties
);
122 ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties
);
124 std::sort( aProperties
.begin(), aProperties
.end(),
125 ::chart::PropertyNameLess() );
127 return comphelper::containerToSequence( aProperties
);
131 struct StaticRegressionCurveInfoHelper
: public rtl::StaticAggregate
< ::cppu::OPropertyArrayHelper
, StaticRegressionCurveInfoHelper_Initializer
>
135 struct StaticRegressionCurveInfo_Initializer
137 uno::Reference
< beans::XPropertySetInfo
>* operator()()
139 static uno::Reference
< beans::XPropertySetInfo
> xPropertySetInfo(
140 ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticRegressionCurveInfoHelper::get() ) );
141 return &xPropertySetInfo
;
145 struct StaticRegressionCurveInfo
: public rtl::StaticAggregate
< uno::Reference
< beans::XPropertySetInfo
>, StaticRegressionCurveInfo_Initializer
>
149 } // anonymous namespace
154 RegressionCurveModel::RegressionCurveModel( tCurveType eCurveType
) :
155 ::property::OPropertySet( m_aMutex
),
156 m_eRegressionCurveType( eCurveType
),
157 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()),
158 m_xEquationProperties( new RegressionEquation
)
160 // set 0 line width (default) hard, so that it is always written to XML,
161 // because the old implementation uses different defaults
162 setFastPropertyValue_NoBroadcast(
163 LinePropertiesHelper::PROP_LINE_WIDTH
, uno::Any( sal_Int32( 0 )));
164 ModifyListenerHelper::addListener( m_xEquationProperties
, m_xModifyEventForwarder
);
167 RegressionCurveModel::RegressionCurveModel( const RegressionCurveModel
& rOther
) :
168 impl::RegressionCurveModel_Base(rOther
),
169 ::property::OPropertySet( rOther
, m_aMutex
),
170 m_eRegressionCurveType( rOther
.m_eRegressionCurveType
),
171 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
173 m_xEquationProperties
.set( CloneHelper::CreateRefClone
< beans::XPropertySet
>()( rOther
.m_xEquationProperties
));
174 ModifyListenerHelper::addListener( m_xEquationProperties
, m_xModifyEventForwarder
);
177 RegressionCurveModel::~RegressionCurveModel()
180 // ____ XRegressionCurve ____
181 uno::Reference
< chart2::XRegressionCurveCalculator
> SAL_CALL
182 RegressionCurveModel::getCalculator()
184 return RegressionCurveHelper::createRegressionCurveCalculatorByServiceName( getServiceName());
187 uno::Reference
< beans::XPropertySet
> SAL_CALL
RegressionCurveModel::getEquationProperties()
189 return m_xEquationProperties
;
192 void SAL_CALL
RegressionCurveModel::setEquationProperties( const uno::Reference
< beans::XPropertySet
>& xEquationProperties
)
194 if( xEquationProperties
.is())
196 if( m_xEquationProperties
.is())
197 ModifyListenerHelper::removeListener( m_xEquationProperties
, m_xModifyEventForwarder
);
199 m_xEquationProperties
.set( xEquationProperties
);
200 ModifyListenerHelper::addListener( m_xEquationProperties
, m_xModifyEventForwarder
);
205 // ____ XServiceName ____
206 OUString SAL_CALL
RegressionCurveModel::getServiceName()
208 switch( m_eRegressionCurveType
)
210 case CURVE_TYPE_MEAN_VALUE
:
211 return "com.sun.star.chart2.MeanValueRegressionCurve";
212 case CURVE_TYPE_LINEAR
:
213 return "com.sun.star.chart2.LinearRegressionCurve";
214 case CURVE_TYPE_LOGARITHM
:
215 return "com.sun.star.chart2.LogarithmicRegressionCurve";
216 case CURVE_TYPE_EXPONENTIAL
:
217 return "com.sun.star.chart2.ExponentialRegressionCurve";
218 case CURVE_TYPE_POWER
:
219 return "com.sun.star.chart2.PotentialRegressionCurve";
220 case CURVE_TYPE_POLYNOMIAL
:
221 return "com.sun.star.chart2.PolynomialRegressionCurve";
222 case CURVE_TYPE_MOVING_AVERAGE
:
223 return "com.sun.star.chart2.MovingAverageRegressionCurve";
229 // ____ XModifyBroadcaster ____
230 void SAL_CALL
RegressionCurveModel::addModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
234 uno::Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
235 xBroadcaster
->addModifyListener( aListener
);
237 catch( const uno::Exception
& )
239 DBG_UNHANDLED_EXCEPTION("chart2");
243 void SAL_CALL
RegressionCurveModel::removeModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
247 uno::Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
248 xBroadcaster
->removeModifyListener( aListener
);
250 catch( const uno::Exception
& )
252 DBG_UNHANDLED_EXCEPTION("chart2");
256 // ____ XModifyListener ____
257 void SAL_CALL
RegressionCurveModel::modified( const lang::EventObject
& aEvent
)
259 m_xModifyEventForwarder
->modified( aEvent
);
262 // ____ XEventListener (base of XModifyListener) ____
263 void SAL_CALL
RegressionCurveModel::disposing( const lang::EventObject
& /* Source */ )
268 // ____ OPropertySet ____
269 void RegressionCurveModel::firePropertyChangeEvent()
274 void RegressionCurveModel::fireModifyEvent()
276 m_xModifyEventForwarder
->modified( lang::EventObject( static_cast< uno::XWeak
* >( this )));
279 // ____ OPropertySet ____
280 uno::Any
RegressionCurveModel::GetDefaultValue( sal_Int32 nHandle
) const
282 const tPropertyValueMap
& rStaticDefaults
= *StaticXXXDefaults::get();
283 tPropertyValueMap::const_iterator
aFound( rStaticDefaults
.find( nHandle
) );
284 if( aFound
== rStaticDefaults
.end() )
286 return (*aFound
).second
;
289 ::cppu::IPropertyArrayHelper
& SAL_CALL
RegressionCurveModel::getInfoHelper()
291 return *StaticRegressionCurveInfoHelper::get();
294 // ____ XPropertySet ____
295 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
RegressionCurveModel::getPropertySetInfo()
297 return *StaticRegressionCurveInfo::get();
300 // needed by MSC compiler
301 using impl::RegressionCurveModel_Base
;
303 IMPLEMENT_FORWARD_XINTERFACE2( RegressionCurveModel
, RegressionCurveModel_Base
, OPropertySet
)
304 IMPLEMENT_FORWARD_XTYPEPROVIDER2( RegressionCurveModel
, RegressionCurveModel_Base
, OPropertySet
)
308 MeanValueRegressionCurve::MeanValueRegressionCurve()
309 : RegressionCurveModel( RegressionCurveModel::CURVE_TYPE_MEAN_VALUE
)
311 MeanValueRegressionCurve::MeanValueRegressionCurve(
312 const MeanValueRegressionCurve
& rOther
) :
313 RegressionCurveModel( rOther
)
315 MeanValueRegressionCurve::~MeanValueRegressionCurve()
318 OUString SAL_CALL
MeanValueRegressionCurve::getImplementationName()
320 return "com.sun.star.comp.chart2.MeanValueRegressionCurve";
323 sal_Bool SAL_CALL
MeanValueRegressionCurve::supportsService( const OUString
& rServiceName
)
325 return cppu::supportsService(this, rServiceName
);
328 css::uno::Sequence
< OUString
> SAL_CALL
MeanValueRegressionCurve::getSupportedServiceNames()
330 return { "com.sun.star.chart2.RegressionCurve", "com.sun.star.chart2.MeanValueRegressionCurve" };
333 uno::Reference
< util::XCloneable
> SAL_CALL
MeanValueRegressionCurve::createClone()
335 return uno::Reference
< util::XCloneable
>( new MeanValueRegressionCurve( *this ));
338 LinearRegressionCurve::LinearRegressionCurve()
339 : RegressionCurveModel( RegressionCurveModel::CURVE_TYPE_LINEAR
)
341 LinearRegressionCurve::LinearRegressionCurve(
342 const LinearRegressionCurve
& rOther
) :
343 RegressionCurveModel( rOther
)
345 LinearRegressionCurve::~LinearRegressionCurve()
348 OUString SAL_CALL
LinearRegressionCurve::getImplementationName()
350 return "com.sun.star.comp.chart2.LinearRegressionCurve";
353 sal_Bool SAL_CALL
LinearRegressionCurve::supportsService( const OUString
& rServiceName
)
355 return cppu::supportsService(this, rServiceName
);
358 css::uno::Sequence
< OUString
> SAL_CALL
LinearRegressionCurve::getSupportedServiceNames()
360 return { "com.sun.star.chart2.RegressionCurve", "com.sun.star.chart2.LinearRegressionCurve" };
363 uno::Reference
< util::XCloneable
> SAL_CALL
LinearRegressionCurve::createClone()
365 return uno::Reference
< util::XCloneable
>( new LinearRegressionCurve( *this ));
368 LogarithmicRegressionCurve::LogarithmicRegressionCurve()
369 : RegressionCurveModel( RegressionCurveModel::CURVE_TYPE_LOGARITHM
)
371 LogarithmicRegressionCurve::LogarithmicRegressionCurve(
372 const LogarithmicRegressionCurve
& rOther
) :
373 RegressionCurveModel( rOther
)
375 LogarithmicRegressionCurve::~LogarithmicRegressionCurve()
378 OUString SAL_CALL
LogarithmicRegressionCurve::getImplementationName()
380 return "com.sun.star.comp.chart2.LogarithmicRegressionCurve";
383 sal_Bool SAL_CALL
LogarithmicRegressionCurve::supportsService( const OUString
& rServiceName
)
385 return cppu::supportsService(this, rServiceName
);
388 css::uno::Sequence
< OUString
> SAL_CALL
LogarithmicRegressionCurve::getSupportedServiceNames()
390 return { "com.sun.star.chart2.RegressionCurve", "com.sun.star.chart2.LogarithmicRegressionCurve" };
393 uno::Reference
< util::XCloneable
> SAL_CALL
LogarithmicRegressionCurve::createClone()
395 return uno::Reference
< util::XCloneable
>( new LogarithmicRegressionCurve( *this ));
398 ExponentialRegressionCurve::ExponentialRegressionCurve()
399 : RegressionCurveModel( RegressionCurveModel::CURVE_TYPE_EXPONENTIAL
)
401 ExponentialRegressionCurve::ExponentialRegressionCurve(
402 const ExponentialRegressionCurve
& rOther
) :
403 RegressionCurveModel( rOther
)
405 ExponentialRegressionCurve::~ExponentialRegressionCurve()
408 OUString SAL_CALL
ExponentialRegressionCurve::getImplementationName()
410 return "com.sun.star.comp.chart2.ExponentialRegressionCurve";
413 sal_Bool SAL_CALL
ExponentialRegressionCurve::supportsService( const OUString
& rServiceName
)
415 return cppu::supportsService(this, rServiceName
);
418 css::uno::Sequence
< OUString
> SAL_CALL
ExponentialRegressionCurve::getSupportedServiceNames()
420 return { "com.sun.star.chart2.RegressionCurve", "com.sun.star.chart2.ExponentialRegressionCurve" };
423 uno::Reference
< util::XCloneable
> SAL_CALL
ExponentialRegressionCurve::createClone()
425 return uno::Reference
< util::XCloneable
>( new ExponentialRegressionCurve( *this ));
428 PotentialRegressionCurve::PotentialRegressionCurve()
429 : RegressionCurveModel( RegressionCurveModel::CURVE_TYPE_POWER
)
431 PotentialRegressionCurve::PotentialRegressionCurve(
432 const PotentialRegressionCurve
& rOther
) :
433 RegressionCurveModel( rOther
)
435 PotentialRegressionCurve::~PotentialRegressionCurve()
438 OUString SAL_CALL
PotentialRegressionCurve::getImplementationName()
440 return "com.sun.star.comp.chart2.PotentialRegressionCurve";
443 sal_Bool SAL_CALL
PotentialRegressionCurve::supportsService( const OUString
& rServiceName
)
445 return cppu::supportsService(this, rServiceName
);
448 css::uno::Sequence
< OUString
> SAL_CALL
PotentialRegressionCurve::getSupportedServiceNames()
450 return { "com.sun.star.chart2.RegressionCurve", "com.sun.star.chart2.PotentialRegressionCurve" };
453 uno::Reference
< util::XCloneable
> SAL_CALL
PotentialRegressionCurve::createClone()
455 return uno::Reference
< util::XCloneable
>( new PotentialRegressionCurve( *this ));
458 PolynomialRegressionCurve::PolynomialRegressionCurve()
459 : RegressionCurveModel( RegressionCurveModel::CURVE_TYPE_POLYNOMIAL
)
461 PolynomialRegressionCurve::PolynomialRegressionCurve(
462 const PolynomialRegressionCurve
& rOther
) :
463 RegressionCurveModel( rOther
)
465 PolynomialRegressionCurve::~PolynomialRegressionCurve()
468 OUString SAL_CALL
PolynomialRegressionCurve::getImplementationName()
470 return "com.sun.star.comp.chart2.PolynomialRegressionCurve";
473 sal_Bool SAL_CALL
PolynomialRegressionCurve::supportsService( const OUString
& rServiceName
)
475 return cppu::supportsService(this, rServiceName
);
478 css::uno::Sequence
< OUString
> SAL_CALL
PolynomialRegressionCurve::getSupportedServiceNames()
480 return { "com.sun.star.chart2.RegressionCurve", "com.sun.star.chart2.PolynomialRegressionCurve" };
483 uno::Reference
< util::XCloneable
> SAL_CALL
PolynomialRegressionCurve::createClone()
485 return uno::Reference
< util::XCloneable
>( new PolynomialRegressionCurve( *this ));
488 MovingAverageRegressionCurve::MovingAverageRegressionCurve()
489 : RegressionCurveModel( RegressionCurveModel::CURVE_TYPE_MOVING_AVERAGE
)
491 MovingAverageRegressionCurve::MovingAverageRegressionCurve(
492 const MovingAverageRegressionCurve
& rOther
) :
493 RegressionCurveModel( rOther
)
495 MovingAverageRegressionCurve::~MovingAverageRegressionCurve()
498 OUString SAL_CALL
MovingAverageRegressionCurve::getImplementationName()
500 return "com.sun.star.comp.chart2.MovingAverageRegressionCurve";
503 sal_Bool SAL_CALL
MovingAverageRegressionCurve::supportsService( const OUString
& rServiceName
)
505 return cppu::supportsService(this, rServiceName
);
508 css::uno::Sequence
< OUString
> SAL_CALL
MovingAverageRegressionCurve::getSupportedServiceNames()
510 return { "com.sun.star.chart2.RegressionCurve", "com.sun.star.chart2.MovingAverageRegressionCurve" };
513 uno::Reference
< util::XCloneable
> SAL_CALL
MovingAverageRegressionCurve::createClone()
515 return uno::Reference
< util::XCloneable
>( new MovingAverageRegressionCurve( *this ));
520 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
521 com_sun_star_comp_chart2_ExponentialRegressionCurve_get_implementation(css::uno::XComponentContext
*,
522 css::uno::Sequence
<css::uno::Any
> const &)
524 return cppu::acquire(new ::chart::ExponentialRegressionCurve
);
527 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
528 com_sun_star_comp_chart2_LinearRegressionCurve_get_implementation(css::uno::XComponentContext
*,
529 css::uno::Sequence
<css::uno::Any
> const &)
531 return cppu::acquire(new ::chart::LinearRegressionCurve
);
534 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
535 com_sun_star_comp_chart2_LogarithmicRegressionCurve_get_implementation(css::uno::XComponentContext
*,
536 css::uno::Sequence
<css::uno::Any
> const &)
538 return cppu::acquire(new ::chart::LogarithmicRegressionCurve
);
541 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
542 com_sun_star_comp_chart2_MeanValueRegressionCurve_get_implementation(css::uno::XComponentContext
*,
543 css::uno::Sequence
<css::uno::Any
> const &)
545 return cppu::acquire(new ::chart::MeanValueRegressionCurve
);
548 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
549 com_sun_star_comp_chart2_PotentialRegressionCurve_get_implementation(css::uno::XComponentContext
*,
550 css::uno::Sequence
<css::uno::Any
> const &)
552 return cppu::acquire(new ::chart::PotentialRegressionCurve
);
555 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
556 com_sun_star_comp_chart2_PolynomialRegressionCurve_get_implementation(css::uno::XComponentContext
*,
557 css::uno::Sequence
<css::uno::Any
> const &)
559 return cppu::acquire(new ::chart::PolynomialRegressionCurve
);
562 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
563 com_sun_star_comp_chart2_MovingAverageRegressionCurve_get_implementation(css::uno::XComponentContext
*,
564 css::uno::Sequence
<css::uno::Any
> const &)
566 return cppu::acquire(new ::chart::MovingAverageRegressionCurve
);
570 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */