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 "RegressionEquation.hxx"
21 #include <LinePropertiesHelper.hxx>
22 #include <FillProperties.hxx>
23 #include <UserDefinedProperties.hxx>
24 #include <CharacterProperties.hxx>
25 #include <PropertyHelper.hxx>
26 #include <ModifyListenerHelper.hxx>
27 #include <unonames.hxx>
28 #include <cppuhelper/supportsservice.hxx>
30 #include <com/sun/star/uno/Sequence.hxx>
31 #include <com/sun/star/drawing/FillStyle.hpp>
32 #include <com/sun/star/drawing/LineStyle.hpp>
33 #include <com/sun/star/beans/PropertyAttribute.hpp>
34 #include <com/sun/star/chart2/RelativePosition.hpp>
35 #include <com/sun/star/awt/Size.hpp>
39 namespace com::sun::star::uno
{ class XComponentContext
; }
41 using namespace ::com::sun::star
;
43 using ::com::sun::star::uno::Reference
;
44 using ::com::sun::star::beans::Property
;
45 using ::osl::MutexGuard
;
55 PROP_EQUATION_SHOW_CORRELATION_COEFF
,
56 PROP_EQUATION_MAY_HAVE_CORRELATION_COEFF
,
57 PROP_EQUATION_REF_PAGE_SIZE
,
58 PROP_EQUATION_REL_POS
,
59 PROP_EQUATION_NUMBER_FORMAT
62 void lcl_AddPropertiesToVector(
63 std::vector
< Property
> & rOutProperties
)
65 rOutProperties
.emplace_back( "ShowEquation",
67 cppu::UnoType
<bool>::get(),
68 beans::PropertyAttribute::BOUND
69 | beans::PropertyAttribute::MAYBEDEFAULT
);
71 rOutProperties
.emplace_back( "XName",
73 cppu::UnoType
<OUString
>::get(),
74 beans::PropertyAttribute::BOUND
75 | beans::PropertyAttribute::MAYBEDEFAULT
);
77 rOutProperties
.emplace_back( "YName",
79 cppu::UnoType
<OUString
>::get(),
80 beans::PropertyAttribute::BOUND
81 | beans::PropertyAttribute::MAYBEDEFAULT
);
83 rOutProperties
.emplace_back( "ShowCorrelationCoefficient",
84 PROP_EQUATION_SHOW_CORRELATION_COEFF
,
85 cppu::UnoType
<bool>::get(),
86 beans::PropertyAttribute::BOUND
87 | beans::PropertyAttribute::MAYBEDEFAULT
);
89 rOutProperties
.emplace_back( "MayHaveCorrelationCoefficient",
90 PROP_EQUATION_MAY_HAVE_CORRELATION_COEFF
,
91 cppu::UnoType
<bool>::get(),
92 beans::PropertyAttribute::BOUND
93 | beans::PropertyAttribute::MAYBEDEFAULT
);
95 rOutProperties
.emplace_back( "ReferencePageSize",
96 PROP_EQUATION_REF_PAGE_SIZE
,
97 cppu::UnoType
<awt::Size
>::get(),
98 beans::PropertyAttribute::BOUND
99 | beans::PropertyAttribute::MAYBEVOID
);
101 rOutProperties
.emplace_back( "RelativePosition",
102 PROP_EQUATION_REL_POS
,
103 cppu::UnoType
<chart2::RelativePosition
>::get(),
104 beans::PropertyAttribute::BOUND
105 | beans::PropertyAttribute::MAYBEVOID
);
107 rOutProperties
.emplace_back( CHART_UNONAME_NUMFMT
,
108 PROP_EQUATION_NUMBER_FORMAT
,
109 cppu::UnoType
<sal_Int32
>::get(),
110 beans::PropertyAttribute::BOUND
111 | beans::PropertyAttribute::MAYBEVOID
);
114 ::chart::tPropertyValueMap
& GetStaticRegressionEquationDefaults()
116 static ::chart::tPropertyValueMap aStaticDefaults
=
118 ::chart::tPropertyValueMap aOutMap
;
119 ::chart::LinePropertiesHelper::AddDefaultsToMap( aOutMap
);
120 ::chart::FillProperties::AddDefaultsToMap( aOutMap
);
121 ::chart::CharacterProperties::AddDefaultsToMap( aOutMap
);
123 ::chart::PropertyHelper::setPropertyValueDefault( aOutMap
, PROP_EQUATION_SHOW
, false );
124 ::chart::PropertyHelper::setPropertyValueDefault( aOutMap
, PROP_EQUATION_XNAME
, u
"x"_ustr
);
125 ::chart::PropertyHelper::setPropertyValueDefault( aOutMap
, PROP_EQUATION_YNAME
, u
"f(x)"_ustr
);
126 ::chart::PropertyHelper::setPropertyValueDefault( aOutMap
, PROP_EQUATION_SHOW_CORRELATION_COEFF
, false );
127 ::chart::PropertyHelper::setPropertyValueDefault( aOutMap
, PROP_EQUATION_MAY_HAVE_CORRELATION_COEFF
, true );
128 //::chart::PropertyHelper::setPropertyValueDefault( aOutMap, PROP_EQUATION_SEPARATOR, OUString( '\n' ));
130 // override other defaults
131 ::chart::PropertyHelper::setPropertyValue( aOutMap
, ::chart::FillProperties::PROP_FILL_STYLE
, drawing::FillStyle_NONE
);
132 ::chart::PropertyHelper::setPropertyValue( aOutMap
, ::chart::LinePropertiesHelper::PROP_LINE_STYLE
, drawing::LineStyle_NONE
);
134 float fDefaultCharHeight
= 10.0;
135 ::chart::PropertyHelper::setPropertyValue( aOutMap
, ::chart::CharacterProperties::PROP_CHAR_CHAR_HEIGHT
, fDefaultCharHeight
);
136 ::chart::PropertyHelper::setPropertyValue( aOutMap
, ::chart::CharacterProperties::PROP_CHAR_ASIAN_CHAR_HEIGHT
, fDefaultCharHeight
);
137 ::chart::PropertyHelper::setPropertyValue( aOutMap
, ::chart::CharacterProperties::PROP_CHAR_COMPLEX_CHAR_HEIGHT
, fDefaultCharHeight
);
140 return aStaticDefaults
;
143 ::cppu::OPropertyArrayHelper
& GetStaticRegressionEquationInfoHelper()
145 static ::cppu::OPropertyArrayHelper aPropHelper
=
147 std::vector
< css::beans::Property
> aProperties
;
148 lcl_AddPropertiesToVector( aProperties
);
149 ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties
);
150 ::chart::FillProperties::AddPropertiesToVector( aProperties
);
151 ::chart::CharacterProperties::AddPropertiesToVector( aProperties
);
152 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties
);
154 std::sort( aProperties
.begin(), aProperties
.end(),
155 ::chart::PropertyNameLess() );
157 return comphelper::containerToSequence( aProperties
);
162 const uno::Reference
< beans::XPropertySetInfo
> & GetStaticRegressionEquationInfo()
164 static uno::Reference
< beans::XPropertySetInfo
> xPropertySetInfo(
165 ::cppu::OPropertySetHelper::createPropertySetInfo(GetStaticRegressionEquationInfoHelper()) );
166 return xPropertySetInfo
;
169 } // anonymous namespace
174 RegressionEquation::RegressionEquation() :
175 m_xModifyEventForwarder( new ModifyEventForwarder())
178 RegressionEquation::RegressionEquation( const RegressionEquation
& rOther
) :
179 impl::RegressionEquation_Base(rOther
),
180 ::property::OPropertySet( rOther
),
181 m_xModifyEventForwarder( new ModifyEventForwarder())
184 RegressionEquation::~RegressionEquation()
187 // ____ XCloneable ____
188 uno::Reference
< util::XCloneable
> SAL_CALL
RegressionEquation::createClone()
190 return uno::Reference
< util::XCloneable
>( new RegressionEquation( *this ));
193 // ____ OPropertySet ____
194 void RegressionEquation::GetDefaultValue( sal_Int32 nHandle
, uno::Any
& rAny
) const
196 const tPropertyValueMap
& rStaticDefaults
= GetStaticRegressionEquationDefaults();
197 tPropertyValueMap::const_iterator
aFound( rStaticDefaults
.find( nHandle
) );
198 if( aFound
== rStaticDefaults
.end() )
201 rAny
= (*aFound
).second
;
204 ::cppu::IPropertyArrayHelper
& SAL_CALL
RegressionEquation::getInfoHelper()
206 return GetStaticRegressionEquationInfoHelper();
209 // ____ XPropertySet ____
210 Reference
< beans::XPropertySetInfo
> SAL_CALL
RegressionEquation::getPropertySetInfo()
212 return GetStaticRegressionEquationInfo();
215 // ____ XModifyBroadcaster ____
216 void SAL_CALL
RegressionEquation::addModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
218 m_xModifyEventForwarder
->addModifyListener( aListener
);
221 void SAL_CALL
RegressionEquation::removeModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
223 m_xModifyEventForwarder
->removeModifyListener( aListener
);
226 // ____ XModifyListener ____
227 void SAL_CALL
RegressionEquation::modified( const lang::EventObject
& aEvent
)
229 m_xModifyEventForwarder
->modified( aEvent
);
232 // ____ XEventListener (base of XModifyListener) ____
233 void SAL_CALL
RegressionEquation::disposing( const lang::EventObject
& /* Source */ )
238 // ____ OPropertySet ____
239 void RegressionEquation::firePropertyChangeEvent()
244 void RegressionEquation::fireModifyEvent()
246 m_xModifyEventForwarder
->modified( lang::EventObject( static_cast< uno::XWeak
* >( this )));
250 uno::Sequence
< uno::Reference
< chart2::XFormattedString
> > SAL_CALL
RegressionEquation::getText()
252 MutexGuard
aGuard( m_aMutex
);
256 void SAL_CALL
RegressionEquation::setText( const uno::Sequence
< uno::Reference
< chart2::XFormattedString
> >& Strings
)
258 MutexGuard
aGuard( m_aMutex
);
259 ModifyListenerHelper::removeListenerFromAllElements(
260 comphelper::sequenceToContainer
<std::vector
<uno::Reference
< chart2::XFormattedString
> > >( m_aStrings
),
261 m_xModifyEventForwarder
);
262 m_aStrings
= Strings
;
263 ModifyListenerHelper::addListenerToAllElements(
264 comphelper::sequenceToContainer
<std::vector
<uno::Reference
< chart2::XFormattedString
> > >( m_aStrings
),
265 m_xModifyEventForwarder
);
269 OUString SAL_CALL
RegressionEquation::getImplementationName()
271 return u
"com.sun.star.comp.chart2.RegressionEquation"_ustr
;
274 sal_Bool SAL_CALL
RegressionEquation::supportsService( const OUString
& rServiceName
)
276 return cppu::supportsService(this, rServiceName
);
279 css::uno::Sequence
< OUString
> SAL_CALL
RegressionEquation::getSupportedServiceNames()
281 return { u
"com.sun.star.chart2.RegressionEquation"_ustr
,
282 u
"com.sun.star.beans.PropertySet"_ustr
,
283 u
"com.sun.star.drawing.FillProperties"_ustr
,
284 u
"com.sun.star.drawing.LineProperties"_ustr
,
285 u
"com.sun.star.style.CharacterProperties"_ustr
};
288 using impl::RegressionEquation_Base
;
290 IMPLEMENT_FORWARD_XINTERFACE2( RegressionEquation
, RegressionEquation_Base
, ::property::OPropertySet
)
294 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
295 com_sun_star_comp_chart2_RegressionEquation_get_implementation(css::uno::XComponentContext
*,
296 css::uno::Sequence
<css::uno::Any
> const &)
298 return cppu::acquire(new ::chart::RegressionEquation
);
301 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */