Coverage Report

Created: 2025-12-08 09:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/chart2/source/controller/itemsetwrapper/StatisticsItemConverter.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 <StatisticsItemConverter.hxx>
21
#include "SchWhichPairs.hxx"
22
#include <RegressionCurveHelper.hxx>
23
#include <RegressionCurveModel.hxx>
24
#include <ErrorBar.hxx>
25
#include <StatisticsHelper.hxx>
26
#include <ChartModel.hxx>
27
#include <unonames.hxx>
28
29
#include <svl/stritem.hxx>
30
#include <svx/chrtitem.hxx>
31
#include <svl/intitem.hxx>
32
#include <rtl/math.hxx>
33
34
#include <com/sun/star/chart2/XInternalDataProvider.hpp>
35
#include <com/sun/star/chart2/XRegressionCurveContainer.hpp>
36
#include <com/sun/star/chart/ErrorBarStyle.hpp>
37
#include <utility>
38
#include <comphelper/diagnose_ex.hxx>
39
40
using namespace ::com::sun::star;
41
42
namespace
43
{
44
45
uno::Reference< beans::XPropertySet > lcl_GetErrorBar(
46
    const uno::Reference< beans::XPropertySet > & xProp, bool bYError )
47
0
{
48
0
    uno::Reference< beans::XPropertySet > xResult;
49
50
0
    if( xProp.is())
51
0
        try
52
0
        {
53
0
        ( xProp->getPropertyValue( bYError ? CHART_UNONAME_ERRORBAR_Y : CHART_UNONAME_ERRORBAR_X ) >>= xResult );
54
0
        }
55
0
        catch( const uno::Exception & )
56
0
        {
57
0
            DBG_UNHANDLED_EXCEPTION("chart2");
58
0
        }
59
60
0
    return xResult;
61
0
}
62
63
uno::Reference< beans::XPropertySet > lcl_GetDefaultErrorBar()
64
0
{
65
0
    return uno::Reference< beans::XPropertySet >( new ::chart::ErrorBar );
66
0
}
67
68
void lcl_getErrorValues( const uno::Reference< beans::XPropertySet > & xErrorBarProp,
69
                    double & rOutPosError, double & rOutNegError )
70
0
{
71
0
    if( ! xErrorBarProp.is())
72
0
        return;
73
74
0
    try
75
0
    {
76
0
        xErrorBarProp->getPropertyValue( u"PositiveError"_ustr ) >>= rOutPosError;
77
0
        xErrorBarProp->getPropertyValue( u"NegativeError"_ustr ) >>= rOutNegError;
78
0
    }
79
0
    catch( const uno::Exception & )
80
0
    {
81
0
        DBG_UNHANDLED_EXCEPTION("chart2");
82
0
    }
83
0
}
84
85
void lcl_getErrorIndicatorValues(
86
    const uno::Reference< beans::XPropertySet > & xErrorBarProp,
87
    bool & rOutShowPosError, bool & rOutShowNegError )
88
0
{
89
0
    if( ! xErrorBarProp.is())
90
0
        return;
91
92
0
    try
93
0
    {
94
0
        xErrorBarProp->getPropertyValue( u"ShowPositiveError"_ustr ) >>= rOutShowPosError;
95
0
        xErrorBarProp->getPropertyValue( u"ShowNegativeError"_ustr ) >>= rOutShowNegError;
96
0
    }
97
0
    catch( const uno::Exception & )
98
0
    {
99
0
        DBG_UNHANDLED_EXCEPTION("chart2");
100
0
    }
101
0
}
102
103
uno::Reference< beans::XPropertySet > lcl_getEquationProperties(
104
    const uno::Reference< beans::XPropertySet > & xSeriesPropSet, const SfxItemSet * pItemSet )
105
0
{
106
0
    bool bEquationExists = true;
107
108
    // ensure that a trendline is on
109
0
    if( pItemSet )
110
0
    {
111
0
        if( const SvxChartRegressItem* pRegressionItem = pItemSet->GetItemIfSet( SCHATTR_REGRESSION_TYPE ) )
112
0
        {
113
0
            SvxChartRegress eRegress = pRegressionItem->GetValue();
114
0
            bEquationExists = ( eRegress != SvxChartRegress::NONE );
115
0
        }
116
0
    }
117
118
0
    if( bEquationExists )
119
0
    {
120
0
        uno::Reference< chart2::XRegressionCurveContainer > xRegCnt( xSeriesPropSet, uno::UNO_QUERY );
121
0
        rtl::Reference< ::chart::RegressionCurveModel > xCurve =
122
0
            ::chart::RegressionCurveHelper::getFirstCurveNotMeanValueLine( xRegCnt );
123
0
        if( xCurve.is())
124
0
        {
125
0
            return xCurve->getEquationProperties();
126
0
        }
127
0
    }
128
129
0
    return uno::Reference< beans::XPropertySet >();
130
0
}
131
132
uno::Reference< beans::XPropertySet > lcl_getCurveProperties(
133
    const uno::Reference< beans::XPropertySet > & xSeriesPropSet, const SfxItemSet * pItemSet )
134
0
{
135
0
    bool bExists = true;
136
137
    // ensure that a trendline is on
138
0
    if( pItemSet )
139
0
    {
140
0
        if( const SvxChartRegressItem* pRegressionItem = pItemSet->GetItemIfSet( SCHATTR_REGRESSION_TYPE ) )
141
0
        {
142
0
            SvxChartRegress eRegress = pRegressionItem->GetValue();
143
0
            bExists = ( eRegress != SvxChartRegress::NONE );
144
0
        }
145
0
    }
146
147
0
    if( bExists )
148
0
    {
149
0
        uno::Reference< chart2::XRegressionCurveContainer > xRegCnt( xSeriesPropSet, uno::UNO_QUERY );
150
0
        rtl::Reference< ::chart::RegressionCurveModel > xCurve(
151
0
            ::chart::RegressionCurveHelper::getFirstCurveNotMeanValueLine( xRegCnt ));
152
0
        if( xCurve.is())
153
0
            return xCurve;
154
0
    }
155
156
0
    return uno::Reference< beans::XPropertySet >();
157
0
}
158
159
template <class T, class D>
160
bool lclConvertToPropertySet(const SfxItemSet& rItemSet, sal_uInt16 nWhichId, const uno::Reference<beans::XPropertySet>& xProperties, const OUString& aPropertyID)
161
0
{
162
0
    OSL_ASSERT(xProperties.is());
163
0
    if( xProperties.is() )
164
0
    {
165
0
        T aValue = static_cast<T>(static_cast<const D&>(rItemSet.Get( nWhichId )).GetValue());
166
0
        T aOldValue = aValue;
167
0
        bool aSuccess = xProperties->getPropertyValue( aPropertyID ) >>= aOldValue;
168
0
        if (!aSuccess || aOldValue != aValue)
169
0
        {
170
0
            xProperties->setPropertyValue( aPropertyID , uno::Any( aValue ));
171
0
            return true;
172
0
        }
173
0
    }
174
0
    return false;
175
0
}
Unexecuted instantiation: StatisticsItemConverter.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: StatisticsItemConverter.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: StatisticsItemConverter.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: StatisticsItemConverter.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&)
176
177
template <class T, class D>
178
void lclConvertToItemSet(SfxItemSet& rItemSet, sal_uInt16 nWhichId, const uno::Reference<beans::XPropertySet>& xProperties, const OUString& aPropertyID)
179
0
{
180
0
    OSL_ASSERT(xProperties.is());
181
0
    if( xProperties.is() )
182
0
    {
183
0
        T aValue = static_cast<T>(static_cast<const D&>(rItemSet.Get( nWhichId )).GetValue());
184
0
        if(xProperties->getPropertyValue( aPropertyID ) >>= aValue)
185
0
        {
186
0
            rItemSet.Put(D( nWhichId, aValue ));
187
0
        }
188
0
    }
189
0
}
Unexecuted instantiation: StatisticsItemConverter.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: StatisticsItemConverter.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: StatisticsItemConverter.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&)
190
191
void lclConvertToItemSetDouble(SfxItemSet& rItemSet, TypedWhichId<SvxDoubleItem> nWhichId, const uno::Reference<beans::XPropertySet>& xProperties, const OUString& aPropertyID)
192
0
{
193
0
    OSL_ASSERT(xProperties.is());
194
0
    if( xProperties.is() )
195
0
    {
196
0
        double aValue = rItemSet.Get( nWhichId ).GetValue();
197
0
        if(xProperties->getPropertyValue( aPropertyID ) >>= aValue)
198
0
        {
199
0
            rItemSet.Put(SvxDoubleItem( aValue, nWhichId ));
200
0
        }
201
0
    }
202
0
}
203
204
} // anonymous namespace
205
206
namespace chart::wrapper
207
{
208
209
StatisticsItemConverter::StatisticsItemConverter(
210
    rtl::Reference<::chart::ChartModel> xModel,
211
    const uno::Reference< beans::XPropertySet > & rPropertySet,
212
    SfxItemPool& rItemPool ) :
213
0
        ItemConverter( rPropertySet, rItemPool ),
214
0
        m_xModel(std::move( xModel ))
215
0
{
216
0
}
217
218
StatisticsItemConverter::~StatisticsItemConverter()
219
0
{
220
0
}
221
222
const WhichRangesContainer& StatisticsItemConverter::GetWhichPairs() const
223
0
{
224
    // must span all used items!
225
0
    return nStatWhichPairs;
226
0
}
227
228
bool StatisticsItemConverter::GetItemProperty(
229
    tWhichIdType /* nWhichId */,
230
    tPropertyNameWithMemberId & /* rOutProperty */ ) const
231
0
{
232
0
    return false;
233
0
}
234
235
bool StatisticsItemConverter::ApplySpecialItem(
236
    sal_uInt16 nWhichId, const SfxItemSet & rItemSet )
237
0
{
238
0
    bool bChanged = false;
239
240
0
    switch( nWhichId )
241
0
    {
242
0
        case SCHATTR_STAT_AVERAGE:
243
0
        {
244
0
            uno::Reference< chart2::XRegressionCurveContainer > xRegCnt(
245
0
                GetPropertySet(), uno::UNO_QUERY );
246
0
            bool bOldHasMeanValueLine = RegressionCurveHelper::hasMeanValueLine( xRegCnt );
247
248
0
            bool bNewHasMeanValueLine =
249
0
                static_cast< const SfxBoolItem & >( rItemSet.Get( nWhichId )).GetValue();
250
251
0
            if( bOldHasMeanValueLine != bNewHasMeanValueLine )
252
0
            {
253
0
                if( ! bNewHasMeanValueLine )
254
0
                    RegressionCurveHelper::removeMeanValueLine( xRegCnt );
255
0
                else
256
0
                    RegressionCurveHelper::addMeanValueLine( xRegCnt, GetPropertySet() );
257
0
                bChanged = true;
258
0
            }
259
0
        }
260
0
        break;
261
262
        // Attention !!! This case must be passed before SCHATTR_STAT_PERCENT,
263
        // SCHATTR_STAT_BIGERROR, SCHATTR_STAT_CONSTPLUS,
264
        // SCHATTR_STAT_CONSTMINUS and SCHATTR_STAT_INDICATE
265
0
        case SCHATTR_STAT_KIND_ERROR:
266
0
        {
267
0
            bool bYError =
268
0
                rItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
269
270
0
            uno::Reference< beans::XPropertySet > xErrorBarProp(
271
0
                lcl_GetErrorBar( GetPropertySet(), bYError ));
272
273
0
            SvxChartKindError eErrorKind =
274
0
                static_cast< const SvxChartKindErrorItem & >(
275
0
                    rItemSet.Get( nWhichId )).GetValue();
276
277
0
            if( !xErrorBarProp.is() && eErrorKind == SvxChartKindError::NONE)
278
0
            {
279
                //nothing to do
280
0
            }
281
0
            else
282
0
            {
283
0
                sal_Int32 nStyle = css::chart::ErrorBarStyle::NONE;
284
285
0
                switch( eErrorKind )
286
0
                {
287
0
                    case SvxChartKindError::NONE:
288
0
                        nStyle = css::chart::ErrorBarStyle::NONE; break;
289
0
                    case SvxChartKindError::Variant:
290
0
                        nStyle = css::chart::ErrorBarStyle::VARIANCE; break;
291
0
                    case SvxChartKindError::Sigma:
292
0
                        nStyle = css::chart::ErrorBarStyle::STANDARD_DEVIATION; break;
293
0
                    case SvxChartKindError::Percent:
294
0
                        nStyle = css::chart::ErrorBarStyle::RELATIVE; break;
295
0
                    case SvxChartKindError::BigError:
296
0
                        nStyle = css::chart::ErrorBarStyle::ERROR_MARGIN; break;
297
0
                    case SvxChartKindError::Const:
298
0
                        nStyle = css::chart::ErrorBarStyle::ABSOLUTE; break;
299
0
                    case SvxChartKindError::StdError:
300
0
                        nStyle = css::chart::ErrorBarStyle::STANDARD_ERROR; break;
301
0
                    case SvxChartKindError::Range:
302
0
                        nStyle = css::chart::ErrorBarStyle::FROM_DATA; break;
303
0
                }
304
305
0
                if( !xErrorBarProp.is() )
306
0
                {
307
0
                    xErrorBarProp = lcl_GetDefaultErrorBar();
308
0
                    GetPropertySet()->setPropertyValue( bYError ? CHART_UNONAME_ERRORBAR_Y : CHART_UNONAME_ERRORBAR_X,
309
0
                                                        uno::Any( xErrorBarProp ));
310
0
                }
311
312
0
                xErrorBarProp->setPropertyValue( u"ErrorBarStyle"_ustr , uno::Any( nStyle ));
313
0
                bChanged = true;
314
0
            }
315
0
        }
316
0
        break;
317
318
0
        case SCHATTR_STAT_PERCENT:
319
0
        case SCHATTR_STAT_BIGERROR:
320
0
        {
321
0
            OSL_FAIL( "Deprecated item" );
322
0
            bool bYError =
323
0
                rItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
324
325
0
            uno::Reference< beans::XPropertySet > xErrorBarProp(
326
0
                lcl_GetErrorBar( GetPropertySet(), bYError));
327
0
            bool bOldHasErrorBar = xErrorBarProp.is();
328
329
0
            double fValue =
330
0
                static_cast< const SvxDoubleItem & >(
331
0
                    rItemSet.Get( nWhichId )).GetValue();
332
0
            double fPos(0.0), fNeg(0.0);
333
0
            lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
334
335
0
            if( bOldHasErrorBar &&
336
0
                ! ( ::rtl::math::approxEqual( fPos, fValue ) &&
337
0
                    ::rtl::math::approxEqual( fNeg, fValue )))
338
0
            {
339
0
                xErrorBarProp->setPropertyValue( u"PositiveError"_ustr , uno::Any( fValue ));
340
0
                xErrorBarProp->setPropertyValue( u"NegativeError"_ustr , uno::Any( fValue ));
341
0
                bChanged = true;
342
0
            }
343
0
        }
344
0
        break;
345
346
0
        case SCHATTR_STAT_CONSTPLUS:
347
0
        {
348
0
            bool bYError =
349
0
                rItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
350
351
0
            uno::Reference< beans::XPropertySet > xErrorBarProp(
352
0
                lcl_GetErrorBar( GetPropertySet(),bYError));
353
0
            bool bOldHasErrorBar = xErrorBarProp.is();
354
355
0
            double fValue =
356
0
                static_cast< const SvxDoubleItem & >(
357
0
                    rItemSet.Get( nWhichId )).GetValue();
358
0
            double fPos(0.0), fNeg(0.0);
359
0
            lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
360
361
0
            if( bOldHasErrorBar &&
362
0
                ! ::rtl::math::approxEqual( fPos, fValue ))
363
0
            {
364
0
                xErrorBarProp->setPropertyValue( u"PositiveError"_ustr , uno::Any( fValue ));
365
0
                bChanged = true;
366
0
            }
367
0
        }
368
0
        break;
369
370
0
        case SCHATTR_STAT_CONSTMINUS:
371
0
        {
372
0
            bool bYError =
373
0
                rItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
374
0
            uno::Reference< beans::XPropertySet > xErrorBarProp(
375
0
                lcl_GetErrorBar( GetPropertySet(),bYError));
376
0
            bool bOldHasErrorBar = xErrorBarProp.is();
377
378
0
            double fValue =
379
0
                static_cast< const SvxDoubleItem & >(
380
0
                    rItemSet.Get( nWhichId )).GetValue();
381
0
            double fPos(0.0), fNeg(0.0);
382
0
            lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
383
384
0
            if( bOldHasErrorBar &&
385
0
                ! ::rtl::math::approxEqual( fNeg, fValue ))
386
0
            {
387
0
                xErrorBarProp->setPropertyValue( u"NegativeError"_ustr , uno::Any( fValue ));
388
0
                bChanged = true;
389
0
            }
390
0
        }
391
0
        break;
392
393
0
        case SCHATTR_REGRESSION_TYPE:
394
0
        {
395
0
            SvxChartRegress eRegress =
396
0
                static_cast< const SvxChartRegressItem& >(
397
0
                    rItemSet.Get( nWhichId )).GetValue();
398
399
0
            uno::Reference< chart2::XRegressionCurve > xCurve( GetPropertySet(), uno::UNO_QUERY );
400
0
            uno::Reference< chart2::XRegressionCurveContainer > xContainer( GetPropertySet(), uno::UNO_QUERY );
401
402
0
            if( eRegress == SvxChartRegress::NONE )
403
0
            {
404
0
                if ( xContainer.is() )
405
0
                {
406
0
                    xContainer->removeRegressionCurve( xCurve );
407
0
                    bChanged = true;
408
0
                }
409
0
            }
410
0
            else
411
0
            {
412
0
                if ( xCurve.is() )
413
0
                {
414
0
                    SvxChartRegress eOldRegress(
415
0
                                RegressionCurveHelper::getRegressionType(xCurve));
416
417
0
                    if( eOldRegress != eRegress )
418
0
                    {
419
0
                        xCurve = RegressionCurveHelper::changeRegressionCurveType(
420
0
                                                eRegress,
421
0
                                                xContainer,
422
0
                                                xCurve);
423
0
                        uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
424
0
                        resetPropertySet( xProperties );
425
0
                        bChanged = true;
426
0
                    }
427
0
                }
428
0
            }
429
0
        }
430
0
        break;
431
432
0
        case SCHATTR_REGRESSION_DEGREE:
433
0
        {
434
0
            uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), &rItemSet ));
435
0
            bChanged = lclConvertToPropertySet<sal_Int32, SfxInt32Item>(rItemSet, nWhichId, xProperties, u"PolynomialDegree"_ustr);
436
0
        }
437
0
        break;
438
439
0
        case SCHATTR_REGRESSION_PERIOD:
440
0
        {
441
0
            uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), &rItemSet ));
442
0
            bChanged = lclConvertToPropertySet<sal_Int32, SfxInt32Item>(rItemSet, nWhichId, xProperties, u"MovingAveragePeriod"_ustr);
443
0
        }
444
0
        break;
445
446
0
        case SCHATTR_REGRESSION_MOVING_TYPE:
447
0
        {
448
0
            uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), &rItemSet ));
449
0
            bChanged = lclConvertToPropertySet<sal_Int32, SfxInt32Item>(rItemSet, nWhichId, xProperties, u"MovingAverageType"_ustr);
450
0
        }
451
0
        break;
452
453
0
        case SCHATTR_REGRESSION_EXTRAPOLATE_FORWARD:
454
0
        {
455
0
            uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), &rItemSet ));
456
0
            bChanged = lclConvertToPropertySet<double, SvxDoubleItem>(rItemSet, nWhichId, xProperties, u"ExtrapolateForward"_ustr);
457
0
        }
458
0
        break;
459
460
0
        case SCHATTR_REGRESSION_EXTRAPOLATE_BACKWARD:
461
0
        {
462
0
            uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), &rItemSet ));
463
0
            bChanged = lclConvertToPropertySet<double, SvxDoubleItem>(rItemSet, nWhichId, xProperties, u"ExtrapolateBackward"_ustr);
464
0
        }
465
0
        break;
466
467
0
        case SCHATTR_REGRESSION_SET_INTERCEPT:
468
0
        {
469
0
            uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), &rItemSet ));
470
0
            bChanged = lclConvertToPropertySet<bool, SfxBoolItem>(rItemSet, nWhichId, xProperties, u"ForceIntercept"_ustr);
471
0
        }
472
0
        break;
473
474
0
        case SCHATTR_REGRESSION_INTERCEPT_VALUE:
475
0
        {
476
0
            uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), &rItemSet ));
477
0
            bChanged = lclConvertToPropertySet<double, SvxDoubleItem>(rItemSet, nWhichId, xProperties, u"InterceptValue"_ustr);
478
0
        }
479
0
        break;
480
481
0
        case SCHATTR_REGRESSION_CURVE_NAME:
482
0
        {
483
0
            uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), &rItemSet ));
484
0
            bChanged = lclConvertToPropertySet<OUString, SfxStringItem>(rItemSet, nWhichId, xProperties, u"CurveName"_ustr);
485
0
        }
486
0
        break;
487
488
0
        case SCHATTR_REGRESSION_SHOW_EQUATION:
489
0
        {
490
0
            uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), &rItemSet ));
491
0
            bChanged = lclConvertToPropertySet<bool, SfxBoolItem>(rItemSet, nWhichId, xEqProp, u"ShowEquation"_ustr);
492
0
        }
493
0
        break;
494
495
0
        case SCHATTR_REGRESSION_XNAME:
496
0
        {
497
0
            uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), &rItemSet ));
498
0
            bChanged = lclConvertToPropertySet<OUString, SfxStringItem>(rItemSet, nWhichId, xEqProp, u"XName"_ustr);
499
0
        }
500
0
        break;
501
502
0
        case SCHATTR_REGRESSION_YNAME:
503
0
        {
504
0
            uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), &rItemSet ));
505
0
            bChanged = lclConvertToPropertySet<OUString, SfxStringItem>(rItemSet, nWhichId, xEqProp, u"YName"_ustr);
506
0
        }
507
0
        break;
508
509
0
        case SCHATTR_REGRESSION_SHOW_COEFF:
510
0
        {
511
0
            uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), &rItemSet ));
512
0
            bChanged = lclConvertToPropertySet<bool, SfxBoolItem>(rItemSet, nWhichId, xEqProp, u"ShowCorrelationCoefficient"_ustr);
513
0
        }
514
0
        break;
515
516
0
        case SCHATTR_STAT_INDICATE:
517
0
        {
518
0
            bool bYError =
519
0
                rItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
520
0
            uno::Reference< beans::XPropertySet > xErrorBarProp(
521
0
                lcl_GetErrorBar( GetPropertySet(),bYError));
522
0
            bool bOldHasErrorBar = xErrorBarProp.is();
523
524
0
            SvxChartIndicate eIndicate =
525
0
                static_cast< const SvxChartIndicateItem & >(
526
0
                    rItemSet.Get( nWhichId )).GetValue();
527
528
0
            bool bNewIndPos = (eIndicate == SvxChartIndicate::Both || eIndicate == SvxChartIndicate::Up );
529
0
            bool bNewIndNeg = (eIndicate == SvxChartIndicate::Both || eIndicate == SvxChartIndicate::Down );
530
531
0
            bool bShowPos(false), bShowNeg(false);
532
0
            lcl_getErrorIndicatorValues( xErrorBarProp, bShowPos, bShowNeg );
533
534
0
            if( bOldHasErrorBar &&
535
0
                ( bShowPos != bNewIndPos ||
536
0
                  bShowNeg != bNewIndNeg ))
537
0
            {
538
0
                xErrorBarProp->setPropertyValue( u"ShowPositiveError"_ustr , uno::Any( bNewIndPos ));
539
0
                xErrorBarProp->setPropertyValue( u"ShowNegativeError"_ustr , uno::Any( bNewIndNeg ));
540
0
                bChanged = true;
541
0
            }
542
0
        }
543
0
        break;
544
545
0
        case SCHATTR_STAT_RANGE_POS:
546
0
        case SCHATTR_STAT_RANGE_NEG:
547
0
        {
548
0
            const bool bYError =
549
0
                rItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
550
0
            uno::Reference< chart2::data::XDataSource > xErrorBarSource( lcl_GetErrorBar( GetPropertySet(), bYError),
551
0
                                                                         uno::UNO_QUERY );
552
0
            uno::Reference< chart2::data::XDataProvider > xDataProvider;
553
554
0
            if( m_xModel.is())
555
0
                xDataProvider.set( m_xModel->getDataProvider());
556
0
            if( xErrorBarSource.is() && xDataProvider.is())
557
0
            {
558
0
                OUString aNewRange( static_cast< const SfxStringItem & >( rItemSet.Get( nWhichId )).GetValue());
559
0
                bool bApplyNewRange = false;
560
561
0
                bool bIsPositiveValue( nWhichId == SCHATTR_STAT_RANGE_POS );
562
0
                if( m_xModel->hasInternalDataProvider())
563
0
                {
564
0
                    if( !aNewRange.isEmpty())
565
0
                    {
566
0
                        uno::Reference< chart2::data::XDataSequence > xSeq(
567
0
                            StatisticsHelper::getErrorDataSequenceFromDataSource(
568
0
                                xErrorBarSource, bIsPositiveValue, bYError ));
569
0
                        if( ! xSeq.is())
570
0
                        {
571
                            // no data range for error bars yet => create
572
0
                            uno::Reference< chart2::XInternalDataProvider > xIntDataProvider( xDataProvider, uno::UNO_QUERY );
573
0
                            OSL_ASSERT( xIntDataProvider.is());
574
0
                            if( xIntDataProvider.is())
575
0
                            {
576
0
                                xIntDataProvider->appendSequence();
577
0
                                aNewRange = "last";
578
0
                                bApplyNewRange = true;
579
0
                            }
580
0
                        }
581
0
                    }
582
0
                }
583
0
                else
584
0
                {
585
0
                    uno::Reference< chart2::data::XDataSequence > xSeq(
586
0
                        StatisticsHelper::getErrorDataSequenceFromDataSource(
587
0
                            xErrorBarSource, bIsPositiveValue, bYError ));
588
0
                    bApplyNewRange =
589
0
                        ! ( xSeq.is() && (aNewRange == xSeq->getSourceRangeRepresentation()));
590
0
                }
591
592
0
                if( bApplyNewRange )
593
0
                    StatisticsHelper::setErrorDataSequence(
594
0
                        xErrorBarSource, xDataProvider, aNewRange, bIsPositiveValue, bYError );
595
0
            }
596
0
        }
597
0
        break;
598
0
    }
599
600
0
    return bChanged;
601
0
}
602
603
void StatisticsItemConverter::FillSpecialItem(
604
    sal_uInt16 nWhichId, SfxItemSet & rOutItemSet ) const
605
0
{
606
0
    switch( nWhichId )
607
0
    {
608
0
        case SCHATTR_STAT_AVERAGE:
609
0
            rOutItemSet.Put(
610
0
                SfxBoolItem( nWhichId,
611
0
                             RegressionCurveHelper::hasMeanValueLine(
612
0
                                 uno::Reference< chart2::XRegressionCurveContainer >(
613
0
                                     GetPropertySet(), uno::UNO_QUERY ))));
614
0
            break;
615
616
0
        case SCHATTR_STAT_KIND_ERROR:
617
0
        {
618
0
            bool bYError =
619
0
                rOutItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
620
0
            SvxChartKindError eErrorKind = SvxChartKindError::NONE;
621
0
            uno::Reference< beans::XPropertySet > xErrorBarProp(
622
0
                lcl_GetErrorBar( GetPropertySet(), bYError));
623
0
            if( xErrorBarProp.is() )
624
0
            {
625
0
                sal_Int32 nStyle = 0;
626
0
                if( xErrorBarProp->getPropertyValue( u"ErrorBarStyle"_ustr ) >>= nStyle )
627
0
                {
628
0
                    switch( nStyle )
629
0
                    {
630
0
                        case css::chart::ErrorBarStyle::NONE:
631
0
                            break;
632
0
                        case css::chart::ErrorBarStyle::VARIANCE:
633
0
                            eErrorKind = SvxChartKindError::Variant; break;
634
0
                        case css::chart::ErrorBarStyle::STANDARD_DEVIATION:
635
0
                            eErrorKind = SvxChartKindError::Sigma; break;
636
0
                        case css::chart::ErrorBarStyle::ABSOLUTE:
637
0
                            eErrorKind = SvxChartKindError::Const; break;
638
0
                        case css::chart::ErrorBarStyle::RELATIVE:
639
0
                            eErrorKind = SvxChartKindError::Percent; break;
640
0
                        case css::chart::ErrorBarStyle::ERROR_MARGIN:
641
0
                            eErrorKind = SvxChartKindError::BigError; break;
642
0
                        case css::chart::ErrorBarStyle::STANDARD_ERROR:
643
0
                            eErrorKind = SvxChartKindError::StdError; break;
644
0
                        case css::chart::ErrorBarStyle::FROM_DATA:
645
0
                            eErrorKind = SvxChartKindError::Range; break;
646
0
                    }
647
0
                }
648
0
            }
649
0
            rOutItemSet.Put( SvxChartKindErrorItem( eErrorKind, SCHATTR_STAT_KIND_ERROR ));
650
0
        }
651
0
        break;
652
653
0
        case SCHATTR_STAT_PERCENT:
654
0
        {
655
0
            bool bYError =
656
0
                rOutItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
657
0
            uno::Reference< beans::XPropertySet > xErrorBarProp( lcl_GetErrorBar( GetPropertySet(),bYError));
658
0
            if( xErrorBarProp.is())
659
0
            {
660
0
                double fPos(0.0), fNeg(0.0);
661
0
                lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
662
0
                rOutItemSet.Put( SvxDoubleItem( ( fPos + fNeg ) / 2.0, SCHATTR_STAT_PERCENT ));
663
0
            }
664
0
        }
665
0
        break;
666
667
0
        case SCHATTR_STAT_BIGERROR:
668
0
        {
669
0
            bool bYError =
670
0
                rOutItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
671
0
            uno::Reference< beans::XPropertySet > xErrorBarProp( lcl_GetErrorBar( GetPropertySet(),bYError));
672
0
            if( xErrorBarProp.is())
673
0
            {
674
0
                double fPos(0.0), fNeg(0.0);
675
0
                lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
676
0
                rOutItemSet.Put( SvxDoubleItem( ( fPos + fNeg ) / 2.0, SCHATTR_STAT_BIGERROR ));
677
0
            }
678
0
        }
679
0
        break;
680
681
0
        case SCHATTR_STAT_CONSTPLUS:
682
0
        {
683
0
            bool bYError =
684
0
                rOutItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
685
0
            uno::Reference< beans::XPropertySet > xErrorBarProp( lcl_GetErrorBar( GetPropertySet(),bYError));
686
0
            if( xErrorBarProp.is())
687
0
            {
688
0
                double fPos(0.0), fNeg(0.0);
689
0
                lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
690
0
                rOutItemSet.Put( SvxDoubleItem( fPos, SCHATTR_STAT_CONSTPLUS ));
691
0
            }
692
0
        }
693
0
        break;
694
695
0
        case SCHATTR_STAT_CONSTMINUS:
696
0
        {
697
0
            bool bYError =
698
0
                rOutItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
699
0
            uno::Reference< beans::XPropertySet > xErrorBarProp( lcl_GetErrorBar( GetPropertySet(),bYError));
700
0
            if( xErrorBarProp.is())
701
0
            {
702
0
                double fPos(0.0), fNeg(0.0);
703
0
                lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
704
0
                rOutItemSet.Put( SvxDoubleItem( fNeg, SCHATTR_STAT_CONSTMINUS ));
705
0
            }
706
0
        }
707
0
        break;
708
709
0
        case SCHATTR_REGRESSION_TYPE:
710
0
        {
711
0
            SvxChartRegress eRegress =
712
0
                    RegressionCurveHelper::getFirstRegressTypeNotMeanValueLine(
713
0
                        uno::Reference< chart2::XRegressionCurveContainer >(
714
0
                            GetPropertySet(), uno::UNO_QUERY ) );
715
0
            rOutItemSet.Put( SvxChartRegressItem( eRegress, SCHATTR_REGRESSION_TYPE ));
716
0
        }
717
0
        break;
718
719
0
        case SCHATTR_REGRESSION_DEGREE:
720
0
        {
721
722
0
            uno::Reference<beans::XPropertySet> xProperties( lcl_getCurveProperties( GetPropertySet(), nullptr ));
723
0
            lclConvertToItemSet<sal_Int32, SfxInt32Item>(rOutItemSet, nWhichId, xProperties, u"PolynomialDegree"_ustr);
724
0
        }
725
0
        break;
726
727
0
        case SCHATTR_REGRESSION_PERIOD:
728
0
        {
729
0
            uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), nullptr ));
730
0
            lclConvertToItemSet<sal_Int32, SfxInt32Item>(rOutItemSet, nWhichId, xProperties, u"MovingAveragePeriod"_ustr);
731
0
        }
732
0
        break;
733
734
0
        case SCHATTR_REGRESSION_MOVING_TYPE:
735
0
        {
736
0
            uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), nullptr ));
737
0
            lclConvertToItemSet<sal_Int32, SfxInt32Item>(rOutItemSet, nWhichId, xProperties, u"MovingAverageType"_ustr);
738
0
        }
739
0
        break;
740
741
0
        case SCHATTR_REGRESSION_EXTRAPOLATE_FORWARD:
742
0
        {
743
0
            uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), nullptr ));
744
0
            lclConvertToItemSetDouble(rOutItemSet, SCHATTR_REGRESSION_EXTRAPOLATE_FORWARD, xProperties, u"ExtrapolateForward"_ustr);
745
0
        }
746
0
        break;
747
748
0
        case SCHATTR_REGRESSION_EXTRAPOLATE_BACKWARD:
749
0
        {
750
0
            uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), nullptr ));
751
0
            lclConvertToItemSetDouble(rOutItemSet, SCHATTR_REGRESSION_EXTRAPOLATE_BACKWARD, xProperties, u"ExtrapolateBackward"_ustr);
752
0
        }
753
0
        break;
754
755
0
        case SCHATTR_REGRESSION_SET_INTERCEPT:
756
0
        {
757
0
            uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), nullptr ));
758
0
            lclConvertToItemSet<bool, SfxBoolItem>(rOutItemSet, nWhichId, xProperties, u"ForceIntercept"_ustr);
759
0
        }
760
0
        break;
761
762
0
        case SCHATTR_REGRESSION_INTERCEPT_VALUE:
763
0
        {
764
0
            uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), nullptr ));
765
0
            lclConvertToItemSetDouble(rOutItemSet, SCHATTR_REGRESSION_INTERCEPT_VALUE, xProperties, u"InterceptValue"_ustr);
766
0
        }
767
0
        break;
768
769
0
        case SCHATTR_REGRESSION_CURVE_NAME:
770
0
        {
771
0
            uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), nullptr ));
772
0
            lclConvertToItemSet<OUString, SfxStringItem>(rOutItemSet, nWhichId, xProperties, u"CurveName"_ustr);
773
0
        }
774
0
        break;
775
776
0
        case SCHATTR_REGRESSION_SHOW_EQUATION:
777
0
        {
778
0
            uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), nullptr ));
779
0
            lclConvertToItemSet<bool, SfxBoolItem>(rOutItemSet, nWhichId, xEqProp, u"ShowEquation"_ustr);
780
0
        }
781
0
        break;
782
783
0
        case SCHATTR_REGRESSION_XNAME:
784
0
        {
785
0
            uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), nullptr ));
786
0
            lclConvertToItemSet<OUString, SfxStringItem>(rOutItemSet, nWhichId, xEqProp, u"XName"_ustr);
787
0
        }
788
0
        break;
789
790
0
        case SCHATTR_REGRESSION_YNAME:
791
0
        {
792
0
            uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), nullptr ));
793
0
            lclConvertToItemSet<OUString, SfxStringItem>(rOutItemSet, nWhichId, xEqProp, u"YName"_ustr);
794
0
        }
795
0
        break;
796
797
0
        case SCHATTR_REGRESSION_SHOW_COEFF:
798
0
        {
799
0
            uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), nullptr ));
800
0
            lclConvertToItemSet<bool, SfxBoolItem>(rOutItemSet, nWhichId, xEqProp, u"ShowCorrelationCoefficient"_ustr);
801
0
        }
802
0
        break;
803
804
0
        case SCHATTR_STAT_INDICATE:
805
0
        {
806
0
            bool bYError =
807
0
                rOutItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
808
0
            uno::Reference< beans::XPropertySet > xErrorBarProp( lcl_GetErrorBar( GetPropertySet(),bYError));
809
0
            SvxChartIndicate eIndicate = SvxChartIndicate::Both;
810
0
            if( xErrorBarProp.is())
811
0
            {
812
0
                bool bShowPos(false), bShowNeg(false);
813
0
                lcl_getErrorIndicatorValues( xErrorBarProp, bShowPos, bShowNeg );
814
815
0
                if( bShowPos )
816
0
                {
817
0
                    if( bShowNeg )
818
0
                        eIndicate = SvxChartIndicate::Both;
819
0
                    else
820
0
                        eIndicate = SvxChartIndicate::Up;
821
0
                }
822
0
                else
823
0
                {
824
0
                    if( bShowNeg )
825
0
                        eIndicate = SvxChartIndicate::Down;
826
0
                    else
827
0
                        eIndicate = SvxChartIndicate::NONE;
828
0
                }
829
0
            }
830
0
            rOutItemSet.Put( SvxChartIndicateItem( eIndicate, SCHATTR_STAT_INDICATE ));
831
0
        }
832
0
        break;
833
834
0
        case SCHATTR_STAT_RANGE_POS:
835
0
        case SCHATTR_STAT_RANGE_NEG:
836
0
        {
837
0
            bool bYError =
838
0
                rOutItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE).GetValue();
839
0
            uno::Reference< chart2::data::XDataSource > xErrorBarSource( lcl_GetErrorBar( GetPropertySet(),bYError),
840
0
                                                                         uno::UNO_QUERY );
841
0
            if( xErrorBarSource.is())
842
0
            {
843
0
                uno::Reference< chart2::data::XDataSequence > xSeq(
844
0
                    StatisticsHelper::getErrorDataSequenceFromDataSource(
845
0
                        xErrorBarSource, (nWhichId == SCHATTR_STAT_RANGE_POS), bYError ));
846
0
                if( xSeq.is())
847
0
                    rOutItemSet.Put( SfxStringItem( nWhichId, xSeq->getSourceRangeRepresentation()));
848
0
            }
849
0
        }
850
0
        break;
851
0
   }
852
0
}
853
854
} //  namespace chart
855
856
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */