LibreOffice Module chart2 (master) 1
ChartController_Properties.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <ChartController.hxx>
21#include <ChartView.hxx>
24#include <ObjectIdentifier.hxx>
28#include <dlg_View3D.hxx>
33#include <AxisItemConverter.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>
49#include <DataSeries.hxx>
51#include <DiagramHelper.hxx>
52#include <Diagram.hxx>
54#include "UndoGuard.hxx"
56#include <ResId.hxx>
57#include <strings.hrc>
61#include <com/sun/star/util/CloseVetoException.hpp>
63#include <o3tl/string_view.hxx>
64
65#include <memory>
66
67#include <vcl/svapp.hxx>
70
71namespace chart
72{
73using namespace ::com::sun::star;
74using namespace ::com::sun::star::chart2;
75using namespace ::chart::DataSeriesProperties;
76using ::com::sun::star::uno::Reference;
77
78namespace
79{
80
81wrapper::ItemConverter* createItemConverter(
82 std::u16string_view aObjectCID, const rtl::Reference<::chart::ChartModel>& xChartModel,
83 const uno::Reference<uno::XComponentContext>& xContext, SdrModel& rDrawModel,
84 ExplicitValueProvider* pExplicitValueProvider, ReferenceSizeProvider const * pRefSizeProvider )
85{
86 wrapper::ItemConverter* pItemConverter=nullptr;
87
88 //get type of selected object
89 ObjectType eObjectType = ObjectIdentifier::getObjectType( aObjectCID );
90 if( eObjectType==OBJECTTYPE_UNKNOWN )
91 {
92 OSL_FAIL("unknown ObjectType");
93 return nullptr;
94 }
95
96 std::u16string_view aParticleID = ObjectIdentifier::getParticleID( aObjectCID );
97 bool bAffectsMultipleObjects = aParticleID == u"ALLELEMENTS";
98 if( !bAffectsMultipleObjects )
99 {
100 uno::Reference< beans::XPropertySet > xObjectProperties =
101 ObjectIdentifier::getObjectPropertySet( aObjectCID, xChartModel );
102 if(!xObjectProperties.is())
103 return nullptr;
104 //create itemconverter for a single object
105 switch(eObjectType)
106 {
107 case OBJECTTYPE_PAGE:
108 pItemConverter = new wrapper::GraphicPropertyItemConverter(
109 xObjectProperties, rDrawModel.GetItemPool(),
110 rDrawModel, xChartModel,
112 break;
113 case OBJECTTYPE_TITLE:
114 {
115 std::unique_ptr<awt::Size> pRefSize;
116 if (pRefSizeProvider)
117 pRefSize.reset(new awt::Size(pRefSizeProvider->getPageSize()));
118
119 pItemConverter = new wrapper::TitleItemConverter(
120 xObjectProperties, rDrawModel.GetItemPool(), rDrawModel,
121 xChartModel,
122 pRefSize.get());
123 }
124 break;
126 {
127 std::unique_ptr<awt::Size> pRefSize;
128 if (pRefSizeProvider)
129 pRefSize.reset( new awt::Size( pRefSizeProvider->getPageSize()));
130
131 pItemConverter = new wrapper::LegendItemConverter(
132 xObjectProperties, rDrawModel.GetItemPool(), rDrawModel,
133 xChartModel,
134 pRefSize.get());
135 }
136 break;
138 break;
140 break;
143 pItemConverter = new wrapper::GraphicPropertyItemConverter(
144 xObjectProperties, rDrawModel.GetItemPool(),
145 rDrawModel, xChartModel,
147 break;
148 case OBJECTTYPE_AXIS:
149 {
150 std::unique_ptr<awt::Size> pRefSize;
151 if (pRefSizeProvider)
152 pRefSize.reset( new awt::Size( pRefSizeProvider->getPageSize()));
153
154 // the second property set contains the property CoordinateOrigin
155 // nOriginIndex is the index of the corresponding index of the
156 // origin (x=0, y=1, z=2)
157
158 ExplicitScaleData aExplicitScale;
159 ExplicitIncrementData aExplicitIncrement;
160 if( pExplicitValueProvider )
161 pExplicitValueProvider->getExplicitValuesForAxis(
162 dynamic_cast< Axis* >( xObjectProperties.get() ),
163 aExplicitScale, aExplicitIncrement );
164
165 pItemConverter = new wrapper::AxisItemConverter(
166 xObjectProperties, rDrawModel.GetItemPool(),
167 rDrawModel,
168 xChartModel,
169 &aExplicitScale, &aExplicitIncrement,
170 pRefSize.get() );
171 }
172 break;
174 break;
177 {
178 std::unique_ptr<awt::Size> pRefSize;
179 if (pRefSizeProvider)
180 pRefSize.reset( new awt::Size( pRefSizeProvider->getPageSize()));
181
182 rtl::Reference<DataSeries> xSeries = ObjectIdentifier::getDataSeriesForCID(aObjectCID, xChartModel);
183
184 bool bDataSeries = eObjectType == OBJECTTYPE_DATA_LABELS;
185
186 sal_Int32 nNumberFormat = ExplicitValueProvider::getExplicitNumberFormatKeyForDataLabel( xObjectProperties );
187 sal_Int32 nPercentNumberFormat = ExplicitValueProvider::getExplicitPercentageNumberFormatKeyForDataLabel(
188 xObjectProperties, xChartModel);
189
190 pItemConverter = new wrapper::TextLabelItemConverter(
191 xChartModel, xObjectProperties, xSeries,
192 rDrawModel.GetItemPool(), pRefSize.get(), bDataSeries,
193 nNumberFormat, nPercentNumberFormat);
194 }
195 break;
198 {
199 std::unique_ptr<awt::Size> pRefSize;
200 if (pRefSizeProvider)
201 pRefSize.reset( new awt::Size( pRefSizeProvider->getPageSize()));
202
205
206 rtl::Reference< DataSeries > xSeries = ObjectIdentifier::getDataSeriesForCID( aObjectCID, xChartModel );
207 rtl::Reference< ChartType > xChartType = ChartModelHelper::getChartTypeOfSeries( xChartModel, xSeries );
208
209 rtl::Reference< Diagram > xDiagram = xChartModel->getFirstChartDiagram();
210 sal_Int32 nDimensionCount = xDiagram->getDimension();
211 if( !ChartTypeHelper::isSupportingAreaProperties( xChartType, nDimensionCount ) )
213
214 bool bDataSeries = eObjectType == OBJECTTYPE_DATA_SERIES;
215
216 //special color for pie chart:
217 bool bUseSpecialFillColor = false;
218 sal_Int32 nSpecialFillColor =0;
219 sal_Int32 nPointIndex = -1; /*-1 for whole series*/
220 if(!bDataSeries)
221 {
222 nPointIndex = o3tl::toInt32(aParticleID);
223 bool bVaryColorsByPoint = false;
224 if( xSeries.is() &&
225 // "VaryColorsByPoint"
226 (xSeries->getFastPropertyValue(PROP_DATASERIES_VARY_COLORS_BY_POINT) >>= bVaryColorsByPoint) &&
227 bVaryColorsByPoint )
228 {
229 if( !ColorPerPointHelper::hasPointOwnColor( xSeries, nPointIndex, xObjectProperties ) )
230 {
231 bUseSpecialFillColor = true;
232 OSL_ASSERT( xDiagram.is());
233 uno::Reference< XColorScheme > xColorScheme( xDiagram->getDefaultColorScheme() );
234 if( xColorScheme.is())
235 nSpecialFillColor = xColorScheme->getColorByIndex( nPointIndex );
236 }
237 }
238 }
239 sal_Int32 nNumberFormat=ExplicitValueProvider::getExplicitNumberFormatKeyForDataLabel( xObjectProperties );
240 sal_Int32 nPercentNumberFormat=ExplicitValueProvider::getExplicitPercentageNumberFormatKeyForDataLabel(
241 xObjectProperties, xChartModel);
242
243 pItemConverter = new wrapper::DataPointItemConverter( xChartModel, xContext,
244 xObjectProperties, xSeries, rDrawModel.GetItemPool(), rDrawModel,
245 xChartModel,
246 eMapTo, pRefSize.get(), bDataSeries, bUseSpecialFillColor, nSpecialFillColor, true,
247 nNumberFormat, nPercentNumberFormat, nPointIndex );
248 break;
249 }
250 case OBJECTTYPE_GRID:
253 pItemConverter = new wrapper::GraphicPropertyItemConverter(
254 xObjectProperties, rDrawModel.GetItemPool(),
255 rDrawModel, xChartModel,
257 break;
258
262 pItemConverter = new wrapper::ErrorBarItemConverter(
263 xChartModel, xObjectProperties, rDrawModel.GetItemPool(),
264 rDrawModel, xChartModel);
265 break;
266
268 pItemConverter = new wrapper::RegressionCurveItemConverter(
269 xObjectProperties,
270 ObjectIdentifier::getDataSeriesForCID( aObjectCID, xChartModel ),
271 rDrawModel.GetItemPool(), rDrawModel,
272 xChartModel);
273 break;
275 {
276 std::unique_ptr<awt::Size> pRefSize;
277 if (pRefSizeProvider)
278 pRefSize.reset(new awt::Size(pRefSizeProvider->getPageSize()));
279
280 pItemConverter = new wrapper::RegressionEquationItemConverter(
281 xObjectProperties, rDrawModel.GetItemPool(), rDrawModel,
282 xChartModel,
283 pRefSize.get());
284 break;
285 }
287 break;
290 pItemConverter = new wrapper::GraphicPropertyItemConverter(
291 xObjectProperties, rDrawModel.GetItemPool(),
292 rDrawModel, xChartModel,
294 break;
296 {
297 pItemConverter = new wrapper::DataTableItemConverter(
298 xObjectProperties, rDrawModel.GetItemPool(),
299 rDrawModel, xChartModel);
300 }
301 break;
302 default: //OBJECTTYPE_UNKNOWN
303 break;
304 }
305 }
306 else
307 {
308 //create itemconverter for all objects of given type
309 switch(eObjectType)
310 {
311 case OBJECTTYPE_TITLE:
312 pItemConverter = new wrapper::AllTitleItemConverter( xChartModel, rDrawModel.GetItemPool(),
313 rDrawModel, xChartModel);
314 break;
315 case OBJECTTYPE_AXIS:
316 {
317 std::unique_ptr<awt::Size> pRefSize;
318 if (pRefSizeProvider)
319 pRefSize.reset( new awt::Size( pRefSizeProvider->getPageSize()));
320
321 pItemConverter = new wrapper::AllAxisItemConverter(
322 xChartModel, rDrawModel.GetItemPool(),
323 rDrawModel, pRefSize.get());
324 }
325 break;
326 case OBJECTTYPE_GRID:
328 pItemConverter = new wrapper::AllGridItemConverter( xChartModel, rDrawModel.GetItemPool(),
329 rDrawModel, xChartModel);
330 break;
331 default: //for this type it is not supported to change all elements at once
332 break;
333 }
334
335 }
336 return pItemConverter;
337}
338
339OUString lcl_getTitleCIDForCommand( std::string_view rDispatchCommand, const rtl::Reference<::chart::ChartModel> & xChartModel )
340{
341 if( rDispatchCommand == "AllTitles")
343
345 if( rDispatchCommand == "SubTitle" )
346 nTitleType = TitleHelper::SUB_TITLE;
347 else if( rDispatchCommand == "XTitle" )
348 nTitleType = TitleHelper::X_AXIS_TITLE;
349 else if( rDispatchCommand == "YTitle" )
350 nTitleType = TitleHelper::Y_AXIS_TITLE;
351 else if( rDispatchCommand == "ZTitle" )
352 nTitleType = TitleHelper::Z_AXIS_TITLE;
353 else if( rDispatchCommand == "SecondaryXTitle" )
355 else if( rDispatchCommand == "SecondaryYTitle" )
357
358 rtl::Reference< Title > xTitle( TitleHelper::getTitle( nTitleType, xChartModel ) );
359 return ObjectIdentifier::createClassifiedIdentifierForObject( xTitle, xChartModel );
360}
361
362OUString lcl_getAxisCIDForCommand( std::string_view rDispatchCommand, const rtl::Reference<::chart::ChartModel>& xChartModel )
363{
364 if( rDispatchCommand == "DiagramAxisAll")
366
367 sal_Int32 nDimensionIndex=0;
368 bool bMainAxis=true;
369 if( rDispatchCommand == "DiagramAxisX")
370 {
371 nDimensionIndex=0; bMainAxis=true;
372 }
373 else if( rDispatchCommand == "DiagramAxisY")
374 {
375 nDimensionIndex=1; bMainAxis=true;
376 }
377 else if( rDispatchCommand == "DiagramAxisZ")
378 {
379 nDimensionIndex=2; bMainAxis=true;
380 }
381 else if( rDispatchCommand == "DiagramAxisA")
382 {
383 nDimensionIndex=0; bMainAxis=false;
384 }
385 else if( rDispatchCommand == "DiagramAxisB")
386 {
387 nDimensionIndex=1; bMainAxis=false;
388 }
389
390 rtl::Reference< Diagram > xDiagram = xChartModel->getFirstChartDiagram();
391 rtl::Reference< Axis > xAxis = AxisHelper::getAxis( nDimensionIndex, bMainAxis, xDiagram );
393}
394
395OUString lcl_getGridCIDForCommand( std::string_view rDispatchCommand, const rtl::Reference<::chart::ChartModel>& xChartModel )
396{
397 rtl::Reference< Diagram > xDiagram = xChartModel->getFirstChartDiagram();
398
399 if( rDispatchCommand == "DiagramGridAll")
401
402 sal_Int32 nDimensionIndex=0;
403 bool bMainGrid=true;
404
405 //x and y is swapped in the commands
406
407 if( rDispatchCommand == "DiagramGridYMain")
408 {
409 nDimensionIndex=0; bMainGrid=true;
410 }
411 else if( rDispatchCommand == "DiagramGridXMain")
412 {
413 nDimensionIndex=1; bMainGrid=true;
414 }
415 else if( rDispatchCommand == "DiagramGridZMain")
416 {
417 nDimensionIndex=2; bMainGrid=true;
418 }
419 else if( rDispatchCommand == "DiagramGridYHelp")
420 {
421 nDimensionIndex=0; bMainGrid=false;
422 }
423 else if( rDispatchCommand == "DiagramGridXHelp")
424 {
425 nDimensionIndex=1; bMainGrid=false;
426 }
427 else if( rDispatchCommand == "DiagramGridZHelp")
428 {
429 nDimensionIndex=2; bMainGrid=false;
430 }
431
432 rtl::Reference< Axis > xAxis = AxisHelper::getAxis( nDimensionIndex, true/*bMainAxis*/, xDiagram );
433
434 sal_Int32 nSubGridIndex= bMainGrid ? -1 : 0;
435 OUString aCID( ObjectIdentifier::createClassifiedIdentifierForGrid( xAxis, xChartModel, nSubGridIndex ) );
436 return aCID;
437}
438
439OUString lcl_getErrorCIDForCommand( const ObjectType eDispatchType, const ObjectType &eSelectedType, const OUString &rSelectedCID)
440{
441 if( eSelectedType == eDispatchType )
442 return rSelectedCID;
443
444 return ObjectIdentifier::createClassifiedIdentifierWithParent( eDispatchType, u"", rSelectedCID );
445}
446
447OUString lcl_getObjectCIDForCommand( std::string_view rDispatchCommand, const rtl::Reference<::chart::ChartModel> & xChartDocument, const OUString& rSelectedCID )
448{
449 ObjectType eObjectType = OBJECTTYPE_UNKNOWN;
450
451 const ObjectType eSelectedType = ObjectIdentifier::getObjectType( rSelectedCID );
452 rtl::Reference< DataSeries > xSeries = ObjectIdentifier::getDataSeriesForCID( rSelectedCID, xChartDocument );
453
454 //legend
455 if( rDispatchCommand == "Legend" || rDispatchCommand == "FormatLegend" )
456 {
457 eObjectType = OBJECTTYPE_LEGEND;
458 //@todo set particular aParticleID if we have more than one legend
459 }
460 //wall floor area
461 else if( rDispatchCommand == "DiagramWall" || rDispatchCommand == "FormatWall" )
462 {
463 //OBJECTTYPE_DIAGRAM;
464 eObjectType = OBJECTTYPE_DIAGRAM_WALL;
465 //@todo set particular aParticleID if we have more than one diagram
466 }
467 else if( rDispatchCommand == "DiagramFloor" || rDispatchCommand == "FormatFloor" )
468 {
469 eObjectType = OBJECTTYPE_DIAGRAM_FLOOR;
470 //@todo set particular aParticleID if we have more than one diagram
471 }
472 else if( rDispatchCommand == "DiagramArea" || rDispatchCommand == "FormatChartArea" )
473 {
474 eObjectType = OBJECTTYPE_PAGE;
475 }
476 //title
477 else if( rDispatchCommand == "MainTitle"
478 || rDispatchCommand == "SubTitle"
479 || rDispatchCommand == "XTitle"
480 || rDispatchCommand == "YTitle"
481 || rDispatchCommand == "ZTitle"
482 || rDispatchCommand == "SecondaryXTitle"
483 || rDispatchCommand == "SecondaryYTitle"
484 || rDispatchCommand == "AllTitles"
485 )
486 {
487 return lcl_getTitleCIDForCommand( rDispatchCommand, xChartDocument );
488 }
489 //axis
490 else if( rDispatchCommand == "DiagramAxisX"
491 || rDispatchCommand == "DiagramAxisY"
492 || rDispatchCommand == "DiagramAxisZ"
493 || rDispatchCommand == "DiagramAxisA"
494 || rDispatchCommand == "DiagramAxisB"
495 || rDispatchCommand == "DiagramAxisAll"
496 )
497 {
498 return lcl_getAxisCIDForCommand( rDispatchCommand, xChartDocument );
499 }
500 //grid
501 else if( rDispatchCommand == "DiagramGridYMain"
502 || rDispatchCommand == "DiagramGridXMain"
503 || rDispatchCommand == "DiagramGridZMain"
504 || rDispatchCommand == "DiagramGridYHelp"
505 || rDispatchCommand == "DiagramGridXHelp"
506 || rDispatchCommand == "DiagramGridZHelp"
507 || rDispatchCommand == "DiagramGridAll"
508 )
509 {
510 return lcl_getGridCIDForCommand( rDispatchCommand, xChartDocument );
511 }
512 //data series
513 else if( rDispatchCommand == "FormatDataSeries" )
514 {
515 if( eSelectedType == OBJECTTYPE_DATA_SERIES )
516 return rSelectedCID;
517 else
520 }
521 //data point
522 else if( rDispatchCommand == "FormatDataPoint" )
523 {
524 return rSelectedCID;
525 }
526 //data labels
527 else if( rDispatchCommand == "FormatDataLabels" )
528 {
529 if( eSelectedType == OBJECTTYPE_DATA_LABELS )
530 return rSelectedCID;
531 else
533 OBJECTTYPE_DATA_LABELS, u"", rSelectedCID );
534 }
535 //data labels
536 else if( rDispatchCommand == "FormatDataLabel" )
537 {
538 if( eSelectedType == OBJECTTYPE_DATA_LABEL )
539 return rSelectedCID;
540 else
541 {
542 sal_Int32 nPointIndex = o3tl::toInt32(ObjectIdentifier::getParticleID( rSelectedCID ));
543 if( nPointIndex>=0 )
544 {
545 OUString aSeriesParticle = ObjectIdentifier::getSeriesParticleFromCID( rSelectedCID );
546 OUString aChildParticle( ObjectIdentifier::getStringForType( OBJECTTYPE_DATA_LABELS ) + "=" );
547 OUString aLabelsCID = ObjectIdentifier::createClassifiedIdentifierForParticles( aSeriesParticle, aChildParticle );
549 OBJECTTYPE_DATA_LABEL, u"", aLabelsCID );
550
551 return ObjectIdentifier::createPointCID( aLabelCID_Stub, nPointIndex );
552 }
553 }
554 }
555 //mean value line
556 else if( rDispatchCommand == "FormatMeanValue" )
557 {
558 if( eSelectedType == OBJECTTYPE_DATA_AVERAGE_LINE )
559 return rSelectedCID;
560 else
564 RegressionCurveHelper::getMeanValueLine( xSeries ) ), true );
565 }
566 //trend line
567 else if( rDispatchCommand == "FormatTrendline" )
568 {
569 if( eSelectedType == OBJECTTYPE_DATA_CURVE )
570 return rSelectedCID;
571 else
576 }
577 //trend line equation
578 else if( rDispatchCommand == "FormatTrendlineEquation" )
579 {
580 if( eSelectedType == OBJECTTYPE_DATA_CURVE_EQUATION )
581 return rSelectedCID;
582 else
587 }
588 // y error bars
589 else if( rDispatchCommand == "FormatXErrorBars" )
590 {
591 return lcl_getErrorCIDForCommand(OBJECTTYPE_DATA_ERRORS_X, eSelectedType, rSelectedCID );
592 }
593 // y error bars
594 else if( rDispatchCommand == "FormatYErrorBars" )
595 {
596 return lcl_getErrorCIDForCommand(OBJECTTYPE_DATA_ERRORS_Y, eSelectedType, rSelectedCID );
597 }
598 // axis
599 else if( rDispatchCommand == "FormatAxis" )
600 {
601 if( eSelectedType == OBJECTTYPE_AXIS )
602 return rSelectedCID;
603 else
604 {
605 rtl::Reference< Axis > xAxis = ObjectIdentifier::getAxisForCID( rSelectedCID, xChartDocument );
606 return ObjectIdentifier::createClassifiedIdentifierForObject( xAxis , xChartDocument );
607 }
608 }
609 // major grid
610 else if( rDispatchCommand == "FormatMajorGrid" )
611 {
612 if( eSelectedType == OBJECTTYPE_GRID )
613 return rSelectedCID;
614 else
615 {
616 rtl::Reference< Axis > xAxis = ObjectIdentifier::getAxisForCID( rSelectedCID, xChartDocument );
617 return ObjectIdentifier::createClassifiedIdentifierForGrid( xAxis, xChartDocument );
618 }
619
620 }
621 // minor grid
622 else if( rDispatchCommand == "FormatMinorGrid" )
623 {
624 if( eSelectedType == OBJECTTYPE_SUBGRID )
625 return rSelectedCID;
626 else
627 {
628 rtl::Reference< Axis > xAxis = ObjectIdentifier::getAxisForCID( rSelectedCID, xChartDocument );
629 return ObjectIdentifier::createClassifiedIdentifierForGrid( xAxis, xChartDocument, 0 /*sub grid index*/ );
630 }
631 }
632 // title
633 else if( rDispatchCommand == "FormatTitle" )
634 {
635 if( eSelectedType == OBJECTTYPE_TITLE )
636 return rSelectedCID;
637 }
638 // stock loss
639 else if( rDispatchCommand == "FormatStockLoss" )
640 {
641 if( eSelectedType == OBJECTTYPE_DATA_STOCK_LOSS )
642 return rSelectedCID;
643 else
645 }
646 // stock gain
647 else if( rDispatchCommand == "FormatStockGain" )
648 {
649 if( eSelectedType == OBJECTTYPE_DATA_STOCK_GAIN )
650 return rSelectedCID;
651 else
653 }
654
656 eObjectType,
657 u"" ); // aParticleID
658}
659
660}
661// anonymous namespace
662
663void ChartController::executeDispatch_FormatObject(std::u16string_view rDispatchCommand)
664{
666 OString aCommand( OUStringToOString( rDispatchCommand, RTL_TEXTENCODING_ASCII_US ) );
667 OUString rObjectCID = lcl_getObjectCIDForCommand( aCommand, xChartDocument, m_aSelection.getSelectedCID() );
668 executeDlg_ObjectProperties( rObjectCID );
669}
670
672{
674}
675
676namespace
677{
678
679OUString lcl_getFormatCIDforSelectedCID( const OUString& rSelectedCID )
680{
681 OUString aFormatCID(rSelectedCID);
682
683 //get type of selected object
684 ObjectType eObjectType = ObjectIdentifier::getObjectType( aFormatCID );
685
686 // some legend entries are handled as if they were data series
687 if( eObjectType==OBJECTTYPE_LEGEND_ENTRY )
688 {
689 std::u16string_view aParentParticle( ObjectIdentifier::getFullParentParticle( rSelectedCID ) );
690 aFormatCID = ObjectIdentifier::createClassifiedIdentifierForParticle( aParentParticle );
691 }
692
693 // treat diagram as wall
694 if( eObjectType==OBJECTTYPE_DIAGRAM )
696
697 return aFormatCID;
698}
699
700}//end anonymous namespace
701
702void ChartController::executeDlg_ObjectProperties( const OUString& rSelectedObjectCID )
703{
704 OUString aObjectCID = lcl_getFormatCIDforSelectedCID( rSelectedObjectCID );
705
710
711 bool bSuccess = ChartController::executeDlg_ObjectProperties_withoutUndoGuard( aObjectCID, false );
712 if( bSuccess )
713 aUndoGuard.commit();
714}
715
717 const OUString& rObjectCID, bool bSuccessOnUnchanged )
718{
719 //return true if the properties were changed successfully
720 bool bRet = false;
721 if( rObjectCID.isEmpty() )
722 {
723 return bRet;
724 }
725 try
726 {
727 //get type of object
728 ObjectType eObjectType = ObjectIdentifier::getObjectType( rObjectCID );
729 if( eObjectType==OBJECTTYPE_UNKNOWN )
730 {
731 return bRet;
732 }
733 if( eObjectType==OBJECTTYPE_DIAGRAM_WALL || eObjectType==OBJECTTYPE_DIAGRAM_FLOOR )
734 {
735 if( !getFirstDiagram()->isSupportingFloorAndWall() )
736 return bRet;
737 }
738
739 //convert properties to ItemSet
740
741 std::unique_ptr<ReferenceSizeProvider> pRefSizeProv(impl_createReferenceSizeProvider());
742
743 std::unique_ptr<wrapper::ItemConverter> pItemConverter(
744 createItemConverter( rObjectCID, getChartModel(), m_xCC,
745 m_pDrawModelWrapper->getSdrModel(),
746 m_xChartView.get(),
747 pRefSizeProv.get()));
748
749 if (!pItemConverter)
750 return bRet;
751
752 SfxItemSet aItemSet = pItemConverter->CreateEmptyItemSet();
753
754 if ( eObjectType == OBJECTTYPE_DATA_ERRORS_X || eObjectType == OBJECTTYPE_DATA_ERRORS_Y )
756
757 pItemConverter->FillItemSet(aItemSet);
758
759 //prepare dialog
760 ObjectPropertiesDialogParameter aDialogParameter( rObjectCID );
761 aDialogParameter.init( getChartModel() );
762 ViewElementListProvider aViewElementListProvider( m_pDrawModelWrapper.get() );
763
764 SolarMutexGuard aGuard;
765 SchAttribTabDlg aDlg(
766 GetChartFrame(), &aItemSet, &aDialogParameter,
767 &aViewElementListProvider,
768 getChartModel() );
769
770 if(aDialogParameter.HasSymbolProperties())
771 {
772 uno::Reference< beans::XPropertySet > xObjectProperties =
775 , xObjectProperties, ObjectIdentifier::getDataSeriesForCID( rObjectCID, getChartModel() )
776 , m_pDrawModelWrapper->getSdrModel().GetItemPool()
777 , m_pDrawModelWrapper->getSdrModel()
778 , getChartModel()
780
781 SfxItemSet aSymbolShapeProperties(aSymbolItemConverter.CreateEmptyItemSet() );
782 aSymbolItemConverter.FillItemSet( aSymbolShapeProperties );
783
784 sal_Int32 const nStandardSymbol=0;//@todo get from somewhere
785 std::optional<Graphic> oAutoSymbolGraphic(std::in_place, aViewElementListProvider.GetSymbolGraphic( nStandardSymbol, &aSymbolShapeProperties ) );
786 // note: the dialog takes the ownership of pSymbolShapeProperties and pAutoSymbolGraphic
787 aDlg.setSymbolInformation( std::move(aSymbolShapeProperties), std::move(oAutoSymbolGraphic) );
788 }
789 if( aDialogParameter.HasStatisticProperties() )
790 {
793 }
794
795 //open the dialog
796 if (aDlg.run() == RET_OK || (bSuccessOnUnchanged && aDlg.DialogWasClosedWithOK()))
797 {
798 const SfxItemSet* pOutItemSet = aDlg.GetOutputItemSet();
799 if(pOutItemSet)
800 {
802 (void)pItemConverter->ApplyItemSet(*pOutItemSet); //model should be changed now
803 bRet = true;
804 }
805 }
806 }
807 catch( const util::CloseVetoException& )
808 {
809 }
810 catch( const uno::RuntimeException& )
811 {
812 }
813 return bRet;
814}
815
817{
818 try
819 {
820 UndoLiveUpdateGuard aUndoGuard(
821 SchResId( STR_ACTION_EDIT_3D_VIEW ),
823
824 //open dialog
825 SolarMutexGuard aSolarGuard;
827 if (aDlg.run() == RET_OK)
828 aUndoGuard.commit();
829 }
830 catch(const uno::RuntimeException&)
831 {
832 TOOLS_WARN_EXCEPTION("chart2", "" );
833 }
834}
835
836} //namespace chart
837
838/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr TypedWhichId< SfxBoolItem > SCHATTR_STAT_ERRORBAR_TYPE(SCHATTR_STAT_START+9)
static OUString createDescription(ActionType eActionType, std::u16string_view rObjectName)
const SfxItemPool & GetItemPool() const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
virtual short run() override
const SfxItemSet * GetOutputItemSet() const
static rtl::Reference< ::chart::Axis > getAxis(sal_Int32 nDimensionIndex, bool bMainAxis, const rtl::Reference< ::chart::Diagram > &xDiagram)
rtl::Reference<::chart::ChartModel > getChartModel()
css::uno::Reference< css::document::XUndoManager > m_xUndoManager
void executeDlg_ObjectProperties(const OUString &rObjectCID)
std::unique_ptr< ReferenceSizeProvider > impl_createReferenceSizeProvider()
std::shared_ptr< DrawModelWrapper > m_pDrawModelWrapper
rtl::Reference<::chart::ChartView > m_xChartView
weld::Window * GetChartFrame()
bool executeDlg_ObjectProperties_withoutUndoGuard(const OUString &rObjectCID, bool bSuccessOnUnchanged)
rtl::Reference<::chart::Diagram > getFirstDiagram()
void executeDispatch_FormatObject(std::u16string_view rDispatchCommand)
css::uno::Reference< css::uno::XComponentContext > m_xCC
static rtl::Reference< ChartType > getChartTypeOfSeries(const rtl::Reference<::chart::ChartModel > &xModel, const rtl::Reference< ::chart::DataSeries > &xGivenDataSeries)
static bool isSupportingAreaProperties(const rtl::Reference< ::chart::ChartType > &xChartType, sal_Int32 nDimensionCount)
static bool hasPointOwnColor(const rtl::Reference< ::chart::DataSeries > &xDataSeries, sal_Int32 nPointIndex, const css::uno::Reference< css::beans::XPropertySet > &xDataPointProperties)
This guard calls lockControllers at the given Model in the CTOR and unlockControllers in the DTOR.
static double getAxisMinorStepWidthForErrorBarDecimals(const rtl::Reference<::chart::ChartModel > &xChartModel, const rtl::Reference<::chart::ChartView > &xChartView, std::u16string_view rSelectedObjectCID)
static OUString createClassifiedIdentifierForParticle(std::u16string_view rParticle)
static OUString getSeriesParticleFromCID(std::u16string_view rCID)
static OUString createDataCurveEquationCID(std::u16string_view rSeriesParticle, sal_Int32 nCurveIndex)
static rtl::Reference< ::chart::DataSeries > getDataSeriesForCID(std::u16string_view rObjectCID, const rtl::Reference<::chart::ChartModel > &xChartModel)
static OUString getStringForType(ObjectType eObjectType)
static OUString createDataCurveCID(std::u16string_view rSeriesParticle, sal_Int32 nCurveIndex, bool bAverageLine)
static std::u16string_view getParticleID(std::u16string_view rCID)
static OUString createClassifiedIdentifier(enum ObjectType eObjectType, std::u16string_view rParticleID)
static css::uno::Reference< css::beans::XPropertySet > getObjectPropertySet(std::u16string_view rObjectCID, const rtl::Reference< ::chart::ChartModel > &xChartDocument)
static OUString createClassifiedIdentifierForParticles(std::u16string_view rParentParticle, std::u16string_view rChildParticle, std::u16string_view rDragMethodServiceName=std::u16string_view(), std::u16string_view rDragParameterString=std::u16string_view())
static rtl::Reference< ::chart::Axis > getAxisForCID(std::u16string_view rObjectCID, const rtl::Reference<::chart::ChartModel > &xChartModel)
static OUString createClassifiedIdentifierWithParent(enum ObjectType, std::u16string_view rParticleID, std::u16string_view rParentPartical, std::u16string_view rDragMethodServiceName=std::u16string_view(), std::u16string_view rDragParameterString=std::u16string_view())
static OUString createPointCID(std::u16string_view rPointCID_Stub, sal_Int32 nIndex)
static std::u16string_view getFullParentParticle(std::u16string_view rCID)
static OUString createClassifiedIdentifierForGrid(const css::uno::Reference< css::chart2::XAxis > &xAxis, const rtl::Reference<::chart::ChartModel > &xChartModel, sal_Int32 nSubIndex=-1)
ObjectType getObjectType() const
static OUString createClassifiedIdentifierForObject(const css::uno::Reference< css::uno::XInterface > &xObject, const rtl::Reference<::chart::ChartModel > &xChartModel)
static OUString getName(ObjectType eObjectType, bool bPlural=false)
void init(const rtl::Reference<::chart::ChartModel > &xModel)
void setSymbolInformation(SfxItemSet &&rSymbolShapeProperties, std::optional< Graphic > oAutoSymbolGraphic)
void SetAxisMinorStepWidthForErrorBarDecimals(double fMinorStepWidth)
OUString const & getSelectedCID() const
static rtl::Reference< ::chart::Title > getTitle(eTitleType nTitleIndex, ChartModel &rModel)
A guard which does nothing, unless you explicitly call commitAction.
Definition: UndoGuard.hxx:37
A guard which, in its destructor, restores the model state it found in the constructor.
Definition: UndoGuard.hxx:68
virtual short run() override
Definition: dlg_View3D.cxx:71
Graphic GetSymbolGraphic(sal_Int32 nStandardSymbol, const SfxItemSet *pSymbolShapeProperties) const
virtual void FillItemSet(SfxItemSet &rOutItemSet) const override
applies all properties that can be mapped to items into the given item set.
SfxItemSet CreateEmptyItemSet() const
creates an empty item set using the given pool or a common pool if empty (see GetItemPool) and allowi...
#define TOOLS_WARN_EXCEPTION(area, stream)
float u
OOO_DLLPUBLIC_CHARTTOOLS rtl::Reference<::chart::RegressionCurveModel > getFirstCurveNotMeanValueLine(const css::uno::Reference< css::chart2::XRegressionCurveContainer > &xCurveContainer)
Returns the first regression curve found that is not of type mean-value line.
OOO_DLLPUBLIC_CHARTTOOLS rtl::Reference<::chart::RegressionCurveModel > getMeanValueLine(const css::uno::Reference< css::chart2::XRegressionCurveContainer > &xRegCnt)
OOO_DLLPUBLIC_CHARTTOOLS sal_Int32 getRegressionCurveIndex(const rtl::Reference<::chart::DataSeries > &xContainer, const rtl::Reference<::chart::RegressionCurveModel > &xCurve)
@ OBJECTTYPE_DATA_SERIES
@ OBJECTTYPE_DATA_LABELS
@ OBJECTTYPE_DATA_TABLE
@ OBJECTTYPE_DIAGRAM
@ OBJECTTYPE_LEGEND_ENTRY
@ OBJECTTYPE_DATA_ERRORS_X
@ OBJECTTYPE_DATA_STOCK_LOSS
@ OBJECTTYPE_DIAGRAM_FLOOR
@ OBJECTTYPE_DATA_POINT
@ OBJECTTYPE_DATA_STOCK_RANGE
@ OBJECTTYPE_UNKNOWN
@ OBJECTTYPE_SUBGRID
@ OBJECTTYPE_DATA_ERRORS_Y
@ OBJECTTYPE_AXIS_UNITLABEL
@ OBJECTTYPE_DATA_CURVE_EQUATION
@ OBJECTTYPE_DATA_STOCK_GAIN
@ OBJECTTYPE_DATA_AVERAGE_LINE
@ OBJECTTYPE_DATA_ERRORS_Z
@ OBJECTTYPE_DATA_CURVE
@ OBJECTTYPE_DATA_LABEL
@ OBJECTTYPE_DIAGRAM_WALL
OUString OOO_DLLPUBLIC_CHARTTOOLS SchResId(TranslateId aId)
Definition: ResId.cxx:24
sal_Int32 toInt32(std::u16string_view str, sal_Int16 radix=10)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
ObjectType
OUString aCommand
RET_OK