1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "ObjectNameProvider.hxx"
22 #include "Strings.hrc"
24 #include "AxisHelper.hxx"
25 #include "ChartModelHelper.hxx"
26 #include "DiagramHelper.hxx"
27 #include "DataSeriesHelper.hxx"
28 #include "TitleHelper.hxx"
29 #include "AxisIndexDefines.hxx"
30 #include "ExplicitCategoriesProvider.hxx"
31 #include "CommonConverters.hxx"
32 #include "NumberFormatterWrapper.hxx"
33 #include "RegressionCurveHelper.hxx"
34 #include <rtl/math.hxx>
35 #include <rtl/ustring.hxx>
37 #include <com/sun/star/chart2/XTitle.hpp>
38 #include <com/sun/star/chart2/XRegressionCurveContainer.hpp>
42 using namespace ::com::sun::star
;
43 using namespace ::com::sun::star::chart2
;
44 using ::com::sun::star::uno::Reference
;
45 using ::com::sun::star::uno::Sequence
;
46 using ::com::sun::star::uno::Any
;
51 OUString
lcl_getDataSeriesName( const OUString
& rObjectCID
, const Reference
< frame::XModel
>& xChartModel
)
55 Reference
< XDiagram
> xDiagram( ChartModelHelper::findDiagram( xChartModel
) );
56 Reference
< XDataSeries
> xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID
, xChartModel
), uno::UNO_QUERY
);
57 if( xDiagram
.is() && xSeries
.is() )
59 Reference
< XChartType
> xChartType( DiagramHelper::getChartTypeOfSeries( xDiagram
, xSeries
) );
62 aRet
= ::chart::DataSeriesHelper::getDataSeriesLabel(
63 xSeries
, xChartType
->getRoleOfSequenceForSeriesLabel() ) ;
70 OUString
lcl_getFullSeriesName( const OUString
& rObjectCID
, const Reference
< frame::XModel
>& xChartModel
)
72 OUString
aRet(SCH_RESSTR(STR_TIP_DATASERIES
));
73 OUString
aWildcard( "%SERIESNAME" );
74 sal_Int32 nIndex
= aRet
.indexOf( aWildcard
);
76 aRet
= aRet
.replaceAt( nIndex
, aWildcard
.getLength(), lcl_getDataSeriesName( rObjectCID
, xChartModel
) );
80 void lcl_addText( OUString
& rOut
, const OUString
& rSeparator
, const OUString
& rNext
)
82 if( !(rOut
.isEmpty() || rNext
.isEmpty()) )
84 if( !rNext
.isEmpty() )
88 OUString
lcl_getDataPointValueText( const Reference
< XDataSeries
>& xSeries
, sal_Int32 nPointIndex
,
89 const Reference
< XCoordinateSystem
>& xCooSys
,
90 const Reference
< frame::XModel
>& xChartModel
)
95 Reference
<data::XDataSource
> xDataSource(
96 uno::Reference
<data::XDataSource
>( xSeries
, uno::UNO_QUERY
) );
100 Sequence
< Reference
< data::XLabeledDataSequence
> > aDataSequences( xDataSource
->getDataSequences() );
102 OUString aX
, aY
, aY_Min
, aY_Max
, aY_First
, aY_Last
, a_Size
;
105 uno::Reference
< util::XNumberFormatsSupplier
> xNumberFormatsSupplier( xChartModel
, uno::UNO_QUERY
);
106 NumberFormatterWrapper
aNumberFormatterWrapper( xNumberFormatsSupplier
);
107 sal_Int32 nLabelColor
= 0;//dummy
108 bool bColorChanged
;//dummy
110 for(sal_Int32 nN
= aDataSequences
.getLength();nN
--;)
112 uno::Reference
<data::XDataSequence
> xDataSequence( aDataSequences
[nN
]->getValues());
113 if( !xDataSequence
.is() )
115 Sequence
< Any
> aData( xDataSequence
->getData() );
116 if( nPointIndex
>= aData
.getLength() )
118 uno::Reference
<beans::XPropertySet
> xProp(xDataSequence
, uno::UNO_QUERY
);
123 uno::Any aARole
= xProp
->getPropertyValue( "Role" );
127 if( aRole
== "values-x" )
129 aData
[nPointIndex
]>>= fValue
;
130 sal_Int32 nNumberFormatKey
= xDataSequence
->getNumberFormatKeyByIndex( nPointIndex
);
131 aX
= aNumberFormatterWrapper
.getFormattedString( nNumberFormatKey
, fValue
, nLabelColor
, bColorChanged
);
133 else if( aRole
== "values-y")
135 aData
[nPointIndex
]>>= fValue
;
136 sal_Int32 nNumberFormatKey
= xDataSequence
->getNumberFormatKeyByIndex( nPointIndex
);
137 aY
= aNumberFormatterWrapper
.getFormattedString( nNumberFormatKey
, fValue
, nLabelColor
, bColorChanged
);
139 else if( aRole
== "values-first" )
141 aData
[nPointIndex
]>>= fValue
;
142 sal_Int32 nNumberFormatKey
= xDataSequence
->getNumberFormatKeyByIndex( nPointIndex
);
143 aY_First
= aNumberFormatterWrapper
.getFormattedString( nNumberFormatKey
, fValue
, nLabelColor
, bColorChanged
);
145 else if( aRole
== "values-min" )
147 aData
[nPointIndex
]>>= fValue
;
148 sal_Int32 nNumberFormatKey
= xDataSequence
->getNumberFormatKeyByIndex( nPointIndex
);
149 aY_Min
= aNumberFormatterWrapper
.getFormattedString( nNumberFormatKey
, fValue
, nLabelColor
, bColorChanged
);
151 else if( aRole
== "values-max" )
153 aData
[nPointIndex
]>>= fValue
;
154 sal_Int32 nNumberFormatKey
= xDataSequence
->getNumberFormatKeyByIndex( nPointIndex
);
155 aY_Max
= aNumberFormatterWrapper
.getFormattedString( nNumberFormatKey
, fValue
, nLabelColor
, bColorChanged
);
157 else if( aRole
== "values-last" )
159 aData
[nPointIndex
]>>= fValue
;
160 sal_Int32 nNumberFormatKey
= xDataSequence
->getNumberFormatKeyByIndex( nPointIndex
);
161 aY_Last
= aNumberFormatterWrapper
.getFormattedString( nNumberFormatKey
, fValue
, nLabelColor
, bColorChanged
);
163 else if( aRole
== "values-size" )
165 aData
[nPointIndex
]>>= fValue
;
166 sal_Int32 nNumberFormatKey
= xDataSequence
->getNumberFormatKeyByIndex( nPointIndex
);
167 a_Size
= aNumberFormatterWrapper
.getFormattedString( nNumberFormatKey
, fValue
, nLabelColor
, bColorChanged
);
170 catch( const uno::Exception
& e
)
172 ASSERT_EXCEPTION( e
);
179 ChartModel
& rModel
= dynamic_cast<ChartModel
&>(*xChartModel
.get());
180 aRet
= ExplicitCategoriesProvider::getCategoryByIndex( xCooSys
, rModel
, nPointIndex
);
187 OUString
aSeparator( " " );
189 lcl_addText( aRet
, aSeparator
, aY
);
190 lcl_addText( aRet
, aSeparator
, aY_First
);
191 lcl_addText( aRet
, aSeparator
, aY_Min
);
192 lcl_addText( aRet
, aSeparator
, aY_Max
);
193 lcl_addText( aRet
, aSeparator
, aY_Last
);
194 lcl_addText( aRet
, aSeparator
, a_Size
);
199 } //end anonymous namespace
201 OUString
ObjectNameProvider::getName( ObjectType eObjectType
, bool bPlural
)
204 switch( eObjectType
)
206 case OBJECTTYPE_PAGE
:
207 aRet
=SCH_RESSTR(STR_OBJECT_PAGE
);
209 case OBJECTTYPE_TITLE
:
212 aRet
=SCH_RESSTR(STR_OBJECT_TITLES
);
214 aRet
=SCH_RESSTR(STR_OBJECT_TITLE
);
217 case OBJECTTYPE_LEGEND
:
218 aRet
=SCH_RESSTR(STR_OBJECT_LEGEND
);
220 case OBJECTTYPE_LEGEND_ENTRY
:
221 aRet
=SCH_RESSTR(STR_OBJECT_LEGEND_SYMBOL
);//@todo change string if we do differenciate symbol and legend entry in future
223 case OBJECTTYPE_DIAGRAM
:
224 aRet
=SCH_RESSTR(STR_OBJECT_DIAGRAM
);
226 case OBJECTTYPE_DIAGRAM_WALL
:
227 aRet
=SCH_RESSTR(STR_OBJECT_DIAGRAM_WALL
);
229 case OBJECTTYPE_DIAGRAM_FLOOR
:
230 aRet
=SCH_RESSTR(STR_OBJECT_DIAGRAM_FLOOR
);
232 case OBJECTTYPE_AXIS
:
235 aRet
=SCH_RESSTR(STR_OBJECT_AXES
);
237 aRet
=SCH_RESSTR(STR_OBJECT_AXIS
);
240 case OBJECTTYPE_AXIS_UNITLABEL
:
241 aRet
=SCH_RESSTR(STR_OBJECT_LABEL
);//@todo maybe a more concrete name
243 case OBJECTTYPE_GRID
:
244 case OBJECTTYPE_SUBGRID
: //maybe todo: different names for subgrids
247 aRet
=SCH_RESSTR(STR_OBJECT_GRIDS
);
249 aRet
=SCH_RESSTR(STR_OBJECT_GRID
);
252 case OBJECTTYPE_DATA_SERIES
:
255 aRet
=SCH_RESSTR(STR_OBJECT_DATASERIES_PLURAL
);
257 aRet
=SCH_RESSTR(STR_OBJECT_DATASERIES
);
260 case OBJECTTYPE_DATA_POINT
:
263 aRet
=SCH_RESSTR(STR_OBJECT_DATAPOINTS
);
265 aRet
=SCH_RESSTR(STR_OBJECT_DATAPOINT
);
268 case OBJECTTYPE_DATA_LABELS
:
269 aRet
=SCH_RESSTR(STR_OBJECT_DATALABELS
);
271 case OBJECTTYPE_DATA_LABEL
:
272 aRet
=SCH_RESSTR(STR_OBJECT_LABEL
);
274 case OBJECTTYPE_DATA_ERRORS_X
:
275 aRet
=SCH_RESSTR(STR_OBJECT_ERROR_BARS_X
);
277 case OBJECTTYPE_DATA_ERRORS_Y
:
278 aRet
=SCH_RESSTR(STR_OBJECT_ERROR_BARS_Y
);
280 case OBJECTTYPE_DATA_ERRORS_Z
:
281 aRet
=SCH_RESSTR(STR_OBJECT_ERROR_BARS_Z
);
283 case OBJECTTYPE_DATA_AVERAGE_LINE
:
284 aRet
=SCH_RESSTR(STR_OBJECT_AVERAGE_LINE
);
286 case OBJECTTYPE_DATA_CURVE
:
289 aRet
=SCH_RESSTR(STR_OBJECT_CURVES
);
291 aRet
=SCH_RESSTR(STR_OBJECT_CURVE
);
294 case OBJECTTYPE_DATA_STOCK_RANGE
:
296 case OBJECTTYPE_DATA_STOCK_LOSS
:
297 aRet
=SCH_RESSTR(STR_OBJECT_STOCK_LOSS
);
299 case OBJECTTYPE_DATA_STOCK_GAIN
:
300 aRet
=SCH_RESSTR(STR_OBJECT_STOCK_GAIN
);
302 case OBJECTTYPE_DATA_CURVE_EQUATION
:
303 aRet
=SCH_RESSTR(STR_OBJECT_CURVE_EQUATION
);
305 default: //OBJECTTYPE_UNKNOWN
311 OUString
ObjectNameProvider::getAxisName( const OUString
& rObjectCID
312 , const uno::Reference
< frame::XModel
>& xChartModel
)
316 Reference
< XAxis
> xAxis(
317 ObjectIdentifier::getObjectPropertySet( rObjectCID
, xChartModel
), uno::UNO_QUERY
);
319 sal_Int32 nCooSysIndex
= 0;
320 sal_Int32 nDimensionIndex
= 0;
321 sal_Int32 nAxisIndex
= 0;
322 AxisHelper::getIndicesForAxis( xAxis
, ChartModelHelper::findDiagram( xChartModel
), nCooSysIndex
, nDimensionIndex
, nAxisIndex
);
324 switch(nDimensionIndex
)
327 if( nAxisIndex
== 0 )
328 aRet
=SCH_RESSTR(STR_OBJECT_AXIS_X
);
330 aRet
=SCH_RESSTR(STR_OBJECT_SECONDARY_X_AXIS
);
333 if( nAxisIndex
== 0 )
334 aRet
=SCH_RESSTR(STR_OBJECT_AXIS_Y
);
336 aRet
=SCH_RESSTR(STR_OBJECT_SECONDARY_Y_AXIS
);
339 aRet
=SCH_RESSTR(STR_OBJECT_AXIS_Z
);
342 aRet
=SCH_RESSTR(STR_OBJECT_AXIS
);
349 OUString
ObjectNameProvider::getTitleNameByType( TitleHelper::eTitleType eType
)
355 case TitleHelper::MAIN_TITLE
:
356 aRet
=SCH_RESSTR(STR_OBJECT_TITLE_MAIN
);
358 case TitleHelper::SUB_TITLE
:
359 aRet
=SCH_RESSTR(STR_OBJECT_TITLE_SUB
);
361 case TitleHelper::X_AXIS_TITLE
:
362 aRet
=SCH_RESSTR(STR_OBJECT_TITLE_X_AXIS
);
364 case TitleHelper::Y_AXIS_TITLE
:
365 aRet
=SCH_RESSTR(STR_OBJECT_TITLE_Y_AXIS
);
367 case TitleHelper::Z_AXIS_TITLE
:
368 aRet
=SCH_RESSTR(STR_OBJECT_TITLE_Z_AXIS
);
370 case TitleHelper::SECONDARY_X_AXIS_TITLE
:
371 aRet
=SCH_RESSTR(STR_OBJECT_TITLE_SECONDARY_X_AXIS
);
373 case TitleHelper::SECONDARY_Y_AXIS_TITLE
:
374 aRet
=SCH_RESSTR(STR_OBJECT_TITLE_SECONDARY_Y_AXIS
);
377 OSL_FAIL("unknown title type");
382 aRet
=SCH_RESSTR(STR_OBJECT_TITLE
);
387 OUString
ObjectNameProvider::getTitleName( const OUString
& rObjectCID
388 , const Reference
< frame::XModel
>& xChartModel
)
392 Reference
< XTitle
> xTitle(
393 ObjectIdentifier::getObjectPropertySet( rObjectCID
, xChartModel
), uno::UNO_QUERY
);
396 TitleHelper::eTitleType eType
;
397 if( TitleHelper::getTitleType( eType
, xTitle
, xChartModel
) )
398 aRet
= ObjectNameProvider::getTitleNameByType( eType
);
401 aRet
=SCH_RESSTR(STR_OBJECT_TITLE
);
406 OUString
ObjectNameProvider::getGridName( const OUString
& rObjectCID
407 , const uno::Reference
< frame::XModel
>& xChartModel
)
411 sal_Int32 nCooSysIndex
= -1;
412 sal_Int32 nDimensionIndex
= -1;
413 sal_Int32 nAxisIndex
= -1;
414 Reference
< XAxis
> xAxis( ObjectIdentifier::getAxisForCID( rObjectCID
, xChartModel
) );
415 AxisHelper::getIndicesForAxis( xAxis
, ChartModelHelper::findDiagram( xChartModel
)
416 , nCooSysIndex
, nDimensionIndex
, nAxisIndex
);
418 bool bMainGrid
= (ObjectIdentifier::getObjectType( rObjectCID
) == OBJECTTYPE_GRID
);
422 switch(nDimensionIndex
)
425 aRet
=SCH_RESSTR(STR_OBJECT_GRID_MAJOR_X
);
428 aRet
=SCH_RESSTR(STR_OBJECT_GRID_MAJOR_Y
);
431 aRet
=SCH_RESSTR(STR_OBJECT_GRID_MAJOR_Z
);
434 aRet
=SCH_RESSTR(STR_OBJECT_GRID
);
440 switch(nDimensionIndex
)
443 aRet
=SCH_RESSTR(STR_OBJECT_GRID_MINOR_X
);
446 aRet
=SCH_RESSTR(STR_OBJECT_GRID_MINOR_Y
);
449 aRet
=SCH_RESSTR(STR_OBJECT_GRID_MINOR_Z
);
452 aRet
=SCH_RESSTR(STR_OBJECT_GRID
);
459 OUString
ObjectNameProvider::getHelpText( const OUString
& rObjectCID
, const Reference
< chart2::XChartDocument
>& xChartDocument
, bool bVerbose
)
461 return getHelpText( rObjectCID
, Reference
< frame::XModel
>( xChartDocument
, uno::UNO_QUERY
), bVerbose
);
464 OUString
ObjectNameProvider::getHelpText( const OUString
& rObjectCID
, const Reference
< frame::XModel
>& xChartModel
, bool bVerbose
)
467 ObjectType
eObjectType( ObjectIdentifier::getObjectType(rObjectCID
) );
468 if( OBJECTTYPE_AXIS
== eObjectType
)
470 aRet
=ObjectNameProvider::getAxisName( rObjectCID
, xChartModel
);
472 else if( OBJECTTYPE_GRID
== eObjectType
473 || OBJECTTYPE_SUBGRID
== eObjectType
)
475 aRet
=ObjectNameProvider::getGridName( rObjectCID
, xChartModel
);
477 else if( OBJECTTYPE_TITLE
== eObjectType
)
479 aRet
=ObjectNameProvider::getTitleName( rObjectCID
, xChartModel
);
481 else if( OBJECTTYPE_DATA_SERIES
== eObjectType
)
483 aRet
= lcl_getFullSeriesName( rObjectCID
, xChartModel
);
485 else if( OBJECTTYPE_DATA_POINT
== eObjectType
)
489 OUString
aNewLine( "\n" );
491 aRet
=SCH_RESSTR(STR_TIP_DATAPOINT_INDEX
);
493 aRet
+=SCH_RESSTR(STR_TIP_DATASERIES
);
495 aRet
+=SCH_RESSTR(STR_TIP_DATAPOINT_VALUES
);
498 aRet
=SCH_RESSTR(STR_TIP_DATAPOINT
);
500 Reference
< XDiagram
> xDiagram( ChartModelHelper::findDiagram( xChartModel
) );
501 Reference
< XDataSeries
> xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID
, xChartModel
), uno::UNO_QUERY
);
502 if( xDiagram
.is() && xSeries
.is() )
504 sal_Int32
nPointIndex( ObjectIdentifier::getParticleID(rObjectCID
).toInt32() );
506 //replace data point index
507 OUString
aWildcard( "%POINTNUMBER" );
508 sal_Int32 nIndex
= aRet
.indexOf( aWildcard
);
511 aRet
= aRet
.replaceAt( nIndex
, aWildcard
.getLength(), OUString::number(nPointIndex
+1) );
514 //replace data series index
515 aWildcard
= "%SERIESNUMBER";
516 nIndex
= aRet
.indexOf( aWildcard
);
519 ::std::vector
< Reference
< chart2::XDataSeries
> > aSeriesVector(
520 DiagramHelper::getDataSeriesFromDiagram( xDiagram
) );
521 sal_Int32 nSeriesIndex
= -1;
522 for( nSeriesIndex
=aSeriesVector
.size();nSeriesIndex
--;)
524 if( aSeriesVector
[nSeriesIndex
] == xSeries
)
530 OUString
aReplacement( OUString::number(nSeriesIndex
+1) );
531 aRet
= aRet
.replaceAt( nIndex
, aWildcard
.getLength(), aReplacement
);
534 //replace point values
535 aWildcard
= "%POINTVALUES";
536 nIndex
= aRet
.indexOf( aWildcard
);
538 aRet
= aRet
.replaceAt( nIndex
, aWildcard
.getLength(), lcl_getDataPointValueText(
539 xSeries
,nPointIndex
, DataSeriesHelper::getCoordinateSystemOfSeries(xSeries
, xDiagram
), xChartModel
) );
541 //replace series name
542 aWildcard
= "%SERIESNAME";
543 nIndex
= aRet
.indexOf( aWildcard
);
545 aRet
= aRet
.replaceAt( nIndex
, aWildcard
.getLength(), lcl_getDataSeriesName( rObjectCID
, xChartModel
) );
548 else if( OBJECTTYPE_DATA_CURVE
== eObjectType
)
552 aRet
= SCH_RESSTR( STR_OBJECT_CURVE_WITH_PARAMETERS
);
553 Reference
< chart2::XDataSeries
> xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID
, xChartModel
));
554 Reference
< chart2::XRegressionCurveContainer
> xCurveCnt( xSeries
, uno::UNO_QUERY
);
558 sal_Int32 nCurveIndex
= ObjectIdentifier::getIndexFromParticleOrCID( rObjectCID
);
559 Reference
< chart2::XRegressionCurve
> xCurve( RegressionCurveHelper::getRegressionCurveAtIndex(xCurveCnt
, nCurveIndex
) );
564 Reference
< chart2::XRegressionCurveCalculator
> xCalculator( xCurve
->getCalculator(), uno::UNO_QUERY_THROW
);
565 sal_Int32 aDegree
= 2;
566 sal_Int32 aPeriod
= 2;
567 bool aForceIntercept
= false;
568 double aInterceptValue
= 0.0;
569 uno::Reference
< beans::XPropertySet
> xProperties( xCurve
, uno::UNO_QUERY
);
570 if ( xProperties
.is())
572 xProperties
->getPropertyValue( "PolynomialDegree") >>= aDegree
;
573 xProperties
->getPropertyValue( "MovingAveragePeriod") >>= aPeriod
;
574 xProperties
->getPropertyValue( "ForceIntercept") >>= aForceIntercept
;
576 xProperties
->getPropertyValue( "InterceptValue") >>= aInterceptValue
;
578 xCalculator
->setRegressionProperties(aDegree
, aForceIntercept
, aInterceptValue
, 2);
579 RegressionCurveHelper::initializeCurveCalculator( xCalculator
, xSeries
, xChartModel
);
581 // change text for Moving Average
582 OUString
aWildcard( "%PERIOD" );
583 sal_Int32 nIndex
= xCalculator
->getRepresentation().indexOf( aWildcard
);
586 aRet
= xCalculator
->getRepresentation();
587 aRet
= aRet
.replaceAt( nIndex
, aWildcard
.getLength(), OUString::number(aPeriod
) );
591 aWildcard
= "%FORMULA";
592 nIndex
= aRet
.indexOf( aWildcard
);
594 aRet
= aRet
.replaceAt( nIndex
, aWildcard
.getLength(), xCalculator
->getRepresentation());
597 aWildcard
= "%RSQUARED";
598 nIndex
= aRet
.indexOf( aWildcard
);
601 sal_Unicode
aDecimalSep( '.' );
602 double fR( xCalculator
->getCorrelationCoefficient());
603 aRet
= aRet
.replaceAt(
604 nIndex
, aWildcard
.getLength(),
605 ::rtl::math::doubleToUString(
606 fR
*fR
, rtl_math_StringFormat_G
, 4, aDecimalSep
, true ));
609 catch( const uno::Exception
& ex
)
611 ASSERT_EXCEPTION( ex
);
618 Reference
< chart2::XDataSeries
> xSeries( ObjectIdentifier::getDataSeriesForCID(rObjectCID
, xChartModel
));
619 Reference
< chart2::XRegressionCurveContainer
> xCurveCnt( xSeries
, uno::UNO_QUERY
);
620 aRet
+= getName(eObjectType
, false);
624 sal_Int32 nCurveIndex
= ObjectIdentifier::getIndexFromParticleOrCID( rObjectCID
);
625 Reference
< chart2::XRegressionCurve
> xCurve( RegressionCurveHelper::getRegressionCurveAtIndex(xCurveCnt
, nCurveIndex
) );
629 aRet
+= RegressionCurveHelper::getRegressionCurveName(xCurve
);
635 else if( OBJECTTYPE_DATA_AVERAGE_LINE
== eObjectType
)
639 aRet
= SCH_RESSTR(STR_OBJECT_AVERAGE_LINE_WITH_PARAMETERS
);
640 Reference
< chart2::XDataSeries
> xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID
, xChartModel
));
641 Reference
< chart2::XRegressionCurveContainer
> xCurveCnt( xSeries
, uno::UNO_QUERY
);
644 Reference
< chart2::XRegressionCurve
> xCurve( RegressionCurveHelper::getMeanValueLine( xCurveCnt
));
649 Reference
< chart2::XRegressionCurveCalculator
> xCalculator( xCurve
->getCalculator(), uno::UNO_QUERY_THROW
);
650 RegressionCurveHelper::initializeCurveCalculator( xCalculator
, xSeries
, xChartModel
);
652 sal_Unicode
aDecimalSep( '.' );
654 OUString
aWildcard( "%AVERAGE_VALUE" );
655 sal_Int32 nIndex
= aRet
.indexOf( aWildcard
);
656 // as the curve is constant, the value at any x-value is ok
659 const double fMeanValue( xCalculator
->getCurveValue( 0.0 ));
660 aRet
= aRet
.replaceAt(
661 nIndex
, aWildcard
.getLength(),
662 ::rtl::math::doubleToUString(
663 fMeanValue
, rtl_math_StringFormat_G
, 4, aDecimalSep
, true ));
666 // replace standard deviation
667 aWildcard
= "%STD_DEVIATION";
668 nIndex
= aRet
.indexOf( aWildcard
);
671 const double fStdDev( xCalculator
->getCorrelationCoefficient());
672 aRet
= aRet
.replaceAt(
673 nIndex
, aWildcard
.getLength(),
674 ::rtl::math::doubleToUString(
675 fStdDev
, rtl_math_StringFormat_G
, 4, aDecimalSep
, true ));
678 catch( const uno::Exception
& ex
)
680 ASSERT_EXCEPTION( ex
);
688 aRet
= ObjectNameProvider::getName( eObjectType
, false );
693 aRet
= ObjectNameProvider::getName( eObjectType
, false );
698 OUString
ObjectNameProvider::getSelectedObjectText( const OUString
& rObjectCID
, const ::com::sun::star::uno::Reference
< ::com::sun::star::chart2::XChartDocument
>& xChartDocument
)
701 ObjectType
eObjectType( ObjectIdentifier::getObjectType(rObjectCID
) );
702 Reference
< frame::XModel
> xChartModel( xChartDocument
, uno::UNO_QUERY
);
704 if( OBJECTTYPE_DATA_POINT
== eObjectType
)
706 aRet
= SCH_RESSTR( STR_STATUS_DATAPOINT_MARKED
);
708 Reference
< XDiagram
> xDiagram( ChartModelHelper::findDiagram( xChartModel
) );
709 Reference
< XDataSeries
> xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID
, xChartModel
), uno::UNO_QUERY
);
710 if( xDiagram
.is() && xSeries
.is() )
712 sal_Int32
nPointIndex( ObjectIdentifier::getParticleID(rObjectCID
).toInt32() );
714 // replace data point index
715 replaceParamterInString( aRet
, "%POINTNUMBER", OUString::number( nPointIndex
+ 1 ));
717 // replace data series index
719 ::std::vector
< Reference
< chart2::XDataSeries
> > aSeriesVector(
720 DiagramHelper::getDataSeriesFromDiagram( xDiagram
) );
721 sal_Int32 nSeriesIndex
= -1;
722 for( nSeriesIndex
=aSeriesVector
.size();nSeriesIndex
--;)
724 if( aSeriesVector
[nSeriesIndex
] == xSeries
)
727 replaceParamterInString( aRet
, "%SERIESNUMBER", OUString::number( nSeriesIndex
+ 1 ) );
730 // replace point value
731 replaceParamterInString( aRet
, "%POINTVALUES", lcl_getDataPointValueText(
732 xSeries
, nPointIndex
, DataSeriesHelper::getCoordinateSystemOfSeries(xSeries
, xDiagram
), xChartModel
) );
737 // use the verbose text including the formula for trend lines
738 const bool bVerbose( OBJECTTYPE_DATA_CURVE
== eObjectType
|| OBJECTTYPE_DATA_AVERAGE_LINE
== eObjectType
);
739 const OUString
aHelpText( getHelpText( rObjectCID
, xChartModel
, bVerbose
));
740 if( !aHelpText
.isEmpty())
742 aRet
= SCH_RESSTR( STR_STATUS_OBJECT_MARKED
);
743 replaceParamterInString( aRet
, "%OBJECTNAME", aHelpText
);
750 OUString
ObjectNameProvider::getNameForCID(
751 const OUString
& rObjectCID
,
752 const uno::Reference
< chart2::XChartDocument
>& xChartDocument
)
754 ObjectType
eType( ObjectIdentifier::getObjectType( rObjectCID
));
755 Reference
< frame::XModel
> xModel( xChartDocument
, uno::UNO_QUERY
);
759 case OBJECTTYPE_AXIS
:
760 return getAxisName( rObjectCID
, xModel
);
761 case OBJECTTYPE_TITLE
:
762 return getTitleName( rObjectCID
, xModel
);
763 case OBJECTTYPE_GRID
:
764 case OBJECTTYPE_SUBGRID
:
765 return getGridName( rObjectCID
, xModel
);
766 case OBJECTTYPE_DATA_SERIES
:
767 return lcl_getFullSeriesName( rObjectCID
, xModel
);
768 case OBJECTTYPE_DATA_POINT
:
769 case OBJECTTYPE_DATA_LABELS
:
770 case OBJECTTYPE_DATA_LABEL
:
771 case OBJECTTYPE_DATA_ERRORS_X
:
772 case OBJECTTYPE_DATA_ERRORS_Y
:
773 case OBJECTTYPE_DATA_ERRORS_Z
:
774 case OBJECTTYPE_DATA_AVERAGE_LINE
:
775 case OBJECTTYPE_DATA_CURVE
:
776 case OBJECTTYPE_DATA_CURVE_EQUATION
:
778 OUString aRet
= lcl_getFullSeriesName( rObjectCID
, xModel
);
780 if( eType
== OBJECTTYPE_DATA_POINT
|| eType
== OBJECTTYPE_DATA_LABEL
)
782 aRet
+= getName( OBJECTTYPE_DATA_POINT
);
783 sal_Int32 nPointIndex
= ObjectIdentifier::getIndexFromParticleOrCID( rObjectCID
);
785 aRet
+= OUString::number(nPointIndex
+1);
787 if( eType
== OBJECTTYPE_DATA_LABEL
)
790 aRet
+= getName( OBJECTTYPE_DATA_LABEL
);
793 else if (eType
== OBJECTTYPE_DATA_CURVE
|| eType
== OBJECTTYPE_DATA_CURVE_EQUATION
)
795 Reference
< chart2::XDataSeries
> xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID
, xModel
));
796 Reference
< chart2::XRegressionCurveContainer
> xCurveCnt( xSeries
, uno::UNO_QUERY
);
799 aRet
+= getName(eType
);
803 sal_Int32 nCurveIndex
= ObjectIdentifier::getIndexFromParticleOrCID( rObjectCID
);
804 Reference
< chart2::XRegressionCurve
> xCurve( RegressionCurveHelper::getRegressionCurveAtIndex(xCurveCnt
, nCurveIndex
) );
808 aRet
+= RegressionCurveHelper::getRegressionCurveName(xCurve
);
815 aRet
+= getName( eType
);
823 return getName( eType
);
826 OUString
ObjectNameProvider::getName_ObjectForSeries(
827 ObjectType eObjectType
,
828 const OUString
& rSeriesCID
,
829 const uno::Reference
< chart2::XChartDocument
>& xChartDocument
)
831 uno::Reference
< frame::XModel
> xChartModel( xChartDocument
, uno::UNO_QUERY
);
832 Reference
< XDataSeries
> xSeries( ObjectIdentifier::getDataSeriesForCID( rSeriesCID
, xChartModel
), uno::UNO_QUERY
);
835 OUString aRet
= SCH_RESSTR(STR_OBJECT_FOR_SERIES
);
836 replaceParamterInString( aRet
, "%OBJECTNAME", getName( eObjectType
, false /*bPlural*/ ) );
837 replaceParamterInString( aRet
, "%SERIESNAME", lcl_getDataSeriesName( rSeriesCID
, xChartModel
) );
841 return ObjectNameProvider::getName_ObjectForAllSeries( eObjectType
);
844 OUString
ObjectNameProvider::getName_ObjectForAllSeries( ObjectType eObjectType
)
846 OUString aRet
= SCH_RESSTR(STR_OBJECT_FOR_ALL_SERIES
);
847 replaceParamterInString( aRet
, "%OBJECTNAME", getName( eObjectType
, true /*bPlural*/ ) );
853 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */