fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / controller / dialogs / ObjectNameProvider.cxx
blob6f0e30738e297a06303cdefc804390eac1b083a0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "ObjectNameProvider.hxx"
21 #include "ResId.hxx"
22 #include "Strings.hrc"
23 #include "macros.hxx"
24 #include "AxisHelper.hxx"
25 #include "ChartModelHelper.hxx"
26 #include "DiagramHelper.hxx"
27 #include "DataSeriesHelper.hxx"
28 #include "TitleHelper.hxx"
29 #include "AxisIndexDefines.hxx"
30 #include "ExplicitCategoriesProvider.hxx"
31 #include "CommonConverters.hxx"
32 #include "NumberFormatterWrapper.hxx"
33 #include "RegressionCurveHelper.hxx"
34 #include <rtl/math.hxx>
35 #include <rtl/ustring.hxx>
37 #include <com/sun/star/chart2/XTitle.hpp>
38 #include <com/sun/star/chart2/XRegressionCurveContainer.hpp>
40 namespace chart
42 using namespace ::com::sun::star;
43 using namespace ::com::sun::star::chart2;
44 using ::com::sun::star::uno::Reference;
45 using ::com::sun::star::uno::Sequence;
46 using ::com::sun::star::uno::Any;
48 namespace
51 OUString lcl_getDataSeriesName( const OUString& rObjectCID, const Reference< frame::XModel >& xChartModel )
53 OUString aRet;
55 Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) );
56 Reference< XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID , xChartModel ), uno::UNO_QUERY );
57 if( xDiagram.is() && xSeries.is() )
59 Reference< XChartType > xChartType( DiagramHelper::getChartTypeOfSeries( xDiagram, xSeries ) );
60 if( xChartType.is() )
62 aRet = ::chart::DataSeriesHelper::getDataSeriesLabel(
63 xSeries, xChartType->getRoleOfSequenceForSeriesLabel() ) ;
67 return aRet;
70 OUString lcl_getFullSeriesName( const OUString& rObjectCID, const Reference< frame::XModel >& xChartModel )
72 OUString aRet(SCH_RESSTR(STR_TIP_DATASERIES));
73 OUString aWildcard( "%SERIESNAME" );
74 sal_Int32 nIndex = aRet.indexOf( aWildcard );
75 if( nIndex != -1 )
76 aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), lcl_getDataSeriesName( rObjectCID, xChartModel ) );
77 return aRet;
80 void lcl_addText( OUString& rOut, const OUString& rSeparator, const OUString& rNext )
82 if( !(rOut.isEmpty() || rNext.isEmpty()) )
83 rOut+=rSeparator;
84 if( !rNext.isEmpty() )
85 rOut+=rNext;
88 OUString lcl_getDataPointValueText( const Reference< XDataSeries >& xSeries, sal_Int32 nPointIndex,
89 const Reference< XCoordinateSystem >& xCooSys,
90 const Reference< frame::XModel >& xChartModel )
93 OUString aRet;
95 Reference<data::XDataSource> xDataSource(
96 uno::Reference<data::XDataSource>( xSeries, uno::UNO_QUERY ) );
97 if(!xDataSource.is())
98 return aRet;
100 Sequence< Reference< data::XLabeledDataSequence > > aDataSequences( xDataSource->getDataSequences() );
102 OUString aX, aY, aY_Min, aY_Max, aY_First, aY_Last, a_Size;
103 double fValue = 0;
105 uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( xChartModel, uno::UNO_QUERY );
106 NumberFormatterWrapper aNumberFormatterWrapper( xNumberFormatsSupplier );
107 sal_Int32 nLabelColor = 0;//dummy
108 bool bColorChanged;//dummy
110 for(sal_Int32 nN = aDataSequences.getLength();nN--;)
112 uno::Reference<data::XDataSequence> xDataSequence( aDataSequences[nN]->getValues());
113 if( !xDataSequence.is() )
114 continue;
115 Sequence< Any > aData( xDataSequence->getData() );
116 if( nPointIndex >= aData.getLength() )
117 continue;
118 uno::Reference<beans::XPropertySet> xProp(xDataSequence, uno::UNO_QUERY );
119 if( xProp.is())
123 uno::Any aARole = xProp->getPropertyValue( "Role" );
124 OUString aRole;
125 aARole >>= aRole;
127 if( aRole == "values-x" )
129 aData[nPointIndex]>>= fValue;
130 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
131 aX = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
133 else if( aRole == "values-y")
135 aData[nPointIndex]>>= fValue;
136 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
137 aY = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
139 else if( aRole == "values-first" )
141 aData[nPointIndex]>>= fValue;
142 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
143 aY_First = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
145 else if( aRole == "values-min" )
147 aData[nPointIndex]>>= fValue;
148 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
149 aY_Min = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
151 else if( aRole == "values-max" )
153 aData[nPointIndex]>>= fValue;
154 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
155 aY_Max = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
157 else if( aRole == "values-last" )
159 aData[nPointIndex]>>= fValue;
160 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
161 aY_Last = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
163 else if( aRole == "values-size" )
165 aData[nPointIndex]>>= fValue;
166 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
167 a_Size = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
170 catch( const uno::Exception& e )
172 ASSERT_EXCEPTION( e );
177 if( aX.isEmpty() )
179 ChartModel& rModel = dynamic_cast<ChartModel&>(*xChartModel.get());
180 aRet = ExplicitCategoriesProvider::getCategoryByIndex( xCooSys, rModel, nPointIndex );
182 else
184 aRet = aX;
187 OUString aSeparator( " " );
189 lcl_addText( aRet, aSeparator, aY );
190 lcl_addText( aRet, aSeparator, aY_First );
191 lcl_addText( aRet, aSeparator, aY_Min );
192 lcl_addText( aRet, aSeparator, aY_Max );
193 lcl_addText( aRet, aSeparator, aY_Last );
194 lcl_addText( aRet, aSeparator, a_Size );
196 return aRet;
199 } //end anonymous namespace
201 OUString ObjectNameProvider::getName( ObjectType eObjectType, bool bPlural )
203 OUString aRet;
204 switch( eObjectType )
206 case OBJECTTYPE_PAGE:
207 aRet=SCH_RESSTR(STR_OBJECT_PAGE);
208 break;
209 case OBJECTTYPE_TITLE:
211 if(bPlural)
212 aRet=SCH_RESSTR(STR_OBJECT_TITLES);
213 else
214 aRet=SCH_RESSTR(STR_OBJECT_TITLE);
216 break;
217 case OBJECTTYPE_LEGEND:
218 aRet=SCH_RESSTR(STR_OBJECT_LEGEND);
219 break;
220 case OBJECTTYPE_LEGEND_ENTRY:
221 aRet=SCH_RESSTR(STR_OBJECT_LEGEND_SYMBOL);//@todo change string if we do differenciate symbol and legend entry in future
222 break;
223 case OBJECTTYPE_DIAGRAM:
224 aRet=SCH_RESSTR(STR_OBJECT_DIAGRAM);
225 break;
226 case OBJECTTYPE_DIAGRAM_WALL:
227 aRet=SCH_RESSTR(STR_OBJECT_DIAGRAM_WALL);
228 break;
229 case OBJECTTYPE_DIAGRAM_FLOOR:
230 aRet=SCH_RESSTR(STR_OBJECT_DIAGRAM_FLOOR);
231 break;
232 case OBJECTTYPE_AXIS:
234 if(bPlural)
235 aRet=SCH_RESSTR(STR_OBJECT_AXES);
236 else
237 aRet=SCH_RESSTR(STR_OBJECT_AXIS);
239 break;
240 case OBJECTTYPE_AXIS_UNITLABEL:
241 aRet=SCH_RESSTR(STR_OBJECT_LABEL);//@todo maybe a more concrete name
242 break;
243 case OBJECTTYPE_GRID:
244 case OBJECTTYPE_SUBGRID: //maybe todo: different names for subgrids
246 if(bPlural)
247 aRet=SCH_RESSTR(STR_OBJECT_GRIDS);
248 else
249 aRet=SCH_RESSTR(STR_OBJECT_GRID);
251 break;
252 case OBJECTTYPE_DATA_SERIES:
254 if(bPlural)
255 aRet=SCH_RESSTR(STR_OBJECT_DATASERIES_PLURAL);
256 else
257 aRet=SCH_RESSTR(STR_OBJECT_DATASERIES);
259 break;
260 case OBJECTTYPE_DATA_POINT:
262 if(bPlural)
263 aRet=SCH_RESSTR(STR_OBJECT_DATAPOINTS);
264 else
265 aRet=SCH_RESSTR(STR_OBJECT_DATAPOINT);
267 break;
268 case OBJECTTYPE_DATA_LABELS:
269 aRet=SCH_RESSTR(STR_OBJECT_DATALABELS);
270 break;
271 case OBJECTTYPE_DATA_LABEL:
272 aRet=SCH_RESSTR(STR_OBJECT_LABEL);
273 break;
274 case OBJECTTYPE_DATA_ERRORS_X:
275 aRet=SCH_RESSTR(STR_OBJECT_ERROR_BARS_X);
276 break;
277 case OBJECTTYPE_DATA_ERRORS_Y:
278 aRet=SCH_RESSTR(STR_OBJECT_ERROR_BARS_Y);
279 break;
280 case OBJECTTYPE_DATA_ERRORS_Z:
281 aRet=SCH_RESSTR(STR_OBJECT_ERROR_BARS_Z);
282 break;
283 case OBJECTTYPE_DATA_AVERAGE_LINE:
284 aRet=SCH_RESSTR(STR_OBJECT_AVERAGE_LINE);
285 break;
286 case OBJECTTYPE_DATA_CURVE:
288 if(bPlural)
289 aRet=SCH_RESSTR(STR_OBJECT_CURVES);
290 else
291 aRet=SCH_RESSTR(STR_OBJECT_CURVE);
293 break;
294 case OBJECTTYPE_DATA_STOCK_RANGE:
295 break;
296 case OBJECTTYPE_DATA_STOCK_LOSS:
297 aRet=SCH_RESSTR(STR_OBJECT_STOCK_LOSS);
298 break;
299 case OBJECTTYPE_DATA_STOCK_GAIN:
300 aRet=SCH_RESSTR(STR_OBJECT_STOCK_GAIN);
301 break;
302 case OBJECTTYPE_DATA_CURVE_EQUATION:
303 aRet=SCH_RESSTR(STR_OBJECT_CURVE_EQUATION);
304 break;
305 default: //OBJECTTYPE_UNKNOWN
308 return aRet;
311 OUString ObjectNameProvider::getAxisName( const OUString& rObjectCID
312 , const uno::Reference< frame::XModel >& xChartModel )
314 OUString aRet;
316 Reference< XAxis > xAxis(
317 ObjectIdentifier::getObjectPropertySet( rObjectCID , xChartModel ), uno::UNO_QUERY );
319 sal_Int32 nCooSysIndex = 0;
320 sal_Int32 nDimensionIndex = 0;
321 sal_Int32 nAxisIndex = 0;
322 AxisHelper::getIndicesForAxis( xAxis, ChartModelHelper::findDiagram( xChartModel ), nCooSysIndex, nDimensionIndex, nAxisIndex );
324 switch(nDimensionIndex)
326 case 0://x-axis
327 if( nAxisIndex == 0 )
328 aRet=SCH_RESSTR(STR_OBJECT_AXIS_X);
329 else
330 aRet=SCH_RESSTR(STR_OBJECT_SECONDARY_X_AXIS);
331 break;
332 case 1://y-axis
333 if( nAxisIndex == 0 )
334 aRet=SCH_RESSTR(STR_OBJECT_AXIS_Y);
335 else
336 aRet=SCH_RESSTR(STR_OBJECT_SECONDARY_Y_AXIS);
337 break;
338 case 2://z-axis
339 aRet=SCH_RESSTR(STR_OBJECT_AXIS_Z);
340 break;
341 default://axis
342 aRet=SCH_RESSTR(STR_OBJECT_AXIS);
343 break;
346 return aRet;
349 OUString ObjectNameProvider::getTitleNameByType( TitleHelper::eTitleType eType )
351 OUString aRet;
353 switch(eType)
355 case TitleHelper::MAIN_TITLE:
356 aRet=SCH_RESSTR(STR_OBJECT_TITLE_MAIN);
357 break;
358 case TitleHelper::SUB_TITLE:
359 aRet=SCH_RESSTR(STR_OBJECT_TITLE_SUB);
360 break;
361 case TitleHelper::X_AXIS_TITLE:
362 aRet=SCH_RESSTR(STR_OBJECT_TITLE_X_AXIS);
363 break;
364 case TitleHelper::Y_AXIS_TITLE:
365 aRet=SCH_RESSTR(STR_OBJECT_TITLE_Y_AXIS);
366 break;
367 case TitleHelper::Z_AXIS_TITLE:
368 aRet=SCH_RESSTR(STR_OBJECT_TITLE_Z_AXIS);
369 break;
370 case TitleHelper::SECONDARY_X_AXIS_TITLE:
371 aRet=SCH_RESSTR(STR_OBJECT_TITLE_SECONDARY_X_AXIS);
372 break;
373 case TitleHelper::SECONDARY_Y_AXIS_TITLE:
374 aRet=SCH_RESSTR(STR_OBJECT_TITLE_SECONDARY_Y_AXIS);
375 break;
376 default:
377 OSL_FAIL("unknown title type");
378 break;
381 if( aRet.isEmpty() )
382 aRet=SCH_RESSTR(STR_OBJECT_TITLE);
384 return aRet;
387 OUString ObjectNameProvider::getTitleName( const OUString& rObjectCID
388 , const Reference< frame::XModel >& xChartModel )
390 OUString aRet;
392 Reference< XTitle > xTitle(
393 ObjectIdentifier::getObjectPropertySet( rObjectCID , xChartModel ), uno::UNO_QUERY );
394 if( xTitle.is() )
396 TitleHelper::eTitleType eType;
397 if( TitleHelper::getTitleType( eType, xTitle, xChartModel ) )
398 aRet = ObjectNameProvider::getTitleNameByType( eType );
400 if( aRet.isEmpty() )
401 aRet=SCH_RESSTR(STR_OBJECT_TITLE);
403 return aRet;
406 OUString ObjectNameProvider::getGridName( const OUString& rObjectCID
407 , const uno::Reference< frame::XModel >& xChartModel )
409 OUString aRet;
411 sal_Int32 nCooSysIndex = -1;
412 sal_Int32 nDimensionIndex = -1;
413 sal_Int32 nAxisIndex = -1;
414 Reference< XAxis > xAxis( ObjectIdentifier::getAxisForCID( rObjectCID , xChartModel ) );
415 AxisHelper::getIndicesForAxis( xAxis, ChartModelHelper::findDiagram( xChartModel )
416 , nCooSysIndex , nDimensionIndex, nAxisIndex );
418 bool bMainGrid = (ObjectIdentifier::getObjectType( rObjectCID ) == OBJECTTYPE_GRID);
420 if( bMainGrid )
422 switch(nDimensionIndex)
424 case 0://x-axis
425 aRet=SCH_RESSTR(STR_OBJECT_GRID_MAJOR_X);
426 break;
427 case 1://y-axis
428 aRet=SCH_RESSTR(STR_OBJECT_GRID_MAJOR_Y);
429 break;
430 case 2://z-axis
431 aRet=SCH_RESSTR(STR_OBJECT_GRID_MAJOR_Z);
432 break;
433 default://axis
434 aRet=SCH_RESSTR(STR_OBJECT_GRID);
435 break;
438 else
440 switch(nDimensionIndex)
442 case 0://x-axis
443 aRet=SCH_RESSTR(STR_OBJECT_GRID_MINOR_X);
444 break;
445 case 1://y-axis
446 aRet=SCH_RESSTR(STR_OBJECT_GRID_MINOR_Y);
447 break;
448 case 2://z-axis
449 aRet=SCH_RESSTR(STR_OBJECT_GRID_MINOR_Z);
450 break;
451 default://axis
452 aRet=SCH_RESSTR(STR_OBJECT_GRID);
453 break;
456 return aRet;
459 OUString ObjectNameProvider::getHelpText( const OUString& rObjectCID, const Reference< chart2::XChartDocument >& xChartDocument, bool bVerbose )
461 return getHelpText( rObjectCID, Reference< frame::XModel >( xChartDocument, uno::UNO_QUERY ), bVerbose );
464 OUString ObjectNameProvider::getHelpText( const OUString& rObjectCID, const Reference< frame::XModel >& xChartModel, bool bVerbose )
466 OUString aRet;
467 ObjectType eObjectType( ObjectIdentifier::getObjectType(rObjectCID) );
468 if( OBJECTTYPE_AXIS == eObjectType )
470 aRet=ObjectNameProvider::getAxisName( rObjectCID, xChartModel );
472 else if( OBJECTTYPE_GRID == eObjectType
473 || OBJECTTYPE_SUBGRID == eObjectType )
475 aRet=ObjectNameProvider::getGridName( rObjectCID, xChartModel );
477 else if( OBJECTTYPE_TITLE == eObjectType )
479 aRet=ObjectNameProvider::getTitleName( rObjectCID, xChartModel );
481 else if( OBJECTTYPE_DATA_SERIES == eObjectType )
483 aRet = lcl_getFullSeriesName( rObjectCID, xChartModel );
485 else if( OBJECTTYPE_DATA_POINT == eObjectType )
487 if( bVerbose )
489 OUString aNewLine( "\n" );
491 aRet=SCH_RESSTR(STR_TIP_DATAPOINT_INDEX);
492 aRet+=aNewLine;
493 aRet+=SCH_RESSTR(STR_TIP_DATASERIES);
494 aRet+=aNewLine;
495 aRet+=SCH_RESSTR(STR_TIP_DATAPOINT_VALUES);
497 else
498 aRet=SCH_RESSTR(STR_TIP_DATAPOINT);
500 Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) );
501 Reference< XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID , xChartModel ), uno::UNO_QUERY );
502 if( xDiagram.is() && xSeries.is() )
504 sal_Int32 nPointIndex( ObjectIdentifier::getParticleID(rObjectCID).toInt32() );
506 //replace data point index
507 OUString aWildcard( "%POINTNUMBER" );
508 sal_Int32 nIndex = aRet.indexOf( aWildcard );
509 if( nIndex != -1 )
511 aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), OUString::number(nPointIndex+1) );
514 //replace data series index
515 aWildcard = "%SERIESNUMBER";
516 nIndex = aRet.indexOf( aWildcard );
517 if( nIndex != -1 )
519 ::std::vector< Reference< chart2::XDataSeries > > aSeriesVector(
520 DiagramHelper::getDataSeriesFromDiagram( xDiagram ) );
521 sal_Int32 nSeriesIndex = -1;
522 for( nSeriesIndex=aSeriesVector.size();nSeriesIndex--;)
524 if( aSeriesVector[nSeriesIndex] == xSeries )
526 break;
530 OUString aReplacement( OUString::number(nSeriesIndex+1) );
531 aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), aReplacement );
534 //replace point values
535 aWildcard = "%POINTVALUES";
536 nIndex = aRet.indexOf( aWildcard );
537 if( nIndex != -1 )
538 aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), lcl_getDataPointValueText(
539 xSeries,nPointIndex, DataSeriesHelper::getCoordinateSystemOfSeries(xSeries, xDiagram), xChartModel ) );
541 //replace series name
542 aWildcard = "%SERIESNAME";
543 nIndex = aRet.indexOf( aWildcard );
544 if( nIndex != -1 )
545 aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), lcl_getDataSeriesName( rObjectCID, xChartModel ) );
548 else if( OBJECTTYPE_DATA_CURVE == eObjectType )
550 if( bVerbose )
552 aRet = SCH_RESSTR( STR_OBJECT_CURVE_WITH_PARAMETERS );
553 Reference< chart2::XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID , xChartModel ));
554 Reference< chart2::XRegressionCurveContainer > xCurveCnt( xSeries, uno::UNO_QUERY );
556 if( xCurveCnt.is())
558 sal_Int32 nCurveIndex = ObjectIdentifier::getIndexFromParticleOrCID( rObjectCID );
559 Reference< chart2::XRegressionCurve > xCurve( RegressionCurveHelper::getRegressionCurveAtIndex(xCurveCnt, nCurveIndex) );
560 if( xCurve.is())
564 Reference< chart2::XRegressionCurveCalculator > xCalculator( xCurve->getCalculator(), uno::UNO_QUERY_THROW );
565 sal_Int32 aDegree = 2;
566 sal_Int32 aPeriod = 2;
567 bool aForceIntercept = false;
568 double aInterceptValue = 0.0;
569 uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
570 if ( xProperties.is())
572 xProperties->getPropertyValue( "PolynomialDegree") >>= aDegree;
573 xProperties->getPropertyValue( "MovingAveragePeriod") >>= aPeriod;
574 xProperties->getPropertyValue( "ForceIntercept") >>= aForceIntercept;
575 if (aForceIntercept)
576 xProperties->getPropertyValue( "InterceptValue") >>= aInterceptValue;
578 xCalculator->setRegressionProperties(aDegree, aForceIntercept, aInterceptValue, 2);
579 RegressionCurveHelper::initializeCurveCalculator( xCalculator, xSeries, xChartModel );
581 // change text for Moving Average
582 OUString aWildcard( "%PERIOD" );
583 sal_Int32 nIndex = xCalculator->getRepresentation().indexOf( aWildcard );
584 if( nIndex != -1 )
585 { // replace period
586 aRet = xCalculator->getRepresentation();
587 aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), OUString::number(aPeriod) );
590 // replace formula
591 aWildcard = "%FORMULA";
592 nIndex = aRet.indexOf( aWildcard );
593 if( nIndex != -1 )
594 aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), xCalculator->getRepresentation());
596 // replace r^2
597 aWildcard = "%RSQUARED";
598 nIndex = aRet.indexOf( aWildcard );
599 if( nIndex != -1 )
601 sal_Unicode aDecimalSep( '.' );
602 double fR( xCalculator->getCorrelationCoefficient());
603 aRet = aRet.replaceAt(
604 nIndex, aWildcard.getLength(),
605 ::rtl::math::doubleToUString(
606 fR*fR, rtl_math_StringFormat_G, 4, aDecimalSep, true ));
609 catch( const uno::Exception & ex )
611 ASSERT_EXCEPTION( ex );
616 else
618 Reference< chart2::XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID(rObjectCID , xChartModel));
619 Reference< chart2::XRegressionCurveContainer > xCurveCnt( xSeries, uno::UNO_QUERY );
620 aRet += getName(eObjectType, false);
622 if( xCurveCnt.is())
624 sal_Int32 nCurveIndex = ObjectIdentifier::getIndexFromParticleOrCID( rObjectCID );
625 Reference< chart2::XRegressionCurve > xCurve( RegressionCurveHelper::getRegressionCurveAtIndex(xCurveCnt, nCurveIndex) );
626 if( xCurve.is())
628 aRet += " (";
629 aRet += RegressionCurveHelper::getRegressionCurveName(xCurve);
630 aRet += " )";
635 else if( OBJECTTYPE_DATA_AVERAGE_LINE == eObjectType )
637 if( bVerbose )
639 aRet = SCH_RESSTR(STR_OBJECT_AVERAGE_LINE_WITH_PARAMETERS);
640 Reference< chart2::XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID , xChartModel ));
641 Reference< chart2::XRegressionCurveContainer > xCurveCnt( xSeries, uno::UNO_QUERY );
642 if( xCurveCnt.is())
644 Reference< chart2::XRegressionCurve > xCurve( RegressionCurveHelper::getMeanValueLine( xCurveCnt ));
645 if( xCurve.is())
649 Reference< chart2::XRegressionCurveCalculator > xCalculator( xCurve->getCalculator(), uno::UNO_QUERY_THROW );
650 RegressionCurveHelper::initializeCurveCalculator( xCalculator, xSeries, xChartModel );
652 sal_Unicode aDecimalSep( '.' );
654 OUString aWildcard( "%AVERAGE_VALUE" );
655 sal_Int32 nIndex = aRet.indexOf( aWildcard );
656 // as the curve is constant, the value at any x-value is ok
657 if( nIndex != -1 )
659 const double fMeanValue( xCalculator->getCurveValue( 0.0 ));
660 aRet = aRet.replaceAt(
661 nIndex, aWildcard.getLength(),
662 ::rtl::math::doubleToUString(
663 fMeanValue, rtl_math_StringFormat_G, 4, aDecimalSep, true ));
666 // replace standard deviation
667 aWildcard = "%STD_DEVIATION";
668 nIndex = aRet.indexOf( aWildcard );
669 if( nIndex != -1 )
671 const double fStdDev( xCalculator->getCorrelationCoefficient());
672 aRet = aRet.replaceAt(
673 nIndex, aWildcard.getLength(),
674 ::rtl::math::doubleToUString(
675 fStdDev, rtl_math_StringFormat_G, 4, aDecimalSep, true ));
678 catch( const uno::Exception & ex )
680 ASSERT_EXCEPTION( ex );
685 else
687 // non-verbose
688 aRet = ObjectNameProvider::getName( eObjectType, false );
691 else
693 aRet = ObjectNameProvider::getName( eObjectType, false );
695 return aRet;
698 OUString ObjectNameProvider::getSelectedObjectText( const OUString & rObjectCID, const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartDocument >& xChartDocument )
700 OUString aRet;
701 ObjectType eObjectType( ObjectIdentifier::getObjectType(rObjectCID) );
702 Reference< frame::XModel > xChartModel( xChartDocument, uno::UNO_QUERY );
704 if( OBJECTTYPE_DATA_POINT == eObjectType )
706 aRet = SCH_RESSTR( STR_STATUS_DATAPOINT_MARKED );
708 Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) );
709 Reference< XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID , xChartModel ), uno::UNO_QUERY );
710 if( xDiagram.is() && xSeries.is() )
712 sal_Int32 nPointIndex( ObjectIdentifier::getParticleID(rObjectCID).toInt32() );
714 // replace data point index
715 replaceParamterInString( aRet, "%POINTNUMBER", OUString::number( nPointIndex + 1 ));
717 // replace data series index
719 ::std::vector< Reference< chart2::XDataSeries > > aSeriesVector(
720 DiagramHelper::getDataSeriesFromDiagram( xDiagram ) );
721 sal_Int32 nSeriesIndex = -1;
722 for( nSeriesIndex=aSeriesVector.size();nSeriesIndex--;)
724 if( aSeriesVector[nSeriesIndex] == xSeries )
725 break;
727 replaceParamterInString( aRet, "%SERIESNUMBER", OUString::number( nSeriesIndex + 1 ) );
730 // replace point value
731 replaceParamterInString( aRet, "%POINTVALUES", lcl_getDataPointValueText(
732 xSeries, nPointIndex, DataSeriesHelper::getCoordinateSystemOfSeries(xSeries, xDiagram), xChartModel ) );
735 else
737 // use the verbose text including the formula for trend lines
738 const bool bVerbose( OBJECTTYPE_DATA_CURVE == eObjectType || OBJECTTYPE_DATA_AVERAGE_LINE == eObjectType );
739 const OUString aHelpText( getHelpText( rObjectCID, xChartModel, bVerbose ));
740 if( !aHelpText.isEmpty())
742 aRet = SCH_RESSTR( STR_STATUS_OBJECT_MARKED );
743 replaceParamterInString( aRet, "%OBJECTNAME", aHelpText );
747 return aRet;
750 OUString ObjectNameProvider::getNameForCID(
751 const OUString& rObjectCID,
752 const uno::Reference< chart2::XChartDocument >& xChartDocument )
754 ObjectType eType( ObjectIdentifier::getObjectType( rObjectCID ));
755 Reference< frame::XModel > xModel( xChartDocument, uno::UNO_QUERY );
757 switch( eType )
759 case OBJECTTYPE_AXIS:
760 return getAxisName( rObjectCID, xModel );
761 case OBJECTTYPE_TITLE:
762 return getTitleName( rObjectCID, xModel );
763 case OBJECTTYPE_GRID:
764 case OBJECTTYPE_SUBGRID:
765 return getGridName( rObjectCID, xModel );
766 case OBJECTTYPE_DATA_SERIES:
767 return lcl_getFullSeriesName( rObjectCID, xModel );
768 case OBJECTTYPE_DATA_POINT:
769 case OBJECTTYPE_DATA_LABELS:
770 case OBJECTTYPE_DATA_LABEL:
771 case OBJECTTYPE_DATA_ERRORS_X:
772 case OBJECTTYPE_DATA_ERRORS_Y:
773 case OBJECTTYPE_DATA_ERRORS_Z:
774 case OBJECTTYPE_DATA_AVERAGE_LINE:
775 case OBJECTTYPE_DATA_CURVE:
776 case OBJECTTYPE_DATA_CURVE_EQUATION:
778 OUString aRet = lcl_getFullSeriesName( rObjectCID, xModel );
779 aRet += " ";
780 if( eType == OBJECTTYPE_DATA_POINT || eType == OBJECTTYPE_DATA_LABEL )
782 aRet += getName( OBJECTTYPE_DATA_POINT );
783 sal_Int32 nPointIndex = ObjectIdentifier::getIndexFromParticleOrCID( rObjectCID );
784 aRet += " ";
785 aRet += OUString::number(nPointIndex+1);
787 if( eType == OBJECTTYPE_DATA_LABEL )
789 aRet += " ";
790 aRet += getName( OBJECTTYPE_DATA_LABEL );
793 else if (eType == OBJECTTYPE_DATA_CURVE || eType == OBJECTTYPE_DATA_CURVE_EQUATION)
795 Reference< chart2::XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID , xModel ));
796 Reference< chart2::XRegressionCurveContainer > xCurveCnt( xSeries, uno::UNO_QUERY );
798 aRet += " ";
799 aRet += getName(eType);
801 if( xCurveCnt.is())
803 sal_Int32 nCurveIndex = ObjectIdentifier::getIndexFromParticleOrCID( rObjectCID );
804 Reference< chart2::XRegressionCurve > xCurve( RegressionCurveHelper::getRegressionCurveAtIndex(xCurveCnt, nCurveIndex) );
805 if( xCurve.is())
807 aRet += " (";
808 aRet += RegressionCurveHelper::getRegressionCurveName(xCurve);
809 aRet += ")";
813 else
815 aRet += getName( eType );
817 return aRet;
819 default:
820 break;
823 return getName( eType );
826 OUString ObjectNameProvider::getName_ObjectForSeries(
827 ObjectType eObjectType,
828 const OUString& rSeriesCID,
829 const uno::Reference< chart2::XChartDocument >& xChartDocument )
831 uno::Reference< frame::XModel> xChartModel( xChartDocument, uno::UNO_QUERY );
832 Reference< XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( rSeriesCID , xChartModel ), uno::UNO_QUERY );
833 if( xSeries.is() )
835 OUString aRet = SCH_RESSTR(STR_OBJECT_FOR_SERIES);
836 replaceParamterInString( aRet, "%OBJECTNAME", getName( eObjectType, false /*bPlural*/ ) );
837 replaceParamterInString( aRet, "%SERIESNAME", lcl_getDataSeriesName( rSeriesCID, xChartModel ) );
838 return aRet;
840 else
841 return ObjectNameProvider::getName_ObjectForAllSeries( eObjectType );
844 OUString ObjectNameProvider::getName_ObjectForAllSeries( ObjectType eObjectType )
846 OUString aRet = SCH_RESSTR(STR_OBJECT_FOR_ALL_SERIES);
847 replaceParamterInString( aRet, "%OBJECTNAME", getName( eObjectType, true /*bPlural*/ ) );
848 return aRet;
851 } //namespace chart
853 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */