Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / chart2 / source / controller / main / ChartController_Properties.cxx
blobbcbe8d3039304070de918c8107d286f346b83533
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 <ChartWindow.hxx>
22 #include <chartview/DrawModelWrapper.hxx>
23 #include <ObjectIdentifier.hxx>
24 #include <chartview/ExplicitValueProvider.hxx>
25 #include <dlg_ObjectProperties.hxx>
26 #include <dlg_View3D.hxx>
27 #include <dlg_InsertErrorBars.hxx>
28 #include <ViewElementListProvider.hxx>
29 #include <DataPointItemConverter.hxx>
30 #include <TextLabelItemConverter.hxx>
31 #include <AxisItemConverter.hxx>
32 #include <MultipleChartConverters.hxx>
33 #include <TitleItemConverter.hxx>
34 #include <LegendItemConverter.hxx>
35 #include <RegressionCurveItemConverter.hxx>
36 #include <RegressionEquationItemConverter.hxx>
37 #include <ErrorBarItemConverter.hxx>
38 #include <ChartModelHelper.hxx>
39 #include <AxisHelper.hxx>
40 #include <TitleHelper.hxx>
41 #include <LegendHelper.hxx>
42 #include <ChartTypeHelper.hxx>
43 #include <ColorPerPointHelper.hxx>
44 #include <DiagramHelper.hxx>
45 #include <servicenames_charttypes.hxx>
46 #include <ControllerLockGuard.hxx>
47 #include "UndoGuard.hxx"
48 #include <ObjectNameProvider.hxx>
49 #include <ResId.hxx>
50 #include <strings.hrc>
51 #include <ReferenceSizeProvider.hxx>
52 #include <RegressionCurveHelper.hxx>
53 #include <com/sun/star/chart2/XChartDocument.hpp>
55 #include <memory>
57 #include <vcl/svapp.hxx>
58 #include <svx/ActionDescriptionProvider.hxx>
60 namespace chart
62 using namespace ::com::sun::star;
63 using namespace ::com::sun::star::chart2;
64 using ::com::sun::star::uno::Reference;
66 namespace
69 wrapper::ItemConverter* createItemConverter(
70 const OUString & aObjectCID, const uno::Reference<frame::XModel>& xChartModel,
71 const uno::Reference<uno::XComponentContext>& xContext, SdrModel& rDrawModel,
72 ExplicitValueProvider* pExplicitValueProvider, ReferenceSizeProvider const * pRefSizeProvider )
74 wrapper::ItemConverter* pItemConverter=nullptr;
76 //get type of selected object
77 ObjectType eObjectType = ObjectIdentifier::getObjectType( aObjectCID );
78 if( eObjectType==OBJECTTYPE_UNKNOWN )
80 OSL_FAIL("unknown ObjectType");
81 return nullptr;
84 OUString aParticleID = ObjectIdentifier::getParticleID( aObjectCID );
85 bool bAffectsMultipleObjects = aParticleID == "ALLELEMENTS";
86 if( !bAffectsMultipleObjects )
88 uno::Reference< beans::XPropertySet > xObjectProperties =
89 ObjectIdentifier::getObjectPropertySet( aObjectCID, xChartModel );
90 if(!xObjectProperties.is())
91 return nullptr;
92 //create itemconverter for a single object
93 switch(eObjectType)
95 case OBJECTTYPE_PAGE:
96 pItemConverter = new wrapper::GraphicPropertyItemConverter(
97 xObjectProperties, rDrawModel.GetItemPool(),
98 rDrawModel, uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ),
99 wrapper::GraphicObjectType::LineAndFillProperties );
100 break;
101 case OBJECTTYPE_TITLE:
103 std::unique_ptr<awt::Size> pRefSize;
104 if (pRefSizeProvider)
105 pRefSize.reset(new awt::Size(pRefSizeProvider->getPageSize()));
107 pItemConverter = new wrapper::TitleItemConverter(
108 xObjectProperties, rDrawModel.GetItemPool(), rDrawModel,
109 uno::Reference<lang::XMultiServiceFactory>(xChartModel, uno::UNO_QUERY),
110 pRefSize.get());
112 break;
113 case OBJECTTYPE_LEGEND:
115 std::unique_ptr<awt::Size> pRefSize;
116 if (pRefSizeProvider)
117 pRefSize.reset( new awt::Size( pRefSizeProvider->getPageSize()));
119 pItemConverter = new wrapper::LegendItemConverter(
120 xObjectProperties, rDrawModel.GetItemPool(), rDrawModel,
121 uno::Reference<lang::XMultiServiceFactory>(xChartModel, uno::UNO_QUERY),
122 pRefSize.get());
124 break;
125 case OBJECTTYPE_LEGEND_ENTRY:
126 break;
127 case OBJECTTYPE_DIAGRAM:
128 break;
129 case OBJECTTYPE_DIAGRAM_WALL:
130 case OBJECTTYPE_DIAGRAM_FLOOR:
131 pItemConverter = new wrapper::GraphicPropertyItemConverter(
132 xObjectProperties, rDrawModel.GetItemPool(),
133 rDrawModel, uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ),
134 wrapper::GraphicObjectType::LineAndFillProperties );
135 break;
136 case OBJECTTYPE_AXIS:
138 std::unique_ptr<awt::Size> pRefSize;
139 if (pRefSizeProvider)
140 pRefSize.reset( new awt::Size( pRefSizeProvider->getPageSize()));
142 uno::Reference< beans::XPropertySet > xDiaProp;
143 xDiaProp.set( ChartModelHelper::findDiagram( xChartModel ), uno::UNO_QUERY );
145 // the second property set contains the property CoordinateOrigin
146 // nOriginIndex is the index of the corresponding index of the
147 // origin (x=0, y=1, z=2)
149 ExplicitScaleData aExplicitScale;
150 ExplicitIncrementData aExplicitIncrement;
151 if( pExplicitValueProvider )
152 pExplicitValueProvider->getExplicitValuesForAxis(
153 uno::Reference< XAxis >( xObjectProperties, uno::UNO_QUERY ),
154 aExplicitScale, aExplicitIncrement );
156 pItemConverter = new wrapper::AxisItemConverter(
157 xObjectProperties, rDrawModel.GetItemPool(),
158 rDrawModel,
159 uno::Reference< chart2::XChartDocument >( xChartModel, uno::UNO_QUERY ),
160 &aExplicitScale, &aExplicitIncrement,
161 pRefSize.get() );
163 break;
164 case OBJECTTYPE_AXIS_UNITLABEL:
165 break;
166 case OBJECTTYPE_DATA_LABELS:
167 case OBJECTTYPE_DATA_LABEL:
169 std::unique_ptr<awt::Size> pRefSize;
170 if (pRefSizeProvider)
171 pRefSize.reset( new awt::Size( pRefSizeProvider->getPageSize()));
173 uno::Reference<XDataSeries> xSeries = ObjectIdentifier::getDataSeriesForCID(aObjectCID, xChartModel);
175 uno::Reference<XDiagram> xDiagram = ChartModelHelper::findDiagram(xChartModel);
177 bool bDataSeries = eObjectType == OBJECTTYPE_DATA_LABELS;
179 sal_Int32 nPointIndex = -1; /*-1 for whole series*/
180 if (!bDataSeries)
181 nPointIndex = aParticleID.toInt32();
183 sal_Int32 nNumberFormat = ExplicitValueProvider::getExplicitNumberFormatKeyForDataLabel(
184 xObjectProperties, xSeries, nPointIndex, xDiagram);
185 sal_Int32 nPercentNumberFormat = ExplicitValueProvider::getExplicitPercentageNumberFormatKeyForDataLabel(
186 xObjectProperties,uno::Reference<util::XNumberFormatsSupplier>(xChartModel, uno::UNO_QUERY));
188 pItemConverter = new wrapper::TextLabelItemConverter(
189 xChartModel, xObjectProperties, xSeries,
190 rDrawModel.GetItemPool(), pRefSize.get(), bDataSeries,
191 nNumberFormat, nPercentNumberFormat);
193 break;
194 case OBJECTTYPE_DATA_SERIES:
195 case OBJECTTYPE_DATA_POINT:
197 std::unique_ptr<awt::Size> pRefSize;
198 if (pRefSizeProvider)
199 pRefSize.reset( new awt::Size( pRefSizeProvider->getPageSize()));
201 wrapper::GraphicObjectType eMapTo =
202 wrapper::GraphicObjectType::FilledDataPoint;
204 uno::Reference< XDataSeries > xSeries = ObjectIdentifier::getDataSeriesForCID( aObjectCID, xChartModel );
205 uno::Reference< XChartType > xChartType = ChartModelHelper::getChartTypeOfSeries( xChartModel, xSeries );
207 uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) );
208 sal_Int32 nDimensionCount = DiagramHelper::getDimension( xDiagram );
209 if( !ChartTypeHelper::isSupportingAreaProperties( xChartType, nDimensionCount ) )
210 eMapTo = wrapper::GraphicObjectType::LineDataPoint;
212 bool bDataSeries = eObjectType == OBJECTTYPE_DATA_SERIES;
214 //special color for pie chart:
215 bool bUseSpecialFillColor = false;
216 sal_Int32 nSpecialFillColor =0;
217 sal_Int32 nPointIndex = -1; /*-1 for whole series*/
218 if(!bDataSeries)
220 nPointIndex = aParticleID.toInt32();
221 uno::Reference< beans::XPropertySet > xSeriesProp( xSeries, uno::UNO_QUERY );
222 bool bVaryColorsByPoint = false;
223 if( xSeriesProp.is() &&
224 (xSeriesProp->getPropertyValue("VaryColorsByPoint") >>= bVaryColorsByPoint) &&
225 bVaryColorsByPoint )
227 if( !ColorPerPointHelper::hasPointOwnColor( xSeriesProp, nPointIndex, xObjectProperties ) )
229 bUseSpecialFillColor = true;
230 OSL_ASSERT( xDiagram.is());
231 uno::Reference< XColorScheme > xColorScheme( xDiagram->getDefaultColorScheme() );
232 if( xColorScheme.is())
233 nSpecialFillColor = xColorScheme->getColorByIndex( nPointIndex );
237 sal_Int32 nNumberFormat=ExplicitValueProvider::getExplicitNumberFormatKeyForDataLabel( xObjectProperties, xSeries, nPointIndex, xDiagram );
238 sal_Int32 nPercentNumberFormat=ExplicitValueProvider::getExplicitPercentageNumberFormatKeyForDataLabel(
239 xObjectProperties,uno::Reference< util::XNumberFormatsSupplier >(xChartModel, uno::UNO_QUERY));
241 pItemConverter = new wrapper::DataPointItemConverter( xChartModel, xContext,
242 xObjectProperties, xSeries, rDrawModel.GetItemPool(), rDrawModel,
243 uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ),
244 eMapTo, pRefSize.get(), bDataSeries, bUseSpecialFillColor, nSpecialFillColor, true,
245 nNumberFormat, nPercentNumberFormat );
246 break;
248 case OBJECTTYPE_GRID:
249 case OBJECTTYPE_SUBGRID:
250 case OBJECTTYPE_DATA_AVERAGE_LINE:
251 pItemConverter = new wrapper::GraphicPropertyItemConverter(
252 xObjectProperties, rDrawModel.GetItemPool(),
253 rDrawModel, uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ),
254 wrapper::GraphicObjectType::LineProperties );
255 break;
257 case OBJECTTYPE_DATA_ERRORS_X:
258 case OBJECTTYPE_DATA_ERRORS_Y:
259 case OBJECTTYPE_DATA_ERRORS_Z:
260 pItemConverter = new wrapper::ErrorBarItemConverter(
261 xChartModel, xObjectProperties, rDrawModel.GetItemPool(),
262 rDrawModel, uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ));
263 break;
265 case OBJECTTYPE_DATA_CURVE:
266 pItemConverter = new wrapper::RegressionCurveItemConverter(
267 xObjectProperties, uno::Reference< chart2::XRegressionCurveContainer >(
268 ObjectIdentifier::getDataSeriesForCID( aObjectCID, xChartModel ), uno::UNO_QUERY ),
269 rDrawModel.GetItemPool(), rDrawModel,
270 uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ));
271 break;
272 case OBJECTTYPE_DATA_CURVE_EQUATION:
274 std::unique_ptr<awt::Size> pRefSize;
275 if (pRefSizeProvider)
276 pRefSize.reset(new awt::Size(pRefSizeProvider->getPageSize()));
278 pItemConverter = new wrapper::RegressionEquationItemConverter(
279 xObjectProperties, rDrawModel.GetItemPool(), rDrawModel,
280 uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ),
281 pRefSize.get());
282 break;
284 case OBJECTTYPE_DATA_STOCK_RANGE:
285 break;
286 case OBJECTTYPE_DATA_STOCK_LOSS:
287 case OBJECTTYPE_DATA_STOCK_GAIN:
288 pItemConverter = new wrapper::GraphicPropertyItemConverter(
289 xObjectProperties, rDrawModel.GetItemPool(),
290 rDrawModel, uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ),
291 wrapper::GraphicObjectType::LineAndFillProperties );
292 break;
293 default: //OBJECTTYPE_UNKNOWN
294 break;
297 else
299 //create itemconverter for a all objects of given type
300 switch(eObjectType)
302 case OBJECTTYPE_TITLE:
303 pItemConverter = new wrapper::AllTitleItemConverter( xChartModel, rDrawModel.GetItemPool(),
304 rDrawModel, uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ));
305 break;
306 case OBJECTTYPE_AXIS:
308 std::unique_ptr<awt::Size> pRefSize;
309 if (pRefSizeProvider)
310 pRefSize.reset( new awt::Size( pRefSizeProvider->getPageSize()));
312 pItemConverter = new wrapper::AllAxisItemConverter(
313 xChartModel, rDrawModel.GetItemPool(),
314 rDrawModel, pRefSize.get());
316 break;
317 case OBJECTTYPE_GRID:
318 case OBJECTTYPE_SUBGRID:
319 pItemConverter = new wrapper::AllGridItemConverter( xChartModel, rDrawModel.GetItemPool(),
320 rDrawModel, uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ));
321 break;
322 default: //for this type it is not supported to change all elements at once
323 break;
327 return pItemConverter;
330 OUString lcl_getTitleCIDForCommand( const OString& rDispatchCommand, const uno::Reference< frame::XModel > & xChartModel )
332 if( rDispatchCommand == "AllTitles")
333 return ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_TITLE, "ALLELEMENTS" );
335 TitleHelper::eTitleType nTitleType( TitleHelper::MAIN_TITLE );
336 if( rDispatchCommand == "SubTitle" )
337 nTitleType = TitleHelper::SUB_TITLE;
338 else if( rDispatchCommand == "XTitle" )
339 nTitleType = TitleHelper::X_AXIS_TITLE;
340 else if( rDispatchCommand == "YTitle" )
341 nTitleType = TitleHelper::Y_AXIS_TITLE;
342 else if( rDispatchCommand == "ZTitle" )
343 nTitleType = TitleHelper::Z_AXIS_TITLE;
344 else if( rDispatchCommand == "SecondaryXTitle" )
345 nTitleType = TitleHelper::SECONDARY_X_AXIS_TITLE;
346 else if( rDispatchCommand == "SecondaryYTitle" )
347 nTitleType = TitleHelper::SECONDARY_Y_AXIS_TITLE;
349 uno::Reference< XTitle > xTitle( TitleHelper::getTitle( nTitleType, xChartModel ) );
350 return ObjectIdentifier::createClassifiedIdentifierForObject( xTitle, xChartModel );
353 OUString lcl_getAxisCIDForCommand( const OString& rDispatchCommand, const uno::Reference< frame::XModel >& xChartModel )
355 if( rDispatchCommand == "DiagramAxisAll")
356 return ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_AXIS, "ALLELEMENTS" );
358 sal_Int32 nDimensionIndex=0;
359 bool bMainAxis=true;
360 if( rDispatchCommand == "DiagramAxisX")
362 nDimensionIndex=0; bMainAxis=true;
364 else if( rDispatchCommand == "DiagramAxisY")
366 nDimensionIndex=1; bMainAxis=true;
368 else if( rDispatchCommand == "DiagramAxisZ")
370 nDimensionIndex=2; bMainAxis=true;
372 else if( rDispatchCommand == "DiagramAxisA")
374 nDimensionIndex=0; bMainAxis=false;
376 else if( rDispatchCommand == "DiagramAxisB")
378 nDimensionIndex=1; bMainAxis=false;
381 uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) );
382 uno::Reference< XAxis > xAxis( AxisHelper::getAxis( nDimensionIndex, bMainAxis, xDiagram ) );
383 return ObjectIdentifier::createClassifiedIdentifierForObject( xAxis, xChartModel );
386 OUString lcl_getGridCIDForCommand( const OString& rDispatchCommand, const uno::Reference< frame::XModel >& xChartModel )
388 uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) );
390 if( rDispatchCommand == "DiagramGridAll")
391 return ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_GRID, "ALLELEMENTS" );
393 sal_Int32 nDimensionIndex=0;
394 bool bMainGrid=true;
396 //x and y is swapped in the commands
398 if( rDispatchCommand == "DiagramGridYMain")
400 nDimensionIndex=0; bMainGrid=true;
402 else if( rDispatchCommand == "DiagramGridXMain")
404 nDimensionIndex=1; bMainGrid=true;
406 else if( rDispatchCommand == "DiagramGridZMain")
408 nDimensionIndex=2; bMainGrid=true;
410 else if( rDispatchCommand == "DiagramGridYHelp")
412 nDimensionIndex=0; bMainGrid=false;
414 else if( rDispatchCommand == "DiagramGridXHelp")
416 nDimensionIndex=1; bMainGrid=false;
418 else if( rDispatchCommand == "DiagramGridZHelp")
420 nDimensionIndex=2; bMainGrid=false;
423 uno::Reference< XAxis > xAxis( AxisHelper::getAxis( nDimensionIndex, true/*bMainAxis*/, xDiagram ) );
425 sal_Int32 nSubGridIndex= bMainGrid ? -1 : 0;
426 OUString aCID( ObjectIdentifier::createClassifiedIdentifierForGrid( xAxis, xChartModel, nSubGridIndex ) );
427 return aCID;
430 OUString lcl_getErrorCIDForCommand( const ObjectType eDispatchType, const ObjectType &eSelectedType, const OUString &rSelectedCID)
432 if( eSelectedType == eDispatchType )
433 return rSelectedCID;
435 return ObjectIdentifier::createClassifiedIdentifierWithParent( eDispatchType, OUString(), rSelectedCID );
438 OUString lcl_getObjectCIDForCommand( const OString& rDispatchCommand, const uno::Reference< XChartDocument > & xChartDocument, const OUString& rSelectedCID )
440 ObjectType eObjectType = OBJECTTYPE_UNKNOWN;
442 uno::Reference< frame::XModel > xChartModel( xChartDocument, uno::UNO_QUERY );
443 const ObjectType eSelectedType = ObjectIdentifier::getObjectType( rSelectedCID );
444 uno::Reference< XDataSeries > xSeries = ObjectIdentifier::getDataSeriesForCID( rSelectedCID, xChartModel );
445 uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt( xSeries, uno::UNO_QUERY );
447 //legend
448 if( rDispatchCommand == "Legend" || rDispatchCommand == "FormatLegend" )
450 eObjectType = OBJECTTYPE_LEGEND;
451 //@todo set particular aParticleID if we have more than one legend
453 //wall floor area
454 else if( rDispatchCommand == "DiagramWall" || rDispatchCommand == "FormatWall" )
456 //OBJECTTYPE_DIAGRAM;
457 eObjectType = OBJECTTYPE_DIAGRAM_WALL;
458 //@todo set particular aParticleID if we have more than one diagram
460 else if( rDispatchCommand == "DiagramFloor" || rDispatchCommand == "FormatFloor" )
462 eObjectType = OBJECTTYPE_DIAGRAM_FLOOR;
463 //@todo set particular aParticleID if we have more than one diagram
465 else if( rDispatchCommand == "DiagramArea" || rDispatchCommand == "FormatChartArea" )
467 eObjectType = OBJECTTYPE_PAGE;
469 //title
470 else if( rDispatchCommand == "MainTitle"
471 || rDispatchCommand == "SubTitle"
472 || rDispatchCommand == "XTitle"
473 || rDispatchCommand == "YTitle"
474 || rDispatchCommand == "ZTitle"
475 || rDispatchCommand == "SecondaryXTitle"
476 || rDispatchCommand == "SecondaryYTitle"
477 || rDispatchCommand == "AllTitles"
480 return lcl_getTitleCIDForCommand( rDispatchCommand, xChartModel );
482 //axis
483 else if( rDispatchCommand == "DiagramAxisX"
484 || rDispatchCommand == "DiagramAxisY"
485 || rDispatchCommand == "DiagramAxisZ"
486 || rDispatchCommand == "DiagramAxisA"
487 || rDispatchCommand == "DiagramAxisB"
488 || rDispatchCommand == "DiagramAxisAll"
491 return lcl_getAxisCIDForCommand( rDispatchCommand, xChartModel );
493 //grid
494 else if( rDispatchCommand == "DiagramGridYMain"
495 || rDispatchCommand == "DiagramGridXMain"
496 || rDispatchCommand == "DiagramGridZMain"
497 || rDispatchCommand == "DiagramGridYHelp"
498 || rDispatchCommand == "DiagramGridXHelp"
499 || rDispatchCommand == "DiagramGridZHelp"
500 || rDispatchCommand == "DiagramGridAll"
503 return lcl_getGridCIDForCommand( rDispatchCommand, xChartModel );
505 //data series
506 else if( rDispatchCommand == "FormatDataSeries" )
508 if( eSelectedType == OBJECTTYPE_DATA_SERIES )
509 return rSelectedCID;
510 else
511 return ObjectIdentifier::createClassifiedIdentifier(
512 OBJECTTYPE_DATA_SERIES, ObjectIdentifier::getSeriesParticleFromCID( rSelectedCID ) );
514 //data point
515 else if( rDispatchCommand == "FormatDataPoint" )
517 return rSelectedCID;
519 //data labels
520 else if( rDispatchCommand == "FormatDataLabels" )
522 if( eSelectedType == OBJECTTYPE_DATA_LABELS )
523 return rSelectedCID;
524 else
525 return ObjectIdentifier::createClassifiedIdentifierWithParent(
526 OBJECTTYPE_DATA_LABELS, OUString(), rSelectedCID );
528 //data labels
529 else if( rDispatchCommand == "FormatDataLabel" )
531 if( eSelectedType == OBJECTTYPE_DATA_LABEL )
532 return rSelectedCID;
533 else
535 sal_Int32 nPointIndex = ObjectIdentifier::getParticleID( rSelectedCID ).toInt32();
536 if( nPointIndex>=0 )
538 OUString aSeriesParticle = ObjectIdentifier::getSeriesParticleFromCID( rSelectedCID );
539 OUString aChildParticle( ObjectIdentifier::getStringForType( OBJECTTYPE_DATA_LABELS ) + "=" );
540 OUString aLabelsCID = ObjectIdentifier::createClassifiedIdentifierForParticles( aSeriesParticle, aChildParticle );
541 OUString aLabelCID_Stub = ObjectIdentifier::createClassifiedIdentifierWithParent(
542 OBJECTTYPE_DATA_LABEL, OUString(), aLabelsCID );
544 return ObjectIdentifier::createPointCID( aLabelCID_Stub, nPointIndex );
548 //mean value line
549 else if( rDispatchCommand == "FormatMeanValue" )
551 if( eSelectedType == OBJECTTYPE_DATA_AVERAGE_LINE )
552 return rSelectedCID;
553 else
554 return ObjectIdentifier::createDataCurveCID(
555 ObjectIdentifier::getSeriesParticleFromCID( rSelectedCID ),
556 RegressionCurveHelper::getRegressionCurveIndex( xRegCurveCnt,
557 RegressionCurveHelper::getMeanValueLine( xRegCurveCnt ) ), true );
559 //trend line
560 else if( rDispatchCommand == "FormatTrendline" )
562 if( eSelectedType == OBJECTTYPE_DATA_CURVE )
563 return rSelectedCID;
564 else
565 return ObjectIdentifier::createDataCurveCID(
566 ObjectIdentifier::getSeriesParticleFromCID( rSelectedCID ),
567 RegressionCurveHelper::getRegressionCurveIndex( xRegCurveCnt,
568 RegressionCurveHelper::getFirstCurveNotMeanValueLine( xRegCurveCnt ) ), false );
570 //trend line equation
571 else if( rDispatchCommand == "FormatTrendlineEquation" )
573 if( eSelectedType == OBJECTTYPE_DATA_CURVE_EQUATION )
574 return rSelectedCID;
575 else
576 return ObjectIdentifier::createDataCurveEquationCID(
577 ObjectIdentifier::getSeriesParticleFromCID( rSelectedCID ),
578 RegressionCurveHelper::getRegressionCurveIndex( xRegCurveCnt,
579 RegressionCurveHelper::getFirstCurveNotMeanValueLine( xRegCurveCnt ) ) );
581 // y error bars
582 else if( rDispatchCommand == "FormatXErrorBars" )
584 return lcl_getErrorCIDForCommand(OBJECTTYPE_DATA_ERRORS_X, eSelectedType, rSelectedCID );
586 // y error bars
587 else if( rDispatchCommand == "FormatYErrorBars" )
589 return lcl_getErrorCIDForCommand(OBJECTTYPE_DATA_ERRORS_Y, eSelectedType, rSelectedCID );
591 // axis
592 else if( rDispatchCommand == "FormatAxis" )
594 if( eSelectedType == OBJECTTYPE_AXIS )
595 return rSelectedCID;
596 else
598 Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( rSelectedCID, xChartModel );
599 return ObjectIdentifier::createClassifiedIdentifierForObject( xAxis , xChartModel );
602 // major grid
603 else if( rDispatchCommand == "FormatMajorGrid" )
605 if( eSelectedType == OBJECTTYPE_GRID )
606 return rSelectedCID;
607 else
609 Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( rSelectedCID, xChartModel );
610 return ObjectIdentifier::createClassifiedIdentifierForGrid( xAxis, xChartModel );
614 // minor grid
615 else if( rDispatchCommand == "FormatMinorGrid" )
617 if( eSelectedType == OBJECTTYPE_SUBGRID )
618 return rSelectedCID;
619 else
621 Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( rSelectedCID, xChartModel );
622 return ObjectIdentifier::createClassifiedIdentifierForGrid( xAxis, xChartModel, 0 /*sub grid index*/ );
625 // title
626 else if( rDispatchCommand == "FormatTitle" )
628 if( eSelectedType == OBJECTTYPE_TITLE )
629 return rSelectedCID;
631 // stock loss
632 else if( rDispatchCommand == "FormatStockLoss" )
634 if( eSelectedType == OBJECTTYPE_DATA_STOCK_LOSS )
635 return rSelectedCID;
636 else
637 return ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DATA_STOCK_LOSS, OUString());
639 // stock gain
640 else if( rDispatchCommand == "FormatStockGain" )
642 if( eSelectedType == OBJECTTYPE_DATA_STOCK_GAIN )
643 return rSelectedCID;
644 else
645 return ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DATA_STOCK_GAIN, OUString() );
648 return ObjectIdentifier::createClassifiedIdentifier(
649 eObjectType,
650 OUString() ); // aParticleID
654 // anonymous namespace
656 void ChartController::executeDispatch_FormatObject(const OUString& rDispatchCommand)
658 uno::Reference< XChartDocument > xChartDocument( getModel(), uno::UNO_QUERY );
659 OString aCommand( OUStringToOString( rDispatchCommand, RTL_TEXTENCODING_ASCII_US ) );
660 OUString rObjectCID = lcl_getObjectCIDForCommand( aCommand, xChartDocument, m_aSelection.getSelectedCID() );
661 executeDlg_ObjectProperties( rObjectCID );
664 void ChartController::executeDispatch_ObjectProperties()
666 executeDlg_ObjectProperties( m_aSelection.getSelectedCID() );
669 namespace
672 OUString lcl_getFormatCIDforSelectedCID( const OUString& rSelectedCID )
674 OUString aFormatCID(rSelectedCID);
676 //get type of selected object
677 ObjectType eObjectType = ObjectIdentifier::getObjectType( aFormatCID );
679 // some legend entries are handled as if they were data series
680 if( eObjectType==OBJECTTYPE_LEGEND_ENTRY )
682 OUString aParentParticle( ObjectIdentifier::getFullParentParticle( rSelectedCID ) );
683 aFormatCID = ObjectIdentifier::createClassifiedIdentifierForParticle( aParentParticle );
686 // treat diagram as wall
687 if( eObjectType==OBJECTTYPE_DIAGRAM )
688 aFormatCID = ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DIAGRAM_WALL, OUString() );
690 return aFormatCID;
693 }//end anonymous namespace
695 void ChartController::executeDlg_ObjectProperties( const OUString& rSelectedObjectCID )
697 OUString aObjectCID = lcl_getFormatCIDforSelectedCID( rSelectedObjectCID );
699 UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription(
700 ActionDescriptionProvider::ActionType::Format,
701 ObjectNameProvider::getName( ObjectIdentifier::getObjectType( aObjectCID ))),
702 m_xUndoManager );
704 bool bSuccess = ChartController::executeDlg_ObjectProperties_withoutUndoGuard( aObjectCID, false );
705 if( bSuccess )
706 aUndoGuard.commit();
709 bool ChartController::executeDlg_ObjectProperties_withoutUndoGuard(
710 const OUString& rObjectCID, bool bSuccessOnUnchanged )
712 //return true if the properties were changed successfully
713 bool bRet = false;
714 if( rObjectCID.isEmpty() )
716 return bRet;
720 //get type of object
721 ObjectType eObjectType = ObjectIdentifier::getObjectType( rObjectCID );
722 if( eObjectType==OBJECTTYPE_UNKNOWN )
724 return bRet;
726 if( eObjectType==OBJECTTYPE_DIAGRAM_WALL || eObjectType==OBJECTTYPE_DIAGRAM_FLOOR )
728 if( !DiagramHelper::isSupportingFloorAndWall( ChartModelHelper::findDiagram( getModel() ) ) )
729 return bRet;
732 //convert properties to ItemSet
734 std::unique_ptr<ReferenceSizeProvider> pRefSizeProv(impl_createReferenceSizeProvider());
736 std::unique_ptr<wrapper::ItemConverter> pItemConverter(
737 createItemConverter( rObjectCID, getModel(), m_xCC,
738 m_pDrawModelWrapper->getSdrModel(),
739 ExplicitValueProvider::getExplicitValueProvider(m_xChartView),
740 pRefSizeProv.get()));
742 if (!pItemConverter)
743 return bRet;
745 SfxItemSet aItemSet = pItemConverter->CreateEmptyItemSet();
747 if ( eObjectType == OBJECTTYPE_DATA_ERRORS_X || eObjectType == OBJECTTYPE_DATA_ERRORS_Y )
748 aItemSet.Put(SfxBoolItem(SCHATTR_STAT_ERRORBAR_TYPE, eObjectType == OBJECTTYPE_DATA_ERRORS_Y ));
750 pItemConverter->FillItemSet(aItemSet);
752 //prepare dialog
753 ObjectPropertiesDialogParameter aDialogParameter = ObjectPropertiesDialogParameter( rObjectCID );
754 aDialogParameter.init( getModel() );
755 ViewElementListProvider aViewElementListProvider( m_pDrawModelWrapper.get() );
757 SolarMutexGuard aGuard;
758 ScopedVclPtrInstance<SchAttribTabDlg> aDlg(
759 GetChartWindow(), &aItemSet, &aDialogParameter,
760 &aViewElementListProvider,
761 uno::Reference< util::XNumberFormatsSupplier >(
762 getModel(), uno::UNO_QUERY ) );
764 if(aDialogParameter.HasSymbolProperties())
766 SfxItemSet* pSymbolShapeProperties=nullptr;
767 uno::Reference< beans::XPropertySet > xObjectProperties =
768 ObjectIdentifier::getObjectPropertySet( rObjectCID, getModel() );
769 wrapper::DataPointItemConverter aSymbolItemConverter( getModel(), m_xCC
770 , xObjectProperties, ObjectIdentifier::getDataSeriesForCID( rObjectCID, getModel() )
771 , m_pDrawModelWrapper->getSdrModel().GetItemPool()
772 , m_pDrawModelWrapper->getSdrModel()
773 , uno::Reference< lang::XMultiServiceFactory >( getModel(), uno::UNO_QUERY )
774 , wrapper::GraphicObjectType::FilledDataPoint );
776 pSymbolShapeProperties = new SfxItemSet( aSymbolItemConverter.CreateEmptyItemSet() );
777 aSymbolItemConverter.FillItemSet( *pSymbolShapeProperties );
779 sal_Int32 const nStandardSymbol=0;//@todo get from somewhere
780 Graphic* pAutoSymbolGraphic = new Graphic( aViewElementListProvider.GetSymbolGraphic( nStandardSymbol, pSymbolShapeProperties ) );
781 // note: the dialog takes the ownership of pSymbolShapeProperties and pAutoSymbolGraphic
782 aDlg->setSymbolInformation( pSymbolShapeProperties, pAutoSymbolGraphic );
784 if( aDialogParameter.HasStatisticProperties() )
786 aDlg->SetAxisMinorStepWidthForErrorBarDecimals(
787 InsertErrorBarsDialog::getAxisMinorStepWidthForErrorBarDecimals( getModel(), m_xChartView, rObjectCID ) );
790 //open the dialog
791 if (aDlg->Execute() == RET_OK || (bSuccessOnUnchanged && aDlg->DialogWasClosedWithOK()))
793 const SfxItemSet* pOutItemSet = aDlg->GetOutputItemSet();
794 if(pOutItemSet)
796 ControllerLockGuardUNO aCLGuard( getModel());
797 (void)pItemConverter->ApplyItemSet(*pOutItemSet); //model should be changed now
798 bRet = true;
802 catch( const util::CloseVetoException& )
805 catch( const uno::RuntimeException& )
808 return bRet;
811 void ChartController::executeDispatch_View3D()
815 UndoLiveUpdateGuard aUndoGuard(
816 SchResId( STR_ACTION_EDIT_3D_VIEW ),
817 m_xUndoManager );
819 //open dialog
820 SolarMutexGuard aSolarGuard;
821 ScopedVclPtrInstance< View3DDialog > aDlg(GetChartWindow(), getModel());
822 if( aDlg->Execute() == RET_OK )
823 aUndoGuard.commit();
825 catch(const uno::RuntimeException& e)
827 SAL_WARN("chart2", "Exception caught. " << e );
831 } //namespace chart
833 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */