LibreOffice Module chart2 (master) 1
RegressionEquation.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
22#include <FillProperties.hxx>
25#include <PropertyHelper.hxx>
27#include <unonames.hxx>
29
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>
36
37#include <algorithm>
38
39namespace com::sun::star::uno { class XComponentContext; }
40
41using namespace ::com::sun::star;
42
43using ::com::sun::star::uno::Reference;
44using ::com::sun::star::beans::Property;
45using ::osl::MutexGuard;
46
47namespace
48{
49
50enum
51{
52 PROP_EQUATION_SHOW,
53 PROP_EQUATION_XNAME,
54 PROP_EQUATION_YNAME,
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
60};
61
62void lcl_AddPropertiesToVector(
63 std::vector< Property > & rOutProperties )
64{
65 rOutProperties.emplace_back( "ShowEquation",
66 PROP_EQUATION_SHOW,
68 beans::PropertyAttribute::BOUND
69 | beans::PropertyAttribute::MAYBEDEFAULT );
70
71 rOutProperties.emplace_back( "XName",
72 PROP_EQUATION_XNAME,
74 beans::PropertyAttribute::BOUND
75 | beans::PropertyAttribute::MAYBEDEFAULT );
76
77 rOutProperties.emplace_back( "YName",
78 PROP_EQUATION_YNAME,
80 beans::PropertyAttribute::BOUND
81 | beans::PropertyAttribute::MAYBEDEFAULT );
82
83 rOutProperties.emplace_back( "ShowCorrelationCoefficient",
84 PROP_EQUATION_SHOW_CORRELATION_COEFF,
86 beans::PropertyAttribute::BOUND
87 | beans::PropertyAttribute::MAYBEDEFAULT );
88
89 rOutProperties.emplace_back( "MayHaveCorrelationCoefficient",
90 PROP_EQUATION_MAY_HAVE_CORRELATION_COEFF,
92 beans::PropertyAttribute::BOUND
93 | beans::PropertyAttribute::MAYBEDEFAULT );
94
95 rOutProperties.emplace_back( "ReferencePageSize",
96 PROP_EQUATION_REF_PAGE_SIZE,
98 beans::PropertyAttribute::BOUND
99 | beans::PropertyAttribute::MAYBEVOID );
100
101 rOutProperties.emplace_back( "RelativePosition",
102 PROP_EQUATION_REL_POS,
104 beans::PropertyAttribute::BOUND
105 | beans::PropertyAttribute::MAYBEVOID );
106
107 rOutProperties.emplace_back( CHART_UNONAME_NUMFMT,
108 PROP_EQUATION_NUMBER_FORMAT,
110 beans::PropertyAttribute::BOUND
111 | beans::PropertyAttribute::MAYBEVOID );
112}
113
114::chart::tPropertyValueMap& GetStaticRegressionEquationDefaults()
115{
116 static ::chart::tPropertyValueMap aStaticDefaults =
117 [](){
122
123 ::chart::PropertyHelper::setPropertyValueDefault( aOutMap, PROP_EQUATION_SHOW, false );
124 ::chart::PropertyHelper::setPropertyValueDefault( aOutMap, PROP_EQUATION_XNAME, OUString("x") );
125 ::chart::PropertyHelper::setPropertyValueDefault( aOutMap, PROP_EQUATION_YNAME, OUString("f(x)") );
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' ));
129
130 // override other defaults
131 ::chart::PropertyHelper::setPropertyValue( aOutMap, ::chart::FillProperties::PROP_FILL_STYLE, drawing::FillStyle_NONE );
133
134 float fDefaultCharHeight = 10.0;
138 return aOutMap;
139 }();
140 return aStaticDefaults;
141};
142
143::cppu::OPropertyArrayHelper& GetStaticRegressionEquationInfoHelper()
144{
145 static ::cppu::OPropertyArrayHelper aPropHelper =
146 [](){
147 std::vector< css::beans::Property > aProperties;
148 lcl_AddPropertiesToVector( aProperties );
153
154 std::sort( aProperties.begin(), aProperties.end(),
156
157 return comphelper::containerToSequence( aProperties );
158 }();
159 return aPropHelper;
160};
161
162const uno::Reference< beans::XPropertySetInfo > & GetStaticRegressionEquationInfo()
163{
164 static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
165 ::cppu::OPropertySetHelper::createPropertySetInfo(GetStaticRegressionEquationInfoHelper()) );
166 return xPropertySetInfo;
167};
168
169} // anonymous namespace
170
171namespace chart
172{
173
175 m_xModifyEventForwarder( new ModifyEventForwarder())
176{}
177
180 ::property::OPropertySet( rOther ),
181 m_xModifyEventForwarder( new ModifyEventForwarder())
182{}
183
185{}
186
187// ____ XCloneable ____
189{
191}
192
193// ____ OPropertySet ____
194void RegressionEquation::GetDefaultValue( sal_Int32 nHandle, uno::Any& rAny ) const
195{
196 const tPropertyValueMap& rStaticDefaults = GetStaticRegressionEquationDefaults();
197 tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
198 if( aFound == rStaticDefaults.end() )
199 rAny.clear();
200 else
201 rAny = (*aFound).second;
202}
203
205{
206 return GetStaticRegressionEquationInfoHelper();
207}
208
209// ____ XPropertySet ____
211{
212 return GetStaticRegressionEquationInfo();
213}
214
215// ____ XModifyBroadcaster ____
217{
218 m_xModifyEventForwarder->addModifyListener( aListener );
219}
220
222{
223 m_xModifyEventForwarder->removeModifyListener( aListener );
224}
225
226// ____ XModifyListener ____
227void SAL_CALL RegressionEquation::modified( const lang::EventObject& aEvent )
228{
229 m_xModifyEventForwarder->modified( aEvent );
230}
231
232// ____ XEventListener (base of XModifyListener) ____
233void SAL_CALL RegressionEquation::disposing( const lang::EventObject& /* Source */ )
234{
235 // nothing
236}
237
238// ____ OPropertySet ____
240{
242}
243
245{
246 m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
247}
248
249// ____ XTitle ____
251{
252 MutexGuard aGuard( m_aMutex );
253 return m_aStrings;
254}
255
257{
258 MutexGuard aGuard( m_aMutex );
262 m_aStrings = Strings;
267}
268
270{
271 return "com.sun.star.comp.chart2.RegressionEquation";
272}
273
274sal_Bool SAL_CALL RegressionEquation::supportsService( const OUString& rServiceName )
275{
276 return cppu::supportsService(this, rServiceName);
277}
278
279css::uno::Sequence< OUString > SAL_CALL RegressionEquation::getSupportedServiceNames()
280{
281 return { "com.sun.star.chart2.RegressionEquation",
282 "com.sun.star.beans.PropertySet",
283 "com.sun.star.drawing.FillProperties",
284 "com.sun.star.drawing.LineProperties",
285 "com.sun.star.style.CharacterProperties" };
286}
287
289
291
292} // namespace chart
293
294extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
296 css::uno::Sequence<css::uno::Any> const &)
297{
298 return cppu::acquire(new ::chart::RegressionEquation);
299}
300
301/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_chart2_RegressionEquation_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
PropertiesInfo aProperties
AnyEventRef aEvent
This helper class serves as forwarder of modify events.
virtual void firePropertyChangeEvent() override
implement this method in derived classes to get called when properties change.
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
css::uno::Sequence< css::uno::Reference< css::chart2::XFormattedString > > m_aStrings
virtual void SAL_CALL modified(const css::lang::EventObject &aEvent) override
virtual ::cppu::IPropertyArrayHelper &SAL_CALL getInfoHelper() override
The InfoHelper table contains all property names and types of this object.
virtual OUString SAL_CALL getImplementationName() override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual void SAL_CALL addModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
virtual void GetDefaultValue(sal_Int32 nHandle, css::uno::Any &rAny) const override
implement this method to provide default values for all properties supporting defaults.
virtual void SAL_CALL setText(const css::uno::Sequence< css::uno::Reference< css::chart2::XFormattedString > > &Strings) override
virtual ~RegressionEquation() override
virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone() override
virtual css::uno::Sequence< css::uno::Reference< css::chart2::XFormattedString > > SAL_CALL getText() override
rtl::Reference< ModifyEventForwarder > m_xModifyEventForwarder
virtual void SAL_CALL removeModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
mutable::osl::Mutex m_aMutex
static css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL createPropertySetInfo(IPropertyArrayHelper &rProperties)
void SAL_CALL disposing()
OOO_DLLPUBLIC_CHARTTOOLS void AddDefaultsToMap(::chart::tPropertyValueMap &rOutMap)
OOO_DLLPUBLIC_CHARTTOOLS void AddPropertiesToVector(std::vector< css::beans::Property > &rOutProperties)
void removeListenerFromAllElements(const Container &rContainer, const css::uno::Reference< css::util::XModifyListener > &xListener)
void addListenerToAllElements(const Container &rContainer, const css::uno::Reference< css::util::XModifyListener > &xListener)
void setPropertyValueDefault(tPropertyValueMap &rOutMap, tPropertyValueMapKey key, const Value &value)
Calls setPropertyValue() but asserts that the given property hasn't been set before.
void setPropertyValue(tPropertyValueMap &rOutMap, tPropertyValueMapKey key, const Value &value)
Set a property to a certain value in the given map.
::cppu::WeakImplHelper< css::lang::XServiceInfo, css::util::XCloneable, css::util::XModifyBroadcaster, css::util::XModifyListener, css::chart2::XTitle > RegressionEquation_Base
std::unordered_map< tPropertyValueMapKey, css::uno::Any > tPropertyValueMap
DstType sequenceToContainer(const css::uno::Sequence< SrcType > &i_Sequence)
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
IMPLEMENT_FORWARD_XINTERFACE2(ChildWindowPane, ChildWindowPaneInterfaceBase, Pane)
sal_Int32 nHandle
unsigned char sal_Bool
constexpr OUStringLiteral CHART_UNONAME_NUMFMT
Definition: unonames.hxx:20