tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / chart2 / source / controller / dialogs / ObjectNameProvider.cxx
blob172ef460a0a72cda7858c0b0a745a84b1cc7f006
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 <sal/config.h>
22 #include <string_view>
24 #include <ObjectNameProvider.hxx>
25 #include <ResId.hxx>
26 #include <strings.hrc>
27 #include <Axis.hxx>
28 #include <AxisHelper.hxx>
29 #include <ChartModel.hxx>
30 #include <ChartType.hxx>
31 #include <Diagram.hxx>
32 #include <DataSeries.hxx>
33 #include <DataSeriesHelper.hxx>
34 #include <TitleHelper.hxx>
35 #include <ExplicitCategoriesProvider.hxx>
36 #include <CommonConverters.hxx>
37 #include <NumberFormatterWrapper.hxx>
38 #include <RegressionCurveHelper.hxx>
39 #include <BaseCoordinateSystem.hxx>
40 #include <RegressionCurveModel.hxx>
41 #include <rtl/math.hxx>
42 #include <rtl/ustring.hxx>
43 #include <vcl/settings.hxx>
44 #include <vcl/svapp.hxx>
45 #include <unotools/localedatawrapper.hxx>
47 #include <com/sun/star/chart2/MovingAverageType.hpp>
48 #include <comphelper/diagnose_ex.hxx>
49 #include <o3tl/string_view.hxx>
51 namespace chart
53 using namespace ::com::sun::star;
54 using namespace ::com::sun::star::chart2;
55 using ::com::sun::star::uno::Reference;
56 using ::com::sun::star::uno::Sequence;
57 using ::com::sun::star::uno::Any;
59 namespace
62 OUString lcl_getDataSeriesName( std::u16string_view rObjectCID, const rtl::Reference<::chart::ChartModel>& xChartModel )
64 OUString aRet;
66 rtl::Reference< Diagram > xDiagram( xChartModel->getFirstChartDiagram() );
67 rtl::Reference< DataSeries > xSeries = ObjectIdentifier::getDataSeriesForCID( rObjectCID , xChartModel );
68 if( xDiagram.is() && xSeries.is() )
70 rtl::Reference< ChartType > xChartType( xDiagram->getChartTypeOfSeries( xSeries ) );
71 if( xChartType.is() )
73 aRet = xSeries->getLabelForRole(
74 xChartType->getRoleOfSequenceForSeriesLabel() ) ;
78 return aRet;
81 OUString lcl_getFullSeriesName( std::u16string_view rObjectCID, const rtl::Reference<::chart::ChartModel>& xChartModel )
83 OUString aRet(SchResId(STR_TIP_DATASERIES));
84 OUString aWildcard( u"%SERIESNAME"_ustr );
85 sal_Int32 nIndex = aRet.indexOf( aWildcard );
86 if( nIndex != -1 )
87 aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), lcl_getDataSeriesName( rObjectCID, xChartModel ) );
88 return aRet;
91 void lcl_addText( OUString& rOut, std::u16string_view rSeparator, std::u16string_view rNext )
93 if( !(rOut.isEmpty() || rNext.empty()) )
94 rOut+=rSeparator;
95 if( !rNext.empty() )
96 rOut+=rNext;
99 OUString lcl_getDataPointValueText( const rtl::Reference< DataSeries >& xSeries, sal_Int32 nPointIndex,
100 const rtl::Reference< BaseCoordinateSystem >& xCooSys,
101 const Reference< frame::XModel >& xChartModel )
104 OUString aRet;
106 if(!xSeries.is())
107 return aRet;
109 const std::vector< uno::Reference< chart2::data::XLabeledDataSequence > > & aDataSequences = xSeries->getDataSequences2();
111 OUString aX, aY, aY_Min, aY_Max, aY_First, aY_Last, a_Size;
112 double fValue = 0;
114 uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( xChartModel, uno::UNO_QUERY );
115 NumberFormatterWrapper aNumberFormatterWrapper( xNumberFormatsSupplier );
116 Color nLabelColor;//dummy
117 bool bColorChanged;//dummy
119 for(sal_Int32 nN = aDataSequences.size();nN--;)
121 uno::Reference<data::XDataSequence> xDataSequence( aDataSequences[nN]->getValues());
122 if( !xDataSequence.is() )
123 continue;
127 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())
134 uno::Any aARole = xProp->getPropertyValue( u"Role"_ustr );
135 OUString aRole;
136 aARole >>= aRole;
138 if( aRole == "values-x" )
140 aData[nPointIndex]>>= fValue;
141 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
142 aX = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
144 else if( aRole == "values-y")
146 aData[nPointIndex]>>= fValue;
147 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
148 aY = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
150 else if( aRole == "values-first" )
152 aData[nPointIndex]>>= fValue;
153 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
154 aY_First = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
156 else if( aRole == "values-min" )
158 aData[nPointIndex]>>= fValue;
159 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
160 aY_Min = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
162 else if( aRole == "values-max" )
164 aData[nPointIndex]>>= fValue;
165 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
166 aY_Max = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
168 else if( aRole == "values-last" )
170 aData[nPointIndex]>>= fValue;
171 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
172 aY_Last = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
174 else if( aRole == "values-size" )
176 aData[nPointIndex]>>= fValue;
177 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
178 a_Size = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
182 catch (const lang::DisposedException&)
184 TOOLS_WARN_EXCEPTION( "chart2", "unexpected exception caught" );
186 catch( const uno::Exception& )
188 TOOLS_WARN_EXCEPTION("chart2", "" );
192 if( aX.isEmpty() )
194 ChartModel& rModel = dynamic_cast<ChartModel&>(*xChartModel);
195 aRet = ExplicitCategoriesProvider::getCategoryByIndex( xCooSys, rModel, nPointIndex );
197 else
199 aRet = aX;
202 OUString aSeparator( u" "_ustr );
204 lcl_addText( aRet, aSeparator, aY );
205 lcl_addText( aRet, aSeparator, aY_First );
206 lcl_addText( aRet, aSeparator, aY_Min );
207 lcl_addText( aRet, aSeparator, aY_Max );
208 lcl_addText( aRet, aSeparator, aY_Last );
209 lcl_addText( aRet, aSeparator, a_Size );
211 return aRet;
214 } //end anonymous namespace
216 OUString ObjectNameProvider::getName( ObjectType eObjectType, bool bPlural )
218 OUString aRet;
219 switch( eObjectType )
221 case OBJECTTYPE_PAGE:
222 aRet=SchResId(STR_OBJECT_PAGE);
223 break;
224 case OBJECTTYPE_TITLE:
226 if(bPlural)
227 aRet=SchResId(STR_OBJECT_TITLES);
228 else
229 aRet=SchResId(STR_OBJECT_TITLE);
231 break;
232 case OBJECTTYPE_LEGEND:
233 aRet=SchResId(STR_OBJECT_LEGEND);
234 break;
235 case OBJECTTYPE_LEGEND_ENTRY:
236 aRet=SchResId(STR_OBJECT_LEGEND_SYMBOL);//@todo change string if we do differentiate symbol and legend entry in future
237 break;
238 case OBJECTTYPE_DIAGRAM:
239 aRet=SchResId(STR_OBJECT_DIAGRAM);
240 break;
241 case OBJECTTYPE_DIAGRAM_WALL:
242 aRet=SchResId(STR_OBJECT_DIAGRAM_WALL);
243 break;
244 case OBJECTTYPE_DIAGRAM_FLOOR:
245 aRet=SchResId(STR_OBJECT_DIAGRAM_FLOOR);
246 break;
247 case OBJECTTYPE_AXIS:
249 if(bPlural)
250 aRet=SchResId(STR_OBJECT_AXES);
251 else
252 aRet=SchResId(STR_OBJECT_AXIS);
254 break;
255 case OBJECTTYPE_AXIS_UNITLABEL:
256 case OBJECTTYPE_DATA_LABEL:
257 aRet=SchResId(STR_OBJECT_LABEL);//@todo maybe a more concrete name
258 break;
259 case OBJECTTYPE_GRID:
260 case OBJECTTYPE_SUBGRID: //maybe todo: different names for subgrids
262 if(bPlural)
263 aRet=SchResId(STR_OBJECT_GRIDS);
264 else
265 aRet=SchResId(STR_OBJECT_GRID);
267 break;
268 case OBJECTTYPE_DATA_SERIES:
270 if(bPlural)
271 aRet=SchResId(STR_OBJECT_DATASERIES_PLURAL);
272 else
273 aRet=SchResId(STR_OBJECT_DATASERIES);
275 break;
276 case OBJECTTYPE_DATA_POINT:
278 if(bPlural)
279 aRet=SchResId(STR_OBJECT_DATAPOINTS);
280 else
281 aRet=SchResId(STR_OBJECT_DATAPOINT);
283 break;
284 case OBJECTTYPE_DATA_LABELS:
285 aRet=SchResId(STR_OBJECT_DATALABELS);
286 break;
287 case OBJECTTYPE_DATA_ERRORS_X:
288 aRet=SchResId(STR_OBJECT_ERROR_BARS_X);
289 break;
290 case OBJECTTYPE_DATA_ERRORS_Y:
291 aRet=SchResId(STR_OBJECT_ERROR_BARS_Y);
292 break;
293 case OBJECTTYPE_DATA_ERRORS_Z:
294 aRet=SchResId(STR_OBJECT_ERROR_BARS_Z);
295 break;
296 case OBJECTTYPE_DATA_AVERAGE_LINE:
297 aRet=SchResId(STR_OBJECT_AVERAGE_LINE);
298 break;
299 case OBJECTTYPE_DATA_CURVE:
301 if(bPlural)
302 aRet=SchResId(STR_OBJECT_CURVES);
303 else
304 aRet=SchResId(STR_OBJECT_CURVE);
306 break;
307 case OBJECTTYPE_DATA_STOCK_RANGE:
308 break;
309 case OBJECTTYPE_DATA_STOCK_LOSS:
310 aRet=SchResId(STR_OBJECT_STOCK_LOSS);
311 break;
312 case OBJECTTYPE_DATA_STOCK_GAIN:
313 aRet=SchResId(STR_OBJECT_STOCK_GAIN);
314 break;
315 case OBJECTTYPE_DATA_CURVE_EQUATION:
316 aRet=SchResId(STR_OBJECT_CURVE_EQUATION);
317 break;
318 case OBJECTTYPE_DATA_TABLE:
319 aRet=SchResId(STR_DATA_TABLE);
320 break;
321 default: //OBJECTTYPE_UNKNOWN
324 return aRet;
327 OUString ObjectNameProvider::getAxisName( std::u16string_view rObjectCID
328 , const rtl::Reference<::chart::ChartModel>& xChartModel )
330 OUString aRet;
332 rtl::Reference< ::chart::Axis > xAxis =
333 dynamic_cast<::chart::Axis*>(ObjectIdentifier::getObjectPropertySet( rObjectCID , xChartModel ).get());
335 sal_Int32 nCooSysIndex = 0;
336 sal_Int32 nDimensionIndex = 0;
337 sal_Int32 nAxisIndex = 0;
338 AxisHelper::getIndicesForAxis( xAxis, xChartModel->getFirstChartDiagram(), nCooSysIndex, nDimensionIndex, nAxisIndex );
340 switch(nDimensionIndex)
342 case 0://x-axis
343 if( nAxisIndex == 0 )
344 aRet=SchResId(STR_OBJECT_AXIS_X);
345 else
346 aRet=SchResId(STR_OBJECT_SECONDARY_X_AXIS);
347 break;
348 case 1://y-axis
349 if( nAxisIndex == 0 )
350 aRet=SchResId(STR_OBJECT_AXIS_Y);
351 else
352 aRet=SchResId(STR_OBJECT_SECONDARY_Y_AXIS);
353 break;
354 case 2://z-axis
355 aRet=SchResId(STR_OBJECT_AXIS_Z);
356 break;
357 default://axis
358 aRet=SchResId(STR_OBJECT_AXIS);
359 break;
362 return aRet;
365 OUString ObjectNameProvider::getTitleNameByType( TitleHelper::eTitleType eType )
367 OUString aRet;
369 switch(eType)
371 case TitleHelper::MAIN_TITLE:
372 aRet=SchResId(STR_OBJECT_TITLE_MAIN);
373 break;
374 case TitleHelper::SUB_TITLE:
375 aRet=SchResId(STR_OBJECT_TITLE_SUB);
376 break;
377 case TitleHelper::X_AXIS_TITLE:
378 aRet=SchResId(STR_OBJECT_TITLE_X_AXIS);
379 break;
380 case TitleHelper::Y_AXIS_TITLE:
381 aRet=SchResId(STR_OBJECT_TITLE_Y_AXIS);
382 break;
383 case TitleHelper::Z_AXIS_TITLE:
384 aRet=SchResId(STR_OBJECT_TITLE_Z_AXIS);
385 break;
386 case TitleHelper::SECONDARY_X_AXIS_TITLE:
387 aRet=SchResId(STR_OBJECT_TITLE_SECONDARY_X_AXIS);
388 break;
389 case TitleHelper::SECONDARY_Y_AXIS_TITLE:
390 aRet=SchResId(STR_OBJECT_TITLE_SECONDARY_Y_AXIS);
391 break;
392 default:
393 OSL_FAIL("unknown title type");
394 break;
397 if( aRet.isEmpty() )
398 aRet=SchResId(STR_OBJECT_TITLE);
400 return aRet;
403 OUString ObjectNameProvider::getTitleName( std::u16string_view rObjectCID
404 , const rtl::Reference<::chart::ChartModel>& xChartModel )
406 OUString aRet;
408 rtl::Reference<Title> xTitle =
409 dynamic_cast<Title*>(ObjectIdentifier::getObjectPropertySet( rObjectCID , xChartModel ).get());
410 if( xTitle )
412 TitleHelper::eTitleType eType;
413 if( TitleHelper::getTitleType( eType, xTitle, xChartModel ) )
414 aRet = ObjectNameProvider::getTitleNameByType( eType );
416 if( aRet.isEmpty() )
417 aRet=SchResId(STR_OBJECT_TITLE);
419 return aRet;
422 OUString ObjectNameProvider::getGridName( std::u16string_view rObjectCID
423 , const rtl::Reference<::chart::ChartModel>& xChartModel )
425 OUString aRet;
427 sal_Int32 nCooSysIndex = -1;
428 sal_Int32 nDimensionIndex = -1;
429 sal_Int32 nAxisIndex = -1;
430 rtl::Reference< Axis > xAxis = ObjectIdentifier::getAxisForCID( rObjectCID , xChartModel );
431 AxisHelper::getIndicesForAxis( xAxis, xChartModel->getFirstChartDiagram()
432 , nCooSysIndex , nDimensionIndex, nAxisIndex );
434 bool bMainGrid = (ObjectIdentifier::getObjectType( rObjectCID ) == OBJECTTYPE_GRID);
436 if( bMainGrid )
438 switch(nDimensionIndex)
440 case 0://x-axis
441 aRet=SchResId(STR_OBJECT_GRID_MAJOR_X);
442 break;
443 case 1://y-axis
444 aRet=SchResId(STR_OBJECT_GRID_MAJOR_Y);
445 break;
446 case 2://z-axis
447 aRet=SchResId(STR_OBJECT_GRID_MAJOR_Z);
448 break;
449 default://axis
450 aRet=SchResId(STR_OBJECT_GRID);
451 break;
454 else
456 switch(nDimensionIndex)
458 case 0://x-axis
459 aRet=SchResId(STR_OBJECT_GRID_MINOR_X);
460 break;
461 case 1://y-axis
462 aRet=SchResId(STR_OBJECT_GRID_MINOR_Y);
463 break;
464 case 2://z-axis
465 aRet=SchResId(STR_OBJECT_GRID_MINOR_Z);
466 break;
467 default://axis
468 aRet=SchResId(STR_OBJECT_GRID);
469 break;
472 return aRet;
475 OUString ObjectNameProvider::getHelpText( std::u16string_view rObjectCID, const rtl::Reference<::chart::ChartModel>& xChartModel, bool bVerbose )
477 OUString aRet;
478 ObjectType eObjectType( ObjectIdentifier::getObjectType(rObjectCID) );
479 if( eObjectType == OBJECTTYPE_AXIS )
481 aRet=ObjectNameProvider::getAxisName( rObjectCID, xChartModel );
483 else if( eObjectType == OBJECTTYPE_GRID
484 || eObjectType == OBJECTTYPE_SUBGRID )
486 aRet=ObjectNameProvider::getGridName( rObjectCID, xChartModel );
488 else if( eObjectType == OBJECTTYPE_TITLE )
490 aRet=ObjectNameProvider::getTitleName( rObjectCID, xChartModel );
492 else if( eObjectType == OBJECTTYPE_DATA_SERIES )
494 aRet = lcl_getFullSeriesName( rObjectCID, xChartModel );
496 else if( eObjectType == OBJECTTYPE_DATA_POINT )
498 if( bVerbose )
500 aRet= SchResId(STR_TIP_DATAPOINT_INDEX) + "\n"
501 + SchResId(STR_TIP_DATASERIES) + "\n"
502 + SchResId(STR_TIP_DATAPOINT_VALUES);
504 else
505 aRet=SchResId(STR_TIP_DATAPOINT);
507 rtl::Reference< Diagram > xDiagram( xChartModel->getFirstChartDiagram() );
508 rtl::Reference< DataSeries > xSeries = ObjectIdentifier::getDataSeriesForCID( rObjectCID , xChartModel );
509 if( xDiagram.is() && xSeries.is() )
511 sal_Int32 nPointIndex = o3tl::toInt32(ObjectIdentifier::getParticleID(rObjectCID));
513 //replace data point index
514 OUString aWildcard( u"%POINTNUMBER"_ustr );
515 sal_Int32 nIndex = aRet.indexOf( aWildcard );
516 if( nIndex != -1 )
518 aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), OUString::number(nPointIndex+1) );
521 //replace data series index
522 aWildcard = "%SERIESNUMBER";
523 nIndex = aRet.indexOf( aWildcard );
524 if( nIndex != -1 )
526 std::vector< rtl::Reference< DataSeries > > aSeriesVector =
527 xDiagram->getDataSeries();
528 sal_Int32 nSeriesIndex = -1;
529 for( nSeriesIndex=aSeriesVector.size();nSeriesIndex--;)
531 if( aSeriesVector[nSeriesIndex] == xSeries )
533 break;
537 OUString aReplacement( OUString::number(nSeriesIndex+1) );
538 aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), aReplacement );
541 //replace point values
542 aWildcard = "%POINTVALUES";
543 nIndex = aRet.indexOf( aWildcard );
544 if( nIndex != -1 )
545 aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), lcl_getDataPointValueText(
546 xSeries,nPointIndex, DataSeriesHelper::getCoordinateSystemOfSeries(xSeries, xDiagram), xChartModel ) );
548 //replace series name
549 aWildcard = "%SERIESNAME";
550 nIndex = aRet.indexOf( aWildcard );
551 if( nIndex != -1 )
552 aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), lcl_getDataSeriesName( rObjectCID, xChartModel ) );
555 else if( eObjectType == OBJECTTYPE_DATA_CURVE )
557 if( bVerbose )
559 aRet = SchResId( STR_OBJECT_CURVE_WITH_PARAMETERS );
560 rtl::Reference< DataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID , xChartModel ));
562 if( xSeries.is())
564 sal_Int32 nCurveIndex = ObjectIdentifier::getIndexFromParticleOrCID( rObjectCID );
565 rtl::Reference< RegressionCurveModel > xCurve = RegressionCurveHelper::getRegressionCurveAtIndex(xSeries, nCurveIndex);
566 if( xCurve.is())
570 Reference< chart2::XRegressionCurveCalculator > xCalculator( xCurve->getCalculator(), uno::UNO_SET_THROW );
571 sal_Int32 aDegree = 2;
572 sal_Int32 aPeriod = 2;
573 sal_Int32 aMovingType = css::chart2::MovingAverageType::Prior;
574 bool bForceIntercept = false;
575 double aInterceptValue = 0.0;
576 OUString aXName (u"x"_ustr), aYName (u"f(x)"_ustr);
577 const LocaleDataWrapper& rLocaleDataWrapper = Application::GetSettings().GetLocaleDataWrapper();
578 const OUString& aNumDecimalSep = rLocaleDataWrapper.getNumDecimalSep();
579 sal_Unicode cDecSeparator = aNumDecimalSep[0];
581 xCurve->getPropertyValue( u"PolynomialDegree"_ustr) >>= aDegree;
582 xCurve->getPropertyValue( u"MovingAveragePeriod"_ustr) >>= aPeriod;
583 xCurve->getPropertyValue( u"MovingAverageType"_ustr) >>= aMovingType;
584 xCurve->getPropertyValue( u"ForceIntercept"_ustr) >>= bForceIntercept;
585 if (bForceIntercept)
586 xCurve->getPropertyValue( u"InterceptValue"_ustr) >>= aInterceptValue;
587 uno::Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties());
588 if( xEqProp.is())
590 if ( !(xEqProp->getPropertyValue( u"XName"_ustr) >>= aXName) )
591 aXName = "x";
592 if ( !(xEqProp->getPropertyValue( u"YName"_ustr) >>= aYName) )
593 aYName = "f(x)";
595 xCalculator->setRegressionProperties(aDegree, bForceIntercept, aInterceptValue, aPeriod, aMovingType);
596 xCalculator->setXYNames ( aXName, aYName );
597 RegressionCurveHelper::initializeCurveCalculator( xCalculator, xSeries, xChartModel );
599 // change text for Moving Average
600 if ( RegressionCurveHelper::getRegressionType( xCurve ) == SvxChartRegress::MovingAverage )
602 aRet = xCalculator->getRepresentation();
604 else
606 // replace formula
607 OUString aWildcard = u"%FORMULA"_ustr;
608 sal_Int32 nIndex = aRet.indexOf( aWildcard );
609 if( nIndex != -1 )
611 OUString aFormula ( xCalculator->getRepresentation() );
612 if ( cDecSeparator != '.' )
614 aFormula = aFormula.replace( '.', cDecSeparator );
616 aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), aFormula );
619 // replace r^2
620 aWildcard = "%RSQUARED";
621 nIndex = aRet.indexOf( aWildcard );
622 if( nIndex != -1 )
624 double fR( xCalculator->getCorrelationCoefficient());
625 aRet = aRet.replaceAt(
626 nIndex, aWildcard.getLength(),
627 ::rtl::math::doubleToUString(
628 fR*fR, rtl_math_StringFormat_G, 4, cDecSeparator, true ));
632 catch( const uno::Exception & )
634 DBG_UNHANDLED_EXCEPTION("chart2");
639 else
641 rtl::Reference< DataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID(rObjectCID , xChartModel));
642 aRet += getName(eObjectType);
644 if( xSeries.is())
646 sal_Int32 nCurveIndex = ObjectIdentifier::getIndexFromParticleOrCID( rObjectCID );
647 rtl::Reference< RegressionCurveModel > xCurve( RegressionCurveHelper::getRegressionCurveAtIndex(xSeries, nCurveIndex) );
648 if( xCurve.is())
650 aRet += " (" + RegressionCurveHelper::getRegressionCurveName(xCurve) + " )";
655 else if( eObjectType == OBJECTTYPE_DATA_AVERAGE_LINE )
657 if( bVerbose )
659 aRet = SchResId(STR_OBJECT_AVERAGE_LINE_WITH_PARAMETERS);
660 rtl::Reference< DataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID , xChartModel ));
661 if( xSeries.is())
663 rtl::Reference< RegressionCurveModel > xCurve( RegressionCurveHelper::getMeanValueLine( xSeries ));
664 if( xCurve.is())
668 Reference< chart2::XRegressionCurveCalculator > xCalculator( xCurve->getCalculator(), uno::UNO_SET_THROW );
669 RegressionCurveHelper::initializeCurveCalculator( xCalculator, xSeries, xChartModel );
671 const LocaleDataWrapper& rLocaleDataWrapper = Application::GetSettings().GetLocaleDataWrapper();
672 const OUString& aNumDecimalSep = rLocaleDataWrapper.getNumDecimalSep();
673 sal_Unicode cDecSeparator = aNumDecimalSep[0];
675 OUString aWildcard( u"%AVERAGE_VALUE"_ustr );
676 sal_Int32 nIndex = aRet.indexOf( aWildcard );
677 // as the curve is constant, the value at any x-value is ok
678 if( nIndex != -1 )
680 const double fMeanValue( xCalculator->getCurveValue( 0.0 ));
681 aRet = aRet.replaceAt(
682 nIndex, aWildcard.getLength(),
683 ::rtl::math::doubleToUString(
684 fMeanValue, rtl_math_StringFormat_G, 4, cDecSeparator, true ));
687 // replace standard deviation
688 aWildcard = "%STD_DEVIATION";
689 nIndex = aRet.indexOf( aWildcard );
690 if( nIndex != -1 )
692 const double fStdDev( xCalculator->getCorrelationCoefficient());
693 aRet = aRet.replaceAt(
694 nIndex, aWildcard.getLength(),
695 ::rtl::math::doubleToUString(
696 fStdDev, rtl_math_StringFormat_G, 4, cDecSeparator, true ));
699 catch( const uno::Exception & )
701 DBG_UNHANDLED_EXCEPTION("chart2");
706 else
708 // non-verbose
709 aRet = ObjectNameProvider::getName( eObjectType );
712 else
714 aRet = ObjectNameProvider::getName( eObjectType );
716 return aRet;
719 OUString ObjectNameProvider::getSelectedObjectText( std::u16string_view rObjectCID, const rtl::Reference<::chart::ChartModel>& xChartDocument )
721 OUString aRet;
722 ObjectType eObjectType( ObjectIdentifier::getObjectType(rObjectCID) );
724 if( eObjectType == OBJECTTYPE_DATA_POINT )
726 aRet = SchResId( STR_STATUS_DATAPOINT_MARKED );
728 rtl::Reference< Diagram > xDiagram( xChartDocument->getFirstChartDiagram() );
729 rtl::Reference< DataSeries > xSeries = ObjectIdentifier::getDataSeriesForCID( rObjectCID , xChartDocument );
730 if( xDiagram.is() && xSeries.is() )
732 sal_Int32 nPointIndex = o3tl::toInt32( ObjectIdentifier::getParticleID(rObjectCID) );
734 // replace data point index
735 replaceParamterInString( aRet, u"%POINTNUMBER", OUString::number( nPointIndex + 1 ));
737 // replace data series index
739 std::vector< rtl::Reference< DataSeries > > aSeriesVector(
740 xDiagram->getDataSeries() );
741 sal_Int32 nSeriesIndex = -1;
742 for( nSeriesIndex=aSeriesVector.size();nSeriesIndex--;)
744 if( aSeriesVector[nSeriesIndex] == xSeries )
745 break;
747 replaceParamterInString( aRet, u"%SERIESNUMBER", OUString::number( nSeriesIndex + 1 ) );
750 // replace point value
751 replaceParamterInString( aRet, u"%POINTVALUES", lcl_getDataPointValueText(
752 xSeries, nPointIndex, DataSeriesHelper::getCoordinateSystemOfSeries(xSeries, xDiagram), xChartDocument ) );
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, xChartDocument, bVerbose ));
760 if( !aHelpText.isEmpty())
762 aRet = SchResId( STR_STATUS_OBJECT_MARKED );
763 replaceParamterInString( aRet, u"%OBJECTNAME", aHelpText );
767 return aRet;
770 OUString ObjectNameProvider::getNameForCID(
771 std::u16string_view rObjectCID,
772 const rtl::Reference<::chart::ChartModel>& xChartDocument )
774 ObjectType eType( ObjectIdentifier::getObjectType( rObjectCID ));
776 switch( eType )
778 case OBJECTTYPE_AXIS:
779 return getAxisName( rObjectCID, xChartDocument );
780 case OBJECTTYPE_TITLE:
781 return getTitleName( rObjectCID, xChartDocument );
782 case OBJECTTYPE_GRID:
783 case OBJECTTYPE_SUBGRID:
784 return getGridName( rObjectCID, xChartDocument );
785 case OBJECTTYPE_DATA_SERIES:
786 return lcl_getFullSeriesName( rObjectCID, xChartDocument );
787 case OBJECTTYPE_DATA_POINT:
788 case OBJECTTYPE_DATA_LABELS:
789 case OBJECTTYPE_DATA_LABEL:
790 case OBJECTTYPE_DATA_ERRORS_X:
791 case OBJECTTYPE_DATA_ERRORS_Y:
792 case OBJECTTYPE_DATA_ERRORS_Z:
793 case OBJECTTYPE_DATA_AVERAGE_LINE:
794 case OBJECTTYPE_DATA_CURVE:
795 case OBJECTTYPE_DATA_CURVE_EQUATION:
797 OUString aRet = lcl_getFullSeriesName( rObjectCID, xChartDocument ) + " ";
798 if( eType == OBJECTTYPE_DATA_POINT || eType == OBJECTTYPE_DATA_LABEL )
800 aRet += getName( OBJECTTYPE_DATA_POINT );
801 sal_Int32 nPointIndex = ObjectIdentifier::getIndexFromParticleOrCID( rObjectCID );
802 aRet += " " + OUString::number(nPointIndex+1);
803 if( eType == OBJECTTYPE_DATA_LABEL )
805 aRet += " " + getName( OBJECTTYPE_DATA_LABEL );
808 else if (eType == OBJECTTYPE_DATA_CURVE || eType == OBJECTTYPE_DATA_CURVE_EQUATION)
810 rtl::Reference< DataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID , xChartDocument ));
812 aRet += " " + getName(eType);
814 if( xSeries.is())
816 sal_Int32 nCurveIndex = ObjectIdentifier::getIndexFromParticleOrCID( rObjectCID );
817 rtl::Reference< RegressionCurveModel > xCurve( RegressionCurveHelper::getRegressionCurveAtIndex(xSeries, nCurveIndex) );
818 if( xCurve.is())
820 aRet += " (" + RegressionCurveHelper::getRegressionCurveName(xCurve) + ")";
824 else
826 aRet += getName( eType );
828 return aRet;
830 default:
831 break;
834 return getName( eType );
837 OUString ObjectNameProvider::getName_ObjectForSeries(
838 ObjectType eObjectType,
839 std::u16string_view rSeriesCID,
840 const rtl::Reference<::chart::ChartModel>& xChartDocument )
842 rtl::Reference< DataSeries > xSeries = ObjectIdentifier::getDataSeriesForCID( rSeriesCID , xChartDocument );
843 if( xSeries.is() )
845 OUString aRet = SchResId(STR_OBJECT_FOR_SERIES);
846 replaceParamterInString( aRet, u"%OBJECTNAME", getName( eObjectType ) );
847 replaceParamterInString( aRet, u"%SERIESNAME", lcl_getDataSeriesName( rSeriesCID, xChartDocument ) );
848 return aRet;
850 else
851 return ObjectNameProvider::getName_ObjectForAllSeries( eObjectType );
854 OUString ObjectNameProvider::getName_ObjectForAllSeries( ObjectType eObjectType )
856 OUString aRet = SchResId(STR_OBJECT_FOR_ALL_SERIES);
857 replaceParamterInString( aRet, u"%OBJECTNAME", getName( eObjectType, true /*bPlural*/ ) );
858 return aRet;
861 } //namespace chart
863 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */