Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / chart2 / source / controller / main / ChartController_Insert.cxx
bloba1510a7db984b3b1efe11a19935f71c8ab28612d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <memory>
21 #include <ChartController.hxx>
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>
30 #include <ChartWindow.hxx>
31 #include <ChartModelHelper.hxx>
32 #include <AxisHelper.hxx>
33 #include <TitleHelper.hxx>
34 #include <DiagramHelper.hxx>
35 #include <chartview/DrawModelWrapper.hxx>
36 #include <NumberFormatterWrapper.hxx>
37 #include <ViewElementListProvider.hxx>
38 #include <MultipleChartConverters.hxx>
39 #include <ControllerLockGuard.hxx>
40 #include "UndoGuard.hxx"
41 #include <ResId.hxx>
42 #include <strings.hrc>
43 #include <ReferenceSizeProvider.hxx>
44 #include <ObjectIdentifier.hxx>
45 #include <RegressionCurveHelper.hxx>
46 #include <RegressionCurveItemConverter.hxx>
47 #include <StatisticsHelper.hxx>
48 #include <ErrorBarItemConverter.hxx>
49 #include <MultipleItemConverter.hxx>
50 #include <DataSeriesHelper.hxx>
51 #include <ObjectNameProvider.hxx>
52 #include <LegendHelper.hxx>
54 #include <com/sun/star/chart2/XRegressionCurve.hpp>
55 #include <com/sun/star/chart/ErrorBarStyle.hpp>
56 #include <svx/ActionDescriptionProvider.hxx>
58 #include <rtl/ustrbuf.hxx>
59 #include <vcl/svapp.hxx>
61 using namespace ::com::sun::star;
62 using namespace ::com::sun::star::chart2;
63 using ::com::sun::star::uno::Reference;
64 using ::com::sun::star::uno::Sequence;
66 namespace
69 void lcl_InsertMeanValueLine( const uno::Reference< chart2::XDataSeries > & xSeries )
71 uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
72 xSeries, uno::UNO_QUERY );
73 if( xRegCurveCnt.is())
75 ::chart::RegressionCurveHelper::addMeanValueLine(
76 xRegCurveCnt, uno::Reference< beans::XPropertySet >( xSeries, uno::UNO_QUERY ));
80 } // anonymous namespace
82 namespace chart
85 void ChartController::executeDispatch_InsertAxes()
87 UndoGuard aUndoGuard(
88 ActionDescriptionProvider::createDescription(
89 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_AXES )),
90 m_xUndoManager );
92 try
94 InsertAxisOrGridDialogData aDialogInput;
95 uno::Reference< XDiagram > xDiagram = ChartModelHelper::findDiagram(getModel());
96 AxisHelper::getAxisOrGridExcistence( aDialogInput.aExistenceList, xDiagram );
97 AxisHelper::getAxisOrGridPossibilities( aDialogInput.aPossibilityList, xDiagram );
99 SolarMutexGuard aGuard;
100 SchAxisDlg aDlg(GetChartFrame(), aDialogInput);
101 if (aDlg.run() == RET_OK)
103 // lock controllers till end of block
104 ControllerLockGuardUNO aCLGuard( getModel() );
106 InsertAxisOrGridDialogData aDialogOutput;
107 aDlg.getResult(aDialogOutput);
108 std::unique_ptr< ReferenceSizeProvider > pRefSizeProvider(
109 impl_createReferenceSizeProvider());
110 bool bChanged = AxisHelper::changeVisibilityOfAxes( xDiagram
111 , aDialogInput.aExistenceList, aDialogOutput.aExistenceList, m_xCC
112 , pRefSizeProvider.get() );
113 if( bChanged )
114 aUndoGuard.commit();
117 catch(const uno::RuntimeException& e)
119 SAL_WARN("chart2", "Exception caught. " << e );
123 void ChartController::executeDispatch_InsertGrid()
125 UndoGuard aUndoGuard(
126 ActionDescriptionProvider::createDescription(
127 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_GRIDS )),
128 m_xUndoManager );
132 InsertAxisOrGridDialogData aDialogInput;
133 uno::Reference< XDiagram > xDiagram = ChartModelHelper::findDiagram(getModel());
134 AxisHelper::getAxisOrGridExcistence( aDialogInput.aExistenceList, xDiagram, false );
135 AxisHelper::getAxisOrGridPossibilities( aDialogInput.aPossibilityList, xDiagram, false );
137 SolarMutexGuard aGuard;
138 SchGridDlg aDlg(GetChartFrame(), aDialogInput);//aItemSet, b3D, bNet, bSecondaryX, bSecondaryY );
139 if (aDlg.run() == RET_OK)
141 // lock controllers till end of block
142 ControllerLockGuardUNO aCLGuard( getModel() );
143 InsertAxisOrGridDialogData aDialogOutput;
144 aDlg.getResult( aDialogOutput );
145 bool bChanged = AxisHelper::changeVisibilityOfGrids( xDiagram
146 , aDialogInput.aExistenceList, aDialogOutput.aExistenceList );
147 if( bChanged )
148 aUndoGuard.commit();
151 catch(const uno::RuntimeException& e)
153 SAL_WARN("chart2", "Exception caught. " << e );
157 void ChartController::executeDispatch_InsertTitles()
159 UndoGuard aUndoGuard(
160 ActionDescriptionProvider::createDescription(
161 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_TITLES )),
162 m_xUndoManager );
166 TitleDialogData aDialogInput;
167 aDialogInput.readFromModel( getModel() );
169 SolarMutexGuard aGuard;
170 ScopedVclPtrInstance< SchTitleDlg > aDlg( GetChartWindow(), aDialogInput );
171 if( aDlg->Execute() == RET_OK )
173 // lock controllers till end of block
174 ControllerLockGuardUNO aCLGuard( getModel() );
175 TitleDialogData aDialogOutput(impl_createReferenceSizeProvider());
176 aDlg->getResult( aDialogOutput );
177 bool bChanged = aDialogOutput.writeDifferenceToModel( getModel(), m_xCC, &aDialogInput );
178 if( bChanged )
179 aUndoGuard.commit();
182 catch(const uno::RuntimeException& e)
184 SAL_WARN("chart2", "Exception caught. " << e );
188 void ChartController::executeDispatch_DeleteLegend()
190 UndoGuard aUndoGuard(
191 ActionDescriptionProvider::createDescription(
192 ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_LEGEND )),
193 m_xUndoManager );
195 ChartModel& rModel = dynamic_cast<ChartModel&>(*getModel().get());
196 LegendHelper::hideLegend(rModel);
197 aUndoGuard.commit();
200 void ChartController::executeDispatch_InsertLegend()
202 UndoGuard aUndoGuard(
203 ActionDescriptionProvider::createDescription(
204 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_LEGEND )),
205 m_xUndoManager );
207 ChartModel& rModel = dynamic_cast<ChartModel&>(*getModel().get());
208 Reference< chart2::XLegend > xLegend = LegendHelper::showLegend(rModel, m_xCC);
209 aUndoGuard.commit();
212 void ChartController::executeDispatch_OpenLegendDialog()
214 UndoGuard aUndoGuard(
215 ActionDescriptionProvider::createDescription(
216 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_LEGEND )),
217 m_xUndoManager );
221 //prepare and open dialog
222 SolarMutexGuard aGuard;
223 ScopedVclPtrInstance< SchLegendDlg > aDlg( GetChartWindow(), m_xCC );
224 aDlg->init( getModel() );
225 if( aDlg->Execute() == RET_OK )
227 // lock controllers till end of block
228 ControllerLockGuardUNO aCLGuard( getModel() );
229 bool bChanged = aDlg->writeToModel( getModel() );
230 if( bChanged )
231 aUndoGuard.commit();
234 catch(const uno::RuntimeException& e)
236 SAL_WARN("chart2", "Exception caught. " << e );
240 void ChartController::executeDispatch_InsertMenu_DataLabels()
242 UndoGuard aUndoGuard(
243 ActionDescriptionProvider::createDescription(
244 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_DATALABELS )),
245 m_xUndoManager );
247 //if a series is selected insert labels for that series only:
248 uno::Reference< chart2::XDataSeries > xSeries(
249 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel()), uno::UNO_QUERY );
250 if( xSeries.is() )
252 // add labels
253 DataSeriesHelper::insertDataLabelsToSeriesAndAllPoints( xSeries );
255 OUString aChildParticle( ObjectIdentifier::getStringForType( OBJECTTYPE_DATA_LABELS ) + "=" );
256 OUString aObjectCID = ObjectIdentifier::createClassifiedIdentifierForParticles(
257 ObjectIdentifier::getSeriesParticleFromCID(m_aSelection.getSelectedCID()), aChildParticle );
259 bool bSuccess = ChartController::executeDlg_ObjectProperties_withoutUndoGuard( aObjectCID, true );
260 if( bSuccess )
261 aUndoGuard.commit();
262 return;
267 wrapper::AllDataLabelItemConverter aItemConverter(
268 getModel(),
269 m_pDrawModelWrapper->GetItemPool(),
270 m_pDrawModelWrapper->getSdrModel(),
271 uno::Reference< lang::XMultiServiceFactory >( getModel(), uno::UNO_QUERY ));
272 SfxItemSet aItemSet = aItemConverter.CreateEmptyItemSet();
273 aItemConverter.FillItemSet( aItemSet );
275 //prepare and open dialog
276 SolarMutexGuard aGuard;
278 //get number formatter
279 uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( getModel(), uno::UNO_QUERY );
280 NumberFormatterWrapper aNumberFormatterWrapper( xNumberFormatsSupplier );
281 SvNumberFormatter* pNumberFormatter = aNumberFormatterWrapper.getSvNumberFormatter();
283 ScopedVclPtrInstance< DataLabelsDialog > aDlg( GetChartWindow(), aItemSet, pNumberFormatter);
285 if( aDlg->Execute() == RET_OK )
287 SfxItemSet aOutItemSet = aItemConverter.CreateEmptyItemSet();
288 aDlg->FillItemSet( aOutItemSet );
289 // lock controllers till end of block
290 ControllerLockGuardUNO aCLGuard( getModel() );
291 bool bChanged = aItemConverter.ApplyItemSet( aOutItemSet );//model should be changed now
292 if( bChanged )
293 aUndoGuard.commit();
296 catch(const uno::RuntimeException& e)
298 SAL_WARN("chart2", "Exception caught. " << e );
302 void ChartController::executeDispatch_InsertMeanValue()
304 UndoGuard aUndoGuard(
305 ActionDescriptionProvider::createDescription(
306 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_AVERAGE_LINE )),
307 m_xUndoManager );
308 lcl_InsertMeanValueLine( ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(),
309 getModel() ) );
310 aUndoGuard.commit();
313 void ChartController::executeDispatch_InsertMenu_MeanValues()
315 UndoGuard aUndoGuard(
316 ActionDescriptionProvider::createDescription(
317 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_AVERAGE_LINE )),
318 m_xUndoManager );
320 uno::Reference< chart2::XDataSeries > xSeries(
321 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
322 if( xSeries.is() )
324 //if a series is selected insert mean value only for that series:
325 lcl_InsertMeanValueLine( xSeries );
327 else
329 std::vector< uno::Reference< chart2::XDataSeries > > aSeries(
330 DiagramHelper::getDataSeriesFromDiagram( ChartModelHelper::findDiagram( getModel() )));
332 for( const auto& xSrs : aSeries )
333 lcl_InsertMeanValueLine( xSrs );
335 aUndoGuard.commit();
338 void ChartController::executeDispatch_InsertMenu_Trendlines()
340 OUString aCID = m_aSelection.getSelectedCID();
342 uno::Reference< chart2::XDataSeries > xSeries(
343 ObjectIdentifier::getDataSeriesForCID( aCID, getModel() ), uno::UNO_QUERY );
345 if( !xSeries.is() )
346 return;
348 executeDispatch_InsertTrendline();
351 void ChartController::executeDispatch_InsertTrendline()
353 uno::Reference< chart2::XRegressionCurveContainer > xRegressionCurveContainer(
354 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel()), uno::UNO_QUERY );
356 if( !xRegressionCurveContainer.is() )
357 return;
359 UndoLiveUpdateGuard aUndoGuard(
360 ActionDescriptionProvider::createDescription(
361 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_CURVE )),
362 m_xUndoManager );
364 uno::Reference< chart2::XRegressionCurve > xCurve =
365 RegressionCurveHelper::addRegressionCurve(
366 SvxChartRegress::Linear,
367 xRegressionCurveContainer );
369 uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
371 if( !xProperties.is())
372 return;
374 wrapper::RegressionCurveItemConverter aItemConverter(
375 xProperties, xRegressionCurveContainer, m_pDrawModelWrapper->getSdrModel().GetItemPool(),
376 m_pDrawModelWrapper->getSdrModel(),
377 uno::Reference< lang::XMultiServiceFactory >( getModel(), uno::UNO_QUERY ));
379 // open dialog
380 SfxItemSet aItemSet = aItemConverter.CreateEmptyItemSet();
381 aItemConverter.FillItemSet( aItemSet );
382 ObjectPropertiesDialogParameter aDialogParameter = ObjectPropertiesDialogParameter(
383 ObjectIdentifier::createDataCurveCID(
384 ObjectIdentifier::getSeriesParticleFromCID( m_aSelection.getSelectedCID()),
385 RegressionCurveHelper::getRegressionCurveIndex( xRegressionCurveContainer, xCurve ), false ));
386 aDialogParameter.init( getModel() );
387 ViewElementListProvider aViewElementListProvider( m_pDrawModelWrapper.get());
388 SolarMutexGuard aGuard;
389 ScopedVclPtrInstance<SchAttribTabDlg> aDialog(
390 GetChartWindow(), &aItemSet, &aDialogParameter,
391 &aViewElementListProvider,
392 uno::Reference< util::XNumberFormatsSupplier >(
393 getModel(), uno::UNO_QUERY ) );
395 // note: when a user pressed "OK" but didn't change any settings in the
396 // dialog, the SfxTabDialog returns "Cancel"
397 if( aDialog->Execute() == RET_OK || aDialog->DialogWasClosedWithOK())
399 const SfxItemSet* pOutItemSet = aDialog->GetOutputItemSet();
400 if( pOutItemSet )
402 ControllerLockGuardUNO aCLGuard( getModel() );
403 aItemConverter.ApplyItemSet( *pOutItemSet );
405 aUndoGuard.commit();
409 void ChartController::executeDispatch_InsertErrorBars( bool bYError )
411 ObjectType objType = bYError ? OBJECTTYPE_DATA_ERRORS_Y : OBJECTTYPE_DATA_ERRORS_X;
413 //if a series is selected insert error bars for that series only:
414 uno::Reference< chart2::XDataSeries > xSeries(
415 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
417 if( xSeries.is())
419 UndoLiveUpdateGuard aUndoGuard(
420 ActionDescriptionProvider::createDescription(
421 ActionDescriptionProvider::ActionType::Insert,
422 SchResId( bYError ? STR_OBJECT_ERROR_BARS_Y : STR_OBJECT_ERROR_BARS_X )),
423 m_xUndoManager );
425 // add error bars with standard deviation
426 uno::Reference< beans::XPropertySet > xErrorBarProp(
427 StatisticsHelper::addErrorBars( xSeries,
428 css::chart::ErrorBarStyle::STANDARD_DEVIATION,
429 bYError));
431 // get an appropriate item converter
432 wrapper::ErrorBarItemConverter aItemConverter(
433 getModel(), xErrorBarProp, m_pDrawModelWrapper->getSdrModel().GetItemPool(),
434 m_pDrawModelWrapper->getSdrModel(),
435 uno::Reference< lang::XMultiServiceFactory >( getModel(), uno::UNO_QUERY ));
437 // open dialog
438 SfxItemSet aItemSet = aItemConverter.CreateEmptyItemSet();
439 aItemSet.Put(SfxBoolItem(SCHATTR_STAT_ERRORBAR_TYPE,bYError));
440 aItemConverter.FillItemSet( aItemSet );
441 ObjectPropertiesDialogParameter aDialogParameter = ObjectPropertiesDialogParameter(
442 ObjectIdentifier::createClassifiedIdentifierWithParent(
443 objType, OUString(), m_aSelection.getSelectedCID()));
444 aDialogParameter.init( getModel() );
445 ViewElementListProvider aViewElementListProvider( m_pDrawModelWrapper.get());
446 SolarMutexGuard aGuard;
447 ScopedVclPtrInstance<SchAttribTabDlg> aDlg(
448 GetChartWindow(), &aItemSet, &aDialogParameter,
449 &aViewElementListProvider,
450 uno::Reference< util::XNumberFormatsSupplier >(
451 getModel(), uno::UNO_QUERY ) );
452 aDlg->SetAxisMinorStepWidthForErrorBarDecimals(
453 InsertErrorBarsDialog::getAxisMinorStepWidthForErrorBarDecimals( getModel(),
454 m_xChartView, m_aSelection.getSelectedCID()));
456 // note: when a user pressed "OK" but didn't change any settings in the
457 // dialog, the SfxTabDialog returns "Cancel"
458 if( aDlg->Execute() == RET_OK || aDlg->DialogWasClosedWithOK())
460 const SfxItemSet* pOutItemSet = aDlg->GetOutputItemSet();
461 if( pOutItemSet )
463 ControllerLockGuardUNO aCLGuard( getModel() );
464 aItemConverter.ApplyItemSet( *pOutItemSet );
466 aUndoGuard.commit();
469 else
471 //if no series is selected insert error bars for all series
472 UndoGuard aUndoGuard(
473 ActionDescriptionProvider::createDescription(
474 ActionDescriptionProvider::ActionType::Insert,
475 ObjectNameProvider::getName_ObjectForAllSeries( objType ) ),
476 m_xUndoManager );
480 wrapper::AllSeriesStatisticsConverter aItemConverter(
481 getModel(), m_pDrawModelWrapper->GetItemPool() );
482 SfxItemSet aItemSet = aItemConverter.CreateEmptyItemSet();
483 aItemConverter.FillItemSet( aItemSet );
485 //prepare and open dialog
486 SolarMutexGuard aGuard;
487 ScopedVclPtrInstance<InsertErrorBarsDialog> aDlg(
488 GetChartWindow(), aItemSet,
489 uno::Reference< chart2::XChartDocument >( getModel(), uno::UNO_QUERY ),
490 bYError ? ErrorBarResources::ERROR_BAR_Y : ErrorBarResources::ERROR_BAR_X);
492 aDlg->SetAxisMinorStepWidthForErrorBarDecimals(
493 InsertErrorBarsDialog::getAxisMinorStepWidthForErrorBarDecimals( getModel(), m_xChartView, OUString() ) );
495 if( aDlg->Execute() == RET_OK )
497 SfxItemSet aOutItemSet = aItemConverter.CreateEmptyItemSet();
498 aDlg->FillItemSet( aOutItemSet );
500 // lock controllers till end of block
501 ControllerLockGuardUNO aCLGuard( getModel() );
502 bool bChanged = aItemConverter.ApplyItemSet( aOutItemSet );//model should be changed now
503 if( bChanged )
504 aUndoGuard.commit();
507 catch(const uno::RuntimeException& e)
509 SAL_WARN("chart2", "Exception caught. " << e );
514 void ChartController::executeDispatch_InsertTrendlineEquation( bool bInsertR2 )
516 uno::Reference< chart2::XRegressionCurve > xRegCurve(
517 ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
518 if( !xRegCurve.is() )
520 uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
521 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
522 xRegCurve.set( RegressionCurveHelper::getFirstCurveNotMeanValueLine( xRegCurveCnt ) );
524 if( xRegCurve.is())
526 uno::Reference< beans::XPropertySet > xEqProp( xRegCurve->getEquationProperties());
527 if( xEqProp.is())
529 UndoGuard aUndoGuard(
530 ActionDescriptionProvider::createDescription(
531 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_CURVE_EQUATION )),
532 m_xUndoManager );
533 xEqProp->setPropertyValue( "ShowEquation", uno::Any( true ));
534 xEqProp->setPropertyValue( "XName", uno::Any( OUString("x") ));
535 xEqProp->setPropertyValue( "YName", uno::Any( OUString("f(x)") ));
536 xEqProp->setPropertyValue( "ShowCorrelationCoefficient", uno::Any( bInsertR2 ));
537 aUndoGuard.commit();
542 void ChartController::executeDispatch_InsertR2Value()
544 uno::Reference< beans::XPropertySet > xEqProp(
545 ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
546 if( xEqProp.is())
548 UndoGuard aUndoGuard(
549 ActionDescriptionProvider::createDescription(
550 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_CURVE_EQUATION )),
551 m_xUndoManager );
552 xEqProp->setPropertyValue( "ShowCorrelationCoefficient", uno::Any( true ));
553 aUndoGuard.commit();
557 void ChartController::executeDispatch_DeleteR2Value()
559 uno::Reference< beans::XPropertySet > xEqProp(
560 ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
561 if( xEqProp.is())
563 UndoGuard aUndoGuard(
564 ActionDescriptionProvider::createDescription(
565 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_CURVE_EQUATION )),
566 m_xUndoManager );
567 xEqProp->setPropertyValue( "ShowCorrelationCoefficient", uno::Any( false ));
568 aUndoGuard.commit();
572 void ChartController::executeDispatch_DeleteMeanValue()
574 uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
575 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
576 if( xRegCurveCnt.is())
578 UndoGuard aUndoGuard(
579 ActionDescriptionProvider::createDescription(
580 ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_AVERAGE_LINE )),
581 m_xUndoManager );
582 RegressionCurveHelper::removeMeanValueLine( xRegCurveCnt );
583 aUndoGuard.commit();
587 void ChartController::executeDispatch_DeleteTrendline()
589 uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
590 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
591 if( xRegCurveCnt.is())
593 UndoGuard aUndoGuard(
594 ActionDescriptionProvider::createDescription(
595 ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_CURVE )),
596 m_xUndoManager );
597 RegressionCurveHelper::removeAllExceptMeanValueLine( xRegCurveCnt );
598 aUndoGuard.commit();
602 void ChartController::executeDispatch_DeleteTrendlineEquation()
604 uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
605 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
606 if( xRegCurveCnt.is())
608 UndoGuard aUndoGuard(
609 ActionDescriptionProvider::createDescription(
610 ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_CURVE_EQUATION )),
611 m_xUndoManager );
612 RegressionCurveHelper::removeEquations( xRegCurveCnt );
613 aUndoGuard.commit();
617 void ChartController::executeDispatch_DeleteErrorBars( bool bYError )
619 uno::Reference< chart2::XDataSeries > xDataSeries(
620 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ));
621 if( xDataSeries.is())
623 UndoGuard aUndoGuard(
624 ActionDescriptionProvider::createDescription(
625 ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_CURVE )),
626 m_xUndoManager );
627 StatisticsHelper::removeErrorBars( xDataSeries, bYError );
628 aUndoGuard.commit();
632 void ChartController::executeDispatch_InsertDataLabels()
634 uno::Reference< chart2::XDataSeries > xSeries(
635 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
636 if( xSeries.is() )
638 UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Insert,
639 SchResId( STR_OBJECT_DATALABELS )),
640 m_xUndoManager );
641 DataSeriesHelper::insertDataLabelsToSeriesAndAllPoints( xSeries );
642 aUndoGuard.commit();
646 void ChartController::executeDispatch_InsertDataLabel()
648 UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Insert,
649 SchResId( STR_OBJECT_LABEL )),
650 m_xUndoManager );
651 DataSeriesHelper::insertDataLabelToPoint( ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getModel() ) );
652 aUndoGuard.commit();
655 void ChartController::executeDispatch_DeleteDataLabels()
657 uno::Reference< chart2::XDataSeries > xSeries(
658 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
659 if( xSeries.is() )
661 UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Delete,
662 SchResId( STR_OBJECT_DATALABELS )),
663 m_xUndoManager );
664 DataSeriesHelper::deleteDataLabelsFromSeriesAndAllPoints( xSeries );
665 aUndoGuard.commit();
669 void ChartController::executeDispatch_DeleteDataLabel()
671 UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Delete,
672 SchResId( STR_OBJECT_LABEL )),
673 m_xUndoManager );
674 DataSeriesHelper::deleteDataLabelsFromPoint( ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getModel() ) );
675 aUndoGuard.commit();
678 void ChartController::executeDispatch_ResetAllDataPoints()
680 UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Format,
681 SchResId( STR_OBJECT_DATAPOINTS )),
682 m_xUndoManager );
683 uno::Reference< chart2::XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
684 if( xSeries.is() )
685 xSeries->resetAllDataPoints();
686 aUndoGuard.commit();
688 void ChartController::executeDispatch_ResetDataPoint()
690 UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Format,
691 SchResId( STR_OBJECT_DATAPOINT )),
692 m_xUndoManager );
693 uno::Reference< chart2::XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
694 if( xSeries.is() )
696 sal_Int32 nPointIndex = ObjectIdentifier::getIndexFromParticleOrCID( m_aSelection.getSelectedCID() );
697 xSeries->resetDataPoint( nPointIndex );
699 aUndoGuard.commit();
702 void ChartController::executeDispatch_InsertAxisTitle()
706 uno::Reference< XTitle > xTitle;
708 UndoGuard aUndoGuard(
709 ActionDescriptionProvider::createDescription(
710 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_TITLE )),
711 m_xUndoManager );
713 Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
714 sal_Int32 nDimensionIndex = -1;
715 sal_Int32 nCooSysIndex = -1;
716 sal_Int32 nAxisIndex = -1;
717 AxisHelper::getIndicesForAxis( xAxis, ChartModelHelper::findDiagram(getModel()), nCooSysIndex, nDimensionIndex, nAxisIndex );
719 TitleHelper::eTitleType eTitleType = TitleHelper::X_AXIS_TITLE;
720 if( nDimensionIndex==0 )
721 eTitleType = nAxisIndex==0 ? TitleHelper::X_AXIS_TITLE : TitleHelper::SECONDARY_X_AXIS_TITLE;
722 else if( nDimensionIndex==1 )
723 eTitleType = nAxisIndex==0 ? TitleHelper::Y_AXIS_TITLE : TitleHelper::SECONDARY_Y_AXIS_TITLE;
724 else
725 eTitleType = TitleHelper::Z_AXIS_TITLE;
727 std::unique_ptr< ReferenceSizeProvider > apRefSizeProvider( impl_createReferenceSizeProvider());
728 xTitle = TitleHelper::createTitle( eTitleType, ObjectNameProvider::getTitleNameByType(eTitleType), getModel(), m_xCC, apRefSizeProvider.get() );
729 aUndoGuard.commit();
732 catch(const uno::RuntimeException& e)
734 SAL_WARN("chart2", "Exception caught. " << e );
738 void ChartController::executeDispatch_InsertAxis()
740 UndoGuard aUndoGuard(
741 ActionDescriptionProvider::createDescription(
742 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_AXIS )),
743 m_xUndoManager );
747 Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
748 if( xAxis.is() )
750 AxisHelper::makeAxisVisible( xAxis );
751 aUndoGuard.commit();
754 catch(const uno::RuntimeException& e)
756 SAL_WARN("chart2", "Exception caught. " << e );
760 void ChartController::executeDispatch_DeleteAxis()
762 UndoGuard aUndoGuard(
763 ActionDescriptionProvider::createDescription(
764 ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_AXIS )),
765 m_xUndoManager );
769 Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
770 if( xAxis.is() )
772 AxisHelper::makeAxisInvisible( xAxis );
773 aUndoGuard.commit();
776 catch(const uno::RuntimeException& e)
778 SAL_WARN("chart2", "Exception caught. " << e );
782 void ChartController::executeDispatch_InsertMajorGrid()
784 UndoGuard aUndoGuard(
785 ActionDescriptionProvider::createDescription(
786 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_GRID )),
787 m_xUndoManager );
791 Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
792 if( xAxis.is() )
794 AxisHelper::makeGridVisible( xAxis->getGridProperties() );
795 aUndoGuard.commit();
798 catch(const uno::RuntimeException& e)
800 SAL_WARN("chart2", "Exception caught. " << e );
804 void ChartController::executeDispatch_DeleteMajorGrid()
806 UndoGuard aUndoGuard(
807 ActionDescriptionProvider::createDescription(
808 ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_GRID )),
809 m_xUndoManager );
813 Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
814 if( xAxis.is() )
816 AxisHelper::makeGridInvisible( xAxis->getGridProperties() );
817 aUndoGuard.commit();
820 catch(const uno::RuntimeException& e)
822 SAL_WARN("chart2", "Exception caught. " << e );
826 void ChartController::executeDispatch_InsertMinorGrid()
828 UndoGuard aUndoGuard(
829 ActionDescriptionProvider::createDescription(
830 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_GRID )),
831 m_xUndoManager );
835 Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
836 if( xAxis.is() )
838 Sequence< Reference< beans::XPropertySet > > aSubGrids( xAxis->getSubGridProperties() );
839 for( sal_Int32 nN=0; nN<aSubGrids.getLength(); nN++)
840 AxisHelper::makeGridVisible( aSubGrids[nN] );
841 aUndoGuard.commit();
844 catch(const uno::RuntimeException& e)
846 SAL_WARN("chart2", "Exception caught. " << e );
850 void ChartController::executeDispatch_DeleteMinorGrid()
852 UndoGuard aUndoGuard(
853 ActionDescriptionProvider::createDescription(
854 ActionDescriptionProvider::ActionType::Delete, SchResId(STR_OBJECT_GRID)),
855 m_xUndoManager );
859 Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
860 if( xAxis.is() )
862 Sequence< Reference< beans::XPropertySet > > aSubGrids( xAxis->getSubGridProperties() );
863 for( sal_Int32 nN=0; nN<aSubGrids.getLength(); nN++)
864 AxisHelper::makeGridInvisible( aSubGrids[nN] );
865 aUndoGuard.commit();
868 catch(const uno::RuntimeException& e)
870 SAL_WARN("chart2", "Exception caught. " << e );
874 } //namespace chart
876 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */