update dev300-m57
[ooovba.git] / chart2 / source / controller / dialogs / ObjectNameProvider.cxx
blob25fb201c3677064e1e29a348df7981ebf40a48bc
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ObjectNameProvider.cxx,v $
10 * $Revision: 1.9 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
34 #include "ObjectNameProvider.hxx"
35 #include "ResId.hxx"
36 #include "Strings.hrc"
37 #include "macros.hxx"
38 #include "AxisHelper.hxx"
39 #include "ChartModelHelper.hxx"
40 #include "DiagramHelper.hxx"
41 #include "DataSeriesHelper.hxx"
42 #include "TitleHelper.hxx"
43 #include "AxisIndexDefines.hxx"
44 #include "ExplicitCategoriesProvider.hxx"
45 #include "CommonConverters.hxx"
46 #include "chartview/NumberFormatterWrapper.hxx"
47 #include "RegressionCurveHelper.hxx"
48 #include <rtl/math.hxx>
49 #include <tools/debug.hxx>
50 #include <tools/string.hxx>
52 // #include <svtools/syslocale.hxx>
54 #include <com/sun/star/chart2/XTitle.hpp>
55 #include <com/sun/star/chart2/XRegressionCurveContainer.hpp>
57 //.............................................................................
58 namespace chart
60 //.............................................................................
61 using namespace ::com::sun::star;
62 using namespace ::com::sun::star::chart2;
63 using ::com::sun::star::uno::Reference;
64 using ::com::sun::star::uno::Sequence;
65 using ::com::sun::star::uno::Any;
66 using rtl::OUString;
68 namespace
71 OUString lcl_getDataSeriesName( const rtl::OUString& rObjectCID, const Reference< frame::XModel >& xChartModel )
73 OUString aRet;
75 Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) );
76 Reference< XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID , xChartModel ), uno::UNO_QUERY );
77 if( xDiagram.is() && xSeries.is() )
79 Reference< XChartType > xChartType( DiagramHelper::getChartTypeOfSeries( xDiagram, xSeries ) );
80 if( xChartType.is() )
82 aRet = ::chart::DataSeriesHelper::getDataSeriesLabel(
83 xSeries, xChartType->getRoleOfSequenceForSeriesLabel() ) ;
87 return aRet;
90 void lcl_addText( OUString& rOut, const OUString& rSeparator, const OUString& rNext )
92 if( rOut.getLength() && rNext.getLength() )
93 rOut+=rSeparator;
94 if( rNext.getLength() )
95 rOut+=rNext;
98 OUString lcl_getDataPointValueText( const Reference< XDataSeries >& xSeries, sal_Int32 nPointIndex,
99 const Reference< XCoordinateSystem >& xCooSys,
100 const Reference< frame::XModel >& xChartModel )
103 OUString aRet;
105 Reference<data::XDataSource> xDataSource(
106 uno::Reference<data::XDataSource>( xSeries, uno::UNO_QUERY ) );
107 if(!xDataSource.is())
108 return aRet;
110 Sequence< Reference< data::XLabeledDataSequence > > aDataSequences( xDataSource->getDataSequences() );
112 rtl::OUString aX, aY, aY_Min, aY_Max, aY_First, aY_Last, a_Size;
113 double fValue = 0;
115 uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( xChartModel, uno::UNO_QUERY );
116 NumberFormatterWrapper aNumberFormatterWrapper( xNumberFormatsSupplier );
117 sal_Int32 nLabelColor = 0;//dummy
118 bool bColorChanged;//dummy
120 for(sal_Int32 nN = aDataSequences.getLength();nN--;)
122 uno::Reference<data::XDataSequence> xDataSequence( aDataSequences[nN]->getValues());
123 if( !xDataSequence.is() )
124 continue;
125 Sequence< Any > aData( xDataSequence->getData() );
126 if( nPointIndex >= aData.getLength() )
127 continue;
128 uno::Reference<beans::XPropertySet> xProp(xDataSequence, uno::UNO_QUERY );
129 if( xProp.is())
133 uno::Any aARole = xProp->getPropertyValue( C2U( "Role" ) );
134 rtl::OUString aRole;
135 aARole >>= aRole;
137 if( aRole.equals(C2U("values-x")) )
139 aData[nPointIndex]>>= fValue;
140 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
141 aX = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
143 else if( aRole.equals(C2U("values-y")) )
145 aData[nPointIndex]>>= fValue;
146 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
147 aY = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
149 else if( aRole.equals(C2U("values-first")) )
151 aData[nPointIndex]>>= fValue;
152 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
153 aY_First = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
155 else if( aRole.equals(C2U("values-min")) )
157 aData[nPointIndex]>>= fValue;
158 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
159 aY_Min = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
161 else if( aRole.equals(C2U("values-max")) )
163 aData[nPointIndex]>>= fValue;
164 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
165 aY_Max = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
167 else if( aRole.equals(C2U("values-last")) )
169 aData[nPointIndex]>>= fValue;
170 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
171 aY_Last = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
173 else if( aRole.equals(C2U("values-size")) )
175 aData[nPointIndex]>>= fValue;
176 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
177 a_Size = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
180 catch( uno::Exception& e )
182 ASSERT_EXCEPTION( e );
187 if( aX.getLength() == 0 )
189 rtl::OUString aCategory = ::rtl::OUString( String(SchResId(STR_TIP_CATEGORY_VALUE)));
191 replaceParamterInString( aCategory
192 , C2U("%CATEGORYVALUE")
193 , ExplicitCategoriesProvider::getCategoryByIndex( xCooSys, nPointIndex )
196 aRet = aCategory;
198 else
200 aRet = aX;
203 OUString aSeparator(C2U(" "));
205 lcl_addText( aRet, aSeparator, aY );
206 lcl_addText( aRet, aSeparator, aY_First );
207 lcl_addText( aRet, aSeparator, aY_Min );
208 lcl_addText( aRet, aSeparator, aY_Max );
209 lcl_addText( aRet, aSeparator, aY_Last );
210 lcl_addText( aRet, aSeparator, a_Size );
212 return aRet;
215 } //end anonymous namespace
217 rtl::OUString ObjectNameProvider::getName( ObjectType eObjectType, bool bPlural )
219 rtl::OUString aRet;
220 switch( eObjectType )
222 case OBJECTTYPE_PAGE:
223 aRet=String(SchResId(STR_OBJECT_PAGE));
224 break;
225 case OBJECTTYPE_TITLE:
227 if(bPlural)
228 aRet=String(SchResId(STR_OBJECT_TITLES));
229 else
230 aRet=String(SchResId(STR_OBJECT_TITLE));
232 break;
233 case OBJECTTYPE_LEGEND:
234 aRet=String(SchResId(STR_OBJECT_LEGEND));
235 break;
236 case OBJECTTYPE_LEGEND_ENTRY:
237 aRet=String(SchResId(STR_OBJECT_LEGEND_SYMBOL));//@todo change string if we do differenciate symbol and legend entry in future
238 break;
239 case OBJECTTYPE_DIAGRAM:
240 aRet=String(SchResId(STR_OBJECT_DIAGRAM));
241 break;
242 case OBJECTTYPE_DIAGRAM_WALL:
243 aRet=String(SchResId(STR_OBJECT_DIAGRAM_WALL));
244 break;
245 case OBJECTTYPE_DIAGRAM_FLOOR:
246 aRet=String(SchResId(STR_OBJECT_DIAGRAM_FLOOR));
247 break;
248 case OBJECTTYPE_AXIS:
250 if(bPlural)
251 aRet=String(SchResId(STR_OBJECT_AXES));
252 else
253 aRet=String(SchResId(STR_OBJECT_AXIS));
255 break;
256 case OBJECTTYPE_AXIS_UNITLABEL:
257 aRet=String(SchResId(STR_OBJECT_LABEL));//@todo maybe a more concrete name
258 break;
259 case OBJECTTYPE_GRID:
260 case OBJECTTYPE_SUBGRID: //maybe todo: different names for subgrids
262 if(bPlural)
263 aRet=String(SchResId(STR_OBJECT_GRIDS));
264 else
265 aRet=String(SchResId(STR_OBJECT_GRID));
267 break;
268 case OBJECTTYPE_DATA_SERIES:
270 if(bPlural)
271 aRet=String(SchResId(STR_OBJECT_DATASERIES_PLURAL));
272 else
273 aRet=String(SchResId(STR_OBJECT_DATASERIES));
275 break;
276 case OBJECTTYPE_DATA_POINT:
278 if(bPlural)
279 aRet=String(SchResId(STR_OBJECT_DATAPOINTS));
280 else
281 aRet=String(SchResId(STR_OBJECT_DATAPOINT));
283 break;
284 case OBJECTTYPE_DATA_LABELS:
285 aRet=String(SchResId(STR_OBJECT_DATALABELS));
286 break;
287 case OBJECTTYPE_DATA_LABEL:
288 aRet=String(SchResId(STR_OBJECT_LABEL));
289 break;
290 case OBJECTTYPE_DATA_ERRORS:
291 aRet=String(SchResId(STR_OBJECT_ERROR_INDICATOR));//@todo? maybe distinguish plural singular
292 break;
293 case OBJECTTYPE_DATA_ERRORS_X:
294 aRet=String(SchResId(STR_OBJECT_ERROR_INDICATOR));//@todo? maybe specialize in future
295 break;
296 case OBJECTTYPE_DATA_ERRORS_Y:
297 aRet=String(SchResId(STR_OBJECT_ERROR_INDICATOR));//@todo? maybe specialize in future
298 break;
299 case OBJECTTYPE_DATA_ERRORS_Z:
300 aRet=String(SchResId(STR_OBJECT_ERROR_INDICATOR));//@todo? maybe specialize in future
301 break;
302 case OBJECTTYPE_DATA_AVERAGE_LINE:
303 aRet=String(SchResId(STR_OBJECT_AVERAGE_LINE));
304 break;
305 case OBJECTTYPE_DATA_CURVE:
306 aRet=String(SchResId(STR_OBJECT_CURVE));
307 break;
308 case OBJECTTYPE_DATA_STOCK_RANGE:
309 //aRet=String(SchResId());
310 break;
311 case OBJECTTYPE_DATA_STOCK_LOSS:
312 aRet=String(SchResId(STR_OBJECT_STOCK_LOSS));
313 break;
314 case OBJECTTYPE_DATA_STOCK_GAIN:
315 aRet=String(SchResId(STR_OBJECT_STOCK_GAIN));
316 break;
317 case OBJECTTYPE_DATA_CURVE_EQUATION:
318 aRet=String(SchResId(STR_OBJECT_CURVE_EQUATION));
319 break;
320 default: //OBJECTTYPE_UNKNOWN
323 return aRet;
325 //static
326 rtl::OUString ObjectNameProvider::getAxisName( const rtl::OUString& rObjectCID
327 , const uno::Reference< frame::XModel >& xChartModel )
329 rtl::OUString aRet;
333 Reference< XAxis > xAxis(
334 ObjectIdentifier::getObjectPropertySet( rObjectCID , xChartModel ), uno::UNO_QUERY );
336 sal_Int32 nDimensionIndex = AxisHelper::getDimensionIndexOfAxis( xAxis, ChartModelHelper::findDiagram( xChartModel ) );
338 switch(nDimensionIndex)
340 case 0://x-axis
341 aRet=String(SchResId(STR_OBJECT_AXIS_X));
342 break;
343 case 1://y-axis
344 aRet=String(SchResId(STR_OBJECT_AXIS_Y));
345 break;
346 case 2://z-axis
347 aRet=String(SchResId(STR_OBJECT_AXIS_Z));
348 break;
349 default://axis
350 aRet=String(SchResId(STR_OBJECT_AXIS));
351 break;
354 return aRet;
357 //static
358 OUString ObjectNameProvider::getTitleName( const OUString& rObjectCID
359 , const Reference< frame::XModel >& xChartModel )
361 OUString aRet;
363 Reference< XTitle > xTitle(
364 ObjectIdentifier::getObjectPropertySet( rObjectCID , xChartModel ), uno::UNO_QUERY );
365 if( xTitle.is() )
367 TitleHelper::eTitleType eType;
368 if( TitleHelper::getTitleType( eType, xTitle, xChartModel ) )
370 switch(eType)
372 case TitleHelper::MAIN_TITLE:
373 aRet=String(SchResId(STR_OBJECT_TITLE_MAIN));
374 break;
375 case TitleHelper::SUB_TITLE:
376 aRet=String(SchResId(STR_OBJECT_TITLE_SUB));
377 break;
378 case TitleHelper::X_AXIS_TITLE:
379 aRet=String(SchResId(STR_OBJECT_TITLE_X_AXIS));
380 break;
381 case TitleHelper::Y_AXIS_TITLE:
382 aRet=String(SchResId(STR_OBJECT_TITLE_Y_AXIS));
383 break;
384 case TitleHelper::Z_AXIS_TITLE:
385 aRet=String(SchResId(STR_OBJECT_TITLE_Z_AXIS));
386 break;
387 case TitleHelper::SECONDARY_X_AXIS_TITLE:
388 aRet=String(SchResId(STR_OBJECT_TITLE_SECONDARY_X_AXIS));
389 break;
390 case TitleHelper::SECONDARY_Y_AXIS_TITLE:
391 aRet=String(SchResId(STR_OBJECT_TITLE_SECONDARY_Y_AXIS));
392 break;
393 default:
394 DBG_ERROR("unknown title type");
395 break;
399 if( !aRet.getLength() )
400 aRet=String(SchResId(STR_OBJECT_TITLE));
402 return aRet;
405 //static
406 rtl::OUString ObjectNameProvider::getGridName( const rtl::OUString& rObjectCID
407 , const uno::Reference< frame::XModel >& xChartModel )
409 rtl::OUString aRet;
412 sal_Int32 nCooSysIndex = -1;
413 sal_Int32 nDimensionIndex = -1;
414 sal_Int32 nAxisIndex = -1;
415 Reference< XAxis > xAxis( ObjectIdentifier::getAxisForCID( rObjectCID , xChartModel ) );
416 AxisHelper::getIndicesForAxis( xAxis, ChartModelHelper::findDiagram( xChartModel )
417 , nCooSysIndex , nDimensionIndex, nAxisIndex );
419 bool bMainGrid = (ObjectIdentifier::getObjectType( rObjectCID ) == OBJECTTYPE_GRID);
421 if( bMainGrid )
423 switch(nDimensionIndex)
425 case 0://x-axis
426 aRet=String(SchResId(STR_OBJECT_GRID_MAJOR_X));
427 break;
428 case 1://y-axis
429 aRet=String(SchResId(STR_OBJECT_GRID_MAJOR_Y));
430 break;
431 case 2://z-axis
432 aRet=String(SchResId(STR_OBJECT_GRID_MAJOR_Z));
433 break;
434 default://axis
435 aRet=String(SchResId(STR_OBJECT_GRID));
436 break;
439 else
441 switch(nDimensionIndex)
443 case 0://x-axis
444 aRet=String(SchResId(STR_OBJECT_GRID_MINOR_X));
445 break;
446 case 1://y-axis
447 aRet=String(SchResId(STR_OBJECT_GRID_MINOR_Y));
448 break;
449 case 2://z-axis
450 aRet=String(SchResId(STR_OBJECT_GRID_MINOR_Z));
451 break;
452 default://axis
453 aRet=String(SchResId(STR_OBJECT_GRID));
454 break;
457 return aRet;
460 rtl::OUString ObjectNameProvider::getHelpText( const rtl::OUString& rObjectCID, const Reference< chart2::XChartDocument >& xChartDocument, bool bVerbose )
462 return getHelpText( rObjectCID, Reference< frame::XModel >( xChartDocument, uno::UNO_QUERY ), bVerbose );
465 rtl::OUString ObjectNameProvider::getHelpText( const rtl::OUString& rObjectCID, const Reference< frame::XModel >& xChartModel, bool bVerbose )
467 rtl::OUString aRet;
468 ObjectType eObjectType( ObjectIdentifier::getObjectType(rObjectCID) );
469 if( OBJECTTYPE_AXIS == eObjectType )
471 aRet=ObjectNameProvider::getAxisName( rObjectCID, xChartModel );
473 else if( OBJECTTYPE_GRID == eObjectType
474 || OBJECTTYPE_SUBGRID == eObjectType )
476 aRet=ObjectNameProvider::getGridName( rObjectCID, xChartModel );
478 else if( OBJECTTYPE_TITLE == eObjectType )
480 aRet=ObjectNameProvider::getTitleName( rObjectCID, xChartModel );
482 else if( OBJECTTYPE_DATA_SERIES == eObjectType )
484 aRet=String(SchResId(STR_TIP_DATASERIES));
486 OUString aWildcard( C2U("%SERIESNAME") );
487 sal_Int32 nIndex = aRet.indexOf( aWildcard );
488 if( nIndex != -1 )
489 aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), lcl_getDataSeriesName( rObjectCID, xChartModel ) );
491 else if( OBJECTTYPE_DATA_POINT == eObjectType )
493 if( bVerbose )
495 OUString aNewLine(C2U("\n"));
497 aRet=String(SchResId(STR_TIP_DATAPOINT_INDEX));
498 aRet+=aNewLine;
499 aRet+=String(SchResId(STR_TIP_DATASERIES));
500 aRet+=aNewLine;
501 aRet+=String(SchResId(STR_TIP_DATAPOINT_VALUES));
503 else
504 aRet=String(SchResId(STR_TIP_DATAPOINT));
506 Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) );
507 Reference< XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID , xChartModel ), uno::UNO_QUERY );
508 if( xDiagram.is() && xSeries.is() )
510 sal_Int32 nPointIndex( ObjectIdentifier::getParticleID(rObjectCID).toInt32() );
512 //replace data point index
513 sal_Int32 nIndex = -1;
514 OUString aWildcard( C2U("%POINTNUMBER") );
515 nIndex = aRet.indexOf( aWildcard );
516 if( nIndex != -1 )
518 aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), OUString::valueOf(nPointIndex+1) );
521 //replace data series index
522 aWildcard = C2U("%SERIESNUMBER");
523 nIndex = aRet.indexOf( aWildcard );
524 if( nIndex != -1 )
526 ::std::vector< Reference< chart2::XDataSeries > > aSeriesVector(
527 DiagramHelper::getDataSeriesFromDiagram( xDiagram ) );
528 sal_Int32 nSeriesIndex = -1;
529 for( nSeriesIndex=aSeriesVector.size();nSeriesIndex--;)
531 if( aSeriesVector[nSeriesIndex] == xSeries )
533 break;
537 OUString aReplacement( OUString::valueOf(nSeriesIndex+1) );
538 aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), aReplacement );
541 //replace point values
542 aWildcard = C2U("%POINTVALUES");
543 nIndex = aRet.indexOf( aWildcard );
544 if( nIndex != -1 )
545 aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), lcl_getDataPointValueText(
546 xSeries,nPointIndex, DataSeriesHelper::getCoordinateSystemOfSeries(xSeries, xDiagram), xChartModel ) );
548 //replace series name
549 aWildcard = C2U("%SERIESNAME");
550 nIndex = aRet.indexOf( aWildcard );
551 if( nIndex != -1 )
552 aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), lcl_getDataSeriesName( rObjectCID, xChartModel ) );
556 else if( OBJECTTYPE_DIAGRAM == eObjectType )
558 //todo different names for different diagram types ???
559 //or different names for series of diferent charttypes
562 else if( OBJECTTYPE_DATA_CURVE == eObjectType )
564 if( bVerbose )
566 aRet = String( SchResId( STR_OBJECT_CURVE_WITH_PARAMETERS ));
567 Reference< chart2::XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID , xChartModel ));
568 Reference< chart2::XRegressionCurveContainer > xCurveCnt( xSeries, uno::UNO_QUERY );
569 if( xCurveCnt.is())
571 Reference< chart2::XRegressionCurve > xCurve( RegressionCurveHelper::getFirstCurveNotMeanValueLine( xCurveCnt ));
572 if( xCurve.is())
576 Reference< chart2::XRegressionCurveCalculator > xCalculator( xCurve->getCalculator(), uno::UNO_QUERY_THROW );
577 RegressionCurveHelper::initializeCurveCalculator( xCalculator, xSeries, xChartModel );
579 // replace formula
580 sal_Int32 nIndex = -1;
581 OUString aWildcard( C2U("%FORMULA") );
582 nIndex = aRet.indexOf( aWildcard );
583 if( nIndex != -1 )
584 aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), xCalculator->getRepresentation());
586 // replace r^2
587 aWildcard = C2U("%RSQUARED");
588 nIndex = aRet.indexOf( aWildcard );
589 if( nIndex != -1 )
591 sal_Unicode aDecimalSep( '.' );
592 //@todo: enable this code when a localized decimal
593 //separator is also available for the formula
594 // SvtSysLocale aSysLocale;
595 // OUString aSep( aSysLocale.GetLocaleData().getNumDecimalSep());
596 // if( aSep.getLength() == 1 )
597 // aDecimalSep = aSep.toChar();
598 double fR( xCalculator->getCorrelationCoefficient());
599 aRet = aRet.replaceAt(
600 nIndex, aWildcard.getLength(),
601 ::rtl::math::doubleToUString(
602 fR*fR, rtl_math_StringFormat_G, 4, aDecimalSep, true ));
605 catch( const uno::Exception & ex )
607 ASSERT_EXCEPTION( ex );
612 else
614 // non-verbose
615 aRet = ObjectNameProvider::getName( eObjectType, false );
618 else if( OBJECTTYPE_DATA_AVERAGE_LINE == eObjectType )
620 if( bVerbose )
622 aRet = String( SchResId( STR_OBJECT_AVERAGE_LINE_WITH_PARAMETERS ));
623 Reference< chart2::XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID , xChartModel ));
624 Reference< chart2::XRegressionCurveContainer > xCurveCnt( xSeries, uno::UNO_QUERY );
625 if( xCurveCnt.is())
627 Reference< chart2::XRegressionCurve > xCurve( RegressionCurveHelper::getMeanValueLine( xCurveCnt ));
628 if( xCurve.is())
632 Reference< chart2::XRegressionCurveCalculator > xCalculator( xCurve->getCalculator(), uno::UNO_QUERY_THROW );
633 RegressionCurveHelper::initializeCurveCalculator( xCalculator, xSeries, xChartModel );
635 sal_Unicode aDecimalSep( '.' );
636 // replace average value
637 // SvtSysLocale aSysLocale;
638 // OUString aSep( aSysLocale.GetLocaleData().getNumDecimalSep());
639 // if( aSep.getLength() == 1 )
640 // aDecimalSep = aSep.toChar();
642 sal_Int32 nIndex = -1;
643 OUString aWildcard( C2U("%AVERAGE_VALUE") );
644 nIndex = aRet.indexOf( aWildcard );
645 // as the curve is constant, the value at any x-value is ok
646 if( nIndex != -1 )
648 const double fMeanValue( xCalculator->getCurveValue( 0.0 ));
649 aRet = aRet.replaceAt(
650 nIndex, aWildcard.getLength(),
651 ::rtl::math::doubleToUString(
652 fMeanValue, rtl_math_StringFormat_G, 4, aDecimalSep, true ));
655 // replace standard deviation
656 aWildcard = C2U("%STD_DEVIATION");
657 nIndex = aRet.indexOf( aWildcard );
658 if( nIndex != -1 )
660 const double fStdDev( xCalculator->getCorrelationCoefficient());
661 aRet = aRet.replaceAt(
662 nIndex, aWildcard.getLength(),
663 ::rtl::math::doubleToUString(
664 fStdDev, rtl_math_StringFormat_G, 4, aDecimalSep, true ));
667 catch( const uno::Exception & ex )
669 ASSERT_EXCEPTION( ex );
674 else
676 // non-verbose
677 aRet = ObjectNameProvider::getName( eObjectType, false );
680 else
682 aRet = ObjectNameProvider::getName( eObjectType, false );
684 return aRet;
687 // static
688 rtl::OUString ObjectNameProvider::getSelectedObjectText( const rtl::OUString & rObjectCID, const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartDocument >& xChartDocument )
690 rtl::OUString aRet;
691 ObjectType eObjectType( ObjectIdentifier::getObjectType(rObjectCID) );
692 Reference< frame::XModel > xChartModel( xChartDocument, uno::UNO_QUERY );
694 if( OBJECTTYPE_DATA_POINT == eObjectType )
696 aRet = String( SchResId( STR_STATUS_DATAPOINT_MARKED ));
698 Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) );
699 Reference< XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID , xChartModel ), uno::UNO_QUERY );
700 if( xDiagram.is() && xSeries.is() )
702 sal_Int32 nPointIndex( ObjectIdentifier::getParticleID(rObjectCID).toInt32() );
704 // replace data point index
705 replaceParamterInString( aRet, C2U("%POINTNUMBER"), OUString::valueOf( nPointIndex + 1 ));
707 // replace data series index
709 ::std::vector< Reference< chart2::XDataSeries > > aSeriesVector(
710 DiagramHelper::getDataSeriesFromDiagram( xDiagram ) );
711 sal_Int32 nSeriesIndex = -1;
712 for( nSeriesIndex=aSeriesVector.size();nSeriesIndex--;)
714 if( aSeriesVector[nSeriesIndex] == xSeries )
715 break;
717 replaceParamterInString( aRet, C2U("%SERIESNUMBER"), OUString::valueOf( nSeriesIndex + 1 ) );
720 // replace point value
721 replaceParamterInString( aRet, C2U("%POINTVALUES"), lcl_getDataPointValueText(
722 xSeries, nPointIndex, DataSeriesHelper::getCoordinateSystemOfSeries(xSeries, xDiagram), xChartModel ) );
725 else
727 // use the verbose text including the formula for trend lines
728 const bool bVerbose( OBJECTTYPE_DATA_CURVE == eObjectType || OBJECTTYPE_DATA_AVERAGE_LINE == eObjectType );
729 const OUString aHelpText( getHelpText( rObjectCID, xChartModel, bVerbose ));
730 if( aHelpText.getLength())
732 aRet = String( SchResId( STR_STATUS_OBJECT_MARKED ));
733 replaceParamterInString( aRet, C2U("%OBJECTNAME"), aHelpText );
737 return aRet;
741 // static
742 rtl::OUString ObjectNameProvider::getNameForCID(
743 const rtl::OUString& rObjectCID,
744 const uno::Reference< chart2::XChartDocument >& xChartDocument )
746 ObjectType eType( ObjectIdentifier::getObjectType( rObjectCID ));
747 Reference< frame::XModel > xModel( xChartDocument, uno::UNO_QUERY );
749 switch( eType )
751 case OBJECTTYPE_AXIS:
752 return getAxisName( rObjectCID, xModel );
753 case OBJECTTYPE_TITLE:
754 return getTitleName( rObjectCID, xModel );
755 case OBJECTTYPE_GRID:
756 return getGridName( rObjectCID, xModel );
757 default:
758 break;
761 return getName( eType );
765 //.............................................................................
766 } //namespace chart
767 //.............................................................................