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