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
{ namespace sun
{ namespace star
{ namespace uno
{ class XComponentContext
; } } } }
33 using namespace ::com::sun::star
;
35 using ::com::sun::star::beans::Property
;
39 static const OUString
lcl_aImplementationName_MeanValue(
40 "com.sun.star.comp.chart2.MeanValueRegressionCurve" );
41 static const OUString
lcl_aImplementationName_Linear(
42 "com.sun.star.comp.chart2.LinearRegressionCurve" );
43 static const OUString
lcl_aImplementationName_Logarithmic(
44 "com.sun.star.comp.chart2.LogarithmicRegressionCurve" );
45 static const OUString
lcl_aImplementationName_Exponential(
46 "com.sun.star.comp.chart2.ExponentialRegressionCurve" );
47 static const OUString
lcl_aImplementationName_Potential(
48 "com.sun.star.comp.chart2.PotentialRegressionCurve" );
49 static const OUString
lcl_aImplementationName_Polynomial(
50 "com.sun.star.comp.chart2.PolynomialRegressionCurve" );
51 static const OUString
lcl_aImplementationName_MovingAverage(
52 "com.sun.star.comp.chart2.MovingAverageRegressionCurve" );
54 static const OUString
lcl_aServiceName(
55 "com.sun.star.chart2.RegressionCurve" );
61 PROPERTY_EXTRAPOLATE_FORWARD
,
62 PROPERTY_EXTRAPOLATE_BACKWARD
,
63 PROPERTY_FORCE_INTERCEPT
,
64 PROPERTY_INTERCEPT_VALUE
,
68 void lcl_AddPropertiesToVector(
69 std::vector
< Property
> & rOutProperties
)
71 rOutProperties
.emplace_back( "PolynomialDegree",
73 cppu::UnoType
<sal_Int32
>::get(),
74 beans::PropertyAttribute::BOUND
|
75 beans::PropertyAttribute::MAYBEDEFAULT
);
77 rOutProperties
.emplace_back( "MovingAveragePeriod",
79 cppu::UnoType
<sal_Int32
>::get(),
80 beans::PropertyAttribute::BOUND
|
81 beans::PropertyAttribute::MAYBEDEFAULT
);
83 rOutProperties
.emplace_back( "ExtrapolateForward",
84 PROPERTY_EXTRAPOLATE_FORWARD
,
85 cppu::UnoType
<double>::get(),
86 beans::PropertyAttribute::BOUND
|
87 beans::PropertyAttribute::MAYBEDEFAULT
);
89 rOutProperties
.emplace_back( "ExtrapolateBackward",
90 PROPERTY_EXTRAPOLATE_BACKWARD
,
91 cppu::UnoType
<double>::get(),
92 beans::PropertyAttribute::BOUND
|
93 beans::PropertyAttribute::MAYBEDEFAULT
);
95 rOutProperties
.emplace_back( "ForceIntercept",
96 PROPERTY_FORCE_INTERCEPT
,
97 cppu::UnoType
<bool>::get(),
98 beans::PropertyAttribute::BOUND
99 | beans::PropertyAttribute::MAYBEDEFAULT
);
101 rOutProperties
.emplace_back( "InterceptValue",
102 PROPERTY_INTERCEPT_VALUE
,
103 cppu::UnoType
<double>::get(),
104 beans::PropertyAttribute::BOUND
|
105 beans::PropertyAttribute::MAYBEDEFAULT
);
107 rOutProperties
.emplace_back( "CurveName",
109 cppu::UnoType
<OUString
>::get(),
110 beans::PropertyAttribute::BOUND
);
113 struct StaticXXXDefaults_Initializer
115 ::chart::tPropertyValueMap
* operator()()
117 static ::chart::tPropertyValueMap aStaticDefaults
;
118 ::chart::LinePropertiesHelper::AddDefaultsToMap( aStaticDefaults
);
119 return &aStaticDefaults
;
123 struct StaticXXXDefaults
: public rtl::StaticAggregate
< ::chart::tPropertyValueMap
, StaticXXXDefaults_Initializer
>
127 struct StaticRegressionCurveInfoHelper_Initializer
129 ::cppu::OPropertyArrayHelper
* operator()()
131 static ::cppu::OPropertyArrayHelper
aPropHelper( lcl_GetPropertySequence() );
136 static uno::Sequence
< Property
> lcl_GetPropertySequence()
138 std::vector
< css::beans::Property
> aProperties
;
139 lcl_AddPropertiesToVector( aProperties
);
140 ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties
);
142 std::sort( aProperties
.begin(), aProperties
.end(),
143 ::chart::PropertyNameLess() );
145 return comphelper::containerToSequence( aProperties
);
149 struct StaticRegressionCurveInfoHelper
: public rtl::StaticAggregate
< ::cppu::OPropertyArrayHelper
, StaticRegressionCurveInfoHelper_Initializer
>
153 struct StaticRegressionCurveInfo_Initializer
155 uno::Reference
< beans::XPropertySetInfo
>* operator()()
157 static uno::Reference
< beans::XPropertySetInfo
> xPropertySetInfo(
158 ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticRegressionCurveInfoHelper::get() ) );
159 return &xPropertySetInfo
;
163 struct StaticRegressionCurveInfo
: public rtl::StaticAggregate
< uno::Reference
< beans::XPropertySetInfo
>, StaticRegressionCurveInfo_Initializer
>
167 } // anonymous namespace
172 RegressionCurveModel::RegressionCurveModel( tCurveType eCurveType
) :
173 ::property::OPropertySet( m_aMutex
),
174 m_eRegressionCurveType( eCurveType
),
175 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()),
176 m_xEquationProperties( new RegressionEquation
)
178 // set 0 line width (default) hard, so that it is always written to XML,
179 // because the old implementation uses different defaults
180 setFastPropertyValue_NoBroadcast(
181 LinePropertiesHelper::PROP_LINE_WIDTH
, uno::Any( sal_Int32( 0 )));
182 ModifyListenerHelper::addListener( m_xEquationProperties
, m_xModifyEventForwarder
);
185 RegressionCurveModel::RegressionCurveModel( const RegressionCurveModel
& rOther
) :
186 impl::RegressionCurveModel_Base(rOther
),
187 ::property::OPropertySet( rOther
, m_aMutex
),
188 m_eRegressionCurveType( rOther
.m_eRegressionCurveType
),
189 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
191 m_xEquationProperties
.set( CloneHelper::CreateRefClone
< beans::XPropertySet
>()( rOther
.m_xEquationProperties
));
192 ModifyListenerHelper::addListener( m_xEquationProperties
, m_xModifyEventForwarder
);
195 RegressionCurveModel::~RegressionCurveModel()
198 // ____ XRegressionCurve ____
199 uno::Reference
< chart2::XRegressionCurveCalculator
> SAL_CALL
200 RegressionCurveModel::getCalculator()
202 return RegressionCurveHelper::createRegressionCurveCalculatorByServiceName( getServiceName());
205 uno::Reference
< beans::XPropertySet
> SAL_CALL
RegressionCurveModel::getEquationProperties()
207 return m_xEquationProperties
;
210 void SAL_CALL
RegressionCurveModel::setEquationProperties( const uno::Reference
< beans::XPropertySet
>& xEquationProperties
)
212 if( xEquationProperties
.is())
214 if( m_xEquationProperties
.is())
215 ModifyListenerHelper::removeListener( m_xEquationProperties
, m_xModifyEventForwarder
);
217 m_xEquationProperties
.set( xEquationProperties
);
218 ModifyListenerHelper::addListener( m_xEquationProperties
, m_xModifyEventForwarder
);
223 // ____ XServiceName ____
224 OUString SAL_CALL
RegressionCurveModel::getServiceName()
226 switch( m_eRegressionCurveType
)
228 case CURVE_TYPE_MEAN_VALUE
:
229 return "com.sun.star.chart2.MeanValueRegressionCurve";
230 case CURVE_TYPE_LINEAR
:
231 return "com.sun.star.chart2.LinearRegressionCurve";
232 case CURVE_TYPE_LOGARITHM
:
233 return "com.sun.star.chart2.LogarithmicRegressionCurve";
234 case CURVE_TYPE_EXPONENTIAL
:
235 return "com.sun.star.chart2.ExponentialRegressionCurve";
236 case CURVE_TYPE_POWER
:
237 return "com.sun.star.chart2.PotentialRegressionCurve";
238 case CURVE_TYPE_POLYNOMIAL
:
239 return "com.sun.star.chart2.PolynomialRegressionCurve";
240 case CURVE_TYPE_MOVING_AVERAGE
:
241 return "com.sun.star.chart2.MovingAverageRegressionCurve";
247 // ____ XModifyBroadcaster ____
248 void SAL_CALL
RegressionCurveModel::addModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
252 uno::Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
253 xBroadcaster
->addModifyListener( aListener
);
255 catch( const uno::Exception
& )
257 DBG_UNHANDLED_EXCEPTION("chart2");
261 void SAL_CALL
RegressionCurveModel::removeModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
265 uno::Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
266 xBroadcaster
->removeModifyListener( aListener
);
268 catch( const uno::Exception
& )
270 DBG_UNHANDLED_EXCEPTION("chart2");
274 // ____ XModifyListener ____
275 void SAL_CALL
RegressionCurveModel::modified( const lang::EventObject
& aEvent
)
277 m_xModifyEventForwarder
->modified( aEvent
);
280 // ____ XEventListener (base of XModifyListener) ____
281 void SAL_CALL
RegressionCurveModel::disposing( const lang::EventObject
& /* Source */ )
286 // ____ OPropertySet ____
287 void RegressionCurveModel::firePropertyChangeEvent()
292 void RegressionCurveModel::fireModifyEvent()
294 m_xModifyEventForwarder
->modified( lang::EventObject( static_cast< uno::XWeak
* >( this )));
297 // ____ OPropertySet ____
298 uno::Any
RegressionCurveModel::GetDefaultValue( sal_Int32 nHandle
) const
300 const tPropertyValueMap
& rStaticDefaults
= *StaticXXXDefaults::get();
301 tPropertyValueMap::const_iterator
aFound( rStaticDefaults
.find( nHandle
) );
302 if( aFound
== rStaticDefaults
.end() )
304 return (*aFound
).second
;
307 ::cppu::IPropertyArrayHelper
& SAL_CALL
RegressionCurveModel::getInfoHelper()
309 return *StaticRegressionCurveInfoHelper::get();
312 // ____ XPropertySet ____
313 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
RegressionCurveModel::getPropertySetInfo()
315 return *StaticRegressionCurveInfo::get();
318 // needed by MSC compiler
319 using impl::RegressionCurveModel_Base
;
321 IMPLEMENT_FORWARD_XINTERFACE2( RegressionCurveModel
, RegressionCurveModel_Base
, OPropertySet
)
322 IMPLEMENT_FORWARD_XTYPEPROVIDER2( RegressionCurveModel
, RegressionCurveModel_Base
, OPropertySet
)
326 MeanValueRegressionCurve::MeanValueRegressionCurve()
327 : RegressionCurveModel( RegressionCurveModel::CURVE_TYPE_MEAN_VALUE
)
329 MeanValueRegressionCurve::MeanValueRegressionCurve(
330 const MeanValueRegressionCurve
& rOther
) :
331 RegressionCurveModel( rOther
)
333 MeanValueRegressionCurve::~MeanValueRegressionCurve()
336 OUString SAL_CALL
MeanValueRegressionCurve::getImplementationName()
338 return lcl_aImplementationName_MeanValue
;
341 sal_Bool SAL_CALL
MeanValueRegressionCurve::supportsService( const OUString
& rServiceName
)
343 return cppu::supportsService(this, rServiceName
);
346 css::uno::Sequence
< OUString
> SAL_CALL
MeanValueRegressionCurve::getSupportedServiceNames()
348 return { lcl_aServiceName
, "com.sun.star.chart2.MeanValueRegressionCurve" };
351 uno::Reference
< util::XCloneable
> SAL_CALL
MeanValueRegressionCurve::createClone()
353 return uno::Reference
< util::XCloneable
>( new MeanValueRegressionCurve( *this ));
356 LinearRegressionCurve::LinearRegressionCurve()
357 : RegressionCurveModel( RegressionCurveModel::CURVE_TYPE_LINEAR
)
359 LinearRegressionCurve::LinearRegressionCurve(
360 const LinearRegressionCurve
& rOther
) :
361 RegressionCurveModel( rOther
)
363 LinearRegressionCurve::~LinearRegressionCurve()
366 OUString SAL_CALL
LinearRegressionCurve::getImplementationName()
368 return lcl_aImplementationName_Linear
;
371 sal_Bool SAL_CALL
LinearRegressionCurve::supportsService( const OUString
& rServiceName
)
373 return cppu::supportsService(this, rServiceName
);
376 css::uno::Sequence
< OUString
> SAL_CALL
LinearRegressionCurve::getSupportedServiceNames()
378 return { lcl_aServiceName
, "com.sun.star.chart2.LinearRegressionCurve" };
381 uno::Reference
< util::XCloneable
> SAL_CALL
LinearRegressionCurve::createClone()
383 return uno::Reference
< util::XCloneable
>( new LinearRegressionCurve( *this ));
386 LogarithmicRegressionCurve::LogarithmicRegressionCurve()
387 : RegressionCurveModel( RegressionCurveModel::CURVE_TYPE_LOGARITHM
)
389 LogarithmicRegressionCurve::LogarithmicRegressionCurve(
390 const LogarithmicRegressionCurve
& rOther
) :
391 RegressionCurveModel( rOther
)
393 LogarithmicRegressionCurve::~LogarithmicRegressionCurve()
396 OUString SAL_CALL
LogarithmicRegressionCurve::getImplementationName()
398 return lcl_aImplementationName_Logarithmic
;
401 sal_Bool SAL_CALL
LogarithmicRegressionCurve::supportsService( const OUString
& rServiceName
)
403 return cppu::supportsService(this, rServiceName
);
406 css::uno::Sequence
< OUString
> SAL_CALL
LogarithmicRegressionCurve::getSupportedServiceNames()
408 return { lcl_aServiceName
, "com.sun.star.chart2.LogarithmicRegressionCurve" };
411 uno::Reference
< util::XCloneable
> SAL_CALL
LogarithmicRegressionCurve::createClone()
413 return uno::Reference
< util::XCloneable
>( new LogarithmicRegressionCurve( *this ));
416 ExponentialRegressionCurve::ExponentialRegressionCurve()
417 : RegressionCurveModel( RegressionCurveModel::CURVE_TYPE_EXPONENTIAL
)
419 ExponentialRegressionCurve::ExponentialRegressionCurve(
420 const ExponentialRegressionCurve
& rOther
) :
421 RegressionCurveModel( rOther
)
423 ExponentialRegressionCurve::~ExponentialRegressionCurve()
426 OUString SAL_CALL
ExponentialRegressionCurve::getImplementationName()
428 return lcl_aImplementationName_Exponential
;
431 sal_Bool SAL_CALL
ExponentialRegressionCurve::supportsService( const OUString
& rServiceName
)
433 return cppu::supportsService(this, rServiceName
);
436 css::uno::Sequence
< OUString
> SAL_CALL
ExponentialRegressionCurve::getSupportedServiceNames()
438 return { lcl_aServiceName
, "com.sun.star.chart2.ExponentialRegressionCurve" };
441 uno::Reference
< util::XCloneable
> SAL_CALL
ExponentialRegressionCurve::createClone()
443 return uno::Reference
< util::XCloneable
>( new ExponentialRegressionCurve( *this ));
446 PotentialRegressionCurve::PotentialRegressionCurve()
447 : RegressionCurveModel( RegressionCurveModel::CURVE_TYPE_POWER
)
449 PotentialRegressionCurve::PotentialRegressionCurve(
450 const PotentialRegressionCurve
& rOther
) :
451 RegressionCurveModel( rOther
)
453 PotentialRegressionCurve::~PotentialRegressionCurve()
456 OUString SAL_CALL
PotentialRegressionCurve::getImplementationName()
458 return lcl_aImplementationName_Potential
;
461 sal_Bool SAL_CALL
PotentialRegressionCurve::supportsService( const OUString
& rServiceName
)
463 return cppu::supportsService(this, rServiceName
);
466 css::uno::Sequence
< OUString
> SAL_CALL
PotentialRegressionCurve::getSupportedServiceNames()
468 return { lcl_aServiceName
, "com.sun.star.chart2.PotentialRegressionCurve" };
471 uno::Reference
< util::XCloneable
> SAL_CALL
PotentialRegressionCurve::createClone()
473 return uno::Reference
< util::XCloneable
>( new PotentialRegressionCurve( *this ));
476 PolynomialRegressionCurve::PolynomialRegressionCurve()
477 : RegressionCurveModel( RegressionCurveModel::CURVE_TYPE_POLYNOMIAL
)
479 PolynomialRegressionCurve::PolynomialRegressionCurve(
480 const PolynomialRegressionCurve
& rOther
) :
481 RegressionCurveModel( rOther
)
483 PolynomialRegressionCurve::~PolynomialRegressionCurve()
486 OUString SAL_CALL
PolynomialRegressionCurve::getImplementationName()
488 return lcl_aImplementationName_Polynomial
;
491 sal_Bool SAL_CALL
PolynomialRegressionCurve::supportsService( const OUString
& rServiceName
)
493 return cppu::supportsService(this, rServiceName
);
496 css::uno::Sequence
< OUString
> SAL_CALL
PolynomialRegressionCurve::getSupportedServiceNames()
498 return { lcl_aServiceName
, "com.sun.star.chart2.PolynomialRegressionCurve" };
501 uno::Reference
< util::XCloneable
> SAL_CALL
PolynomialRegressionCurve::createClone()
503 return uno::Reference
< util::XCloneable
>( new PolynomialRegressionCurve( *this ));
506 MovingAverageRegressionCurve::MovingAverageRegressionCurve()
507 : RegressionCurveModel( RegressionCurveModel::CURVE_TYPE_MOVING_AVERAGE
)
509 MovingAverageRegressionCurve::MovingAverageRegressionCurve(
510 const MovingAverageRegressionCurve
& rOther
) :
511 RegressionCurveModel( rOther
)
513 MovingAverageRegressionCurve::~MovingAverageRegressionCurve()
516 OUString SAL_CALL
MovingAverageRegressionCurve::getImplementationName()
518 return lcl_aImplementationName_MovingAverage
;
521 sal_Bool SAL_CALL
MovingAverageRegressionCurve::supportsService( const OUString
& rServiceName
)
523 return cppu::supportsService(this, rServiceName
);
526 css::uno::Sequence
< OUString
> SAL_CALL
MovingAverageRegressionCurve::getSupportedServiceNames()
528 return { lcl_aServiceName
, "com.sun.star.chart2.MovingAverageRegressionCurve" };
531 uno::Reference
< util::XCloneable
> SAL_CALL
MovingAverageRegressionCurve::createClone()
533 return uno::Reference
< util::XCloneable
>( new MovingAverageRegressionCurve( *this ));
538 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
539 com_sun_star_comp_chart2_ExponentialRegressionCurve_get_implementation(css::uno::XComponentContext
*,
540 css::uno::Sequence
<css::uno::Any
> const &)
542 return cppu::acquire(new ::chart::ExponentialRegressionCurve
);
545 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
546 com_sun_star_comp_chart2_LinearRegressionCurve_get_implementation(css::uno::XComponentContext
*,
547 css::uno::Sequence
<css::uno::Any
> const &)
549 return cppu::acquire(new ::chart::LinearRegressionCurve
);
552 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
553 com_sun_star_comp_chart2_LogarithmicRegressionCurve_get_implementation(css::uno::XComponentContext
*,
554 css::uno::Sequence
<css::uno::Any
> const &)
556 return cppu::acquire(new ::chart::LogarithmicRegressionCurve
);
559 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
560 com_sun_star_comp_chart2_MeanValueRegressionCurve_get_implementation(css::uno::XComponentContext
*,
561 css::uno::Sequence
<css::uno::Any
> const &)
563 return cppu::acquire(new ::chart::MeanValueRegressionCurve
);
566 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
567 com_sun_star_comp_chart2_PotentialRegressionCurve_get_implementation(css::uno::XComponentContext
*,
568 css::uno::Sequence
<css::uno::Any
> const &)
570 return cppu::acquire(new ::chart::PotentialRegressionCurve
);
573 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
574 com_sun_star_comp_chart2_PolynomialRegressionCurve_get_implementation(css::uno::XComponentContext
*,
575 css::uno::Sequence
<css::uno::Any
> const &)
577 return cppu::acquire(new ::chart::PolynomialRegressionCurve
);
580 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
581 com_sun_star_comp_chart2_MovingAverageRegressionCurve_get_implementation(css::uno::XComponentContext
*,
582 css::uno::Sequence
<css::uno::Any
> const &)
584 return cppu::acquire(new ::chart::MovingAverageRegressionCurve
);
588 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */