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 <memory>
21 #include <ChartController.hxx>
22 
23 #include <dlg_InsertAxis_Grid.hxx>
24 #include <dlg_InsertDataLabel.hxx>
25 #include <dlg_InsertLegend.hxx>
26 #include <dlg_InsertErrorBars.hxx>
27 #include <dlg_InsertTitle.hxx>
28 #include <dlg_ObjectProperties.hxx>
29 
30 #include <ChartModel.hxx>
31 #include <ChartModelHelper.hxx>
32 #include <AxisHelper.hxx>
33 #include <TitleHelper.hxx>
34 #include <DiagramHelper.hxx>
35 #include <chartview/DrawModelWrapper.hxx>
36 #include <chartview/ChartSfxItemIds.hxx>
37 #include <NumberFormatterWrapper.hxx>
38 #include <ViewElementListProvider.hxx>
39 #include <MultipleChartConverters.hxx>
40 #include <ControllerLockGuard.hxx>
41 #include "UndoGuard.hxx"
42 #include <ResId.hxx>
43 #include <strings.hrc>
44 #include <ReferenceSizeProvider.hxx>
45 #include <ObjectIdentifier.hxx>
46 #include <RegressionCurveHelper.hxx>
47 #include <RegressionCurveItemConverter.hxx>
48 #include <StatisticsHelper.hxx>
49 #include <ErrorBarItemConverter.hxx>
50 #include <DataSeriesHelper.hxx>
51 #include <ObjectNameProvider.hxx>
52 #include <LegendHelper.hxx>
53 
54 #include <com/sun/star/chart2/XRegressionCurve.hpp>
55 #include <com/sun/star/chart2/XRegressionCurveContainer.hpp>
56 #include <com/sun/star/chart2/XChartDocument.hpp>
57 #include <com/sun/star/chart/ErrorBarStyle.hpp>
58 #include <svx/ActionDescriptionProvider.hxx>
59 
60 #include <tools/diagnose_ex.h>
61 #include <vcl/svapp.hxx>
62 
63 using namespace ::com::sun::star;
64 using namespace ::com::sun::star::chart2;
65 using ::com::sun::star::uno::Reference;
66 using ::com::sun::star::uno::Sequence;
67 
68 namespace
69 {
70 
lcl_InsertMeanValueLine(const uno::Reference<chart2::XDataSeries> & xSeries)71 void lcl_InsertMeanValueLine( const uno::Reference< chart2::XDataSeries > & xSeries )
72 {
73     uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
74         xSeries, uno::UNO_QUERY );
75     if( xRegCurveCnt.is())
76     {
77         ::chart::RegressionCurveHelper::addMeanValueLine(
78             xRegCurveCnt, uno::Reference< beans::XPropertySet >( xSeries, uno::UNO_QUERY ));
79     }
80 }
81 
82 } // anonymous namespace
83 
84 namespace chart
85 {
86 
executeDispatch_InsertAxes()87 void ChartController::executeDispatch_InsertAxes()
88 {
89     UndoGuard aUndoGuard(
90         ActionDescriptionProvider::createDescription(
91             ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_AXES )),
92         m_xUndoManager );
93 
94     try
95     {
96         InsertAxisOrGridDialogData aDialogInput;
97         uno::Reference< XDiagram > xDiagram = ChartModelHelper::findDiagram(getModel());
98         AxisHelper::getAxisOrGridExistence( aDialogInput.aExistenceList, xDiagram );
99         AxisHelper::getAxisOrGridPossibilities( aDialogInput.aPossibilityList, xDiagram );
100 
101         SolarMutexGuard aGuard;
102         SchAxisDlg aDlg(GetChartFrame(), aDialogInput);
103         if (aDlg.run() == RET_OK)
104         {
105             // lock controllers till end of block
106             ControllerLockGuardUNO aCLGuard( getModel() );
107 
108             InsertAxisOrGridDialogData aDialogOutput;
109             aDlg.getResult(aDialogOutput);
110             std::unique_ptr< ReferenceSizeProvider > pRefSizeProvider(
111                 impl_createReferenceSizeProvider());
112             bool bChanged = AxisHelper::changeVisibilityOfAxes( xDiagram
113                 , aDialogInput.aExistenceList, aDialogOutput.aExistenceList, m_xCC
114                 , pRefSizeProvider.get() );
115             if( bChanged )
116                 aUndoGuard.commit();
117         }
118     }
119     catch(const uno::RuntimeException&)
120     {
121         TOOLS_WARN_EXCEPTION("chart2", "" );
122     }
123 }
124 
executeDispatch_InsertGrid()125 void ChartController::executeDispatch_InsertGrid()
126 {
127     UndoGuard aUndoGuard(
128         ActionDescriptionProvider::createDescription(
129             ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_GRIDS )),
130         m_xUndoManager );
131 
132     try
133     {
134         InsertAxisOrGridDialogData aDialogInput;
135         uno::Reference< XDiagram > xDiagram = ChartModelHelper::findDiagram(getModel());
136         AxisHelper::getAxisOrGridExistence( aDialogInput.aExistenceList, xDiagram, false );
137         AxisHelper::getAxisOrGridPossibilities( aDialogInput.aPossibilityList, xDiagram, false );
138 
139         SolarMutexGuard aGuard;
140         SchGridDlg aDlg(GetChartFrame(), aDialogInput);//aItemSet, b3D, bNet, bSecondaryX, bSecondaryY );
141         if (aDlg.run() == RET_OK)
142         {
143             // lock controllers till end of block
144             ControllerLockGuardUNO aCLGuard( getModel() );
145             InsertAxisOrGridDialogData aDialogOutput;
146             aDlg.getResult( aDialogOutput );
147             bool bChanged = AxisHelper::changeVisibilityOfGrids( xDiagram
148                 , aDialogInput.aExistenceList, aDialogOutput.aExistenceList );
149             if( bChanged )
150                 aUndoGuard.commit();
151         }
152     }
153     catch(const uno::RuntimeException&)
154     {
155         TOOLS_WARN_EXCEPTION("chart2", "" );
156     }
157 }
158 
executeDispatch_InsertTitles()159 void ChartController::executeDispatch_InsertTitles()
160 {
161     UndoGuard aUndoGuard(
162         ActionDescriptionProvider::createDescription(
163             ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_TITLES )),
164         m_xUndoManager );
165 
166     try
167     {
168         TitleDialogData aDialogInput;
169         aDialogInput.readFromModel( getModel() );
170 
171         SolarMutexGuard aGuard;
172         SchTitleDlg aDlg(GetChartFrame(), aDialogInput);
173         if (aDlg.run() == RET_OK)
174         {
175             // lock controllers till end of block
176             ControllerLockGuardUNO aCLGuard( getModel() );
177             TitleDialogData aDialogOutput(impl_createReferenceSizeProvider());
178             aDlg.getResult(aDialogOutput);
179             bool bChanged = aDialogOutput.writeDifferenceToModel( getModel(), m_xCC, &aDialogInput );
180             if( bChanged )
181                 aUndoGuard.commit();
182         }
183     }
184     catch(const uno::RuntimeException&)
185     {
186         TOOLS_WARN_EXCEPTION("chart2", "" );
187     }
188 }
189 
executeDispatch_DeleteLegend()190 void ChartController::executeDispatch_DeleteLegend()
191 {
192     UndoGuard aUndoGuard(
193         ActionDescriptionProvider::createDescription(
194             ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_LEGEND )),
195         m_xUndoManager );
196 
197     ChartModel& rModel = dynamic_cast<ChartModel&>(*getModel());
198     LegendHelper::hideLegend(rModel);
199     aUndoGuard.commit();
200 }
201 
executeDispatch_InsertLegend()202 void ChartController::executeDispatch_InsertLegend()
203 {
204     UndoGuard aUndoGuard(
205         ActionDescriptionProvider::createDescription(
206             ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_LEGEND )),
207         m_xUndoManager );
208 
209     ChartModel& rModel = dynamic_cast<ChartModel&>(*getModel());
210     LegendHelper::showLegend(rModel, m_xCC);
211     aUndoGuard.commit();
212 }
213 
executeDispatch_OpenLegendDialog()214 void ChartController::executeDispatch_OpenLegendDialog()
215 {
216     UndoGuard aUndoGuard(
217         ActionDescriptionProvider::createDescription(
218             ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_LEGEND )),
219         m_xUndoManager );
220 
221     try
222     {
223         //prepare and open dialog
224         SolarMutexGuard aGuard;
225         SchLegendDlg aDlg(GetChartFrame(), m_xCC);
226         aDlg.init( getModel() );
227         if (aDlg.run() == RET_OK)
228         {
229             // lock controllers till end of block
230             ControllerLockGuardUNO aCLGuard( getModel() );
231             aDlg.writeToModel( getModel() );
232             aUndoGuard.commit();
233         }
234     }
235     catch(const uno::RuntimeException&)
236     {
237         TOOLS_WARN_EXCEPTION("chart2", "" );
238     }
239 }
240 
executeDispatch_InsertMenu_DataLabels()241 void ChartController::executeDispatch_InsertMenu_DataLabels()
242 {
243     UndoGuard aUndoGuard(
244         ActionDescriptionProvider::createDescription(
245             ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_DATALABELS )),
246         m_xUndoManager );
247 
248     //if a series is selected insert labels for that series only:
249     uno::Reference< chart2::XDataSeries > xSeries =
250         ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel());
251     if( xSeries.is() )
252     {
253         // add labels
254         DataSeriesHelper::insertDataLabelsToSeriesAndAllPoints( xSeries );
255 
256         OUString aChildParticle( ObjectIdentifier::getStringForType( OBJECTTYPE_DATA_LABELS ) + "=" );
257         OUString aObjectCID = ObjectIdentifier::createClassifiedIdentifierForParticles(
258             ObjectIdentifier::getSeriesParticleFromCID(m_aSelection.getSelectedCID()), aChildParticle );
259 
260         bool bSuccess = ChartController::executeDlg_ObjectProperties_withoutUndoGuard( aObjectCID, true );
261         if( bSuccess )
262             aUndoGuard.commit();
263         return;
264     }
265 
266     try
267     {
268         wrapper::AllDataLabelItemConverter aItemConverter(
269             getModel(),
270             m_pDrawModelWrapper->GetItemPool(),
271             m_pDrawModelWrapper->getSdrModel(),
272             uno::Reference< lang::XMultiServiceFactory >( getModel(), uno::UNO_QUERY ));
273         SfxItemSet aItemSet = aItemConverter.CreateEmptyItemSet();
274         aItemConverter.FillItemSet( aItemSet );
275 
276         //prepare and open dialog
277         SolarMutexGuard aGuard;
278 
279         //get number formatter
280         uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( getModel(), uno::UNO_QUERY );
281         NumberFormatterWrapper aNumberFormatterWrapper( xNumberFormatsSupplier );
282         SvNumberFormatter* pNumberFormatter = aNumberFormatterWrapper.getSvNumberFormatter();
283 
284         DataLabelsDialog aDlg(GetChartFrame(), aItemSet, pNumberFormatter);
285 
286         if (aDlg.run() == RET_OK)
287         {
288             SfxItemSet aOutItemSet = aItemConverter.CreateEmptyItemSet();
289             aDlg.FillItemSet(aOutItemSet);
290             // lock controllers till end of block
291             ControllerLockGuardUNO aCLGuard( getModel() );
292             bool bChanged = aItemConverter.ApplyItemSet( aOutItemSet );//model should be changed now
293             if( bChanged )
294                 aUndoGuard.commit();
295         }
296     }
297     catch(const uno::RuntimeException&)
298     {
299         TOOLS_WARN_EXCEPTION("chart2", "" );
300     }
301 }
302 
executeDispatch_InsertMeanValue()303 void ChartController::executeDispatch_InsertMeanValue()
304 {
305     UndoGuard aUndoGuard(
306         ActionDescriptionProvider::createDescription(
307             ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_AVERAGE_LINE )),
308         m_xUndoManager );
309     lcl_InsertMeanValueLine( ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(),
310                                                                     getModel() ) );
311     aUndoGuard.commit();
312 }
313 
executeDispatch_InsertMenu_MeanValues()314 void ChartController::executeDispatch_InsertMenu_MeanValues()
315 {
316     UndoGuard aUndoGuard(
317         ActionDescriptionProvider::createDescription(
318             ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_AVERAGE_LINE )),
319         m_xUndoManager );
320 
321     uno::Reference< chart2::XDataSeries > xSeries =
322         ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() );
323     if( xSeries.is() )
324     {
325         //if a series is selected insert mean value only for that series:
326         lcl_InsertMeanValueLine( xSeries );
327     }
328     else
329     {
330         std::vector< uno::Reference< chart2::XDataSeries > > aSeries(
331             DiagramHelper::getDataSeriesFromDiagram( ChartModelHelper::findDiagram( getModel() )));
332 
333         for( const auto& xSrs : aSeries )
334             lcl_InsertMeanValueLine( xSrs );
335     }
336     aUndoGuard.commit();
337 }
338 
executeDispatch_InsertMenu_Trendlines()339 void ChartController::executeDispatch_InsertMenu_Trendlines()
340 {
341     OUString aCID = m_aSelection.getSelectedCID();
342 
343     uno::Reference< chart2::XDataSeries > xSeries =
344         ObjectIdentifier::getDataSeriesForCID( aCID, getModel() );
345 
346     if( !xSeries.is() )
347         return;
348 
349     executeDispatch_InsertTrendline();
350 }
351 
executeDispatch_InsertTrendline()352 void ChartController::executeDispatch_InsertTrendline()
353 {
354     uno::Reference< chart2::XRegressionCurveContainer > xRegressionCurveContainer(
355         ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel()), uno::UNO_QUERY );
356 
357     if( !xRegressionCurveContainer.is() )
358         return;
359 
360     UndoLiveUpdateGuard aUndoGuard(
361         ActionDescriptionProvider::createDescription(
362             ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_CURVE )),
363         m_xUndoManager );
364 
365     uno::Reference< chart2::XRegressionCurve > xCurve =
366         RegressionCurveHelper::addRegressionCurve(
367             SvxChartRegress::Linear,
368             xRegressionCurveContainer );
369 
370     uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
371 
372     if( !xProperties.is())
373         return;
374 
375     wrapper::RegressionCurveItemConverter aItemConverter(
376         xProperties, xRegressionCurveContainer, m_pDrawModelWrapper->getSdrModel().GetItemPool(),
377         m_pDrawModelWrapper->getSdrModel(),
378         uno::Reference< lang::XMultiServiceFactory >( getModel(), uno::UNO_QUERY ));
379 
380     // open dialog
381     SfxItemSet aItemSet = aItemConverter.CreateEmptyItemSet();
382     aItemConverter.FillItemSet( aItemSet );
383     ObjectPropertiesDialogParameter aDialogParameter(
384         ObjectIdentifier::createDataCurveCID(
385             ObjectIdentifier::getSeriesParticleFromCID( m_aSelection.getSelectedCID()),
386             RegressionCurveHelper::getRegressionCurveIndex( xRegressionCurveContainer, xCurve ), false ));
387     aDialogParameter.init( getModel() );
388     ViewElementListProvider aViewElementListProvider( m_pDrawModelWrapper.get());
389     SolarMutexGuard aGuard;
390     SchAttribTabDlg aDialog(
391         GetChartFrame(), &aItemSet, &aDialogParameter,
392         &aViewElementListProvider,
393         uno::Reference< util::XNumberFormatsSupplier >(
394                 getModel(), uno::UNO_QUERY ) );
395 
396     // note: when a user pressed "OK" but didn't change any settings in the
397     // dialog, the SfxTabDialog returns "Cancel"
398     if( aDialog.run() == RET_OK || aDialog.DialogWasClosedWithOK())
399     {
400         const SfxItemSet* pOutItemSet = aDialog.GetOutputItemSet();
401         if( pOutItemSet )
402         {
403             ControllerLockGuardUNO aCLGuard( getModel() );
404             aItemConverter.ApplyItemSet( *pOutItemSet );
405         }
406         aUndoGuard.commit();
407     }
408 }
409 
executeDispatch_InsertErrorBars(bool bYError)410 void ChartController::executeDispatch_InsertErrorBars( bool bYError )
411 {
412     ObjectType objType = bYError ? OBJECTTYPE_DATA_ERRORS_Y : OBJECTTYPE_DATA_ERRORS_X;
413 
414     //if a series is selected insert error bars for that series only:
415     uno::Reference< chart2::XDataSeries > xSeries =
416         ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() );
417 
418     if( xSeries.is())
419     {
420         UndoLiveUpdateGuard aUndoGuard(
421             ActionDescriptionProvider::createDescription(
422                 ActionDescriptionProvider::ActionType::Insert,
423                 SchResId( bYError ? STR_OBJECT_ERROR_BARS_Y : STR_OBJECT_ERROR_BARS_X )),
424             m_xUndoManager );
425 
426         // add error bars with standard deviation
427         uno::Reference< beans::XPropertySet > xErrorBarProp(
428             StatisticsHelper::addErrorBars( xSeries,
429                                             css::chart::ErrorBarStyle::STANDARD_DEVIATION,
430                                             bYError));
431 
432         // get an appropriate item converter
433         wrapper::ErrorBarItemConverter aItemConverter(
434             getModel(), xErrorBarProp, m_pDrawModelWrapper->getSdrModel().GetItemPool(),
435             m_pDrawModelWrapper->getSdrModel(),
436             uno::Reference< lang::XMultiServiceFactory >( getModel(), uno::UNO_QUERY ));
437 
438         // open dialog
439         SfxItemSet aItemSet = aItemConverter.CreateEmptyItemSet();
440         aItemSet.Put(SfxBoolItem(SCHATTR_STAT_ERRORBAR_TYPE,bYError));
441         aItemConverter.FillItemSet( aItemSet );
442         ObjectPropertiesDialogParameter aDialogParameter(
443             ObjectIdentifier::createClassifiedIdentifierWithParent(
444                 objType, u"", m_aSelection.getSelectedCID()));
445         aDialogParameter.init( getModel() );
446         ViewElementListProvider aViewElementListProvider( m_pDrawModelWrapper.get());
447         SolarMutexGuard aGuard;
448         SchAttribTabDlg aDlg(
449                 GetChartFrame(), &aItemSet, &aDialogParameter,
450                 &aViewElementListProvider,
451                 uno::Reference< util::XNumberFormatsSupplier >(
452                         getModel(), uno::UNO_QUERY ) );
453         aDlg.SetAxisMinorStepWidthForErrorBarDecimals(
454             InsertErrorBarsDialog::getAxisMinorStepWidthForErrorBarDecimals( getModel(),
455                                                                              m_xChartView, m_aSelection.getSelectedCID()));
456 
457         // note: when a user pressed "OK" but didn't change any settings in the
458         // dialog, the SfxTabDialog returns "Cancel"
459         if (aDlg.run() == RET_OK || aDlg.DialogWasClosedWithOK())
460         {
461             const SfxItemSet* pOutItemSet = aDlg.GetOutputItemSet();
462             if( pOutItemSet )
463             {
464                 ControllerLockGuardUNO aCLGuard( getModel() );
465                 aItemConverter.ApplyItemSet( *pOutItemSet );
466             }
467             aUndoGuard.commit();
468         }
469     }
470     else
471     {
472         //if no series is selected insert error bars for all series
473         UndoGuard aUndoGuard(
474             ActionDescriptionProvider::createDescription(
475                 ActionDescriptionProvider::ActionType::Insert,
476                 ObjectNameProvider::getName_ObjectForAllSeries( objType ) ),
477             m_xUndoManager );
478 
479         try
480         {
481             wrapper::AllSeriesStatisticsConverter aItemConverter(
482                 getModel(), m_pDrawModelWrapper->GetItemPool() );
483             SfxItemSet aItemSet = aItemConverter.CreateEmptyItemSet();
484             aItemConverter.FillItemSet( aItemSet );
485 
486             //prepare and open dialog
487             SolarMutexGuard aGuard;
488             InsertErrorBarsDialog aDlg(
489                 GetChartFrame(), aItemSet,
490                 uno::Reference< chart2::XChartDocument >( getModel(), uno::UNO_QUERY ),
491                 bYError ? ErrorBarResources::ERROR_BAR_Y : ErrorBarResources::ERROR_BAR_X);
492 
493             aDlg.SetAxisMinorStepWidthForErrorBarDecimals(
494                 InsertErrorBarsDialog::getAxisMinorStepWidthForErrorBarDecimals( getModel(), m_xChartView, OUString() ) );
495 
496             if (aDlg.run() == RET_OK)
497             {
498                 SfxItemSet aOutItemSet = aItemConverter.CreateEmptyItemSet();
499                 aDlg.FillItemSet( aOutItemSet );
500 
501                 // lock controllers till end of block
502                 ControllerLockGuardUNO aCLGuard( getModel() );
503                 bool bChanged = aItemConverter.ApplyItemSet( aOutItemSet );//model should be changed now
504                 if( bChanged )
505                     aUndoGuard.commit();
506             }
507         }
508         catch(const uno::RuntimeException&)
509         {
510             TOOLS_WARN_EXCEPTION("chart2", "" );
511         }
512     }
513 }
514 
executeDispatch_InsertTrendlineEquation(bool bInsertR2)515 void ChartController::executeDispatch_InsertTrendlineEquation( bool bInsertR2 )
516 {
517     uno::Reference< chart2::XRegressionCurve > xRegCurve(
518         ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
519     if( !xRegCurve.is() )
520     {
521         uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
522             ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
523         xRegCurve.set( RegressionCurveHelper::getFirstCurveNotMeanValueLine( xRegCurveCnt ) );
524     }
525     if( !xRegCurve.is())
526         return;
527 
528     uno::Reference< beans::XPropertySet > xEqProp( xRegCurve->getEquationProperties());
529     if( xEqProp.is())
530     {
531         UndoGuard aUndoGuard(
532             ActionDescriptionProvider::createDescription(
533                 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_CURVE_EQUATION )),
534             m_xUndoManager );
535         xEqProp->setPropertyValue( "ShowEquation", uno::Any( true ));
536         xEqProp->setPropertyValue( "XName", uno::Any( OUString("x") ));
537         xEqProp->setPropertyValue( "YName", uno::Any( OUString("f(x)") ));
538         xEqProp->setPropertyValue( "ShowCorrelationCoefficient", uno::Any( bInsertR2 ));
539         aUndoGuard.commit();
540     }
541 }
542 
executeDispatch_InsertR2Value()543 void ChartController::executeDispatch_InsertR2Value()
544 {
545     uno::Reference< beans::XPropertySet > xEqProp =
546         ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getModel() );
547     if( xEqProp.is())
548     {
549         UndoGuard aUndoGuard(
550             ActionDescriptionProvider::createDescription(
551                 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_CURVE_EQUATION )),
552             m_xUndoManager );
553         xEqProp->setPropertyValue( "ShowCorrelationCoefficient", uno::Any( true ));
554         aUndoGuard.commit();
555     }
556 }
557 
executeDispatch_DeleteR2Value()558 void ChartController::executeDispatch_DeleteR2Value()
559 {
560     uno::Reference< beans::XPropertySet > xEqProp =
561         ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getModel() );
562     if( xEqProp.is())
563     {
564         UndoGuard aUndoGuard(
565             ActionDescriptionProvider::createDescription(
566                 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_CURVE_EQUATION )),
567             m_xUndoManager );
568         xEqProp->setPropertyValue( "ShowCorrelationCoefficient", uno::Any( false ));
569         aUndoGuard.commit();
570     }
571 }
572 
executeDispatch_DeleteMeanValue()573 void ChartController::executeDispatch_DeleteMeanValue()
574 {
575     uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
576         ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
577     if( xRegCurveCnt.is())
578     {
579         UndoGuard aUndoGuard(
580             ActionDescriptionProvider::createDescription(
581                 ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_AVERAGE_LINE )),
582             m_xUndoManager );
583         RegressionCurveHelper::removeMeanValueLine( xRegCurveCnt );
584         aUndoGuard.commit();
585     }
586 }
587 
executeDispatch_DeleteTrendline()588 void ChartController::executeDispatch_DeleteTrendline()
589 {
590     uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
591         ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
592     if( xRegCurveCnt.is())
593     {
594         UndoGuard aUndoGuard(
595             ActionDescriptionProvider::createDescription(
596                 ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_CURVE )),
597             m_xUndoManager );
598         RegressionCurveHelper::removeAllExceptMeanValueLine( xRegCurveCnt );
599         aUndoGuard.commit();
600     }
601 }
602 
executeDispatch_DeleteTrendlineEquation()603 void ChartController::executeDispatch_DeleteTrendlineEquation()
604 {
605     uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
606         ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
607     if( xRegCurveCnt.is())
608     {
609         UndoGuard aUndoGuard(
610             ActionDescriptionProvider::createDescription(
611                 ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_CURVE_EQUATION )),
612             m_xUndoManager );
613         RegressionCurveHelper::removeEquations( xRegCurveCnt );
614         aUndoGuard.commit();
615     }
616 }
617 
executeDispatch_DeleteErrorBars(bool bYError)618 void ChartController::executeDispatch_DeleteErrorBars( bool bYError )
619 {
620     uno::Reference< chart2::XDataSeries > xDataSeries(
621         ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ));
622     if( xDataSeries.is())
623     {
624         UndoGuard aUndoGuard(
625             ActionDescriptionProvider::createDescription(
626                 ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_CURVE )),
627             m_xUndoManager );
628         StatisticsHelper::removeErrorBars( xDataSeries, bYError );
629         aUndoGuard.commit();
630     }
631 }
632 
executeDispatch_InsertDataLabels()633 void ChartController::executeDispatch_InsertDataLabels()
634 {
635     uno::Reference< chart2::XDataSeries > xSeries =
636         ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() );
637     if( xSeries.is() )
638     {
639         UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Insert,
640             SchResId( STR_OBJECT_DATALABELS )),
641             m_xUndoManager );
642         DataSeriesHelper::insertDataLabelsToSeriesAndAllPoints( xSeries );
643         aUndoGuard.commit();
644     }
645 }
646 
executeDispatch_InsertDataLabel()647 void ChartController::executeDispatch_InsertDataLabel()
648 {
649     UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Insert,
650         SchResId( STR_OBJECT_LABEL )),
651         m_xUndoManager );
652     DataSeriesHelper::insertDataLabelToPoint( ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getModel() ) );
653     aUndoGuard.commit();
654 }
655 
executeDispatch_DeleteDataLabels()656 void ChartController::executeDispatch_DeleteDataLabels()
657 {
658     uno::Reference< chart2::XDataSeries > xSeries =
659         ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() );
660     if( xSeries.is() )
661     {
662         UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Delete,
663             SchResId( STR_OBJECT_DATALABELS )),
664             m_xUndoManager );
665         DataSeriesHelper::deleteDataLabelsFromSeriesAndAllPoints( xSeries );
666         aUndoGuard.commit();
667     }
668 }
669 
executeDispatch_DeleteDataLabel()670 void ChartController::executeDispatch_DeleteDataLabel()
671 {
672     UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Delete,
673         SchResId( STR_OBJECT_LABEL )),
674         m_xUndoManager );
675     DataSeriesHelper::deleteDataLabelsFromPoint( ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getModel() ) );
676     aUndoGuard.commit();
677 }
678 
executeDispatch_ResetAllDataPoints()679 void ChartController::executeDispatch_ResetAllDataPoints()
680 {
681     UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Format,
682         SchResId( STR_OBJECT_DATAPOINTS )),
683         m_xUndoManager );
684     uno::Reference< chart2::XDataSeries > xSeries = ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() );
685     if( xSeries.is() )
686         xSeries->resetAllDataPoints();
687     aUndoGuard.commit();
688 }
executeDispatch_ResetDataPoint()689 void ChartController::executeDispatch_ResetDataPoint()
690 {
691     UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Format,
692         SchResId( STR_OBJECT_DATAPOINT )),
693         m_xUndoManager );
694     uno::Reference< chart2::XDataSeries > xSeries = ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() );
695     if( xSeries.is() )
696     {
697         sal_Int32 nPointIndex = ObjectIdentifier::getIndexFromParticleOrCID( m_aSelection.getSelectedCID() );
698         xSeries->resetDataPoint( nPointIndex );
699     }
700     aUndoGuard.commit();
701 }
702 
executeDispatch_InsertAxisTitle()703 void ChartController::executeDispatch_InsertAxisTitle()
704 {
705     try
706     {
707         uno::Reference< XTitle > xTitle;
708         {
709             UndoGuard aUndoGuard(
710             ActionDescriptionProvider::createDescription(
711                 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_TITLE )),
712             m_xUndoManager );
713 
714             Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
715             sal_Int32 nDimensionIndex = -1;
716             sal_Int32 nCooSysIndex = -1;
717             sal_Int32 nAxisIndex = -1;
718             AxisHelper::getIndicesForAxis( xAxis, ChartModelHelper::findDiagram(getModel()), nCooSysIndex, nDimensionIndex, nAxisIndex );
719 
720             TitleHelper::eTitleType eTitleType = TitleHelper::X_AXIS_TITLE;
721             if( nDimensionIndex==0 )
722                 eTitleType = nAxisIndex==0 ? TitleHelper::X_AXIS_TITLE : TitleHelper::SECONDARY_X_AXIS_TITLE;
723             else if( nDimensionIndex==1 )
724                 eTitleType = nAxisIndex==0 ? TitleHelper::Y_AXIS_TITLE : TitleHelper::SECONDARY_Y_AXIS_TITLE;
725             else
726                 eTitleType = TitleHelper::Z_AXIS_TITLE;
727 
728             std::unique_ptr< ReferenceSizeProvider > apRefSizeProvider( impl_createReferenceSizeProvider());
729             xTitle = TitleHelper::createTitle( eTitleType, ObjectNameProvider::getTitleNameByType(eTitleType), getModel(), m_xCC, apRefSizeProvider.get() );
730             aUndoGuard.commit();
731         }
732     }
733     catch(const uno::RuntimeException&)
734     {
735         TOOLS_WARN_EXCEPTION("chart2", "" );
736     }
737 }
738 
executeDispatch_InsertAxis()739 void ChartController::executeDispatch_InsertAxis()
740 {
741     UndoGuard aUndoGuard(
742         ActionDescriptionProvider::createDescription(
743             ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_AXIS )),
744         m_xUndoManager );
745 
746     try
747     {
748         Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
749         if( xAxis.is() )
750         {
751             AxisHelper::makeAxisVisible( xAxis );
752             aUndoGuard.commit();
753         }
754     }
755     catch(const uno::RuntimeException&)
756     {
757         TOOLS_WARN_EXCEPTION("chart2", "" );
758     }
759 }
760 
executeDispatch_DeleteAxis()761 void ChartController::executeDispatch_DeleteAxis()
762 {
763     UndoGuard aUndoGuard(
764         ActionDescriptionProvider::createDescription(
765             ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_AXIS )),
766         m_xUndoManager );
767 
768     try
769     {
770         Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
771         if( xAxis.is() )
772         {
773             AxisHelper::makeAxisInvisible( xAxis );
774             aUndoGuard.commit();
775         }
776     }
777     catch(const uno::RuntimeException&)
778     {
779         TOOLS_WARN_EXCEPTION("chart2", "" );
780     }
781 }
782 
executeDispatch_InsertMajorGrid()783 void ChartController::executeDispatch_InsertMajorGrid()
784 {
785     UndoGuard aUndoGuard(
786         ActionDescriptionProvider::createDescription(
787             ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_GRID )),
788         m_xUndoManager );
789 
790     try
791     {
792         Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
793         if( xAxis.is() )
794         {
795             AxisHelper::makeGridVisible( xAxis->getGridProperties() );
796             aUndoGuard.commit();
797         }
798     }
799     catch(const uno::RuntimeException&)
800     {
801         TOOLS_WARN_EXCEPTION("chart2", "" );
802     }
803 }
804 
executeDispatch_DeleteMajorGrid()805 void ChartController::executeDispatch_DeleteMajorGrid()
806 {
807     UndoGuard aUndoGuard(
808         ActionDescriptionProvider::createDescription(
809             ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_GRID )),
810         m_xUndoManager );
811 
812     try
813     {
814         Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
815         if( xAxis.is() )
816         {
817             AxisHelper::makeGridInvisible( xAxis->getGridProperties() );
818             aUndoGuard.commit();
819         }
820     }
821     catch(const uno::RuntimeException&)
822     {
823         TOOLS_WARN_EXCEPTION("chart2", "" );
824     }
825 }
826 
executeDispatch_InsertMinorGrid()827 void ChartController::executeDispatch_InsertMinorGrid()
828 {
829     UndoGuard aUndoGuard(
830         ActionDescriptionProvider::createDescription(
831             ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_GRID )),
832         m_xUndoManager );
833 
834     try
835     {
836         Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
837         if( xAxis.is() )
838         {
839             const Sequence< Reference< beans::XPropertySet > > aSubGrids( xAxis->getSubGridProperties() );
840             for( Reference< beans::XPropertySet > const & props : aSubGrids)
841                 AxisHelper::makeGridVisible( props );
842             aUndoGuard.commit();
843         }
844     }
845     catch(const uno::RuntimeException&)
846     {
847         TOOLS_WARN_EXCEPTION("chart2", "" );
848     }
849 }
850 
executeDispatch_DeleteMinorGrid()851 void ChartController::executeDispatch_DeleteMinorGrid()
852 {
853     UndoGuard aUndoGuard(
854         ActionDescriptionProvider::createDescription(
855             ActionDescriptionProvider::ActionType::Delete, SchResId(STR_OBJECT_GRID)),
856         m_xUndoManager );
857 
858     try
859     {
860         Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
861         if( xAxis.is() )
862         {
863             const Sequence< Reference< beans::XPropertySet > > aSubGrids( xAxis->getSubGridProperties() );
864             for( Reference< beans::XPropertySet > const & props : aSubGrids)
865                 AxisHelper::makeGridInvisible( props );
866             aUndoGuard.commit();
867         }
868     }
869     catch(const uno::RuntimeException&)
870     {
871         TOOLS_WARN_EXCEPTION("chart2", "" );
872     }
873 }
874 
875 } //namespace chart
876 
877 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
878