Coverage Report

Created: 2026-02-14 09:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/chart2/source/controller/itemsetwrapper/RegressionCurveItemConverter.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 <RegressionCurveHelper.hxx>
21
#include <RegressionCurveModel.hxx>
22
#include <RegressionCurveItemConverter.hxx>
23
#include "SchWhichPairs.hxx"
24
#include <GraphicPropertyItemConverter.hxx>
25
#include <DataSeries.hxx>
26
#include <ChartModel.hxx>
27
28
#include <com/sun/star/chart2/XRegressionCurve.hpp>
29
#include <osl/diagnose.h>
30
31
#include <svl/eitem.hxx>
32
#include <svl/intitem.hxx>
33
#include <svl/stritem.hxx>
34
#include <utility>
35
36
using namespace ::com::sun::star;
37
38
namespace
39
{
40
template <class T, class D>
41
bool lclConvertToPropertySet(const SfxItemSet& rItemSet, sal_uInt16 nWhichId, const uno::Reference<beans::XPropertySet>& xProperties, const OUString& aPropertyID)
42
0
{
43
0
    OSL_ASSERT(xProperties.is());
44
0
    if( xProperties.is() )
45
0
    {
46
0
        T aValue = static_cast<T>(static_cast<const D&>(rItemSet.Get( nWhichId )).GetValue());
47
0
        T aOldValue = aValue;
48
0
        bool aSuccess = xProperties->getPropertyValue( aPropertyID ) >>= aOldValue;
49
0
        if (!aSuccess || aOldValue != aValue)
50
0
        {
51
0
            xProperties->setPropertyValue( aPropertyID , uno::Any( aValue ));
52
0
            return true;
53
0
        }
54
0
    }
55
0
    return false;
56
0
}
Unexecuted instantiation: RegressionCurveItemConverter.cxx:bool (anonymous namespace)::lclConvertToPropertySet<int, SfxInt32Item>(SfxItemSet const&, unsigned short, com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet> const&, rtl::OUString const&)
Unexecuted instantiation: RegressionCurveItemConverter.cxx:bool (anonymous namespace)::lclConvertToPropertySet<double, SvxDoubleItem>(SfxItemSet const&, unsigned short, com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet> const&, rtl::OUString const&)
Unexecuted instantiation: RegressionCurveItemConverter.cxx:bool (anonymous namespace)::lclConvertToPropertySet<bool, SfxBoolItem>(SfxItemSet const&, unsigned short, com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet> const&, rtl::OUString const&)
Unexecuted instantiation: RegressionCurveItemConverter.cxx:bool (anonymous namespace)::lclConvertToPropertySet<rtl::OUString, SfxStringItem>(SfxItemSet const&, unsigned short, com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet> const&, rtl::OUString const&)
57
58
template <class T, class D>
59
void lclConvertToItemSet(SfxItemSet& rItemSet, sal_uInt16 nWhichId, const uno::Reference<beans::XPropertySet>& xProperties, const OUString& aPropertyID)
60
0
{
61
0
    OSL_ASSERT(xProperties.is());
62
0
    if( xProperties.is() )
63
0
    {
64
0
        T aValue = static_cast<T>(static_cast<const D&>(rItemSet.Get( nWhichId )).GetValue());
65
0
        if(xProperties->getPropertyValue( aPropertyID ) >>= aValue)
66
0
        {
67
0
            rItemSet.Put(D( nWhichId, aValue ));
68
0
        }
69
0
    }
70
0
}
Unexecuted instantiation: RegressionCurveItemConverter.cxx:void (anonymous namespace)::lclConvertToItemSet<int, SfxInt32Item>(SfxItemSet&, unsigned short, com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet> const&, rtl::OUString const&)
Unexecuted instantiation: RegressionCurveItemConverter.cxx:void (anonymous namespace)::lclConvertToItemSet<bool, SfxBoolItem>(SfxItemSet&, unsigned short, com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet> const&, rtl::OUString const&)
Unexecuted instantiation: RegressionCurveItemConverter.cxx:void (anonymous namespace)::lclConvertToItemSet<rtl::OUString, SfxStringItem>(SfxItemSet&, unsigned short, com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet> const&, rtl::OUString const&)
71
72
void lclConvertToItemSetDouble(SfxItemSet& rItemSet, TypedWhichId<SvxDoubleItem> nWhichId, const uno::Reference<beans::XPropertySet>& xProperties, const OUString& aPropertyID)
73
0
{
74
0
    OSL_ASSERT(xProperties.is());
75
0
    if( xProperties.is() )
76
0
    {
77
0
        double aValue = rItemSet.Get( nWhichId ).GetValue();
78
0
        if(xProperties->getPropertyValue( aPropertyID ) >>= aValue)
79
0
        {
80
0
            rItemSet.Put(SvxDoubleItem( aValue, nWhichId ));
81
0
        }
82
0
    }
83
0
}
84
85
} // anonymous namespace
86
87
namespace chart::wrapper
88
{
89
90
RegressionCurveItemConverter::RegressionCurveItemConverter(
91
    const uno::Reference< beans::XPropertySet >& rPropertySet,
92
    rtl::Reference< DataSeries > xContainer,
93
    SfxItemPool& rItemPool,
94
    SdrModel& rDrawModel,
95
    const rtl::Reference< ChartModel > & xChartModel ) :
96
0
        ItemConverter( rPropertySet, rItemPool ),
97
0
        m_spGraphicConverter( std::make_shared<GraphicPropertyItemConverter>(
98
0
                                  rPropertySet, rItemPool, rDrawModel,
99
0
                                  xChartModel,
100
0
                                  GraphicObjectType::LineProperties )),
101
0
        m_xCurveContainer(std::move( xContainer ))
102
0
{}
103
104
RegressionCurveItemConverter::~RegressionCurveItemConverter()
105
0
{}
106
107
void RegressionCurveItemConverter::FillItemSet( SfxItemSet & rOutItemSet ) const
108
0
{
109
0
    m_spGraphicConverter->FillItemSet( rOutItemSet );
110
111
    // own items
112
0
    ItemConverter::FillItemSet( rOutItemSet );
113
0
}
114
115
bool RegressionCurveItemConverter::ApplyItemSet( const SfxItemSet & rItemSet )
116
0
{
117
0
    bool bResult = m_spGraphicConverter->ApplyItemSet( rItemSet );
118
119
    // own items
120
0
    return ItemConverter::ApplyItemSet( rItemSet ) || bResult;
121
0
}
122
123
const WhichRangesContainer& RegressionCurveItemConverter::GetWhichPairs() const
124
0
{
125
    // must span all used items!
126
0
    return nRegressionCurveWhichPairs;
127
0
}
128
129
bool RegressionCurveItemConverter::GetItemProperty(
130
    tWhichIdType /* nWhichId */, tPropertyNameWithMemberId & /* rOutProperty */ ) const
131
0
{
132
    // No own (non-special) properties
133
0
    return false;
134
0
}
135
136
bool RegressionCurveItemConverter::ApplySpecialItem(
137
    sal_uInt16 nWhichId, const SfxItemSet & rItemSet )
138
0
{
139
0
    uno::Reference< chart2::XRegressionCurve > xCurve( GetPropertySet(), uno::UNO_QUERY );
140
0
    bool bChanged = false;
141
142
0
    OSL_ASSERT(xCurve.is());
143
0
    if(!xCurve.is())
144
0
        return false;
145
146
0
    switch( nWhichId )
147
0
    {
148
0
        case SCHATTR_REGRESSION_TYPE:
149
0
        {
150
0
            SvxChartRegress eRegress = RegressionCurveHelper::getRegressionType(xCurve);
151
0
            SvxChartRegress eNewRegress = static_cast< const SvxChartRegressItem & >(
152
0
                rItemSet.Get( nWhichId )).GetValue();
153
0
            if( eRegress != eNewRegress )
154
0
            {
155
                // note that changing the regression type changes the object
156
                // for which this converter was created. Not optimal, but
157
                // currently the only way to handle the type in the
158
                // regression curve properties dialog
159
0
                xCurve = RegressionCurveHelper::changeRegressionCurveType(
160
0
                            eNewRegress,
161
0
                            m_xCurveContainer,
162
0
                            xCurve);
163
0
                uno::Reference<beans::XPropertySet> xProperties( xCurve, uno::UNO_QUERY );
164
0
                resetPropertySet( xProperties );
165
0
                bChanged = true;
166
0
            }
167
0
        }
168
0
        break;
169
170
0
        case SCHATTR_REGRESSION_DEGREE:
171
0
        {
172
0
            uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
173
0
            bChanged = lclConvertToPropertySet<sal_Int32, SfxInt32Item>(rItemSet, nWhichId, xProperties, u"PolynomialDegree"_ustr);
174
0
        }
175
0
        break;
176
177
0
        case SCHATTR_REGRESSION_PERIOD:
178
0
        {
179
0
            uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
180
0
            bChanged = lclConvertToPropertySet<sal_Int32, SfxInt32Item>(rItemSet, nWhichId, xProperties, u"MovingAveragePeriod"_ustr);
181
0
        }
182
0
        break;
183
184
0
        case SCHATTR_REGRESSION_EXTRAPOLATE_FORWARD:
185
0
        {
186
0
            uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
187
0
            bChanged = lclConvertToPropertySet<double, SvxDoubleItem>(rItemSet, nWhichId, xProperties, u"ExtrapolateForward"_ustr);
188
0
        }
189
0
        break;
190
191
0
        case SCHATTR_REGRESSION_EXTRAPOLATE_BACKWARD:
192
0
        {
193
0
            uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
194
0
            bChanged = lclConvertToPropertySet<double, SvxDoubleItem>(rItemSet, nWhichId, xProperties, u"ExtrapolateBackward"_ustr);
195
0
        }
196
0
        break;
197
198
0
        case SCHATTR_REGRESSION_SET_INTERCEPT:
199
0
        {
200
0
            uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
201
0
            bChanged = lclConvertToPropertySet<bool, SfxBoolItem>(rItemSet, nWhichId, xProperties, u"ForceIntercept"_ustr);
202
0
        }
203
0
        break;
204
205
0
        case SCHATTR_REGRESSION_INTERCEPT_VALUE:
206
0
        {
207
0
            uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
208
0
            bChanged = lclConvertToPropertySet<double, SvxDoubleItem>(rItemSet, nWhichId, xProperties, u"InterceptValue"_ustr);
209
0
        }
210
0
        break;
211
212
0
        case SCHATTR_REGRESSION_CURVE_NAME:
213
0
        {
214
0
            uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
215
0
            bChanged = lclConvertToPropertySet<OUString, SfxStringItem>(rItemSet, nWhichId, xProperties, u"CurveName"_ustr);
216
0
        }
217
0
        break;
218
219
0
        case SCHATTR_REGRESSION_MOVING_TYPE:
220
0
        {
221
0
            uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
222
0
            bChanged = lclConvertToPropertySet<sal_Int32, SfxInt32Item>(rItemSet, nWhichId, xProperties, u"MovingAverageType"_ustr);
223
0
        }
224
0
        break;
225
226
0
        case SCHATTR_REGRESSION_SHOW_EQUATION:
227
0
        {
228
0
            uno::Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties());
229
0
            bChanged = lclConvertToPropertySet<bool, SfxBoolItem>(rItemSet, nWhichId, xEqProp, u"ShowEquation"_ustr);
230
0
        }
231
0
        break;
232
233
0
        case SCHATTR_REGRESSION_XNAME:
234
0
        {
235
0
            uno::Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties());
236
0
            bChanged = lclConvertToPropertySet<OUString, SfxStringItem>(rItemSet, nWhichId, xEqProp, u"XName"_ustr);
237
0
        }
238
0
        break;
239
240
0
        case SCHATTR_REGRESSION_YNAME:
241
0
        {
242
0
            uno::Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties());
243
0
            bChanged = lclConvertToPropertySet<OUString, SfxStringItem>(rItemSet, nWhichId, xEqProp, u"YName"_ustr);
244
0
        }
245
0
        break;
246
247
0
        case SCHATTR_REGRESSION_SHOW_COEFF:
248
0
        {
249
0
            uno::Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties());
250
0
            bChanged = lclConvertToPropertySet<bool, SfxBoolItem>(rItemSet, nWhichId, xEqProp, u"ShowCorrelationCoefficient"_ustr);
251
0
        }
252
0
        break;
253
254
0
    }
255
0
    return bChanged;
256
0
}
257
258
void RegressionCurveItemConverter::FillSpecialItem(sal_uInt16 nWhichId, SfxItemSet& rOutItemSet ) const
259
0
{
260
0
    uno::Reference<chart2::XRegressionCurve> xCurve(GetPropertySet(), uno::UNO_QUERY);
261
0
    OSL_ASSERT(xCurve.is());
262
0
    if(!xCurve.is())
263
0
        return;
264
265
0
    uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
266
267
0
    switch( nWhichId )
268
0
    {
269
0
        case SCHATTR_REGRESSION_TYPE:
270
0
        {
271
0
            SvxChartRegress eRegress = RegressionCurveHelper::getRegressionType(xCurve);
272
0
            rOutItemSet.Put( SvxChartRegressItem( eRegress, SCHATTR_REGRESSION_TYPE ));
273
0
        }
274
0
        break;
275
276
0
        case SCHATTR_REGRESSION_DEGREE:
277
0
        {
278
0
            lclConvertToItemSet<sal_Int32, SfxInt32Item>(rOutItemSet, nWhichId, xProperties, u"PolynomialDegree"_ustr);
279
0
        }
280
0
        break;
281
282
0
        case SCHATTR_REGRESSION_PERIOD:
283
0
        {
284
0
            lclConvertToItemSet<sal_Int32, SfxInt32Item>(rOutItemSet, nWhichId, xProperties, u"MovingAveragePeriod"_ustr);
285
0
        }
286
0
        break;
287
288
0
        case SCHATTR_REGRESSION_EXTRAPOLATE_FORWARD:
289
0
        {
290
0
            lclConvertToItemSetDouble(rOutItemSet, SCHATTR_REGRESSION_EXTRAPOLATE_FORWARD, xProperties, u"ExtrapolateForward"_ustr);
291
0
        }
292
0
        break;
293
294
0
        case SCHATTR_REGRESSION_EXTRAPOLATE_BACKWARD:
295
0
        {
296
0
            lclConvertToItemSetDouble(rOutItemSet, SCHATTR_REGRESSION_EXTRAPOLATE_BACKWARD, xProperties, u"ExtrapolateBackward"_ustr);
297
0
        }
298
0
        break;
299
300
0
        case SCHATTR_REGRESSION_SET_INTERCEPT:
301
0
        {
302
0
            lclConvertToItemSet<bool, SfxBoolItem>(rOutItemSet, nWhichId, xProperties, u"ForceIntercept"_ustr);
303
0
        }
304
0
        break;
305
306
0
        case SCHATTR_REGRESSION_INTERCEPT_VALUE:
307
0
        {
308
0
            lclConvertToItemSetDouble(rOutItemSet, SCHATTR_REGRESSION_INTERCEPT_VALUE, xProperties, u"InterceptValue"_ustr);
309
0
        }
310
0
        break;
311
312
0
        case SCHATTR_REGRESSION_CURVE_NAME:
313
0
        {
314
0
            lclConvertToItemSet<OUString, SfxStringItem>(rOutItemSet, nWhichId, xProperties, u"CurveName"_ustr);
315
0
        }
316
0
        break;
317
318
0
        case SCHATTR_REGRESSION_MOVING_TYPE:
319
0
        {
320
0
            lclConvertToItemSet<sal_Int32, SfxInt32Item>(rOutItemSet, nWhichId, xProperties, u"MovingAverageType"_ustr);
321
0
        }
322
0
        break;
323
324
0
        case SCHATTR_REGRESSION_SHOW_EQUATION:
325
0
        {
326
0
            lclConvertToItemSet<bool, SfxBoolItem>(rOutItemSet, nWhichId, xCurve->getEquationProperties(), u"ShowEquation"_ustr);
327
0
        }
328
0
        break;
329
330
0
        case SCHATTR_REGRESSION_XNAME:
331
0
        {
332
0
            lclConvertToItemSet<OUString, SfxStringItem>(rOutItemSet, nWhichId, xCurve->getEquationProperties(), u"XName"_ustr);
333
0
        }
334
0
        break;
335
336
0
        case SCHATTR_REGRESSION_YNAME:
337
0
        {
338
0
            lclConvertToItemSet<OUString, SfxStringItem>(rOutItemSet, nWhichId, xCurve->getEquationProperties(), u"YName"_ustr);
339
0
        }
340
0
        break;
341
342
0
        case SCHATTR_REGRESSION_SHOW_COEFF:
343
0
        {
344
0
            lclConvertToItemSet<bool, SfxBoolItem>(rOutItemSet, nWhichId, xCurve->getEquationProperties(), u"ShowCorrelationCoefficient"_ustr);
345
0
        }
346
0
        break;
347
0
    }
348
0
}
349
350
} //  namespace chart::wrapper
351
352
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */