1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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>
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>
65 #include <vcl/svapp.hxx>
66 #include <svx/ActionDescriptionProvider.hxx>
67 #include <comphelper/diagnose_ex.hxx>
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
;
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");
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())
102 //create itemconverter for a single object
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
);
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
,
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
,
139 case OBJECTTYPE_LEGEND_ENTRY
:
141 case OBJECTTYPE_DIAGRAM
:
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(),
164 &aExplicitScale
, &aExplicitIncrement
,
168 case OBJECTTYPE_AXIS_UNITLABEL
:
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
);
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*/
217 nPointIndex
= o3tl::toInt32(aParticleID
);
218 bool bVaryColorsByPoint
= false;
220 // "VaryColorsByPoint"
221 (xSeries
->getFastPropertyValue(PROP_DATASERIES_VARY_COLORS_BY_POINT
) >>= 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
,
241 eMapTo
, pRefSize
, bDataSeries
, bUseSpecialFillColor
, nSpecialFillColor
, true,
242 nNumberFormat
, nPercentNumberFormat
, nPointIndex
);
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
);
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
);
262 case OBJECTTYPE_DATA_CURVE
:
263 pItemConverter
= new wrapper::RegressionCurveItemConverter(
265 ObjectIdentifier::getDataSeriesForCID( aObjectCID
, xChartModel
),
266 rDrawModel
.GetItemPool(), rDrawModel
,
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
,
281 case OBJECTTYPE_DATA_STOCK_RANGE
:
283 case OBJECTTYPE_DATA_TABLE
:
285 pItemConverter
= new wrapper::DataTableItemConverter(
286 xObjectProperties
, rDrawModel
.GetItemPool(),
287 rDrawModel
, xChartModel
);
290 default: //OBJECTTYPE_UNKNOWN
296 //create itemconverter for all objects of given type
299 case OBJECTTYPE_TITLE
:
300 pItemConverter
= new wrapper::AllTitleItemConverter( xChartModel
, rDrawModel
.GetItemPool(),
301 rDrawModel
, xChartModel
);
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
);
314 case OBJECTTYPE_GRID
:
315 case OBJECTTYPE_SUBGRID
:
316 pItemConverter
= new wrapper::AllGridItemConverter( xChartModel
, rDrawModel
.GetItemPool(),
317 rDrawModel
, xChartModel
);
319 default: //for this type it is not supported to change all elements at once
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;
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;
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
) );
427 OUString
lcl_getErrorCIDForCommand( const ObjectType eDispatchType
, const ObjectType
&eSelectedType
, const OUString
&rSelectedCID
)
429 if( eSelectedType
== eDispatchType
)
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
);
443 if( rDispatchCommand
== "Legend" || rDispatchCommand
== "FormatLegend" )
445 eObjectType
= OBJECTTYPE_LEGEND
;
446 //@todo set particular aParticleID if we have more than one legend
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
;
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
);
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
);
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
);
501 else if( rDispatchCommand
== "FormatDataSeries" )
503 if( eSelectedType
== OBJECTTYPE_DATA_SERIES
)
506 return ObjectIdentifier::createClassifiedIdentifier(
507 OBJECTTYPE_DATA_SERIES
, ObjectIdentifier::getSeriesParticleFromCID( rSelectedCID
) );
510 else if( rDispatchCommand
== "FormatDataPoint" )
515 else if( rDispatchCommand
== "FormatDataLabels" )
517 if( eSelectedType
== OBJECTTYPE_DATA_LABELS
)
520 return ObjectIdentifier::createClassifiedIdentifierWithParent(
521 OBJECTTYPE_DATA_LABELS
, u
"", rSelectedCID
);
524 else if( rDispatchCommand
== "FormatDataLabel" )
526 if( eSelectedType
== OBJECTTYPE_DATA_LABEL
)
530 sal_Int32 nPointIndex
= o3tl::toInt32(ObjectIdentifier::getParticleID( rSelectedCID
));
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
);
544 else if( rDispatchCommand
== "FormatMeanValue" )
546 if( eSelectedType
== OBJECTTYPE_DATA_AVERAGE_LINE
)
549 return ObjectIdentifier::createDataCurveCID(
550 ObjectIdentifier::getSeriesParticleFromCID( rSelectedCID
),
551 RegressionCurveHelper::getRegressionCurveIndex( xSeries
,
552 RegressionCurveHelper::getMeanValueLine( xSeries
) ), true );
555 else if( rDispatchCommand
== "FormatTrendline" )
557 if( eSelectedType
== OBJECTTYPE_DATA_CURVE
)
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
)
571 return ObjectIdentifier::createDataCurveEquationCID(
572 ObjectIdentifier::getSeriesParticleFromCID( rSelectedCID
),
573 RegressionCurveHelper::getRegressionCurveIndex( xSeries
,
574 RegressionCurveHelper::getFirstCurveNotMeanValueLine( xSeries
) ) );
577 else if( rDispatchCommand
== "FormatXErrorBars" )
579 return lcl_getErrorCIDForCommand(OBJECTTYPE_DATA_ERRORS_X
, eSelectedType
, rSelectedCID
);
582 else if( rDispatchCommand
== "FormatYErrorBars" )
584 return lcl_getErrorCIDForCommand(OBJECTTYPE_DATA_ERRORS_Y
, eSelectedType
, rSelectedCID
);
587 else if( rDispatchCommand
== "FormatAxis" )
589 if( eSelectedType
== OBJECTTYPE_AXIS
)
593 rtl::Reference
< Axis
> xAxis
= ObjectIdentifier::getAxisForCID( rSelectedCID
, xChartDocument
);
594 return ObjectIdentifier::createClassifiedIdentifierForObject( xAxis
, xChartDocument
);
598 else if( rDispatchCommand
== "FormatMajorGrid" )
600 if( eSelectedType
== OBJECTTYPE_GRID
)
604 rtl::Reference
< Axis
> xAxis
= ObjectIdentifier::getAxisForCID( rSelectedCID
, xChartDocument
);
605 return ObjectIdentifier::createClassifiedIdentifierForGrid( xAxis
, xChartDocument
);
610 else if( rDispatchCommand
== "FormatMinorGrid" )
612 if( eSelectedType
== OBJECTTYPE_SUBGRID
)
616 rtl::Reference
< Axis
> xAxis
= ObjectIdentifier::getAxisForCID( rSelectedCID
, xChartDocument
);
617 return ObjectIdentifier::createClassifiedIdentifierForGrid( xAxis
, xChartDocument
, 0 /*sub grid index*/ );
621 else if( rDispatchCommand
== "FormatTitle" )
623 if( eSelectedType
== OBJECTTYPE_TITLE
)
627 else if( rDispatchCommand
== "FormatStockLoss" )
629 if( eSelectedType
== OBJECTTYPE_DATA_STOCK_LOSS
)
632 return ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DATA_STOCK_LOSS
, u
"");
635 else if( rDispatchCommand
== "FormatStockGain" )
637 if( eSelectedType
== OBJECTTYPE_DATA_STOCK_GAIN
)
640 return ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DATA_STOCK_GAIN
, u
"" );
643 return ObjectIdentifier::createClassifiedIdentifier(
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() );
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
"" );
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
))),
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() )
714 ObjectType eObjectType
= ObjectIdentifier::getObjectType( rObjectCID
);
715 if( eObjectType
==OBJECTTYPE_UNKNOWN
)
719 if( eObjectType
==OBJECTTYPE_DIAGRAM_WALL
|| eObjectType
==OBJECTTYPE_DIAGRAM_FLOOR
)
721 if( !getFirstDiagram()->isSupportingFloorAndWall() )
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(),
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
);
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
,
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()
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
) );
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();
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
),
814 SolarMutexGuard aSolarGuard
;
815 View3DDialog
aDlg(GetChartFrame(), getChartModel());
816 if (aDlg
.run() == RET_OK
)
819 catch(const uno::RuntimeException
&)
821 TOOLS_WARN_EXCEPTION("chart2", "" );
827 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */