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>
23 #include <AxisHelper.hxx>
24 #include <ChartModel.hxx>
25 #include <ChartModelHelper.hxx>
26 #include <DiagramHelper.hxx>
27 #include <DataSeriesHelper.hxx>
28 #include <TitleHelper.hxx>
29 #include <ExplicitCategoriesProvider.hxx>
30 #include <CommonConverters.hxx>
31 #include <NumberFormatterWrapper.hxx>
32 #include <RegressionCurveHelper.hxx>
33 #include <rtl/math.hxx>
34 #include <rtl/ustring.hxx>
35 #include <sal/log.hxx>
36 #include <vcl/settings.hxx>
37 #include <vcl/svapp.hxx>
38 #include <unotools/localedatawrapper.hxx>
40 #include <com/sun/star/chart2/XTitle.hpp>
41 #include <com/sun/star/chart2/XRegressionCurveContainer.hpp>
42 #include <tools/diagnose_ex.h>
46 using namespace ::com::sun::star
;
47 using namespace ::com::sun::star::chart2
;
48 using ::com::sun::star::uno::Reference
;
49 using ::com::sun::star::uno::Sequence
;
50 using ::com::sun::star::uno::Any
;
55 OUString
lcl_getDataSeriesName( const OUString
& rObjectCID
, const Reference
< frame::XModel
>& xChartModel
)
59 Reference
< XDiagram
> xDiagram( ChartModelHelper::findDiagram( xChartModel
) );
60 Reference
< XDataSeries
> xSeries
= ObjectIdentifier::getDataSeriesForCID( rObjectCID
, xChartModel
);
61 if( xDiagram
.is() && xSeries
.is() )
63 Reference
< XChartType
> xChartType( DiagramHelper::getChartTypeOfSeries( xDiagram
, xSeries
) );
66 aRet
= ::chart::DataSeriesHelper::getDataSeriesLabel(
67 xSeries
, xChartType
->getRoleOfSequenceForSeriesLabel() ) ;
74 OUString
lcl_getFullSeriesName( const OUString
& rObjectCID
, const Reference
< frame::XModel
>& xChartModel
)
76 OUString
aRet(SchResId(STR_TIP_DATASERIES
));
77 OUString
aWildcard( "%SERIESNAME" );
78 sal_Int32 nIndex
= aRet
.indexOf( aWildcard
);
80 aRet
= aRet
.replaceAt( nIndex
, aWildcard
.getLength(), lcl_getDataSeriesName( rObjectCID
, xChartModel
) );
84 void lcl_addText( OUString
& rOut
, const OUString
& rSeparator
, const OUString
& rNext
)
86 if( !(rOut
.isEmpty() || rNext
.isEmpty()) )
88 if( !rNext
.isEmpty() )
92 OUString
lcl_getDataPointValueText( const Reference
< XDataSeries
>& xSeries
, sal_Int32 nPointIndex
,
93 const Reference
< XCoordinateSystem
>& xCooSys
,
94 const Reference
< frame::XModel
>& xChartModel
)
99 Reference
<data::XDataSource
> xDataSource(
100 uno::Reference
<data::XDataSource
>( xSeries
, uno::UNO_QUERY
) );
101 if(!xDataSource
.is())
104 Sequence
< Reference
< data::XLabeledDataSequence
> > aDataSequences( xDataSource
->getDataSequences() );
106 OUString aX
, aY
, aY_Min
, aY_Max
, aY_First
, aY_Last
, a_Size
;
109 uno::Reference
< util::XNumberFormatsSupplier
> xNumberFormatsSupplier( xChartModel
, uno::UNO_QUERY
);
110 NumberFormatterWrapper
aNumberFormatterWrapper( xNumberFormatsSupplier
);
111 Color nLabelColor
;//dummy
112 bool bColorChanged
;//dummy
114 for(sal_Int32 nN
= aDataSequences
.getLength();nN
--;)
116 uno::Reference
<data::XDataSequence
> xDataSequence( aDataSequences
[nN
]->getValues());
117 if( !xDataSequence
.is() )
119 Sequence
< Any
> aData( xDataSequence
->getData() );
120 if( nPointIndex
>= aData
.getLength() )
122 uno::Reference
<beans::XPropertySet
> xProp(xDataSequence
, uno::UNO_QUERY
);
127 uno::Any aARole
= xProp
->getPropertyValue( "Role" );
131 if( aRole
== "values-x" )
133 aData
[nPointIndex
]>>= fValue
;
134 sal_Int32 nNumberFormatKey
= xDataSequence
->getNumberFormatKeyByIndex( nPointIndex
);
135 aX
= aNumberFormatterWrapper
.getFormattedString( nNumberFormatKey
, fValue
, nLabelColor
, bColorChanged
);
137 else if( aRole
== "values-y")
139 aData
[nPointIndex
]>>= fValue
;
140 sal_Int32 nNumberFormatKey
= xDataSequence
->getNumberFormatKeyByIndex( nPointIndex
);
141 aY
= aNumberFormatterWrapper
.getFormattedString( nNumberFormatKey
, fValue
, nLabelColor
, bColorChanged
);
143 else if( aRole
== "values-first" )
145 aData
[nPointIndex
]>>= fValue
;
146 sal_Int32 nNumberFormatKey
= xDataSequence
->getNumberFormatKeyByIndex( nPointIndex
);
147 aY_First
= aNumberFormatterWrapper
.getFormattedString( nNumberFormatKey
, fValue
, nLabelColor
, bColorChanged
);
149 else if( aRole
== "values-min" )
151 aData
[nPointIndex
]>>= fValue
;
152 sal_Int32 nNumberFormatKey
= xDataSequence
->getNumberFormatKeyByIndex( nPointIndex
);
153 aY_Min
= aNumberFormatterWrapper
.getFormattedString( nNumberFormatKey
, fValue
, nLabelColor
, bColorChanged
);
155 else if( aRole
== "values-max" )
157 aData
[nPointIndex
]>>= fValue
;
158 sal_Int32 nNumberFormatKey
= xDataSequence
->getNumberFormatKeyByIndex( nPointIndex
);
159 aY_Max
= aNumberFormatterWrapper
.getFormattedString( nNumberFormatKey
, fValue
, nLabelColor
, bColorChanged
);
161 else if( aRole
== "values-last" )
163 aData
[nPointIndex
]>>= fValue
;
164 sal_Int32 nNumberFormatKey
= xDataSequence
->getNumberFormatKeyByIndex( nPointIndex
);
165 aY_Last
= aNumberFormatterWrapper
.getFormattedString( nNumberFormatKey
, fValue
, nLabelColor
, bColorChanged
);
167 else if( aRole
== "values-size" )
169 aData
[nPointIndex
]>>= fValue
;
170 sal_Int32 nNumberFormatKey
= xDataSequence
->getNumberFormatKeyByIndex( nPointIndex
);
171 a_Size
= aNumberFormatterWrapper
.getFormattedString( nNumberFormatKey
, fValue
, nLabelColor
, bColorChanged
);
174 catch( const uno::Exception
& )
176 TOOLS_WARN_EXCEPTION("chart2", "" );
183 ChartModel
& rModel
= dynamic_cast<ChartModel
&>(*xChartModel
);
184 aRet
= ExplicitCategoriesProvider::getCategoryByIndex( xCooSys
, rModel
, nPointIndex
);
191 OUString
aSeparator( " " );
193 lcl_addText( aRet
, aSeparator
, aY
);
194 lcl_addText( aRet
, aSeparator
, aY_First
);
195 lcl_addText( aRet
, aSeparator
, aY_Min
);
196 lcl_addText( aRet
, aSeparator
, aY_Max
);
197 lcl_addText( aRet
, aSeparator
, aY_Last
);
198 lcl_addText( aRet
, aSeparator
, a_Size
);
203 } //end anonymous namespace
205 OUString
ObjectNameProvider::getName( ObjectType eObjectType
, bool bPlural
)
208 switch( eObjectType
)
210 case OBJECTTYPE_PAGE
:
211 aRet
=SchResId(STR_OBJECT_PAGE
);
213 case OBJECTTYPE_TITLE
:
216 aRet
=SchResId(STR_OBJECT_TITLES
);
218 aRet
=SchResId(STR_OBJECT_TITLE
);
221 case OBJECTTYPE_LEGEND
:
222 aRet
=SchResId(STR_OBJECT_LEGEND
);
224 case OBJECTTYPE_LEGEND_ENTRY
:
225 aRet
=SchResId(STR_OBJECT_LEGEND_SYMBOL
);//@todo change string if we do differentiate symbol and legend entry in future
227 case OBJECTTYPE_DIAGRAM
:
228 aRet
=SchResId(STR_OBJECT_DIAGRAM
);
230 case OBJECTTYPE_DIAGRAM_WALL
:
231 aRet
=SchResId(STR_OBJECT_DIAGRAM_WALL
);
233 case OBJECTTYPE_DIAGRAM_FLOOR
:
234 aRet
=SchResId(STR_OBJECT_DIAGRAM_FLOOR
);
236 case OBJECTTYPE_AXIS
:
239 aRet
=SchResId(STR_OBJECT_AXES
);
241 aRet
=SchResId(STR_OBJECT_AXIS
);
244 case OBJECTTYPE_AXIS_UNITLABEL
:
245 aRet
=SchResId(STR_OBJECT_LABEL
);//@todo maybe a more concrete name
247 case OBJECTTYPE_GRID
:
248 case OBJECTTYPE_SUBGRID
: //maybe todo: different names for subgrids
251 aRet
=SchResId(STR_OBJECT_GRIDS
);
253 aRet
=SchResId(STR_OBJECT_GRID
);
256 case OBJECTTYPE_DATA_SERIES
:
259 aRet
=SchResId(STR_OBJECT_DATASERIES_PLURAL
);
261 aRet
=SchResId(STR_OBJECT_DATASERIES
);
264 case OBJECTTYPE_DATA_POINT
:
267 aRet
=SchResId(STR_OBJECT_DATAPOINTS
);
269 aRet
=SchResId(STR_OBJECT_DATAPOINT
);
272 case OBJECTTYPE_DATA_LABELS
:
273 aRet
=SchResId(STR_OBJECT_DATALABELS
);
275 case OBJECTTYPE_DATA_LABEL
:
276 aRet
=SchResId(STR_OBJECT_LABEL
);
278 case OBJECTTYPE_DATA_ERRORS_X
:
279 aRet
=SchResId(STR_OBJECT_ERROR_BARS_X
);
281 case OBJECTTYPE_DATA_ERRORS_Y
:
282 aRet
=SchResId(STR_OBJECT_ERROR_BARS_Y
);
284 case OBJECTTYPE_DATA_ERRORS_Z
:
285 aRet
=SchResId(STR_OBJECT_ERROR_BARS_Z
);
287 case OBJECTTYPE_DATA_AVERAGE_LINE
:
288 aRet
=SchResId(STR_OBJECT_AVERAGE_LINE
);
290 case OBJECTTYPE_DATA_CURVE
:
293 aRet
=SchResId(STR_OBJECT_CURVES
);
295 aRet
=SchResId(STR_OBJECT_CURVE
);
298 case OBJECTTYPE_DATA_STOCK_RANGE
:
300 case OBJECTTYPE_DATA_STOCK_LOSS
:
301 aRet
=SchResId(STR_OBJECT_STOCK_LOSS
);
303 case OBJECTTYPE_DATA_STOCK_GAIN
:
304 aRet
=SchResId(STR_OBJECT_STOCK_GAIN
);
306 case OBJECTTYPE_DATA_CURVE_EQUATION
:
307 aRet
=SchResId(STR_OBJECT_CURVE_EQUATION
);
309 default: //OBJECTTYPE_UNKNOWN
315 OUString
ObjectNameProvider::getAxisName( const OUString
& rObjectCID
316 , const uno::Reference
< frame::XModel
>& xChartModel
)
320 Reference
< XAxis
> xAxis(
321 ObjectIdentifier::getObjectPropertySet( rObjectCID
, xChartModel
), uno::UNO_QUERY
);
323 sal_Int32 nCooSysIndex
= 0;
324 sal_Int32 nDimensionIndex
= 0;
325 sal_Int32 nAxisIndex
= 0;
326 AxisHelper::getIndicesForAxis( xAxis
, ChartModelHelper::findDiagram( xChartModel
), nCooSysIndex
, nDimensionIndex
, nAxisIndex
);
328 switch(nDimensionIndex
)
331 if( nAxisIndex
== 0 )
332 aRet
=SchResId(STR_OBJECT_AXIS_X
);
334 aRet
=SchResId(STR_OBJECT_SECONDARY_X_AXIS
);
337 if( nAxisIndex
== 0 )
338 aRet
=SchResId(STR_OBJECT_AXIS_Y
);
340 aRet
=SchResId(STR_OBJECT_SECONDARY_Y_AXIS
);
343 aRet
=SchResId(STR_OBJECT_AXIS_Z
);
346 aRet
=SchResId(STR_OBJECT_AXIS
);
353 OUString
ObjectNameProvider::getTitleNameByType( TitleHelper::eTitleType eType
)
359 case TitleHelper::MAIN_TITLE
:
360 aRet
=SchResId(STR_OBJECT_TITLE_MAIN
);
362 case TitleHelper::SUB_TITLE
:
363 aRet
=SchResId(STR_OBJECT_TITLE_SUB
);
365 case TitleHelper::X_AXIS_TITLE
:
366 aRet
=SchResId(STR_OBJECT_TITLE_X_AXIS
);
368 case TitleHelper::Y_AXIS_TITLE
:
369 aRet
=SchResId(STR_OBJECT_TITLE_Y_AXIS
);
371 case TitleHelper::Z_AXIS_TITLE
:
372 aRet
=SchResId(STR_OBJECT_TITLE_Z_AXIS
);
374 case TitleHelper::SECONDARY_X_AXIS_TITLE
:
375 aRet
=SchResId(STR_OBJECT_TITLE_SECONDARY_X_AXIS
);
377 case TitleHelper::SECONDARY_Y_AXIS_TITLE
:
378 aRet
=SchResId(STR_OBJECT_TITLE_SECONDARY_Y_AXIS
);
381 OSL_FAIL("unknown title type");
386 aRet
=SchResId(STR_OBJECT_TITLE
);
391 OUString
ObjectNameProvider::getTitleName( const OUString
& rObjectCID
392 , const Reference
< frame::XModel
>& xChartModel
)
396 Reference
< XTitle
> xTitle(
397 ObjectIdentifier::getObjectPropertySet( rObjectCID
, xChartModel
), uno::UNO_QUERY
);
400 TitleHelper::eTitleType eType
;
401 if( TitleHelper::getTitleType( eType
, xTitle
, xChartModel
) )
402 aRet
= ObjectNameProvider::getTitleNameByType( eType
);
405 aRet
=SchResId(STR_OBJECT_TITLE
);
410 OUString
ObjectNameProvider::getGridName( const OUString
& rObjectCID
411 , const uno::Reference
< frame::XModel
>& xChartModel
)
415 sal_Int32 nCooSysIndex
= -1;
416 sal_Int32 nDimensionIndex
= -1;
417 sal_Int32 nAxisIndex
= -1;
418 Reference
< XAxis
> xAxis( ObjectIdentifier::getAxisForCID( rObjectCID
, xChartModel
) );
419 AxisHelper::getIndicesForAxis( xAxis
, ChartModelHelper::findDiagram( xChartModel
)
420 , nCooSysIndex
, nDimensionIndex
, nAxisIndex
);
422 bool bMainGrid
= (ObjectIdentifier::getObjectType( rObjectCID
) == OBJECTTYPE_GRID
);
426 switch(nDimensionIndex
)
429 aRet
=SchResId(STR_OBJECT_GRID_MAJOR_X
);
432 aRet
=SchResId(STR_OBJECT_GRID_MAJOR_Y
);
435 aRet
=SchResId(STR_OBJECT_GRID_MAJOR_Z
);
438 aRet
=SchResId(STR_OBJECT_GRID
);
444 switch(nDimensionIndex
)
447 aRet
=SchResId(STR_OBJECT_GRID_MINOR_X
);
450 aRet
=SchResId(STR_OBJECT_GRID_MINOR_Y
);
453 aRet
=SchResId(STR_OBJECT_GRID_MINOR_Z
);
456 aRet
=SchResId(STR_OBJECT_GRID
);
463 OUString
ObjectNameProvider::getHelpText( const OUString
& rObjectCID
, const Reference
< chart2::XChartDocument
>& xChartDocument
)
465 return getHelpText( rObjectCID
, Reference
< frame::XModel
>( xChartDocument
) );
468 OUString
ObjectNameProvider::getHelpText( const OUString
& rObjectCID
, const Reference
< frame::XModel
>& xChartModel
, bool bVerbose
)
471 ObjectType
eObjectType( ObjectIdentifier::getObjectType(rObjectCID
) );
472 if( eObjectType
== OBJECTTYPE_AXIS
)
474 aRet
=ObjectNameProvider::getAxisName( rObjectCID
, xChartModel
);
476 else if( eObjectType
== OBJECTTYPE_GRID
477 || eObjectType
== OBJECTTYPE_SUBGRID
)
479 aRet
=ObjectNameProvider::getGridName( rObjectCID
, xChartModel
);
481 else if( eObjectType
== OBJECTTYPE_TITLE
)
483 aRet
=ObjectNameProvider::getTitleName( rObjectCID
, xChartModel
);
485 else if( eObjectType
== OBJECTTYPE_DATA_SERIES
)
487 aRet
= lcl_getFullSeriesName( rObjectCID
, xChartModel
);
489 else if( eObjectType
== OBJECTTYPE_DATA_POINT
)
493 aRet
= SchResId(STR_TIP_DATAPOINT_INDEX
) + "\n"
494 + SchResId(STR_TIP_DATASERIES
) + "\n"
495 + SchResId(STR_TIP_DATAPOINT_VALUES
);
498 aRet
=SchResId(STR_TIP_DATAPOINT
);
500 Reference
< XDiagram
> xDiagram( ChartModelHelper::findDiagram( xChartModel
) );
501 Reference
< XDataSeries
> xSeries
= ObjectIdentifier::getDataSeriesForCID( rObjectCID
, xChartModel
);
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( eObjectType
== OBJECTTYPE_DATA_CURVE
)
552 aRet
= SchResId( 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_SET_THROW
);
565 sal_Int32 aDegree
= 2;
566 sal_Int32 aPeriod
= 2;
567 bool bForceIntercept
= false;
568 double aInterceptValue
= 0.0;
569 OUString
aXName ("x"), aYName ("f(x)");
570 const LocaleDataWrapper
& rLocaleDataWrapper
= Application::GetSettings().GetLocaleDataWrapper();
571 const OUString
& aNumDecimalSep
= rLocaleDataWrapper
.getNumDecimalSep();
572 sal_Unicode cDecSeparator
= aNumDecimalSep
[0];
574 uno::Reference
< beans::XPropertySet
> xProperties( xCurve
, uno::UNO_QUERY
);
575 if ( xProperties
.is())
577 xProperties
->getPropertyValue( "PolynomialDegree") >>= aDegree
;
578 xProperties
->getPropertyValue( "MovingAveragePeriod") >>= aPeriod
;
579 xProperties
->getPropertyValue( "ForceIntercept") >>= bForceIntercept
;
581 xProperties
->getPropertyValue( "InterceptValue") >>= aInterceptValue
;
582 uno::Reference
< beans::XPropertySet
> xEqProp( xCurve
->getEquationProperties());
585 if ( !(xEqProp
->getPropertyValue( "XName") >>= aXName
) )
587 if ( !(xEqProp
->getPropertyValue( "YName") >>= aYName
) )
591 xCalculator
->setRegressionProperties(aDegree
, bForceIntercept
, aInterceptValue
, 2);
592 xCalculator
->setXYNames ( aXName
, aYName
);
593 RegressionCurveHelper::initializeCurveCalculator( xCalculator
, xSeries
, xChartModel
);
595 // change text for Moving Average
596 OUString
aWildcard( "%PERIOD" );
597 sal_Int32 nIndex
= xCalculator
->getRepresentation().indexOf( aWildcard
);
600 aRet
= xCalculator
->getRepresentation();
601 aRet
= aRet
.replaceAt( nIndex
, aWildcard
.getLength(), OUString::number(aPeriod
) );
605 aWildcard
= "%FORMULA";
606 nIndex
= aRet
.indexOf( aWildcard
);
609 OUString
aFormula ( xCalculator
->getRepresentation() );
610 if ( cDecSeparator
!= '.' )
612 aFormula
= aFormula
.replace( '.', cDecSeparator
);
614 aRet
= aRet
.replaceAt( nIndex
, aWildcard
.getLength(), aFormula
);
618 aWildcard
= "%RSQUARED";
619 nIndex
= aRet
.indexOf( aWildcard
);
622 double fR( xCalculator
->getCorrelationCoefficient());
623 aRet
= aRet
.replaceAt(
624 nIndex
, aWildcard
.getLength(),
625 ::rtl::math::doubleToUString(
626 fR
*fR
, rtl_math_StringFormat_G
, 4, cDecSeparator
, true ));
629 catch( const uno::Exception
& )
631 DBG_UNHANDLED_EXCEPTION("chart2");
638 Reference
< chart2::XDataSeries
> xSeries( ObjectIdentifier::getDataSeriesForCID(rObjectCID
, xChartModel
));
639 Reference
< chart2::XRegressionCurveContainer
> xCurveCnt( xSeries
, uno::UNO_QUERY
);
640 aRet
+= getName(eObjectType
);
644 sal_Int32 nCurveIndex
= ObjectIdentifier::getIndexFromParticleOrCID( rObjectCID
);
645 Reference
< chart2::XRegressionCurve
> xCurve( RegressionCurveHelper::getRegressionCurveAtIndex(xCurveCnt
, nCurveIndex
) );
648 aRet
+= " (" + RegressionCurveHelper::getRegressionCurveName(xCurve
) + " )";
653 else if( eObjectType
== OBJECTTYPE_DATA_AVERAGE_LINE
)
657 aRet
= SchResId(STR_OBJECT_AVERAGE_LINE_WITH_PARAMETERS
);
658 Reference
< chart2::XDataSeries
> xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID
, xChartModel
));
659 Reference
< chart2::XRegressionCurveContainer
> xCurveCnt( xSeries
, uno::UNO_QUERY
);
662 Reference
< chart2::XRegressionCurve
> xCurve( RegressionCurveHelper::getMeanValueLine( xCurveCnt
));
667 Reference
< chart2::XRegressionCurveCalculator
> xCalculator( xCurve
->getCalculator(), uno::UNO_SET_THROW
);
668 RegressionCurveHelper::initializeCurveCalculator( xCalculator
, xSeries
, xChartModel
);
670 const LocaleDataWrapper
& rLocaleDataWrapper
= Application::GetSettings().GetLocaleDataWrapper();
671 const OUString
& aNumDecimalSep
= rLocaleDataWrapper
.getNumDecimalSep();
672 sal_Unicode cDecSeparator
= aNumDecimalSep
[0];
674 OUString
aWildcard( "%AVERAGE_VALUE" );
675 sal_Int32 nIndex
= aRet
.indexOf( aWildcard
);
676 // as the curve is constant, the value at any x-value is ok
679 const double fMeanValue( xCalculator
->getCurveValue( 0.0 ));
680 aRet
= aRet
.replaceAt(
681 nIndex
, aWildcard
.getLength(),
682 ::rtl::math::doubleToUString(
683 fMeanValue
, rtl_math_StringFormat_G
, 4, cDecSeparator
, true ));
686 // replace standard deviation
687 aWildcard
= "%STD_DEVIATION";
688 nIndex
= aRet
.indexOf( aWildcard
);
691 const double fStdDev( xCalculator
->getCorrelationCoefficient());
692 aRet
= aRet
.replaceAt(
693 nIndex
, aWildcard
.getLength(),
694 ::rtl::math::doubleToUString(
695 fStdDev
, rtl_math_StringFormat_G
, 4, cDecSeparator
, true ));
698 catch( const uno::Exception
& )
700 DBG_UNHANDLED_EXCEPTION("chart2");
708 aRet
= ObjectNameProvider::getName( eObjectType
);
713 aRet
= ObjectNameProvider::getName( eObjectType
);
718 OUString
ObjectNameProvider::getSelectedObjectText( const OUString
& rObjectCID
, const css::uno::Reference
< css::chart2::XChartDocument
>& xChartDocument
)
721 ObjectType
eObjectType( ObjectIdentifier::getObjectType(rObjectCID
) );
722 Reference
< frame::XModel
> xChartModel
= xChartDocument
;
724 if( eObjectType
== OBJECTTYPE_DATA_POINT
)
726 aRet
= SchResId( STR_STATUS_DATAPOINT_MARKED
);
728 Reference
< XDiagram
> xDiagram( ChartModelHelper::findDiagram( xChartModel
) );
729 Reference
< XDataSeries
> xSeries
= ObjectIdentifier::getDataSeriesForCID( rObjectCID
, xChartModel
);
730 if( xDiagram
.is() && xSeries
.is() )
732 sal_Int32
nPointIndex( ObjectIdentifier::getParticleID(rObjectCID
).toInt32() );
734 // replace data point index
735 replaceParamterInString( aRet
, "%POINTNUMBER", OUString::number( nPointIndex
+ 1 ));
737 // replace data series index
739 std::vector
< Reference
< chart2::XDataSeries
> > aSeriesVector(
740 DiagramHelper::getDataSeriesFromDiagram( xDiagram
) );
741 sal_Int32 nSeriesIndex
= -1;
742 for( nSeriesIndex
=aSeriesVector
.size();nSeriesIndex
--;)
744 if( aSeriesVector
[nSeriesIndex
] == xSeries
)
747 replaceParamterInString( aRet
, "%SERIESNUMBER", OUString::number( nSeriesIndex
+ 1 ) );
750 // replace point value
751 replaceParamterInString( aRet
, "%POINTVALUES", lcl_getDataPointValueText(
752 xSeries
, nPointIndex
, DataSeriesHelper::getCoordinateSystemOfSeries(xSeries
, xDiagram
), xChartModel
) );
757 // use the verbose text including the formula for trend lines
758 const bool bVerbose( eObjectType
== OBJECTTYPE_DATA_CURVE
|| eObjectType
== OBJECTTYPE_DATA_AVERAGE_LINE
);
759 const OUString
aHelpText( getHelpText( rObjectCID
, xChartModel
, bVerbose
));
760 if( !aHelpText
.isEmpty())
762 aRet
= SchResId( STR_STATUS_OBJECT_MARKED
);
763 replaceParamterInString( aRet
, "%OBJECTNAME", aHelpText
);
770 OUString
ObjectNameProvider::getNameForCID(
771 const OUString
& rObjectCID
,
772 const uno::Reference
< chart2::XChartDocument
>& xChartDocument
)
774 ObjectType
eType( ObjectIdentifier::getObjectType( rObjectCID
));
775 Reference
< frame::XModel
> xModel
= xChartDocument
;
779 case OBJECTTYPE_AXIS
:
780 return getAxisName( rObjectCID
, xModel
);
781 case OBJECTTYPE_TITLE
:
782 return getTitleName( rObjectCID
, xModel
);
783 case OBJECTTYPE_GRID
:
784 case OBJECTTYPE_SUBGRID
:
785 return getGridName( rObjectCID
, xModel
);
786 case OBJECTTYPE_DATA_SERIES
:
787 return lcl_getFullSeriesName( rObjectCID
, xModel
);
788 case OBJECTTYPE_DATA_POINT
:
789 case OBJECTTYPE_DATA_LABELS
:
790 case OBJECTTYPE_DATA_LABEL
:
791 case OBJECTTYPE_DATA_ERRORS_X
:
792 case OBJECTTYPE_DATA_ERRORS_Y
:
793 case OBJECTTYPE_DATA_ERRORS_Z
:
794 case OBJECTTYPE_DATA_AVERAGE_LINE
:
795 case OBJECTTYPE_DATA_CURVE
:
796 case OBJECTTYPE_DATA_CURVE_EQUATION
:
798 OUString aRet
= lcl_getFullSeriesName( rObjectCID
, xModel
) + " ";
799 if( eType
== OBJECTTYPE_DATA_POINT
|| eType
== OBJECTTYPE_DATA_LABEL
)
801 aRet
+= getName( OBJECTTYPE_DATA_POINT
);
802 sal_Int32 nPointIndex
= ObjectIdentifier::getIndexFromParticleOrCID( rObjectCID
);
803 aRet
+= " " + OUString::number(nPointIndex
+1);
804 if( eType
== OBJECTTYPE_DATA_LABEL
)
806 aRet
+= " " + getName( OBJECTTYPE_DATA_LABEL
);
809 else if (eType
== OBJECTTYPE_DATA_CURVE
|| eType
== OBJECTTYPE_DATA_CURVE_EQUATION
)
811 Reference
< chart2::XDataSeries
> xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID
, xModel
));
812 Reference
< chart2::XRegressionCurveContainer
> xCurveCnt( xSeries
, uno::UNO_QUERY
);
814 aRet
+= " " + getName(eType
);
818 sal_Int32 nCurveIndex
= ObjectIdentifier::getIndexFromParticleOrCID( rObjectCID
);
819 Reference
< chart2::XRegressionCurve
> xCurve( RegressionCurveHelper::getRegressionCurveAtIndex(xCurveCnt
, nCurveIndex
) );
822 aRet
+= " (" + RegressionCurveHelper::getRegressionCurveName(xCurve
) + ")";
828 aRet
+= getName( eType
);
836 return getName( eType
);
839 OUString
ObjectNameProvider::getName_ObjectForSeries(
840 ObjectType eObjectType
,
841 const OUString
& rSeriesCID
,
842 const uno::Reference
< chart2::XChartDocument
>& xChartDocument
)
844 uno::Reference
< frame::XModel
> xChartModel
= xChartDocument
;
845 Reference
< XDataSeries
> xSeries
= ObjectIdentifier::getDataSeriesForCID( rSeriesCID
, xChartModel
);
848 OUString aRet
= SchResId(STR_OBJECT_FOR_SERIES
);
849 replaceParamterInString( aRet
, "%OBJECTNAME", getName( eObjectType
) );
850 replaceParamterInString( aRet
, "%SERIESNAME", lcl_getDataSeriesName( rSeriesCID
, xChartModel
) );
854 return ObjectNameProvider::getName_ObjectForAllSeries( eObjectType
);
857 OUString
ObjectNameProvider::getName_ObjectForAllSeries( ObjectType eObjectType
)
859 OUString aRet
= SchResId(STR_OBJECT_FOR_ALL_SERIES
);
860 replaceParamterInString( aRet
, "%OBJECTNAME", getName( eObjectType
, true /*bPlural*/ ) );
866 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */