Coverage Report

Created: 2026-06-30 11:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/chart2/source/tools/RegressionEquation.cxx
Line
Count
Source
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
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>
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
39
namespace com::sun::star::uno { class XComponentContext; }
40
41
using namespace ::com::sun::star;
42
43
using ::com::sun::star::uno::Reference;
44
using ::com::sun::star::beans::Property;
45
using ::osl::MutexGuard;
46
47
namespace
48
{
49
50
enum
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
62
void lcl_AddPropertiesToVector(
63
    std::vector< Property > & rOutProperties )
64
0
{
65
0
    rOutProperties.emplace_back( "ShowEquation",
66
0
                  PROP_EQUATION_SHOW,
67
0
                  cppu::UnoType<bool>::get(),
68
0
                  beans::PropertyAttribute::BOUND
69
0
                  | beans::PropertyAttribute::MAYBEDEFAULT );
70
71
0
    rOutProperties.emplace_back( "XName",
72
0
                  PROP_EQUATION_XNAME,
73
0
                  cppu::UnoType<OUString>::get(),
74
0
                  beans::PropertyAttribute::BOUND
75
0
                  | beans::PropertyAttribute::MAYBEDEFAULT );
76
77
0
    rOutProperties.emplace_back( "YName",
78
0
                  PROP_EQUATION_YNAME,
79
0
                  cppu::UnoType<OUString>::get(),
80
0
                  beans::PropertyAttribute::BOUND
81
0
                  | beans::PropertyAttribute::MAYBEDEFAULT );
82
83
0
    rOutProperties.emplace_back( "ShowCorrelationCoefficient",
84
0
                  PROP_EQUATION_SHOW_CORRELATION_COEFF,
85
0
                  cppu::UnoType<bool>::get(),
86
0
                  beans::PropertyAttribute::BOUND
87
0
                  | beans::PropertyAttribute::MAYBEDEFAULT );
88
89
0
    rOutProperties.emplace_back( "MayHaveCorrelationCoefficient",
90
0
                  PROP_EQUATION_MAY_HAVE_CORRELATION_COEFF,
91
0
                  cppu::UnoType<bool>::get(),
92
0
                  beans::PropertyAttribute::BOUND
93
0
                  | beans::PropertyAttribute::MAYBEDEFAULT );
94
95
0
    rOutProperties.emplace_back( "ReferencePageSize",
96
0
                  PROP_EQUATION_REF_PAGE_SIZE,
97
0
                  cppu::UnoType<awt::Size>::get(),
98
0
                  beans::PropertyAttribute::BOUND
99
0
                  | beans::PropertyAttribute::MAYBEVOID );
100
101
0
    rOutProperties.emplace_back( "RelativePosition",
102
0
                  PROP_EQUATION_REL_POS,
103
0
                  cppu::UnoType<chart2::RelativePosition>::get(),
104
0
                  beans::PropertyAttribute::BOUND
105
0
                  | beans::PropertyAttribute::MAYBEVOID );
106
107
0
    rOutProperties.emplace_back( CHART_UNONAME_NUMFMT,
108
0
                  PROP_EQUATION_NUMBER_FORMAT,
109
0
                  cppu::UnoType<sal_Int32>::get(),
110
0
                  beans::PropertyAttribute::BOUND
111
0
                  | beans::PropertyAttribute::MAYBEVOID );
112
0
}
113
114
::chart::tPropertyValueMap& GetStaticRegressionEquationDefaults()
115
0
{
116
0
    static ::chart::tPropertyValueMap aStaticDefaults =
117
0
        [](){
118
0
            ::chart::tPropertyValueMap aOutMap;
119
0
            ::chart::LinePropertiesHelper::AddDefaultsToMap( aOutMap );
120
0
            ::chart::FillProperties::AddDefaultsToMap( aOutMap );
121
0
            ::chart::CharacterProperties::AddDefaultsToMap( aOutMap );
122
123
0
            ::chart::PropertyHelper::setPropertyValueDefault( aOutMap, PROP_EQUATION_SHOW, false );
124
0
            ::chart::PropertyHelper::setPropertyValueDefault( aOutMap, PROP_EQUATION_XNAME, u"x"_ustr );
125
0
            ::chart::PropertyHelper::setPropertyValueDefault( aOutMap, PROP_EQUATION_YNAME, u"f(x)"_ustr );
126
0
            ::chart::PropertyHelper::setPropertyValueDefault( aOutMap, PROP_EQUATION_SHOW_CORRELATION_COEFF, false );
127
0
            ::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
0
            ::chart::PropertyHelper::setPropertyValue( aOutMap, ::chart::FillProperties::PROP_FILL_STYLE, drawing::FillStyle_NONE );
132
0
            ::chart::PropertyHelper::setPropertyValue( aOutMap, ::chart::LinePropertiesHelper::PROP_LINE_STYLE, drawing::LineStyle_NONE );
133
134
0
            float fDefaultCharHeight = 10.0;
135
0
            ::chart::PropertyHelper::setPropertyValue( aOutMap, ::chart::CharacterProperties::PROP_CHAR_CHAR_HEIGHT, fDefaultCharHeight );
136
0
            ::chart::PropertyHelper::setPropertyValue( aOutMap, ::chart::CharacterProperties::PROP_CHAR_ASIAN_CHAR_HEIGHT, fDefaultCharHeight );
137
0
            ::chart::PropertyHelper::setPropertyValue( aOutMap, ::chart::CharacterProperties::PROP_CHAR_COMPLEX_CHAR_HEIGHT, fDefaultCharHeight );
138
0
            return aOutMap;
139
0
        }();
140
0
    return aStaticDefaults;
141
0
};
142
143
::cppu::OPropertyArrayHelper& GetStaticRegressionEquationInfoHelper()
144
0
{
145
0
    static ::cppu::OPropertyArrayHelper aPropHelper =
146
0
        [](){
147
0
            std::vector< css::beans::Property > aProperties;
148
0
            lcl_AddPropertiesToVector( aProperties );
149
0
            ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties );
150
0
            ::chart::FillProperties::AddPropertiesToVector( aProperties );
151
0
            ::chart::CharacterProperties::AddPropertiesToVector( aProperties );
152
0
            ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
153
154
0
            std::sort( aProperties.begin(), aProperties.end(),
155
0
                         ::chart::PropertyNameLess() );
156
157
0
            return comphelper::containerToSequence( aProperties );
158
0
        }();
159
0
    return aPropHelper;
160
0
};
161
162
const uno::Reference< beans::XPropertySetInfo > & GetStaticRegressionEquationInfo()
163
0
{
164
0
    static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
165
0
        ::cppu::OPropertySetHelper::createPropertySetInfo(GetStaticRegressionEquationInfoHelper()) );
166
0
    return xPropertySetInfo;
167
0
};
168
169
} // anonymous namespace
170
171
namespace chart
172
{
173
174
RegressionEquation::RegressionEquation() :
175
0
        m_xModifyEventForwarder( new ModifyEventForwarder())
176
0
{}
177
178
RegressionEquation::RegressionEquation( const RegressionEquation & rOther ) :
179
0
        impl::RegressionEquation_Base(rOther),
180
0
        ::property::OPropertySet( rOther ),
181
0
    m_xModifyEventForwarder( new ModifyEventForwarder())
182
0
{}
183
184
RegressionEquation::~RegressionEquation()
185
0
{}
186
187
// ____ XCloneable ____
188
uno::Reference< util::XCloneable > SAL_CALL RegressionEquation::createClone()
189
0
{
190
0
    return uno::Reference< util::XCloneable >( new RegressionEquation( *this ));
191
0
}
192
193
// ____ OPropertySet ____
194
void RegressionEquation::GetDefaultValue( sal_Int32 nHandle, uno::Any& rAny ) const
195
0
{
196
0
    const tPropertyValueMap& rStaticDefaults = GetStaticRegressionEquationDefaults();
197
0
    tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
198
0
    if( aFound == rStaticDefaults.end() )
199
0
        rAny.clear();
200
0
    else
201
0
        rAny = (*aFound).second;
202
0
}
203
204
::cppu::IPropertyArrayHelper & SAL_CALL RegressionEquation::getInfoHelper()
205
0
{
206
0
    return GetStaticRegressionEquationInfoHelper();
207
0
}
208
209
// ____ XPropertySet ____
210
Reference< beans::XPropertySetInfo > SAL_CALL RegressionEquation::getPropertySetInfo()
211
0
{
212
0
    return GetStaticRegressionEquationInfo();
213
0
}
214
215
// ____ XModifyBroadcaster ____
216
void SAL_CALL RegressionEquation::addModifyListener( const uno::Reference< util::XModifyListener >& aListener )
217
0
{
218
0
    m_xModifyEventForwarder->addModifyListener( aListener );
219
0
}
220
221
void SAL_CALL RegressionEquation::removeModifyListener( const uno::Reference< util::XModifyListener >& aListener )
222
0
{
223
0
    m_xModifyEventForwarder->removeModifyListener( aListener );
224
0
}
225
226
// ____ XModifyListener ____
227
void SAL_CALL RegressionEquation::modified( const lang::EventObject& aEvent )
228
0
{
229
0
    m_xModifyEventForwarder->modified( aEvent );
230
0
}
231
232
// ____ XEventListener (base of XModifyListener) ____
233
void SAL_CALL RegressionEquation::disposing( const lang::EventObject& /* Source */ )
234
0
{
235
    // nothing
236
0
}
237
238
// ____ OPropertySet ____
239
void RegressionEquation::firePropertyChangeEvent()
240
0
{
241
0
    fireModifyEvent();
242
0
}
243
244
void RegressionEquation::fireModifyEvent()
245
0
{
246
0
    m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
247
0
}
248
249
// ____ XTitle ____
250
uno::Sequence< uno::Reference< chart2::XFormattedString > > SAL_CALL RegressionEquation::getText()
251
0
{
252
0
    MutexGuard aGuard( m_aMutex );
253
0
    return m_aStrings;
254
0
}
255
256
void SAL_CALL RegressionEquation::setText( const uno::Sequence< uno::Reference< chart2::XFormattedString > >& Strings )
257
0
{
258
0
    MutexGuard aGuard( m_aMutex );
259
0
    ModifyListenerHelper::removeListenerFromAllElements(
260
0
        comphelper::sequenceToContainer<std::vector<uno::Reference< chart2::XFormattedString > > >( m_aStrings ),
261
0
        m_xModifyEventForwarder );
262
0
    m_aStrings = Strings;
263
0
    ModifyListenerHelper::addListenerToAllElements(
264
0
        comphelper::sequenceToContainer<std::vector<uno::Reference< chart2::XFormattedString > > >( m_aStrings ),
265
0
        m_xModifyEventForwarder );
266
0
    fireModifyEvent();
267
0
}
268
269
OUString SAL_CALL RegressionEquation::getImplementationName()
270
0
{
271
0
    return u"com.sun.star.comp.chart2.RegressionEquation"_ustr;
272
0
}
273
274
sal_Bool SAL_CALL RegressionEquation::supportsService( const OUString& rServiceName )
275
0
{
276
0
    return cppu::supportsService(this, rServiceName);
277
0
}
278
279
css::uno::Sequence< OUString > SAL_CALL RegressionEquation::getSupportedServiceNames()
280
0
{
281
0
    return { u"com.sun.star.chart2.RegressionEquation"_ustr,
282
0
             u"com.sun.star.beans.PropertySet"_ustr,
283
0
             u"com.sun.star.drawing.FillProperties"_ustr,
284
0
             u"com.sun.star.drawing.LineProperties"_ustr,
285
0
             u"com.sun.star.style.CharacterProperties"_ustr };
286
0
}
287
288
using impl::RegressionEquation_Base;
289
290
IMPLEMENT_FORWARD_XINTERFACE2( RegressionEquation, RegressionEquation_Base, ::property::OPropertySet )
291
292
} //  namespace chart
293
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 &)
297
0
{
298
0
    return cppu::acquire(new ::chart::RegressionEquation);
299
0
}
300
301
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */