Bump for 3.6-28
[LibreOffice.git] / chart2 / source / controller / dialogs / ObjectNameProvider.cxx
blob0f0ae829814fe1d8612fa8fd591a0e79ebfffaf0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include "ObjectNameProvider.hxx"
31 #include "ResId.hxx"
32 #include "Strings.hrc"
33 #include "macros.hxx"
34 #include "AxisHelper.hxx"
35 #include "ChartModelHelper.hxx"
36 #include "DiagramHelper.hxx"
37 #include "DataSeriesHelper.hxx"
38 #include "TitleHelper.hxx"
39 #include "AxisIndexDefines.hxx"
40 #include "ExplicitCategoriesProvider.hxx"
41 #include "CommonConverters.hxx"
42 #include "NumberFormatterWrapper.hxx"
43 #include "RegressionCurveHelper.hxx"
44 #include <rtl/math.hxx>
45 #include <tools/string.hxx>
47 #include <com/sun/star/chart2/XTitle.hpp>
48 #include <com/sun/star/chart2/XRegressionCurveContainer.hpp>
50 //.............................................................................
51 namespace chart
53 //.............................................................................
54 using namespace ::com::sun::star;
55 using namespace ::com::sun::star::chart2;
56 using ::com::sun::star::uno::Reference;
57 using ::com::sun::star::uno::Sequence;
58 using ::com::sun::star::uno::Any;
59 using rtl::OUString;
61 namespace
64 OUString lcl_getDataSeriesName( const rtl::OUString& rObjectCID, const Reference< frame::XModel >& xChartModel )
66 OUString aRet;
68 Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) );
69 Reference< XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID , xChartModel ), uno::UNO_QUERY );
70 if( xDiagram.is() && xSeries.is() )
72 Reference< XChartType > xChartType( DiagramHelper::getChartTypeOfSeries( xDiagram, xSeries ) );
73 if( xChartType.is() )
75 aRet = ::chart::DataSeriesHelper::getDataSeriesLabel(
76 xSeries, xChartType->getRoleOfSequenceForSeriesLabel() ) ;
80 return aRet;
83 OUString lcl_getFullSeriesName( const rtl::OUString& rObjectCID, const Reference< frame::XModel >& xChartModel )
85 OUString aRet = String(SchResId(STR_TIP_DATASERIES));
86 OUString aWildcard( C2U("%SERIESNAME") );
87 sal_Int32 nIndex = aRet.indexOf( aWildcard );
88 if( nIndex != -1 )
89 aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), lcl_getDataSeriesName( rObjectCID, xChartModel ) );
90 return aRet;
93 void lcl_addText( OUString& rOut, const OUString& rSeparator, const OUString& rNext )
95 if( !(rOut.isEmpty() || rNext.isEmpty()) )
96 rOut+=rSeparator;
97 if( !rNext.isEmpty() )
98 rOut+=rNext;
101 OUString lcl_getDataPointValueText( const Reference< XDataSeries >& xSeries, sal_Int32 nPointIndex,
102 const Reference< XCoordinateSystem >& xCooSys,
103 const Reference< frame::XModel >& xChartModel )
106 OUString aRet;
108 Reference<data::XDataSource> xDataSource(
109 uno::Reference<data::XDataSource>( xSeries, uno::UNO_QUERY ) );
110 if(!xDataSource.is())
111 return aRet;
113 Sequence< Reference< data::XLabeledDataSequence > > aDataSequences( xDataSource->getDataSequences() );
115 rtl::OUString aX, aY, aY_Min, aY_Max, aY_First, aY_Last, a_Size;
116 double fValue = 0;
118 uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( xChartModel, uno::UNO_QUERY );
119 NumberFormatterWrapper aNumberFormatterWrapper( xNumberFormatsSupplier );
120 sal_Int32 nLabelColor = 0;//dummy
121 bool bColorChanged;//dummy
123 for(sal_Int32 nN = aDataSequences.getLength();nN--;)
125 uno::Reference<data::XDataSequence> xDataSequence( aDataSequences[nN]->getValues());
126 if( !xDataSequence.is() )
127 continue;
128 Sequence< Any > aData( xDataSequence->getData() );
129 if( nPointIndex >= aData.getLength() )
130 continue;
131 uno::Reference<beans::XPropertySet> xProp(xDataSequence, uno::UNO_QUERY );
132 if( xProp.is())
136 uno::Any aARole = xProp->getPropertyValue( C2U( "Role" ) );
137 rtl::OUString aRole;
138 aARole >>= aRole;
140 if( aRole.equals(C2U("values-x")) )
142 aData[nPointIndex]>>= fValue;
143 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
144 aX = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
146 else if( aRole.equals(C2U("values-y")) )
148 aData[nPointIndex]>>= fValue;
149 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
150 aY = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
152 else if( aRole.equals(C2U("values-first")) )
154 aData[nPointIndex]>>= fValue;
155 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
156 aY_First = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
158 else if( aRole.equals(C2U("values-min")) )
160 aData[nPointIndex]>>= fValue;
161 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
162 aY_Min = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
164 else if( aRole.equals(C2U("values-max")) )
166 aData[nPointIndex]>>= fValue;
167 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
168 aY_Max = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
170 else if( aRole.equals(C2U("values-last")) )
172 aData[nPointIndex]>>= fValue;
173 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
174 aY_Last = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
176 else if( aRole.equals(C2U("values-size")) )
178 aData[nPointIndex]>>= fValue;
179 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
180 a_Size = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
183 catch( const uno::Exception& e )
185 ASSERT_EXCEPTION( e );
190 if( aX.isEmpty() )
192 aRet = ExplicitCategoriesProvider::getCategoryByIndex( xCooSys, xChartModel, nPointIndex );
194 else
196 aRet = aX;
199 OUString aSeparator(C2U(" "));
201 lcl_addText( aRet, aSeparator, aY );
202 lcl_addText( aRet, aSeparator, aY_First );
203 lcl_addText( aRet, aSeparator, aY_Min );
204 lcl_addText( aRet, aSeparator, aY_Max );
205 lcl_addText( aRet, aSeparator, aY_Last );
206 lcl_addText( aRet, aSeparator, a_Size );
208 return aRet;
211 } //end anonymous namespace
213 rtl::OUString ObjectNameProvider::getName( ObjectType eObjectType, bool bPlural )
215 rtl::OUString aRet;
216 switch( eObjectType )
218 case OBJECTTYPE_PAGE:
219 aRet=String(SchResId(STR_OBJECT_PAGE));
220 break;
221 case OBJECTTYPE_TITLE:
223 if(bPlural)
224 aRet=String(SchResId(STR_OBJECT_TITLES));
225 else
226 aRet=String(SchResId(STR_OBJECT_TITLE));
228 break;
229 case OBJECTTYPE_LEGEND:
230 aRet=String(SchResId(STR_OBJECT_LEGEND));
231 break;
232 case OBJECTTYPE_LEGEND_ENTRY:
233 aRet=String(SchResId(STR_OBJECT_LEGEND_SYMBOL));//@todo change string if we do differenciate symbol and legend entry in future
234 break;
235 case OBJECTTYPE_DIAGRAM:
236 aRet=String(SchResId(STR_OBJECT_DIAGRAM));
237 break;
238 case OBJECTTYPE_DIAGRAM_WALL:
239 aRet=String(SchResId(STR_OBJECT_DIAGRAM_WALL));
240 break;
241 case OBJECTTYPE_DIAGRAM_FLOOR:
242 aRet=String(SchResId(STR_OBJECT_DIAGRAM_FLOOR));
243 break;
244 case OBJECTTYPE_AXIS:
246 if(bPlural)
247 aRet=String(SchResId(STR_OBJECT_AXES));
248 else
249 aRet=String(SchResId(STR_OBJECT_AXIS));
251 break;
252 case OBJECTTYPE_AXIS_UNITLABEL:
253 aRet=String(SchResId(STR_OBJECT_LABEL));//@todo maybe a more concrete name
254 break;
255 case OBJECTTYPE_GRID:
256 case OBJECTTYPE_SUBGRID: //maybe todo: different names for subgrids
258 if(bPlural)
259 aRet=String(SchResId(STR_OBJECT_GRIDS));
260 else
261 aRet=String(SchResId(STR_OBJECT_GRID));
263 break;
264 case OBJECTTYPE_DATA_SERIES:
266 if(bPlural)
267 aRet=String(SchResId(STR_OBJECT_DATASERIES_PLURAL));
268 else
269 aRet=String(SchResId(STR_OBJECT_DATASERIES));
271 break;
272 case OBJECTTYPE_DATA_POINT:
274 if(bPlural)
275 aRet=String(SchResId(STR_OBJECT_DATAPOINTS));
276 else
277 aRet=String(SchResId(STR_OBJECT_DATAPOINT));
279 break;
280 case OBJECTTYPE_DATA_LABELS:
281 aRet=String(SchResId(STR_OBJECT_DATALABELS));
282 break;
283 case OBJECTTYPE_DATA_LABEL:
284 aRet=String(SchResId(STR_OBJECT_LABEL));
285 break;
286 case OBJECTTYPE_DATA_ERRORS_X:
287 aRet=String(SchResId(STR_OBJECT_ERROR_BARS_X));
288 break;
289 case OBJECTTYPE_DATA_ERRORS_Y:
290 aRet=String(SchResId(STR_OBJECT_ERROR_BARS_Y));
291 break;
292 case OBJECTTYPE_DATA_ERRORS_Z:
293 aRet=String(SchResId(STR_OBJECT_ERROR_BARS_Z));
294 break;
295 case OBJECTTYPE_DATA_AVERAGE_LINE:
296 aRet=String(SchResId(STR_OBJECT_AVERAGE_LINE));
297 break;
298 case OBJECTTYPE_DATA_CURVE:
300 if(bPlural)
301 aRet=String(SchResId(STR_OBJECT_CURVES));
302 else
303 aRet=String(SchResId(STR_OBJECT_CURVE));
305 break;
306 case OBJECTTYPE_DATA_STOCK_RANGE:
307 break;
308 case OBJECTTYPE_DATA_STOCK_LOSS:
309 aRet=String(SchResId(STR_OBJECT_STOCK_LOSS));
310 break;
311 case OBJECTTYPE_DATA_STOCK_GAIN:
312 aRet=String(SchResId(STR_OBJECT_STOCK_GAIN));
313 break;
314 case OBJECTTYPE_DATA_CURVE_EQUATION:
315 aRet=String(SchResId(STR_OBJECT_CURVE_EQUATION));
316 break;
317 default: //OBJECTTYPE_UNKNOWN
320 return aRet;
323 rtl::OUString ObjectNameProvider::getAxisName( const rtl::OUString& rObjectCID
324 , const uno::Reference< frame::XModel >& xChartModel )
326 rtl::OUString aRet;
330 Reference< XAxis > xAxis(
331 ObjectIdentifier::getObjectPropertySet( rObjectCID , xChartModel ), uno::UNO_QUERY );
333 sal_Int32 nCooSysIndex = 0;
334 sal_Int32 nDimensionIndex = 0;
335 sal_Int32 nAxisIndex = 0;
336 AxisHelper::getIndicesForAxis( xAxis, ChartModelHelper::findDiagram( xChartModel ), nCooSysIndex, nDimensionIndex, nAxisIndex );
338 switch(nDimensionIndex)
340 case 0://x-axis
341 if( nAxisIndex == 0 )
342 aRet=String(SchResId(STR_OBJECT_AXIS_X));
343 else
344 aRet=String(SchResId(STR_OBJECT_SECONDARY_X_AXIS));
345 break;
346 case 1://y-axis
347 if( nAxisIndex == 0 )
348 aRet=String(SchResId(STR_OBJECT_AXIS_Y));
349 else
350 aRet=String(SchResId(STR_OBJECT_SECONDARY_Y_AXIS));
351 break;
352 case 2://z-axis
353 aRet=String(SchResId(STR_OBJECT_AXIS_Z));
354 break;
355 default://axis
356 aRet=String(SchResId(STR_OBJECT_AXIS));
357 break;
360 return aRet;
363 OUString ObjectNameProvider::getTitleNameByType( TitleHelper::eTitleType eType )
365 OUString aRet;
367 switch(eType)
369 case TitleHelper::MAIN_TITLE:
370 aRet=String(SchResId(STR_OBJECT_TITLE_MAIN));
371 break;
372 case TitleHelper::SUB_TITLE:
373 aRet=String(SchResId(STR_OBJECT_TITLE_SUB));
374 break;
375 case TitleHelper::X_AXIS_TITLE:
376 aRet=String(SchResId(STR_OBJECT_TITLE_X_AXIS));
377 break;
378 case TitleHelper::Y_AXIS_TITLE:
379 aRet=String(SchResId(STR_OBJECT_TITLE_Y_AXIS));
380 break;
381 case TitleHelper::Z_AXIS_TITLE:
382 aRet=String(SchResId(STR_OBJECT_TITLE_Z_AXIS));
383 break;
384 case TitleHelper::SECONDARY_X_AXIS_TITLE:
385 aRet=String(SchResId(STR_OBJECT_TITLE_SECONDARY_X_AXIS));
386 break;
387 case TitleHelper::SECONDARY_Y_AXIS_TITLE:
388 aRet=String(SchResId(STR_OBJECT_TITLE_SECONDARY_Y_AXIS));
389 break;
390 default:
391 OSL_FAIL("unknown title type");
392 break;
395 if( aRet.isEmpty() )
396 aRet=String(SchResId(STR_OBJECT_TITLE));
398 return aRet;
401 OUString ObjectNameProvider::getTitleName( const OUString& rObjectCID
402 , const Reference< frame::XModel >& xChartModel )
404 OUString aRet;
406 Reference< XTitle > xTitle(
407 ObjectIdentifier::getObjectPropertySet( rObjectCID , xChartModel ), uno::UNO_QUERY );
408 if( xTitle.is() )
410 TitleHelper::eTitleType eType;
411 if( TitleHelper::getTitleType( eType, xTitle, xChartModel ) )
412 aRet = ObjectNameProvider::getTitleNameByType( eType );
414 if( aRet.isEmpty() )
415 aRet=String(SchResId(STR_OBJECT_TITLE));
417 return aRet;
420 rtl::OUString ObjectNameProvider::getGridName( const rtl::OUString& rObjectCID
421 , const uno::Reference< frame::XModel >& xChartModel )
423 rtl::OUString aRet;
426 sal_Int32 nCooSysIndex = -1;
427 sal_Int32 nDimensionIndex = -1;
428 sal_Int32 nAxisIndex = -1;
429 Reference< XAxis > xAxis( ObjectIdentifier::getAxisForCID( rObjectCID , xChartModel ) );
430 AxisHelper::getIndicesForAxis( xAxis, ChartModelHelper::findDiagram( xChartModel )
431 , nCooSysIndex , nDimensionIndex, nAxisIndex );
433 bool bMainGrid = (ObjectIdentifier::getObjectType( rObjectCID ) == OBJECTTYPE_GRID);
435 if( bMainGrid )
437 switch(nDimensionIndex)
439 case 0://x-axis
440 aRet=String(SchResId(STR_OBJECT_GRID_MAJOR_X));
441 break;
442 case 1://y-axis
443 aRet=String(SchResId(STR_OBJECT_GRID_MAJOR_Y));
444 break;
445 case 2://z-axis
446 aRet=String(SchResId(STR_OBJECT_GRID_MAJOR_Z));
447 break;
448 default://axis
449 aRet=String(SchResId(STR_OBJECT_GRID));
450 break;
453 else
455 switch(nDimensionIndex)
457 case 0://x-axis
458 aRet=String(SchResId(STR_OBJECT_GRID_MINOR_X));
459 break;
460 case 1://y-axis
461 aRet=String(SchResId(STR_OBJECT_GRID_MINOR_Y));
462 break;
463 case 2://z-axis
464 aRet=String(SchResId(STR_OBJECT_GRID_MINOR_Z));
465 break;
466 default://axis
467 aRet=String(SchResId(STR_OBJECT_GRID));
468 break;
471 return aRet;
474 rtl::OUString ObjectNameProvider::getHelpText( const rtl::OUString& rObjectCID, const Reference< chart2::XChartDocument >& xChartDocument, bool bVerbose )
476 return getHelpText( rObjectCID, Reference< frame::XModel >( xChartDocument, uno::UNO_QUERY ), bVerbose );
479 rtl::OUString ObjectNameProvider::getHelpText( const rtl::OUString& rObjectCID, const Reference< frame::XModel >& xChartModel, bool bVerbose )
481 rtl::OUString aRet;
482 ObjectType eObjectType( ObjectIdentifier::getObjectType(rObjectCID) );
483 if( OBJECTTYPE_AXIS == eObjectType )
485 aRet=ObjectNameProvider::getAxisName( rObjectCID, xChartModel );
487 else if( OBJECTTYPE_GRID == eObjectType
488 || OBJECTTYPE_SUBGRID == eObjectType )
490 aRet=ObjectNameProvider::getGridName( rObjectCID, xChartModel );
492 else if( OBJECTTYPE_TITLE == eObjectType )
494 aRet=ObjectNameProvider::getTitleName( rObjectCID, xChartModel );
496 else if( OBJECTTYPE_DATA_SERIES == eObjectType )
498 aRet = lcl_getFullSeriesName( rObjectCID, xChartModel );
500 else if( OBJECTTYPE_DATA_POINT == eObjectType )
502 if( bVerbose )
504 OUString aNewLine(C2U("\n"));
506 aRet=String(SchResId(STR_TIP_DATAPOINT_INDEX));
507 aRet+=aNewLine;
508 aRet+=String(SchResId(STR_TIP_DATASERIES));
509 aRet+=aNewLine;
510 aRet+=String(SchResId(STR_TIP_DATAPOINT_VALUES));
512 else
513 aRet=String(SchResId(STR_TIP_DATAPOINT));
515 Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) );
516 Reference< XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID , xChartModel ), uno::UNO_QUERY );
517 if( xDiagram.is() && xSeries.is() )
519 sal_Int32 nPointIndex( ObjectIdentifier::getParticleID(rObjectCID).toInt32() );
521 //replace data point index
522 sal_Int32 nIndex = -1;
523 OUString aWildcard( C2U("%POINTNUMBER") );
524 nIndex = aRet.indexOf( aWildcard );
525 if( nIndex != -1 )
527 aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), OUString::valueOf(nPointIndex+1) );
530 //replace data series index
531 aWildcard = C2U("%SERIESNUMBER");
532 nIndex = aRet.indexOf( aWildcard );
533 if( nIndex != -1 )
535 ::std::vector< Reference< chart2::XDataSeries > > aSeriesVector(
536 DiagramHelper::getDataSeriesFromDiagram( xDiagram ) );
537 sal_Int32 nSeriesIndex = -1;
538 for( nSeriesIndex=aSeriesVector.size();nSeriesIndex--;)
540 if( aSeriesVector[nSeriesIndex] == xSeries )
542 break;
546 OUString aReplacement( OUString::valueOf(nSeriesIndex+1) );
547 aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), aReplacement );
550 //replace point values
551 aWildcard = C2U("%POINTVALUES");
552 nIndex = aRet.indexOf( aWildcard );
553 if( nIndex != -1 )
554 aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), lcl_getDataPointValueText(
555 xSeries,nPointIndex, DataSeriesHelper::getCoordinateSystemOfSeries(xSeries, xDiagram), xChartModel ) );
557 //replace series name
558 aWildcard = C2U("%SERIESNAME");
559 nIndex = aRet.indexOf( aWildcard );
560 if( nIndex != -1 )
561 aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), lcl_getDataSeriesName( rObjectCID, xChartModel ) );
564 else if( OBJECTTYPE_DATA_CURVE == eObjectType )
566 if( bVerbose )
568 aRet = String( SchResId( STR_OBJECT_CURVE_WITH_PARAMETERS ));
569 Reference< chart2::XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID , xChartModel ));
570 Reference< chart2::XRegressionCurveContainer > xCurveCnt( xSeries, uno::UNO_QUERY );
571 if( xCurveCnt.is())
573 Reference< chart2::XRegressionCurve > xCurve( RegressionCurveHelper::getFirstCurveNotMeanValueLine( xCurveCnt ));
574 if( xCurve.is())
578 Reference< chart2::XRegressionCurveCalculator > xCalculator( xCurve->getCalculator(), uno::UNO_QUERY_THROW );
579 RegressionCurveHelper::initializeCurveCalculator( xCalculator, xSeries, xChartModel );
581 // replace formula
582 sal_Int32 nIndex = -1;
583 OUString aWildcard( C2U("%FORMULA") );
584 nIndex = aRet.indexOf( aWildcard );
585 if( nIndex != -1 )
586 aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), xCalculator->getRepresentation());
588 // replace r^2
589 aWildcard = C2U("%RSQUARED");
590 nIndex = aRet.indexOf( aWildcard );
591 if( nIndex != -1 )
593 sal_Unicode aDecimalSep( '.' );
594 double fR( xCalculator->getCorrelationCoefficient());
595 aRet = aRet.replaceAt(
596 nIndex, aWildcard.getLength(),
597 ::rtl::math::doubleToUString(
598 fR*fR, rtl_math_StringFormat_G, 4, aDecimalSep, true ));
601 catch( const uno::Exception & ex )
603 ASSERT_EXCEPTION( ex );
608 else
610 // non-verbose
611 aRet = ObjectNameProvider::getName( eObjectType, false );
614 else if( OBJECTTYPE_DATA_AVERAGE_LINE == eObjectType )
616 if( bVerbose )
618 aRet = String( SchResId( STR_OBJECT_AVERAGE_LINE_WITH_PARAMETERS ));
619 Reference< chart2::XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID , xChartModel ));
620 Reference< chart2::XRegressionCurveContainer > xCurveCnt( xSeries, uno::UNO_QUERY );
621 if( xCurveCnt.is())
623 Reference< chart2::XRegressionCurve > xCurve( RegressionCurveHelper::getMeanValueLine( xCurveCnt ));
624 if( xCurve.is())
628 Reference< chart2::XRegressionCurveCalculator > xCalculator( xCurve->getCalculator(), uno::UNO_QUERY_THROW );
629 RegressionCurveHelper::initializeCurveCalculator( xCalculator, xSeries, xChartModel );
631 sal_Unicode aDecimalSep( '.' );
633 sal_Int32 nIndex = -1;
634 OUString aWildcard( C2U("%AVERAGE_VALUE") );
635 nIndex = aRet.indexOf( aWildcard );
636 // as the curve is constant, the value at any x-value is ok
637 if( nIndex != -1 )
639 const double fMeanValue( xCalculator->getCurveValue( 0.0 ));
640 aRet = aRet.replaceAt(
641 nIndex, aWildcard.getLength(),
642 ::rtl::math::doubleToUString(
643 fMeanValue, rtl_math_StringFormat_G, 4, aDecimalSep, true ));
646 // replace standard deviation
647 aWildcard = C2U("%STD_DEVIATION");
648 nIndex = aRet.indexOf( aWildcard );
649 if( nIndex != -1 )
651 const double fStdDev( xCalculator->getCorrelationCoefficient());
652 aRet = aRet.replaceAt(
653 nIndex, aWildcard.getLength(),
654 ::rtl::math::doubleToUString(
655 fStdDev, rtl_math_StringFormat_G, 4, aDecimalSep, true ));
658 catch( const uno::Exception & ex )
660 ASSERT_EXCEPTION( ex );
665 else
667 // non-verbose
668 aRet = ObjectNameProvider::getName( eObjectType, false );
671 else
673 aRet = ObjectNameProvider::getName( eObjectType, false );
675 return aRet;
678 rtl::OUString ObjectNameProvider::getSelectedObjectText( const rtl::OUString & rObjectCID, const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartDocument >& xChartDocument )
680 rtl::OUString aRet;
681 ObjectType eObjectType( ObjectIdentifier::getObjectType(rObjectCID) );
682 Reference< frame::XModel > xChartModel( xChartDocument, uno::UNO_QUERY );
684 if( OBJECTTYPE_DATA_POINT == eObjectType )
686 aRet = String( SchResId( STR_STATUS_DATAPOINT_MARKED ));
688 Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) );
689 Reference< XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID , xChartModel ), uno::UNO_QUERY );
690 if( xDiagram.is() && xSeries.is() )
692 sal_Int32 nPointIndex( ObjectIdentifier::getParticleID(rObjectCID).toInt32() );
694 // replace data point index
695 replaceParamterInString( aRet, C2U("%POINTNUMBER"), OUString::valueOf( nPointIndex + 1 ));
697 // replace data series index
699 ::std::vector< Reference< chart2::XDataSeries > > aSeriesVector(
700 DiagramHelper::getDataSeriesFromDiagram( xDiagram ) );
701 sal_Int32 nSeriesIndex = -1;
702 for( nSeriesIndex=aSeriesVector.size();nSeriesIndex--;)
704 if( aSeriesVector[nSeriesIndex] == xSeries )
705 break;
707 replaceParamterInString( aRet, C2U("%SERIESNUMBER"), OUString::valueOf( nSeriesIndex + 1 ) );
710 // replace point value
711 replaceParamterInString( aRet, C2U("%POINTVALUES"), lcl_getDataPointValueText(
712 xSeries, nPointIndex, DataSeriesHelper::getCoordinateSystemOfSeries(xSeries, xDiagram), xChartModel ) );
715 else
717 // use the verbose text including the formula for trend lines
718 const bool bVerbose( OBJECTTYPE_DATA_CURVE == eObjectType || OBJECTTYPE_DATA_AVERAGE_LINE == eObjectType );
719 const OUString aHelpText( getHelpText( rObjectCID, xChartModel, bVerbose ));
720 if( !aHelpText.isEmpty())
722 aRet = String( SchResId( STR_STATUS_OBJECT_MARKED ));
723 replaceParamterInString( aRet, C2U("%OBJECTNAME"), aHelpText );
727 return aRet;
731 rtl::OUString ObjectNameProvider::getNameForCID(
732 const rtl::OUString& rObjectCID,
733 const uno::Reference< chart2::XChartDocument >& xChartDocument )
735 ObjectType eType( ObjectIdentifier::getObjectType( rObjectCID ));
736 Reference< frame::XModel > xModel( xChartDocument, uno::UNO_QUERY );
738 switch( eType )
740 case OBJECTTYPE_AXIS:
741 return getAxisName( rObjectCID, xModel );
742 case OBJECTTYPE_TITLE:
743 return getTitleName( rObjectCID, xModel );
744 case OBJECTTYPE_GRID:
745 case OBJECTTYPE_SUBGRID:
746 return getGridName( rObjectCID, xModel );
747 case OBJECTTYPE_DATA_SERIES:
748 return lcl_getFullSeriesName( rObjectCID, xModel );
749 case OBJECTTYPE_DATA_POINT:
750 case OBJECTTYPE_DATA_LABELS:
751 case OBJECTTYPE_DATA_LABEL:
752 case OBJECTTYPE_DATA_ERRORS_X:
753 case OBJECTTYPE_DATA_ERRORS_Y:
754 case OBJECTTYPE_DATA_ERRORS_Z:
755 case OBJECTTYPE_DATA_CURVE:
756 case OBJECTTYPE_DATA_AVERAGE_LINE:
757 case OBJECTTYPE_DATA_CURVE_EQUATION:
759 rtl::OUString aRet = lcl_getFullSeriesName( rObjectCID, xModel );
760 aRet += C2U(" ");
761 if( eType == OBJECTTYPE_DATA_POINT || eType == OBJECTTYPE_DATA_LABEL )
763 aRet += getName( OBJECTTYPE_DATA_POINT );
764 sal_Int32 nPointIndex = ObjectIdentifier::getIndexFromParticleOrCID( rObjectCID );
765 aRet += C2U(" ");
766 aRet += OUString::valueOf(nPointIndex+1);
768 if( eType == OBJECTTYPE_DATA_LABEL )
770 aRet += C2U(" ");
771 aRet += getName( OBJECTTYPE_DATA_LABEL );
774 else
775 aRet += getName( eType );
776 return aRet;
778 default:
779 break;
782 return getName( eType );
785 rtl::OUString ObjectNameProvider::getName_ObjectForSeries(
786 ObjectType eObjectType,
787 const rtl::OUString& rSeriesCID,
788 const uno::Reference< chart2::XChartDocument >& xChartDocument )
790 uno::Reference< frame::XModel> xChartModel( xChartDocument, uno::UNO_QUERY );
791 Reference< XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( rSeriesCID , xChartModel ), uno::UNO_QUERY );
792 if( xSeries.is() )
794 OUString aRet = String(SchResId(STR_OBJECT_FOR_SERIES));
795 replaceParamterInString( aRet, C2U("%OBJECTNAME"), getName( eObjectType, false /*bPlural*/ ) );
796 replaceParamterInString( aRet, C2U("%SERIESNAME"), lcl_getDataSeriesName( rSeriesCID, xChartModel ) );
797 return aRet;
799 else
800 return ObjectNameProvider::getName_ObjectForAllSeries( eObjectType );
803 rtl::OUString ObjectNameProvider::getName_ObjectForAllSeries( ObjectType eObjectType )
805 OUString aRet = String(SchResId(STR_OBJECT_FOR_ALL_SERIES));
806 replaceParamterInString( aRet, C2U("%OBJECTNAME"), getName( eObjectType, true /*bPlural*/ ) );
807 return aRet;
810 //.............................................................................
811 } //namespace chart
812 //.............................................................................
814 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */