Update ooo320-m1
[ooovba.git] / chart2 / source / controller / dialogs / ObjectNameProvider.cxx
blobb82bf7cfeffb3e574c00236a3c9f6820c81f8bc2
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 OUString lcl_getFullSeriesName( const rtl::OUString& rObjectCID, const Reference< frame::XModel >& xChartModel )
92 OUString aRet = String(SchResId(STR_TIP_DATASERIES));
93 OUString aWildcard( C2U("%SERIESNAME") );
94 sal_Int32 nIndex = aRet.indexOf( aWildcard );
95 if( nIndex != -1 )
96 aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), lcl_getDataSeriesName( rObjectCID, xChartModel ) );
97 return aRet;
100 void lcl_addText( OUString& rOut, const OUString& rSeparator, const OUString& rNext )
102 if( rOut.getLength() && rNext.getLength() )
103 rOut+=rSeparator;
104 if( rNext.getLength() )
105 rOut+=rNext;
108 OUString lcl_getDataPointValueText( const Reference< XDataSeries >& xSeries, sal_Int32 nPointIndex,
109 const Reference< XCoordinateSystem >& xCooSys,
110 const Reference< frame::XModel >& xChartModel )
113 OUString aRet;
115 Reference<data::XDataSource> xDataSource(
116 uno::Reference<data::XDataSource>( xSeries, uno::UNO_QUERY ) );
117 if(!xDataSource.is())
118 return aRet;
120 Sequence< Reference< data::XLabeledDataSequence > > aDataSequences( xDataSource->getDataSequences() );
122 rtl::OUString aX, aY, aY_Min, aY_Max, aY_First, aY_Last, a_Size;
123 double fValue = 0;
125 uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( xChartModel, uno::UNO_QUERY );
126 NumberFormatterWrapper aNumberFormatterWrapper( xNumberFormatsSupplier );
127 sal_Int32 nLabelColor = 0;//dummy
128 bool bColorChanged;//dummy
130 for(sal_Int32 nN = aDataSequences.getLength();nN--;)
132 uno::Reference<data::XDataSequence> xDataSequence( aDataSequences[nN]->getValues());
133 if( !xDataSequence.is() )
134 continue;
135 Sequence< Any > aData( xDataSequence->getData() );
136 if( nPointIndex >= aData.getLength() )
137 continue;
138 uno::Reference<beans::XPropertySet> xProp(xDataSequence, uno::UNO_QUERY );
139 if( xProp.is())
143 uno::Any aARole = xProp->getPropertyValue( C2U( "Role" ) );
144 rtl::OUString aRole;
145 aARole >>= aRole;
147 if( aRole.equals(C2U("values-x")) )
149 aData[nPointIndex]>>= fValue;
150 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
151 aX = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
153 else if( aRole.equals(C2U("values-y")) )
155 aData[nPointIndex]>>= fValue;
156 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
157 aY = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
159 else if( aRole.equals(C2U("values-first")) )
161 aData[nPointIndex]>>= fValue;
162 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
163 aY_First = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
165 else if( aRole.equals(C2U("values-min")) )
167 aData[nPointIndex]>>= fValue;
168 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
169 aY_Min = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
171 else if( aRole.equals(C2U("values-max")) )
173 aData[nPointIndex]>>= fValue;
174 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
175 aY_Max = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
177 else if( aRole.equals(C2U("values-last")) )
179 aData[nPointIndex]>>= fValue;
180 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
181 aY_Last = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
183 else if( aRole.equals(C2U("values-size")) )
185 aData[nPointIndex]>>= fValue;
186 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
187 a_Size = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
190 catch( uno::Exception& e )
192 ASSERT_EXCEPTION( e );
197 if( aX.getLength() == 0 )
199 rtl::OUString aCategory = ::rtl::OUString( String(SchResId(STR_TIP_CATEGORY_VALUE)));
201 replaceParamterInString( aCategory
202 , C2U("%CATEGORYVALUE")
203 , ExplicitCategoriesProvider::getCategoryByIndex( xCooSys, nPointIndex )
206 aRet = aCategory;
208 else
210 aRet = aX;
213 OUString aSeparator(C2U(" "));
215 lcl_addText( aRet, aSeparator, aY );
216 lcl_addText( aRet, aSeparator, aY_First );
217 lcl_addText( aRet, aSeparator, aY_Min );
218 lcl_addText( aRet, aSeparator, aY_Max );
219 lcl_addText( aRet, aSeparator, aY_Last );
220 lcl_addText( aRet, aSeparator, a_Size );
222 return aRet;
225 } //end anonymous namespace
227 rtl::OUString ObjectNameProvider::getName( ObjectType eObjectType, bool bPlural )
229 rtl::OUString aRet;
230 switch( eObjectType )
232 case OBJECTTYPE_PAGE:
233 aRet=String(SchResId(STR_OBJECT_PAGE));
234 break;
235 case OBJECTTYPE_TITLE:
237 if(bPlural)
238 aRet=String(SchResId(STR_OBJECT_TITLES));
239 else
240 aRet=String(SchResId(STR_OBJECT_TITLE));
242 break;
243 case OBJECTTYPE_LEGEND:
244 aRet=String(SchResId(STR_OBJECT_LEGEND));
245 break;
246 case OBJECTTYPE_LEGEND_ENTRY:
247 aRet=String(SchResId(STR_OBJECT_LEGEND_SYMBOL));//@todo change string if we do differenciate symbol and legend entry in future
248 break;
249 case OBJECTTYPE_DIAGRAM:
250 aRet=String(SchResId(STR_OBJECT_DIAGRAM));
251 break;
252 case OBJECTTYPE_DIAGRAM_WALL:
253 aRet=String(SchResId(STR_OBJECT_DIAGRAM_WALL));
254 break;
255 case OBJECTTYPE_DIAGRAM_FLOOR:
256 aRet=String(SchResId(STR_OBJECT_DIAGRAM_FLOOR));
257 break;
258 case OBJECTTYPE_AXIS:
260 if(bPlural)
261 aRet=String(SchResId(STR_OBJECT_AXES));
262 else
263 aRet=String(SchResId(STR_OBJECT_AXIS));
265 break;
266 case OBJECTTYPE_AXIS_UNITLABEL:
267 aRet=String(SchResId(STR_OBJECT_LABEL));//@todo maybe a more concrete name
268 break;
269 case OBJECTTYPE_GRID:
270 case OBJECTTYPE_SUBGRID: //maybe todo: different names for subgrids
272 if(bPlural)
273 aRet=String(SchResId(STR_OBJECT_GRIDS));
274 else
275 aRet=String(SchResId(STR_OBJECT_GRID));
277 break;
278 case OBJECTTYPE_DATA_SERIES:
280 if(bPlural)
281 aRet=String(SchResId(STR_OBJECT_DATASERIES_PLURAL));
282 else
283 aRet=String(SchResId(STR_OBJECT_DATASERIES));
285 break;
286 case OBJECTTYPE_DATA_POINT:
288 if(bPlural)
289 aRet=String(SchResId(STR_OBJECT_DATAPOINTS));
290 else
291 aRet=String(SchResId(STR_OBJECT_DATAPOINT));
293 break;
294 case OBJECTTYPE_DATA_LABELS:
295 aRet=String(SchResId(STR_OBJECT_DATALABELS));
296 break;
297 case OBJECTTYPE_DATA_LABEL:
298 aRet=String(SchResId(STR_OBJECT_LABEL));
299 break;
300 case OBJECTTYPE_DATA_ERRORS:
301 aRet=String(SchResId(STR_OBJECT_ERROR_BARS));//@todo? maybe distinguish plural singular
302 break;
303 case OBJECTTYPE_DATA_ERRORS_X:
304 aRet=String(SchResId(STR_OBJECT_ERROR_BARS));//@todo? maybe specialize in future
305 break;
306 case OBJECTTYPE_DATA_ERRORS_Y:
307 aRet=String(SchResId(STR_OBJECT_ERROR_BARS));//@todo? maybe specialize in future
308 break;
309 case OBJECTTYPE_DATA_ERRORS_Z:
310 aRet=String(SchResId(STR_OBJECT_ERROR_BARS));//@todo? maybe specialize in future
311 break;
312 case OBJECTTYPE_DATA_AVERAGE_LINE:
313 aRet=String(SchResId(STR_OBJECT_AVERAGE_LINE));
314 break;
315 case OBJECTTYPE_DATA_CURVE:
317 if(bPlural)
318 aRet=String(SchResId(STR_OBJECT_CURVES));
319 else
320 aRet=String(SchResId(STR_OBJECT_CURVE));
322 break;
323 case OBJECTTYPE_DATA_STOCK_RANGE:
324 //aRet=String(SchResId());
325 break;
326 case OBJECTTYPE_DATA_STOCK_LOSS:
327 aRet=String(SchResId(STR_OBJECT_STOCK_LOSS));
328 break;
329 case OBJECTTYPE_DATA_STOCK_GAIN:
330 aRet=String(SchResId(STR_OBJECT_STOCK_GAIN));
331 break;
332 case OBJECTTYPE_DATA_CURVE_EQUATION:
333 aRet=String(SchResId(STR_OBJECT_CURVE_EQUATION));
334 break;
335 default: //OBJECTTYPE_UNKNOWN
338 return aRet;
340 //static
341 rtl::OUString ObjectNameProvider::getAxisName( const rtl::OUString& rObjectCID
342 , const uno::Reference< frame::XModel >& xChartModel )
344 rtl::OUString aRet;
348 Reference< XAxis > xAxis(
349 ObjectIdentifier::getObjectPropertySet( rObjectCID , xChartModel ), uno::UNO_QUERY );
351 sal_Int32 nCooSysIndex = 0;
352 sal_Int32 nDimensionIndex = 0;
353 sal_Int32 nAxisIndex = 0;
354 AxisHelper::getIndicesForAxis( xAxis, ChartModelHelper::findDiagram( xChartModel ), nCooSysIndex, nDimensionIndex, nAxisIndex );
356 switch(nDimensionIndex)
358 case 0://x-axis
359 if( nAxisIndex == 0 )
360 aRet=String(SchResId(STR_OBJECT_AXIS_X));
361 else
362 aRet=String(SchResId(STR_OBJECT_SECONDARY_X_AXIS));
363 break;
364 case 1://y-axis
365 if( nAxisIndex == 0 )
366 aRet=String(SchResId(STR_OBJECT_AXIS_Y));
367 else
368 aRet=String(SchResId(STR_OBJECT_SECONDARY_Y_AXIS));
369 break;
370 case 2://z-axis
371 aRet=String(SchResId(STR_OBJECT_AXIS_Z));
372 break;
373 default://axis
374 aRet=String(SchResId(STR_OBJECT_AXIS));
375 break;
378 return aRet;
381 //static
382 OUString ObjectNameProvider::getTitleNameByType( TitleHelper::eTitleType eType )
384 OUString aRet;
386 switch(eType)
388 case TitleHelper::MAIN_TITLE:
389 aRet=String(SchResId(STR_OBJECT_TITLE_MAIN));
390 break;
391 case TitleHelper::SUB_TITLE:
392 aRet=String(SchResId(STR_OBJECT_TITLE_SUB));
393 break;
394 case TitleHelper::X_AXIS_TITLE:
395 aRet=String(SchResId(STR_OBJECT_TITLE_X_AXIS));
396 break;
397 case TitleHelper::Y_AXIS_TITLE:
398 aRet=String(SchResId(STR_OBJECT_TITLE_Y_AXIS));
399 break;
400 case TitleHelper::Z_AXIS_TITLE:
401 aRet=String(SchResId(STR_OBJECT_TITLE_Z_AXIS));
402 break;
403 case TitleHelper::SECONDARY_X_AXIS_TITLE:
404 aRet=String(SchResId(STR_OBJECT_TITLE_SECONDARY_X_AXIS));
405 break;
406 case TitleHelper::SECONDARY_Y_AXIS_TITLE:
407 aRet=String(SchResId(STR_OBJECT_TITLE_SECONDARY_Y_AXIS));
408 break;
409 default:
410 DBG_ERROR("unknown title type");
411 break;
414 if( !aRet.getLength() )
415 aRet=String(SchResId(STR_OBJECT_TITLE));
417 return aRet;
420 //static
421 OUString ObjectNameProvider::getTitleName( const OUString& rObjectCID
422 , const Reference< frame::XModel >& xChartModel )
424 OUString aRet;
426 Reference< XTitle > xTitle(
427 ObjectIdentifier::getObjectPropertySet( rObjectCID , xChartModel ), uno::UNO_QUERY );
428 if( xTitle.is() )
430 TitleHelper::eTitleType eType;
431 if( TitleHelper::getTitleType( eType, xTitle, xChartModel ) )
432 aRet = ObjectNameProvider::getTitleNameByType( eType );
434 if( !aRet.getLength() )
435 aRet=String(SchResId(STR_OBJECT_TITLE));
437 return aRet;
440 //static
441 rtl::OUString ObjectNameProvider::getGridName( const rtl::OUString& rObjectCID
442 , const uno::Reference< frame::XModel >& xChartModel )
444 rtl::OUString aRet;
447 sal_Int32 nCooSysIndex = -1;
448 sal_Int32 nDimensionIndex = -1;
449 sal_Int32 nAxisIndex = -1;
450 Reference< XAxis > xAxis( ObjectIdentifier::getAxisForCID( rObjectCID , xChartModel ) );
451 AxisHelper::getIndicesForAxis( xAxis, ChartModelHelper::findDiagram( xChartModel )
452 , nCooSysIndex , nDimensionIndex, nAxisIndex );
454 bool bMainGrid = (ObjectIdentifier::getObjectType( rObjectCID ) == OBJECTTYPE_GRID);
456 if( bMainGrid )
458 switch(nDimensionIndex)
460 case 0://x-axis
461 aRet=String(SchResId(STR_OBJECT_GRID_MAJOR_X));
462 break;
463 case 1://y-axis
464 aRet=String(SchResId(STR_OBJECT_GRID_MAJOR_Y));
465 break;
466 case 2://z-axis
467 aRet=String(SchResId(STR_OBJECT_GRID_MAJOR_Z));
468 break;
469 default://axis
470 aRet=String(SchResId(STR_OBJECT_GRID));
471 break;
474 else
476 switch(nDimensionIndex)
478 case 0://x-axis
479 aRet=String(SchResId(STR_OBJECT_GRID_MINOR_X));
480 break;
481 case 1://y-axis
482 aRet=String(SchResId(STR_OBJECT_GRID_MINOR_Y));
483 break;
484 case 2://z-axis
485 aRet=String(SchResId(STR_OBJECT_GRID_MINOR_Z));
486 break;
487 default://axis
488 aRet=String(SchResId(STR_OBJECT_GRID));
489 break;
492 return aRet;
495 rtl::OUString ObjectNameProvider::getHelpText( const rtl::OUString& rObjectCID, const Reference< chart2::XChartDocument >& xChartDocument, bool bVerbose )
497 return getHelpText( rObjectCID, Reference< frame::XModel >( xChartDocument, uno::UNO_QUERY ), bVerbose );
500 rtl::OUString ObjectNameProvider::getHelpText( const rtl::OUString& rObjectCID, const Reference< frame::XModel >& xChartModel, bool bVerbose )
502 rtl::OUString aRet;
503 ObjectType eObjectType( ObjectIdentifier::getObjectType(rObjectCID) );
504 if( OBJECTTYPE_AXIS == eObjectType )
506 aRet=ObjectNameProvider::getAxisName( rObjectCID, xChartModel );
508 else if( OBJECTTYPE_GRID == eObjectType
509 || OBJECTTYPE_SUBGRID == eObjectType )
511 aRet=ObjectNameProvider::getGridName( rObjectCID, xChartModel );
513 else if( OBJECTTYPE_TITLE == eObjectType )
515 aRet=ObjectNameProvider::getTitleName( rObjectCID, xChartModel );
517 else if( OBJECTTYPE_DATA_SERIES == eObjectType )
519 aRet = lcl_getFullSeriesName( rObjectCID, xChartModel );
521 else if( OBJECTTYPE_DATA_POINT == eObjectType )
523 if( bVerbose )
525 OUString aNewLine(C2U("\n"));
527 aRet=String(SchResId(STR_TIP_DATAPOINT_INDEX));
528 aRet+=aNewLine;
529 aRet+=String(SchResId(STR_TIP_DATASERIES));
530 aRet+=aNewLine;
531 aRet+=String(SchResId(STR_TIP_DATAPOINT_VALUES));
533 else
534 aRet=String(SchResId(STR_TIP_DATAPOINT));
536 Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) );
537 Reference< XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID , xChartModel ), uno::UNO_QUERY );
538 if( xDiagram.is() && xSeries.is() )
540 sal_Int32 nPointIndex( ObjectIdentifier::getParticleID(rObjectCID).toInt32() );
542 //replace data point index
543 sal_Int32 nIndex = -1;
544 OUString aWildcard( C2U("%POINTNUMBER") );
545 nIndex = aRet.indexOf( aWildcard );
546 if( nIndex != -1 )
548 aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), OUString::valueOf(nPointIndex+1) );
551 //replace data series index
552 aWildcard = C2U("%SERIESNUMBER");
553 nIndex = aRet.indexOf( aWildcard );
554 if( nIndex != -1 )
556 ::std::vector< Reference< chart2::XDataSeries > > aSeriesVector(
557 DiagramHelper::getDataSeriesFromDiagram( xDiagram ) );
558 sal_Int32 nSeriesIndex = -1;
559 for( nSeriesIndex=aSeriesVector.size();nSeriesIndex--;)
561 if( aSeriesVector[nSeriesIndex] == xSeries )
563 break;
567 OUString aReplacement( OUString::valueOf(nSeriesIndex+1) );
568 aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), aReplacement );
571 //replace point values
572 aWildcard = C2U("%POINTVALUES");
573 nIndex = aRet.indexOf( aWildcard );
574 if( nIndex != -1 )
575 aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), lcl_getDataPointValueText(
576 xSeries,nPointIndex, DataSeriesHelper::getCoordinateSystemOfSeries(xSeries, xDiagram), xChartModel ) );
578 //replace series name
579 aWildcard = C2U("%SERIESNAME");
580 nIndex = aRet.indexOf( aWildcard );
581 if( nIndex != -1 )
582 aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), lcl_getDataSeriesName( rObjectCID, xChartModel ) );
586 else if( OBJECTTYPE_DIAGRAM == eObjectType )
588 //todo different names for different diagram types ???
589 //or different names for series of diferent charttypes
592 else if( OBJECTTYPE_DATA_CURVE == eObjectType )
594 if( bVerbose )
596 aRet = String( SchResId( STR_OBJECT_CURVE_WITH_PARAMETERS ));
597 Reference< chart2::XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID , xChartModel ));
598 Reference< chart2::XRegressionCurveContainer > xCurveCnt( xSeries, uno::UNO_QUERY );
599 if( xCurveCnt.is())
601 Reference< chart2::XRegressionCurve > xCurve( RegressionCurveHelper::getFirstCurveNotMeanValueLine( xCurveCnt ));
602 if( xCurve.is())
606 Reference< chart2::XRegressionCurveCalculator > xCalculator( xCurve->getCalculator(), uno::UNO_QUERY_THROW );
607 RegressionCurveHelper::initializeCurveCalculator( xCalculator, xSeries, xChartModel );
609 // replace formula
610 sal_Int32 nIndex = -1;
611 OUString aWildcard( C2U("%FORMULA") );
612 nIndex = aRet.indexOf( aWildcard );
613 if( nIndex != -1 )
614 aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), xCalculator->getRepresentation());
616 // replace r^2
617 aWildcard = C2U("%RSQUARED");
618 nIndex = aRet.indexOf( aWildcard );
619 if( nIndex != -1 )
621 sal_Unicode aDecimalSep( '.' );
622 //@todo: enable this code when a localized decimal
623 //separator is also available for the formula
624 // SvtSysLocale aSysLocale;
625 // OUString aSep( aSysLocale.GetLocaleData().getNumDecimalSep());
626 // if( aSep.getLength() == 1 )
627 // aDecimalSep = aSep.toChar();
628 double fR( xCalculator->getCorrelationCoefficient());
629 aRet = aRet.replaceAt(
630 nIndex, aWildcard.getLength(),
631 ::rtl::math::doubleToUString(
632 fR*fR, rtl_math_StringFormat_G, 4, aDecimalSep, true ));
635 catch( const uno::Exception & ex )
637 ASSERT_EXCEPTION( ex );
642 else
644 // non-verbose
645 aRet = ObjectNameProvider::getName( eObjectType, false );
648 else if( OBJECTTYPE_DATA_AVERAGE_LINE == eObjectType )
650 if( bVerbose )
652 aRet = String( SchResId( STR_OBJECT_AVERAGE_LINE_WITH_PARAMETERS ));
653 Reference< chart2::XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID , xChartModel ));
654 Reference< chart2::XRegressionCurveContainer > xCurveCnt( xSeries, uno::UNO_QUERY );
655 if( xCurveCnt.is())
657 Reference< chart2::XRegressionCurve > xCurve( RegressionCurveHelper::getMeanValueLine( xCurveCnt ));
658 if( xCurve.is())
662 Reference< chart2::XRegressionCurveCalculator > xCalculator( xCurve->getCalculator(), uno::UNO_QUERY_THROW );
663 RegressionCurveHelper::initializeCurveCalculator( xCalculator, xSeries, xChartModel );
665 sal_Unicode aDecimalSep( '.' );
666 // replace average value
667 // SvtSysLocale aSysLocale;
668 // OUString aSep( aSysLocale.GetLocaleData().getNumDecimalSep());
669 // if( aSep.getLength() == 1 )
670 // aDecimalSep = aSep.toChar();
672 sal_Int32 nIndex = -1;
673 OUString aWildcard( C2U("%AVERAGE_VALUE") );
674 nIndex = aRet.indexOf( aWildcard );
675 // as the curve is constant, the value at any x-value is ok
676 if( nIndex != -1 )
678 const double fMeanValue( xCalculator->getCurveValue( 0.0 ));
679 aRet = aRet.replaceAt(
680 nIndex, aWildcard.getLength(),
681 ::rtl::math::doubleToUString(
682 fMeanValue, rtl_math_StringFormat_G, 4, aDecimalSep, true ));
685 // replace standard deviation
686 aWildcard = C2U("%STD_DEVIATION");
687 nIndex = aRet.indexOf( aWildcard );
688 if( nIndex != -1 )
690 const double fStdDev( xCalculator->getCorrelationCoefficient());
691 aRet = aRet.replaceAt(
692 nIndex, aWildcard.getLength(),
693 ::rtl::math::doubleToUString(
694 fStdDev, rtl_math_StringFormat_G, 4, aDecimalSep, true ));
697 catch( const uno::Exception & ex )
699 ASSERT_EXCEPTION( ex );
704 else
706 // non-verbose
707 aRet = ObjectNameProvider::getName( eObjectType, false );
710 else
712 aRet = ObjectNameProvider::getName( eObjectType, false );
714 return aRet;
717 // static
718 rtl::OUString ObjectNameProvider::getSelectedObjectText( const rtl::OUString & rObjectCID, const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartDocument >& xChartDocument )
720 rtl::OUString aRet;
721 ObjectType eObjectType( ObjectIdentifier::getObjectType(rObjectCID) );
722 Reference< frame::XModel > xChartModel( xChartDocument, uno::UNO_QUERY );
724 if( OBJECTTYPE_DATA_POINT == eObjectType )
726 aRet = String( SchResId( STR_STATUS_DATAPOINT_MARKED ));
728 Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) );
729 Reference< XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID , xChartModel ), uno::UNO_QUERY );
730 if( xDiagram.is() && xSeries.is() )
732 sal_Int32 nPointIndex( ObjectIdentifier::getParticleID(rObjectCID).toInt32() );
734 // replace data point index
735 replaceParamterInString( aRet, C2U("%POINTNUMBER"), OUString::valueOf( 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 )
745 break;
747 replaceParamterInString( aRet, C2U("%SERIESNUMBER"), OUString::valueOf( nSeriesIndex + 1 ) );
750 // replace point value
751 replaceParamterInString( aRet, C2U("%POINTVALUES"), lcl_getDataPointValueText(
752 xSeries, nPointIndex, DataSeriesHelper::getCoordinateSystemOfSeries(xSeries, xDiagram), xChartModel ) );
755 else
757 // use the verbose text including the formula for trend lines
758 const bool bVerbose( OBJECTTYPE_DATA_CURVE == eObjectType || OBJECTTYPE_DATA_AVERAGE_LINE == eObjectType );
759 const OUString aHelpText( getHelpText( rObjectCID, xChartModel, bVerbose ));
760 if( aHelpText.getLength())
762 aRet = String( SchResId( STR_STATUS_OBJECT_MARKED ));
763 replaceParamterInString( aRet, C2U("%OBJECTNAME"), aHelpText );
767 return aRet;
771 // static
772 rtl::OUString ObjectNameProvider::getNameForCID(
773 const rtl::OUString& rObjectCID,
774 const uno::Reference< chart2::XChartDocument >& xChartDocument )
776 ObjectType eType( ObjectIdentifier::getObjectType( rObjectCID ));
777 Reference< frame::XModel > xModel( xChartDocument, uno::UNO_QUERY );
779 switch( eType )
781 case OBJECTTYPE_AXIS:
782 return getAxisName( rObjectCID, xModel );
783 case OBJECTTYPE_TITLE:
784 return getTitleName( rObjectCID, xModel );
785 case OBJECTTYPE_GRID:
786 case OBJECTTYPE_SUBGRID:
787 return getGridName( rObjectCID, xModel );
788 case OBJECTTYPE_DATA_SERIES:
789 return lcl_getFullSeriesName( rObjectCID, xModel );
790 //case OBJECTTYPE_LEGEND_ENTRY:
791 case OBJECTTYPE_DATA_POINT:
792 case OBJECTTYPE_DATA_LABELS:
793 case OBJECTTYPE_DATA_LABEL:
794 case OBJECTTYPE_DATA_ERRORS:
795 case OBJECTTYPE_DATA_ERRORS_X:
796 case OBJECTTYPE_DATA_ERRORS_Y:
797 case OBJECTTYPE_DATA_ERRORS_Z:
798 case OBJECTTYPE_DATA_CURVE:
799 case OBJECTTYPE_DATA_AVERAGE_LINE:
800 case OBJECTTYPE_DATA_CURVE_EQUATION:
802 rtl::OUString aRet = lcl_getFullSeriesName( rObjectCID, xModel );
803 aRet += C2U(" ");
804 if( eType == OBJECTTYPE_DATA_POINT || eType == OBJECTTYPE_DATA_LABEL )
806 aRet += getName( OBJECTTYPE_DATA_POINT );
807 sal_Int32 nPointIndex = ObjectIdentifier::getIndexFromParticleOrCID( rObjectCID );
808 aRet += C2U(" ");
809 aRet += OUString::valueOf(nPointIndex+1);
811 if( eType == OBJECTTYPE_DATA_LABEL )
813 aRet += C2U(" ");
814 aRet += getName( OBJECTTYPE_DATA_LABEL );
817 else
818 aRet += getName( eType );
819 return aRet;
821 default:
822 break;
825 return getName( eType );
828 //static
829 rtl::OUString ObjectNameProvider::getName_ObjectForSeries(
830 ObjectType eObjectType,
831 const rtl::OUString& rSeriesCID,
832 const uno::Reference< chart2::XChartDocument >& xChartDocument )
834 uno::Reference< frame::XModel> xChartModel( xChartDocument, uno::UNO_QUERY );
835 Reference< XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( rSeriesCID , xChartModel ), uno::UNO_QUERY );
836 if( xSeries.is() )
838 OUString aRet = String(SchResId(STR_OBJECT_FOR_SERIES));
839 replaceParamterInString( aRet, C2U("%OBJECTNAME"), getName( eObjectType, false /*bPlural*/ ) );
840 replaceParamterInString( aRet, C2U("%SERIESNAME"), lcl_getDataSeriesName( rSeriesCID, xChartModel ) );
841 return aRet;
843 else
844 return ObjectNameProvider::getName_ObjectForAllSeries( eObjectType );
847 //static
848 rtl::OUString ObjectNameProvider::getName_ObjectForAllSeries( ObjectType eObjectType )
850 OUString aRet = String(SchResId(STR_OBJECT_FOR_ALL_SERIES));
851 replaceParamterInString( aRet, C2U("%OBJECTNAME"), getName( eObjectType, true /*bPlural*/ ) );
852 return aRet;
855 //.............................................................................
856 } //namespace chart
857 //.............................................................................