merged tag ooo/OOO330_m14
[LibreOffice.git] / chart2 / source / controller / dialogs / ObjectNameProvider.cxx
blob0836ab9ca93a60bb849e58fe6afe9c6d7511d21f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_chart2.hxx"
31 #include "ObjectNameProvider.hxx"
32 #include "ResId.hxx"
33 #include "Strings.hrc"
34 #include "macros.hxx"
35 #include "AxisHelper.hxx"
36 #include "ChartModelHelper.hxx"
37 #include "DiagramHelper.hxx"
38 #include "DataSeriesHelper.hxx"
39 #include "TitleHelper.hxx"
40 #include "AxisIndexDefines.hxx"
41 #include "ExplicitCategoriesProvider.hxx"
42 #include "CommonConverters.hxx"
43 #include "chartview/NumberFormatterWrapper.hxx"
44 #include "RegressionCurveHelper.hxx"
45 #include <rtl/math.hxx>
46 #include <tools/debug.hxx>
47 #include <tools/string.hxx>
49 #include <com/sun/star/chart2/XTitle.hpp>
50 #include <com/sun/star/chart2/XRegressionCurveContainer.hpp>
52 //.............................................................................
53 namespace chart
55 //.............................................................................
56 using namespace ::com::sun::star;
57 using namespace ::com::sun::star::chart2;
58 using ::com::sun::star::uno::Reference;
59 using ::com::sun::star::uno::Sequence;
60 using ::com::sun::star::uno::Any;
61 using rtl::OUString;
63 namespace
66 OUString lcl_getDataSeriesName( const rtl::OUString& rObjectCID, const Reference< frame::XModel >& xChartModel )
68 OUString aRet;
70 Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) );
71 Reference< XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID , xChartModel ), uno::UNO_QUERY );
72 if( xDiagram.is() && xSeries.is() )
74 Reference< XChartType > xChartType( DiagramHelper::getChartTypeOfSeries( xDiagram, xSeries ) );
75 if( xChartType.is() )
77 aRet = ::chart::DataSeriesHelper::getDataSeriesLabel(
78 xSeries, xChartType->getRoleOfSequenceForSeriesLabel() ) ;
82 return aRet;
85 OUString lcl_getFullSeriesName( const rtl::OUString& rObjectCID, const Reference< frame::XModel >& xChartModel )
87 OUString aRet = String(SchResId(STR_TIP_DATASERIES));
88 OUString aWildcard( C2U("%SERIESNAME") );
89 sal_Int32 nIndex = aRet.indexOf( aWildcard );
90 if( nIndex != -1 )
91 aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), lcl_getDataSeriesName( rObjectCID, xChartModel ) );
92 return aRet;
95 void lcl_addText( OUString& rOut, const OUString& rSeparator, const OUString& rNext )
97 if( rOut.getLength() && rNext.getLength() )
98 rOut+=rSeparator;
99 if( rNext.getLength() )
100 rOut+=rNext;
103 OUString lcl_getDataPointValueText( const Reference< XDataSeries >& xSeries, sal_Int32 nPointIndex,
104 const Reference< XCoordinateSystem >& xCooSys,
105 const Reference< frame::XModel >& xChartModel )
108 OUString aRet;
110 Reference<data::XDataSource> xDataSource(
111 uno::Reference<data::XDataSource>( xSeries, uno::UNO_QUERY ) );
112 if(!xDataSource.is())
113 return aRet;
115 Sequence< Reference< data::XLabeledDataSequence > > aDataSequences( xDataSource->getDataSequences() );
117 rtl::OUString aX, aY, aY_Min, aY_Max, aY_First, aY_Last, a_Size;
118 double fValue = 0;
120 uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( xChartModel, uno::UNO_QUERY );
121 NumberFormatterWrapper aNumberFormatterWrapper( xNumberFormatsSupplier );
122 sal_Int32 nLabelColor = 0;//dummy
123 bool bColorChanged;//dummy
125 for(sal_Int32 nN = aDataSequences.getLength();nN--;)
127 uno::Reference<data::XDataSequence> xDataSequence( aDataSequences[nN]->getValues());
128 if( !xDataSequence.is() )
129 continue;
130 Sequence< Any > aData( xDataSequence->getData() );
131 if( nPointIndex >= aData.getLength() )
132 continue;
133 uno::Reference<beans::XPropertySet> xProp(xDataSequence, uno::UNO_QUERY );
134 if( xProp.is())
138 uno::Any aARole = xProp->getPropertyValue( C2U( "Role" ) );
139 rtl::OUString aRole;
140 aARole >>= aRole;
142 if( aRole.equals(C2U("values-x")) )
144 aData[nPointIndex]>>= fValue;
145 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
146 aX = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
148 else if( aRole.equals(C2U("values-y")) )
150 aData[nPointIndex]>>= fValue;
151 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
152 aY = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
154 else if( aRole.equals(C2U("values-first")) )
156 aData[nPointIndex]>>= fValue;
157 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
158 aY_First = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
160 else if( aRole.equals(C2U("values-min")) )
162 aData[nPointIndex]>>= fValue;
163 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
164 aY_Min = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
166 else if( aRole.equals(C2U("values-max")) )
168 aData[nPointIndex]>>= fValue;
169 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
170 aY_Max = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
172 else if( aRole.equals(C2U("values-last")) )
174 aData[nPointIndex]>>= fValue;
175 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
176 aY_Last = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
178 else if( aRole.equals(C2U("values-size")) )
180 aData[nPointIndex]>>= fValue;
181 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
182 a_Size = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
185 catch( uno::Exception& e )
187 ASSERT_EXCEPTION( e );
192 if( aX.getLength() == 0 )
194 rtl::OUString aCategory = ::rtl::OUString( String(SchResId(STR_TIP_CATEGORY_VALUE)));
196 replaceParamterInString( aCategory
197 , C2U("%CATEGORYVALUE")
198 , ExplicitCategoriesProvider::getCategoryByIndex( xCooSys, xChartModel, nPointIndex )
201 aRet = aCategory;
203 else
205 aRet = aX;
208 OUString aSeparator(C2U(" "));
210 lcl_addText( aRet, aSeparator, aY );
211 lcl_addText( aRet, aSeparator, aY_First );
212 lcl_addText( aRet, aSeparator, aY_Min );
213 lcl_addText( aRet, aSeparator, aY_Max );
214 lcl_addText( aRet, aSeparator, aY_Last );
215 lcl_addText( aRet, aSeparator, a_Size );
217 return aRet;
220 } //end anonymous namespace
222 rtl::OUString ObjectNameProvider::getName( ObjectType eObjectType, bool bPlural )
224 rtl::OUString aRet;
225 switch( eObjectType )
227 case OBJECTTYPE_PAGE:
228 aRet=String(SchResId(STR_OBJECT_PAGE));
229 break;
230 case OBJECTTYPE_TITLE:
232 if(bPlural)
233 aRet=String(SchResId(STR_OBJECT_TITLES));
234 else
235 aRet=String(SchResId(STR_OBJECT_TITLE));
237 break;
238 case OBJECTTYPE_LEGEND:
239 aRet=String(SchResId(STR_OBJECT_LEGEND));
240 break;
241 case OBJECTTYPE_LEGEND_ENTRY:
242 aRet=String(SchResId(STR_OBJECT_LEGEND_SYMBOL));//@todo change string if we do differenciate symbol and legend entry in future
243 break;
244 case OBJECTTYPE_DIAGRAM:
245 aRet=String(SchResId(STR_OBJECT_DIAGRAM));
246 break;
247 case OBJECTTYPE_DIAGRAM_WALL:
248 aRet=String(SchResId(STR_OBJECT_DIAGRAM_WALL));
249 break;
250 case OBJECTTYPE_DIAGRAM_FLOOR:
251 aRet=String(SchResId(STR_OBJECT_DIAGRAM_FLOOR));
252 break;
253 case OBJECTTYPE_AXIS:
255 if(bPlural)
256 aRet=String(SchResId(STR_OBJECT_AXES));
257 else
258 aRet=String(SchResId(STR_OBJECT_AXIS));
260 break;
261 case OBJECTTYPE_AXIS_UNITLABEL:
262 aRet=String(SchResId(STR_OBJECT_LABEL));//@todo maybe a more concrete name
263 break;
264 case OBJECTTYPE_GRID:
265 case OBJECTTYPE_SUBGRID: //maybe todo: different names for subgrids
267 if(bPlural)
268 aRet=String(SchResId(STR_OBJECT_GRIDS));
269 else
270 aRet=String(SchResId(STR_OBJECT_GRID));
272 break;
273 case OBJECTTYPE_DATA_SERIES:
275 if(bPlural)
276 aRet=String(SchResId(STR_OBJECT_DATASERIES_PLURAL));
277 else
278 aRet=String(SchResId(STR_OBJECT_DATASERIES));
280 break;
281 case OBJECTTYPE_DATA_POINT:
283 if(bPlural)
284 aRet=String(SchResId(STR_OBJECT_DATAPOINTS));
285 else
286 aRet=String(SchResId(STR_OBJECT_DATAPOINT));
288 break;
289 case OBJECTTYPE_DATA_LABELS:
290 aRet=String(SchResId(STR_OBJECT_DATALABELS));
291 break;
292 case OBJECTTYPE_DATA_LABEL:
293 aRet=String(SchResId(STR_OBJECT_LABEL));
294 break;
295 case OBJECTTYPE_DATA_ERRORS:
296 aRet=String(SchResId(STR_OBJECT_ERROR_BARS));//@todo? maybe distinguish plural singular
297 break;
298 case OBJECTTYPE_DATA_ERRORS_X:
299 aRet=String(SchResId(STR_OBJECT_ERROR_BARS));//@todo? maybe specialize in future
300 break;
301 case OBJECTTYPE_DATA_ERRORS_Y:
302 aRet=String(SchResId(STR_OBJECT_ERROR_BARS));//@todo? maybe specialize in future
303 break;
304 case OBJECTTYPE_DATA_ERRORS_Z:
305 aRet=String(SchResId(STR_OBJECT_ERROR_BARS));//@todo? maybe specialize in future
306 break;
307 case OBJECTTYPE_DATA_AVERAGE_LINE:
308 aRet=String(SchResId(STR_OBJECT_AVERAGE_LINE));
309 break;
310 case OBJECTTYPE_DATA_CURVE:
312 if(bPlural)
313 aRet=String(SchResId(STR_OBJECT_CURVES));
314 else
315 aRet=String(SchResId(STR_OBJECT_CURVE));
317 break;
318 case OBJECTTYPE_DATA_STOCK_RANGE:
319 //aRet=String(SchResId());
320 break;
321 case OBJECTTYPE_DATA_STOCK_LOSS:
322 aRet=String(SchResId(STR_OBJECT_STOCK_LOSS));
323 break;
324 case OBJECTTYPE_DATA_STOCK_GAIN:
325 aRet=String(SchResId(STR_OBJECT_STOCK_GAIN));
326 break;
327 case OBJECTTYPE_DATA_CURVE_EQUATION:
328 aRet=String(SchResId(STR_OBJECT_CURVE_EQUATION));
329 break;
330 default: //OBJECTTYPE_UNKNOWN
333 return aRet;
335 //static
336 rtl::OUString ObjectNameProvider::getAxisName( const rtl::OUString& rObjectCID
337 , const uno::Reference< frame::XModel >& xChartModel )
339 rtl::OUString aRet;
343 Reference< XAxis > xAxis(
344 ObjectIdentifier::getObjectPropertySet( rObjectCID , xChartModel ), uno::UNO_QUERY );
346 sal_Int32 nCooSysIndex = 0;
347 sal_Int32 nDimensionIndex = 0;
348 sal_Int32 nAxisIndex = 0;
349 AxisHelper::getIndicesForAxis( xAxis, ChartModelHelper::findDiagram( xChartModel ), nCooSysIndex, nDimensionIndex, nAxisIndex );
351 switch(nDimensionIndex)
353 case 0://x-axis
354 if( nAxisIndex == 0 )
355 aRet=String(SchResId(STR_OBJECT_AXIS_X));
356 else
357 aRet=String(SchResId(STR_OBJECT_SECONDARY_X_AXIS));
358 break;
359 case 1://y-axis
360 if( nAxisIndex == 0 )
361 aRet=String(SchResId(STR_OBJECT_AXIS_Y));
362 else
363 aRet=String(SchResId(STR_OBJECT_SECONDARY_Y_AXIS));
364 break;
365 case 2://z-axis
366 aRet=String(SchResId(STR_OBJECT_AXIS_Z));
367 break;
368 default://axis
369 aRet=String(SchResId(STR_OBJECT_AXIS));
370 break;
373 return aRet;
376 //static
377 OUString ObjectNameProvider::getTitleNameByType( TitleHelper::eTitleType eType )
379 OUString aRet;
381 switch(eType)
383 case TitleHelper::MAIN_TITLE:
384 aRet=String(SchResId(STR_OBJECT_TITLE_MAIN));
385 break;
386 case TitleHelper::SUB_TITLE:
387 aRet=String(SchResId(STR_OBJECT_TITLE_SUB));
388 break;
389 case TitleHelper::X_AXIS_TITLE:
390 aRet=String(SchResId(STR_OBJECT_TITLE_X_AXIS));
391 break;
392 case TitleHelper::Y_AXIS_TITLE:
393 aRet=String(SchResId(STR_OBJECT_TITLE_Y_AXIS));
394 break;
395 case TitleHelper::Z_AXIS_TITLE:
396 aRet=String(SchResId(STR_OBJECT_TITLE_Z_AXIS));
397 break;
398 case TitleHelper::SECONDARY_X_AXIS_TITLE:
399 aRet=String(SchResId(STR_OBJECT_TITLE_SECONDARY_X_AXIS));
400 break;
401 case TitleHelper::SECONDARY_Y_AXIS_TITLE:
402 aRet=String(SchResId(STR_OBJECT_TITLE_SECONDARY_Y_AXIS));
403 break;
404 default:
405 DBG_ERROR("unknown title type");
406 break;
409 if( !aRet.getLength() )
410 aRet=String(SchResId(STR_OBJECT_TITLE));
412 return aRet;
415 //static
416 OUString ObjectNameProvider::getTitleName( const OUString& rObjectCID
417 , const Reference< frame::XModel >& xChartModel )
419 OUString aRet;
421 Reference< XTitle > xTitle(
422 ObjectIdentifier::getObjectPropertySet( rObjectCID , xChartModel ), uno::UNO_QUERY );
423 if( xTitle.is() )
425 TitleHelper::eTitleType eType;
426 if( TitleHelper::getTitleType( eType, xTitle, xChartModel ) )
427 aRet = ObjectNameProvider::getTitleNameByType( eType );
429 if( !aRet.getLength() )
430 aRet=String(SchResId(STR_OBJECT_TITLE));
432 return aRet;
435 //static
436 rtl::OUString ObjectNameProvider::getGridName( const rtl::OUString& rObjectCID
437 , const uno::Reference< frame::XModel >& xChartModel )
439 rtl::OUString aRet;
442 sal_Int32 nCooSysIndex = -1;
443 sal_Int32 nDimensionIndex = -1;
444 sal_Int32 nAxisIndex = -1;
445 Reference< XAxis > xAxis( ObjectIdentifier::getAxisForCID( rObjectCID , xChartModel ) );
446 AxisHelper::getIndicesForAxis( xAxis, ChartModelHelper::findDiagram( xChartModel )
447 , nCooSysIndex , nDimensionIndex, nAxisIndex );
449 bool bMainGrid = (ObjectIdentifier::getObjectType( rObjectCID ) == OBJECTTYPE_GRID);
451 if( bMainGrid )
453 switch(nDimensionIndex)
455 case 0://x-axis
456 aRet=String(SchResId(STR_OBJECT_GRID_MAJOR_X));
457 break;
458 case 1://y-axis
459 aRet=String(SchResId(STR_OBJECT_GRID_MAJOR_Y));
460 break;
461 case 2://z-axis
462 aRet=String(SchResId(STR_OBJECT_GRID_MAJOR_Z));
463 break;
464 default://axis
465 aRet=String(SchResId(STR_OBJECT_GRID));
466 break;
469 else
471 switch(nDimensionIndex)
473 case 0://x-axis
474 aRet=String(SchResId(STR_OBJECT_GRID_MINOR_X));
475 break;
476 case 1://y-axis
477 aRet=String(SchResId(STR_OBJECT_GRID_MINOR_Y));
478 break;
479 case 2://z-axis
480 aRet=String(SchResId(STR_OBJECT_GRID_MINOR_Z));
481 break;
482 default://axis
483 aRet=String(SchResId(STR_OBJECT_GRID));
484 break;
487 return aRet;
490 rtl::OUString ObjectNameProvider::getHelpText( const rtl::OUString& rObjectCID, const Reference< chart2::XChartDocument >& xChartDocument, bool bVerbose )
492 return getHelpText( rObjectCID, Reference< frame::XModel >( xChartDocument, uno::UNO_QUERY ), bVerbose );
495 rtl::OUString ObjectNameProvider::getHelpText( const rtl::OUString& rObjectCID, const Reference< frame::XModel >& xChartModel, bool bVerbose )
497 rtl::OUString aRet;
498 ObjectType eObjectType( ObjectIdentifier::getObjectType(rObjectCID) );
499 if( OBJECTTYPE_AXIS == eObjectType )
501 aRet=ObjectNameProvider::getAxisName( rObjectCID, xChartModel );
503 else if( OBJECTTYPE_GRID == eObjectType
504 || OBJECTTYPE_SUBGRID == eObjectType )
506 aRet=ObjectNameProvider::getGridName( rObjectCID, xChartModel );
508 else if( OBJECTTYPE_TITLE == eObjectType )
510 aRet=ObjectNameProvider::getTitleName( rObjectCID, xChartModel );
512 else if( OBJECTTYPE_DATA_SERIES == eObjectType )
514 aRet = lcl_getFullSeriesName( rObjectCID, xChartModel );
516 else if( OBJECTTYPE_DATA_POINT == eObjectType )
518 if( bVerbose )
520 OUString aNewLine(C2U("\n"));
522 aRet=String(SchResId(STR_TIP_DATAPOINT_INDEX));
523 aRet+=aNewLine;
524 aRet+=String(SchResId(STR_TIP_DATASERIES));
525 aRet+=aNewLine;
526 aRet+=String(SchResId(STR_TIP_DATAPOINT_VALUES));
528 else
529 aRet=String(SchResId(STR_TIP_DATAPOINT));
531 Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) );
532 Reference< XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID , xChartModel ), uno::UNO_QUERY );
533 if( xDiagram.is() && xSeries.is() )
535 sal_Int32 nPointIndex( ObjectIdentifier::getParticleID(rObjectCID).toInt32() );
537 //replace data point index
538 sal_Int32 nIndex = -1;
539 OUString aWildcard( C2U("%POINTNUMBER") );
540 nIndex = aRet.indexOf( aWildcard );
541 if( nIndex != -1 )
543 aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), OUString::valueOf(nPointIndex+1) );
546 //replace data series index
547 aWildcard = C2U("%SERIESNUMBER");
548 nIndex = aRet.indexOf( aWildcard );
549 if( nIndex != -1 )
551 ::std::vector< Reference< chart2::XDataSeries > > aSeriesVector(
552 DiagramHelper::getDataSeriesFromDiagram( xDiagram ) );
553 sal_Int32 nSeriesIndex = -1;
554 for( nSeriesIndex=aSeriesVector.size();nSeriesIndex--;)
556 if( aSeriesVector[nSeriesIndex] == xSeries )
558 break;
562 OUString aReplacement( OUString::valueOf(nSeriesIndex+1) );
563 aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), aReplacement );
566 //replace point values
567 aWildcard = C2U("%POINTVALUES");
568 nIndex = aRet.indexOf( aWildcard );
569 if( nIndex != -1 )
570 aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), lcl_getDataPointValueText(
571 xSeries,nPointIndex, DataSeriesHelper::getCoordinateSystemOfSeries(xSeries, xDiagram), xChartModel ) );
573 //replace series name
574 aWildcard = C2U("%SERIESNAME");
575 nIndex = aRet.indexOf( aWildcard );
576 if( nIndex != -1 )
577 aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), lcl_getDataSeriesName( rObjectCID, xChartModel ) );
581 else if( OBJECTTYPE_DIAGRAM == eObjectType )
583 //todo different names for different diagram types ???
584 //or different names for series of diferent charttypes
587 else if( OBJECTTYPE_DATA_CURVE == eObjectType )
589 if( bVerbose )
591 aRet = String( SchResId( STR_OBJECT_CURVE_WITH_PARAMETERS ));
592 Reference< chart2::XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID , xChartModel ));
593 Reference< chart2::XRegressionCurveContainer > xCurveCnt( xSeries, uno::UNO_QUERY );
594 if( xCurveCnt.is())
596 Reference< chart2::XRegressionCurve > xCurve( RegressionCurveHelper::getFirstCurveNotMeanValueLine( xCurveCnt ));
597 if( xCurve.is())
601 Reference< chart2::XRegressionCurveCalculator > xCalculator( xCurve->getCalculator(), uno::UNO_QUERY_THROW );
602 RegressionCurveHelper::initializeCurveCalculator( xCalculator, xSeries, xChartModel );
604 // replace formula
605 sal_Int32 nIndex = -1;
606 OUString aWildcard( C2U("%FORMULA") );
607 nIndex = aRet.indexOf( aWildcard );
608 if( nIndex != -1 )
609 aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), xCalculator->getRepresentation());
611 // replace r^2
612 aWildcard = C2U("%RSQUARED");
613 nIndex = aRet.indexOf( aWildcard );
614 if( nIndex != -1 )
616 sal_Unicode aDecimalSep( '.' );
617 //@todo: enable this code when a localized decimal
618 //separator is also available for the formula
619 // SvtSysLocale aSysLocale;
620 // OUString aSep( aSysLocale.GetLocaleData().getNumDecimalSep());
621 // if( aSep.getLength() == 1 )
622 // aDecimalSep = aSep.toChar();
623 double fR( xCalculator->getCorrelationCoefficient());
624 aRet = aRet.replaceAt(
625 nIndex, aWildcard.getLength(),
626 ::rtl::math::doubleToUString(
627 fR*fR, rtl_math_StringFormat_G, 4, aDecimalSep, true ));
630 catch( const uno::Exception & ex )
632 ASSERT_EXCEPTION( ex );
637 else
639 // non-verbose
640 aRet = ObjectNameProvider::getName( eObjectType, false );
643 else if( OBJECTTYPE_DATA_AVERAGE_LINE == eObjectType )
645 if( bVerbose )
647 aRet = String( SchResId( STR_OBJECT_AVERAGE_LINE_WITH_PARAMETERS ));
648 Reference< chart2::XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID , xChartModel ));
649 Reference< chart2::XRegressionCurveContainer > xCurveCnt( xSeries, uno::UNO_QUERY );
650 if( xCurveCnt.is())
652 Reference< chart2::XRegressionCurve > xCurve( RegressionCurveHelper::getMeanValueLine( xCurveCnt ));
653 if( xCurve.is())
657 Reference< chart2::XRegressionCurveCalculator > xCalculator( xCurve->getCalculator(), uno::UNO_QUERY_THROW );
658 RegressionCurveHelper::initializeCurveCalculator( xCalculator, xSeries, xChartModel );
660 sal_Unicode aDecimalSep( '.' );
661 // replace average value
662 // SvtSysLocale aSysLocale;
663 // OUString aSep( aSysLocale.GetLocaleData().getNumDecimalSep());
664 // if( aSep.getLength() == 1 )
665 // aDecimalSep = aSep.toChar();
667 sal_Int32 nIndex = -1;
668 OUString aWildcard( C2U("%AVERAGE_VALUE") );
669 nIndex = aRet.indexOf( aWildcard );
670 // as the curve is constant, the value at any x-value is ok
671 if( nIndex != -1 )
673 const double fMeanValue( xCalculator->getCurveValue( 0.0 ));
674 aRet = aRet.replaceAt(
675 nIndex, aWildcard.getLength(),
676 ::rtl::math::doubleToUString(
677 fMeanValue, rtl_math_StringFormat_G, 4, aDecimalSep, true ));
680 // replace standard deviation
681 aWildcard = C2U("%STD_DEVIATION");
682 nIndex = aRet.indexOf( aWildcard );
683 if( nIndex != -1 )
685 const double fStdDev( xCalculator->getCorrelationCoefficient());
686 aRet = aRet.replaceAt(
687 nIndex, aWildcard.getLength(),
688 ::rtl::math::doubleToUString(
689 fStdDev, rtl_math_StringFormat_G, 4, aDecimalSep, true ));
692 catch( const uno::Exception & ex )
694 ASSERT_EXCEPTION( ex );
699 else
701 // non-verbose
702 aRet = ObjectNameProvider::getName( eObjectType, false );
705 else
707 aRet = ObjectNameProvider::getName( eObjectType, false );
709 return aRet;
712 // static
713 rtl::OUString ObjectNameProvider::getSelectedObjectText( const rtl::OUString & rObjectCID, const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartDocument >& xChartDocument )
715 rtl::OUString aRet;
716 ObjectType eObjectType( ObjectIdentifier::getObjectType(rObjectCID) );
717 Reference< frame::XModel > xChartModel( xChartDocument, uno::UNO_QUERY );
719 if( OBJECTTYPE_DATA_POINT == eObjectType )
721 aRet = String( SchResId( STR_STATUS_DATAPOINT_MARKED ));
723 Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) );
724 Reference< XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID , xChartModel ), uno::UNO_QUERY );
725 if( xDiagram.is() && xSeries.is() )
727 sal_Int32 nPointIndex( ObjectIdentifier::getParticleID(rObjectCID).toInt32() );
729 // replace data point index
730 replaceParamterInString( aRet, C2U("%POINTNUMBER"), OUString::valueOf( nPointIndex + 1 ));
732 // replace data series index
734 ::std::vector< Reference< chart2::XDataSeries > > aSeriesVector(
735 DiagramHelper::getDataSeriesFromDiagram( xDiagram ) );
736 sal_Int32 nSeriesIndex = -1;
737 for( nSeriesIndex=aSeriesVector.size();nSeriesIndex--;)
739 if( aSeriesVector[nSeriesIndex] == xSeries )
740 break;
742 replaceParamterInString( aRet, C2U("%SERIESNUMBER"), OUString::valueOf( nSeriesIndex + 1 ) );
745 // replace point value
746 replaceParamterInString( aRet, C2U("%POINTVALUES"), lcl_getDataPointValueText(
747 xSeries, nPointIndex, DataSeriesHelper::getCoordinateSystemOfSeries(xSeries, xDiagram), xChartModel ) );
750 else
752 // use the verbose text including the formula for trend lines
753 const bool bVerbose( OBJECTTYPE_DATA_CURVE == eObjectType || OBJECTTYPE_DATA_AVERAGE_LINE == eObjectType );
754 const OUString aHelpText( getHelpText( rObjectCID, xChartModel, bVerbose ));
755 if( aHelpText.getLength())
757 aRet = String( SchResId( STR_STATUS_OBJECT_MARKED ));
758 replaceParamterInString( aRet, C2U("%OBJECTNAME"), aHelpText );
762 return aRet;
766 // static
767 rtl::OUString ObjectNameProvider::getNameForCID(
768 const rtl::OUString& rObjectCID,
769 const uno::Reference< chart2::XChartDocument >& xChartDocument )
771 ObjectType eType( ObjectIdentifier::getObjectType( rObjectCID ));
772 Reference< frame::XModel > xModel( xChartDocument, uno::UNO_QUERY );
774 switch( eType )
776 case OBJECTTYPE_AXIS:
777 return getAxisName( rObjectCID, xModel );
778 case OBJECTTYPE_TITLE:
779 return getTitleName( rObjectCID, xModel );
780 case OBJECTTYPE_GRID:
781 case OBJECTTYPE_SUBGRID:
782 return getGridName( rObjectCID, xModel );
783 case OBJECTTYPE_DATA_SERIES:
784 return lcl_getFullSeriesName( rObjectCID, xModel );
785 //case OBJECTTYPE_LEGEND_ENTRY:
786 case OBJECTTYPE_DATA_POINT:
787 case OBJECTTYPE_DATA_LABELS:
788 case OBJECTTYPE_DATA_LABEL:
789 case OBJECTTYPE_DATA_ERRORS:
790 case OBJECTTYPE_DATA_ERRORS_X:
791 case OBJECTTYPE_DATA_ERRORS_Y:
792 case OBJECTTYPE_DATA_ERRORS_Z:
793 case OBJECTTYPE_DATA_CURVE:
794 case OBJECTTYPE_DATA_AVERAGE_LINE:
795 case OBJECTTYPE_DATA_CURVE_EQUATION:
797 rtl::OUString aRet = lcl_getFullSeriesName( rObjectCID, xModel );
798 aRet += C2U(" ");
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 += C2U(" ");
804 aRet += OUString::valueOf(nPointIndex+1);
806 if( eType == OBJECTTYPE_DATA_LABEL )
808 aRet += C2U(" ");
809 aRet += getName( OBJECTTYPE_DATA_LABEL );
812 else
813 aRet += getName( eType );
814 return aRet;
816 default:
817 break;
820 return getName( eType );
823 //static
824 rtl::OUString ObjectNameProvider::getName_ObjectForSeries(
825 ObjectType eObjectType,
826 const rtl::OUString& rSeriesCID,
827 const uno::Reference< chart2::XChartDocument >& xChartDocument )
829 uno::Reference< frame::XModel> xChartModel( xChartDocument, uno::UNO_QUERY );
830 Reference< XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( rSeriesCID , xChartModel ), uno::UNO_QUERY );
831 if( xSeries.is() )
833 OUString aRet = String(SchResId(STR_OBJECT_FOR_SERIES));
834 replaceParamterInString( aRet, C2U("%OBJECTNAME"), getName( eObjectType, false /*bPlural*/ ) );
835 replaceParamterInString( aRet, C2U("%SERIESNAME"), lcl_getDataSeriesName( rSeriesCID, xChartModel ) );
836 return aRet;
838 else
839 return ObjectNameProvider::getName_ObjectForAllSeries( eObjectType );
842 //static
843 rtl::OUString ObjectNameProvider::getName_ObjectForAllSeries( ObjectType eObjectType )
845 OUString aRet = String(SchResId(STR_OBJECT_FOR_ALL_SERIES));
846 replaceParamterInString( aRet, C2U("%OBJECTNAME"), getName( eObjectType, true /*bPlural*/ ) );
847 return aRet;
850 //.............................................................................
851 } //namespace chart
852 //.............................................................................