Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / chart2 / source / controller / dialogs / ObjectNameProvider.cxx
blob4edd9c4c2c13e58cd497673c3c5c5d549671a8a3
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 <AxisHelper.hxx>
24 #include <ChartModel.hxx>
25 #include <ChartModelHelper.hxx>
26 #include <DiagramHelper.hxx>
27 #include <DataSeriesHelper.hxx>
28 #include <TitleHelper.hxx>
29 #include <ExplicitCategoriesProvider.hxx>
30 #include <CommonConverters.hxx>
31 #include <NumberFormatterWrapper.hxx>
32 #include <RegressionCurveHelper.hxx>
33 #include <rtl/math.hxx>
34 #include <rtl/ustring.hxx>
35 #include <sal/log.hxx>
36 #include <vcl/settings.hxx>
37 #include <vcl/svapp.hxx>
38 #include <unotools/localedatawrapper.hxx>
40 #include <com/sun/star/chart2/XTitle.hpp>
41 #include <com/sun/star/chart2/XRegressionCurveContainer.hpp>
42 #include <tools/diagnose_ex.h>
44 namespace chart
46 using namespace ::com::sun::star;
47 using namespace ::com::sun::star::chart2;
48 using ::com::sun::star::uno::Reference;
49 using ::com::sun::star::uno::Sequence;
50 using ::com::sun::star::uno::Any;
52 namespace
55 OUString lcl_getDataSeriesName( const OUString& rObjectCID, const Reference< frame::XModel >& xChartModel )
57 OUString aRet;
59 Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) );
60 Reference< XDataSeries > xSeries = ObjectIdentifier::getDataSeriesForCID( rObjectCID , xChartModel );
61 if( xDiagram.is() && xSeries.is() )
63 Reference< XChartType > xChartType( DiagramHelper::getChartTypeOfSeries( xDiagram, xSeries ) );
64 if( xChartType.is() )
66 aRet = ::chart::DataSeriesHelper::getDataSeriesLabel(
67 xSeries, xChartType->getRoleOfSequenceForSeriesLabel() ) ;
71 return aRet;
74 OUString lcl_getFullSeriesName( const OUString& rObjectCID, const Reference< frame::XModel >& xChartModel )
76 OUString aRet(SchResId(STR_TIP_DATASERIES));
77 OUString aWildcard( "%SERIESNAME" );
78 sal_Int32 nIndex = aRet.indexOf( aWildcard );
79 if( nIndex != -1 )
80 aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), lcl_getDataSeriesName( rObjectCID, xChartModel ) );
81 return aRet;
84 void lcl_addText( OUString& rOut, const OUString& rSeparator, const OUString& rNext )
86 if( !(rOut.isEmpty() || rNext.isEmpty()) )
87 rOut+=rSeparator;
88 if( !rNext.isEmpty() )
89 rOut+=rNext;
92 OUString lcl_getDataPointValueText( const Reference< XDataSeries >& xSeries, sal_Int32 nPointIndex,
93 const Reference< XCoordinateSystem >& xCooSys,
94 const Reference< frame::XModel >& xChartModel )
97 OUString aRet;
99 Reference<data::XDataSource> xDataSource(
100 uno::Reference<data::XDataSource>( xSeries, uno::UNO_QUERY ) );
101 if(!xDataSource.is())
102 return aRet;
104 Sequence< Reference< data::XLabeledDataSequence > > aDataSequences( xDataSource->getDataSequences() );
106 OUString aX, aY, aY_Min, aY_Max, aY_First, aY_Last, a_Size;
107 double fValue = 0;
109 uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( xChartModel, uno::UNO_QUERY );
110 NumberFormatterWrapper aNumberFormatterWrapper( xNumberFormatsSupplier );
111 Color nLabelColor;//dummy
112 bool bColorChanged;//dummy
114 for(sal_Int32 nN = aDataSequences.getLength();nN--;)
116 uno::Reference<data::XDataSequence> xDataSequence( aDataSequences[nN]->getValues());
117 if( !xDataSequence.is() )
118 continue;
119 Sequence< Any > aData( xDataSequence->getData() );
120 if( nPointIndex >= aData.getLength() )
121 continue;
122 uno::Reference<beans::XPropertySet> xProp(xDataSequence, uno::UNO_QUERY );
123 if( xProp.is())
127 uno::Any aARole = xProp->getPropertyValue( "Role" );
128 OUString aRole;
129 aARole >>= aRole;
131 if( aRole == "values-x" )
133 aData[nPointIndex]>>= fValue;
134 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
135 aX = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
137 else if( aRole == "values-y")
139 aData[nPointIndex]>>= fValue;
140 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
141 aY = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
143 else if( aRole == "values-first" )
145 aData[nPointIndex]>>= fValue;
146 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
147 aY_First = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
149 else if( aRole == "values-min" )
151 aData[nPointIndex]>>= fValue;
152 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
153 aY_Min = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
155 else if( aRole == "values-max" )
157 aData[nPointIndex]>>= fValue;
158 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
159 aY_Max = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
161 else if( aRole == "values-last" )
163 aData[nPointIndex]>>= fValue;
164 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
165 aY_Last = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
167 else if( aRole == "values-size" )
169 aData[nPointIndex]>>= fValue;
170 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
171 a_Size = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
174 catch( const uno::Exception& )
176 TOOLS_WARN_EXCEPTION("chart2", "" );
181 if( aX.isEmpty() )
183 ChartModel& rModel = dynamic_cast<ChartModel&>(*xChartModel);
184 aRet = ExplicitCategoriesProvider::getCategoryByIndex( xCooSys, rModel, nPointIndex );
186 else
188 aRet = aX;
191 OUString aSeparator( " " );
193 lcl_addText( aRet, aSeparator, aY );
194 lcl_addText( aRet, aSeparator, aY_First );
195 lcl_addText( aRet, aSeparator, aY_Min );
196 lcl_addText( aRet, aSeparator, aY_Max );
197 lcl_addText( aRet, aSeparator, aY_Last );
198 lcl_addText( aRet, aSeparator, a_Size );
200 return aRet;
203 } //end anonymous namespace
205 OUString ObjectNameProvider::getName( ObjectType eObjectType, bool bPlural )
207 OUString aRet;
208 switch( eObjectType )
210 case OBJECTTYPE_PAGE:
211 aRet=SchResId(STR_OBJECT_PAGE);
212 break;
213 case OBJECTTYPE_TITLE:
215 if(bPlural)
216 aRet=SchResId(STR_OBJECT_TITLES);
217 else
218 aRet=SchResId(STR_OBJECT_TITLE);
220 break;
221 case OBJECTTYPE_LEGEND:
222 aRet=SchResId(STR_OBJECT_LEGEND);
223 break;
224 case OBJECTTYPE_LEGEND_ENTRY:
225 aRet=SchResId(STR_OBJECT_LEGEND_SYMBOL);//@todo change string if we do differentiate symbol and legend entry in future
226 break;
227 case OBJECTTYPE_DIAGRAM:
228 aRet=SchResId(STR_OBJECT_DIAGRAM);
229 break;
230 case OBJECTTYPE_DIAGRAM_WALL:
231 aRet=SchResId(STR_OBJECT_DIAGRAM_WALL);
232 break;
233 case OBJECTTYPE_DIAGRAM_FLOOR:
234 aRet=SchResId(STR_OBJECT_DIAGRAM_FLOOR);
235 break;
236 case OBJECTTYPE_AXIS:
238 if(bPlural)
239 aRet=SchResId(STR_OBJECT_AXES);
240 else
241 aRet=SchResId(STR_OBJECT_AXIS);
243 break;
244 case OBJECTTYPE_AXIS_UNITLABEL:
245 aRet=SchResId(STR_OBJECT_LABEL);//@todo maybe a more concrete name
246 break;
247 case OBJECTTYPE_GRID:
248 case OBJECTTYPE_SUBGRID: //maybe todo: different names for subgrids
250 if(bPlural)
251 aRet=SchResId(STR_OBJECT_GRIDS);
252 else
253 aRet=SchResId(STR_OBJECT_GRID);
255 break;
256 case OBJECTTYPE_DATA_SERIES:
258 if(bPlural)
259 aRet=SchResId(STR_OBJECT_DATASERIES_PLURAL);
260 else
261 aRet=SchResId(STR_OBJECT_DATASERIES);
263 break;
264 case OBJECTTYPE_DATA_POINT:
266 if(bPlural)
267 aRet=SchResId(STR_OBJECT_DATAPOINTS);
268 else
269 aRet=SchResId(STR_OBJECT_DATAPOINT);
271 break;
272 case OBJECTTYPE_DATA_LABELS:
273 aRet=SchResId(STR_OBJECT_DATALABELS);
274 break;
275 case OBJECTTYPE_DATA_LABEL:
276 aRet=SchResId(STR_OBJECT_LABEL);
277 break;
278 case OBJECTTYPE_DATA_ERRORS_X:
279 aRet=SchResId(STR_OBJECT_ERROR_BARS_X);
280 break;
281 case OBJECTTYPE_DATA_ERRORS_Y:
282 aRet=SchResId(STR_OBJECT_ERROR_BARS_Y);
283 break;
284 case OBJECTTYPE_DATA_ERRORS_Z:
285 aRet=SchResId(STR_OBJECT_ERROR_BARS_Z);
286 break;
287 case OBJECTTYPE_DATA_AVERAGE_LINE:
288 aRet=SchResId(STR_OBJECT_AVERAGE_LINE);
289 break;
290 case OBJECTTYPE_DATA_CURVE:
292 if(bPlural)
293 aRet=SchResId(STR_OBJECT_CURVES);
294 else
295 aRet=SchResId(STR_OBJECT_CURVE);
297 break;
298 case OBJECTTYPE_DATA_STOCK_RANGE:
299 break;
300 case OBJECTTYPE_DATA_STOCK_LOSS:
301 aRet=SchResId(STR_OBJECT_STOCK_LOSS);
302 break;
303 case OBJECTTYPE_DATA_STOCK_GAIN:
304 aRet=SchResId(STR_OBJECT_STOCK_GAIN);
305 break;
306 case OBJECTTYPE_DATA_CURVE_EQUATION:
307 aRet=SchResId(STR_OBJECT_CURVE_EQUATION);
308 break;
309 default: //OBJECTTYPE_UNKNOWN
312 return aRet;
315 OUString ObjectNameProvider::getAxisName( const OUString& rObjectCID
316 , const uno::Reference< frame::XModel >& xChartModel )
318 OUString aRet;
320 Reference< XAxis > xAxis(
321 ObjectIdentifier::getObjectPropertySet( rObjectCID , xChartModel ), uno::UNO_QUERY );
323 sal_Int32 nCooSysIndex = 0;
324 sal_Int32 nDimensionIndex = 0;
325 sal_Int32 nAxisIndex = 0;
326 AxisHelper::getIndicesForAxis( xAxis, ChartModelHelper::findDiagram( xChartModel ), nCooSysIndex, nDimensionIndex, nAxisIndex );
328 switch(nDimensionIndex)
330 case 0://x-axis
331 if( nAxisIndex == 0 )
332 aRet=SchResId(STR_OBJECT_AXIS_X);
333 else
334 aRet=SchResId(STR_OBJECT_SECONDARY_X_AXIS);
335 break;
336 case 1://y-axis
337 if( nAxisIndex == 0 )
338 aRet=SchResId(STR_OBJECT_AXIS_Y);
339 else
340 aRet=SchResId(STR_OBJECT_SECONDARY_Y_AXIS);
341 break;
342 case 2://z-axis
343 aRet=SchResId(STR_OBJECT_AXIS_Z);
344 break;
345 default://axis
346 aRet=SchResId(STR_OBJECT_AXIS);
347 break;
350 return aRet;
353 OUString ObjectNameProvider::getTitleNameByType( TitleHelper::eTitleType eType )
355 OUString aRet;
357 switch(eType)
359 case TitleHelper::MAIN_TITLE:
360 aRet=SchResId(STR_OBJECT_TITLE_MAIN);
361 break;
362 case TitleHelper::SUB_TITLE:
363 aRet=SchResId(STR_OBJECT_TITLE_SUB);
364 break;
365 case TitleHelper::X_AXIS_TITLE:
366 aRet=SchResId(STR_OBJECT_TITLE_X_AXIS);
367 break;
368 case TitleHelper::Y_AXIS_TITLE:
369 aRet=SchResId(STR_OBJECT_TITLE_Y_AXIS);
370 break;
371 case TitleHelper::Z_AXIS_TITLE:
372 aRet=SchResId(STR_OBJECT_TITLE_Z_AXIS);
373 break;
374 case TitleHelper::SECONDARY_X_AXIS_TITLE:
375 aRet=SchResId(STR_OBJECT_TITLE_SECONDARY_X_AXIS);
376 break;
377 case TitleHelper::SECONDARY_Y_AXIS_TITLE:
378 aRet=SchResId(STR_OBJECT_TITLE_SECONDARY_Y_AXIS);
379 break;
380 default:
381 OSL_FAIL("unknown title type");
382 break;
385 if( aRet.isEmpty() )
386 aRet=SchResId(STR_OBJECT_TITLE);
388 return aRet;
391 OUString ObjectNameProvider::getTitleName( const OUString& rObjectCID
392 , const Reference< frame::XModel >& xChartModel )
394 OUString aRet;
396 Reference< XTitle > xTitle(
397 ObjectIdentifier::getObjectPropertySet( rObjectCID , xChartModel ), uno::UNO_QUERY );
398 if( xTitle.is() )
400 TitleHelper::eTitleType eType;
401 if( TitleHelper::getTitleType( eType, xTitle, xChartModel ) )
402 aRet = ObjectNameProvider::getTitleNameByType( eType );
404 if( aRet.isEmpty() )
405 aRet=SchResId(STR_OBJECT_TITLE);
407 return aRet;
410 OUString ObjectNameProvider::getGridName( const OUString& rObjectCID
411 , const uno::Reference< frame::XModel >& xChartModel )
413 OUString aRet;
415 sal_Int32 nCooSysIndex = -1;
416 sal_Int32 nDimensionIndex = -1;
417 sal_Int32 nAxisIndex = -1;
418 Reference< XAxis > xAxis( ObjectIdentifier::getAxisForCID( rObjectCID , xChartModel ) );
419 AxisHelper::getIndicesForAxis( xAxis, ChartModelHelper::findDiagram( xChartModel )
420 , nCooSysIndex , nDimensionIndex, nAxisIndex );
422 bool bMainGrid = (ObjectIdentifier::getObjectType( rObjectCID ) == OBJECTTYPE_GRID);
424 if( bMainGrid )
426 switch(nDimensionIndex)
428 case 0://x-axis
429 aRet=SchResId(STR_OBJECT_GRID_MAJOR_X);
430 break;
431 case 1://y-axis
432 aRet=SchResId(STR_OBJECT_GRID_MAJOR_Y);
433 break;
434 case 2://z-axis
435 aRet=SchResId(STR_OBJECT_GRID_MAJOR_Z);
436 break;
437 default://axis
438 aRet=SchResId(STR_OBJECT_GRID);
439 break;
442 else
444 switch(nDimensionIndex)
446 case 0://x-axis
447 aRet=SchResId(STR_OBJECT_GRID_MINOR_X);
448 break;
449 case 1://y-axis
450 aRet=SchResId(STR_OBJECT_GRID_MINOR_Y);
451 break;
452 case 2://z-axis
453 aRet=SchResId(STR_OBJECT_GRID_MINOR_Z);
454 break;
455 default://axis
456 aRet=SchResId(STR_OBJECT_GRID);
457 break;
460 return aRet;
463 OUString ObjectNameProvider::getHelpText( const OUString& rObjectCID, const Reference< chart2::XChartDocument >& xChartDocument )
465 return getHelpText( rObjectCID, Reference< frame::XModel >( xChartDocument ) );
468 OUString ObjectNameProvider::getHelpText( const OUString& rObjectCID, const Reference< frame::XModel >& xChartModel, bool bVerbose )
470 OUString aRet;
471 ObjectType eObjectType( ObjectIdentifier::getObjectType(rObjectCID) );
472 if( eObjectType == OBJECTTYPE_AXIS )
474 aRet=ObjectNameProvider::getAxisName( rObjectCID, xChartModel );
476 else if( eObjectType == OBJECTTYPE_GRID
477 || eObjectType == OBJECTTYPE_SUBGRID )
479 aRet=ObjectNameProvider::getGridName( rObjectCID, xChartModel );
481 else if( eObjectType == OBJECTTYPE_TITLE )
483 aRet=ObjectNameProvider::getTitleName( rObjectCID, xChartModel );
485 else if( eObjectType == OBJECTTYPE_DATA_SERIES )
487 aRet = lcl_getFullSeriesName( rObjectCID, xChartModel );
489 else if( eObjectType == OBJECTTYPE_DATA_POINT )
491 if( bVerbose )
493 aRet= SchResId(STR_TIP_DATAPOINT_INDEX) + "\n"
494 + SchResId(STR_TIP_DATASERIES) + "\n"
495 + SchResId(STR_TIP_DATAPOINT_VALUES);
497 else
498 aRet=SchResId(STR_TIP_DATAPOINT);
500 Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) );
501 Reference< XDataSeries > xSeries = ObjectIdentifier::getDataSeriesForCID( rObjectCID , xChartModel );
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( eObjectType == OBJECTTYPE_DATA_CURVE )
550 if( bVerbose )
552 aRet = SchResId( 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_SET_THROW );
565 sal_Int32 aDegree = 2;
566 sal_Int32 aPeriod = 2;
567 bool bForceIntercept = false;
568 double aInterceptValue = 0.0;
569 OUString aXName ("x"), aYName ("f(x)");
570 const LocaleDataWrapper& rLocaleDataWrapper = Application::GetSettings().GetLocaleDataWrapper();
571 const OUString& aNumDecimalSep = rLocaleDataWrapper.getNumDecimalSep();
572 sal_Unicode cDecSeparator = aNumDecimalSep[0];
574 uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
575 if ( xProperties.is())
577 xProperties->getPropertyValue( "PolynomialDegree") >>= aDegree;
578 xProperties->getPropertyValue( "MovingAveragePeriod") >>= aPeriod;
579 xProperties->getPropertyValue( "ForceIntercept") >>= bForceIntercept;
580 if (bForceIntercept)
581 xProperties->getPropertyValue( "InterceptValue") >>= aInterceptValue;
582 uno::Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties());
583 if( xEqProp.is())
585 if ( !(xEqProp->getPropertyValue( "XName") >>= aXName) )
586 aXName = "x";
587 if ( !(xEqProp->getPropertyValue( "YName") >>= aYName) )
588 aYName = "f(x)";
591 xCalculator->setRegressionProperties(aDegree, bForceIntercept, aInterceptValue, 2);
592 xCalculator->setXYNames ( aXName, aYName );
593 RegressionCurveHelper::initializeCurveCalculator( xCalculator, xSeries, xChartModel );
595 // change text for Moving Average
596 OUString aWildcard( "%PERIOD" );
597 sal_Int32 nIndex = xCalculator->getRepresentation().indexOf( aWildcard );
598 if( nIndex != -1 )
599 { // replace period
600 aRet = xCalculator->getRepresentation();
601 aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), OUString::number(aPeriod) );
604 // replace formula
605 aWildcard = "%FORMULA";
606 nIndex = aRet.indexOf( aWildcard );
607 if( nIndex != -1 )
609 OUString aFormula ( xCalculator->getRepresentation() );
610 if ( cDecSeparator != '.' )
612 aFormula = aFormula.replace( '.', cDecSeparator );
614 aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), aFormula );
617 // replace r^2
618 aWildcard = "%RSQUARED";
619 nIndex = aRet.indexOf( aWildcard );
620 if( nIndex != -1 )
622 double fR( xCalculator->getCorrelationCoefficient());
623 aRet = aRet.replaceAt(
624 nIndex, aWildcard.getLength(),
625 ::rtl::math::doubleToUString(
626 fR*fR, rtl_math_StringFormat_G, 4, cDecSeparator, true ));
629 catch( const uno::Exception & )
631 DBG_UNHANDLED_EXCEPTION("chart2");
636 else
638 Reference< chart2::XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID(rObjectCID , xChartModel));
639 Reference< chart2::XRegressionCurveContainer > xCurveCnt( xSeries, uno::UNO_QUERY );
640 aRet += getName(eObjectType);
642 if( xCurveCnt.is())
644 sal_Int32 nCurveIndex = ObjectIdentifier::getIndexFromParticleOrCID( rObjectCID );
645 Reference< chart2::XRegressionCurve > xCurve( RegressionCurveHelper::getRegressionCurveAtIndex(xCurveCnt, nCurveIndex) );
646 if( xCurve.is())
648 aRet += " (" + RegressionCurveHelper::getRegressionCurveName(xCurve) + " )";
653 else if( eObjectType == OBJECTTYPE_DATA_AVERAGE_LINE )
655 if( bVerbose )
657 aRet = SchResId(STR_OBJECT_AVERAGE_LINE_WITH_PARAMETERS);
658 Reference< chart2::XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID , xChartModel ));
659 Reference< chart2::XRegressionCurveContainer > xCurveCnt( xSeries, uno::UNO_QUERY );
660 if( xCurveCnt.is())
662 Reference< chart2::XRegressionCurve > xCurve( RegressionCurveHelper::getMeanValueLine( xCurveCnt ));
663 if( xCurve.is())
667 Reference< chart2::XRegressionCurveCalculator > xCalculator( xCurve->getCalculator(), uno::UNO_SET_THROW );
668 RegressionCurveHelper::initializeCurveCalculator( xCalculator, xSeries, xChartModel );
670 const LocaleDataWrapper& rLocaleDataWrapper = Application::GetSettings().GetLocaleDataWrapper();
671 const OUString& aNumDecimalSep = rLocaleDataWrapper.getNumDecimalSep();
672 sal_Unicode cDecSeparator = aNumDecimalSep[0];
674 OUString aWildcard( "%AVERAGE_VALUE" );
675 sal_Int32 nIndex = aRet.indexOf( aWildcard );
676 // as the curve is constant, the value at any x-value is ok
677 if( nIndex != -1 )
679 const double fMeanValue( xCalculator->getCurveValue( 0.0 ));
680 aRet = aRet.replaceAt(
681 nIndex, aWildcard.getLength(),
682 ::rtl::math::doubleToUString(
683 fMeanValue, rtl_math_StringFormat_G, 4, cDecSeparator, true ));
686 // replace standard deviation
687 aWildcard = "%STD_DEVIATION";
688 nIndex = aRet.indexOf( aWildcard );
689 if( nIndex != -1 )
691 const double fStdDev( xCalculator->getCorrelationCoefficient());
692 aRet = aRet.replaceAt(
693 nIndex, aWildcard.getLength(),
694 ::rtl::math::doubleToUString(
695 fStdDev, rtl_math_StringFormat_G, 4, cDecSeparator, true ));
698 catch( const uno::Exception & )
700 DBG_UNHANDLED_EXCEPTION("chart2");
705 else
707 // non-verbose
708 aRet = ObjectNameProvider::getName( eObjectType );
711 else
713 aRet = ObjectNameProvider::getName( eObjectType );
715 return aRet;
718 OUString ObjectNameProvider::getSelectedObjectText( const OUString & rObjectCID, const css::uno::Reference< css::chart2::XChartDocument >& xChartDocument )
720 OUString aRet;
721 ObjectType eObjectType( ObjectIdentifier::getObjectType(rObjectCID) );
722 Reference< frame::XModel > xChartModel = xChartDocument;
724 if( eObjectType == OBJECTTYPE_DATA_POINT )
726 aRet = SchResId( STR_STATUS_DATAPOINT_MARKED );
728 Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) );
729 Reference< XDataSeries > xSeries = ObjectIdentifier::getDataSeriesForCID( rObjectCID , xChartModel );
730 if( xDiagram.is() && xSeries.is() )
732 sal_Int32 nPointIndex( ObjectIdentifier::getParticleID(rObjectCID).toInt32() );
734 // replace data point index
735 replaceParamterInString( aRet, "%POINTNUMBER", OUString::number( 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, "%SERIESNUMBER", OUString::number( nSeriesIndex + 1 ) );
750 // replace point value
751 replaceParamterInString( aRet, "%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( eObjectType == OBJECTTYPE_DATA_CURVE || eObjectType == OBJECTTYPE_DATA_AVERAGE_LINE );
759 const OUString aHelpText( getHelpText( rObjectCID, xChartModel, bVerbose ));
760 if( !aHelpText.isEmpty())
762 aRet = SchResId( STR_STATUS_OBJECT_MARKED );
763 replaceParamterInString( aRet, "%OBJECTNAME", aHelpText );
767 return aRet;
770 OUString ObjectNameProvider::getNameForCID(
771 const OUString& rObjectCID,
772 const uno::Reference< chart2::XChartDocument >& xChartDocument )
774 ObjectType eType( ObjectIdentifier::getObjectType( rObjectCID ));
775 Reference< frame::XModel > xModel = xChartDocument;
777 switch( eType )
779 case OBJECTTYPE_AXIS:
780 return getAxisName( rObjectCID, xModel );
781 case OBJECTTYPE_TITLE:
782 return getTitleName( rObjectCID, xModel );
783 case OBJECTTYPE_GRID:
784 case OBJECTTYPE_SUBGRID:
785 return getGridName( rObjectCID, xModel );
786 case OBJECTTYPE_DATA_SERIES:
787 return lcl_getFullSeriesName( rObjectCID, xModel );
788 case OBJECTTYPE_DATA_POINT:
789 case OBJECTTYPE_DATA_LABELS:
790 case OBJECTTYPE_DATA_LABEL:
791 case OBJECTTYPE_DATA_ERRORS_X:
792 case OBJECTTYPE_DATA_ERRORS_Y:
793 case OBJECTTYPE_DATA_ERRORS_Z:
794 case OBJECTTYPE_DATA_AVERAGE_LINE:
795 case OBJECTTYPE_DATA_CURVE:
796 case OBJECTTYPE_DATA_CURVE_EQUATION:
798 OUString aRet = lcl_getFullSeriesName( rObjectCID, xModel ) + " ";
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 += " " + OUString::number(nPointIndex+1);
804 if( eType == OBJECTTYPE_DATA_LABEL )
806 aRet += " " + getName( OBJECTTYPE_DATA_LABEL );
809 else if (eType == OBJECTTYPE_DATA_CURVE || eType == OBJECTTYPE_DATA_CURVE_EQUATION)
811 Reference< chart2::XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID , xModel ));
812 Reference< chart2::XRegressionCurveContainer > xCurveCnt( xSeries, uno::UNO_QUERY );
814 aRet += " " + getName(eType);
816 if( xCurveCnt.is())
818 sal_Int32 nCurveIndex = ObjectIdentifier::getIndexFromParticleOrCID( rObjectCID );
819 Reference< chart2::XRegressionCurve > xCurve( RegressionCurveHelper::getRegressionCurveAtIndex(xCurveCnt, nCurveIndex) );
820 if( xCurve.is())
822 aRet += " (" + RegressionCurveHelper::getRegressionCurveName(xCurve) + ")";
826 else
828 aRet += getName( eType );
830 return aRet;
832 default:
833 break;
836 return getName( eType );
839 OUString ObjectNameProvider::getName_ObjectForSeries(
840 ObjectType eObjectType,
841 const OUString& rSeriesCID,
842 const uno::Reference< chart2::XChartDocument >& xChartDocument )
844 uno::Reference< frame::XModel> xChartModel = xChartDocument;
845 Reference< XDataSeries > xSeries = ObjectIdentifier::getDataSeriesForCID( rSeriesCID , xChartModel );
846 if( xSeries.is() )
848 OUString aRet = SchResId(STR_OBJECT_FOR_SERIES);
849 replaceParamterInString( aRet, "%OBJECTNAME", getName( eObjectType ) );
850 replaceParamterInString( aRet, "%SERIESNAME", lcl_getDataSeriesName( rSeriesCID, xChartModel ) );
851 return aRet;
853 else
854 return ObjectNameProvider::getName_ObjectForAllSeries( eObjectType );
857 OUString ObjectNameProvider::getName_ObjectForAllSeries( ObjectType eObjectType )
859 OUString aRet = SchResId(STR_OBJECT_FOR_ALL_SERIES);
860 replaceParamterInString( aRet, "%OBJECTNAME", getName( eObjectType, true /*bPlural*/ ) );
861 return aRet;
864 } //namespace chart
866 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */