LibreOffice Module chart2 (master) 1
RegressionCurveModel.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
25#include <CloneHelper.hxx>
26#include <PropertyHelper.hxx>
29#include <com/sun/star/beans/PropertyAttribute.hpp>
30
31namespace com::sun::star::uno { class XComponentContext; }
32
33using namespace ::com::sun::star;
34
35using ::com::sun::star::beans::Property;
36
37namespace
38{
39enum
40{
41 PROPERTY_DEGREE,
42 PROPERTY_PERIOD,
43 PROPERTY_EXTRAPOLATE_FORWARD,
44 PROPERTY_EXTRAPOLATE_BACKWARD,
45 PROPERTY_FORCE_INTERCEPT,
46 PROPERTY_INTERCEPT_VALUE,
47 PROPERTY_CURVE_NAME,
48 PROPERTY_MOVING_AVERAGE_TYPE
49};
50
51void lcl_AddPropertiesToVector(
52 std::vector< Property > & rOutProperties )
53{
54 rOutProperties.emplace_back( "PolynomialDegree",
55 PROPERTY_DEGREE,
57 beans::PropertyAttribute::BOUND |
58 beans::PropertyAttribute::MAYBEDEFAULT );
59
60 rOutProperties.emplace_back( "MovingAveragePeriod",
61 PROPERTY_PERIOD,
63 beans::PropertyAttribute::BOUND |
64 beans::PropertyAttribute::MAYBEDEFAULT );
65
66 rOutProperties.emplace_back( "MovingAverageType",
67 PROPERTY_MOVING_AVERAGE_TYPE,
69 beans::PropertyAttribute::BOUND |
70 beans::PropertyAttribute::MAYBEDEFAULT );
71
72 rOutProperties.emplace_back( "ExtrapolateForward",
73 PROPERTY_EXTRAPOLATE_FORWARD,
75 beans::PropertyAttribute::BOUND |
76 beans::PropertyAttribute::MAYBEDEFAULT );
77
78 rOutProperties.emplace_back( "ExtrapolateBackward",
79 PROPERTY_EXTRAPOLATE_BACKWARD,
81 beans::PropertyAttribute::BOUND |
82 beans::PropertyAttribute::MAYBEDEFAULT );
83
84 rOutProperties.emplace_back( "ForceIntercept",
85 PROPERTY_FORCE_INTERCEPT,
87 beans::PropertyAttribute::BOUND
88 | beans::PropertyAttribute::MAYBEDEFAULT );
89
90 rOutProperties.emplace_back( "InterceptValue",
91 PROPERTY_INTERCEPT_VALUE,
93 beans::PropertyAttribute::BOUND |
94 beans::PropertyAttribute::MAYBEDEFAULT );
95
96 rOutProperties.emplace_back( "CurveName",
97 PROPERTY_CURVE_NAME,
99 beans::PropertyAttribute::BOUND );
100}
101
102const ::chart::tPropertyValueMap & GetStaticXXXDefaults()
103{
104 static ::chart::tPropertyValueMap aStaticDefaults =
105 [](){
108 return aTmp;
109 }();
110 return aStaticDefaults;
111};
112
113::cppu::OPropertyArrayHelper& GetStaticRegressionCurveInfoHelper()
114{
115 static ::cppu::OPropertyArrayHelper aPropHelper =
116 [](){
117 std::vector< css::beans::Property > aProperties;
118 lcl_AddPropertiesToVector( aProperties );
120
121 std::sort( aProperties.begin(), aProperties.end(),
123
124 return comphelper::containerToSequence( aProperties );
125 }();
126 return aPropHelper;
127};
128
129uno::Reference< beans::XPropertySetInfo >& GetStaticRegressionCurveInfo()
130{
131 static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
132 ::cppu::OPropertySetHelper::createPropertySetInfo(GetStaticRegressionCurveInfoHelper() ) );
133 return xPropertySetInfo;
134};
135
136} // anonymous namespace
137
138namespace chart
139{
140
142 m_eRegressionCurveType( eCurveType ),
143 m_xModifyEventForwarder( new ModifyEventForwarder() ),
144 m_xEquationProperties( new RegressionEquation )
145{
146 // set 0 line width (default) hard, so that it is always written to XML,
147 // because the old implementation uses different defaults
151}
152
155 ::property::OPropertySet( rOther ),
156 m_eRegressionCurveType( rOther.m_eRegressionCurveType ),
157 m_xModifyEventForwarder( new ModifyEventForwarder() )
158{
161}
162
164{}
165
166// ____ XRegressionCurve ____
169{
171}
172
174{
176}
177
179{
180 if( xEquationProperties.is())
181 {
182 if( m_xEquationProperties.is())
184
185 m_xEquationProperties.set( xEquationProperties );
189 }
190}
191
193{
194 if( m_xEquationProperties.is()) {
196 m_xEquationProperties->setPropertyValue( "MayHaveCorrelationCoefficient", uno::Any( bMayHaveR2 ) );
197 }
198}
199
200// ____ XServiceName ____
202{
203 switch( m_eRegressionCurveType )
204 {
206 return "com.sun.star.chart2.MeanValueRegressionCurve";
208 return "com.sun.star.chart2.LinearRegressionCurve";
210 return "com.sun.star.chart2.LogarithmicRegressionCurve";
212 return "com.sun.star.chart2.ExponentialRegressionCurve";
213 case CURVE_TYPE_POWER:
214 return "com.sun.star.chart2.PotentialRegressionCurve";
216 return "com.sun.star.chart2.PolynomialRegressionCurve";
218 return "com.sun.star.chart2.MovingAverageRegressionCurve";
219 }
220
221 return OUString();
222}
223
224// ____ XModifyBroadcaster ____
226{
227 m_xModifyEventForwarder->addModifyListener( aListener );
228}
229
231{
232 m_xModifyEventForwarder->removeModifyListener( aListener );
233}
234
235// ____ XModifyListener ____
236void SAL_CALL RegressionCurveModel::modified( const lang::EventObject& aEvent )
237{
238 m_xModifyEventForwarder->modified( aEvent );
239}
240
241// ____ XEventListener (base of XModifyListener) ____
242void SAL_CALL RegressionCurveModel::disposing( const lang::EventObject& /* Source */ )
243{
244 // nothing
245}
246
247// ____ OPropertySet ____
249{
252}
253
255{
256 m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
257}
258
259// ____ OPropertySet ____
260void RegressionCurveModel::GetDefaultValue( sal_Int32 nHandle, uno::Any& rAny ) const
261{
262 const tPropertyValueMap& rStaticDefaults = GetStaticXXXDefaults();
263 tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
264 if( aFound == rStaticDefaults.end() )
265 rAny.clear();
266 else
267 rAny = (*aFound).second;
268}
269
271{
272 return GetStaticRegressionCurveInfoHelper();
273}
274
275// ____ XPropertySet ____
277{
278 return GetStaticRegressionCurveInfo();
279}
280
281// needed by MSC compiler
283
286
287// implementations
288
290 : RegressionCurveModel( RegressionCurveModel::CURVE_TYPE_MEAN_VALUE )
291{}
293 const MeanValueRegressionCurve & rOther ) :
294 RegressionCurveModel( rOther )
295{}
297{}
298
300{
301 return "com.sun.star.comp.chart2.MeanValueRegressionCurve";
302}
303
304sal_Bool SAL_CALL MeanValueRegressionCurve::supportsService( const OUString& rServiceName )
305{
306 return cppu::supportsService(this, rServiceName);
307}
308
309css::uno::Sequence< OUString > SAL_CALL MeanValueRegressionCurve::getSupportedServiceNames()
310{
311 return { "com.sun.star.chart2.RegressionCurve", "com.sun.star.chart2.MeanValueRegressionCurve" };
312}
313
315{
317}
318
320 : RegressionCurveModel( RegressionCurveModel::CURVE_TYPE_LINEAR )
321{}
323 const LinearRegressionCurve & rOther ) :
324 RegressionCurveModel( rOther )
325{}
327{}
328
330{
331 return "com.sun.star.comp.chart2.LinearRegressionCurve";
332}
333
334sal_Bool SAL_CALL LinearRegressionCurve::supportsService( const OUString& rServiceName )
335{
336 return cppu::supportsService(this, rServiceName);
337}
338
339css::uno::Sequence< OUString > SAL_CALL LinearRegressionCurve::getSupportedServiceNames()
340{
341 return { "com.sun.star.chart2.RegressionCurve", "com.sun.star.chart2.LinearRegressionCurve" };
342}
343
345{
347}
348
350 : RegressionCurveModel( RegressionCurveModel::CURVE_TYPE_LOGARITHM )
351{}
353 const LogarithmicRegressionCurve & rOther ) :
354 RegressionCurveModel( rOther )
355{}
357{}
358
360{
361 return "com.sun.star.comp.chart2.LogarithmicRegressionCurve";
362}
363
364sal_Bool SAL_CALL LogarithmicRegressionCurve::supportsService( const OUString& rServiceName )
365{
366 return cppu::supportsService(this, rServiceName);
367}
368
369css::uno::Sequence< OUString > SAL_CALL LogarithmicRegressionCurve::getSupportedServiceNames()
370{
371 return { "com.sun.star.chart2.RegressionCurve", "com.sun.star.chart2.LogarithmicRegressionCurve" };
372}
373
375{
377}
378
380 : RegressionCurveModel( RegressionCurveModel::CURVE_TYPE_EXPONENTIAL )
381{}
383 const ExponentialRegressionCurve & rOther ) :
384 RegressionCurveModel( rOther )
385{}
387{}
388
390{
391 return "com.sun.star.comp.chart2.ExponentialRegressionCurve";
392}
393
394sal_Bool SAL_CALL ExponentialRegressionCurve::supportsService( const OUString& rServiceName )
395{
396 return cppu::supportsService(this, rServiceName);
397}
398
399css::uno::Sequence< OUString > SAL_CALL ExponentialRegressionCurve::getSupportedServiceNames()
400{
401 return { "com.sun.star.chart2.RegressionCurve", "com.sun.star.chart2.ExponentialRegressionCurve" };
402}
403
405{
407}
408
410 : RegressionCurveModel( RegressionCurveModel::CURVE_TYPE_POWER )
411{}
413 const PotentialRegressionCurve & rOther ) :
414 RegressionCurveModel( rOther )
415{}
417{}
418
420{
421 return "com.sun.star.comp.chart2.PotentialRegressionCurve";
422}
423
424sal_Bool SAL_CALL PotentialRegressionCurve::supportsService( const OUString& rServiceName )
425{
426 return cppu::supportsService(this, rServiceName);
427}
428
429css::uno::Sequence< OUString > SAL_CALL PotentialRegressionCurve::getSupportedServiceNames()
430{
431 return { "com.sun.star.chart2.RegressionCurve", "com.sun.star.chart2.PotentialRegressionCurve" };
432}
433
435{
437}
438
440 : RegressionCurveModel( RegressionCurveModel::CURVE_TYPE_POLYNOMIAL )
441{}
443 const PolynomialRegressionCurve & rOther ) :
444 RegressionCurveModel( rOther )
445{}
447{}
448
450{
451 return "com.sun.star.comp.chart2.PolynomialRegressionCurve";
452}
453
454sal_Bool SAL_CALL PolynomialRegressionCurve::supportsService( const OUString& rServiceName )
455{
456 return cppu::supportsService(this, rServiceName);
457}
458
459css::uno::Sequence< OUString > SAL_CALL PolynomialRegressionCurve::getSupportedServiceNames()
460{
461 return { "com.sun.star.chart2.RegressionCurve", "com.sun.star.chart2.PolynomialRegressionCurve" };
462}
463
465{
467}
468
470 : RegressionCurveModel( RegressionCurveModel::CURVE_TYPE_MOVING_AVERAGE )
471{}
473 const MovingAverageRegressionCurve & rOther ) :
474 RegressionCurveModel( rOther )
475{}
477{}
478
480{
481 return "com.sun.star.comp.chart2.MovingAverageRegressionCurve";
482}
483
484sal_Bool SAL_CALL MovingAverageRegressionCurve::supportsService( const OUString& rServiceName )
485{
486 return cppu::supportsService(this, rServiceName);
487}
488
489css::uno::Sequence< OUString > SAL_CALL MovingAverageRegressionCurve::getSupportedServiceNames()
490{
491 return { "com.sun.star.chart2.RegressionCurve", "com.sun.star.chart2.MovingAverageRegressionCurve" };
492}
493
495{
497}
498
499} // namespace chart
500
501extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
503 css::uno::Sequence<css::uno::Any> const &)
504{
505 return cppu::acquire(new ::chart::ExponentialRegressionCurve );
506}
507
508extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
510 css::uno::Sequence<css::uno::Any> const &)
511{
512 return cppu::acquire(new ::chart::LinearRegressionCurve );
513}
514
515extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
517 css::uno::Sequence<css::uno::Any> const &)
518{
519 return cppu::acquire(new ::chart::LogarithmicRegressionCurve );
520}
521
522extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
524 css::uno::Sequence<css::uno::Any> const &)
525{
526 return cppu::acquire(new ::chart::MeanValueRegressionCurve );
527}
528
529extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
531 css::uno::Sequence<css::uno::Any> const &)
532{
533 return cppu::acquire(new ::chart::PotentialRegressionCurve );
534}
535
536extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
538 css::uno::Sequence<css::uno::Any> const &)
539{
540 return cppu::acquire(new ::chart::PolynomialRegressionCurve );
541}
542
543extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
545 css::uno::Sequence<css::uno::Any> const &)
546{
547 return cppu::acquire(new ::chart::MovingAverageRegressionCurve );
548}
549
550
551/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_chart2_PotentialRegressionCurve_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_chart2_MovingAverageRegressionCurve_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_chart2_PolynomialRegressionCurve_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_chart2_ExponentialRegressionCurve_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_chart2_LinearRegressionCurve_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_chart2_MeanValueRegressionCurve_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_chart2_LogarithmicRegressionCurve_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
PropertiesInfo aProperties
AnyEventRef aEvent
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual OUString SAL_CALL getImplementationName() override
XServiceInfo declarations.
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone() override
virtual OUString SAL_CALL getImplementationName() override
XServiceInfo declarations.
virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual OUString SAL_CALL getImplementationName() override
XServiceInfo declarations.
virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual OUString SAL_CALL getImplementationName() override
XServiceInfo declarations.
virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone() override
This helper class serves as forwarder of modify events.
virtual OUString SAL_CALL getImplementationName() override
XServiceInfo declarations.
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone() override
virtual OUString SAL_CALL getImplementationName() override
XServiceInfo declarations.
virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone() override
virtual OUString SAL_CALL getImplementationName() override
XServiceInfo declarations.
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual css::uno::Reference< css::beans::XPropertySet > SAL_CALL getEquationProperties() override
virtual ::cppu::IPropertyArrayHelper &SAL_CALL getInfoHelper() override
The InfoHelper table contains all property names and types of this object.
virtual css::uno::Reference< css::chart2::XRegressionCurveCalculator > SAL_CALL getCalculator() override
RegressionCurveModel(tCurveType eCurveType)
virtual void SAL_CALL modified(const css::lang::EventObject &aEvent) override
virtual void GetDefaultValue(sal_Int32 nHandle, css::uno::Any &rAny) const override
merge XInterface implementations
css::uno::Reference< css::beans::XPropertySet > m_xEquationProperties
virtual void SAL_CALL setEquationProperties(const css::uno::Reference< css::beans::XPropertySet > &xEquationProperties) override
virtual void SAL_CALL addModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
virtual ~RegressionCurveModel() override
virtual OUString SAL_CALL getServiceName() override
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
rtl::Reference< ModifyEventForwarder > m_xModifyEventForwarder
virtual void SAL_CALL removeModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
virtual void firePropertyChangeEvent() override
implement this method in derived classes to get called when properties change.
static css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL createPropertySetInfo(IPropertyArrayHelper &rProperties)
void SAL_CALL disposing()
virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any &rValue) override
The same as setFastPropertyValue; nHandle is always valid.
OOO_DLLPUBLIC_CHARTTOOLS void AddDefaultsToMap(::chart::tPropertyValueMap &rOutMap)
OOO_DLLPUBLIC_CHARTTOOLS void AddPropertiesToVector(std::vector< css::beans::Property > &rOutProperties)
void removeListener(const InterfaceRef &xObject, const css::uno::Reference< css::util::XModifyListener > &xListener)
void addListener(const InterfaceRef &xObject, const css::uno::Reference< css::util::XModifyListener > &xListener)
OOO_DLLPUBLIC_CHARTTOOLS rtl::Reference<::chart::RegressionCurveCalculator > createRegressionCurveCalculatorByServiceName(std::u16string_view aServiceName)
returns a calculator object for regression curves (used by the view)
::cppu::WeakImplHelper< css::lang::XServiceInfo, css::lang::XServiceName, css::chart2::XRegressionCurve, css::util::XCloneable, css::util::XModifyBroadcaster, css::util::XModifyListener > RegressionCurveModel_Base
std::unordered_map< tPropertyValueMapKey, css::uno::Any > tPropertyValueMap
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
IMPLEMENT_FORWARD_XTYPEPROVIDER2(ChildWindowPane, ChildWindowPaneInterfaceBase, Pane)
IMPLEMENT_FORWARD_XINTERFACE2(ChildWindowPane, ChildWindowPaneInterfaceBase, Pane)
sal_Int32 nHandle
functor that clones a UNO-Reference
Definition: CloneHelper.hxx:33
unsigned char sal_Bool