tdf#154285 Check upper bound of arguments in SbRtl_Minute function
[LibreOffice.git] / chart2 / source / controller / main / ChartController_Properties.cxx
blob304af1d07dc676ec6a117f532eee5b595944d857
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 <ChartController.hxx>
21 #include <ChartView.hxx>
22 #include <chartview/DrawModelWrapper.hxx>
23 #include <chartview/ChartSfxItemIds.hxx>
24 #include <ObjectIdentifier.hxx>
25 #include <chartview/ExplicitScaleValues.hxx>
26 #include <chartview/ExplicitValueProvider.hxx>
27 #include <dlg_ObjectProperties.hxx>
28 #include <dlg_View3D.hxx>
29 #include <dlg_InsertErrorBars.hxx>
30 #include <ViewElementListProvider.hxx>
31 #include <DataPointItemConverter.hxx>
32 #include <TextLabelItemConverter.hxx>
33 #include <AxisItemConverter.hxx>
34 #include <MultipleChartConverters.hxx>
35 #include <TitleItemConverter.hxx>
36 #include <LegendItemConverter.hxx>
37 #include <DataTableItemConverter.hxx>
38 #include <RegressionCurveItemConverter.hxx>
39 #include <RegressionEquationItemConverter.hxx>
40 #include <ErrorBarItemConverter.hxx>
41 #include <ChartModelHelper.hxx>
42 #include <Axis.hxx>
43 #include <AxisHelper.hxx>
44 #include <TitleHelper.hxx>
45 #include <ChartType.hxx>
46 #include <ChartTypeHelper.hxx>
47 #include <ChartModel.hxx>
48 #include <ColorPerPointHelper.hxx>
49 #include <DataSeries.hxx>
50 #include <DataSeriesProperties.hxx>
51 #include <Diagram.hxx>
52 #include <ControllerLockGuard.hxx>
53 #include "UndoGuard.hxx"
54 #include <ObjectNameProvider.hxx>
55 #include <ResId.hxx>
56 #include <strings.hrc>
57 #include <ReferenceSizeProvider.hxx>
58 #include <RegressionCurveHelper.hxx>
59 #include <RegressionCurveModel.hxx>
60 #include <o3tl/string_view.hxx>
61 #include <com/sun/star/util/CloseVetoException.hpp>
63 #include <memory>
65 #include <vcl/svapp.hxx>
66 #include <svx/ActionDescriptionProvider.hxx>
67 #include <comphelper/diagnose_ex.hxx>
69 namespace chart
71 using namespace ::com::sun::star;
72 using namespace ::com::sun::star::chart2;
73 using namespace ::chart::DataSeriesProperties;
74 using ::com::sun::star::uno::Reference;
76 namespace
79 wrapper::ItemConverter* createItemConverter(
80 std::u16string_view aObjectCID, const rtl::Reference<::chart::ChartModel>& xChartModel,
81 const uno::Reference<uno::XComponentContext>& xContext, SdrModel& rDrawModel,
82 ExplicitValueProvider* pExplicitValueProvider, ReferenceSizeProvider const * pRefSizeProvider )
84 wrapper::ItemConverter* pItemConverter=nullptr;
86 //get type of selected object
87 ObjectType eObjectType = ObjectIdentifier::getObjectType( aObjectCID );
88 if( eObjectType==OBJECTTYPE_UNKNOWN )
90 OSL_FAIL("unknown ObjectType");
91 return nullptr;
94 std::u16string_view aParticleID = ObjectIdentifier::getParticleID( aObjectCID );
95 bool bAffectsMultipleObjects = aParticleID == u"ALLELEMENTS";
96 if( !bAffectsMultipleObjects )
98 uno::Reference< beans::XPropertySet > xObjectProperties =
99 ObjectIdentifier::getObjectPropertySet( aObjectCID, xChartModel );
100 if(!xObjectProperties.is())
101 return nullptr;
102 //create itemconverter for a single object
103 switch(eObjectType)
105 case OBJECTTYPE_DATA_STOCK_LOSS:
106 case OBJECTTYPE_DATA_STOCK_GAIN:
107 case OBJECTTYPE_DIAGRAM_WALL:
108 case OBJECTTYPE_DIAGRAM_FLOOR:
109 case OBJECTTYPE_PAGE:
110 pItemConverter = new wrapper::GraphicPropertyItemConverter(
111 xObjectProperties, rDrawModel.GetItemPool(),
112 rDrawModel, xChartModel,
113 wrapper::GraphicObjectType::LineAndFillProperties );
114 break;
115 case OBJECTTYPE_TITLE:
117 std::optional<awt::Size> pRefSize;
118 if (pRefSizeProvider)
119 pRefSize.emplace(pRefSizeProvider->getPageSize());
121 pItemConverter = new wrapper::TitleItemConverter(
122 xObjectProperties, rDrawModel.GetItemPool(), rDrawModel,
123 xChartModel,
124 pRefSize);
126 break;
127 case OBJECTTYPE_LEGEND:
129 std::optional<awt::Size> pRefSize;
130 if (pRefSizeProvider)
131 pRefSize.emplace( pRefSizeProvider->getPageSize() );
133 pItemConverter = new wrapper::LegendItemConverter(
134 xObjectProperties, rDrawModel.GetItemPool(), rDrawModel,
135 xChartModel,
136 pRefSize);
138 break;
139 case OBJECTTYPE_LEGEND_ENTRY:
140 break;
141 case OBJECTTYPE_DIAGRAM:
142 break;
143 case OBJECTTYPE_AXIS:
145 std::optional<awt::Size> pRefSize;
146 if (pRefSizeProvider)
147 pRefSize.emplace( pRefSizeProvider->getPageSize() );
149 // the second property set contains the property CoordinateOrigin
150 // nOriginIndex is the index of the corresponding index of the
151 // origin (x=0, y=1, z=2)
153 ExplicitScaleData aExplicitScale;
154 ExplicitIncrementData aExplicitIncrement;
155 if( pExplicitValueProvider )
156 pExplicitValueProvider->getExplicitValuesForAxis(
157 dynamic_cast< Axis* >( xObjectProperties.get() ),
158 aExplicitScale, aExplicitIncrement );
160 pItemConverter = new wrapper::AxisItemConverter(
161 xObjectProperties, rDrawModel.GetItemPool(),
162 rDrawModel,
163 xChartModel,
164 &aExplicitScale, &aExplicitIncrement,
165 pRefSize );
167 break;
168 case OBJECTTYPE_AXIS_UNITLABEL:
169 break;
170 case OBJECTTYPE_DATA_LABELS:
171 case OBJECTTYPE_DATA_LABEL:
173 std::optional<awt::Size> pRefSize;
174 if (pRefSizeProvider)
175 pRefSize.emplace( pRefSizeProvider->getPageSize() );
177 rtl::Reference<DataSeries> xSeries = ObjectIdentifier::getDataSeriesForCID(aObjectCID, xChartModel);
179 bool bDataSeries = eObjectType == OBJECTTYPE_DATA_LABELS;
181 sal_Int32 nNumberFormat = ExplicitValueProvider::getExplicitNumberFormatKeyForDataLabel( xObjectProperties );
182 sal_Int32 nPercentNumberFormat = ExplicitValueProvider::getExplicitPercentageNumberFormatKeyForDataLabel(
183 xObjectProperties, xChartModel);
185 pItemConverter = new wrapper::TextLabelItemConverter(
186 xChartModel, xObjectProperties, xSeries,
187 rDrawModel.GetItemPool(), pRefSize, bDataSeries,
188 nNumberFormat, nPercentNumberFormat);
190 break;
191 case OBJECTTYPE_DATA_SERIES:
192 case OBJECTTYPE_DATA_POINT:
194 std::optional<awt::Size> pRefSize;
195 if (pRefSizeProvider)
196 pRefSize.emplace( pRefSizeProvider->getPageSize() );
198 wrapper::GraphicObjectType eMapTo =
199 wrapper::GraphicObjectType::FilledDataPoint;
201 rtl::Reference< DataSeries > xSeries = ObjectIdentifier::getDataSeriesForCID( aObjectCID, xChartModel );
202 rtl::Reference< ChartType > xChartType = ChartModelHelper::getChartTypeOfSeries( xChartModel, xSeries );
204 rtl::Reference< Diagram > xDiagram = xChartModel->getFirstChartDiagram();
205 sal_Int32 nDimensionCount = xDiagram->getDimension();
206 if( !ChartTypeHelper::isSupportingAreaProperties( xChartType, nDimensionCount ) )
207 eMapTo = wrapper::GraphicObjectType::LineDataPoint;
209 bool bDataSeries = eObjectType == OBJECTTYPE_DATA_SERIES;
211 //special color for pie chart:
212 bool bUseSpecialFillColor = false;
213 sal_Int32 nSpecialFillColor =0;
214 sal_Int32 nPointIndex = -1; /*-1 for whole series*/
215 if(!bDataSeries)
217 nPointIndex = o3tl::toInt32(aParticleID);
218 bool bVaryColorsByPoint = false;
219 if( xSeries.is() &&
220 // "VaryColorsByPoint"
221 (xSeries->getFastPropertyValue(PROP_DATASERIES_VARY_COLORS_BY_POINT) >>= bVaryColorsByPoint) &&
222 bVaryColorsByPoint )
224 if( !ColorPerPointHelper::hasPointOwnColor( xSeries, nPointIndex, xObjectProperties ) )
226 bUseSpecialFillColor = true;
227 OSL_ASSERT( xDiagram.is());
228 uno::Reference< XColorScheme > xColorScheme( xDiagram->getDefaultColorScheme() );
229 if( xColorScheme.is())
230 nSpecialFillColor = xColorScheme->getColorByIndex( nPointIndex );
234 sal_Int32 nNumberFormat=ExplicitValueProvider::getExplicitNumberFormatKeyForDataLabel( xObjectProperties );
235 sal_Int32 nPercentNumberFormat=ExplicitValueProvider::getExplicitPercentageNumberFormatKeyForDataLabel(
236 xObjectProperties, xChartModel);
238 pItemConverter = new wrapper::DataPointItemConverter( xChartModel, xContext,
239 xObjectProperties, xSeries, rDrawModel.GetItemPool(), rDrawModel,
240 xChartModel,
241 eMapTo, pRefSize, bDataSeries, bUseSpecialFillColor, nSpecialFillColor, true,
242 nNumberFormat, nPercentNumberFormat, nPointIndex );
243 break;
245 case OBJECTTYPE_GRID:
246 case OBJECTTYPE_SUBGRID:
247 case OBJECTTYPE_DATA_AVERAGE_LINE:
248 pItemConverter = new wrapper::GraphicPropertyItemConverter(
249 xObjectProperties, rDrawModel.GetItemPool(),
250 rDrawModel, xChartModel,
251 wrapper::GraphicObjectType::LineProperties );
252 break;
254 case OBJECTTYPE_DATA_ERRORS_X:
255 case OBJECTTYPE_DATA_ERRORS_Y:
256 case OBJECTTYPE_DATA_ERRORS_Z:
257 pItemConverter = new wrapper::ErrorBarItemConverter(
258 xChartModel, xObjectProperties, rDrawModel.GetItemPool(),
259 rDrawModel, xChartModel);
260 break;
262 case OBJECTTYPE_DATA_CURVE:
263 pItemConverter = new wrapper::RegressionCurveItemConverter(
264 xObjectProperties,
265 ObjectIdentifier::getDataSeriesForCID( aObjectCID, xChartModel ),
266 rDrawModel.GetItemPool(), rDrawModel,
267 xChartModel);
268 break;
269 case OBJECTTYPE_DATA_CURVE_EQUATION:
271 std::optional<awt::Size> pRefSize;
272 if (pRefSizeProvider)
273 pRefSize.emplace(pRefSizeProvider->getPageSize());
275 pItemConverter = new wrapper::RegressionEquationItemConverter(
276 xObjectProperties, rDrawModel.GetItemPool(), rDrawModel,
277 xChartModel,
278 pRefSize);
279 break;
281 case OBJECTTYPE_DATA_STOCK_RANGE:
282 break;
283 case OBJECTTYPE_DATA_TABLE:
285 pItemConverter = new wrapper::DataTableItemConverter(
286 xObjectProperties, rDrawModel.GetItemPool(),
287 rDrawModel, xChartModel);
289 break;
290 default: //OBJECTTYPE_UNKNOWN
291 break;
294 else
296 //create itemconverter for all objects of given type
297 switch(eObjectType)
299 case OBJECTTYPE_TITLE:
300 pItemConverter = new wrapper::AllTitleItemConverter( xChartModel, rDrawModel.GetItemPool(),
301 rDrawModel, xChartModel);
302 break;
303 case OBJECTTYPE_AXIS:
305 std::optional<awt::Size> pRefSize;
306 if (pRefSizeProvider)
307 pRefSize.emplace( pRefSizeProvider->getPageSize() );
309 pItemConverter = new wrapper::AllAxisItemConverter(
310 xChartModel, rDrawModel.GetItemPool(),
311 rDrawModel, pRefSize );
313 break;
314 case OBJECTTYPE_GRID:
315 case OBJECTTYPE_SUBGRID:
316 pItemConverter = new wrapper::AllGridItemConverter( xChartModel, rDrawModel.GetItemPool(),
317 rDrawModel, xChartModel);
318 break;
319 default: //for this type it is not supported to change all elements at once
320 break;
324 return pItemConverter;
327 OUString lcl_getTitleCIDForCommand( std::string_view rDispatchCommand, const rtl::Reference<::chart::ChartModel> & xChartModel )
329 if( rDispatchCommand == "AllTitles")
330 return ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_TITLE, u"ALLELEMENTS" );
332 TitleHelper::eTitleType nTitleType( TitleHelper::MAIN_TITLE );
333 if( rDispatchCommand == "SubTitle" )
334 nTitleType = TitleHelper::SUB_TITLE;
335 else if( rDispatchCommand == "XTitle" )
336 nTitleType = TitleHelper::X_AXIS_TITLE;
337 else if( rDispatchCommand == "YTitle" )
338 nTitleType = TitleHelper::Y_AXIS_TITLE;
339 else if( rDispatchCommand == "ZTitle" )
340 nTitleType = TitleHelper::Z_AXIS_TITLE;
341 else if( rDispatchCommand == "SecondaryXTitle" )
342 nTitleType = TitleHelper::SECONDARY_X_AXIS_TITLE;
343 else if( rDispatchCommand == "SecondaryYTitle" )
344 nTitleType = TitleHelper::SECONDARY_Y_AXIS_TITLE;
346 rtl::Reference< Title > xTitle( TitleHelper::getTitle( nTitleType, xChartModel ) );
347 return ObjectIdentifier::createClassifiedIdentifierForObject( xTitle, xChartModel );
350 OUString lcl_getAxisCIDForCommand( std::string_view rDispatchCommand, const rtl::Reference<::chart::ChartModel>& xChartModel )
352 if( rDispatchCommand == "DiagramAxisAll")
353 return ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_AXIS, u"ALLELEMENTS" );
355 sal_Int32 nDimensionIndex=0;
356 bool bMainAxis=true;
357 if( rDispatchCommand == "DiagramAxisX")
359 nDimensionIndex=0; bMainAxis=true;
361 else if( rDispatchCommand == "DiagramAxisY")
363 nDimensionIndex=1; bMainAxis=true;
365 else if( rDispatchCommand == "DiagramAxisZ")
367 nDimensionIndex=2; bMainAxis=true;
369 else if( rDispatchCommand == "DiagramAxisA")
371 nDimensionIndex=0; bMainAxis=false;
373 else if( rDispatchCommand == "DiagramAxisB")
375 nDimensionIndex=1; bMainAxis=false;
378 rtl::Reference< Diagram > xDiagram = xChartModel->getFirstChartDiagram();
379 rtl::Reference< Axis > xAxis = AxisHelper::getAxis( nDimensionIndex, bMainAxis, xDiagram );
380 return ObjectIdentifier::createClassifiedIdentifierForObject( xAxis, xChartModel );
383 OUString lcl_getGridCIDForCommand( std::string_view rDispatchCommand, const rtl::Reference<::chart::ChartModel>& xChartModel )
385 rtl::Reference< Diagram > xDiagram = xChartModel->getFirstChartDiagram();
387 if( rDispatchCommand == "DiagramGridAll")
388 return ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_GRID, u"ALLELEMENTS" );
390 sal_Int32 nDimensionIndex=0;
391 bool bMainGrid=true;
393 //x and y is swapped in the commands
395 if( rDispatchCommand == "DiagramGridYMain")
397 nDimensionIndex=0; bMainGrid=true;
399 else if( rDispatchCommand == "DiagramGridXMain")
401 nDimensionIndex=1; bMainGrid=true;
403 else if( rDispatchCommand == "DiagramGridZMain")
405 nDimensionIndex=2; bMainGrid=true;
407 else if( rDispatchCommand == "DiagramGridYHelp")
409 nDimensionIndex=0; bMainGrid=false;
411 else if( rDispatchCommand == "DiagramGridXHelp")
413 nDimensionIndex=1; bMainGrid=false;
415 else if( rDispatchCommand == "DiagramGridZHelp")
417 nDimensionIndex=2; bMainGrid=false;
420 rtl::Reference< Axis > xAxis = AxisHelper::getAxis( nDimensionIndex, true/*bMainAxis*/, xDiagram );
422 sal_Int32 nSubGridIndex= bMainGrid ? -1 : 0;
423 OUString aCID( ObjectIdentifier::createClassifiedIdentifierForGrid( xAxis, xChartModel, nSubGridIndex ) );
424 return aCID;
427 OUString lcl_getErrorCIDForCommand( const ObjectType eDispatchType, const ObjectType &eSelectedType, const OUString &rSelectedCID)
429 if( eSelectedType == eDispatchType )
430 return rSelectedCID;
432 return ObjectIdentifier::createClassifiedIdentifierWithParent( eDispatchType, u"", rSelectedCID );
435 OUString lcl_getObjectCIDForCommand( std::string_view rDispatchCommand, const rtl::Reference<::chart::ChartModel> & xChartDocument, const OUString& rSelectedCID )
437 ObjectType eObjectType = OBJECTTYPE_UNKNOWN;
439 const ObjectType eSelectedType = ObjectIdentifier::getObjectType( rSelectedCID );
440 rtl::Reference< DataSeries > xSeries = ObjectIdentifier::getDataSeriesForCID( rSelectedCID, xChartDocument );
442 //legend
443 if( rDispatchCommand == "Legend" || rDispatchCommand == "FormatLegend" )
445 eObjectType = OBJECTTYPE_LEGEND;
446 //@todo set particular aParticleID if we have more than one legend
448 //wall floor area
449 else if( rDispatchCommand == "DiagramWall" || rDispatchCommand == "FormatWall" )
451 //OBJECTTYPE_DIAGRAM;
452 eObjectType = OBJECTTYPE_DIAGRAM_WALL;
453 //@todo set particular aParticleID if we have more than one diagram
455 else if( rDispatchCommand == "DiagramFloor" || rDispatchCommand == "FormatFloor" )
457 eObjectType = OBJECTTYPE_DIAGRAM_FLOOR;
458 //@todo set particular aParticleID if we have more than one diagram
460 else if( rDispatchCommand == "DiagramArea" || rDispatchCommand == "FormatChartArea" )
462 eObjectType = OBJECTTYPE_PAGE;
464 //title
465 else if( rDispatchCommand == "MainTitle"
466 || rDispatchCommand == "SubTitle"
467 || rDispatchCommand == "XTitle"
468 || rDispatchCommand == "YTitle"
469 || rDispatchCommand == "ZTitle"
470 || rDispatchCommand == "SecondaryXTitle"
471 || rDispatchCommand == "SecondaryYTitle"
472 || rDispatchCommand == "AllTitles"
475 return lcl_getTitleCIDForCommand( rDispatchCommand, xChartDocument );
477 //axis
478 else if( rDispatchCommand == "DiagramAxisX"
479 || rDispatchCommand == "DiagramAxisY"
480 || rDispatchCommand == "DiagramAxisZ"
481 || rDispatchCommand == "DiagramAxisA"
482 || rDispatchCommand == "DiagramAxisB"
483 || rDispatchCommand == "DiagramAxisAll"
486 return lcl_getAxisCIDForCommand( rDispatchCommand, xChartDocument );
488 //grid
489 else if( rDispatchCommand == "DiagramGridYMain"
490 || rDispatchCommand == "DiagramGridXMain"
491 || rDispatchCommand == "DiagramGridZMain"
492 || rDispatchCommand == "DiagramGridYHelp"
493 || rDispatchCommand == "DiagramGridXHelp"
494 || rDispatchCommand == "DiagramGridZHelp"
495 || rDispatchCommand == "DiagramGridAll"
498 return lcl_getGridCIDForCommand( rDispatchCommand, xChartDocument );
500 //data series
501 else if( rDispatchCommand == "FormatDataSeries" )
503 if( eSelectedType == OBJECTTYPE_DATA_SERIES )
504 return rSelectedCID;
505 else
506 return ObjectIdentifier::createClassifiedIdentifier(
507 OBJECTTYPE_DATA_SERIES, ObjectIdentifier::getSeriesParticleFromCID( rSelectedCID ) );
509 //data point
510 else if( rDispatchCommand == "FormatDataPoint" )
512 return rSelectedCID;
514 //data labels
515 else if( rDispatchCommand == "FormatDataLabels" )
517 if( eSelectedType == OBJECTTYPE_DATA_LABELS )
518 return rSelectedCID;
519 else
520 return ObjectIdentifier::createClassifiedIdentifierWithParent(
521 OBJECTTYPE_DATA_LABELS, u"", rSelectedCID );
523 //data labels
524 else if( rDispatchCommand == "FormatDataLabel" )
526 if( eSelectedType == OBJECTTYPE_DATA_LABEL )
527 return rSelectedCID;
528 else
530 sal_Int32 nPointIndex = o3tl::toInt32(ObjectIdentifier::getParticleID( rSelectedCID ));
531 if( nPointIndex>=0 )
533 OUString aSeriesParticle = ObjectIdentifier::getSeriesParticleFromCID( rSelectedCID );
534 OUString aChildParticle( ObjectIdentifier::getStringForType( OBJECTTYPE_DATA_LABELS ) + "=" );
535 OUString aLabelsCID = ObjectIdentifier::createClassifiedIdentifierForParticles( aSeriesParticle, aChildParticle );
536 OUString aLabelCID_Stub = ObjectIdentifier::createClassifiedIdentifierWithParent(
537 OBJECTTYPE_DATA_LABEL, u"", aLabelsCID );
539 return ObjectIdentifier::createPointCID( aLabelCID_Stub, nPointIndex );
543 //mean value line
544 else if( rDispatchCommand == "FormatMeanValue" )
546 if( eSelectedType == OBJECTTYPE_DATA_AVERAGE_LINE )
547 return rSelectedCID;
548 else
549 return ObjectIdentifier::createDataCurveCID(
550 ObjectIdentifier::getSeriesParticleFromCID( rSelectedCID ),
551 RegressionCurveHelper::getRegressionCurveIndex( xSeries,
552 RegressionCurveHelper::getMeanValueLine( xSeries ) ), true );
554 //trend line
555 else if( rDispatchCommand == "FormatTrendline" )
557 if( eSelectedType == OBJECTTYPE_DATA_CURVE )
558 return rSelectedCID;
559 else
560 return ObjectIdentifier::createDataCurveCID(
561 ObjectIdentifier::getSeriesParticleFromCID( rSelectedCID ),
562 RegressionCurveHelper::getRegressionCurveIndex( xSeries,
563 RegressionCurveHelper::getFirstCurveNotMeanValueLine( xSeries ) ), false );
565 //trend line equation
566 else if( rDispatchCommand == "FormatTrendlineEquation" )
568 if( eSelectedType == OBJECTTYPE_DATA_CURVE_EQUATION )
569 return rSelectedCID;
570 else
571 return ObjectIdentifier::createDataCurveEquationCID(
572 ObjectIdentifier::getSeriesParticleFromCID( rSelectedCID ),
573 RegressionCurveHelper::getRegressionCurveIndex( xSeries,
574 RegressionCurveHelper::getFirstCurveNotMeanValueLine( xSeries ) ) );
576 // y error bars
577 else if( rDispatchCommand == "FormatXErrorBars" )
579 return lcl_getErrorCIDForCommand(OBJECTTYPE_DATA_ERRORS_X, eSelectedType, rSelectedCID );
581 // y error bars
582 else if( rDispatchCommand == "FormatYErrorBars" )
584 return lcl_getErrorCIDForCommand(OBJECTTYPE_DATA_ERRORS_Y, eSelectedType, rSelectedCID );
586 // axis
587 else if( rDispatchCommand == "FormatAxis" )
589 if( eSelectedType == OBJECTTYPE_AXIS )
590 return rSelectedCID;
591 else
593 rtl::Reference< Axis > xAxis = ObjectIdentifier::getAxisForCID( rSelectedCID, xChartDocument );
594 return ObjectIdentifier::createClassifiedIdentifierForObject( xAxis , xChartDocument );
597 // major grid
598 else if( rDispatchCommand == "FormatMajorGrid" )
600 if( eSelectedType == OBJECTTYPE_GRID )
601 return rSelectedCID;
602 else
604 rtl::Reference< Axis > xAxis = ObjectIdentifier::getAxisForCID( rSelectedCID, xChartDocument );
605 return ObjectIdentifier::createClassifiedIdentifierForGrid( xAxis, xChartDocument );
609 // minor grid
610 else if( rDispatchCommand == "FormatMinorGrid" )
612 if( eSelectedType == OBJECTTYPE_SUBGRID )
613 return rSelectedCID;
614 else
616 rtl::Reference< Axis > xAxis = ObjectIdentifier::getAxisForCID( rSelectedCID, xChartDocument );
617 return ObjectIdentifier::createClassifiedIdentifierForGrid( xAxis, xChartDocument, 0 /*sub grid index*/ );
620 // title
621 else if( rDispatchCommand == "FormatTitle" )
623 if( eSelectedType == OBJECTTYPE_TITLE )
624 return rSelectedCID;
626 // stock loss
627 else if( rDispatchCommand == "FormatStockLoss" )
629 if( eSelectedType == OBJECTTYPE_DATA_STOCK_LOSS )
630 return rSelectedCID;
631 else
632 return ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DATA_STOCK_LOSS, u"");
634 // stock gain
635 else if( rDispatchCommand == "FormatStockGain" )
637 if( eSelectedType == OBJECTTYPE_DATA_STOCK_GAIN )
638 return rSelectedCID;
639 else
640 return ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DATA_STOCK_GAIN, u"" );
643 return ObjectIdentifier::createClassifiedIdentifier(
644 eObjectType,
645 u"" ); // aParticleID
649 // anonymous namespace
651 void ChartController::executeDispatch_FormatObject(std::u16string_view rDispatchCommand)
653 rtl::Reference<::chart::ChartModel> xChartDocument( getChartModel() );
654 OString aCommand( OUStringToOString( rDispatchCommand, RTL_TEXTENCODING_ASCII_US ) );
655 OUString rObjectCID = lcl_getObjectCIDForCommand( aCommand, xChartDocument, m_aSelection.getSelectedCID() );
656 executeDlg_ObjectProperties( rObjectCID );
659 void ChartController::executeDispatch_ObjectProperties()
661 executeDlg_ObjectProperties( m_aSelection.getSelectedCID() );
664 namespace
667 OUString lcl_getFormatCIDforSelectedCID( const OUString& rSelectedCID )
669 OUString aFormatCID(rSelectedCID);
671 //get type of selected object
672 ObjectType eObjectType = ObjectIdentifier::getObjectType( aFormatCID );
674 // some legend entries are handled as if they were data series
675 if( eObjectType==OBJECTTYPE_LEGEND_ENTRY )
677 std::u16string_view aParentParticle( ObjectIdentifier::getFullParentParticle( rSelectedCID ) );
678 aFormatCID = ObjectIdentifier::createClassifiedIdentifierForParticle( aParentParticle );
681 // treat diagram as wall
682 if( eObjectType==OBJECTTYPE_DIAGRAM )
683 aFormatCID = ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DIAGRAM_WALL, u"" );
685 return aFormatCID;
688 }//end anonymous namespace
690 void ChartController::executeDlg_ObjectProperties( const OUString& rSelectedObjectCID )
692 OUString aObjectCID = lcl_getFormatCIDforSelectedCID( rSelectedObjectCID );
694 auto xUndoGuard = std::make_shared<UndoGuard>(
695 ActionDescriptionProvider::createDescription(
696 ActionDescriptionProvider::ActionType::Format,
697 ObjectNameProvider::getName( ObjectIdentifier::getObjectType( aObjectCID ))),
698 m_xUndoManager );
700 ChartController::executeDlg_ObjectProperties_withUndoGuard(std::move(xUndoGuard), aObjectCID, false );
703 void ChartController::executeDlg_ObjectProperties_withUndoGuard(
704 std::shared_ptr<UndoGuard> xUndoGuard, const OUString& rObjectCID, bool bSuccessOnUnchanged )
706 //return true if the properties were changed successfully
707 if( rObjectCID.isEmpty() )
709 return;
713 //get type of object
714 ObjectType eObjectType = ObjectIdentifier::getObjectType( rObjectCID );
715 if( eObjectType==OBJECTTYPE_UNKNOWN )
717 return;
719 if( eObjectType==OBJECTTYPE_DIAGRAM_WALL || eObjectType==OBJECTTYPE_DIAGRAM_FLOOR )
721 if( !getFirstDiagram()->isSupportingFloorAndWall() )
722 return;
725 //convert properties to ItemSet
727 ReferenceSizeProvider aRefSizeProv(impl_createReferenceSizeProvider());
729 rtl::Reference<::chart::ChartModel> xChartDoc(getChartModel());
731 std::shared_ptr<wrapper::ItemConverter> pItemConverter(
732 createItemConverter( rObjectCID, xChartDoc, m_xCC,
733 m_pDrawModelWrapper->getSdrModel(),
734 m_xChartView.get(),
735 &aRefSizeProv));
737 if (!pItemConverter)
738 return;
740 SfxItemSet aItemSet = pItemConverter->CreateEmptyItemSet();
742 if ( eObjectType == OBJECTTYPE_DATA_ERRORS_X || eObjectType == OBJECTTYPE_DATA_ERRORS_Y )
743 aItemSet.Put(SfxBoolItem(SCHATTR_STAT_ERRORBAR_TYPE, eObjectType == OBJECTTYPE_DATA_ERRORS_Y ));
745 pItemConverter->FillItemSet(aItemSet);
747 //prepare dialog
748 ObjectPropertiesDialogParameter aDialogParameter( rObjectCID );
749 aDialogParameter.init(xChartDoc);
750 ViewElementListProvider aViewElementListProvider( m_pDrawModelWrapper.get() );
752 SolarMutexGuard aGuard;
753 std::shared_ptr<SchAttribTabDlg> aDlgPtr = std::make_shared<SchAttribTabDlg>(
754 GetChartFrame(), &aItemSet, &aDialogParameter,
755 &aViewElementListProvider,
756 xChartDoc);
758 if(aDialogParameter.HasSymbolProperties())
760 uno::Reference< beans::XPropertySet > xObjectProperties =
761 ObjectIdentifier::getObjectPropertySet( rObjectCID, xChartDoc );
762 wrapper::DataPointItemConverter aSymbolItemConverter( xChartDoc, m_xCC
763 , xObjectProperties, ObjectIdentifier::getDataSeriesForCID( rObjectCID, xChartDoc )
764 , m_pDrawModelWrapper->getSdrModel().GetItemPool()
765 , m_pDrawModelWrapper->getSdrModel()
766 , xChartDoc
767 , wrapper::GraphicObjectType::FilledDataPoint );
769 SfxItemSet aSymbolShapeProperties(aSymbolItemConverter.CreateEmptyItemSet() );
770 aSymbolItemConverter.FillItemSet( aSymbolShapeProperties );
772 sal_Int32 const nStandardSymbol=0;//@todo get from somewhere
773 std::optional<Graphic> oAutoSymbolGraphic(std::in_place, aViewElementListProvider.GetSymbolGraphic( nStandardSymbol, &aSymbolShapeProperties ) );
774 // note: the dialog takes the ownership of pSymbolShapeProperties and pAutoSymbolGraphic
775 aDlgPtr->setSymbolInformation( std::move(aSymbolShapeProperties), std::move(oAutoSymbolGraphic) );
777 if( aDialogParameter.HasStatisticProperties() )
779 aDlgPtr->SetAxisMinorStepWidthForErrorBarDecimals(
780 InsertErrorBarsDialog::getAxisMinorStepWidthForErrorBarDecimals( xChartDoc, m_xChartView, rObjectCID ) );
783 //open the dialog
784 SfxTabDialogController::runAsync(aDlgPtr, [aDlgPtr, xChartDoc, pItemConverter=std::move(pItemConverter),
785 bSuccessOnUnchanged, xUndoGuard=std::move(xUndoGuard)] (int nResult)
787 if (nResult == RET_OK || (bSuccessOnUnchanged && aDlgPtr->DialogWasClosedWithOK())) {
788 const SfxItemSet* pOutItemSet = aDlgPtr->GetOutputItemSet();
789 if(pOutItemSet) {
790 ControllerLockGuardUNO aCLGuard(xChartDoc);
791 (void)pItemConverter->ApplyItemSet(*pOutItemSet); //model should be changed now
792 xUndoGuard->commit();
797 catch( const util::CloseVetoException& )
800 catch( const uno::RuntimeException& )
805 void ChartController::executeDispatch_View3D()
809 UndoLiveUpdateGuard aUndoGuard(
810 SchResId( STR_ACTION_EDIT_3D_VIEW ),
811 m_xUndoManager );
813 //open dialog
814 SolarMutexGuard aSolarGuard;
815 View3DDialog aDlg(GetChartFrame(), getChartModel());
816 if (aDlg.run() == RET_OK)
817 aUndoGuard.commit();
819 catch(const uno::RuntimeException&)
821 TOOLS_WARN_EXCEPTION("chart2", "" );
825 } //namespace chart
827 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */